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/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() : manager_updates_(0), errors_(0) { | 39 TestListener() : technology_list_updates_(0), |
| 40 errors_(0) { | |
| 40 } | 41 } |
| 41 | 42 |
| 42 virtual void UpdateManagedList(ManagedState::ManagedType type, | 43 virtual void UpdateManagedList(ManagedState::ManagedType type, |
| 43 const base::ListValue& entries) OVERRIDE { | 44 const base::ListValue& entries) OVERRIDE { |
| 44 UpdateEntries(GetTypeString(type), entries); | 45 UpdateEntries(GetTypeString(type), entries); |
| 45 } | 46 } |
| 46 | 47 |
| 47 virtual void UpdateManagedStateProperties( | 48 virtual void UpdateManagedStateProperties( |
| 48 ManagedState::ManagedType type, | 49 ManagedState::ManagedType type, |
| 49 const std::string& path, | 50 const std::string& path, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 61 AddPropertyUpdate(flimflam::kServicesProperty, service_path); | 62 AddPropertyUpdate(flimflam::kServicesProperty, service_path); |
| 62 } | 63 } |
| 63 | 64 |
| 64 virtual void UpdateDeviceProperty( | 65 virtual void UpdateDeviceProperty( |
| 65 const std::string& device_path, | 66 const std::string& device_path, |
| 66 const std::string& key, | 67 const std::string& key, |
| 67 const base::Value& value) OVERRIDE { | 68 const base::Value& value) OVERRIDE { |
| 68 AddPropertyUpdate(flimflam::kDevicesProperty, device_path); | 69 AddPropertyUpdate(flimflam::kDevicesProperty, device_path); |
| 69 } | 70 } |
| 70 | 71 |
| 71 virtual void NotifyManagerPropertyChanged() OVERRIDE { | 72 virtual void TechnologyListChanged() OVERRIDE { |
| 72 ++manager_updates_; | 73 ++technology_list_updates_; |
| 73 } | 74 } |
| 74 | 75 |
| 75 virtual void CheckPortalListChanged( | 76 virtual void CheckPortalListChanged( |
| 76 const std::string& check_portal_list) OVERRIDE { | 77 const std::string& check_portal_list) OVERRIDE { |
| 77 } | 78 } |
| 78 | 79 |
| 79 virtual void ManagedStateListChanged( | 80 virtual void ManagedStateListChanged( |
| 80 ManagedState::ManagedType type) OVERRIDE { | 81 ManagedState::ManagedType type) OVERRIDE { |
| 81 AddStateListUpdate(GetTypeString(type)); | 82 AddStateListUpdate(GetTypeString(type)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 std::vector<std::string>& entries(const std::string& type) { | 85 std::vector<std::string>& entries(const std::string& type) { |
| 85 return entries_[type]; | 86 return entries_[type]; |
| 86 } | 87 } |
| 87 std::map<std::string, int>& property_updates(const std::string& type) { | 88 std::map<std::string, int>& property_updates(const std::string& type) { |
| 88 return property_updates_[type]; | 89 return property_updates_[type]; |
| 89 } | 90 } |
| 90 std::map<std::string, int>& initial_property_updates( | 91 std::map<std::string, int>& initial_property_updates( |
| 91 const std::string& type) { | 92 const std::string& type) { |
| 92 return initial_property_updates_[type]; | 93 return initial_property_updates_[type]; |
| 93 } | 94 } |
| 94 int list_updates(const std::string& type) { return list_updates_[type]; } | 95 int list_updates(const std::string& type) { return list_updates_[type]; } |
| 95 int manager_updates() { return manager_updates_; } | 96 int technology_list_updates() { return technology_list_updates_; } |
| 96 int errors() { return errors_; } | 97 int errors() { return errors_; } |
| 97 | 98 |
| 98 private: | 99 private: |
| 99 std::string GetTypeString(ManagedState::ManagedType type) { | 100 std::string GetTypeString(ManagedState::ManagedType type) { |
| 100 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 101 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
| 101 return flimflam::kServicesProperty; | 102 return flimflam::kServicesProperty; |
| 102 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { | 103 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { |
| 103 return shill::kServiceCompleteListProperty; | 104 return shill::kServiceCompleteListProperty; |
| 104 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 105 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
| 105 return flimflam::kDevicesProperty; | 106 return flimflam::kDevicesProperty; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 list_updates_[type] += 1; | 141 list_updates_[type] += 1; |
| 141 } | 142 } |
| 142 | 143 |
| 143 // Map of list-type -> paths | 144 // Map of list-type -> paths |
| 144 std::map<std::string, std::vector<std::string> > entries_; | 145 std::map<std::string, std::vector<std::string> > entries_; |
| 145 // Map of list-type -> map of paths -> update counts | 146 // Map of list-type -> map of paths -> update counts |
| 146 std::map<std::string, std::map<std::string, int> > property_updates_; | 147 std::map<std::string, std::map<std::string, int> > property_updates_; |
| 147 std::map<std::string, std::map<std::string, int> > initial_property_updates_; | 148 std::map<std::string, std::map<std::string, int> > initial_property_updates_; |
| 148 // Map of list-type -> list update counts | 149 // Map of list-type -> list update counts |
| 149 std::map<std::string, int > list_updates_; | 150 std::map<std::string, int > list_updates_; |
| 150 int manager_updates_; | 151 int technology_list_updates_; |
| 151 int errors_; | 152 int errors_; |
| 152 }; | 153 }; |
| 153 | 154 |
| 154 } // namespace | 155 } // namespace |
| 155 | 156 |
| 156 class ShillPropertyHandlerTest : public testing::Test { | 157 class ShillPropertyHandlerTest : public testing::Test { |
| 157 public: | 158 public: |
| 158 ShillPropertyHandlerTest() | 159 ShillPropertyHandlerTest() |
| 159 : manager_test_(NULL), | 160 : manager_test_(NULL), |
| 160 device_test_(NULL), | 161 device_test_(NULL), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 ShillManagerClient::TestInterface* manager_test_; | 280 ShillManagerClient::TestInterface* manager_test_; |
| 280 ShillDeviceClient::TestInterface* device_test_; | 281 ShillDeviceClient::TestInterface* device_test_; |
| 281 ShillServiceClient::TestInterface* service_test_; | 282 ShillServiceClient::TestInterface* service_test_; |
| 282 ShillProfileClient::TestInterface* profile_test_; | 283 ShillProfileClient::TestInterface* profile_test_; |
| 283 | 284 |
| 284 private: | 285 private: |
| 285 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); | 286 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); |
| 286 }; | 287 }; |
| 287 | 288 |
| 288 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { | 289 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { |
| 289 EXPECT_EQ(1, listener_->manager_updates()); | |
| 290 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( | 290 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( |
| 291 flimflam::kTypeWifi)); | 291 flimflam::kTypeWifi)); |
| 292 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( | 292 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( |
| 293 flimflam::kTypeWifi)); | 293 flimflam::kTypeWifi)); |
| 294 const size_t kNumShillManagerClientStubImplDevices = 2; | 294 const size_t kNumShillManagerClientStubImplDevices = 2; |
| 295 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 295 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 296 listener_->entries(flimflam::kDevicesProperty).size()); | 296 listener_->entries(flimflam::kDevicesProperty).size()); |
| 297 const size_t kNumShillManagerClientStubImplServices = 4; | 297 const size_t kNumShillManagerClientStubImplServices = 4; |
| 298 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 298 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 299 listener_->entries(flimflam::kServicesProperty).size()); | 299 listener_->entries(flimflam::kServicesProperty).size()); |
| 300 | 300 |
| 301 EXPECT_EQ(0, listener_->errors()); | 301 EXPECT_EQ(0, listener_->errors()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { | 304 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { |
| 305 EXPECT_EQ(1, listener_->manager_updates()); | 305 const int initial_technology_updates = 2; // Available and Enabled lists |
|
pneubeck (no reviews)
2013/09/11 20:13:35
did the number of notifications increase for Updat
stevenjb
2013/09/11 21:23:46
UpdateManagerProperties() will trigger 2 notificat
| |
| 306 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates()); | |
| 306 | 307 |
| 307 // Remove a technology. Updates both the Available and Enabled lists. | 308 // Remove a technology. Updates both the Available and Enabled lists. |
| 308 manager_test_->RemoveTechnology(flimflam::kTypeWimax); | 309 manager_test_->RemoveTechnology(flimflam::kTypeWimax); |
| 309 message_loop_.RunUntilIdle(); | 310 message_loop_.RunUntilIdle(); |
| 310 EXPECT_EQ(3, listener_->manager_updates()); | 311 EXPECT_EQ(initial_technology_updates + 2, |
| 312 listener_->technology_list_updates()); | |
| 311 | 313 |
| 312 // Add a disabled technology. | 314 // Add a disabled technology. |
| 313 manager_test_->AddTechnology(flimflam::kTypeWimax, false); | 315 manager_test_->AddTechnology(flimflam::kTypeWimax, false); |
| 314 message_loop_.RunUntilIdle(); | 316 message_loop_.RunUntilIdle(); |
| 315 EXPECT_EQ(4, listener_->manager_updates()); | 317 EXPECT_EQ(initial_technology_updates + 3, |
| 318 listener_->technology_list_updates()); | |
| 316 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( | 319 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( |
| 317 flimflam::kTypeWimax)); | 320 flimflam::kTypeWimax)); |
| 318 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled( | 321 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled( |
| 319 flimflam::kTypeWimax)); | 322 flimflam::kTypeWimax)); |
| 320 | 323 |
| 321 // Enable the technology. | 324 // Enable the technology. |
| 322 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( | 325 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( |
| 323 flimflam::kTypeWimax, | 326 flimflam::kTypeWimax, |
| 324 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 327 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 325 message_loop_.RunUntilIdle(); | 328 message_loop_.RunUntilIdle(); |
| 326 EXPECT_EQ(5, listener_->manager_updates()); | 329 EXPECT_EQ(initial_technology_updates + 4, |
| 330 listener_->technology_list_updates()); | |
| 327 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( | 331 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( |
| 328 flimflam::kTypeWimax)); | 332 flimflam::kTypeWimax)); |
| 329 | 333 |
| 330 EXPECT_EQ(0, listener_->errors()); | 334 EXPECT_EQ(0, listener_->errors()); |
| 331 } | 335 } |
| 332 | 336 |
| 333 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { | 337 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { |
| 334 EXPECT_EQ(1, listener_->manager_updates()); | |
|
pneubeck (no reviews)
2013/09/11 20:13:35
could you modify the listener_ to through an error
stevenjb
2013/09/11 21:23:46
We test the NetworkStateHandler notification count
| |
| 335 EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); | 338 EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); |
| 336 const size_t kNumShillManagerClientStubImplDevices = 2; | 339 const size_t kNumShillManagerClientStubImplDevices = 2; |
| 337 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 340 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 338 listener_->entries(flimflam::kDevicesProperty).size()); | 341 listener_->entries(flimflam::kDevicesProperty).size()); |
| 339 // Add a device. | 342 // Add a device. |
| 340 const std::string kTestDevicePath("test_wifi_device1"); | 343 const std::string kTestDevicePath("test_wifi_device1"); |
| 341 AddDevice(flimflam::kTypeWifi, kTestDevicePath); | 344 AddDevice(flimflam::kTypeWifi, kTestDevicePath); |
| 342 message_loop_.RunUntilIdle(); | 345 message_loop_.RunUntilIdle(); |
| 343 EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. | |
| 344 EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); | 346 EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); |
| 345 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, | 347 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, |
| 346 listener_->entries(flimflam::kDevicesProperty).size()); | 348 listener_->entries(flimflam::kDevicesProperty).size()); |
| 347 // Device changes are not observed. | 349 // Device changes are not observed. |
| 348 // Remove a device | 350 // Remove a device |
| 349 RemoveDevice(kTestDevicePath); | 351 RemoveDevice(kTestDevicePath); |
| 350 message_loop_.RunUntilIdle(); | 352 message_loop_.RunUntilIdle(); |
| 351 EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); | 353 EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); |
| 352 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 354 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 353 listener_->entries(flimflam::kDevicesProperty).size()); | 355 listener_->entries(flimflam::kDevicesProperty).size()); |
| 354 | 356 |
| 355 EXPECT_EQ(0, listener_->errors()); | 357 EXPECT_EQ(0, listener_->errors()); |
| 356 } | 358 } |
| 357 | 359 |
| 358 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { | 360 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { |
| 359 EXPECT_EQ(1, listener_->manager_updates()); | |
| 360 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); | 361 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); |
| 361 const size_t kNumShillManagerClientStubImplServices = 4; | 362 const size_t kNumShillManagerClientStubImplServices = 4; |
| 362 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 363 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 363 listener_->entries(flimflam::kServicesProperty).size()); | 364 listener_->entries(flimflam::kServicesProperty).size()); |
| 364 | 365 |
| 365 // Add an unwatched service. | 366 // Add an unwatched service. |
| 366 const std::string kTestServicePath("test_wifi_service1"); | 367 const std::string kTestServicePath("test_wifi_service1"); |
| 367 AddService(flimflam::kTypeWifi, kTestServicePath, | 368 AddService(flimflam::kTypeWifi, kTestServicePath, |
| 368 flimflam::kStateIdle, false); | 369 flimflam::kStateIdle, false); |
| 369 message_loop_.RunUntilIdle(); | 370 message_loop_.RunUntilIdle(); |
| 370 EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. | |
| 371 // Watched and unwatched services trigger a service list update. | 371 // Watched and unwatched services trigger a service list update. |
| 372 EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); | 372 EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); |
| 373 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, | 373 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, |
| 374 listener_->entries(flimflam::kServicesProperty).size()); | 374 listener_->entries(flimflam::kServicesProperty).size()); |
| 375 // Service receives an initial property update. | 375 // Service receives an initial property update. |
| 376 EXPECT_EQ(1, listener_->initial_property_updates( | 376 EXPECT_EQ(1, listener_->initial_property_updates( |
| 377 flimflam::kServicesProperty)[kTestServicePath]); | 377 flimflam::kServicesProperty)[kTestServicePath]); |
| 378 // Change a property. | 378 // Change a property. |
| 379 base::FundamentalValue scan_interval(3); | 379 base::FundamentalValue scan_interval(3); |
| 380 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 380 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 message_loop_.RunUntilIdle(); | 531 message_loop_.RunUntilIdle(); |
| 532 // Property change should trigger an update for the Network only; no | 532 // Property change should trigger an update for the Network only; no |
| 533 // property updates pushed by Shill affect Favorites. | 533 // property updates pushed by Shill affect Favorites. |
| 534 EXPECT_EQ(2, listener_->property_updates( | 534 EXPECT_EQ(2, listener_->property_updates( |
| 535 flimflam::kServicesProperty)[kTestServicePath2]); | 535 flimflam::kServicesProperty)[kTestServicePath2]); |
| 536 EXPECT_EQ(0, listener_->property_updates( | 536 EXPECT_EQ(0, listener_->property_updates( |
| 537 shill::kServiceCompleteListProperty)[kTestServicePath2]); | 537 shill::kServiceCompleteListProperty)[kTestServicePath2]); |
| 538 } | 538 } |
| 539 | 539 |
| 540 } // namespace chromeos | 540 } // namespace chromeos |
| OLD | NEW |