diff --git a/ash/multi_device_setup/multi_device_notification_presenter.cc b/ash/multi_device_setup/multi_device_notification_presenter.cc index 4e7f2dd14aea3b..46edd0752e6da9 100644 --- a/ash/multi_device_setup/multi_device_notification_presenter.cc +++ b/ash/multi_device_setup/multi_device_notification_presenter.cc @@ -56,18 +56,6 @@ MultiDeviceNotificationPresenter::GetNotificationDescriptionForLogging( NOTREACHED(); } -MultiDeviceNotificationPresenter::OpenUiDelegate::~OpenUiDelegate() = default; - -void MultiDeviceNotificationPresenter::OpenUiDelegate:: - OpenMultiDeviceSetupUi() { - Shell::Get()->system_tray_model()->client()->ShowMultiDeviceSetup(); -} - -void MultiDeviceNotificationPresenter::OpenUiDelegate:: - OpenConnectedDevicesSettings() { - Shell::Get()->system_tray_model()->client()->ShowConnectedDevicesSettings(); -} - // static MultiDeviceNotificationPresenter::NotificationType MultiDeviceNotificationPresenter::GetMetricValueForNotification( @@ -91,7 +79,6 @@ MultiDeviceNotificationPresenter::MultiDeviceNotificationPresenter( : message_center_(message_center), connector_(connector), binding_(this), - open_ui_delegate_(std::make_unique()), weak_ptr_factory_(this) { DCHECK(message_center_); DCHECK(connector_); @@ -191,14 +178,17 @@ void MultiDeviceNotificationPresenter::OnNotificationClicked( kNotificationTypeMax); switch (notification_status_) { case Status::kNewUserNotificationVisible: - open_ui_delegate_->OpenMultiDeviceSetupUi(); + Shell::Get()->system_tray_model()->client()->ShowMultiDeviceSetup(); break; case Status::kExistingUserHostSwitchedNotificationVisible: // Clicks on the 'host switched' and 'Chromebook added' notifications have // the same effect, i.e. opening the Settings subpage. FALLTHROUGH; case Status::kExistingUserNewChromebookNotificationVisible: - open_ui_delegate_->OpenConnectedDevicesSettings(); + Shell::Get() + ->system_tray_model() + ->client() + ->ShowConnectedDevicesSettings(); break; case Status::kNoNotificationVisible: NOTREACHED(); diff --git a/ash/multi_device_setup/multi_device_notification_presenter.h b/ash/multi_device_setup/multi_device_notification_presenter.h index 4d9571fdfefc92..77bc760b836616 100644 --- a/ash/multi_device_setup/multi_device_notification_presenter.h +++ b/ash/multi_device_setup/multi_device_notification_presenter.h @@ -84,16 +84,6 @@ class ASH_EXPORT MultiDeviceNotificationPresenter // MultiDevice setup notification ID. static const char kNotificationId[]; - // These methods are delegated to a nested class to make them easier to stub - // in unit tests. This way they can all be stubbed simultaneously by building - // a test delegate class deriving from OpenUiDelegate. - class OpenUiDelegate { - public: - virtual ~OpenUiDelegate(); - virtual void OpenMultiDeviceSetupUi(); - virtual void OpenConnectedDevicesSettings(); - }; - // Represents each possible MultiDevice setup notification that the setup flow // can show with a "none" option for the general state with no notification // present. @@ -141,7 +131,6 @@ class ASH_EXPORT MultiDeviceNotificationPresenter mojo::Binding binding_; - std::unique_ptr open_ui_delegate_; base::WeakPtrFactory weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(MultiDeviceNotificationPresenter); diff --git a/ash/multi_device_setup/multi_device_notification_presenter_unittest.cc b/ash/multi_device_setup/multi_device_notification_presenter_unittest.cc index 2cd617a834963e..b212a4492fed5d 100644 --- a/ash/multi_device_setup/multi_device_notification_presenter_unittest.cc +++ b/ash/multi_device_setup/multi_device_notification_presenter_unittest.cc @@ -8,10 +8,10 @@ #include #include +#include "ash/public/cpp/test/test_system_tray_client.h" #include "ash/session/test_session_controller_client.h" #include "ash/strings/grit/ash_strings.h" #include "ash/test/ash_test_base.h" -#include "ash/test/ash_test_helper.h" #include "base/bind.h" #include "base/logging.h" #include "base/memory/ptr_util.h" @@ -94,43 +94,12 @@ class TestMessageCenter : public message_center::FakeMessageCenter { class MultiDeviceNotificationPresenterTest : public NoSessionAshTestBase { public: - class TestOpenUiDelegate - : public MultiDeviceNotificationPresenter::OpenUiDelegate { - public: - TestOpenUiDelegate() = default; - ~TestOpenUiDelegate() override = default; - - int open_multi_device_setup_ui_count() const { - return open_multi_device_setup_ui_count_; - } - - int open_connected_devices_settings_count() const { - return open_connected_devices_settings_count_; - } - - // MultiDeviceNotificationPresenter::OpenUiDelegate: - void OpenMultiDeviceSetupUi() override { - ++open_multi_device_setup_ui_count_; - } - - void OpenConnectedDevicesSettings() override { - ++open_connected_devices_settings_count_; - } - - private: - int open_multi_device_setup_ui_count_ = 0; - int open_connected_devices_settings_count_ = 0; - }; - - protected: MultiDeviceNotificationPresenterTest() = default; void SetUp() override { NoSessionAshTestBase::SetUp(); - std::unique_ptr test_open_ui_delegate = - std::make_unique(); - test_open_ui_delegate_ = test_open_ui_delegate.get(); + test_system_tray_client_ = GetSystemTrayClient(); service_manager::mojom::ConnectorRequest request; connector_ = service_manager::Connector::Create(&request); @@ -150,8 +119,6 @@ class MultiDeviceNotificationPresenterTest : public NoSessionAshTestBase { notification_presenter_ = std::make_unique( &test_message_center_, connector_.get()); - notification_presenter_->open_ui_delegate_ = - std::move(test_open_ui_delegate); } void TearDown() override { @@ -271,7 +238,7 @@ class MultiDeviceNotificationPresenterTest : public NoSessionAshTestBase { } base::HistogramTester histogram_tester_; - TestOpenUiDelegate* test_open_ui_delegate_; + TestSystemTrayClient* test_system_tray_client_; TestMessageCenter test_message_center_; std::unique_ptr connector_; std::unique_ptr @@ -354,7 +321,7 @@ TEST_F(MultiDeviceNotificationPresenterTest, notification_presenter_->RemoveMultiDeviceSetupNotification(); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationClicked", 0); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationShown", 1); } @@ -369,7 +336,7 @@ TEST_F(MultiDeviceNotificationPresenterTest, ClickNotification(); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 1); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 1); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationClicked", 1); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationShown", 1); } @@ -384,7 +351,7 @@ TEST_F(MultiDeviceNotificationPresenterTest, DismissNotification(true /* by_user */); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationDismissed", 1); ShowNewUserNotification(); @@ -393,7 +360,7 @@ TEST_F(MultiDeviceNotificationPresenterTest, DismissNotification(false /* by_user */); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationDismissed", 1); } @@ -406,7 +373,7 @@ TEST_F(MultiDeviceNotificationPresenterTest, TestNoLongerNewUserEvent) { TriggerNoLongerNewUserEvent(); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationClicked", 0); AssertPotentialHostBucketCount("MultiDeviceSetup_NotificationShown", 1); } @@ -421,7 +388,8 @@ TEST_F(MultiDeviceNotificationPresenterTest, notification_presenter_->RemoveMultiDeviceSetupNotification(); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_connected_devices_settings_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_connected_devices_settings_count(), + 0); AssertHostSwitchedBucketCount("MultiDeviceSetup_NotificationClicked", 0); AssertHostSwitchedBucketCount("MultiDeviceSetup_NotificationShown", 1); } @@ -436,7 +404,8 @@ TEST_F(MultiDeviceNotificationPresenterTest, ClickNotification(); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_connected_devices_settings_count(), 1); + EXPECT_EQ(test_system_tray_client_->show_connected_devices_settings_count(), + 1); AssertHostSwitchedBucketCount("MultiDeviceSetup_NotificationClicked", 1); AssertHostSwitchedBucketCount("MultiDeviceSetup_NotificationShown", 1); } @@ -451,7 +420,7 @@ TEST_F(MultiDeviceNotificationPresenterTest, DismissNotification(true /* by_user */); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertHostSwitchedBucketCount("MultiDeviceSetup_NotificationDismissed", 1); ShowExistingUserHostSwitchedNotification(); @@ -460,7 +429,7 @@ TEST_F(MultiDeviceNotificationPresenterTest, DismissNotification(false /* by_user */); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertHostSwitchedBucketCount("MultiDeviceSetup_NotificationDismissed", 1); } @@ -475,7 +444,8 @@ TEST_F( notification_presenter_->RemoveMultiDeviceSetupNotification(); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_connected_devices_settings_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_connected_devices_settings_count(), + 0); AssertNewChromebookBucketCount("MultiDeviceSetup_NotificationClicked", 0); AssertNewChromebookBucketCount("MultiDeviceSetup_NotificationShown", 1); } @@ -490,7 +460,8 @@ TEST_F(MultiDeviceNotificationPresenterTest, ClickNotification(); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_connected_devices_settings_count(), 1); + EXPECT_EQ(test_system_tray_client_->show_connected_devices_settings_count(), + 1); AssertNewChromebookBucketCount("MultiDeviceSetup_NotificationClicked", 1); AssertNewChromebookBucketCount("MultiDeviceSetup_NotificationShown", 1); } @@ -506,7 +477,7 @@ TEST_F( DismissNotification(true /* by_user */); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertNewChromebookBucketCount("MultiDeviceSetup_NotificationDismissed", 1); ShowExistingUserNewChromebookNotification(); @@ -515,7 +486,7 @@ TEST_F( DismissNotification(false /* by_user */); VerifyNoNotificationIsVisible(); - EXPECT_EQ(test_open_ui_delegate_->open_multi_device_setup_ui_count(), 0); + EXPECT_EQ(test_system_tray_client_->show_multi_device_setup_count(), 0); AssertNewChromebookBucketCount("MultiDeviceSetup_NotificationDismissed", 1); } diff --git a/ash/public/cpp/BUILD.gn b/ash/public/cpp/BUILD.gn index ecf5389fa10b98..cd58ff410c0d5b 100644 --- a/ash/public/cpp/BUILD.gn +++ b/ash/public/cpp/BUILD.gn @@ -297,6 +297,8 @@ source_set("test_support") { "test/test_keyboard_controller_observer.h", "test/test_new_window_delegate.cc", "test/test_new_window_delegate.h", + "test/test_system_tray_client.cc", + "test/test_system_tray_client.h", ] deps = [ diff --git a/ash/public/cpp/system_tray_client.h b/ash/public/cpp/system_tray_client.h index 9d2bda34ba77a5..81692e1ae0670a 100644 --- a/ash/public/cpp/system_tray_client.h +++ b/ash/public/cpp/system_tray_client.h @@ -12,8 +12,6 @@ namespace ash { -class SystemTrayClient; - // Handles method calls delegated back to chrome from ash. class ASH_PUBLIC_EXPORT SystemTrayClient { public: diff --git a/ash/public/cpp/test/test_system_tray_client.cc b/ash/public/cpp/test/test_system_tray_client.cc new file mode 100644 index 00000000000000..e6d941d41fc03f --- /dev/null +++ b/ash/public/cpp/test/test_system_tray_client.cc @@ -0,0 +1,78 @@ +// Copyright 2019 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/public/cpp/test/test_system_tray_client.h" + +namespace ash { + +TestSystemTrayClient::TestSystemTrayClient() = default; + +TestSystemTrayClient::~TestSystemTrayClient() = default; + +void TestSystemTrayClient::ShowSettings() {} + +void TestSystemTrayClient::ShowBluetoothSettings() { + show_bluetooth_settings_count_++; +} + +void TestSystemTrayClient::ShowBluetoothPairingDialog( + const std::string& address, + const base::string16& name_for_display, + bool paired, + bool connected) {} + +void TestSystemTrayClient::ShowDateSettings() {} + +void TestSystemTrayClient::ShowSetTimeDialog() {} + +void TestSystemTrayClient::ShowDisplaySettings() {} + +void TestSystemTrayClient::ShowPowerSettings() {} + +void TestSystemTrayClient::ShowChromeSlow() {} + +void TestSystemTrayClient::ShowIMESettings() {} + +void TestSystemTrayClient::ShowConnectedDevicesSettings() { + show_connected_devices_settings_count_++; +} + +void TestSystemTrayClient::ShowAboutChromeOS() {} + +void TestSystemTrayClient::ShowHelp() {} + +void TestSystemTrayClient::ShowAccessibilityHelp() {} + +void TestSystemTrayClient::ShowAccessibilitySettings() {} + +void TestSystemTrayClient::ShowPaletteHelp() {} + +void TestSystemTrayClient::ShowPaletteSettings() {} + +void TestSystemTrayClient::ShowPublicAccountInfo() {} + +void TestSystemTrayClient::ShowEnterpriseInfo() {} + +void TestSystemTrayClient::ShowNetworkConfigure(const std::string& network_id) { +} + +void TestSystemTrayClient::ShowNetworkCreate(const std::string& type) {} + +void TestSystemTrayClient::ShowThirdPartyVpnCreate( + const std::string& extension_id) {} + +void TestSystemTrayClient::ShowArcVpnCreate(const std::string& app_id) {} + +void TestSystemTrayClient::ShowNetworkSettings(const std::string& network_id) {} + +void TestSystemTrayClient::ShowMultiDeviceSetup() { + show_multi_device_setup_count_++; +} + +void TestSystemTrayClient::RequestRestartForUpdate() {} + +void TestSystemTrayClient::SetLocaleAndExit( + const std::string& locale_iso_code) {} + +} // namespace ash diff --git a/ash/public/cpp/test/test_system_tray_client.h b/ash/public/cpp/test/test_system_tray_client.h new file mode 100644 index 00000000000000..6c1b9e21e17da2 --- /dev/null +++ b/ash/public/cpp/test/test_system_tray_client.h @@ -0,0 +1,71 @@ +// Copyright 2019 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_PUBLIC_CPP_TEST_TEST_SYSTEM_TRAY_CLIENT_H_ +#define ASH_PUBLIC_CPP_TEST_TEST_SYSTEM_TRAY_CLIENT_H_ + +#include "ash/public/cpp/ash_public_export.h" +#include "ash/public/cpp/system_tray_client.h" +#include "base/macros.h" + +namespace ash { + +// A SystemTrayClient that does nothing. Used by AshTestBase. +class ASH_PUBLIC_EXPORT TestSystemTrayClient : public SystemTrayClient { + public: + TestSystemTrayClient(); + ~TestSystemTrayClient() override; + + // SystemTrayClient: + void ShowSettings() override; + void ShowBluetoothSettings() override; + void ShowBluetoothPairingDialog(const std::string& address, + const base::string16& name_for_display, + bool paired, + bool connected) override; + void ShowDateSettings() override; + void ShowSetTimeDialog() override; + void ShowDisplaySettings() override; + void ShowPowerSettings() override; + void ShowChromeSlow() override; + void ShowIMESettings() override; + void ShowConnectedDevicesSettings() override; + void ShowAboutChromeOS() override; + void ShowHelp() override; + void ShowAccessibilityHelp() override; + void ShowAccessibilitySettings() override; + void ShowPaletteHelp() override; + void ShowPaletteSettings() override; + void ShowPublicAccountInfo() override; + void ShowEnterpriseInfo() override; + void ShowNetworkConfigure(const std::string& network_id) override; + void ShowNetworkCreate(const std::string& type) override; + void ShowThirdPartyVpnCreate(const std::string& extension_id) override; + void ShowArcVpnCreate(const std::string& app_id) override; + void ShowNetworkSettings(const std::string& network_id) override; + void ShowMultiDeviceSetup() override; + void RequestRestartForUpdate() override; + void SetLocaleAndExit(const std::string& locale_iso_code) override; + + int show_bluetooth_settings_count() const { + return show_bluetooth_settings_count_; + } + int show_multi_device_setup_count() const { + return show_multi_device_setup_count_; + } + int show_connected_devices_settings_count() const { + return show_connected_devices_settings_count_; + } + + private: + int show_bluetooth_settings_count_ = 0; + int show_multi_device_setup_count_ = 0; + int show_connected_devices_settings_count_ = 0; + + DISALLOW_COPY_AND_ASSIGN(TestSystemTrayClient); +}; + +} // namespace ash + +#endif // ASH_PUBLIC_CPP_TEST_TEST_SYSTEM_TRAY_CLIENT_H_ diff --git a/ash/system/bluetooth/bluetooth_notification_controller.cc b/ash/system/bluetooth/bluetooth_notification_controller.cc index f75372397bd00f..d9160b22d05fbb 100644 --- a/ash/system/bluetooth/bluetooth_notification_controller.cc +++ b/ash/system/bluetooth/bluetooth_notification_controller.cc @@ -137,36 +137,25 @@ const char class BluetoothNotificationController::BluetoothPairedNotificationDelegate : public message_center::NotificationDelegate { public: - explicit BluetoothPairedNotificationDelegate(OpenUiDelegate* open_delegate) - : open_delegate_(open_delegate) {} + BluetoothPairedNotificationDelegate() = default; protected: ~BluetoothPairedNotificationDelegate() override = default; + // message_center::NotificationDelegate: void Click(const base::Optional& button_index, - const base::Optional& reply) override; + const base::Optional& reply) override { + if (TrayPopupUtils::CanOpenWebUISettings()) + Shell::Get()->system_tray_model()->client()->ShowBluetoothSettings(); + } private: - OpenUiDelegate* open_delegate_; DISALLOW_COPY_AND_ASSIGN(BluetoothPairedNotificationDelegate); }; -void BluetoothNotificationController::BluetoothPairedNotificationDelegate:: - Click(const base::Optional& button_index, - const base::Optional& reply) { - if (TrayPopupUtils::CanOpenWebUISettings()) - open_delegate_->OpenBluetoothSettings(); -} - -void BluetoothNotificationController::OpenUiDelegate::OpenBluetoothSettings() { - Shell::Get()->system_tray_model()->client()->ShowBluetoothSettings(); -} - BluetoothNotificationController::BluetoothNotificationController( message_center::MessageCenter* message_center) - : open_delegate_(std::make_unique()), - message_center_(message_center), - weak_ptr_factory_(this) { + : message_center_(message_center), weak_ptr_factory_(this) { BluetoothAdapterFactory::GetAdapter( base::BindOnce(&BluetoothNotificationController::OnGetAdapter, weak_ptr_factory_.GetWeakPtr())); @@ -365,8 +354,7 @@ void BluetoothNotificationController::NotifyPairedDevice( message_center::NotifierId(message_center::NotifierType::SYSTEM_COMPONENT, kNotifierBluetooth), message_center::RichNotificationData(), - base::MakeRefCounted( - open_delegate_.get()), + base::MakeRefCounted(), kNotificationBluetoothIcon, message_center::SystemNotificationWarningLevel::NORMAL); message_center_->AddNotification(std::move(notification)); diff --git a/ash/system/bluetooth/bluetooth_notification_controller.h b/ash/system/bluetooth/bluetooth_notification_controller.h index 9a1aac9ff5d4c6..81accf4d857a89 100644 --- a/ash/system/bluetooth/bluetooth_notification_controller.h +++ b/ash/system/bluetooth/bluetooth_notification_controller.h @@ -62,14 +62,6 @@ class ASH_EXPORT BluetoothNotificationController friend class BluetoothNotificationControllerTest; class BluetoothPairedNotificationDelegate; - // Wraps calls to settings code which are mocked out for tests. - class OpenUiDelegate { - public: - OpenUiDelegate() = default; - virtual ~OpenUiDelegate() = default; - virtual void OpenBluetoothSettings(); - }; - static const char kBluetoothDeviceDiscoverableNotificationId[]; // Identifier for the pairing notification; the Bluetooth code ensures we // only receive one pairing request at a time, so a single id is sufficient @@ -98,8 +90,6 @@ class ASH_EXPORT BluetoothNotificationController // Clears any shown pairing notification now that the device has been paired. void NotifyPairedDevice(device::BluetoothDevice* device); - std::unique_ptr open_delegate_; - message_center::MessageCenter* const message_center_; // Reference to the underlying BluetoothAdapter object, holding this reference diff --git a/ash/system/bluetooth/bluetooth_notification_controller_unittest.cc b/ash/system/bluetooth/bluetooth_notification_controller_unittest.cc index 180c7f2ddd64e2..5f8304709c6932 100644 --- a/ash/system/bluetooth/bluetooth_notification_controller_unittest.cc +++ b/ash/system/bluetooth/bluetooth_notification_controller_unittest.cc @@ -7,11 +7,11 @@ #include #include +#include "ash/public/cpp/test/test_system_tray_client.h" #include "ash/session/test_session_controller_client.h" #include "ash/strings/grit/ash_strings.h" #include "ash/system/tray/tray_popup_utils.h" #include "ash/test/ash_test_base.h" -#include "ash/test/ash_test_helper.h" #include "base/containers/flat_map.h" #include "base/logging.h" #include "base/memory/ptr_util.h" @@ -47,27 +47,6 @@ class TestMessageCenter : public message_center::FakeMessageCenter { class BluetoothNotificationControllerTest : public AshTestBase { public: - class TestOpenUiDelegate - : public BluetoothNotificationController::OpenUiDelegate { - public: - TestOpenUiDelegate() = default; - ~TestOpenUiDelegate() override = default; - - size_t open_bluetooth_settings_ui_count() const { - return open_bluetooth_settings_ui_count_; - } - - void OpenBluetoothSettings() override { - ++open_bluetooth_settings_ui_count_; - } - - private: - size_t open_bluetooth_settings_ui_count_ = 0u; - - DISALLOW_COPY_AND_ASSIGN(TestOpenUiDelegate); - }; - - protected: BluetoothNotificationControllerTest() = default; void SetUp() override { @@ -75,9 +54,7 @@ class BluetoothNotificationControllerTest : public AshTestBase { notification_controller_ = std::make_unique( &test_message_center_); - auto open_delegate = std::make_unique(); - open_ui_delegate_ = open_delegate.get(); - notification_controller_->open_delegate_ = std::move(open_delegate); + system_tray_client_ = GetSystemTrayClient(); bluetooth_device_ = std::make_unique>( nullptr /* adapter */, 0 /* bluetooth_class */, "name", "address", @@ -126,7 +103,7 @@ class BluetoothNotificationControllerTest : public AshTestBase { TestMessageCenter test_message_center_; std::unique_ptr notification_controller_; - TestOpenUiDelegate* open_ui_delegate_; + TestSystemTrayClient* system_tray_client_; std::unique_ptr bluetooth_device_; DISALLOW_COPY_AND_ASSIGN(BluetoothNotificationControllerTest); @@ -146,7 +123,7 @@ TEST_F(BluetoothNotificationControllerTest, VerifyPairedNotificationIsVisible(bluetooth_device_.get()); // Check the notification controller tried to open the UI. - EXPECT_EQ(1u, open_ui_delegate_->open_bluetooth_settings_ui_count()); + EXPECT_EQ(1, system_tray_client_->show_bluetooth_settings_count()); } TEST_F(BluetoothNotificationControllerTest, @@ -160,7 +137,7 @@ TEST_F(BluetoothNotificationControllerTest, VerifyPairedNotificationIsNotVisible(); // The settings UI should not open when closing the notification. - EXPECT_EQ(0u, open_ui_delegate_->open_bluetooth_settings_ui_count()); + EXPECT_EQ(0, system_tray_client_->show_bluetooth_settings_count()); } TEST_F(BluetoothNotificationControllerTest, @@ -173,7 +150,7 @@ TEST_F(BluetoothNotificationControllerTest, DismissPairedNotification(false /* by_user */); VerifyPairedNotificationIsNotVisible(); - EXPECT_EQ(0u, open_ui_delegate_->open_bluetooth_settings_ui_count()); + EXPECT_EQ(0, system_tray_client_->show_bluetooth_settings_count()); } } // namespace ash diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index 5e3b9b7a0d1aca..d606c4496031fe 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -361,6 +361,10 @@ TestSessionControllerClient* AshTestBase::GetSessionControllerClient() { return ash_test_helper_->test_session_controller_client(); } +TestSystemTrayClient* AshTestBase::GetSystemTrayClient() { + return ash_test_helper_->system_tray_client(); +} + AppListTestHelper* AshTestBase::GetAppListTestHelper() { return ash_test_helper_->app_list_test_helper(); } diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index da1a195a1fbbe8..1a9a6763bf202e 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -67,6 +67,7 @@ class AppListTestHelper; class AshTestHelper; class Shelf; class TestScreenshotDelegate; +class TestSystemTrayClient; class UnifiedSystemTray; class WorkAreaInsets; @@ -194,6 +195,8 @@ class AshTestBase : public testing::Test { TestSessionControllerClient* GetSessionControllerClient(); + TestSystemTrayClient* GetSystemTrayClient(); + AppListTestHelper* GetAppListTestHelper(); // Emulates an ash session that have |session_count| user sessions running. diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc index c8c0c10453c46f..64ca13eaa680c6 100644 --- a/ash/test/ash_test_helper.cc +++ b/ash/test/ash_test_helper.cc @@ -19,10 +19,12 @@ #include "ash/public/cpp/ash_switches.h" #include "ash/public/cpp/test/test_keyboard_controller_observer.h" #include "ash/public/cpp/test/test_new_window_delegate.h" +#include "ash/public/cpp/test/test_system_tray_client.h" #include "ash/session/test_pref_service_provider.h" #include "ash/session/test_session_controller_client.h" #include "ash/shell.h" #include "ash/shell_init_params.h" +#include "ash/system/model/system_tray_model.h" #include "ash/system/screen_layout_observer.h" #include "ash/test/ash_test_views_delegate.h" #include "ash/test_shell_delegate.h" @@ -151,6 +153,9 @@ void AshTestHelper::SetUp(bool start_session, bool provide_local_state) { shell->session_controller(), prefs_provider_.get())); session_controller_client_->InitializeAndSetClient(); + system_tray_client_ = std::make_unique(); + shell->system_tray_model()->SetClient(system_tray_client_.get()); + if (start_session) session_controller_client_->CreatePredefinedUserSessions(1); diff --git a/ash/test/ash_test_helper.h b/ash/test/ash_test_helper.h index be17ffae493c09..aac29cdc391b04 100644 --- a/ash/test/ash_test_helper.h +++ b/ash/test/ash_test_helper.h @@ -47,6 +47,7 @@ class TestKeyboardControllerObserver; class TestNewWindowDelegate; class TestPrefServiceProvider; class TestShellDelegate; +class TestSystemTrayClient; // A helper class that does common initialization required for Ash. Creates a // root window and an ash::Shell instance with a test delegate. @@ -88,6 +89,9 @@ class AshTestHelper { std::unique_ptr session_controller_client) { session_controller_client_ = std::move(session_controller_client); } + TestSystemTrayClient* system_tray_client() { + return system_tray_client_.get(); + } TestPrefServiceProvider* prefs_provider() { return prefs_provider_.get(); } AppListTestHelper* app_list_test_helper() { @@ -118,6 +122,7 @@ class AshTestHelper { bool power_policy_controller_initialized_ = false; std::unique_ptr session_controller_client_; + std::unique_ptr system_tray_client_; std::unique_ptr prefs_provider_; std::unique_ptr context_factories_;