Commit 98efd1be authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

[CrOS PhoneHub] Wire up buttons for the onboarding view.

This CL adds handlers for "Get started" and "Dismiss" buttons on the
onboarding screen.

Misc: Update unittests in |PhoneHubUiControllerTest|.

BUG=1106937,1126208
TEST=unittested.

Change-Id: I6576b3fb32c1bd5b6a96a61ff9fcdc5ac9c2fc70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2439363
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812954}
parent b0587ddd
......@@ -2134,6 +2134,7 @@ test("ash_unittests") {
"system/palette/tools/create_note_unittest.cc",
"system/palette/tools/metalayer_unittest.cc",
"system/palette/tools/screenshot_unittest.cc",
"system/phonehub/onboarding_view_unittest.cc",
"system/phonehub/phone_hub_notification_controller_unittest.cc",
"system/phonehub/phone_hub_tray_unittest.cc",
"system/phonehub/phone_hub_ui_controller_unittest.cc",
......
......@@ -9,11 +9,16 @@
#include <vector>
#include "ash/public/cpp/resources/grit/ash_public_unscaled_resources.h"
#include "ash/public/cpp/system_tray_client.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/phonehub/phone_hub_interstitial_view.h"
#include "ash/system/phonehub/phone_hub_view_ids.h"
#include "ash/system/unified/rounded_label_button.h"
#include "base/strings/string16.h"
#include "chromeos/components/phonehub/onboarding_ui_tracker.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/button/button.h"
......@@ -22,15 +27,11 @@
namespace ash {
namespace {
OnboardingView::OnboardingView(
chromeos::phonehub::OnboardingUiTracker* onboarding_ui_tracker)
: onboarding_ui_tracker_(onboarding_ui_tracker) {
SetID(PhoneHubViewID::kOnboardingView);
// Tag value used to uniquely identify the "Dismiss" and "Get started" buttons.
constexpr int kDismissButtonTag = 1;
constexpr int kGetStartedTag = 2;
} // namespace
OnboardingView::OnboardingView() {
SetLayoutManager(std::make_unique<views::FillLayout>());
content_view_ = AddChildView(
std::make_unique<PhoneHubInterstitialView>(/*show_progress=*/false));
......@@ -51,13 +52,13 @@ OnboardingView::OnboardingView() {
IDS_ASH_PHONE_HUB_ONBOARDING_DIALOG_DISMISS_BUTTON));
dismiss->SetEnabledTextColors(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary));
dismiss->set_tag(kDismissButtonTag);
dismiss->SetID(PhoneHubViewID::kOnboardingDismissButton);
content_view_->AddButton(std::move(dismiss));
auto get_started = std::make_unique<RoundedLabelButton>(
this, l10n_util::GetStringUTF16(
IDS_ASH_PHONE_HUB_ONBOARDING_DIALOG_GET_STARTED_BUTTON));
get_started->set_tag(kGetStartedTag);
get_started->SetID(PhoneHubViewID::kOnboardingGetStartedButton);
content_view_->AddButton(std::move(get_started));
}
......@@ -65,7 +66,14 @@ OnboardingView::~OnboardingView() = default;
void OnboardingView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
// TODO(meilinw): implement button pressed actions.
switch (sender->GetID()) {
case PhoneHubViewID::kOnboardingGetStartedButton:
onboarding_ui_tracker_->HandleGetStarted();
return;
case PhoneHubViewID::kOnboardingDismissButton:
onboarding_ui_tracker_->DismissSetupUi();
return;
}
}
BEGIN_METADATA(OnboardingView, views::View)
......
......@@ -10,6 +10,12 @@
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
namespace chromeos {
namespace phonehub {
class OnboardingUiTracker;
} // namespace phonehub
} // namespace chromeos
namespace ash {
class PhoneHubInterstitialView;
......@@ -21,7 +27,8 @@ class ASH_EXPORT OnboardingView : public views::View,
public:
METADATA_HEADER(OnboardingView);
OnboardingView();
explicit OnboardingView(
chromeos::phonehub::OnboardingUiTracker* onboarding_ui_tracker);
OnboardingView(const OnboardingView&) = delete;
OnboardingView& operator=(const OnboardingView&) = delete;
~OnboardingView() override;
......@@ -30,6 +37,8 @@ class ASH_EXPORT OnboardingView : public views::View,
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
chromeos::phonehub::OnboardingUiTracker* onboarding_ui_tracker_ = nullptr;
// The view responsible for displaying the onboarding UI contents.
// Owned by view hierarchy.
PhoneHubInterstitialView* content_view_ = nullptr;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/phonehub/onboarding_view.h"
#include <memory>
#include "ash/public/cpp/test/test_system_tray_client.h"
#include "ash/system/phonehub/phone_hub_view_ids.h"
#include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/components/phonehub/fake_onboarding_ui_tracker.h"
#include "chromeos/constants/chromeos_features.h"
namespace ash {
class OnboardingViewTest : public AshTestBase {
public:
OnboardingViewTest() = default;
~OnboardingViewTest() override = default;
// AshTestBase:
void SetUp() override {
feature_list_.InitAndEnableFeature(chromeos::features::kPhoneHub);
AshTestBase::SetUp();
onboarding_view_ =
std::make_unique<OnboardingView>(&fake_onboarding_ui_tracker_);
}
void TearDown() override {
onboarding_view_.reset();
AshTestBase::TearDown();
}
protected:
OnboardingView* onboarding_view() { return onboarding_view_.get(); }
views::Button* get_started_button() {
return static_cast<views::Button*>(onboarding_view_->GetViewByID(
PhoneHubViewID::kOnboardingGetStartedButton));
}
views::Button* dismiss_button() {
return static_cast<views::Button*>(onboarding_view_->GetViewByID(
PhoneHubViewID::kOnboardingDismissButton));
}
chromeos::phonehub::FakeOnboardingUiTracker* fake_onboarding_ui_tracker() {
return &fake_onboarding_ui_tracker_;
}
private:
base::test::ScopedFeatureList feature_list_;
chromeos::phonehub::FakeOnboardingUiTracker fake_onboarding_ui_tracker_;
std::unique_ptr<OnboardingView> onboarding_view_ = nullptr;
};
TEST_F(OnboardingViewTest, PressGetStartedButton) {
EXPECT_EQ(0u, fake_onboarding_ui_tracker()->handle_get_started_call_count());
// Simulates a mouse press on the Get started button.
onboarding_view()->ButtonPressed(
get_started_button(),
ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(), gfx::PointF(),
base::TimeTicks(), 0, 0));
// Pressing Get started button should invoke the |HandleGetStarted| call.
EXPECT_EQ(1u, fake_onboarding_ui_tracker()->handle_get_started_call_count());
}
TEST_F(OnboardingViewTest, PressDismissButton) {
fake_onboarding_ui_tracker()->SetShouldShowOnboardingUi(true);
// Simulates a mouse press on the Dismiss button.
onboarding_view()->ButtonPressed(
dismiss_button(), ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(),
gfx::PointF(), base::TimeTicks(), 0, 0));
// Pressing Dismiss button should disable the ability to show onboarding UI
// again.
EXPECT_FALSE(fake_onboarding_ui_tracker()->ShouldShowOnboardingUi());
}
} // namespace ash
......@@ -4,6 +4,8 @@
#include "ash/system/phonehub/phone_hub_ui_controller.h"
#include <memory>
#include "ash/system/phonehub/bluetooth_disabled_view.h"
#include "ash/system/phonehub/connection_error_view.h"
#include "ash/system/phonehub/initial_connecting_view.h"
......@@ -51,10 +53,9 @@ std::unique_ptr<views::View> PhoneHubUiController::CreateContentView(
case UiState::kHidden:
return nullptr;
case UiState::kOnboardingWithoutPhone:
// TODO(tengs): distinguish this onboarding with phone state.
FALLTHROUGH;
case UiState::kOnboardingWithPhone:
return std::make_unique<OnboardingView>();
return std::make_unique<OnboardingView>(
phone_hub_manager_->GetOnboardingUiTracker());
case UiState::kBluetoothDisabled:
return std::make_unique<BluetoothDisabledView>();
case UiState::kInitialConnecting:
......
......@@ -4,6 +4,7 @@
#include "ash/system/phonehub/phone_hub_ui_controller.h"
#include "ash/system/phonehub/phone_hub_view_ids.h"
#include "ash/test/ash_test_base.h"
#include "chromeos/components/phonehub/fake_phone_hub_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -78,8 +79,7 @@ TEST_F(PhoneHubUiControllerTest, ShowOnboardingUi_WithoutPhone) {
controller_.ui_state());
auto content_view = controller_.CreateContentView(/*bubble_view=*/nullptr);
// TODO(tengs): Test the actual view id.
EXPECT_EQ(0, content_view->GetID());
EXPECT_EQ(PhoneHubViewID::kOnboardingView, content_view->GetID());
}
TEST_F(PhoneHubUiControllerTest, ShowOnboardingUi_WithPhone) {
......@@ -94,8 +94,7 @@ TEST_F(PhoneHubUiControllerTest, ShowOnboardingUi_WithPhone) {
controller_.ui_state());
auto content_view = controller_.CreateContentView(/*bubble_view=*/nullptr);
// TODO(tengs): Test the actual view id.
EXPECT_EQ(0, content_view->GetID());
EXPECT_EQ(PhoneHubViewID::kOnboardingView, content_view->GetID());
}
TEST_F(PhoneHubUiControllerTest, PhoneConnectingForOnboarding) {
......
......@@ -17,6 +17,11 @@ enum PhoneHubViewID {
kNotificationOptInView,
kQuickActionsView,
kTaskContinuationView,
// Onboarding view and its components.
kOnboardingView,
kOnboardingGetStartedButton,
kOnboardingDismissButton,
};
} // namespace ash
......
......@@ -17,13 +17,15 @@ class FakeOnboardingUiTracker : public OnboardingUiTracker {
void SetShouldShowOnboardingUi(bool should_show_onboarding_ui);
// OnboardingUiTracker:
bool ShouldShowOnboardingUi() const override;
size_t handle_get_started_call_count() {
return handle_get_started_call_count_;
}
private:
// OnboardingUiTracker:
bool ShouldShowOnboardingUi() const override;
void DismissSetupUi() override;
void HandleGetStarted() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment