Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 | |
| 5 #include "ash/system/network/tray_network.h" | |
| 6 | |
| 7 #include "ash/login_status.h" | |
| 8 #include "ash/system/network/network_state_list_detailed_view.h" | |
| 9 #include "ash/system/tray/system_tray.h" | |
| 10 #include "ash/test/ash_test_base.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 13 #include "chromeos/network/network_handler.h" | |
| 14 #include "components/prefs/testing_pref_service.h" | |
| 15 #include "ui/message_center/message_center.h" | |
| 16 | |
| 17 using message_center::MessageCenter; | |
| 18 | |
| 19 namespace ash { | |
| 20 namespace { | |
| 21 | |
| 22 class TrayNetworkTest : public test::AshTestBase { | |
|
stevenjb
2017/05/03 22:11:40
Tests, hooray!
| |
| 23 public: | |
| 24 TrayNetworkTest() = default; | |
| 25 ~TrayNetworkTest() override = default; | |
| 26 | |
| 27 // testing::Test: | |
| 28 void SetUp() override { | |
| 29 chromeos::DBusThreadManager::Initialize(); | |
| 30 // Initializing NetworkHandler before ash is more like production. | |
| 31 chromeos::NetworkHandler::Initialize(); | |
| 32 test::AshTestBase::SetUp(); | |
| 33 chromeos::NetworkHandler::Get()->InitializePrefServices(&profile_prefs_, | |
| 34 &local_state_); | |
| 35 // Networking stubs may have asynchronous initialization. | |
| 36 RunAllPendingInMessageLoop(); | |
| 37 } | |
| 38 | |
| 39 void TearDown() override { | |
| 40 // This roughly matches production shutdown order. | |
| 41 chromeos::NetworkHandler::Get()->ShutdownPrefServices(); | |
| 42 test::AshTestBase::TearDown(); | |
| 43 chromeos::NetworkHandler::Shutdown(); | |
| 44 chromeos::DBusThreadManager::Shutdown(); | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 TestingPrefServiceSimple profile_prefs_; | |
| 49 TestingPrefServiceSimple local_state_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(TrayNetworkTest); | |
| 52 }; | |
| 53 | |
| 54 // Verifies that the network views can be created. | |
| 55 TEST_F(TrayNetworkTest, Basics) { | |
| 56 // Open the system tray menu. | |
| 57 SystemTray* system_tray = GetPrimarySystemTray(); | |
| 58 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 59 RunAllPendingInMessageLoop(); | |
| 60 | |
| 61 // Show network details. | |
| 62 TrayNetwork* tray_network = system_tray->GetTrayNetworkForTesting(); | |
| 63 const int close_delay_in_seconds = 0; | |
| 64 bool activate = true; | |
| 65 system_tray->ShowDetailedView(tray_network, close_delay_in_seconds, activate, | |
| 66 BUBBLE_USE_EXISTING); | |
| 67 RunAllPendingInMessageLoop(); | |
| 68 | |
| 69 // Network details view was created. | |
| 70 ASSERT_TRUE(tray_network->detailed()); | |
| 71 EXPECT_TRUE(tray_network->detailed()->visible()); | |
| 72 } | |
| 73 | |
| 74 // Verifies that toggling Wi-Fi (usually via keyboard) shows a notification. | |
| 75 TEST_F(TrayNetworkTest, ToggleWifi) { | |
| 76 TrayNetwork* tray_network = | |
| 77 GetPrimarySystemTray()->GetTrayNetworkForTesting(); | |
| 78 | |
| 79 // No notifications at startup. | |
| 80 ASSERT_EQ(0u, MessageCenter::Get()->NotificationCount()); | |
| 81 | |
| 82 // Simulate a user action to toggle Wi-Fi. | |
| 83 tray_network->RequestToggleWifi(); | |
| 84 | |
| 85 // Notification was shown. | |
| 86 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); | |
| 87 EXPECT_TRUE(MessageCenter::Get()->HasPopupNotifications()); | |
| 88 EXPECT_TRUE(MessageCenter::Get()->FindVisibleNotificationById("wifi-toggle")); | |
| 89 } | |
| 90 | |
| 91 } // namespace | |
| 92 } // namespace ash | |
| OLD | NEW |