Commit 1181fce6 authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

[CrOS PhoneHub] Wire up buttons for Bluetooth disabled view.

This CL adds handlers for buttons on the Bluetooth disabled view.

Misc: test minor refactoring.

BUG=1106937,1126208
TEST=unittested.

Change-Id: I891d81bb67f3ef7b52cdee8835d66a05f49b8341
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495827
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821610}
parent 00a566f5
...@@ -1192,6 +1192,7 @@ component("ash") { ...@@ -1192,6 +1192,7 @@ component("ash") {
"system/phonehub/silence_phone_quick_action_controller.h", "system/phonehub/silence_phone_quick_action_controller.h",
"system/phonehub/task_continuation_view.cc", "system/phonehub/task_continuation_view.cc",
"system/phonehub/task_continuation_view.h", "system/phonehub/task_continuation_view.h",
"system/phonehub/url_constants.h",
"system/power/backlights_forced_off_setter.cc", "system/power/backlights_forced_off_setter.cc",
"system/power/backlights_forced_off_setter.h", "system/power/backlights_forced_off_setter.h",
"system/power/battery_notification.cc", "system/power/battery_notification.cc",
......
...@@ -4,13 +4,19 @@ ...@@ -4,13 +4,19 @@
#include "ash/system/phonehub/bluetooth_disabled_view.h" #include "ash/system/phonehub/bluetooth_disabled_view.h"
#include "ash/public/cpp/new_window_delegate.h"
#include "ash/public/cpp/resources/grit/ash_public_unscaled_resources.h" #include "ash/public/cpp/resources/grit/ash_public_unscaled_resources.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/system/phonehub/interstitial_view_button.h" #include "ash/system/phonehub/interstitial_view_button.h"
#include "ash/system/phonehub/phone_hub_interstitial_view.h" #include "ash/system/phonehub/phone_hub_interstitial_view.h"
#include "ash/system/phonehub/phone_hub_metrics.h" #include "ash/system/phonehub/phone_hub_metrics.h"
#include "ash/system/phonehub/phone_hub_tray.h"
#include "ash/system/phonehub/phone_hub_view_ids.h" #include "ash/system/phonehub/phone_hub_view_ids.h"
#include "ash/system/phonehub/url_constants.h"
#include "ash/system/status_area_widget.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -22,15 +28,6 @@ using phone_hub_metrics::InterstitialScreen; ...@@ -22,15 +28,6 @@ using phone_hub_metrics::InterstitialScreen;
using phone_hub_metrics::InterstitialScreenEvent; using phone_hub_metrics::InterstitialScreenEvent;
using phone_hub_metrics::LogInterstitialScreenEvent; using phone_hub_metrics::LogInterstitialScreenEvent;
namespace {
// Tag value used to uniquely identify the "Learn More" and "Ok, got it"
// buttons.
constexpr int kLearnMoreButtonTag = 1;
constexpr int kOkButtonTag = 2;
} // namespace
BluetoothDisabledView::BluetoothDisabledView() { BluetoothDisabledView::BluetoothDisabledView() {
SetID(PhoneHubViewID::kBluetoothDisabledView); SetID(PhoneHubViewID::kBluetoothDisabledView);
...@@ -57,16 +54,16 @@ BluetoothDisabledView::BluetoothDisabledView() { ...@@ -57,16 +54,16 @@ BluetoothDisabledView::BluetoothDisabledView() {
learn_more->SetEnabledTextColors( learn_more->SetEnabledTextColors(
AshColorProvider::Get()->GetContentLayerColor( AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary)); AshColorProvider::ContentLayerType::kTextColorPrimary));
learn_more->set_tag(kLearnMoreButtonTag); learn_more->SetID(PhoneHubViewID::kBluetoothDisabledLearnMoreButton);
content_view_->AddButton(std::move(learn_more)); content_view_->AddButton(std::move(learn_more));
auto refresh = std::make_unique<InterstitialViewButton>( auto confirm = std::make_unique<InterstitialViewButton>(
this, this,
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
IDS_ASH_PHONE_HUB_BLUETOOTH_DISABLED_DIALOG_OK_BUTTON), IDS_ASH_PHONE_HUB_BLUETOOTH_DISABLED_DIALOG_OK_BUTTON),
/*paint_background=*/true); /*paint_background=*/true);
refresh->set_tag(kOkButtonTag); confirm->SetID(PhoneHubViewID::kBluetoothDisabledConfirmButton);
content_view_->AddButton(std::move(refresh)); content_view_->AddButton(std::move(confirm));
LogInterstitialScreenEvent(InterstitialScreen::kBluetoothOrWifiDisabled, LogInterstitialScreenEvent(InterstitialScreen::kBluetoothOrWifiDisabled,
InterstitialScreenEvent::kShown); InterstitialScreenEvent::kShown);
...@@ -76,13 +73,21 @@ BluetoothDisabledView::~BluetoothDisabledView() = default; ...@@ -76,13 +73,21 @@ BluetoothDisabledView::~BluetoothDisabledView() = default;
void BluetoothDisabledView::ButtonPressed(views::Button* sender, void BluetoothDisabledView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
// TODO(crbug.com/1126208): implement button pressed actions. switch (sender->GetID()) {
if (sender->tag() == kLearnMoreButtonTag) { case kBluetoothDisabledLearnMoreButton:
LogInterstitialScreenEvent(InterstitialScreen::kBluetoothOrWifiDisabled, LogInterstitialScreenEvent(InterstitialScreen::kBluetoothOrWifiDisabled,
InterstitialScreenEvent::kLearnMore); InterstitialScreenEvent::kLearnMore);
} else if (sender->tag() == kOkButtonTag) { NewWindowDelegate::GetInstance()->NewTabWithUrl(
LogInterstitialScreenEvent(InterstitialScreen::kBluetoothOrWifiDisabled, GURL(kLearnMoreUrl), /*from_user_interaction=*/true);
InterstitialScreenEvent::kConfirm); return;
case kBluetoothDisabledConfirmButton:
LogInterstitialScreenEvent(InterstitialScreen::kBluetoothOrWifiDisabled,
InterstitialScreenEvent::kConfirm);
Shell::GetPrimaryRootWindowController()
->GetStatusAreaWidget()
->phone_hub_tray()
->CloseBubble();
return;
} }
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/system/phonehub/phone_hub_interstitial_view.h" #include "ash/system/phonehub/phone_hub_interstitial_view.h"
#include "ash/system/phonehub/phone_hub_metrics.h" #include "ash/system/phonehub/phone_hub_metrics.h"
#include "ash/system/phonehub/phone_hub_view_ids.h" #include "ash/system/phonehub/phone_hub_view_ids.h"
#include "ash/system/phonehub/url_constants.h"
#include "chromeos/components/phonehub/connection_scheduler.h" #include "chromeos/components/phonehub/connection_scheduler.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -26,14 +27,6 @@ using phone_hub_metrics::InterstitialScreen; ...@@ -26,14 +27,6 @@ using phone_hub_metrics::InterstitialScreen;
using phone_hub_metrics::InterstitialScreenEvent; using phone_hub_metrics::InterstitialScreenEvent;
using phone_hub_metrics::LogInterstitialScreenEvent; using phone_hub_metrics::LogInterstitialScreenEvent;
namespace {
// TODO(meilinw): replace it with the real one.
constexpr char kLearnMoreUrl[] =
"https://support.google.com/chromebook/?p=multi_device";
} // namespace
ConnectionErrorView::ConnectionErrorView( ConnectionErrorView::ConnectionErrorView(
ErrorStatus error, ErrorStatus error,
chromeos::phonehub::ConnectionScheduler* connection_scheduler) chromeos::phonehub::ConnectionScheduler* connection_scheduler)
......
...@@ -90,56 +90,59 @@ class PhoneHubTrayTest : public AshTestBase { ...@@ -90,56 +90,59 @@ class PhoneHubTrayTest : public AshTestBase {
MockNewWindowDelegate& new_window_delegate() { return new_window_delegate_; } MockNewWindowDelegate& new_window_delegate() { return new_window_delegate_; }
views::View* bubble_view() { return phone_hub_tray_->GetBubbleView(); }
views::View* content_view() { views::View* content_view() {
return phone_hub_tray_->content_view_for_testing(); return phone_hub_tray_->content_view_for_testing();
} }
NotificationOptInView* notification_opt_in_view() { NotificationOptInView* notification_opt_in_view() {
return static_cast<NotificationOptInView*>( return static_cast<NotificationOptInView*>(
phone_hub_tray_->GetBubbleView()->GetViewByID( bubble_view()->GetViewByID(PhoneHubViewID::kNotificationOptInView));
PhoneHubViewID::kNotificationOptInView));
}
views::Button* disconnected_refresh_button() {
return static_cast<views::Button*>(
phone_hub_tray_->GetBubbleView()->GetViewByID(
PhoneHubViewID::kDisconnectedRefreshButton));
}
views::Button* disconnected_learn_more_button() {
return static_cast<views::Button*>(
phone_hub_tray_->GetBubbleView()->GetViewByID(
PhoneHubViewID::kDisconnectedLearnMoreButton));
} }
views::View* onboarding_main_view() { views::View* onboarding_main_view() {
return static_cast<views::View*>( return bubble_view()->GetViewByID(PhoneHubViewID::kOnboardingMainView);
phone_hub_tray_->GetBubbleView()->GetViewByID(
PhoneHubViewID::kOnboardingMainView));
} }
views::View* onboarding_dismiss_prompt_view() { views::View* onboarding_dismiss_prompt_view() {
return static_cast<views::View*>( return bubble_view()->GetViewByID(
phone_hub_tray_->GetBubbleView()->GetViewByID( PhoneHubViewID::kOnboardingDismissPromptView);
PhoneHubViewID::kOnboardingDismissPromptView));
} }
views::Button* onboarding_get_started_button() { views::Button* onboarding_get_started_button() {
return static_cast<views::Button*>( return static_cast<views::Button*>(bubble_view()->GetViewByID(
phone_hub_tray_->GetBubbleView()->GetViewByID( PhoneHubViewID::kOnboardingGetStartedButton));
PhoneHubViewID::kOnboardingGetStartedButton));
} }
views::Button* onboarding_dismiss_button() { views::Button* onboarding_dismiss_button() {
return static_cast<views::Button*>( return static_cast<views::Button*>(
phone_hub_tray_->GetBubbleView()->GetViewByID( bubble_view()->GetViewByID(PhoneHubViewID::kOnboardingDismissButton));
PhoneHubViewID::kOnboardingDismissButton));
} }
views::Button* onboarding_dismiss_ack_button() { views::Button* onboarding_dismiss_ack_button() {
return static_cast<views::Button*>(bubble_view()->GetViewByID(
PhoneHubViewID::kOnboardingDismissAckButton));
}
views::Button* disconnected_refresh_button() {
return static_cast<views::Button*>( return static_cast<views::Button*>(
phone_hub_tray_->GetBubbleView()->GetViewByID( bubble_view()->GetViewByID(PhoneHubViewID::kDisconnectedRefreshButton));
PhoneHubViewID::kOnboardingDismissAckButton)); }
views::Button* disconnected_learn_more_button() {
return static_cast<views::Button*>(bubble_view()->GetViewByID(
PhoneHubViewID::kDisconnectedLearnMoreButton));
}
views::Button* bluetooth_disabled_learn_more_button() {
return static_cast<views::Button*>(bubble_view()->GetViewByID(
PhoneHubViewID::kBluetoothDisabledLearnMoreButton));
}
views::Button* bluetooth_disabled_confirm_button() {
return static_cast<views::Button*>(bubble_view()->GetViewByID(
PhoneHubViewID::kBluetoothDisabledConfirmButton));
} }
protected: protected:
...@@ -348,6 +351,7 @@ TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) { ...@@ -348,6 +351,7 @@ TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) {
ClickTrayButton(); ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active()); EXPECT_TRUE(phone_hub_tray_->is_active());
EXPECT_TRUE(content_view());
EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID()); EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID());
// Simulates a click on the "Refresh" button. // Simulates a click on the "Refresh" button.
...@@ -368,8 +372,32 @@ TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) { ...@@ -368,8 +372,32 @@ TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) {
// Simulates a click on the "Learn more" button. // Simulates a click on the "Learn more" button.
ClickOnAndWait(disconnected_learn_more_button()); ClickOnAndWait(disconnected_learn_more_button());
EXPECT_TRUE(content_view()); }
EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID());
TEST_F(PhoneHubTrayTest, ClickButtonsOnBluetoothDisabledView) {
// Simulate a Bluetooth unavailable state.
GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kUnavailableBluetoothOff);
ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active());
EXPECT_EQ(PhoneHubViewID::kBluetoothDisabledView, content_view()->GetID());
// Clicking "Learn more" button should open the corresponding help center
// article in a browser tab.
EXPECT_CALL(new_window_delegate(), NewTabWithUrl)
.WillOnce([](const GURL& url, bool from_user_interaction) {
EXPECT_EQ(GURL("https://support.google.com/chromebook/?p=multi_device"),
url);
EXPECT_TRUE(from_user_interaction);
});
// Simulate a click on "Learn more" button.
ClickOnAndWait(bluetooth_disabled_learn_more_button());
// Simulate a click on "Ok, got it" button.
ClickOnAndWait(bluetooth_disabled_confirm_button());
// Clicking "Ok, got it" button should dimiss the bubble.
EXPECT_FALSE(phone_hub_tray_->GetBubbleView());
} }
} // namespace ash } // namespace ash
...@@ -32,9 +32,13 @@ enum PhoneHubViewID { ...@@ -32,9 +32,13 @@ enum PhoneHubViewID {
kDisconnectedLearnMoreButton, kDisconnectedLearnMoreButton,
kDisconnectedRefreshButton, kDisconnectedRefreshButton,
// Bluetooth disabled view and its components.
kBluetoothDisabledView,
kBluetoothDisabledLearnMoreButton,
kBluetoothDisabledConfirmButton,
kPhoneConnectedView, kPhoneConnectedView,
kInitialConnectingView, kInitialConnectingView,
kBluetoothDisabledView,
}; };
} // namespace ash } // namespace ash
......
// 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.
#ifndef ASH_SYSTEM_PHONEHUB_URL_CONSTANTS_H_
#define ASH_SYSTEM_PHONEHUB_URL_CONSTANTS_H_
namespace ash {
// TODO(meilinw): replace it with the real one.
constexpr char kLearnMoreUrl[] =
"https://support.google.com/chromebook/?p=multi_device";
} // namespace ash
#endif // ASH_SYSTEM_PHONEHUB_URL_CONSTANTS_H_
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