| 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/shill_property_handler.h" | 5 #include "chromeos/network/shill_property_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 18 matching lines...) Expand all Loading... |
| 29 void DoNothingWithCallStatus(DBusMethodCallStatus call_status) { | 29 void DoNothingWithCallStatus(DBusMethodCallStatus call_status) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 void ErrorCallbackFunction(const std::string& error_name, | 32 void ErrorCallbackFunction(const std::string& error_name, |
| 33 const std::string& error_message) { | 33 const std::string& error_message) { |
| 34 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; | 34 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; |
| 35 } | 35 } |
| 36 | 36 |
| 37 class TestListener : public internal::ShillPropertyHandler::Listener { | 37 class TestListener : public internal::ShillPropertyHandler::Listener { |
| 38 public: | 38 public: |
| 39 TestListener() : technology_list_updates_(0), | 39 TestListener() : device_list_updates_(0), |
| 40 service_list_updates_(0), |
| 41 technology_list_updates_(0), |
| 40 errors_(0) { | 42 errors_(0) { |
| 41 } | 43 } |
| 42 | 44 |
| 43 virtual void UpdateManagedList(ManagedState::ManagedType type, | 45 virtual void UpdateManagedDevices(const base::ListValue& entries) OVERRIDE { |
| 44 const base::ListValue& entries) OVERRIDE { | 46 VLOG(1) << "UpdateManagedDevices: " << entries.GetSize(); |
| 45 UpdateEntries(GetTypeString(type), entries); | 47 UpdateEntries(shill::kDevicesProperty, entries); |
| 48 } |
| 49 |
| 50 virtual void UpdateManagedNetworks(const base::ListValue& entries, |
| 51 bool complete_list) OVERRIDE { |
| 52 VLOG(1) << "UpdateManagedNetworks(" << complete_list |
| 53 << ") : " << entries.GetSize(); |
| 54 if (complete_list) { |
| 55 UpdateEntries(shill::kServiceCompleteListProperty, entries); |
| 56 } else { |
| 57 UpdateEntries(shill::kServicesProperty, entries); |
| 58 } |
| 46 } | 59 } |
| 47 | 60 |
| 48 virtual void UpdateManagedStateProperties( | 61 virtual void UpdateManagedStateProperties( |
| 49 ManagedState::ManagedType type, | 62 ManagedState::ManagedType type, |
| 50 const std::string& path, | 63 const std::string& path, |
| 51 const base::DictionaryValue& properties) OVERRIDE { | 64 const base::DictionaryValue& properties) OVERRIDE { |
| 52 AddInitialPropertyUpdate(GetTypeString(type), path); | 65 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
| 66 AddInitialPropertyUpdate(shill::kServicesProperty, path); |
| 67 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
| 68 AddInitialPropertyUpdate(shill::kDevicesProperty, path); |
| 69 } else { |
| 70 NOTREACHED(); |
| 71 } |
| 53 } | 72 } |
| 54 | 73 |
| 55 virtual void ProfileListChanged() OVERRIDE { | 74 virtual void ProfileListChanged() OVERRIDE { |
| 56 } | 75 } |
| 57 | 76 |
| 58 virtual void UpdateNetworkServiceProperty( | 77 virtual void UpdateNetworkServiceProperty( |
| 59 const std::string& service_path, | 78 const std::string& service_path, |
| 60 const std::string& key, | 79 const std::string& key, |
| 61 const base::Value& value) OVERRIDE { | 80 const base::Value& value) OVERRIDE { |
| 62 AddPropertyUpdate(shill::kServicesProperty, service_path); | 81 AddPropertyUpdate(shill::kServicesProperty, service_path); |
| 63 } | 82 } |
| 64 | 83 |
| 65 virtual void UpdateDeviceProperty( | 84 virtual void UpdateDeviceProperty( |
| 66 const std::string& device_path, | 85 const std::string& device_path, |
| 67 const std::string& key, | 86 const std::string& key, |
| 68 const base::Value& value) OVERRIDE { | 87 const base::Value& value) OVERRIDE { |
| 69 AddPropertyUpdate(shill::kDevicesProperty, device_path); | 88 AddPropertyUpdate(shill::kDevicesProperty, device_path); |
| 70 } | 89 } |
| 71 | 90 |
| 72 virtual void UpdateIPConfigProperties( | 91 virtual void UpdateIPConfigProperties( |
| 73 ManagedState::ManagedType type, | 92 ManagedState::ManagedType type, |
| 74 const std::string& path, | 93 const std::string& path, |
| 75 const std::string& ip_config_path, | 94 const std::string& ip_config_path, |
| 76 const base::DictionaryValue& properties) OVERRIDE { | 95 const base::DictionaryValue& properties) OVERRIDE { |
| 77 AddPropertyUpdate(shill::kIPConfigsProperty, ip_config_path); | 96 AddPropertyUpdate(shill::kIPConfigsProperty, ip_config_path); |
| 78 } | 97 } |
| 79 | 98 |
| 80 virtual void TechnologyListChanged() OVERRIDE { | 99 virtual void TechnologyListChanged() OVERRIDE { |
| 100 VLOG(1) << "TechnologyListChanged."; |
| 81 ++technology_list_updates_; | 101 ++technology_list_updates_; |
| 82 } | 102 } |
| 83 | 103 |
| 84 virtual void CheckPortalListChanged( | 104 virtual void CheckPortalListChanged( |
| 85 const std::string& check_portal_list) OVERRIDE { | 105 const std::string& check_portal_list) OVERRIDE { |
| 86 } | 106 } |
| 87 | 107 |
| 88 virtual void ManagedStateListChanged( | 108 virtual void ManagedStateListChanged( |
| 89 ManagedState::ManagedType type) OVERRIDE { | 109 ManagedState::ManagedType type) OVERRIDE { |
| 90 AddStateListUpdate(GetTypeString(type)); | 110 VLOG(1) << "ManagedStateListChanged: " << type; |
| 111 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
| 112 ++service_list_updates_; |
| 113 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
| 114 ++device_list_updates_; |
| 115 } |
| 91 } | 116 } |
| 92 | 117 |
| 93 virtual void DefaultNetworkServiceChanged( | 118 virtual void DefaultNetworkServiceChanged( |
| 94 const std::string& service_path) OVERRIDE { | 119 const std::string& service_path) OVERRIDE { |
| 95 } | 120 } |
| 96 | 121 |
| 97 std::vector<std::string>& entries(const std::string& type) { | 122 std::vector<std::string>& entries(const std::string& type) { |
| 98 return entries_[type]; | 123 return entries_[type]; |
| 99 } | 124 } |
| 100 std::map<std::string, int>& property_updates(const std::string& type) { | 125 std::map<std::string, int>& property_updates(const std::string& type) { |
| 101 return property_updates_[type]; | 126 return property_updates_[type]; |
| 102 } | 127 } |
| 103 std::map<std::string, int>& initial_property_updates( | 128 std::map<std::string, int>& initial_property_updates( |
| 104 const std::string& type) { | 129 const std::string& type) { |
| 105 return initial_property_updates_[type]; | 130 return initial_property_updates_[type]; |
| 106 } | 131 } |
| 107 int list_updates(const std::string& type) { return list_updates_[type]; } | 132 int device_list_updates() { return device_list_updates_; } |
| 108 void reset_list_updates() { list_updates_.clear(); } | 133 int service_list_updates() { return service_list_updates_; } |
| 109 int technology_list_updates() { return technology_list_updates_; } | 134 int technology_list_updates() { return technology_list_updates_; } |
| 135 void reset_list_updates() { |
| 136 DVLOG(1) << "=== RESET LIST UPDATES ==="; |
| 137 device_list_updates_ = 0; |
| 138 service_list_updates_ = 0; |
| 139 technology_list_updates_ = 0; |
| 140 } |
| 110 int errors() { return errors_; } | 141 int errors() { return errors_; } |
| 111 | 142 |
| 112 private: | 143 private: |
| 113 std::string GetTypeString(ManagedState::ManagedType type) { | |
| 114 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | |
| 115 return shill::kServicesProperty; | |
| 116 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { | |
| 117 return shill::kServiceCompleteListProperty; | |
| 118 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | |
| 119 return shill::kDevicesProperty; | |
| 120 } | |
| 121 LOG(ERROR) << "UpdateManagedList called with unrecognized type: " << type; | |
| 122 ++errors_; | |
| 123 return std::string(); | |
| 124 } | |
| 125 | |
| 126 void UpdateEntries(const std::string& type, const base::ListValue& entries) { | 144 void UpdateEntries(const std::string& type, const base::ListValue& entries) { |
| 127 if (type.empty()) | 145 if (type.empty()) |
| 128 return; | 146 return; |
| 129 entries_[type].clear(); | 147 entries_[type].clear(); |
| 130 for (base::ListValue::const_iterator iter = entries.begin(); | 148 for (base::ListValue::const_iterator iter = entries.begin(); |
| 131 iter != entries.end(); ++iter) { | 149 iter != entries.end(); ++iter) { |
| 132 std::string path; | 150 std::string path; |
| 133 if ((*iter)->GetAsString(&path)) | 151 if ((*iter)->GetAsString(&path)) |
| 134 entries_[type].push_back(path); | 152 entries_[type].push_back(path); |
| 135 } | 153 } |
| 136 } | 154 } |
| 137 | 155 |
| 138 void AddPropertyUpdate(const std::string& type, const std::string& path) { | 156 void AddPropertyUpdate(const std::string& type, const std::string& path) { |
| 139 if (type.empty()) | 157 if (type.empty()) |
| 140 return; | 158 return; |
| 159 VLOG(2) << "AddPropertyUpdate: " << type; |
| 141 property_updates(type)[path] += 1; | 160 property_updates(type)[path] += 1; |
| 142 } | 161 } |
| 143 | 162 |
| 144 void AddInitialPropertyUpdate(const std::string& type, | 163 void AddInitialPropertyUpdate(const std::string& type, |
| 145 const std::string& path) { | 164 const std::string& path) { |
| 146 if (type.empty()) | 165 if (type.empty()) |
| 147 return; | 166 return; |
| 167 VLOG(2) << "AddInitialPropertyUpdate: " << type; |
| 148 initial_property_updates(type)[path] += 1; | 168 initial_property_updates(type)[path] += 1; |
| 149 } | 169 } |
| 150 | 170 |
| 151 void AddStateListUpdate(const std::string& type) { | |
| 152 if (type.empty()) | |
| 153 return; | |
| 154 list_updates_[type] += 1; | |
| 155 } | |
| 156 | |
| 157 // Map of list-type -> paths | 171 // Map of list-type -> paths |
| 158 std::map<std::string, std::vector<std::string> > entries_; | 172 std::map<std::string, std::vector<std::string> > entries_; |
| 159 // Map of list-type -> map of paths -> update counts | 173 // Map of list-type -> map of paths -> update counts |
| 160 std::map<std::string, std::map<std::string, int> > property_updates_; | 174 std::map<std::string, std::map<std::string, int> > property_updates_; |
| 161 std::map<std::string, std::map<std::string, int> > initial_property_updates_; | 175 std::map<std::string, std::map<std::string, int> > initial_property_updates_; |
| 162 // Map of list-type -> list update counts | 176 int device_list_updates_; |
| 163 std::map<std::string, int > list_updates_; | 177 int service_list_updates_; |
| 164 int technology_list_updates_; | 178 int technology_list_updates_; |
| 165 int errors_; | 179 int errors_; |
| 166 }; | 180 }; |
| 167 | 181 |
| 168 } // namespace | 182 } // namespace |
| 169 | 183 |
| 170 class ShillPropertyHandlerTest : public testing::Test { | 184 class ShillPropertyHandlerTest : public testing::Test { |
| 171 public: | 185 public: |
| 172 ShillPropertyHandlerTest() | 186 ShillPropertyHandlerTest() |
| 173 : manager_test_(NULL), | 187 : manager_test_(NULL), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 200 } | 214 } |
| 201 | 215 |
| 202 virtual void TearDown() OVERRIDE { | 216 virtual void TearDown() OVERRIDE { |
| 203 shill_property_handler_.reset(); | 217 shill_property_handler_.reset(); |
| 204 listener_.reset(); | 218 listener_.reset(); |
| 205 DBusThreadManager::Shutdown(); | 219 DBusThreadManager::Shutdown(); |
| 206 } | 220 } |
| 207 | 221 |
| 208 void AddDevice(const std::string& type, const std::string& id) { | 222 void AddDevice(const std::string& type, const std::string& id) { |
| 209 ASSERT_TRUE(IsValidType(type)); | 223 ASSERT_TRUE(IsValidType(type)); |
| 210 device_test_->AddDevice(id, type, std::string("/device/" + id)); | 224 device_test_->AddDevice(id, type, id); |
| 211 } | 225 } |
| 212 | 226 |
| 213 void RemoveDevice(const std::string& id) { | 227 void RemoveDevice(const std::string& id) { |
| 214 device_test_->RemoveDevice(id); | 228 device_test_->RemoveDevice(id); |
| 215 } | 229 } |
| 216 | 230 |
| 217 void AddService(const std::string& type, | 231 void AddService(const std::string& type, |
| 218 const std::string& id, | 232 const std::string& id, |
| 219 const std::string& state, | 233 const std::string& state) { |
| 220 bool add_to_watch_list) { | |
| 221 ASSERT_TRUE(IsValidType(type)); | 234 ASSERT_TRUE(IsValidType(type)); |
| 222 service_test_->AddService(id, id, type, state, | 235 service_test_->AddService(id, id, type, state, |
| 223 true /* visible */, add_to_watch_list); | 236 true /* visible */, |
| 237 true /* add_to_watch_list */); |
| 224 } | 238 } |
| 225 | 239 |
| 226 void AddServiceWithIPConfig(const std::string& type, | 240 void AddServiceWithIPConfig(const std::string& type, |
| 227 const std::string& id, | 241 const std::string& id, |
| 228 const std::string& state, | 242 const std::string& state, |
| 229 const std::string& ipconfig_path, | 243 const std::string& ipconfig_path) { |
| 230 bool add_to_watch_list) { | |
| 231 ASSERT_TRUE(IsValidType(type)); | 244 ASSERT_TRUE(IsValidType(type)); |
| 232 service_test_->AddServiceWithIPConfig(id, /* service_path */ | 245 service_test_->AddServiceWithIPConfig(id, /* service_path */ |
| 233 "" /* guid */, | 246 "" /* guid */, |
| 234 id /* name */, | 247 id /* name */, |
| 235 type, | 248 type, |
| 236 state, | 249 state, |
| 237 ipconfig_path, | 250 ipconfig_path, |
| 238 true /* visible */, | 251 true /* visible */, |
| 239 add_to_watch_list); | 252 true /* add_to_watch_list */); |
| 240 } | 253 } |
| 241 | 254 |
| 242 void AddServiceToProfile(const std::string& type, | 255 void AddServiceToProfile(const std::string& type, |
| 243 const std::string& id, | 256 const std::string& id, |
| 244 bool visible) { | 257 bool visible) { |
| 245 service_test_->AddService(id, id, type, shill::kStateIdle, | 258 service_test_->AddService(id, id, type, shill::kStateIdle, |
| 246 visible, false /* watch */); | 259 visible, true /* watch */); |
| 247 std::vector<std::string> profiles; | 260 std::vector<std::string> profiles; |
| 248 profile_test_->GetProfilePaths(&profiles); | 261 profile_test_->GetProfilePaths(&profiles); |
| 249 ASSERT_TRUE(profiles.size() > 0); | 262 ASSERT_TRUE(profiles.size() > 0); |
| 250 base::DictionaryValue properties; // Empty entry | 263 base::DictionaryValue properties; // Empty entry |
| 251 profile_test_->AddService(profiles[0], id); | 264 profile_test_->AddService(profiles[0], id); |
| 252 } | 265 } |
| 253 | 266 |
| 254 void RemoveService(const std::string& id) { | 267 void RemoveService(const std::string& id) { |
| 255 service_test_->RemoveService(id); | 268 service_test_->RemoveService(id); |
| 256 } | 269 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 274 type == shill::kTypeVPN); | 287 type == shill::kTypeVPN); |
| 275 } | 288 } |
| 276 | 289 |
| 277 protected: | 290 protected: |
| 278 void SetupDefaultShillState() { | 291 void SetupDefaultShillState() { |
| 279 message_loop_.RunUntilIdle(); // Process any pending updates | 292 message_loop_.RunUntilIdle(); // Process any pending updates |
| 280 device_test_->ClearDevices(); | 293 device_test_->ClearDevices(); |
| 281 AddDevice(shill::kTypeWifi, "stub_wifi_device1"); | 294 AddDevice(shill::kTypeWifi, "stub_wifi_device1"); |
| 282 AddDevice(shill::kTypeCellular, "stub_cellular_device1"); | 295 AddDevice(shill::kTypeCellular, "stub_cellular_device1"); |
| 283 service_test_->ClearServices(); | 296 service_test_->ClearServices(); |
| 284 const bool add_to_watchlist = true; | 297 AddService(shill::kTypeEthernet, "stub_ethernet", shill::kStateOnline); |
| 285 AddService(shill::kTypeEthernet, "stub_ethernet", | 298 AddService(shill::kTypeWifi, "stub_wifi1", shill::kStateOnline); |
| 286 shill::kStateOnline, add_to_watchlist); | 299 AddService(shill::kTypeWifi, "stub_wifi2", shill::kStateIdle); |
| 287 AddService(shill::kTypeWifi, "stub_wifi1", | 300 AddService(shill::kTypeCellular, "stub_cellular1", shill::kStateIdle); |
| 288 shill::kStateOnline, add_to_watchlist); | |
| 289 AddService(shill::kTypeWifi, "stub_wifi2", | |
| 290 shill::kStateIdle, add_to_watchlist); | |
| 291 AddService(shill::kTypeCellular, "stub_cellular1", | |
| 292 shill::kStateIdle, add_to_watchlist); | |
| 293 } | 301 } |
| 294 | 302 |
| 295 base::MessageLoopForUI message_loop_; | 303 base::MessageLoopForUI message_loop_; |
| 296 scoped_ptr<TestListener> listener_; | 304 scoped_ptr<TestListener> listener_; |
| 297 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; | 305 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; |
| 298 ShillManagerClient::TestInterface* manager_test_; | 306 ShillManagerClient::TestInterface* manager_test_; |
| 299 ShillDeviceClient::TestInterface* device_test_; | 307 ShillDeviceClient::TestInterface* device_test_; |
| 300 ShillServiceClient::TestInterface* service_test_; | 308 ShillServiceClient::TestInterface* service_test_; |
| 301 ShillProfileClient::TestInterface* profile_test_; | 309 ShillProfileClient::TestInterface* profile_test_; |
| 302 | 310 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 315 listener_->entries(shill::kServicesProperty).size()); | 323 listener_->entries(shill::kServicesProperty).size()); |
| 316 | 324 |
| 317 EXPECT_EQ(0, listener_->errors()); | 325 EXPECT_EQ(0, listener_->errors()); |
| 318 } | 326 } |
| 319 | 327 |
| 320 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { | 328 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { |
| 321 const int initial_technology_updates = 2; // Available and Enabled lists | 329 const int initial_technology_updates = 2; // Available and Enabled lists |
| 322 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates()); | 330 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates()); |
| 323 | 331 |
| 324 // Remove an enabled technology. Updates both the Available and Enabled lists. | 332 // Remove an enabled technology. Updates both the Available and Enabled lists. |
| 333 listener_->reset_list_updates(); |
| 325 manager_test_->RemoveTechnology(shill::kTypeWifi); | 334 manager_test_->RemoveTechnology(shill::kTypeWifi); |
| 326 message_loop_.RunUntilIdle(); | 335 message_loop_.RunUntilIdle(); |
| 327 EXPECT_EQ(initial_technology_updates + 2, | 336 EXPECT_EQ(2, listener_->technology_list_updates()); |
| 328 listener_->technology_list_updates()); | |
| 329 | 337 |
| 330 // Add a disabled technology. | 338 // Add a disabled technology. |
| 339 listener_->reset_list_updates(); |
| 331 manager_test_->AddTechnology(shill::kTypeWifi, false); | 340 manager_test_->AddTechnology(shill::kTypeWifi, false); |
| 332 message_loop_.RunUntilIdle(); | 341 message_loop_.RunUntilIdle(); |
| 333 EXPECT_EQ(initial_technology_updates + 3, | 342 EXPECT_EQ(1, listener_->technology_list_updates()); |
| 334 listener_->technology_list_updates()); | |
| 335 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( | 343 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( |
| 336 shill::kTypeWifi)); | 344 shill::kTypeWifi)); |
| 337 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi)); | 345 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi)); |
| 338 | 346 |
| 339 // Enable the technology. | 347 // Enable the technology. This will add new services which will request a |
| 348 // manager update, triggering a total of 3 new updates. |
| 349 listener_->reset_list_updates(); |
| 340 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( | 350 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( |
| 341 shill::kTypeWifi, | 351 shill::kTypeWifi, |
| 342 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 352 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 343 message_loop_.RunUntilIdle(); | 353 message_loop_.RunUntilIdle(); |
| 344 EXPECT_EQ(initial_technology_updates + 4, | 354 EXPECT_EQ(3, listener_->technology_list_updates()); |
| 345 listener_->technology_list_updates()); | |
| 346 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi)); | 355 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi)); |
| 347 | 356 |
| 348 EXPECT_EQ(0, listener_->errors()); | 357 EXPECT_EQ(0, listener_->errors()); |
| 349 } | 358 } |
| 350 | 359 |
| 351 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { | 360 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { |
| 352 const size_t kNumShillManagerClientStubImplDevices = 2; | 361 const size_t kNumShillManagerClientStubImplDevices = 2; |
| 353 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 362 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 354 listener_->entries(shill::kDevicesProperty).size()); | 363 listener_->entries(shill::kDevicesProperty).size()); |
| 355 // Add a device. | 364 // Add a device. |
| 356 listener_->reset_list_updates(); | 365 listener_->reset_list_updates(); |
| 357 const std::string kTestDevicePath("test_wifi_device1"); | 366 const std::string kTestDevicePath("test_wifi_device1"); |
| 358 AddDevice(shill::kTypeWifi, kTestDevicePath); | 367 AddDevice(shill::kTypeWifi, kTestDevicePath); |
| 359 message_loop_.RunUntilIdle(); | 368 message_loop_.RunUntilIdle(); |
| 360 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty)); | 369 EXPECT_EQ(1, listener_->device_list_updates()); |
| 361 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, | 370 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, |
| 362 listener_->entries(shill::kDevicesProperty).size()); | 371 listener_->entries(shill::kDevicesProperty).size()); |
| 363 // Device changes are not observed. | 372 |
| 364 // Remove a device | 373 // Remove a device |
| 365 listener_->reset_list_updates(); | 374 listener_->reset_list_updates(); |
| 366 RemoveDevice(kTestDevicePath); | 375 RemoveDevice(kTestDevicePath); |
| 367 message_loop_.RunUntilIdle(); | 376 message_loop_.RunUntilIdle(); |
| 368 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty)); | 377 EXPECT_EQ(1, listener_->device_list_updates()); |
| 369 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 378 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 370 listener_->entries(shill::kDevicesProperty).size()); | 379 listener_->entries(shill::kDevicesProperty).size()); |
| 371 | 380 |
| 372 EXPECT_EQ(0, listener_->errors()); | 381 EXPECT_EQ(0, listener_->errors()); |
| 373 } | 382 } |
| 374 | 383 |
| 375 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { | 384 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { |
| 376 const size_t kNumShillManagerClientStubImplServices = 4; | 385 const size_t kNumShillManagerClientStubImplServices = 4; |
| 377 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 386 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 378 listener_->entries(shill::kServicesProperty).size()); | 387 listener_->entries(shill::kServicesProperty).size()); |
| 379 | 388 |
| 380 // Add an unwatched service. | 389 // Add a service. |
| 381 listener_->reset_list_updates(); | 390 listener_->reset_list_updates(); |
| 382 const std::string kTestServicePath("test_wifi_service1"); | 391 const std::string kTestServicePath("test_wifi_service1"); |
| 383 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, false); | 392 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle); |
| 384 message_loop_.RunUntilIdle(); | 393 message_loop_.RunUntilIdle(); |
| 385 // Watched and unwatched services trigger a service list update. | 394 // Add should trigger a service list update and update entries. |
| 386 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); | 395 EXPECT_EQ(1, listener_->service_list_updates()); |
| 387 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, | 396 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, |
| 388 listener_->entries(shill::kServicesProperty).size()); | 397 listener_->entries(shill::kServicesProperty).size()); |
| 389 // Service receives an initial property update. | 398 // Service receives an initial property update. |
| 390 EXPECT_EQ(1, listener_->initial_property_updates( | 399 EXPECT_EQ(1, listener_->initial_property_updates( |
| 391 shill::kServicesProperty)[kTestServicePath]); | 400 shill::kServicesProperty)[kTestServicePath]); |
| 392 // Change a property. | 401 // Change a property. |
| 393 base::FundamentalValue scan_interval(3); | 402 base::FundamentalValue scan_interval(3); |
| 394 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 403 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 395 dbus::ObjectPath(kTestServicePath), | 404 dbus::ObjectPath(kTestServicePath), |
| 396 shill::kScanIntervalProperty, | 405 shill::kScanIntervalProperty, |
| 397 scan_interval, | 406 scan_interval, |
| 398 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 407 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 399 message_loop_.RunUntilIdle(); | 408 message_loop_.RunUntilIdle(); |
| 400 // Property change triggers an update. | 409 // Property change triggers an update (but not a service list update). |
| 401 EXPECT_EQ(1, listener_->property_updates( | 410 EXPECT_EQ(1, listener_->property_updates( |
| 402 shill::kServicesProperty)[kTestServicePath]); | 411 shill::kServicesProperty)[kTestServicePath]); |
| 403 | 412 |
| 404 // Add the existing service to the watch list. | 413 // Remove a service. This will update the entries but will not signal a |
| 405 listener_->reset_list_updates(); | 414 // service list update since no new services need to be requested. |
| 406 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, true); | |
| 407 message_loop_.RunUntilIdle(); | |
| 408 // Service list update should be received when watch list changes. | |
| 409 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); | |
| 410 // Number of services shouldn't change. | |
| 411 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, | |
| 412 listener_->entries(shill::kServicesProperty).size()); | |
| 413 | |
| 414 // Change a property. | |
| 415 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | |
| 416 dbus::ObjectPath(kTestServicePath), | |
| 417 shill::kScanIntervalProperty, | |
| 418 scan_interval, | |
| 419 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | |
| 420 message_loop_.RunUntilIdle(); | |
| 421 // Property change should trigger another update. | |
| 422 EXPECT_EQ(2, listener_->property_updates( | |
| 423 shill::kServicesProperty)[kTestServicePath]); | |
| 424 | |
| 425 // Remove a service | |
| 426 listener_->reset_list_updates(); | 415 listener_->reset_list_updates(); |
| 427 RemoveService(kTestServicePath); | 416 RemoveService(kTestServicePath); |
| 428 message_loop_.RunUntilIdle(); | 417 message_loop_.RunUntilIdle(); |
| 429 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); | |
| 430 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 418 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 431 listener_->entries(shill::kServicesProperty).size()); | 419 listener_->entries(shill::kServicesProperty).size()); |
| 432 | 420 |
| 433 EXPECT_EQ(0, listener_->errors()); | 421 EXPECT_EQ(0, listener_->errors()); |
| 434 } | 422 } |
| 435 | 423 |
| 436 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) { | 424 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) { |
| 437 // Set the properties for an IP Config object. | 425 // Set the properties for an IP Config object. |
| 438 const std::string kTestIPConfigPath("test_ip_config_path"); | 426 const std::string kTestIPConfigPath("test_ip_config_path"); |
| 439 | 427 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 457 base::StringValue gateway("192.0.0.1"); | 445 base::StringValue gateway("192.0.0.1"); |
| 458 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( | 446 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( |
| 459 dbus::ObjectPath(kTestIPConfigPath), | 447 dbus::ObjectPath(kTestIPConfigPath), |
| 460 shill::kGatewayProperty, gateway, | 448 shill::kGatewayProperty, gateway, |
| 461 base::Bind(&DoNothingWithCallStatus)); | 449 base::Bind(&DoNothingWithCallStatus)); |
| 462 message_loop_.RunUntilIdle(); | 450 message_loop_.RunUntilIdle(); |
| 463 | 451 |
| 464 // Add a service with an empty ipconfig and then update | 452 // Add a service with an empty ipconfig and then update |
| 465 // its ipconfig property. | 453 // its ipconfig property. |
| 466 const std::string kTestServicePath1("test_wifi_service1"); | 454 const std::string kTestServicePath1("test_wifi_service1"); |
| 467 AddService(shill::kTypeWifi, kTestServicePath1, shill::kStateIdle, true); | 455 AddService(shill::kTypeWifi, kTestServicePath1, shill::kStateIdle); |
| 468 message_loop_.RunUntilIdle(); | 456 message_loop_.RunUntilIdle(); |
| 469 // This is the initial property update. | 457 // This is the initial property update. |
| 470 EXPECT_EQ(1, listener_->initial_property_updates( | 458 EXPECT_EQ(1, listener_->initial_property_updates( |
| 471 shill::kServicesProperty)[kTestServicePath1]); | 459 shill::kServicesProperty)[kTestServicePath1]); |
| 472 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 460 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 473 dbus::ObjectPath(kTestServicePath1), | 461 dbus::ObjectPath(kTestServicePath1), |
| 474 shill::kIPConfigProperty, | 462 shill::kIPConfigProperty, |
| 475 base::StringValue(kTestIPConfigPath), | 463 base::StringValue(kTestIPConfigPath), |
| 476 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 464 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 477 message_loop_.RunUntilIdle(); | 465 message_loop_.RunUntilIdle(); |
| 478 // IPConfig property change on the service should trigger an IPConfigs update. | 466 // IPConfig property change on the service should trigger an IPConfigs update. |
| 479 EXPECT_EQ(1, listener_->property_updates( | 467 EXPECT_EQ(1, listener_->property_updates( |
| 480 shill::kIPConfigsProperty)[kTestIPConfigPath]); | 468 shill::kIPConfigsProperty)[kTestIPConfigPath]); |
| 481 | 469 |
| 482 // Now, Add a new watched service with the IPConfig already set. | 470 // Now, Add a new service with the IPConfig already set. |
| 483 const std::string kTestServicePath2("test_wifi_service2"); | 471 const std::string kTestServicePath2("test_wifi_service2"); |
| 484 AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2, | 472 AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2, |
| 485 shill::kStateIdle, kTestIPConfigPath, true); | 473 shill::kStateIdle, kTestIPConfigPath); |
| 486 message_loop_.RunUntilIdle(); | 474 message_loop_.RunUntilIdle(); |
| 487 // A watched service with the IPConfig property already set should trigger an | 475 // A service with the IPConfig property already set should trigger an |
| 488 // additional IPConfigs update. | 476 // additional IPConfigs update. |
| 489 EXPECT_EQ(2, listener_->property_updates( | 477 EXPECT_EQ(2, listener_->property_updates( |
| 490 shill::kIPConfigsProperty)[kTestIPConfigPath]); | 478 shill::kIPConfigsProperty)[kTestIPConfigPath]); |
| 491 } | 479 } |
| 492 | 480 |
| 493 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) { | 481 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceList) { |
| 494 // Add a new entry to the profile only (triggers a Services update). | 482 // Add an entry to the profile only. |
| 495 const std::string kTestServicePath1("stub_wifi_profile_only1"); | 483 const std::string kTestServicePath1("stub_wifi_profile_only1"); |
| 496 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false); | 484 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false /* visible */); |
| 497 message_loop_.RunUntilIdle(); | 485 message_loop_.RunUntilIdle(); |
| 498 | 486 |
| 499 // Update the Manager properties. This should trigger a single list update | 487 // Update the Manager properties. This should trigger a single list update |
| 500 // for both Services and ServiceCompleteList, and a single property update | 488 // and a single initial property update. |
| 501 // for ServiceCompleteList. | |
| 502 listener_->reset_list_updates(); | 489 listener_->reset_list_updates(); |
| 503 shill_property_handler_->UpdateManagerProperties(); | 490 shill_property_handler_->UpdateManagerProperties(); |
| 504 message_loop_.RunUntilIdle(); | 491 message_loop_.RunUntilIdle(); |
| 505 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); | 492 EXPECT_EQ(1, listener_->service_list_updates()); |
| 506 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); | 493 EXPECT_EQ(1, listener_->initial_property_updates( |
| 507 EXPECT_EQ(0, listener_->initial_property_updates( | |
| 508 shill::kServicesProperty)[kTestServicePath1]); | 494 shill::kServicesProperty)[kTestServicePath1]); |
| 509 EXPECT_EQ(1, listener_->initial_property_updates( | 495 |
| 510 shill::kServiceCompleteListProperty)[kTestServicePath1]); | |
| 511 EXPECT_EQ(0, listener_->property_updates( | 496 EXPECT_EQ(0, listener_->property_updates( |
| 512 shill::kServicesProperty)[kTestServicePath1]); | 497 shill::kServicesProperty)[kTestServicePath1]); |
| 513 EXPECT_EQ(0, listener_->property_updates( | 498 EXPECT_EQ(0, listener_->property_updates( |
| 499 shill::kServicesProperty)[kTestServicePath1]); |
| 500 |
| 501 EXPECT_EQ(0, listener_->property_updates( |
| 514 shill::kServiceCompleteListProperty)[kTestServicePath1]); | 502 shill::kServiceCompleteListProperty)[kTestServicePath1]); |
| 515 | 503 |
| 516 // Add a new entry to the services and the profile; should also trigger a | 504 // Add a new entry to the services and the profile; should also trigger a |
| 517 // single list update for both Services and ServiceCompleteList, and should | 505 // service lis tupdate, and a property update. |
| 518 // trigger tow property updates for Services (one when the Profile propety | |
| 519 // changes, and one for the Request) and one ServiceCompleteList change for | |
| 520 // the Request. | |
| 521 listener_->reset_list_updates(); | 506 listener_->reset_list_updates(); |
| 522 const std::string kTestServicePath2("stub_wifi_profile_only2"); | 507 const std::string kTestServicePath2("stub_wifi_profile_only2"); |
| 523 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true); | 508 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true); |
| 524 shill_property_handler_->UpdateManagerProperties(); | 509 shill_property_handler_->UpdateManagerProperties(); |
| 525 message_loop_.RunUntilIdle(); | 510 message_loop_.RunUntilIdle(); |
| 526 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); | 511 EXPECT_EQ(1, listener_->service_list_updates()); |
| 527 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); | |
| 528 EXPECT_EQ(1, listener_->initial_property_updates( | 512 EXPECT_EQ(1, listener_->initial_property_updates( |
| 529 shill::kServicesProperty)[kTestServicePath2]); | 513 shill::kServicesProperty)[kTestServicePath2]); |
| 530 EXPECT_EQ(1, listener_->initial_property_updates( | |
| 531 shill::kServiceCompleteListProperty)[kTestServicePath2]); | |
| 532 // Expect one property update for the Profile property of the Network. | |
| 533 EXPECT_EQ(1, listener_->property_updates( | 514 EXPECT_EQ(1, listener_->property_updates( |
| 534 shill::kServicesProperty)[kTestServicePath2]); | 515 shill::kServicesProperty)[kTestServicePath2]); |
| 535 EXPECT_EQ(0, listener_->property_updates( | |
| 536 shill::kServiceCompleteListProperty)[kTestServicePath2]); | |
| 537 | |
| 538 // Change a property of a Network in a Profile. | |
| 539 base::FundamentalValue scan_interval(3); | |
| 540 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | |
| 541 dbus::ObjectPath(kTestServicePath2), | |
| 542 shill::kScanIntervalProperty, | |
| 543 scan_interval, | |
| 544 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | |
| 545 message_loop_.RunUntilIdle(); | |
| 546 // Property change should trigger an update for the Network only; no | |
| 547 // property updates pushed by Shill affect Favorites. | |
| 548 EXPECT_EQ(2, listener_->property_updates( | |
| 549 shill::kServicesProperty)[kTestServicePath2]); | |
| 550 EXPECT_EQ(0, listener_->property_updates( | |
| 551 shill::kServiceCompleteListProperty)[kTestServicePath2]); | |
| 552 } | 516 } |
| 553 | 517 |
| 554 } // namespace chromeos | 518 } // namespace chromeos |
| OLD | NEW |