| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 ShillManagerClient::TestInterface* manager_test_; | 281 ShillManagerClient::TestInterface* manager_test_; |
| 281 ShillDeviceClient::TestInterface* device_test_; | 282 ShillDeviceClient::TestInterface* device_test_; |
| 282 ShillServiceClient::TestInterface* service_test_; | 283 ShillServiceClient::TestInterface* service_test_; |
| 283 ShillProfileClient::TestInterface* profile_test_; | 284 ShillProfileClient::TestInterface* profile_test_; |
| 284 | 285 |
| 285 private: | 286 private: |
| 286 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); | 287 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); |
| 287 }; | 288 }; |
| 288 | 289 |
| 289 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { | 290 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { |
| 290 EXPECT_EQ(1, listener_->manager_updates()); | |
| 291 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( | 291 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( |
| 292 flimflam::kTypeWifi)); | 292 flimflam::kTypeWifi)); |
| 293 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( | 293 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( |
| 294 flimflam::kTypeWifi)); | 294 flimflam::kTypeWifi)); |
| 295 const size_t kNumShillManagerClientStubImplDevices = 2; | 295 const size_t kNumShillManagerClientStubImplDevices = 2; |
| 296 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 296 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 297 listener_->entries(flimflam::kDevicesProperty).size()); | 297 listener_->entries(flimflam::kDevicesProperty).size()); |
| 298 const size_t kNumShillManagerClientStubImplServices = 4; | 298 const size_t kNumShillManagerClientStubImplServices = 4; |
| 299 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 299 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 300 listener_->entries(flimflam::kServicesProperty).size()); | 300 listener_->entries(flimflam::kServicesProperty).size()); |
| 301 | 301 |
| 302 EXPECT_EQ(0, listener_->errors()); | 302 EXPECT_EQ(0, listener_->errors()); |
| 303 } | 303 } |
| 304 | 304 |
| 305 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { | 305 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { |
| 306 EXPECT_EQ(1, listener_->manager_updates()); | 306 const int initial_technology_updates = 2; // Available and Enabled lists |
| 307 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates()); |
| 307 | 308 |
| 308 // Remove a technology. Updates both the Available and Enabled lists. | 309 // Remove a technology. Updates both the Available and Enabled lists. |
| 309 manager_test_->RemoveTechnology(flimflam::kTypeWimax); | 310 manager_test_->RemoveTechnology(flimflam::kTypeWimax); |
| 310 message_loop_.RunUntilIdle(); | 311 message_loop_.RunUntilIdle(); |
| 311 EXPECT_EQ(3, listener_->manager_updates()); | 312 EXPECT_EQ(initial_technology_updates + 2, |
| 313 listener_->technology_list_updates()); |
| 312 | 314 |
| 313 // Add a disabled technology. | 315 // Add a disabled technology. |
| 314 manager_test_->AddTechnology(flimflam::kTypeWimax, false); | 316 manager_test_->AddTechnology(flimflam::kTypeWimax, false); |
| 315 message_loop_.RunUntilIdle(); | 317 message_loop_.RunUntilIdle(); |
| 316 EXPECT_EQ(4, listener_->manager_updates()); | 318 EXPECT_EQ(initial_technology_updates + 3, |
| 319 listener_->technology_list_updates()); |
| 317 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( | 320 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( |
| 318 flimflam::kTypeWimax)); | 321 flimflam::kTypeWimax)); |
| 319 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled( | 322 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled( |
| 320 flimflam::kTypeWimax)); | 323 flimflam::kTypeWimax)); |
| 321 | 324 |
| 322 // Enable the technology. | 325 // Enable the technology. |
| 323 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( | 326 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( |
| 324 flimflam::kTypeWimax, | 327 flimflam::kTypeWimax, |
| 325 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 328 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 326 message_loop_.RunUntilIdle(); | 329 message_loop_.RunUntilIdle(); |
| 327 EXPECT_EQ(5, listener_->manager_updates()); | 330 EXPECT_EQ(initial_technology_updates + 4, |
| 331 listener_->technology_list_updates()); |
| 328 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( | 332 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( |
| 329 flimflam::kTypeWimax)); | 333 flimflam::kTypeWimax)); |
| 330 | 334 |
| 331 EXPECT_EQ(0, listener_->errors()); | 335 EXPECT_EQ(0, listener_->errors()); |
| 332 } | 336 } |
| 333 | 337 |
| 334 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { | 338 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { |
| 335 EXPECT_EQ(1, listener_->manager_updates()); | |
| 336 EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); | 339 EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); |
| 337 const size_t kNumShillManagerClientStubImplDevices = 2; | 340 const size_t kNumShillManagerClientStubImplDevices = 2; |
| 338 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 341 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 339 listener_->entries(flimflam::kDevicesProperty).size()); | 342 listener_->entries(flimflam::kDevicesProperty).size()); |
| 340 // Add a device. | 343 // Add a device. |
| 341 const std::string kTestDevicePath("test_wifi_device1"); | 344 const std::string kTestDevicePath("test_wifi_device1"); |
| 342 AddDevice(flimflam::kTypeWifi, kTestDevicePath); | 345 AddDevice(flimflam::kTypeWifi, kTestDevicePath); |
| 343 message_loop_.RunUntilIdle(); | 346 message_loop_.RunUntilIdle(); |
| 344 EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. | |
| 345 EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); | 347 EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); |
| 346 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, | 348 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, |
| 347 listener_->entries(flimflam::kDevicesProperty).size()); | 349 listener_->entries(flimflam::kDevicesProperty).size()); |
| 348 // Device changes are not observed. | 350 // Device changes are not observed. |
| 349 // Remove a device | 351 // Remove a device |
| 350 RemoveDevice(kTestDevicePath); | 352 RemoveDevice(kTestDevicePath); |
| 351 message_loop_.RunUntilIdle(); | 353 message_loop_.RunUntilIdle(); |
| 352 EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); | 354 EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); |
| 353 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 355 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 354 listener_->entries(flimflam::kDevicesProperty).size()); | 356 listener_->entries(flimflam::kDevicesProperty).size()); |
| 355 | 357 |
| 356 EXPECT_EQ(0, listener_->errors()); | 358 EXPECT_EQ(0, listener_->errors()); |
| 357 } | 359 } |
| 358 | 360 |
| 359 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { | 361 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { |
| 360 EXPECT_EQ(1, listener_->manager_updates()); | |
| 361 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); | 362 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); |
| 362 const size_t kNumShillManagerClientStubImplServices = 4; | 363 const size_t kNumShillManagerClientStubImplServices = 4; |
| 363 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 364 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 364 listener_->entries(flimflam::kServicesProperty).size()); | 365 listener_->entries(flimflam::kServicesProperty).size()); |
| 365 | 366 |
| 366 // Add an unwatched service. | 367 // Add an unwatched service. |
| 367 const std::string kTestServicePath("test_wifi_service1"); | 368 const std::string kTestServicePath("test_wifi_service1"); |
| 368 AddService(flimflam::kTypeWifi, kTestServicePath, | 369 AddService(flimflam::kTypeWifi, kTestServicePath, |
| 369 flimflam::kStateIdle, false); | 370 flimflam::kStateIdle, false); |
| 370 message_loop_.RunUntilIdle(); | 371 message_loop_.RunUntilIdle(); |
| 371 EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. | |
| 372 // Watched and unwatched services trigger a service list update. | 372 // Watched and unwatched services trigger a service list update. |
| 373 EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); | 373 EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); |
| 374 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, | 374 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, |
| 375 listener_->entries(flimflam::kServicesProperty).size()); | 375 listener_->entries(flimflam::kServicesProperty).size()); |
| 376 // Service receives an initial property update. | 376 // Service receives an initial property update. |
| 377 EXPECT_EQ(1, listener_->initial_property_updates( | 377 EXPECT_EQ(1, listener_->initial_property_updates( |
| 378 flimflam::kServicesProperty)[kTestServicePath]); | 378 flimflam::kServicesProperty)[kTestServicePath]); |
| 379 // Change a property. | 379 // Change a property. |
| 380 base::FundamentalValue scan_interval(3); | 380 base::FundamentalValue scan_interval(3); |
| 381 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | 381 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 message_loop_.RunUntilIdle(); | 532 message_loop_.RunUntilIdle(); |
| 533 // Property change should trigger an update for the Network only; no | 533 // Property change should trigger an update for the Network only; no |
| 534 // property updates pushed by Shill affect Favorites. | 534 // property updates pushed by Shill affect Favorites. |
| 535 EXPECT_EQ(2, listener_->property_updates( | 535 EXPECT_EQ(2, listener_->property_updates( |
| 536 flimflam::kServicesProperty)[kTestServicePath2]); | 536 flimflam::kServicesProperty)[kTestServicePath2]); |
| 537 EXPECT_EQ(0, listener_->property_updates( | 537 EXPECT_EQ(0, listener_->property_updates( |
| 538 shill::kServiceCompleteListProperty)[kTestServicePath2]); | 538 shill::kServiceCompleteListProperty)[kTestServicePath2]); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace chromeos | 541 } // namespace chromeos |
| OLD | NEW |