Chromium Code Reviews| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 } | 351 } |
| 352 | 352 |
| 353 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { | 353 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { |
| 354 ShillManagerClient::TestInterface* manager_test = | 354 ShillManagerClient::TestInterface* manager_test = |
| 355 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); | 355 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); |
| 356 ASSERT_TRUE(manager_test); | 356 ASSERT_TRUE(manager_test); |
| 357 ShillServiceClient::TestInterface* service_test = | 357 ShillServiceClient::TestInterface* service_test = |
| 358 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 358 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 359 ASSERT_TRUE(service_test); | 359 ASSERT_TRUE(service_test); |
| 360 | 360 |
| 361 // Change the default network by changing the state of eth1 to Idle which | |
| 362 // should re-sort Manager.Services. | |
| 363 const std::string eth1 = kShillManagerClientStubDefaultService; | 361 const std::string eth1 = kShillManagerClientStubDefaultService; |
| 362 // The default service should be eth1. There should have been one initial plus | |
| 363 // one additional default network change signal. | |
| 364 EXPECT_EQ(eth1, test_observer_->default_network()); | |
| 365 EXPECT_EQ(2u, test_observer_->default_network_change_count()); | |
| 366 | |
| 367 // Change the default network by changing Manager.DefaultService. | |
| 364 const std::string wifi1 = kShillManagerClientStubDefaultWireless; | 368 const std::string wifi1 = kShillManagerClientStubDefaultWireless; |
| 365 base::StringValue connection_state_idle_value(shill::kStateIdle); | 369 base::StringValue wifi1_value(wifi1); |
| 366 service_test->SetServiceProperty(eth1, shill::kStateProperty, | 370 manager_test->SetManagerProperty(shill::kDefaultServiceProperty, wifi1_value); |
| 367 connection_state_idle_value); | |
| 368 message_loop_.RunUntilIdle(); | 371 message_loop_.RunUntilIdle(); |
| 369 EXPECT_EQ(wifi1, test_observer_->default_network()); | 372 EXPECT_EQ(wifi1, test_observer_->default_network()); |
| 370 EXPECT_EQ(shill::kStateOnline, | 373 EXPECT_EQ(3u, test_observer_->default_network_change_count()); |
| 374 | |
| 375 // Change the state of the default network. | |
| 376 base::StringValue connection_state_ready_value(shill::kStateReady); | |
| 377 service_test->SetServiceProperty(wifi1, shill::kStateProperty, | |
| 378 connection_state_ready_value); | |
| 379 message_loop_.RunUntilIdle(); | |
| 380 EXPECT_EQ(shill::kStateReady, | |
| 371 test_observer_->default_network_connection_state()); | 381 test_observer_->default_network_connection_state()); |
| 372 // We should have seen 2 default network updates - for the default | 382 EXPECT_EQ(4u, test_observer_->default_network_change_count()); |
|
pneubeck (no reviews)
2014/02/24 09:22:58
nit: instead of counting indefinitely upwards, cou
stevenjb
2014/02/24 23:59:42
Done.
| |
| 373 // service change, and for the state change. | |
| 374 EXPECT_EQ(2u, test_observer_->default_network_change_count()); | |
| 375 | 383 |
| 376 // Updating a property on the default network should trigger | 384 // Updating a property on the default network should trigger |
| 377 // a default network change. | 385 // a default network change. |
| 378 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 386 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 379 dbus::ObjectPath(wifi1), | 387 dbus::ObjectPath(wifi1), |
| 380 shill::kSecurityProperty, base::StringValue("TestSecurity"), | 388 shill::kSecurityProperty, base::StringValue("TestSecurity"), |
| 381 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 389 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 382 message_loop_.RunUntilIdle(); | 390 message_loop_.RunUntilIdle(); |
| 383 EXPECT_EQ(3u, test_observer_->default_network_change_count()); | 391 EXPECT_EQ(5u, test_observer_->default_network_change_count()); |
| 384 | 392 |
| 385 // No default network updates for signal strength changes. | 393 // No default network updates for signal strength changes. |
| 386 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 394 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 387 dbus::ObjectPath(wifi1), | 395 dbus::ObjectPath(wifi1), |
| 388 shill::kSignalStrengthProperty, base::FundamentalValue(32), | 396 shill::kSignalStrengthProperty, base::FundamentalValue(32), |
| 389 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 397 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 390 message_loop_.RunUntilIdle(); | 398 message_loop_.RunUntilIdle(); |
| 391 EXPECT_EQ(3u, test_observer_->default_network_change_count()); | 399 EXPECT_EQ(5u, test_observer_->default_network_change_count()); |
| 392 } | 400 } |
| 393 | 401 |
| 394 TEST_F(NetworkStateHandlerTest, RequestUpdate) { | 402 TEST_F(NetworkStateHandlerTest, RequestUpdate) { |
| 395 // Request an update for kShillManagerClientStubDefaultWireless. | 403 // Request an update for kShillManagerClientStubDefaultWireless. |
| 396 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( | 404 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( |
| 397 kShillManagerClientStubDefaultWireless)); | 405 kShillManagerClientStubDefaultWireless)); |
| 398 network_state_handler_->RequestUpdateForNetwork( | 406 network_state_handler_->RequestUpdateForNetwork( |
| 399 kShillManagerClientStubDefaultWireless); | 407 kShillManagerClientStubDefaultWireless); |
| 400 message_loop_.RunUntilIdle(); | 408 message_loop_.RunUntilIdle(); |
| 401 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 409 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 402 kShillManagerClientStubDefaultWireless)); | 410 kShillManagerClientStubDefaultWireless)); |
| 403 | 411 |
| 404 // Request an update for all networks. | 412 // Request an update for all networks. |
| 405 network_state_handler_->RequestUpdateForAllNetworks(); | 413 network_state_handler_->RequestUpdateForAllNetworks(); |
| 406 message_loop_.RunUntilIdle(); | 414 message_loop_.RunUntilIdle(); |
| 407 // kShillManagerClientStubDefaultWireless should now have 3 updates | 415 // kShillManagerClientStubDefaultWireless should now have 3 updates |
| 408 EXPECT_EQ(3, test_observer_->PropertyUpdatesForService( | 416 EXPECT_EQ(3, test_observer_->PropertyUpdatesForService( |
| 409 kShillManagerClientStubDefaultWireless)); | 417 kShillManagerClientStubDefaultWireless)); |
| 410 // Other networks should have 2 updates (inital + request). | 418 // Other networks should have 2 updates (inital + request). |
| 411 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 419 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 412 kShillManagerClientStubDefaultService)); | 420 kShillManagerClientStubDefaultService)); |
| 413 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 421 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 414 kShillManagerClientStubWireless2)); | 422 kShillManagerClientStubWireless2)); |
| 415 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 423 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 416 kShillManagerClientStubCellular)); | 424 kShillManagerClientStubCellular)); |
| 417 } | 425 } |
| 418 | 426 |
| 419 } // namespace chromeos | 427 } // namespace chromeos |
| OLD | NEW |