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 "chromeos/network/network_state_handler.h" | 5 #include "chromeos/network/network_state_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 namespace chromeos { | 123 namespace chromeos { |
124 | 124 |
125 class NetworkStateHandlerTest : public testing::Test { | 125 class NetworkStateHandlerTest : public testing::Test { |
126 public: | 126 public: |
127 NetworkStateHandlerTest() {} | 127 NetworkStateHandlerTest() {} |
128 virtual ~NetworkStateHandlerTest() {} | 128 virtual ~NetworkStateHandlerTest() {} |
129 | 129 |
130 virtual void SetUp() OVERRIDE { | 130 virtual void SetUp() OVERRIDE { |
131 // Initialize DBusThreadManager with a stub implementation. | 131 // Initialize DBusThreadManager with a stub implementation. |
132 DBusThreadManager::InitializeWithStub(); | 132 DBusThreadManager::InitializeWithStub(); |
| 133 SetupNetworkStateHandler(); |
| 134 message_loop_.RunUntilIdle(); |
133 } | 135 } |
134 | 136 |
135 virtual void TearDown() OVERRIDE { | 137 virtual void TearDown() OVERRIDE { |
136 network_state_handler_.reset(); | 138 network_state_handler_.reset(); |
137 test_observer_.reset(); | 139 test_observer_.reset(); |
138 DBusThreadManager::Shutdown(); | 140 DBusThreadManager::Shutdown(); |
139 } | 141 } |
140 | 142 |
141 void SetupNetworkStateHandler() { | 143 void SetupNetworkStateHandler() { |
142 SetupDefaultShillState(); | 144 SetupDefaultShillState(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 183 |
182 MessageLoopForUI message_loop_; | 184 MessageLoopForUI message_loop_; |
183 scoped_ptr<NetworkStateHandler> network_state_handler_; | 185 scoped_ptr<NetworkStateHandler> network_state_handler_; |
184 scoped_ptr<TestObserver> test_observer_; | 186 scoped_ptr<TestObserver> test_observer_; |
185 | 187 |
186 private: | 188 private: |
187 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandlerTest); | 189 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandlerTest); |
188 }; | 190 }; |
189 | 191 |
190 TEST_F(NetworkStateHandlerTest, NetworkStateHandlerStub) { | 192 TEST_F(NetworkStateHandlerTest, NetworkStateHandlerStub) { |
191 SetupNetworkStateHandler(); | |
192 message_loop_.RunUntilIdle(); | |
193 EXPECT_EQ(1u, test_observer_->manager_changed_count()); | 193 EXPECT_EQ(1u, test_observer_->manager_changed_count()); |
194 // Ensure that the network list is the expected size. | 194 // Ensure that the network list is the expected size. |
195 const size_t kNumShillManagerClientStubImplServices = 4; | 195 const size_t kNumShillManagerClientStubImplServices = 4; |
196 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 196 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
197 test_observer_->network_count()); | 197 test_observer_->network_count()); |
198 // Ensure that the first stub network is the default network. | 198 // Ensure that the first stub network is the default network. |
199 EXPECT_EQ(kShillManagerClientStubDefaultService, | 199 EXPECT_EQ(kShillManagerClientStubDefaultService, |
200 test_observer_->default_network()); | 200 test_observer_->default_network()); |
201 EXPECT_EQ(kShillManagerClientStubDefaultService, | 201 EXPECT_EQ(kShillManagerClientStubDefaultService, |
202 network_state_handler_->ConnectedNetworkByType( | 202 network_state_handler_->ConnectedNetworkByType( |
203 NetworkStateHandler::kMatchTypeDefault)->path()); | 203 NetworkStateHandler::kMatchTypeDefault)->path()); |
204 EXPECT_EQ(kShillManagerClientStubDefaultService, | 204 EXPECT_EQ(kShillManagerClientStubDefaultService, |
205 network_state_handler_->ConnectedNetworkByType( | 205 network_state_handler_->ConnectedNetworkByType( |
206 flimflam::kTypeEthernet)->path()); | 206 flimflam::kTypeEthernet)->path()); |
207 EXPECT_EQ(kShillManagerClientStubDefaultWireless, | 207 EXPECT_EQ(kShillManagerClientStubDefaultWireless, |
208 network_state_handler_->ConnectedNetworkByType( | 208 network_state_handler_->ConnectedNetworkByType( |
209 NetworkStateHandler::kMatchTypeWireless)->path()); | 209 NetworkStateHandler::kMatchTypeWireless)->path()); |
210 EXPECT_EQ(flimflam::kStateOnline, | 210 EXPECT_EQ(flimflam::kStateOnline, |
211 test_observer_->default_network_connection_state()); | 211 test_observer_->default_network_connection_state()); |
212 } | 212 } |
213 | 213 |
214 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { | 214 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { |
215 SetupNetworkStateHandler(); | |
216 message_loop_.RunUntilIdle(); | |
217 EXPECT_EQ(1u, test_observer_->manager_changed_count()); | 215 EXPECT_EQ(1u, test_observer_->manager_changed_count()); |
218 // Enable a technology. | 216 // Enable a technology. |
219 EXPECT_NE(NetworkStateHandler::TECHNOLOGY_ENABLED, | 217 EXPECT_NE(NetworkStateHandler::TECHNOLOGY_ENABLED, |
220 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 218 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
221 network_state_handler_->SetTechnologyEnabled( | 219 network_state_handler_->SetTechnologyEnabled( |
222 flimflam::kTypeWimax, true, network_handler::ErrorCallback()); | 220 flimflam::kTypeWimax, true, network_handler::ErrorCallback()); |
223 // The technology state should immediately change to ENABLING and we should | 221 // The technology state should immediately change to ENABLING and we should |
224 // receive a manager changed callback. | 222 // receive a manager changed callback. |
225 EXPECT_EQ(2u, test_observer_->manager_changed_count()); | 223 EXPECT_EQ(2u, test_observer_->manager_changed_count()); |
226 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLING, | 224 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLING, |
227 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 225 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
228 message_loop_.RunUntilIdle(); | 226 message_loop_.RunUntilIdle(); |
229 // Ensure we receive another manager changed callbacks when the technology | 227 // Ensure we receive another manager changed callbacks when the technology |
230 // becomes enabled. | 228 // becomes enabled. |
231 EXPECT_EQ(3u, test_observer_->manager_changed_count()); | 229 EXPECT_EQ(3u, test_observer_->manager_changed_count()); |
232 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, | 230 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, |
233 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); | 231 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
234 } | 232 } |
235 | 233 |
| 234 TEST_F(NetworkStateHandlerTest, TechnologyState) { |
| 235 ShillManagerClient::TestInterface* manager_test = |
| 236 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); |
| 237 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, |
| 238 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
| 239 |
| 240 manager_test->AddTechnology(flimflam::kTypeWimax, false); |
| 241 message_loop_.RunUntilIdle(); |
| 242 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_AVAILABLE, |
| 243 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
| 244 |
| 245 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, true); |
| 246 message_loop_.RunUntilIdle(); |
| 247 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNINITIALIZED, |
| 248 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
| 249 |
| 250 manager_test->SetTechnologyInitializing(flimflam::kTypeWimax, false); |
| 251 network_state_handler_->SetTechnologyEnabled( |
| 252 flimflam::kTypeWimax, true, network_handler::ErrorCallback()); |
| 253 message_loop_.RunUntilIdle(); |
| 254 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, |
| 255 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
| 256 |
| 257 manager_test->RemoveTechnology(flimflam::kTypeWimax); |
| 258 message_loop_.RunUntilIdle(); |
| 259 EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, |
| 260 network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); |
| 261 } |
| 262 |
236 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { | 263 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { |
237 SetupNetworkStateHandler(); | |
238 message_loop_.RunUntilIdle(); | |
239 // Set a service property. | 264 // Set a service property. |
240 const std::string eth0 = "stub_ethernet"; | 265 const std::string eth0 = "stub_ethernet"; |
241 EXPECT_EQ("", network_state_handler_->GetNetworkState(eth0)->security()); | 266 EXPECT_EQ("", network_state_handler_->GetNetworkState(eth0)->security()); |
242 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth0)); | 267 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth0)); |
243 base::StringValue security_value("TestSecurity"); | 268 base::StringValue security_value("TestSecurity"); |
244 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 269 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
245 dbus::ObjectPath(eth0), | 270 dbus::ObjectPath(eth0), |
246 flimflam::kSecurityProperty, security_value, | 271 flimflam::kSecurityProperty, security_value, |
247 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 272 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
248 message_loop_.RunUntilIdle(); | 273 message_loop_.RunUntilIdle(); |
249 EXPECT_EQ("TestSecurity", | 274 EXPECT_EQ("TestSecurity", |
250 network_state_handler_->GetNetworkState(eth0)->security()); | 275 network_state_handler_->GetNetworkState(eth0)->security()); |
251 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth0)); | 276 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth0)); |
252 } | 277 } |
253 | 278 |
254 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { | 279 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { |
255 SetupNetworkStateHandler(); | |
256 message_loop_.RunUntilIdle(); | |
257 // Change a network state. | 280 // Change a network state. |
258 ShillServiceClient::TestInterface* service_test = | 281 ShillServiceClient::TestInterface* service_test = |
259 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 282 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
260 const std::string eth0 = "stub_ethernet"; | 283 const std::string eth0 = "stub_ethernet"; |
261 base::StringValue connection_state_idle_value(flimflam::kStateIdle); | 284 base::StringValue connection_state_idle_value(flimflam::kStateIdle); |
262 service_test->SetServiceProperty(eth0, flimflam::kStateProperty, | 285 service_test->SetServiceProperty(eth0, flimflam::kStateProperty, |
263 connection_state_idle_value); | 286 connection_state_idle_value); |
264 message_loop_.RunUntilIdle(); | 287 message_loop_.RunUntilIdle(); |
265 EXPECT_EQ(flimflam::kStateIdle, | 288 EXPECT_EQ(flimflam::kStateIdle, |
266 test_observer_->NetworkConnectionStateForService(eth0)); | 289 test_observer_->NetworkConnectionStateForService(eth0)); |
267 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth0)); | 290 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth0)); |
268 // Confirm that changing the connection state to the same value does *not* | 291 // Confirm that changing the connection state to the same value does *not* |
269 // signal the observer. | 292 // signal the observer. |
270 service_test->SetServiceProperty(eth0, flimflam::kStateProperty, | 293 service_test->SetServiceProperty(eth0, flimflam::kStateProperty, |
271 connection_state_idle_value); | 294 connection_state_idle_value); |
272 message_loop_.RunUntilIdle(); | 295 message_loop_.RunUntilIdle(); |
273 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth0)); | 296 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth0)); |
274 } | 297 } |
275 | 298 |
276 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { | 299 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { |
277 SetupNetworkStateHandler(); | |
278 message_loop_.RunUntilIdle(); | |
279 | |
280 ShillManagerClient::TestInterface* manager_test = | 300 ShillManagerClient::TestInterface* manager_test = |
281 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); | 301 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); |
282 ASSERT_TRUE(manager_test); | 302 ASSERT_TRUE(manager_test); |
283 ShillServiceClient::TestInterface* service_test = | 303 ShillServiceClient::TestInterface* service_test = |
284 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 304 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
285 ASSERT_TRUE(service_test); | 305 ASSERT_TRUE(service_test); |
286 | 306 |
287 // Change the default network by inserting wifi1 at the front of the list | 307 // Change the default network by inserting wifi1 at the front of the list |
288 // and changing the state of stub_ethernet to Idle. | 308 // and changing the state of stub_ethernet to Idle. |
289 const std::string wifi1 = "stub_wifi1"; | 309 const std::string wifi1 = "stub_wifi1"; |
(...skipping 22 matching lines...) Expand all Loading... |
312 // No default network updates for signal strength changes. | 332 // No default network updates for signal strength changes. |
313 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 333 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
314 dbus::ObjectPath(wifi1), | 334 dbus::ObjectPath(wifi1), |
315 flimflam::kSignalStrengthProperty, base::FundamentalValue(32), | 335 flimflam::kSignalStrengthProperty, base::FundamentalValue(32), |
316 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 336 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
317 message_loop_.RunUntilIdle(); | 337 message_loop_.RunUntilIdle(); |
318 EXPECT_EQ(3u, test_observer_->default_network_change_count()); | 338 EXPECT_EQ(3u, test_observer_->default_network_change_count()); |
319 } | 339 } |
320 | 340 |
321 } // namespace chromeos | 341 } // namespace chromeos |
OLD | NEW |