| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 using chromeos::NetworkState; | 39 using chromeos::NetworkState; |
| 40 using chromeos::NetworkStateHandler; | 40 using chromeos::NetworkStateHandler; |
| 41 | 41 |
| 42 class TestObserver : public chromeos::NetworkStateHandlerObserver { | 42 class TestObserver : public chromeos::NetworkStateHandlerObserver { |
| 43 public: | 43 public: |
| 44 explicit TestObserver(NetworkStateHandler* handler) | 44 explicit TestObserver(NetworkStateHandler* handler) |
| 45 : handler_(handler), | 45 : handler_(handler), |
| 46 device_list_changed_count_(0), | 46 device_list_changed_count_(0), |
| 47 device_count_(0), | 47 device_count_(0), |
| 48 network_list_changed_count_(0), |
| 48 network_count_(0), | 49 network_count_(0), |
| 49 default_network_change_count_(0) { | 50 default_network_change_count_(0) { |
| 50 } | 51 } |
| 51 | 52 |
| 52 virtual ~TestObserver() { | 53 virtual ~TestObserver() { |
| 53 } | 54 } |
| 54 | 55 |
| 55 virtual void DeviceListChanged() OVERRIDE { | 56 virtual void DeviceListChanged() OVERRIDE { |
| 56 NetworkStateHandler::DeviceStateList devices; | 57 NetworkStateHandler::DeviceStateList devices; |
| 57 handler_->GetDeviceList(&devices); | 58 handler_->GetDeviceList(&devices); |
| 58 device_count_ = devices.size(); | 59 device_count_ = devices.size(); |
| 59 ++device_list_changed_count_; | 60 ++device_list_changed_count_; |
| 60 } | 61 } |
| 61 | 62 |
| 62 virtual void NetworkListChanged() OVERRIDE { | 63 virtual void NetworkListChanged() OVERRIDE { |
| 63 NetworkStateHandler::NetworkStateList networks; | 64 NetworkStateHandler::NetworkStateList networks; |
| 64 handler_->GetNetworkListByType(chromeos::NetworkTypePattern::Default(), | 65 handler_->GetNetworkListByType(chromeos::NetworkTypePattern::Default(), |
| 65 false /* configured_only */, | 66 false /* configured_only */, |
| 66 false /* visible_only */, | 67 false /* visible_only */, |
| 67 0 /* no limit */, | 68 0 /* no limit */, |
| 68 &networks); | 69 &networks); |
| 69 network_count_ = networks.size(); | 70 network_count_ = networks.size(); |
| 70 if (network_count_ == 0) { | 71 if (network_count_ == 0) { |
| 71 default_network_ = ""; | 72 default_network_ = ""; |
| 72 default_network_connection_state_ = ""; | 73 default_network_connection_state_ = ""; |
| 73 } | 74 } |
| 75 ++network_list_changed_count_; |
| 74 } | 76 } |
| 75 | 77 |
| 76 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE { | 78 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE { |
| 77 ++default_network_change_count_; | 79 ++default_network_change_count_; |
| 78 default_network_ = network ? network->path() : ""; | 80 default_network_ = network ? network->path() : ""; |
| 79 default_network_connection_state_ = | 81 default_network_connection_state_ = |
| 80 network ? network->connection_state() : ""; | 82 network ? network->connection_state() : ""; |
| 81 DVLOG(1) << "DefaultNetworkChanged: " << default_network_ | 83 DVLOG(1) << "DefaultNetworkChanged: " << default_network_ |
| 82 << " State: " << default_network_connection_state_; | 84 << " State: " << default_network_connection_state_; |
| 83 } | 85 } |
| 84 | 86 |
| 85 virtual void NetworkConnectionStateChanged( | 87 virtual void NetworkConnectionStateChanged( |
| 86 const NetworkState* network) OVERRIDE { | 88 const NetworkState* network) OVERRIDE { |
| 87 network_connection_state_[network->path()] = network->connection_state(); | 89 network_connection_state_[network->path()] = network->connection_state(); |
| 88 connection_state_changes_[network->path()]++; | 90 connection_state_changes_[network->path()]++; |
| 89 } | 91 } |
| 90 | 92 |
| 91 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE { | 93 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE { |
| 92 DCHECK(network); | 94 DCHECK(network); |
| 93 property_updates_[network->path()]++; | 95 property_updates_[network->path()]++; |
| 94 } | 96 } |
| 95 | 97 |
| 96 size_t device_list_changed_count() { return device_list_changed_count_; } | 98 size_t device_list_changed_count() { return device_list_changed_count_; } |
| 97 size_t device_count() { return device_count_; } | 99 size_t device_count() { return device_count_; } |
| 100 size_t network_list_changed_count() { return network_list_changed_count_; } |
| 98 size_t network_count() { return network_count_; } | 101 size_t network_count() { return network_count_; } |
| 99 size_t default_network_change_count() { | 102 size_t default_network_change_count() { |
| 100 return default_network_change_count_; | 103 return default_network_change_count_; |
| 101 } | 104 } |
| 102 void reset_change_counts() { | 105 void reset_change_counts() { |
| 103 DVLOG(1) << "=== RESET CHANGE COUNTS ==="; | 106 DVLOG(1) << "=== RESET CHANGE COUNTS ==="; |
| 104 default_network_change_count_ = 0; | 107 default_network_change_count_ = 0; |
| 105 device_list_changed_count_ = 0; | 108 device_list_changed_count_ = 0; |
| 109 network_list_changed_count_ = 0; |
| 106 } | 110 } |
| 107 std::string default_network() { return default_network_; } | 111 std::string default_network() { return default_network_; } |
| 108 std::string default_network_connection_state() { | 112 std::string default_network_connection_state() { |
| 109 return default_network_connection_state_; | 113 return default_network_connection_state_; |
| 110 } | 114 } |
| 111 | 115 |
| 112 int PropertyUpdatesForService(const std::string& service_path) { | 116 int PropertyUpdatesForService(const std::string& service_path) { |
| 113 return property_updates_[service_path]; | 117 return property_updates_[service_path]; |
| 114 } | 118 } |
| 115 | 119 |
| 116 int ConnectionStateChangesForService(const std::string& service_path) { | 120 int ConnectionStateChangesForService(const std::string& service_path) { |
| 117 return connection_state_changes_[service_path]; | 121 return connection_state_changes_[service_path]; |
| 118 } | 122 } |
| 119 | 123 |
| 120 std::string NetworkConnectionStateForService( | 124 std::string NetworkConnectionStateForService( |
| 121 const std::string& service_path) { | 125 const std::string& service_path) { |
| 122 return network_connection_state_[service_path]; | 126 return network_connection_state_[service_path]; |
| 123 } | 127 } |
| 124 | 128 |
| 125 private: | 129 private: |
| 126 NetworkStateHandler* handler_; | 130 NetworkStateHandler* handler_; |
| 127 size_t device_list_changed_count_; | 131 size_t device_list_changed_count_; |
| 128 size_t device_count_; | 132 size_t device_count_; |
| 133 size_t network_list_changed_count_; |
| 129 size_t network_count_; | 134 size_t network_count_; |
| 130 size_t default_network_change_count_; | 135 size_t default_network_change_count_; |
| 131 std::string default_network_; | 136 std::string default_network_; |
| 132 std::string default_network_connection_state_; | 137 std::string default_network_connection_state_; |
| 133 std::map<std::string, int> property_updates_; | 138 std::map<std::string, int> property_updates_; |
| 134 std::map<std::string, int> connection_state_changes_; | 139 std::map<std::string, int> connection_state_changes_; |
| 135 std::map<std::string, std::string> network_connection_state_; | 140 std::map<std::string, std::string> network_connection_state_; |
| 136 | 141 |
| 137 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 142 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 138 }; | 143 }; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 EXPECT_EQ(kNumShillManagerClientStubImplServices, networks.size()); | 324 EXPECT_EQ(kNumShillManagerClientStubImplServices, networks.size()); |
| 320 // Get configured (profile) networks. | 325 // Get configured (profile) networks. |
| 321 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(), | 326 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(), |
| 322 true /* configured_only */, | 327 true /* configured_only */, |
| 323 false /* visible_only */, | 328 false /* visible_only */, |
| 324 0 /* no limit */, | 329 0 /* no limit */, |
| 325 &networks); | 330 &networks); |
| 326 EXPECT_EQ(1u, networks.size()); | 331 EXPECT_EQ(1u, networks.size()); |
| 327 } | 332 } |
| 328 | 333 |
| 334 TEST_F(NetworkStateHandlerTest, NetworkListChanged) { |
| 335 size_t stub_network_count = test_observer_->network_count(); |
| 336 // Set up two additional visible networks. |
| 337 const std::string wifi3 = "/service/wifi3"; |
| 338 const std::string wifi4 = "/service/wifi4"; |
| 339 service_test_->SetServiceProperties( |
| 340 wifi3, "wifi3_guid", "wifi3", |
| 341 shill::kTypeWifi, shill::kStateIdle, true /* visible */); |
| 342 service_test_->SetServiceProperties( |
| 343 wifi4, "wifi4_guid", "wifi4", |
| 344 shill::kTypeWifi, shill::kStateIdle, true /* visible */); |
| 345 // Add the services to the Manager. Only notify when the second service is |
| 346 // added. |
| 347 manager_test_->AddManagerService(wifi3, false); |
| 348 manager_test_->AddManagerService(wifi4, true); |
| 349 UpdateManagerProperties(); |
| 350 // Expect two service updates and one list update. |
| 351 EXPECT_EQ(stub_network_count + 2, test_observer_->network_count()); |
| 352 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(wifi3)); |
| 353 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(wifi4)); |
| 354 EXPECT_EQ(1u, test_observer_->network_list_changed_count()); |
| 355 } |
| 356 |
| 329 TEST_F(NetworkStateHandlerTest, GetVisibleNetworks) { | 357 TEST_F(NetworkStateHandlerTest, GetVisibleNetworks) { |
| 330 // Ensure that the network list is the expected size. | 358 // Ensure that the network list is the expected size. |
| 331 const size_t kNumShillManagerClientStubImplServices = 4; | 359 const size_t kNumShillManagerClientStubImplServices = 4; |
| 332 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 360 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 333 test_observer_->network_count()); | 361 test_observer_->network_count()); |
| 334 // Add a non-visible network to the profile. | 362 // Add a non-visible network to the profile. |
| 335 const std::string profile = "/profile/profile1"; | 363 const std::string profile = "/profile/profile1"; |
| 336 const std::string wifi_favorite_path = "/service/wifi_faviorite"; | 364 const std::string wifi_favorite_path = "/service/wifi_faviorite"; |
| 337 service_test_->AddService(wifi_favorite_path, "wifi_faviorite", | 365 service_test_->AddService(wifi_favorite_path, "wifi_faviorite", |
| 338 shill::kTypeWifi, shill::kStateIdle, | 366 shill::kTypeWifi, shill::kStateIdle, |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 // the NetworkState was created with the same GUID. | 697 // the NetworkState was created with the same GUID. |
| 670 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | 698 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); |
| 671 UpdateManagerProperties(); | 699 UpdateManagerProperties(); |
| 672 network = network_state_handler_->GetNetworkStateFromServicePath( | 700 network = network_state_handler_->GetNetworkStateFromServicePath( |
| 673 wifi_path, is_service_configured); | 701 wifi_path, is_service_configured); |
| 674 ASSERT_TRUE(network); | 702 ASSERT_TRUE(network); |
| 675 EXPECT_EQ(wifi_guid, network->guid()); | 703 EXPECT_EQ(wifi_guid, network->guid()); |
| 676 } | 704 } |
| 677 | 705 |
| 678 } // namespace chromeos | 706 } // namespace chromeos |
| OLD | NEW |