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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "chromeos/dbus/shill_device_client.h" | 16 #include "chromeos/dbus/shill_device_client.h" |
17 #include "chromeos/dbus/shill_manager_client.h" | 17 #include "chromeos/dbus/shill_manager_client.h" |
18 #include "chromeos/dbus/shill_profile_client.h" | 18 #include "chromeos/dbus/shill_profile_client.h" |
19 #include "chromeos/dbus/shill_service_client.h" | 19 #include "chromeos/dbus/shill_service_client.h" |
20 #include "chromeos/network/favorite_state.h" | |
20 #include "chromeos/network/network_state.h" | 21 #include "chromeos/network/network_state.h" |
21 #include "chromeos/network/network_state_handler_observer.h" | 22 #include "chromeos/network/network_state_handler_observer.h" |
22 #include "chromeos/network/shill_property_util.h" | 23 #include "chromeos/network/shill_property_util.h" |
23 #include "dbus/object_path.h" | 24 #include "dbus/object_path.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 void ErrorCallbackFunction(const std::string& error_name, | 30 void ErrorCallbackFunction(const std::string& error_name, |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 add_to_visible, | 207 add_to_visible, |
207 add_to_watchlist); | 208 add_to_watchlist); |
208 service_test_->AddService(kShillManagerClientStubCellular, | 209 service_test_->AddService(kShillManagerClientStubCellular, |
209 kShillManagerClientStubCellular, | 210 kShillManagerClientStubCellular, |
210 shill::kTypeCellular, | 211 shill::kTypeCellular, |
211 shill::kStateIdle, | 212 shill::kStateIdle, |
212 add_to_visible, | 213 add_to_visible, |
213 add_to_watchlist); | 214 add_to_watchlist); |
214 } | 215 } |
215 | 216 |
217 void UpdateManagerProperties() { | |
218 message_loop_.RunUntilIdle(); | |
219 network_state_handler_->UpdateManagerProperties(); | |
220 message_loop_.RunUntilIdle(); | |
221 } | |
222 | |
216 base::MessageLoopForUI message_loop_; | 223 base::MessageLoopForUI message_loop_; |
217 scoped_ptr<NetworkStateHandler> network_state_handler_; | 224 scoped_ptr<NetworkStateHandler> network_state_handler_; |
218 scoped_ptr<TestObserver> test_observer_; | 225 scoped_ptr<TestObserver> test_observer_; |
219 ShillDeviceClient::TestInterface* device_test_; | 226 ShillDeviceClient::TestInterface* device_test_; |
220 ShillManagerClient::TestInterface* manager_test_; | 227 ShillManagerClient::TestInterface* manager_test_; |
221 ShillServiceClient::TestInterface* service_test_; | 228 ShillServiceClient::TestInterface* service_test_; |
222 | 229 |
223 private: | 230 private: |
224 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandlerTest); | 231 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandlerTest); |
225 }; | 232 }; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 message_loop_.RunUntilIdle(); | 349 message_loop_.RunUntilIdle(); |
343 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1)); | 350 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1)); |
344 } | 351 } |
345 | 352 |
346 TEST_F(NetworkStateHandlerTest, FavoriteState) { | 353 TEST_F(NetworkStateHandlerTest, FavoriteState) { |
347 // Set the profile entry of a service | 354 // Set the profile entry of a service |
348 const std::string wifi1 = kShillManagerClientStubDefaultWireless; | 355 const std::string wifi1 = kShillManagerClientStubDefaultWireless; |
349 ShillProfileClient::TestInterface* profile_test = | 356 ShillProfileClient::TestInterface* profile_test = |
350 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 357 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
351 EXPECT_TRUE(profile_test->AddService("/profile/default", wifi1)); | 358 EXPECT_TRUE(profile_test->AddService("/profile/default", wifi1)); |
352 message_loop_.RunUntilIdle(); | 359 UpdateManagerProperties(); |
353 network_state_handler_->UpdateManagerProperties(); | |
354 message_loop_.RunUntilIdle(); | |
355 EXPECT_EQ(1u, test_observer_->favorite_count()); | 360 EXPECT_EQ(1u, test_observer_->favorite_count()); |
356 } | 361 } |
357 | 362 |
358 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { | 363 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { |
359 // Change a network state. | 364 // Change a network state. |
360 const std::string eth1 = kShillManagerClientStubDefaultService; | 365 const std::string eth1 = kShillManagerClientStubDefaultService; |
361 base::StringValue connection_state_idle_value(shill::kStateIdle); | 366 base::StringValue connection_state_idle_value(shill::kStateIdle); |
362 service_test_->SetServiceProperty(eth1, shill::kStateProperty, | 367 service_test_->SetServiceProperty(eth1, shill::kStateProperty, |
363 connection_state_idle_value); | 368 connection_state_idle_value); |
364 message_loop_.RunUntilIdle(); | 369 message_loop_.RunUntilIdle(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 // Request an update for kShillManagerClientStubDefaultWireless. | 476 // Request an update for kShillManagerClientStubDefaultWireless. |
472 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( | 477 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( |
473 kShillManagerClientStubDefaultWireless)); | 478 kShillManagerClientStubDefaultWireless)); |
474 network_state_handler_->RequestUpdateForNetwork( | 479 network_state_handler_->RequestUpdateForNetwork( |
475 kShillManagerClientStubDefaultWireless); | 480 kShillManagerClientStubDefaultWireless); |
476 message_loop_.RunUntilIdle(); | 481 message_loop_.RunUntilIdle(); |
477 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 482 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
478 kShillManagerClientStubDefaultWireless)); | 483 kShillManagerClientStubDefaultWireless)); |
479 } | 484 } |
480 | 485 |
486 TEST_F(NetworkStateHandlerTest, NetworkGuid) { | |
pneubeck (no reviews)
2014/05/12 13:37:07
you need a second test that does more or less the
stevenjb
2014/05/13 01:19:00
Good point. I added the second test. The "InProfil
| |
487 // And a Favorite, ensure it has a GUID. | |
488 const std::string wifi_path = "wifi_with_guid"; | |
489 service_test_->AddService( | |
490 wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline, | |
491 true /* add_to_visible */, true /* add_to_watchlist */); | |
492 ShillProfileClient::TestInterface* profile_test = | |
pneubeck (no reviews)
2014/05/12 13:37:07
nit: better move this to the test class to make th
stevenjb
2014/05/13 01:19:00
Done.
| |
493 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | |
494 EXPECT_TRUE(profile_test->AddService("/profile/default", wifi_path)); | |
495 UpdateManagerProperties(); | |
496 // Verify that a FavoriteState existis with a valid GUID. | |
pneubeck (no reviews)
2014/05/12 13:37:07
existis -> exists
stevenjb
2014/05/13 01:19:00
Done.
| |
497 const FavoriteState* favorite = | |
498 network_state_handler_->GetFavoriteState(wifi_path); | |
pneubeck (no reviews)
2014/05/12 13:37:07
you could also test GetFavoriteStateFromGuid() her
stevenjb
2014/05/13 01:19:00
Added a GetState test
| |
499 ASSERT_TRUE(favorite); | |
500 std::string wifi_guid = favorite->guid(); | |
501 EXPECT_FALSE(wifi_guid.empty()); | |
502 // Verify that a NetworkState existis with the same GUID. | |
pneubeck (no reviews)
2014/05/12 13:37:07
existis -> exists
stevenjb
2014/05/13 01:19:00
Done.
| |
503 const NetworkState* network = | |
504 network_state_handler_->GetNetworkState(wifi_path); | |
505 ASSERT_TRUE(network); | |
506 EXPECT_EQ(wifi_guid, network->guid()); | |
507 // Remove the service, verify that there is no longer a NetworkState for it. | |
508 service_test_->RemoveService(wifi_path); | |
pneubeck (no reviews)
2014/05/12 13:37:07
I think you're not testing the right thing anymore
stevenjb
2014/05/13 01:19:00
ServiceClientTest::RemoveService does *NOT* remove
pneubeck (no reviews)
2014/05/13 08:43:54
In that case and if the profile isn't removed, sho
stevenjb
2014/05/13 18:25:07
Well, the Fake clients are just an approximation.
pneubeck (no reviews)
2014/05/14 08:46:06
so why the misleading 'out-of-range' comment that
| |
509 UpdateManagerProperties(); | |
510 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); | |
511 // Add the service and verify that a NetworkState exists with the same guid. | |
512 service_test_->AddService( | |
513 wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline, | |
514 true /* add_to_visible */, true /* add_to_watchlist */); | |
515 UpdateManagerProperties(); | |
516 network = network_state_handler_->GetNetworkState(wifi_path); | |
517 ASSERT_TRUE(network); | |
518 EXPECT_EQ(wifi_guid, network->guid()); | |
519 } | |
520 | |
481 } // namespace chromeos | 521 } // namespace chromeos |
OLD | NEW |