Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: chromeos/network/shill_property_handler_unittest.cc

Issue 24348002: Migrate DBus service constants from flimflam namespace to shill namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased to ToT Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/network/shill_property_handler.cc ('k') | chromeos/network/shill_property_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 AddInitialPropertyUpdate(GetTypeString(type), path); 52 AddInitialPropertyUpdate(GetTypeString(type), path);
53 } 53 }
54 54
55 virtual void ProfileListChanged() OVERRIDE { 55 virtual void ProfileListChanged() OVERRIDE {
56 } 56 }
57 57
58 virtual void UpdateNetworkServiceProperty( 58 virtual void UpdateNetworkServiceProperty(
59 const std::string& service_path, 59 const std::string& service_path,
60 const std::string& key, 60 const std::string& key,
61 const base::Value& value) OVERRIDE { 61 const base::Value& value) OVERRIDE {
62 AddPropertyUpdate(flimflam::kServicesProperty, service_path); 62 AddPropertyUpdate(shill::kServicesProperty, service_path);
63 } 63 }
64 64
65 virtual void UpdateDeviceProperty( 65 virtual void UpdateDeviceProperty(
66 const std::string& device_path, 66 const std::string& device_path,
67 const std::string& key, 67 const std::string& key,
68 const base::Value& value) OVERRIDE { 68 const base::Value& value) OVERRIDE {
69 AddPropertyUpdate(flimflam::kDevicesProperty, device_path); 69 AddPropertyUpdate(shill::kDevicesProperty, device_path);
70 } 70 }
71 71
72 virtual void TechnologyListChanged() OVERRIDE { 72 virtual void TechnologyListChanged() OVERRIDE {
73 ++technology_list_updates_; 73 ++technology_list_updates_;
74 } 74 }
75 75
76 virtual void CheckPortalListChanged( 76 virtual void CheckPortalListChanged(
77 const std::string& check_portal_list) OVERRIDE { 77 const std::string& check_portal_list) OVERRIDE {
78 } 78 }
79 79
(...skipping 12 matching lines...) Expand all
92 const std::string& type) { 92 const std::string& type) {
93 return initial_property_updates_[type]; 93 return initial_property_updates_[type];
94 } 94 }
95 int list_updates(const std::string& type) { return list_updates_[type]; } 95 int list_updates(const std::string& type) { return list_updates_[type]; }
96 int technology_list_updates() { return technology_list_updates_; } 96 int technology_list_updates() { return technology_list_updates_; }
97 int errors() { return errors_; } 97 int errors() { return errors_; }
98 98
99 private: 99 private:
100 std::string GetTypeString(ManagedState::ManagedType type) { 100 std::string GetTypeString(ManagedState::ManagedType type) {
101 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 101 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
102 return flimflam::kServicesProperty; 102 return shill::kServicesProperty;
103 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { 103 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) {
104 return shill::kServiceCompleteListProperty; 104 return shill::kServiceCompleteListProperty;
105 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 105 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
106 return flimflam::kDevicesProperty; 106 return shill::kDevicesProperty;
107 } 107 }
108 LOG(ERROR) << "UpdateManagedList called with unrecognized type: " << type; 108 LOG(ERROR) << "UpdateManagedList called with unrecognized type: " << type;
109 ++errors_; 109 ++errors_;
110 return std::string(); 110 return std::string();
111 } 111 }
112 112
113 void UpdateEntries(const std::string& type, const base::ListValue& entries) { 113 void UpdateEntries(const std::string& type, const base::ListValue& entries) {
114 if (type.empty()) 114 if (type.empty())
115 return; 115 return;
116 entries_[type].clear(); 116 entries_[type].clear();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ASSERT_TRUE(IsValidType(type)); 218 ASSERT_TRUE(IsValidType(type));
219 service_test_->AddServiceWithIPConfig(id, id, type, state, 219 service_test_->AddServiceWithIPConfig(id, id, type, state,
220 ipconfig_path, 220 ipconfig_path,
221 true /* visible */, 221 true /* visible */,
222 add_to_watch_list); 222 add_to_watch_list);
223 } 223 }
224 224
225 void AddServiceToProfile(const std::string& type, 225 void AddServiceToProfile(const std::string& type,
226 const std::string& id, 226 const std::string& id,
227 bool visible) { 227 bool visible) {
228 service_test_->AddService(id, id, type, flimflam::kStateIdle, 228 service_test_->AddService(id, id, type, shill::kStateIdle,
229 visible, false /* watch */); 229 visible, false /* watch */);
230 std::vector<std::string> profiles; 230 std::vector<std::string> profiles;
231 profile_test_->GetProfilePaths(&profiles); 231 profile_test_->GetProfilePaths(&profiles);
232 ASSERT_TRUE(profiles.size() > 0); 232 ASSERT_TRUE(profiles.size() > 0);
233 base::DictionaryValue properties; // Empty entry 233 base::DictionaryValue properties; // Empty entry
234 profile_test_->AddService(profiles[0], id); 234 profile_test_->AddService(profiles[0], id);
235 } 235 }
236 236
237 void RemoveService(const std::string& id) { 237 void RemoveService(const std::string& id) {
238 service_test_->RemoveService(id); 238 service_test_->RemoveService(id);
239 } 239 }
240 240
241 // Call this after any initial Shill client setup 241 // Call this after any initial Shill client setup
242 void SetupShillPropertyHandler() { 242 void SetupShillPropertyHandler() {
243 SetupDefaultShillState(); 243 SetupDefaultShillState();
244 listener_.reset(new TestListener); 244 listener_.reset(new TestListener);
245 shill_property_handler_.reset( 245 shill_property_handler_.reset(
246 new internal::ShillPropertyHandler(listener_.get())); 246 new internal::ShillPropertyHandler(listener_.get()));
247 shill_property_handler_->Init(); 247 shill_property_handler_->Init();
248 } 248 }
249 249
250 bool IsValidType(const std::string& type) { 250 bool IsValidType(const std::string& type) {
251 return (type == flimflam::kTypeEthernet || 251 return (type == shill::kTypeEthernet ||
252 type == shill::kTypeEthernetEap || 252 type == shill::kTypeEthernetEap ||
253 type == flimflam::kTypeWifi || 253 type == shill::kTypeWifi ||
254 type == flimflam::kTypeWimax || 254 type == shill::kTypeWimax ||
255 type == flimflam::kTypeBluetooth || 255 type == shill::kTypeBluetooth ||
256 type == flimflam::kTypeCellular || 256 type == shill::kTypeCellular ||
257 type == flimflam::kTypeVPN); 257 type == shill::kTypeVPN);
258 } 258 }
259 259
260 protected: 260 protected:
261 void SetupDefaultShillState() { 261 void SetupDefaultShillState() {
262 message_loop_.RunUntilIdle(); // Process any pending updates 262 message_loop_.RunUntilIdle(); // Process any pending updates
263 device_test_->ClearDevices(); 263 device_test_->ClearDevices();
264 AddDevice(flimflam::kTypeWifi, "stub_wifi_device1"); 264 AddDevice(shill::kTypeWifi, "stub_wifi_device1");
265 AddDevice(flimflam::kTypeCellular, "stub_cellular_device1"); 265 AddDevice(shill::kTypeCellular, "stub_cellular_device1");
266 service_test_->ClearServices(); 266 service_test_->ClearServices();
267 const bool add_to_watchlist = true; 267 const bool add_to_watchlist = true;
268 AddService(flimflam::kTypeEthernet, "stub_ethernet", 268 AddService(shill::kTypeEthernet, "stub_ethernet",
269 flimflam::kStateOnline, add_to_watchlist); 269 shill::kStateOnline, add_to_watchlist);
270 AddService(flimflam::kTypeWifi, "stub_wifi1", 270 AddService(shill::kTypeWifi, "stub_wifi1",
271 flimflam::kStateOnline, add_to_watchlist); 271 shill::kStateOnline, add_to_watchlist);
272 AddService(flimflam::kTypeWifi, "stub_wifi2", 272 AddService(shill::kTypeWifi, "stub_wifi2",
273 flimflam::kStateIdle, add_to_watchlist); 273 shill::kStateIdle, add_to_watchlist);
274 AddService(flimflam::kTypeCellular, "stub_cellular1", 274 AddService(shill::kTypeCellular, "stub_cellular1",
275 flimflam::kStateIdle, add_to_watchlist); 275 shill::kStateIdle, add_to_watchlist);
276 } 276 }
277 277
278 base::MessageLoopForUI message_loop_; 278 base::MessageLoopForUI message_loop_;
279 scoped_ptr<TestListener> listener_; 279 scoped_ptr<TestListener> listener_;
280 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; 280 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_;
281 ShillManagerClient::TestInterface* manager_test_; 281 ShillManagerClient::TestInterface* manager_test_;
282 ShillDeviceClient::TestInterface* device_test_; 282 ShillDeviceClient::TestInterface* device_test_;
283 ShillServiceClient::TestInterface* service_test_; 283 ShillServiceClient::TestInterface* service_test_;
284 ShillProfileClient::TestInterface* profile_test_; 284 ShillProfileClient::TestInterface* profile_test_;
285 285
286 private: 286 private:
287 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); 287 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest);
288 }; 288 };
289 289
290 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { 290 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) {
291 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( 291 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(shill::kTypeWifi));
292 flimflam::kTypeWifi)); 292 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi));
293 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(
294 flimflam::kTypeWifi));
295 const size_t kNumShillManagerClientStubImplDevices = 2; 293 const size_t kNumShillManagerClientStubImplDevices = 2;
296 EXPECT_EQ(kNumShillManagerClientStubImplDevices, 294 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
297 listener_->entries(flimflam::kDevicesProperty).size()); 295 listener_->entries(shill::kDevicesProperty).size());
298 const size_t kNumShillManagerClientStubImplServices = 4; 296 const size_t kNumShillManagerClientStubImplServices = 4;
299 EXPECT_EQ(kNumShillManagerClientStubImplServices, 297 EXPECT_EQ(kNumShillManagerClientStubImplServices,
300 listener_->entries(flimflam::kServicesProperty).size()); 298 listener_->entries(shill::kServicesProperty).size());
301 299
302 EXPECT_EQ(0, listener_->errors()); 300 EXPECT_EQ(0, listener_->errors());
303 } 301 }
304 302
305 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { 303 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) {
306 const int initial_technology_updates = 2; // Available and Enabled lists 304 const int initial_technology_updates = 2; // Available and Enabled lists
307 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates()); 305 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates());
308 306
309 // Remove a technology. Updates both the Available and Enabled lists. 307 // Remove a technology. Updates both the Available and Enabled lists.
310 manager_test_->RemoveTechnology(flimflam::kTypeWimax); 308 manager_test_->RemoveTechnology(shill::kTypeWimax);
311 message_loop_.RunUntilIdle(); 309 message_loop_.RunUntilIdle();
312 EXPECT_EQ(initial_technology_updates + 2, 310 EXPECT_EQ(initial_technology_updates + 2,
313 listener_->technology_list_updates()); 311 listener_->technology_list_updates());
314 312
315 // Add a disabled technology. 313 // Add a disabled technology.
316 manager_test_->AddTechnology(flimflam::kTypeWimax, false); 314 manager_test_->AddTechnology(shill::kTypeWimax, false);
317 message_loop_.RunUntilIdle(); 315 message_loop_.RunUntilIdle();
318 EXPECT_EQ(initial_technology_updates + 3, 316 EXPECT_EQ(initial_technology_updates + 3,
319 listener_->technology_list_updates()); 317 listener_->technology_list_updates());
320 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( 318 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(
321 flimflam::kTypeWimax)); 319 shill::kTypeWimax));
322 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled( 320 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax));
323 flimflam::kTypeWimax));
324 321
325 // Enable the technology. 322 // Enable the technology.
326 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( 323 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology(
327 flimflam::kTypeWimax, 324 shill::kTypeWimax,
328 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 325 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
329 message_loop_.RunUntilIdle(); 326 message_loop_.RunUntilIdle();
330 EXPECT_EQ(initial_technology_updates + 4, 327 EXPECT_EQ(initial_technology_updates + 4,
331 listener_->technology_list_updates()); 328 listener_->technology_list_updates());
332 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( 329 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax));
333 flimflam::kTypeWimax));
334 330
335 EXPECT_EQ(0, listener_->errors()); 331 EXPECT_EQ(0, listener_->errors());
336 } 332 }
337 333
338 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { 334 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) {
339 EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); 335 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
340 const size_t kNumShillManagerClientStubImplDevices = 2; 336 const size_t kNumShillManagerClientStubImplDevices = 2;
341 EXPECT_EQ(kNumShillManagerClientStubImplDevices, 337 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
342 listener_->entries(flimflam::kDevicesProperty).size()); 338 listener_->entries(shill::kDevicesProperty).size());
343 // Add a device. 339 // Add a device.
344 const std::string kTestDevicePath("test_wifi_device1"); 340 const std::string kTestDevicePath("test_wifi_device1");
345 AddDevice(flimflam::kTypeWifi, kTestDevicePath); 341 AddDevice(shill::kTypeWifi, kTestDevicePath);
346 message_loop_.RunUntilIdle(); 342 message_loop_.RunUntilIdle();
347 EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); 343 EXPECT_EQ(2, listener_->list_updates(shill::kDevicesProperty));
348 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, 344 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1,
349 listener_->entries(flimflam::kDevicesProperty).size()); 345 listener_->entries(shill::kDevicesProperty).size());
350 // Device changes are not observed. 346 // Device changes are not observed.
351 // Remove a device 347 // Remove a device
352 RemoveDevice(kTestDevicePath); 348 RemoveDevice(kTestDevicePath);
353 message_loop_.RunUntilIdle(); 349 message_loop_.RunUntilIdle();
354 EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); 350 EXPECT_EQ(3, listener_->list_updates(shill::kDevicesProperty));
355 EXPECT_EQ(kNumShillManagerClientStubImplDevices, 351 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
356 listener_->entries(flimflam::kDevicesProperty).size()); 352 listener_->entries(shill::kDevicesProperty).size());
357 353
358 EXPECT_EQ(0, listener_->errors()); 354 EXPECT_EQ(0, listener_->errors());
359 } 355 }
360 356
361 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { 357 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) {
362 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); 358 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
363 const size_t kNumShillManagerClientStubImplServices = 4; 359 const size_t kNumShillManagerClientStubImplServices = 4;
364 EXPECT_EQ(kNumShillManagerClientStubImplServices, 360 EXPECT_EQ(kNumShillManagerClientStubImplServices,
365 listener_->entries(flimflam::kServicesProperty).size()); 361 listener_->entries(shill::kServicesProperty).size());
366 362
367 // Add an unwatched service. 363 // Add an unwatched service.
368 const std::string kTestServicePath("test_wifi_service1"); 364 const std::string kTestServicePath("test_wifi_service1");
369 AddService(flimflam::kTypeWifi, kTestServicePath, 365 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, false);
370 flimflam::kStateIdle, false);
371 message_loop_.RunUntilIdle(); 366 message_loop_.RunUntilIdle();
372 // Watched and unwatched services trigger a service list update. 367 // Watched and unwatched services trigger a service list update.
373 EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); 368 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty));
374 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, 369 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
375 listener_->entries(flimflam::kServicesProperty).size()); 370 listener_->entries(shill::kServicesProperty).size());
376 // Service receives an initial property update. 371 // Service receives an initial property update.
377 EXPECT_EQ(1, listener_->initial_property_updates( 372 EXPECT_EQ(1, listener_->initial_property_updates(
378 flimflam::kServicesProperty)[kTestServicePath]); 373 shill::kServicesProperty)[kTestServicePath]);
379 // Change a property. 374 // Change a property.
380 base::FundamentalValue scan_interval(3); 375 base::FundamentalValue scan_interval(3);
381 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 376 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
382 dbus::ObjectPath(kTestServicePath), 377 dbus::ObjectPath(kTestServicePath),
383 flimflam::kScanIntervalProperty, 378 shill::kScanIntervalProperty,
384 scan_interval, 379 scan_interval,
385 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 380 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
386 message_loop_.RunUntilIdle(); 381 message_loop_.RunUntilIdle();
387 // Property change triggers an update. 382 // Property change triggers an update.
388 EXPECT_EQ(1, listener_->property_updates( 383 EXPECT_EQ(1, listener_->property_updates(
389 flimflam::kServicesProperty)[kTestServicePath]); 384 shill::kServicesProperty)[kTestServicePath]);
390 385
391 // Add the existing service to the watch list. 386 // Add the existing service to the watch list.
392 AddService(flimflam::kTypeWifi, kTestServicePath, 387 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, true);
393 flimflam::kStateIdle, true);
394 message_loop_.RunUntilIdle(); 388 message_loop_.RunUntilIdle();
395 // Service list update should be received when watch list changes. 389 // Service list update should be received when watch list changes.
396 EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); 390 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty));
397 // Number of services shouldn't change. 391 // Number of services shouldn't change.
398 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, 392 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
399 listener_->entries(flimflam::kServicesProperty).size()); 393 listener_->entries(shill::kServicesProperty).size());
400 394
401 // Change a property. 395 // Change a property.
402 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 396 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
403 dbus::ObjectPath(kTestServicePath), 397 dbus::ObjectPath(kTestServicePath),
404 flimflam::kScanIntervalProperty, 398 shill::kScanIntervalProperty,
405 scan_interval, 399 scan_interval,
406 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 400 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
407 message_loop_.RunUntilIdle(); 401 message_loop_.RunUntilIdle();
408 // Property change should trigger another update. 402 // Property change should trigger another update.
409 EXPECT_EQ(2, listener_->property_updates( 403 EXPECT_EQ(2, listener_->property_updates(
410 flimflam::kServicesProperty)[kTestServicePath]); 404 shill::kServicesProperty)[kTestServicePath]);
411 405
412 // Remove a service 406 // Remove a service
413 RemoveService(kTestServicePath); 407 RemoveService(kTestServicePath);
414 message_loop_.RunUntilIdle(); 408 message_loop_.RunUntilIdle();
415 EXPECT_EQ(3, listener_->list_updates(flimflam::kServicesProperty)); 409 EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty));
416 EXPECT_EQ(kNumShillManagerClientStubImplServices, 410 EXPECT_EQ(kNumShillManagerClientStubImplServices,
417 listener_->entries(flimflam::kServicesProperty).size()); 411 listener_->entries(shill::kServicesProperty).size());
418 412
419 EXPECT_EQ(0, listener_->errors()); 413 EXPECT_EQ(0, listener_->errors());
420 } 414 }
421 415
422 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) { 416 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) {
423 // Set the properties for an IP Config object. 417 // Set the properties for an IP Config object.
424 const std::string kTestIPConfigPath("test_ip_config_path"); 418 const std::string kTestIPConfigPath("test_ip_config_path");
425 419
426 base::StringValue ip_address("192.168.1.1"); 420 base::StringValue ip_address("192.168.1.1");
427 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( 421 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
428 dbus::ObjectPath(kTestIPConfigPath), 422 dbus::ObjectPath(kTestIPConfigPath),
429 flimflam::kAddressProperty, ip_address, 423 shill::kAddressProperty, ip_address,
430 base::Bind(&DoNothingWithCallStatus)); 424 base::Bind(&DoNothingWithCallStatus));
431 base::ListValue dns_servers; 425 base::ListValue dns_servers;
432 dns_servers.Append(base::Value::CreateStringValue("192.168.1.100")); 426 dns_servers.Append(base::Value::CreateStringValue("192.168.1.100"));
433 dns_servers.Append(base::Value::CreateStringValue("192.168.1.101")); 427 dns_servers.Append(base::Value::CreateStringValue("192.168.1.101"));
434 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( 428 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
435 dbus::ObjectPath(kTestIPConfigPath), 429 dbus::ObjectPath(kTestIPConfigPath),
436 flimflam::kNameServersProperty, dns_servers, 430 shill::kNameServersProperty, dns_servers,
437 base::Bind(&DoNothingWithCallStatus)); 431 base::Bind(&DoNothingWithCallStatus));
438 base::FundamentalValue prefixlen(8); 432 base::FundamentalValue prefixlen(8);
439 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( 433 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
440 dbus::ObjectPath(kTestIPConfigPath), 434 dbus::ObjectPath(kTestIPConfigPath),
441 flimflam::kPrefixlenProperty, prefixlen, 435 shill::kPrefixlenProperty, prefixlen,
442 base::Bind(&DoNothingWithCallStatus)); 436 base::Bind(&DoNothingWithCallStatus));
443 base::StringValue gateway("192.0.0.1"); 437 base::StringValue gateway("192.0.0.1");
444 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( 438 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
445 dbus::ObjectPath(kTestIPConfigPath), 439 dbus::ObjectPath(kTestIPConfigPath),
446 flimflam::kGatewayProperty, gateway, 440 shill::kGatewayProperty, gateway,
447 base::Bind(&DoNothingWithCallStatus)); 441 base::Bind(&DoNothingWithCallStatus));
448 message_loop_.RunUntilIdle(); 442 message_loop_.RunUntilIdle();
449 443
450 // Add a service with an empty ipconfig and then update 444 // Add a service with an empty ipconfig and then update
451 // its ipconfig property. 445 // its ipconfig property.
452 const std::string kTestServicePath1("test_wifi_service1"); 446 const std::string kTestServicePath1("test_wifi_service1");
453 AddService(flimflam::kTypeWifi, kTestServicePath1, 447 AddService(shill::kTypeWifi, kTestServicePath1, shill::kStateIdle, true);
454 flimflam::kStateIdle, true);
455 message_loop_.RunUntilIdle(); 448 message_loop_.RunUntilIdle();
456 // This is the initial property update. 449 // This is the initial property update.
457 EXPECT_EQ(1, listener_->initial_property_updates( 450 EXPECT_EQ(1, listener_->initial_property_updates(
458 flimflam::kServicesProperty)[kTestServicePath1]); 451 shill::kServicesProperty)[kTestServicePath1]);
459 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 452 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
460 dbus::ObjectPath(kTestServicePath1), 453 dbus::ObjectPath(kTestServicePath1),
461 shill::kIPConfigProperty, 454 shill::kIPConfigProperty,
462 base::StringValue(kTestIPConfigPath), 455 base::StringValue(kTestIPConfigPath),
463 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 456 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
464 message_loop_.RunUntilIdle(); 457 message_loop_.RunUntilIdle();
465 // IPConfig property change on the service should trigger property updates for 458 // IPConfig property change on the service should trigger property updates for
466 // IP Address, DNS, prefixlen, and gateway. 459 // IP Address, DNS, prefixlen, and gateway.
467 EXPECT_EQ(4, listener_->property_updates( 460 EXPECT_EQ(4, listener_->property_updates(
468 flimflam::kServicesProperty)[kTestServicePath1]); 461 shill::kServicesProperty)[kTestServicePath1]);
469 462
470 // Now, Add a new watched service with the IPConfig already set. 463 // Now, Add a new watched service with the IPConfig already set.
471 const std::string kTestServicePath2("test_wifi_service2"); 464 const std::string kTestServicePath2("test_wifi_service2");
472 AddServiceWithIPConfig(flimflam::kTypeWifi, kTestServicePath2, 465 AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2,
473 flimflam::kStateIdle, kTestIPConfigPath, true); 466 shill::kStateIdle, kTestIPConfigPath, true);
474 message_loop_.RunUntilIdle(); 467 message_loop_.RunUntilIdle();
475 // A watched service with the IPConfig property already set must trigger 468 // A watched service with the IPConfig property already set must trigger
476 // property updates for IP Address, DNS, prefixlen, and gateway when added. 469 // property updates for IP Address, DNS, prefixlen, and gateway when added.
477 EXPECT_EQ(4, listener_->property_updates( 470 EXPECT_EQ(4, listener_->property_updates(
478 flimflam::kServicesProperty)[kTestServicePath2]); 471 shill::kServicesProperty)[kTestServicePath2]);
479 } 472 }
480 473
481 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) { 474 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) {
482 // Initial list updates. 475 // Initial list updates.
483 EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); 476 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
484 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); 477 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
485 478
486 // Add a new entry to the profile only; should trigger a single list update 479 // Add a new entry to the profile only; should trigger a single list update
487 // for both Services and ServiceCompleteList, and a single property update 480 // for both Services and ServiceCompleteList, and a single property update
488 // for ServiceCompleteList. 481 // for ServiceCompleteList.
489 const std::string kTestServicePath1("stub_wifi_profile_only1"); 482 const std::string kTestServicePath1("stub_wifi_profile_only1");
490 AddServiceToProfile(flimflam::kTypeWifi, kTestServicePath1, false); 483 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false);
491 shill_property_handler_->UpdateManagerProperties(); 484 shill_property_handler_->UpdateManagerProperties();
492 message_loop_.RunUntilIdle(); 485 message_loop_.RunUntilIdle();
493 EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); 486 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty));
494 EXPECT_EQ(2, listener_->list_updates(shill::kServiceCompleteListProperty)); 487 EXPECT_EQ(2, listener_->list_updates(shill::kServiceCompleteListProperty));
495 EXPECT_EQ(0, listener_->initial_property_updates( 488 EXPECT_EQ(0, listener_->initial_property_updates(
496 flimflam::kServicesProperty)[kTestServicePath1]); 489 shill::kServicesProperty)[kTestServicePath1]);
497 EXPECT_EQ(1, listener_->initial_property_updates( 490 EXPECT_EQ(1, listener_->initial_property_updates(
498 shill::kServiceCompleteListProperty)[kTestServicePath1]); 491 shill::kServiceCompleteListProperty)[kTestServicePath1]);
499 EXPECT_EQ(0, listener_->property_updates( 492 EXPECT_EQ(0, listener_->property_updates(
500 flimflam::kServicesProperty)[kTestServicePath1]); 493 shill::kServicesProperty)[kTestServicePath1]);
501 EXPECT_EQ(0, listener_->property_updates( 494 EXPECT_EQ(0, listener_->property_updates(
502 shill::kServiceCompleteListProperty)[kTestServicePath1]); 495 shill::kServiceCompleteListProperty)[kTestServicePath1]);
503 496
504 // Add a new entry to the services and the profile; should also trigger a 497 // Add a new entry to the services and the profile; should also trigger a
505 // single list update for both Services and ServiceCompleteList, and should 498 // single list update for both Services and ServiceCompleteList, and should
506 // trigger tow property updates for Services (one when the Profile propety 499 // trigger tow property updates for Services (one when the Profile propety
507 // changes, and one for the Request) and one ServiceCompleteList change for 500 // changes, and one for the Request) and one ServiceCompleteList change for
508 // the Request. 501 // the Request.
509 const std::string kTestServicePath2("stub_wifi_profile_only2"); 502 const std::string kTestServicePath2("stub_wifi_profile_only2");
510 AddServiceToProfile(flimflam::kTypeWifi, kTestServicePath2, true); 503 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true);
511 shill_property_handler_->UpdateManagerProperties(); 504 shill_property_handler_->UpdateManagerProperties();
512 message_loop_.RunUntilIdle(); 505 message_loop_.RunUntilIdle();
513 EXPECT_EQ(3, listener_->list_updates(flimflam::kServicesProperty)); 506 EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty));
514 EXPECT_EQ(3, listener_->list_updates(shill::kServiceCompleteListProperty)); 507 EXPECT_EQ(3, listener_->list_updates(shill::kServiceCompleteListProperty));
515 EXPECT_EQ(1, listener_->initial_property_updates( 508 EXPECT_EQ(1, listener_->initial_property_updates(
516 flimflam::kServicesProperty)[kTestServicePath2]); 509 shill::kServicesProperty)[kTestServicePath2]);
517 EXPECT_EQ(1, listener_->initial_property_updates( 510 EXPECT_EQ(1, listener_->initial_property_updates(
518 shill::kServiceCompleteListProperty)[kTestServicePath2]); 511 shill::kServiceCompleteListProperty)[kTestServicePath2]);
519 // Expect one property update for the Profile property of the Network. 512 // Expect one property update for the Profile property of the Network.
520 EXPECT_EQ(1, listener_->property_updates( 513 EXPECT_EQ(1, listener_->property_updates(
521 flimflam::kServicesProperty)[kTestServicePath2]); 514 shill::kServicesProperty)[kTestServicePath2]);
522 EXPECT_EQ(0, listener_->property_updates( 515 EXPECT_EQ(0, listener_->property_updates(
523 shill::kServiceCompleteListProperty)[kTestServicePath2]); 516 shill::kServiceCompleteListProperty)[kTestServicePath2]);
524 517
525 // Change a property of a Network in a Profile. 518 // Change a property of a Network in a Profile.
526 base::FundamentalValue scan_interval(3); 519 base::FundamentalValue scan_interval(3);
527 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 520 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
528 dbus::ObjectPath(kTestServicePath2), 521 dbus::ObjectPath(kTestServicePath2),
529 flimflam::kScanIntervalProperty, 522 shill::kScanIntervalProperty,
530 scan_interval, 523 scan_interval,
531 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 524 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
532 message_loop_.RunUntilIdle(); 525 message_loop_.RunUntilIdle();
533 // Property change should trigger an update for the Network only; no 526 // Property change should trigger an update for the Network only; no
534 // property updates pushed by Shill affect Favorites. 527 // property updates pushed by Shill affect Favorites.
535 EXPECT_EQ(2, listener_->property_updates( 528 EXPECT_EQ(2, listener_->property_updates(
536 flimflam::kServicesProperty)[kTestServicePath2]); 529 shill::kServicesProperty)[kTestServicePath2]);
537 EXPECT_EQ(0, listener_->property_updates( 530 EXPECT_EQ(0, listener_->property_updates(
538 shill::kServiceCompleteListProperty)[kTestServicePath2]); 531 shill::kServiceCompleteListProperty)[kTestServicePath2]);
539 } 532 }
540 533
541 } // namespace chromeos 534 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/shill_property_handler.cc ('k') | chromeos/network/shill_property_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698