OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/network/network_state_notifier.h" | 5 #include "ui/chromeos/network/network_state_notifier.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "base/run_loop.h" |
8 #include "ash/shelf/shelf_widget.h" | |
9 #include "ash/shell.h" | |
10 #include "ash/system/chromeos/network/network_connect.h" | |
11 #include "ash/system/status_area_widget.h" | |
12 #include "ash/system/tray/system_tray.h" | |
13 #include "ash/test/ash_test_base.h" | |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/shill_device_client.h" | 9 #include "chromeos/dbus/shill_device_client.h" |
16 #include "chromeos/dbus/shill_service_client.h" | 10 #include "chromeos/dbus/shill_service_client.h" |
17 #include "chromeos/login/login_state.h" | 11 #include "chromeos/login/login_state.h" |
18 #include "chromeos/network/network_handler.h" | 12 #include "chromeos/network/network_handler.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 #include "ui/chromeos/network/network_connect.h" |
20 #include "ui/message_center/message_center.h" | 17 #include "ui/message_center/message_center.h" |
21 | 18 |
22 namespace { | |
23 | |
24 ash::SystemTray* GetSystemTray() { | |
25 return ash::Shell::GetPrimaryRootWindowController() | |
26 ->shelf() | |
27 ->status_area_widget() | |
28 ->system_tray(); | |
29 } | |
30 | |
31 } // namespace | |
32 | |
33 using chromeos::DBusThreadManager; | 19 using chromeos::DBusThreadManager; |
34 using chromeos::ShillDeviceClient; | 20 using chromeos::ShillDeviceClient; |
35 using chromeos::ShillServiceClient; | 21 using chromeos::ShillServiceClient; |
36 | 22 |
37 namespace ash { | 23 namespace ui { |
38 namespace test { | 24 namespace test { |
39 | 25 |
40 class NetworkConnectTestDelegate : public NetworkConnect::Delegate { | 26 class NetworkConnectTestDelegate : public NetworkConnect::Delegate { |
41 public: | 27 public: |
42 NetworkConnectTestDelegate() {} | 28 NetworkConnectTestDelegate() {} |
43 ~NetworkConnectTestDelegate() override {} | 29 ~NetworkConnectTestDelegate() override {} |
44 | 30 |
45 // NetworkConnect::Delegate | 31 // NetworkConnect::Delegate |
46 void ShowNetworkConfigure(const std::string& network_id) override {} | 32 void ShowNetworkConfigure(const std::string& network_id) override {} |
47 void ShowNetworkSettings(const std::string& network_id) override {} | 33 void ShowNetworkSettings(const std::string& network_id) override {} |
48 bool ShowEnrollNetwork(const std::string& network_id) override { | 34 bool ShowEnrollNetwork(const std::string& network_id) override { |
49 return false; | 35 return false; |
50 } | 36 } |
51 void ShowMobileSimDialog() override {} | 37 void ShowMobileSimDialog() override {} |
52 void ShowMobileSetupDialog(const std::string& service_path) override {} | 38 void ShowMobileSetupDialog(const std::string& service_path) override {} |
53 | 39 |
54 private: | 40 private: |
55 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); | 41 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); |
56 }; | 42 }; |
57 | 43 |
58 class NetworkStateNotifierTest : public AshTestBase { | 44 class NetworkStateNotifierTest : public testing::Test { |
59 public: | 45 public: |
60 NetworkStateNotifierTest() {} | 46 NetworkStateNotifierTest() {} |
61 ~NetworkStateNotifierTest() override {} | 47 ~NetworkStateNotifierTest() override {} |
62 | 48 |
63 void SetUp() override { | 49 void SetUp() override { |
| 50 testing::Test::SetUp(); |
64 DBusThreadManager::Initialize(); | 51 DBusThreadManager::Initialize(); |
65 chromeos::LoginState::Initialize(); | 52 chromeos::LoginState::Initialize(); |
66 SetupDefaultShillState(); | 53 SetupDefaultShillState(); |
67 chromeos::NetworkHandler::Initialize(); | 54 chromeos::NetworkHandler::Initialize(); |
68 RunAllPendingInMessageLoop(); | 55 message_center::MessageCenter::Initialize(); |
69 AshTestBase::SetUp(); | 56 base::RunLoop().RunUntilIdle(); |
70 network_connect_delegate_.reset(new NetworkConnectTestDelegate); | 57 network_connect_delegate_.reset(new NetworkConnectTestDelegate); |
71 NetworkConnect::Initialize(network_connect_delegate_.get()); | 58 NetworkConnect::Initialize(network_connect_delegate_.get()); |
72 } | 59 } |
73 | 60 |
74 void TearDown() override { | 61 void TearDown() override { |
75 NetworkConnect::Shutdown(); | 62 NetworkConnect::Shutdown(); |
76 network_connect_delegate_.reset(); | 63 network_connect_delegate_.reset(); |
77 AshTestBase::TearDown(); | 64 message_center::MessageCenter::Shutdown(); |
78 chromeos::LoginState::Shutdown(); | 65 chromeos::LoginState::Shutdown(); |
79 chromeos::NetworkHandler::Shutdown(); | 66 chromeos::NetworkHandler::Shutdown(); |
80 DBusThreadManager::Shutdown(); | 67 DBusThreadManager::Shutdown(); |
| 68 testing::Test::TearDown(); |
81 } | 69 } |
82 | 70 |
83 protected: | 71 protected: |
84 void SetupDefaultShillState() { | 72 void SetupDefaultShillState() { |
85 RunAllPendingInMessageLoop(); | 73 base::RunLoop().RunUntilIdle(); |
86 ShillDeviceClient::TestInterface* device_test = | 74 ShillDeviceClient::TestInterface* device_test = |
87 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 75 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
88 device_test->ClearDevices(); | 76 device_test->ClearDevices(); |
89 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi, | 77 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi, |
90 "stub_wifi_device1"); | 78 "stub_wifi_device1"); |
91 device_test->AddDevice("/device/stub_cellular_device1", | 79 device_test->AddDevice("/device/stub_cellular_device1", |
92 shill::kTypeCellular, "stub_cellular_device1"); | 80 shill::kTypeCellular, "stub_cellular_device1"); |
93 | 81 |
94 ShillServiceClient::TestInterface* service_test = | 82 ShillServiceClient::TestInterface* service_test = |
95 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 83 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
96 service_test->ClearServices(); | 84 service_test->ClearServices(); |
97 const bool add_to_visible = true; | 85 const bool add_to_visible = true; |
98 // Create a wifi network and set to online. | 86 // Create a wifi network and set to online. |
99 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1", | 87 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1", |
100 shill::kTypeWifi, shill::kStateIdle, | 88 shill::kTypeWifi, shill::kStateIdle, |
101 add_to_visible); | 89 add_to_visible); |
102 service_test->SetServiceProperty("wifi1", shill::kSecurityProperty, | 90 service_test->SetServiceProperty("wifi1", shill::kSecurityProperty, |
103 base::StringValue(shill::kSecurityWep)); | 91 base::StringValue(shill::kSecurityWep)); |
104 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty, | 92 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty, |
105 base::FundamentalValue(true)); | 93 base::FundamentalValue(true)); |
106 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty, | 94 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty, |
107 base::StringValue("failure")); | 95 base::StringValue("failure")); |
108 RunAllPendingInMessageLoop(); | 96 base::RunLoop().RunUntilIdle(); |
109 } | 97 } |
110 | 98 |
111 scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_; | 99 scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_; |
| 100 base::MessageLoop message_loop_; |
112 | 101 |
113 private: | 102 private: |
114 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); | 103 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); |
115 }; | 104 }; |
116 | 105 |
117 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { | 106 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { |
118 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); | |
119 NetworkConnect::Get()->ConnectToNetwork("wifi1"); | 107 NetworkConnect::Get()->ConnectToNetwork("wifi1"); |
120 RunAllPendingInMessageLoop(); | 108 base::RunLoop().RunUntilIdle(); |
121 // Failure should spawn a notification. | 109 // Failure should spawn a notification. |
122 message_center::MessageCenter* message_center = | 110 message_center::MessageCenter* message_center = |
123 message_center::MessageCenter::Get(); | 111 message_center::MessageCenter::Get(); |
124 EXPECT_TRUE(message_center->FindVisibleNotificationById( | 112 EXPECT_TRUE(message_center->FindVisibleNotificationById( |
125 NetworkStateNotifier::kNetworkConnectNotificationId)); | 113 NetworkStateNotifier::kNetworkConnectNotificationId)); |
126 } | 114 } |
127 | 115 |
128 } // namespace test | 116 } // namespace test |
129 } // namespace ash | 117 } // namespace ui |
OLD | NEW |