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 |
| 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 TEST_F(NetworkStateHandlerTest, FavoriteState) { | 361 TEST_F(NetworkStateHandlerTest, FavoriteState) { |
| 361 // Set the profile entry of a service | 362 // Set the profile entry of a service |
| 362 const std::string profile = "/profile/profile1"; | 363 const std::string profile = "/profile/profile1"; |
| 363 const std::string wifi1 = kShillManagerClientStubDefaultWifi; | 364 const std::string wifi1 = kShillManagerClientStubDefaultWifi; |
| 364 profile_test_->AddProfile(profile, "" /* userhash */); | 365 profile_test_->AddProfile(profile, "" /* userhash */); |
| 365 EXPECT_TRUE(profile_test_->AddService(profile, wifi1)); | 366 EXPECT_TRUE(profile_test_->AddService(profile, wifi1)); |
| 366 UpdateManagerProperties(); | 367 UpdateManagerProperties(); |
| 367 EXPECT_EQ(1u, test_observer_->favorite_count()); | 368 EXPECT_EQ(1u, test_observer_->favorite_count()); |
| 368 } | 369 } |
| 369 | 370 |
| 371 TEST_F(NetworkStateHandlerTest, GetState) { | |
| 372 const std::string profile = "/profile/profile1"; | |
| 373 profile_test_->AddProfile(profile, "" /* userhash */); | |
| 374 base::StringValue profile_value(profile); | |
| 375 EXPECT_TRUE(service_test_->SetServiceProperty( | |
| 376 kShillManagerClientStubWifi2, shill::kProfileProperty, profile_value)); | |
| 377 UpdateManagerProperties(); | |
| 378 | |
| 379 const NetworkState* wifi_network = | |
| 380 network_state_handler_->GetNetworkState(kShillManagerClientStubWifi2); | |
| 381 ASSERT_TRUE(wifi_network); | |
| 382 const FavoriteState* wifi_favorite = | |
| 383 network_state_handler_->GetFavoriteStateFromServicePath( | |
| 384 kShillManagerClientStubWifi2, true /* configured_only */); | |
| 385 ASSERT_TRUE(wifi_favorite); | |
| 386 EXPECT_EQ(wifi_network->path(), wifi_favorite->path()); | |
| 387 ASSERT_FALSE(wifi_favorite->guid().empty()); | |
| 388 const FavoriteState* wifi_favorite_guid = | |
| 389 network_state_handler_->GetFavoriteStateFromGuid(wifi_favorite->guid()); | |
| 390 EXPECT_EQ(wifi_favorite, wifi_favorite_guid); | |
| 391 } | |
| 392 | |
| 370 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { | 393 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { |
| 371 // Change a network state. | 394 // Change a network state. |
| 372 const std::string eth1 = kShillManagerClientStubDefaultService; | 395 const std::string eth1 = kShillManagerClientStubDefaultService; |
| 373 base::StringValue connection_state_idle_value(shill::kStateIdle); | 396 base::StringValue connection_state_idle_value(shill::kStateIdle); |
| 374 service_test_->SetServiceProperty(eth1, shill::kStateProperty, | 397 service_test_->SetServiceProperty(eth1, shill::kStateProperty, |
| 375 connection_state_idle_value); | 398 connection_state_idle_value); |
| 376 message_loop_.RunUntilIdle(); | 399 message_loop_.RunUntilIdle(); |
| 377 EXPECT_EQ(shill::kStateIdle, | 400 EXPECT_EQ(shill::kStateIdle, |
| 378 test_observer_->NetworkConnectionStateForService(eth1)); | 401 test_observer_->NetworkConnectionStateForService(eth1)); |
| 379 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); | 402 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 TEST_F(NetworkStateHandlerTest, RequestUpdate) { | 505 TEST_F(NetworkStateHandlerTest, RequestUpdate) { |
| 483 // Request an update for kShillManagerClientStubDefaultWifi. | 506 // Request an update for kShillManagerClientStubDefaultWifi. |
| 484 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( | 507 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( |
| 485 kShillManagerClientStubDefaultWifi)); | 508 kShillManagerClientStubDefaultWifi)); |
| 486 network_state_handler_->RequestUpdateForNetwork( | 509 network_state_handler_->RequestUpdateForNetwork( |
| 487 kShillManagerClientStubDefaultWifi); | 510 kShillManagerClientStubDefaultWifi); |
| 488 message_loop_.RunUntilIdle(); | 511 message_loop_.RunUntilIdle(); |
| 489 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( | 512 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( |
| 490 kShillManagerClientStubDefaultWifi)); | 513 kShillManagerClientStubDefaultWifi)); |
| 491 } | 514 } |
| 515 | |
| 516 TEST_F(NetworkStateHandlerTest, NetworkGuidInProfile) { | |
| 517 // And a network to the default Profile. | |
| 518 const std::string profile = "/profile/profile1"; | |
| 519 const std::string wifi_path = "wifi_with_guid"; | |
| 520 const std::string wifi_guid = "WIFI_GUID"; | |
| 521 const bool is_service_configured = true; | |
| 522 | |
| 523 service_test_->AddServiceWithIPConfig( | |
| 524 wifi_path, wifi_guid, wifi_path /* name */, | |
| 525 shill::kTypeWifi, shill::kStateOnline, "" /* ipconfig_path */, | |
| 526 true /* add_to_visible */, true /* add_to_watchlist */); | |
| 527 profile_test_->AddProfile(profile, "" /* userhash */); | |
| 528 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); | |
| 529 UpdateManagerProperties(); | |
|
pneubeck (no reviews)
2014/05/13 08:43:54
Just to restate what's going on here (for my own c
stevenjb
2014/05/13 18:25:07
I'll add comments and break these each into two te
| |
| 530 | |
| 531 // Verify that a FavoriteState exists with a valid GUID. | |
| 532 const FavoriteState* favorite = | |
| 533 network_state_handler_->GetFavoriteStateFromServicePath( | |
| 534 wifi_path, is_service_configured); | |
| 535 ASSERT_TRUE(favorite); | |
| 536 EXPECT_EQ(wifi_guid, favorite->guid()); | |
| 537 // Verify that a NetworkState exists with the same GUID. | |
| 538 const NetworkState* network = | |
| 539 network_state_handler_->GetNetworkState(wifi_path); | |
| 540 ASSERT_TRUE(network); | |
| 541 EXPECT_EQ(wifi_guid, network->guid()); | |
| 542 | |
| 543 // Remove the service, verify that there is no longer a NetworkState or | |
| 544 // FavoriteState for it. | |
| 545 service_test_->RemoveService(wifi_path); | |
|
pneubeck (no reviews)
2014/05/13 08:43:54
the service is completely disappearing as if the p
| |
| 546 UpdateManagerProperties(); | |
| 547 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); | |
| 548 EXPECT_FALSE(network_state_handler_->GetFavoriteStateFromServicePath( | |
|
pneubeck (no reviews)
2014/05/13 08:43:54
this verifies unrelated to GUID that the network/f
| |
| 549 wifi_path, false /* configured_only */)); | |
| 550 | |
| 551 // Add the service and verify that a FavorteState exists with the same guid. | |
|
pneubeck (no reviews)
2014/05/13 08:43:54
instead of relying on the FakeShillProfileClient t
stevenjb
2014/05/13 18:25:07
I have intentionally avoided adding fake behavior
pneubeck (no reviews)
2014/05/14 08:46:07
Sure, I didn't want to imply that.
What I meant i
| |
| 552 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | |
|
pneubeck (no reviews)
2014/05/13 08:43:54
this makes the service appear again (like a Profil
| |
| 553 UpdateManagerProperties(); | |
| 554 favorite = network_state_handler_->GetFavoriteStateFromServicePath( | |
| 555 wifi_path, is_service_configured); | |
| 556 ASSERT_TRUE(favorite); | |
| 557 EXPECT_EQ(wifi_guid, favorite->guid()); | |
| 558 // Verify that a NetworkState exists with the same GUID. | |
| 559 network = network_state_handler_->GetNetworkState(wifi_path); | |
| 560 ASSERT_TRUE(network); | |
| 561 EXPECT_EQ(wifi_guid, network->guid()); | |
| 562 } | |
| 563 | |
| 564 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) { | |
| 565 // And a network but do not save it to a profile. | |
| 566 const std::string wifi_path = "wifi_with_guid"; | |
| 567 const bool is_service_configured = false; | |
| 568 | |
| 569 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | |
| 570 UpdateManagerProperties(); | |
| 571 | |
| 572 // Verify that a FavoriteState exists with an assigned GUID. | |
| 573 const FavoriteState* favorite = | |
| 574 network_state_handler_->GetFavoriteStateFromServicePath( | |
| 575 wifi_path, is_service_configured); | |
| 576 ASSERT_TRUE(favorite); | |
| 577 std::string wifi_guid = favorite->guid(); | |
| 578 EXPECT_FALSE(wifi_guid.empty()); | |
| 579 // Verify that a NetworkState exists with the same GUID. | |
| 580 const NetworkState* network = | |
| 581 network_state_handler_->GetNetworkState(wifi_path); | |
| 582 ASSERT_TRUE(network); | |
| 583 EXPECT_EQ(wifi_guid, network->guid()); | |
| 584 | |
| 585 // Remove the service, verify that there is no longer a NetworkState or | |
| 586 // FavoriteState for it. | |
| 587 service_test_->RemoveService(wifi_path); | |
| 588 UpdateManagerProperties(); | |
| 589 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); | |
|
pneubeck (no reviews)
2014/05/13 08:43:54
as in the previous test, this is unrelated an shou
| |
| 590 EXPECT_FALSE(network_state_handler_->GetFavoriteStateFromServicePath( | |
| 591 wifi_path, false /* configured_only */)); | |
| 592 | |
| 593 // Add the service and verify that a FavorteState exists with the same guid. | |
| 594 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | |
| 595 UpdateManagerProperties(); | |
| 596 favorite = network_state_handler_->GetFavoriteStateFromServicePath( | |
| 597 wifi_path, is_service_configured); | |
| 598 ASSERT_TRUE(favorite); | |
| 599 EXPECT_EQ(wifi_guid, favorite->guid()); | |
| 600 // Verify that a NetworkState exists with the same GUID. | |
| 601 network = network_state_handler_->GetNetworkState(wifi_path); | |
| 602 ASSERT_TRUE(network); | |
| 603 EXPECT_EQ(wifi_guid, network->guid()); | |
| 604 } | |
| 605 | |
| 492 } // namespace chromeos | 606 } // namespace chromeos |
| OLD | NEW |