Commit 8ae3e213 authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

[CrOS PhoneHub] Wire up buttons for disconnected view.

This CL adds handlers for "Learn More" and "Refresh" buttons on the
disconnected view.

Misc:
1. Minor refactoring on |PhoneHubTrayTest|.
2. Adds initial value for |num_schedule_connection_now_calls_|.

BUG=1106937,1126208
TEST=unittested.

Change-Id: I3e6c74b331710c1f6607865061f12267f8d27af6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2439639
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@{#813311}
parent d98b011d
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
#include <memory> #include <memory>
#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/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/phone_hub_interstitial_view.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 "ash/system/unified/rounded_label_button.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"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -19,13 +22,19 @@ namespace ash { ...@@ -19,13 +22,19 @@ namespace ash {
namespace { namespace {
// Tag value used to uniquely identify the "Learn More" and "Refresh" buttons. // TODO(meilinw): replace it with the real one.
constexpr int kLearnMoreButtonTag = 1; constexpr char kLearnMoreUrl[] =
constexpr int kRefreshButtonTag = 2; "https://support.google.com/chromebook/?p=multi_device";
} // namespace } // namespace
ConnectionErrorView::ConnectionErrorView(ErrorStatus error) { ConnectionErrorView::ConnectionErrorView(
ErrorStatus error,
chromeos::phonehub::ConnectionScheduler* connection_scheduler)
: connection_scheduler_(connection_scheduler) {
SetID(error == ErrorStatus::kDisconnected
? PhoneHubViewID::kDisconnectedView
: PhoneHubViewID::kReconnectingView);
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
content_view_ = AddChildView(std::make_unique<PhoneHubInterstitialView>( content_view_ = AddChildView(std::make_unique<PhoneHubInterstitialView>(
/*show_progress=*/error == ErrorStatus::kReconnecting)); /*show_progress=*/error == ErrorStatus::kReconnecting));
...@@ -55,13 +64,13 @@ ConnectionErrorView::ConnectionErrorView(ErrorStatus error) { ...@@ -55,13 +64,13 @@ ConnectionErrorView::ConnectionErrorView(ErrorStatus error) {
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::kDisconnectedLearnMoreButton);
content_view_->AddButton(std::move(learn_more)); content_view_->AddButton(std::move(learn_more));
auto refresh = std::make_unique<RoundedLabelButton>( auto refresh = std::make_unique<RoundedLabelButton>(
this, l10n_util::GetStringUTF16( this, l10n_util::GetStringUTF16(
IDS_ASH_PHONE_HUB_CONNECTION_ERROR_DIALOG_REFRESH_BUTTON)); IDS_ASH_PHONE_HUB_CONNECTION_ERROR_DIALOG_REFRESH_BUTTON));
refresh->set_tag(kRefreshButtonTag); refresh->SetID(PhoneHubViewID::kDisconnectedRefreshButton);
content_view_->AddButton(std::move(refresh)); content_view_->AddButton(std::move(refresh));
} }
...@@ -69,7 +78,16 @@ ConnectionErrorView::~ConnectionErrorView() = default; ...@@ -69,7 +78,16 @@ ConnectionErrorView::~ConnectionErrorView() = default;
void ConnectionErrorView::ButtonPressed(views::Button* sender, void ConnectionErrorView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
// TODO(meilinw): implement button pressed actions. switch (sender->GetID()) {
case PhoneHubViewID::kDisconnectedRefreshButton:
// Retry the connection attempt.
connection_scheduler_->ScheduleConnectionNow();
return;
case PhoneHubViewID::kDisconnectedLearnMoreButton:
NewWindowDelegate::GetInstance()->NewTabWithUrl(
GURL(kLearnMoreUrl), /*from_user_interaction=*/true);
return;
}
} }
BEGIN_METADATA(ConnectionErrorView, views::View) BEGIN_METADATA(ConnectionErrorView, views::View)
......
...@@ -8,6 +8,12 @@ ...@@ -8,6 +8,12 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
namespace chromeos {
namespace phonehub {
class ConnectionScheduler;
} // namespace phonehub
} // namespace chromeos
namespace ash { namespace ash {
class PhoneHubInterstitialView; class PhoneHubInterstitialView;
...@@ -25,7 +31,9 @@ class ASH_EXPORT ConnectionErrorView : public views::View, ...@@ -25,7 +31,9 @@ class ASH_EXPORT ConnectionErrorView : public views::View,
kReconnecting, // Attempts to resume the connection to the phone. kReconnecting, // Attempts to resume the connection to the phone.
}; };
explicit ConnectionErrorView(ErrorStatus error); ConnectionErrorView(
ErrorStatus error,
chromeos::phonehub::ConnectionScheduler* connection_scheduler);
ConnectionErrorView(const ConnectionErrorView&) = delete; ConnectionErrorView(const ConnectionErrorView&) = delete;
ConnectionErrorView& operator=(const ConnectionErrorView&) = delete; ConnectionErrorView& operator=(const ConnectionErrorView&) = delete;
~ConnectionErrorView() override; ~ConnectionErrorView() override;
...@@ -34,6 +42,8 @@ class ASH_EXPORT ConnectionErrorView : public views::View, ...@@ -34,6 +42,8 @@ class ASH_EXPORT ConnectionErrorView : public views::View,
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
chromeos::phonehub::ConnectionScheduler* connection_scheduler_ = nullptr;
PhoneHubInterstitialView* content_view_ = nullptr; PhoneHubInterstitialView* content_view_ = nullptr;
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/system/status_area_widget_test_helper.h" #include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chromeos/components/phonehub/fake_connection_scheduler.h"
#include "chromeos/components/phonehub/fake_notification_access_manager.h" #include "chromeos/components/phonehub/fake_notification_access_manager.h"
#include "chromeos/components/phonehub/fake_phone_hub_manager.h" #include "chromeos/components/phonehub/fake_phone_hub_manager.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
...@@ -60,10 +61,8 @@ class PhoneHubTrayTest : public AshTestBase { ...@@ -60,10 +61,8 @@ class PhoneHubTrayTest : public AshTestBase {
return phone_hub_manager_.fake_notification_access_manager(); return phone_hub_manager_.fake_notification_access_manager();
} }
void ClickTrayButton() { chromeos::phonehub::FakeConnectionScheduler* GetConnectionScheduler() {
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), return phone_hub_manager_.fake_connection_scheduler();
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
phone_hub_tray_->PerformAction(tap);
} }
// Simulate a mouse click on the given view. // Simulate a mouse click on the given view.
...@@ -76,14 +75,32 @@ class PhoneHubTrayTest : public AshTestBase { ...@@ -76,14 +75,32 @@ class PhoneHubTrayTest : public AshTestBase {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
void ClickTrayButton() { ClickOnAndWait(phone_hub_tray_); }
MockNewWindowDelegate& new_window_delegate() { return new_window_delegate_; } MockNewWindowDelegate& new_window_delegate() { return new_window_delegate_; }
views::View* content_view() {
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( phone_hub_tray_->GetBubbleView()->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));
}
protected: protected:
PhoneHubTray* phone_hub_tray_ = nullptr; PhoneHubTray* phone_hub_tray_ = nullptr;
chromeos::phonehub::FakePhoneHubManager phone_hub_manager_; chromeos::phonehub::FakePhoneHubManager phone_hub_manager_;
...@@ -182,18 +199,44 @@ TEST_F(PhoneHubTrayTest, TransitionContentView) { ...@@ -182,18 +199,44 @@ TEST_F(PhoneHubTrayTest, TransitionContentView) {
ClickTrayButton(); ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active()); EXPECT_TRUE(phone_hub_tray_->is_active());
auto* content_view = phone_hub_tray_->content_view_for_testing(); EXPECT_TRUE(content_view());
EXPECT_TRUE(content_view);
// TODO(tengs) Test the actual view id. // TODO(tengs) Test the actual view id.
EXPECT_EQ(0, content_view->GetID()); EXPECT_EQ(0, content_view()->GetID());
GetFeatureStatusProvider()->SetStatus( GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kEnabledButDisconnected); chromeos::phonehub::FeatureStatus::kEnabledButDisconnected);
content_view = phone_hub_tray_->content_view_for_testing(); EXPECT_TRUE(content_view());
EXPECT_TRUE(content_view); EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID());
// TODO(tengs) Test the actual view id. }
EXPECT_EQ(0, content_view->GetID());
TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) {
// Simulates a phone disconnected error state to show the disconnected view.
GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kEnabledButDisconnected);
ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active());
EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID());
// Simulates a click on the "Refresh" button.
EXPECT_EQ(0u, GetConnectionScheduler()->num_schedule_connection_now_calls());
ClickOnAndWait(disconnected_refresh_button());
// Clicking "Refresh" button should schedule a connection attempt.
EXPECT_EQ(1u, GetConnectionScheduler()->num_schedule_connection_now_calls());
// 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);
});
// Simulates a click on the "Learn more" button.
ClickOnAndWait(disconnected_learn_more_button());
} }
} // namespace ash } // namespace ash
...@@ -62,10 +62,12 @@ std::unique_ptr<views::View> PhoneHubUiController::CreateContentView( ...@@ -62,10 +62,12 @@ std::unique_ptr<views::View> PhoneHubUiController::CreateContentView(
return std::make_unique<InitialConnectingView>(); return std::make_unique<InitialConnectingView>();
case UiState::kPhoneConnecting: case UiState::kPhoneConnecting:
return std::make_unique<ConnectionErrorView>( return std::make_unique<ConnectionErrorView>(
ConnectionErrorView::ErrorStatus::kReconnecting); ConnectionErrorView::ErrorStatus::kReconnecting,
phone_hub_manager_->GetConnectionScheduler());
case UiState::kConnectionError: case UiState::kConnectionError:
return std::make_unique<ConnectionErrorView>( return std::make_unique<ConnectionErrorView>(
ConnectionErrorView::ErrorStatus::kDisconnected); ConnectionErrorView::ErrorStatus::kDisconnected,
phone_hub_manager_->GetConnectionScheduler());
case UiState::kPhoneConnected: case UiState::kPhoneConnected:
return std::make_unique<PhoneConnectedView>(bubble_view, return std::make_unique<PhoneConnectedView>(bubble_view,
phone_hub_manager_); phone_hub_manager_);
......
...@@ -125,8 +125,7 @@ TEST_F(PhoneHubUiControllerTest, PhoneDisconnected) { ...@@ -125,8 +125,7 @@ TEST_F(PhoneHubUiControllerTest, PhoneDisconnected) {
controller_.ui_state()); controller_.ui_state());
auto content_view = controller_.CreateContentView(/*bubble_view=*/nullptr); auto content_view = controller_.CreateContentView(/*bubble_view=*/nullptr);
// TODO(tengs): Test the actual view id. EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view->GetID());
EXPECT_EQ(0, content_view->GetID());
} }
TEST_F(PhoneHubUiControllerTest, PhoneConnecting) { TEST_F(PhoneHubUiControllerTest, PhoneConnecting) {
...@@ -135,8 +134,7 @@ TEST_F(PhoneHubUiControllerTest, PhoneConnecting) { ...@@ -135,8 +134,7 @@ TEST_F(PhoneHubUiControllerTest, PhoneConnecting) {
controller_.ui_state()); controller_.ui_state());
auto content_view = controller_.CreateContentView(/*bubble_view=*/nullptr); auto content_view = controller_.CreateContentView(/*bubble_view=*/nullptr);
// TODO(tengs): Test the actual view id. EXPECT_EQ(PhoneHubViewID::kReconnectingView, content_view->GetID());
EXPECT_EQ(0, content_view->GetID());
} }
TEST_F(PhoneHubUiControllerTest, PhoneConnected) { TEST_F(PhoneHubUiControllerTest, PhoneConnected) {
......
...@@ -22,6 +22,12 @@ enum PhoneHubViewID { ...@@ -22,6 +22,12 @@ enum PhoneHubViewID {
kOnboardingView, kOnboardingView,
kOnboardingGetStartedButton, kOnboardingGetStartedButton,
kOnboardingDismissButton, kOnboardingDismissButton,
// Connection error view and its components.
kDisconnectedView,
kReconnectingView,
kDisconnectedLearnMoreButton,
kDisconnectedRefreshButton,
}; };
} // namespace ash } // namespace ash
......
...@@ -25,7 +25,7 @@ class FakeConnectionScheduler : public ConnectionScheduler { ...@@ -25,7 +25,7 @@ class FakeConnectionScheduler : public ConnectionScheduler {
// ConnectionScheduler: // ConnectionScheduler:
void ScheduleConnectionNow() override; void ScheduleConnectionNow() override;
size_t num_schedule_connection_now_calls_; size_t num_schedule_connection_now_calls_ = 0u;
}; };
} // namespace phonehub } // namespace phonehub
......
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