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

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

Issue 175243004: Chrome OS: Use Manager.DefaultService for Default Network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/network/shill_property_handler.cc ('k') | no next file » | 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
80 virtual void ManagedStateListChanged( 80 virtual void ManagedStateListChanged(
81 ManagedState::ManagedType type) OVERRIDE { 81 ManagedState::ManagedType type) OVERRIDE {
82 AddStateListUpdate(GetTypeString(type)); 82 AddStateListUpdate(GetTypeString(type));
83 } 83 }
84 84
85 virtual void DefaultNetworkServiceChanged(
86 const std::string& service_path) OVERRIDE {
87 }
88
85 std::vector<std::string>& entries(const std::string& type) { 89 std::vector<std::string>& entries(const std::string& type) {
86 return entries_[type]; 90 return entries_[type];
87 } 91 }
88 std::map<std::string, int>& property_updates(const std::string& type) { 92 std::map<std::string, int>& property_updates(const std::string& type) {
89 return property_updates_[type]; 93 return property_updates_[type];
90 } 94 }
91 std::map<std::string, int>& initial_property_updates( 95 std::map<std::string, int>& initial_property_updates(
92 const std::string& type) { 96 const std::string& type) {
93 return initial_property_updates_[type]; 97 return initial_property_updates_[type];
94 } 98 }
95 int list_updates(const std::string& type) { return list_updates_[type]; } 99 int list_updates(const std::string& type) { return list_updates_[type]; }
100 void reset_list_updates() { list_updates_.clear(); }
96 int technology_list_updates() { return technology_list_updates_; } 101 int technology_list_updates() { return technology_list_updates_; }
97 int errors() { return errors_; } 102 int errors() { return errors_; }
98 103
99 private: 104 private:
100 std::string GetTypeString(ManagedState::ManagedType type) { 105 std::string GetTypeString(ManagedState::ManagedType type) {
101 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 106 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
102 return shill::kServicesProperty; 107 return shill::kServicesProperty;
103 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { 108 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) {
104 return shill::kServiceCompleteListProperty; 109 return shill::kServiceCompleteListProperty;
105 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 110 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 330 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
326 message_loop_.RunUntilIdle(); 331 message_loop_.RunUntilIdle();
327 EXPECT_EQ(initial_technology_updates + 4, 332 EXPECT_EQ(initial_technology_updates + 4,
328 listener_->technology_list_updates()); 333 listener_->technology_list_updates());
329 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax)); 334 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax));
330 335
331 EXPECT_EQ(0, listener_->errors()); 336 EXPECT_EQ(0, listener_->errors());
332 } 337 }
333 338
334 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { 339 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) {
335 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
336 const size_t kNumShillManagerClientStubImplDevices = 2; 340 const size_t kNumShillManagerClientStubImplDevices = 2;
337 EXPECT_EQ(kNumShillManagerClientStubImplDevices, 341 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
338 listener_->entries(shill::kDevicesProperty).size()); 342 listener_->entries(shill::kDevicesProperty).size());
339 // Add a device. 343 // Add a device.
344 listener_->reset_list_updates();
340 const std::string kTestDevicePath("test_wifi_device1"); 345 const std::string kTestDevicePath("test_wifi_device1");
341 AddDevice(shill::kTypeWifi, kTestDevicePath); 346 AddDevice(shill::kTypeWifi, kTestDevicePath);
342 message_loop_.RunUntilIdle(); 347 message_loop_.RunUntilIdle();
343 EXPECT_EQ(2, listener_->list_updates(shill::kDevicesProperty)); 348 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
344 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, 349 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1,
345 listener_->entries(shill::kDevicesProperty).size()); 350 listener_->entries(shill::kDevicesProperty).size());
346 // Device changes are not observed. 351 // Device changes are not observed.
347 // Remove a device 352 // Remove a device
353 listener_->reset_list_updates();
348 RemoveDevice(kTestDevicePath); 354 RemoveDevice(kTestDevicePath);
349 message_loop_.RunUntilIdle(); 355 message_loop_.RunUntilIdle();
350 EXPECT_EQ(3, listener_->list_updates(shill::kDevicesProperty)); 356 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
351 EXPECT_EQ(kNumShillManagerClientStubImplDevices, 357 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
352 listener_->entries(shill::kDevicesProperty).size()); 358 listener_->entries(shill::kDevicesProperty).size());
353 359
354 EXPECT_EQ(0, listener_->errors()); 360 EXPECT_EQ(0, listener_->errors());
355 } 361 }
356 362
357 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { 363 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) {
358 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
359 const size_t kNumShillManagerClientStubImplServices = 4; 364 const size_t kNumShillManagerClientStubImplServices = 4;
360 EXPECT_EQ(kNumShillManagerClientStubImplServices, 365 EXPECT_EQ(kNumShillManagerClientStubImplServices,
361 listener_->entries(shill::kServicesProperty).size()); 366 listener_->entries(shill::kServicesProperty).size());
362 367
363 // Add an unwatched service. 368 // Add an unwatched service.
369 listener_->reset_list_updates();
364 const std::string kTestServicePath("test_wifi_service1"); 370 const std::string kTestServicePath("test_wifi_service1");
365 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, false); 371 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, false);
366 message_loop_.RunUntilIdle(); 372 message_loop_.RunUntilIdle();
367 // Watched and unwatched services trigger a service list update. 373 // Watched and unwatched services trigger a service list update.
368 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty)); 374 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
369 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, 375 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
370 listener_->entries(shill::kServicesProperty).size()); 376 listener_->entries(shill::kServicesProperty).size());
371 // Service receives an initial property update. 377 // Service receives an initial property update.
372 EXPECT_EQ(1, listener_->initial_property_updates( 378 EXPECT_EQ(1, listener_->initial_property_updates(
373 shill::kServicesProperty)[kTestServicePath]); 379 shill::kServicesProperty)[kTestServicePath]);
374 // Change a property. 380 // Change a property.
375 base::FundamentalValue scan_interval(3); 381 base::FundamentalValue scan_interval(3);
376 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 382 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
377 dbus::ObjectPath(kTestServicePath), 383 dbus::ObjectPath(kTestServicePath),
378 shill::kScanIntervalProperty, 384 shill::kScanIntervalProperty,
379 scan_interval, 385 scan_interval,
380 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 386 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
381 message_loop_.RunUntilIdle(); 387 message_loop_.RunUntilIdle();
382 // Property change triggers an update. 388 // Property change triggers an update.
383 EXPECT_EQ(1, listener_->property_updates( 389 EXPECT_EQ(1, listener_->property_updates(
384 shill::kServicesProperty)[kTestServicePath]); 390 shill::kServicesProperty)[kTestServicePath]);
385 391
386 // Add the existing service to the watch list. 392 // Add the existing service to the watch list.
393 listener_->reset_list_updates();
387 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, true); 394 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, true);
388 message_loop_.RunUntilIdle(); 395 message_loop_.RunUntilIdle();
389 // Service list update should be received when watch list changes. 396 // Service list update should be received when watch list changes.
390 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty)); 397 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
391 // Number of services shouldn't change. 398 // Number of services shouldn't change.
392 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, 399 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
393 listener_->entries(shill::kServicesProperty).size()); 400 listener_->entries(shill::kServicesProperty).size());
394 401
395 // Change a property. 402 // Change a property.
396 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 403 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
397 dbus::ObjectPath(kTestServicePath), 404 dbus::ObjectPath(kTestServicePath),
398 shill::kScanIntervalProperty, 405 shill::kScanIntervalProperty,
399 scan_interval, 406 scan_interval,
400 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 407 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
401 message_loop_.RunUntilIdle(); 408 message_loop_.RunUntilIdle();
402 // Property change should trigger another update. 409 // Property change should trigger another update.
403 EXPECT_EQ(2, listener_->property_updates( 410 EXPECT_EQ(2, listener_->property_updates(
404 shill::kServicesProperty)[kTestServicePath]); 411 shill::kServicesProperty)[kTestServicePath]);
405 412
406 // Remove a service 413 // Remove a service
414 listener_->reset_list_updates();
407 RemoveService(kTestServicePath); 415 RemoveService(kTestServicePath);
408 message_loop_.RunUntilIdle(); 416 message_loop_.RunUntilIdle();
409 EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty)); 417 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
410 EXPECT_EQ(kNumShillManagerClientStubImplServices, 418 EXPECT_EQ(kNumShillManagerClientStubImplServices,
411 listener_->entries(shill::kServicesProperty).size()); 419 listener_->entries(shill::kServicesProperty).size());
412 420
413 EXPECT_EQ(0, listener_->errors()); 421 EXPECT_EQ(0, listener_->errors());
414 } 422 }
415 423
416 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) { 424 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) {
417 // Set the properties for an IP Config object. 425 // Set the properties for an IP Config object.
418 const std::string kTestIPConfigPath("test_ip_config_path"); 426 const std::string kTestIPConfigPath("test_ip_config_path");
419 427
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2, 473 AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2,
466 shill::kStateIdle, kTestIPConfigPath, true); 474 shill::kStateIdle, kTestIPConfigPath, true);
467 message_loop_.RunUntilIdle(); 475 message_loop_.RunUntilIdle();
468 // A watched service with the IPConfig property already set must trigger 476 // A watched service with the IPConfig property already set must trigger
469 // property updates for IP Address, DNS, prefixlen, and gateway when added. 477 // property updates for IP Address, DNS, prefixlen, and gateway when added.
470 EXPECT_EQ(4, listener_->property_updates( 478 EXPECT_EQ(4, listener_->property_updates(
471 shill::kServicesProperty)[kTestServicePath2]); 479 shill::kServicesProperty)[kTestServicePath2]);
472 } 480 }
473 481
474 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) { 482 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) {
475 // Initial list updates. 483 // Add a new entry to the profile only (triggers a Services update).
484 const std::string kTestServicePath1("stub_wifi_profile_only1");
485 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false);
486 message_loop_.RunUntilIdle();
487
488 // Update the Manager properties. This should trigger a single list update
489 // for both Services and ServiceCompleteList, and a single property update
490 // for ServiceCompleteList.
491 listener_->reset_list_updates();
492 shill_property_handler_->UpdateManagerProperties();
493 message_loop_.RunUntilIdle();
476 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); 494 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
477 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); 495 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
478
479 // Add a new entry to the profile only; should trigger a single list update
480 // for both Services and ServiceCompleteList, and a single property update
481 // for ServiceCompleteList.
482 const std::string kTestServicePath1("stub_wifi_profile_only1");
483 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false);
484 shill_property_handler_->UpdateManagerProperties();
485 message_loop_.RunUntilIdle();
486 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty));
487 EXPECT_EQ(2, listener_->list_updates(shill::kServiceCompleteListProperty));
488 EXPECT_EQ(0, listener_->initial_property_updates( 496 EXPECT_EQ(0, listener_->initial_property_updates(
489 shill::kServicesProperty)[kTestServicePath1]); 497 shill::kServicesProperty)[kTestServicePath1]);
490 EXPECT_EQ(1, listener_->initial_property_updates( 498 EXPECT_EQ(1, listener_->initial_property_updates(
491 shill::kServiceCompleteListProperty)[kTestServicePath1]); 499 shill::kServiceCompleteListProperty)[kTestServicePath1]);
492 EXPECT_EQ(0, listener_->property_updates( 500 EXPECT_EQ(0, listener_->property_updates(
493 shill::kServicesProperty)[kTestServicePath1]); 501 shill::kServicesProperty)[kTestServicePath1]);
494 EXPECT_EQ(0, listener_->property_updates( 502 EXPECT_EQ(0, listener_->property_updates(
495 shill::kServiceCompleteListProperty)[kTestServicePath1]); 503 shill::kServiceCompleteListProperty)[kTestServicePath1]);
496 504
497 // Add a new entry to the services and the profile; should also trigger a 505 // Add a new entry to the services and the profile; should also trigger a
498 // single list update for both Services and ServiceCompleteList, and should 506 // single list update for both Services and ServiceCompleteList, and should
499 // trigger tow property updates for Services (one when the Profile propety 507 // trigger tow property updates for Services (one when the Profile propety
500 // changes, and one for the Request) and one ServiceCompleteList change for 508 // changes, and one for the Request) and one ServiceCompleteList change for
501 // the Request. 509 // the Request.
510 listener_->reset_list_updates();
502 const std::string kTestServicePath2("stub_wifi_profile_only2"); 511 const std::string kTestServicePath2("stub_wifi_profile_only2");
503 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true); 512 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true);
504 shill_property_handler_->UpdateManagerProperties(); 513 shill_property_handler_->UpdateManagerProperties();
505 message_loop_.RunUntilIdle(); 514 message_loop_.RunUntilIdle();
506 EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty)); 515 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
507 EXPECT_EQ(3, listener_->list_updates(shill::kServiceCompleteListProperty)); 516 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
508 EXPECT_EQ(1, listener_->initial_property_updates( 517 EXPECT_EQ(1, listener_->initial_property_updates(
509 shill::kServicesProperty)[kTestServicePath2]); 518 shill::kServicesProperty)[kTestServicePath2]);
510 EXPECT_EQ(1, listener_->initial_property_updates( 519 EXPECT_EQ(1, listener_->initial_property_updates(
511 shill::kServiceCompleteListProperty)[kTestServicePath2]); 520 shill::kServiceCompleteListProperty)[kTestServicePath2]);
512 // Expect one property update for the Profile property of the Network. 521 // Expect one property update for the Profile property of the Network.
513 EXPECT_EQ(1, listener_->property_updates( 522 EXPECT_EQ(1, listener_->property_updates(
514 shill::kServicesProperty)[kTestServicePath2]); 523 shill::kServicesProperty)[kTestServicePath2]);
515 EXPECT_EQ(0, listener_->property_updates( 524 EXPECT_EQ(0, listener_->property_updates(
516 shill::kServiceCompleteListProperty)[kTestServicePath2]); 525 shill::kServiceCompleteListProperty)[kTestServicePath2]);
517 526
518 // Change a property of a Network in a Profile. 527 // Change a property of a Network in a Profile.
519 base::FundamentalValue scan_interval(3); 528 base::FundamentalValue scan_interval(3);
520 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 529 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
521 dbus::ObjectPath(kTestServicePath2), 530 dbus::ObjectPath(kTestServicePath2),
522 shill::kScanIntervalProperty, 531 shill::kScanIntervalProperty,
523 scan_interval, 532 scan_interval,
524 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 533 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
525 message_loop_.RunUntilIdle(); 534 message_loop_.RunUntilIdle();
526 // Property change should trigger an update for the Network only; no 535 // Property change should trigger an update for the Network only; no
527 // property updates pushed by Shill affect Favorites. 536 // property updates pushed by Shill affect Favorites.
528 EXPECT_EQ(2, listener_->property_updates( 537 EXPECT_EQ(2, listener_->property_updates(
529 shill::kServicesProperty)[kTestServicePath2]); 538 shill::kServicesProperty)[kTestServicePath2]);
530 EXPECT_EQ(0, listener_->property_updates( 539 EXPECT_EQ(0, listener_->property_updates(
531 shill::kServiceCompleteListProperty)[kTestServicePath2]); 540 shill::kServiceCompleteListProperty)[kTestServicePath2]);
532 } 541 }
533 542
534 } // namespace chromeos 543 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/shill_property_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698