| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 ASSERT_TRUE(IsValidType(type)); | 181 ASSERT_TRUE(IsValidType(type)); |
| 182 service_test_->AddService(id, id, type, state, add_to_watch_list); | 182 service_test_->AddService(id, id, type, state, add_to_watch_list); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void RemoveService(const std::string& id) { | 185 void RemoveService(const std::string& id) { |
| 186 service_test_->RemoveService(id); | 186 service_test_->RemoveService(id); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Call this after any initial Shill client setup | 189 // Call this after any initial Shill client setup |
| 190 void SetupShillPropertyHandler() { | 190 void SetupShillPropertyHandler() { |
| 191 SetupDefaultShillState(); |
| 191 listener_.reset(new TestListener); | 192 listener_.reset(new TestListener); |
| 192 shill_property_handler_.reset( | 193 shill_property_handler_.reset( |
| 193 new internal::ShillPropertyHandler(listener_.get())); | 194 new internal::ShillPropertyHandler(listener_.get())); |
| 194 shill_property_handler_->Init(); | 195 shill_property_handler_->Init(); |
| 195 } | 196 } |
| 196 | 197 |
| 197 bool IsValidType(const std::string& type) { | 198 bool IsValidType(const std::string& type) { |
| 198 return (type == flimflam::kTypeEthernet || | 199 return (type == flimflam::kTypeEthernet || |
| 199 type == flimflam::kTypeWifi || | 200 type == flimflam::kTypeWifi || |
| 200 type == flimflam::kTypeWimax || | 201 type == flimflam::kTypeWimax || |
| 201 type == flimflam::kTypeBluetooth || | 202 type == flimflam::kTypeBluetooth || |
| 202 type == flimflam::kTypeCellular || | 203 type == flimflam::kTypeCellular || |
| 203 type == flimflam::kTypeVPN); | 204 type == flimflam::kTypeVPN); |
| 204 } | 205 } |
| 205 | 206 |
| 206 protected: | 207 protected: |
| 208 void SetupDefaultShillState() { |
| 209 message_loop_.RunUntilIdle(); // Process any pending updates |
| 210 device_test_->ClearDevices(); |
| 211 AddDevice(flimflam::kTypeWifi, "stub_wifi_device1"); |
| 212 AddDevice(flimflam::kTypeCellular, "stub_cellular_device1"); |
| 213 service_test_->ClearServices(); |
| 214 const bool add_to_watchlist = true; |
| 215 AddService(flimflam::kTypeEthernet, "stub_ethernet", |
| 216 flimflam::kStateOnline, add_to_watchlist); |
| 217 AddService(flimflam::kTypeWifi, "stub_wifi1", |
| 218 flimflam::kStateOnline, add_to_watchlist); |
| 219 AddService(flimflam::kTypeWifi, "stub_wifi2", |
| 220 flimflam::kStateIdle, add_to_watchlist); |
| 221 AddService(flimflam::kTypeCellular, "stub_cellular1", |
| 222 flimflam::kStateIdle, add_to_watchlist); |
| 223 } |
| 224 |
| 207 MessageLoopForUI message_loop_; | 225 MessageLoopForUI message_loop_; |
| 208 scoped_ptr<TestListener> listener_; | 226 scoped_ptr<TestListener> listener_; |
| 209 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; | 227 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; |
| 210 ShillManagerClient::TestInterface* manager_test_; | 228 ShillManagerClient::TestInterface* manager_test_; |
| 211 ShillDeviceClient::TestInterface* device_test_; | 229 ShillDeviceClient::TestInterface* device_test_; |
| 212 ShillServiceClient::TestInterface* service_test_; | 230 ShillServiceClient::TestInterface* service_test_; |
| 213 | 231 |
| 214 private: | 232 private: |
| 215 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); | 233 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); |
| 216 }; | 234 }; |
| 217 | 235 |
| 218 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { | 236 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { |
| 219 SetupShillPropertyHandler(); | 237 SetupShillPropertyHandler(); |
| 220 message_loop_.RunUntilIdle(); | 238 message_loop_.RunUntilIdle(); |
| 221 EXPECT_EQ(1, listener_->manager_updates()); | 239 EXPECT_EQ(1, listener_->manager_updates()); |
| 222 // ShillManagerClient default stub entries are in shill_manager_client.cc. | |
| 223 // TODO(stevenjb): Eliminate default stub entries and add them explicitly. | |
| 224 EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( | 240 EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( |
| 225 flimflam::kTypeWifi)); | 241 flimflam::kTypeWifi)); |
| 226 EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( | 242 EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( |
| 227 flimflam::kTypeWifi)); | 243 flimflam::kTypeWifi)); |
| 228 const size_t kNumShillManagerClientStubImplDevices = 2; | 244 const size_t kNumShillManagerClientStubImplDevices = 2; |
| 229 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 245 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 230 listener_->entries(flimflam::kDevicesProperty).size()); | 246 listener_->entries(flimflam::kDevicesProperty).size()); |
| 231 const size_t kNumShillManagerClientStubImplServices = 4; | 247 const size_t kNumShillManagerClientStubImplServices = 4; |
| 232 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 248 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 233 listener_->entries(flimflam::kServicesProperty).size()); | 249 listener_->entries(flimflam::kServicesProperty).size()); |
| 234 | 250 |
| 235 EXPECT_EQ(0, listener_->errors()); | 251 EXPECT_EQ(0, listener_->errors()); |
| 236 } | 252 } |
| 237 | 253 |
| 238 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { | 254 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { |
| 239 // This relies on the stub dbus implementations for ShillManagerClient, | |
| 240 SetupShillPropertyHandler(); | 255 SetupShillPropertyHandler(); |
| 241 message_loop_.RunUntilIdle(); | 256 message_loop_.RunUntilIdle(); |
| 242 EXPECT_EQ(1, listener_->manager_updates()); | 257 EXPECT_EQ(1, listener_->manager_updates()); |
| 243 // Add a disabled technology. | 258 // Add a disabled technology. |
| 244 manager_test_->AddTechnology(flimflam::kTypeWimax, false); | 259 manager_test_->AddTechnology(flimflam::kTypeWimax, false); |
| 245 message_loop_.RunUntilIdle(); | 260 message_loop_.RunUntilIdle(); |
| 246 EXPECT_EQ(2, listener_->manager_updates()); | 261 EXPECT_EQ(2, listener_->manager_updates()); |
| 247 EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( | 262 EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( |
| 248 flimflam::kTypeWimax)); | 263 flimflam::kTypeWimax)); |
| 249 EXPECT_FALSE(shill_property_handler_->TechnologyEnabled( | 264 EXPECT_FALSE(shill_property_handler_->TechnologyEnabled( |
| 250 flimflam::kTypeWimax)); | 265 flimflam::kTypeWimax)); |
| 251 | 266 |
| 252 // Enable the technology. | 267 // Enable the technology. |
| 253 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( | 268 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( |
| 254 flimflam::kTypeWimax, | 269 flimflam::kTypeWimax, |
| 255 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); | 270 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 256 message_loop_.RunUntilIdle(); | 271 message_loop_.RunUntilIdle(); |
| 257 EXPECT_EQ(3, listener_->manager_updates()); | 272 EXPECT_EQ(3, listener_->manager_updates()); |
| 258 EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( | 273 EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( |
| 259 flimflam::kTypeWimax)); | 274 flimflam::kTypeWimax)); |
| 260 | 275 |
| 261 EXPECT_EQ(0, listener_->errors()); | 276 EXPECT_EQ(0, listener_->errors()); |
| 262 } | 277 } |
| 263 | 278 |
| 264 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { | 279 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { |
| 265 // This relies on the stub dbus implementations for ShillManagerClient, | |
| 266 SetupShillPropertyHandler(); | 280 SetupShillPropertyHandler(); |
| 267 message_loop_.RunUntilIdle(); | 281 message_loop_.RunUntilIdle(); |
| 268 EXPECT_EQ(1, listener_->manager_updates()); | 282 EXPECT_EQ(1, listener_->manager_updates()); |
| 269 EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); | 283 EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); |
| 270 const size_t kNumShillManagerClientStubImplDevices = 2; | 284 const size_t kNumShillManagerClientStubImplDevices = 2; |
| 271 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 285 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 272 listener_->entries(flimflam::kDevicesProperty).size()); | 286 listener_->entries(flimflam::kDevicesProperty).size()); |
| 273 // Add a device. | 287 // Add a device. |
| 274 const std::string kTestDevicePath("test_wifi_device1"); | 288 const std::string kTestDevicePath("test_wifi_device1"); |
| 275 AddDevice(flimflam::kTypeWifi, kTestDevicePath); | 289 AddDevice(flimflam::kTypeWifi, kTestDevicePath); |
| 276 message_loop_.RunUntilIdle(); | 290 message_loop_.RunUntilIdle(); |
| 277 EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. | 291 EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. |
| 278 EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); | 292 EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); |
| 279 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, | 293 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, |
| 280 listener_->entries(flimflam::kDevicesProperty).size()); | 294 listener_->entries(flimflam::kDevicesProperty).size()); |
| 281 // Device changes are not observed. | 295 // Device changes are not observed. |
| 282 // Remove a device | 296 // Remove a device |
| 283 RemoveDevice(kTestDevicePath); | 297 RemoveDevice(kTestDevicePath); |
| 284 message_loop_.RunUntilIdle(); | 298 message_loop_.RunUntilIdle(); |
| 285 EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); | 299 EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); |
| 286 EXPECT_EQ(kNumShillManagerClientStubImplDevices, | 300 EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
| 287 listener_->entries(flimflam::kDevicesProperty).size()); | 301 listener_->entries(flimflam::kDevicesProperty).size()); |
| 288 | 302 |
| 289 EXPECT_EQ(0, listener_->errors()); | 303 EXPECT_EQ(0, listener_->errors()); |
| 290 } | 304 } |
| 291 | 305 |
| 292 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { | 306 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { |
| 293 // This relies on the stub dbus implementations for ShillManagerClient, | |
| 294 SetupShillPropertyHandler(); | 307 SetupShillPropertyHandler(); |
| 295 message_loop_.RunUntilIdle(); | 308 message_loop_.RunUntilIdle(); |
| 296 EXPECT_EQ(1, listener_->manager_updates()); | 309 EXPECT_EQ(1, listener_->manager_updates()); |
| 297 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); | 310 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); |
| 298 const size_t kNumShillManagerClientStubImplServices = 4; | 311 const size_t kNumShillManagerClientStubImplServices = 4; |
| 299 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 312 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 300 listener_->entries(flimflam::kServicesProperty).size()); | 313 listener_->entries(flimflam::kServicesProperty).size()); |
| 301 | 314 |
| 302 // Add an unwatched service. | 315 // Add an unwatched service. |
| 303 const std::string kTestServicePath("test_wifi_service1"); | 316 const std::string kTestServicePath("test_wifi_service1"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 EXPECT_EQ(3, listener_->list_updates(flimflam::kServicesProperty)); | 364 EXPECT_EQ(3, listener_->list_updates(flimflam::kServicesProperty)); |
| 352 EXPECT_EQ(kNumShillManagerClientStubImplServices, | 365 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 353 listener_->entries(flimflam::kServicesProperty).size()); | 366 listener_->entries(flimflam::kServicesProperty).size()); |
| 354 | 367 |
| 355 EXPECT_EQ(0, listener_->errors()); | 368 EXPECT_EQ(0, listener_->errors()); |
| 356 } | 369 } |
| 357 | 370 |
| 358 // TODO(stevenjb): Test IP Configs. | 371 // TODO(stevenjb): Test IP Configs. |
| 359 | 372 |
| 360 } // namespace chromeos | 373 } // namespace chromeos |
| OLD | NEW |