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 "chrome/browser/chromeos/net/network_state_notifier.h" | 5 #include "ui/chromeos/network/network_state_notifier.h" |
6 | |
7 #include <memory> | |
8 | 6 |
9 #include "base/macros.h" | 7 #include "base/macros.h" |
10 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
11 #include "chromeos/dbus/dbus_thread_manager.h" | 9 #include "chromeos/dbus/dbus_thread_manager.h" |
12 #include "chromeos/dbus/shill_device_client.h" | 10 #include "chromeos/dbus/shill_device_client.h" |
13 #include "chromeos/dbus/shill_service_client.h" | 11 #include "chromeos/dbus/shill_service_client.h" |
14 #include "chromeos/login/login_state.h" | 12 #include "chromeos/login/login_state.h" |
15 #include "chromeos/network/network_connect.h" | |
16 #include "chromeos/network/network_handler.h" | 13 #include "chromeos/network/network_handler.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 #include "ui/chromeos/network/network_connect.h" |
20 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
21 | 19 |
22 namespace chromeos { | 20 using chromeos::DBusThreadManager; |
| 21 using chromeos::ShillDeviceClient; |
| 22 using chromeos::ShillServiceClient; |
| 23 |
| 24 namespace ui { |
23 namespace test { | 25 namespace test { |
24 | 26 |
25 namespace { | |
26 | |
27 const char kWiFi1ServicePath[] = "/service/wifi1"; | |
28 const char kWiFi1Guid[] = "wifi1_guid"; | |
29 | |
30 } // namespace | |
31 | |
32 class NetworkConnectTestDelegate : public NetworkConnect::Delegate { | 27 class NetworkConnectTestDelegate : public NetworkConnect::Delegate { |
33 public: | 28 public: |
34 NetworkConnectTestDelegate() | 29 NetworkConnectTestDelegate() {} |
35 : network_state_notifier_(new NetworkStateNotifier()) {} | |
36 ~NetworkConnectTestDelegate() override {} | 30 ~NetworkConnectTestDelegate() override {} |
37 | 31 |
38 // NetworkConnect::Delegate | 32 // NetworkConnect::Delegate |
39 void ShowNetworkConfigure(const std::string& network_id) override {} | 33 void ShowNetworkConfigure(const std::string& network_id) override {} |
40 void ShowNetworkSettings(const std::string& network_id) override {} | 34 void ShowNetworkSettingsForGuid(const std::string& network_id) override {} |
41 bool ShowEnrollNetwork(const std::string& network_id) override { | 35 bool ShowEnrollNetwork(const std::string& network_id) override { |
42 return false; | 36 return false; |
43 } | 37 } |
44 void ShowMobileSimDialog() override {} | 38 void ShowMobileSimDialog() override {} |
45 void ShowMobileSetupDialog(const std::string& service_path) override {} | 39 void ShowMobileSetupDialog(const std::string& service_path) override {} |
46 void ShowNetworkConnectError(const std::string& error_name, | |
47 const std::string& network_id) override { | |
48 network_state_notifier_->ShowNetworkConnectError(error_name, network_id); | |
49 } | |
50 void ShowMobileActivationError(const std::string& network_id) override {} | |
51 | 40 |
52 private: | 41 private: |
53 std::unique_ptr<NetworkStateNotifier> network_state_notifier_; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); | 42 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); |
56 }; | 43 }; |
57 | 44 |
58 class NetworkStateNotifierTest : public testing::Test { | 45 class NetworkStateNotifierTest : public testing::Test { |
59 public: | 46 public: |
60 NetworkStateNotifierTest() {} | 47 NetworkStateNotifierTest() {} |
61 ~NetworkStateNotifierTest() override {} | 48 ~NetworkStateNotifierTest() override {} |
62 | 49 |
63 void SetUp() override { | 50 void SetUp() override { |
64 testing::Test::SetUp(); | 51 testing::Test::SetUp(); |
65 DBusThreadManager::Initialize(); | 52 DBusThreadManager::Initialize(); |
66 LoginState::Initialize(); | 53 chromeos::LoginState::Initialize(); |
67 SetupDefaultShillState(); | 54 SetupDefaultShillState(); |
68 NetworkHandler::Initialize(); | 55 chromeos::NetworkHandler::Initialize(); |
69 message_center::MessageCenter::Initialize(); | 56 message_center::MessageCenter::Initialize(); |
70 base::RunLoop().RunUntilIdle(); | 57 base::RunLoop().RunUntilIdle(); |
71 network_connect_delegate_.reset(new NetworkConnectTestDelegate); | 58 network_connect_delegate_.reset(new NetworkConnectTestDelegate); |
72 NetworkConnect::Initialize(network_connect_delegate_.get()); | 59 NetworkConnect::Initialize(network_connect_delegate_.get()); |
73 } | 60 } |
74 | 61 |
75 void TearDown() override { | 62 void TearDown() override { |
76 NetworkConnect::Shutdown(); | 63 NetworkConnect::Shutdown(); |
77 network_connect_delegate_.reset(); | 64 network_connect_delegate_.reset(); |
78 message_center::MessageCenter::Shutdown(); | 65 message_center::MessageCenter::Shutdown(); |
79 LoginState::Shutdown(); | 66 chromeos::LoginState::Shutdown(); |
80 NetworkHandler::Shutdown(); | 67 chromeos::NetworkHandler::Shutdown(); |
81 DBusThreadManager::Shutdown(); | 68 DBusThreadManager::Shutdown(); |
82 testing::Test::TearDown(); | 69 testing::Test::TearDown(); |
83 } | 70 } |
84 | 71 |
85 protected: | 72 protected: |
86 void SetupDefaultShillState() { | 73 void SetupDefaultShillState() { |
87 base::RunLoop().RunUntilIdle(); | 74 base::RunLoop().RunUntilIdle(); |
88 ShillDeviceClient::TestInterface* device_test = | 75 ShillDeviceClient::TestInterface* device_test = |
89 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 76 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
90 device_test->ClearDevices(); | 77 device_test->ClearDevices(); |
91 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi, | 78 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi, |
92 "stub_wifi_device1"); | 79 "stub_wifi_device1"); |
93 device_test->AddDevice("/device/stub_cellular_device1", | 80 device_test->AddDevice("/device/stub_cellular_device1", |
94 shill::kTypeCellular, "stub_cellular_device1"); | 81 shill::kTypeCellular, "stub_cellular_device1"); |
95 | 82 |
96 ShillServiceClient::TestInterface* service_test = | 83 ShillServiceClient::TestInterface* service_test = |
97 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 84 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
98 service_test->ClearServices(); | 85 service_test->ClearServices(); |
99 const bool add_to_visible = true; | 86 const bool add_to_visible = true; |
100 // Create a wifi network and set to online. | 87 // Create a wifi network and set to online. |
101 service_test->AddService(kWiFi1ServicePath, kWiFi1Guid, "wifi1", | 88 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1", |
102 shill::kTypeWifi, shill::kStateIdle, | 89 shill::kTypeWifi, shill::kStateIdle, |
103 add_to_visible); | 90 add_to_visible); |
104 service_test->SetServiceProperty(kWiFi1ServicePath, | 91 service_test->SetServiceProperty("wifi1", shill::kSecurityClassProperty, |
105 shill::kSecurityClassProperty, | |
106 base::StringValue(shill::kSecurityWep)); | 92 base::StringValue(shill::kSecurityWep)); |
107 service_test->SetServiceProperty(kWiFi1ServicePath, | 93 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty, |
108 shill::kConnectableProperty, | 94 base::Value(true)); |
109 base::FundamentalValue(true)); | 95 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty, |
110 service_test->SetServiceProperty(kWiFi1ServicePath, | |
111 shill::kPassphraseProperty, | |
112 base::StringValue("failure")); | 96 base::StringValue("failure")); |
113 base::RunLoop().RunUntilIdle(); | 97 base::RunLoop().RunUntilIdle(); |
114 } | 98 } |
115 | 99 |
116 std::unique_ptr<NetworkConnectTestDelegate> network_connect_delegate_; | 100 std::unique_ptr<NetworkConnectTestDelegate> network_connect_delegate_; |
117 base::MessageLoop message_loop_; | 101 base::MessageLoop message_loop_; |
118 | 102 |
119 private: | 103 private: |
120 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); | 104 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); |
121 }; | 105 }; |
122 | 106 |
123 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { | 107 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { |
124 NetworkConnect::Get()->ConnectToNetworkId(kWiFi1Guid); | 108 NetworkConnect::Get()->ConnectToNetwork("wifi1"); |
125 base::RunLoop().RunUntilIdle(); | 109 base::RunLoop().RunUntilIdle(); |
126 // Failure should spawn a notification. | 110 // Failure should spawn a notification. |
127 message_center::MessageCenter* message_center = | 111 message_center::MessageCenter* message_center = |
128 message_center::MessageCenter::Get(); | 112 message_center::MessageCenter::Get(); |
129 EXPECT_TRUE(message_center->FindVisibleNotificationById( | 113 EXPECT_TRUE(message_center->FindVisibleNotificationById( |
130 NetworkStateNotifier::kNetworkConnectNotificationId)); | 114 NetworkStateNotifier::kNetworkConnectNotificationId)); |
131 } | 115 } |
132 | 116 |
133 } // namespace test | 117 } // namespace test |
134 } // namespace chromeos | 118 } // namespace ui |
OLD | NEW |