wifi_toggle_notification_controller_unittest.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/network/wifi_toggle_notification_controller.h"
  5. #include "ash/shell.h"
  6. #include "ash/system/model/system_tray_model.h"
  7. #include "ash/system/network/tray_network_state_model.h"
  8. #include "ash/system/tray/system_tray_notifier.h"
  9. #include "ash/test/ash_test_base.h"
  10. #include "base/run_loop.h"
  11. #include "chromeos/ash/components/dbus/shill/shill_clients.h"
  12. #include "chromeos/ash/components/network/network_handler.h"
  13. #include "chromeos/services/network_config/public/cpp/cros_network_config_test_helper.h"
  14. #include "components/prefs/testing_pref_service.h"
  15. #include "ui/base/l10n/l10n_util.h"
  16. #include "ui/message_center/message_center.h"
  17. using message_center::MessageCenter;
  18. namespace ash {
  19. class WifiToggleNotificationControllerTest : public AshTestBase {
  20. public:
  21. WifiToggleNotificationControllerTest() = default;
  22. WifiToggleNotificationControllerTest(
  23. const WifiToggleNotificationControllerTest&) = delete;
  24. WifiToggleNotificationControllerTest& operator=(
  25. const WifiToggleNotificationControllerTest&) = delete;
  26. ~WifiToggleNotificationControllerTest() override = default;
  27. // testing::Test:
  28. void SetUp() override {
  29. AshTestBase::SetUp();
  30. // NOTE: This is necessary to give the TrayNetworkStateModel a chance to
  31. // sync its list of network devices.
  32. base::RunLoop().RunUntilIdle();
  33. }
  34. private:
  35. chromeos::network_config::CrosNetworkConfigTestHelper network_config_helper_;
  36. TestingPrefServiceSimple profile_prefs_;
  37. TestingPrefServiceSimple local_state_;
  38. };
  39. // Verifies that toggling Wi-Fi (usually via keyboard) shows a notification.
  40. TEST_F(WifiToggleNotificationControllerTest, ToggleWifi) {
  41. // No notifications at startup.
  42. ASSERT_EQ(0u, MessageCenter::Get()->NotificationCount());
  43. // Simulate a user action to toggle Wi-Fi.
  44. Shell::Get()->system_tray_notifier()->NotifyRequestToggleWifi();
  45. // Notification was shown.
  46. EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount());
  47. EXPECT_TRUE(MessageCenter::Get()->HasPopupNotifications());
  48. EXPECT_TRUE(MessageCenter::Get()->FindVisibleNotificationById("wifi-toggle"));
  49. }
  50. } // namespace ash