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

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

Issue 330833003: Rely on Service.Visible instead of Manager.Services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix stubs for tests Created 6 years, 6 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 29 matching lines...) Expand all
40 errors_(0) { 40 errors_(0) {
41 } 41 }
42 42
43 virtual void UpdateManagedList(ManagedState::ManagedType type, 43 virtual void UpdateManagedList(ManagedState::ManagedType type,
44 const base::ListValue& entries) OVERRIDE { 44 const base::ListValue& entries) OVERRIDE {
45 VLOG(1) << "UpdateManagedList[" << ManagedState::TypeToString(type) << "]: " 45 VLOG(1) << "UpdateManagedList[" << ManagedState::TypeToString(type) << "]: "
46 << entries.GetSize(); 46 << entries.GetSize();
47 UpdateEntries(GetTypeString(type), entries); 47 UpdateEntries(GetTypeString(type), entries);
48 } 48 }
49 49
50 virtual void UpdateVisibleNetworks(const base::ListValue& entries) OVERRIDE {
51 VLOG(1) << "UpdateVisibleNetworks: " << entries.GetSize();
52 UpdateEntries(shill::kServicesProperty, entries);
53 }
54
55 virtual void UpdateManagedStateProperties( 50 virtual void UpdateManagedStateProperties(
56 ManagedState::ManagedType type, 51 ManagedState::ManagedType type,
57 const std::string& path, 52 const std::string& path,
58 const base::DictionaryValue& properties) OVERRIDE { 53 const base::DictionaryValue& properties) OVERRIDE {
59 VLOG(2) << "UpdateManagedStateProperties: " << GetTypeString(type); 54 VLOG(2) << "UpdateManagedStateProperties: " << GetTypeString(type);
60 initial_property_updates(GetTypeString(type))[path] += 1; 55 initial_property_updates(GetTypeString(type))[path] += 1;
61 } 56 }
62 57
63 virtual void ProfileListChanged() OVERRIDE { 58 virtual void ProfileListChanged() OVERRIDE {
64 } 59 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 }; 293 };
299 294
300 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { 295 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) {
301 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(shill::kTypeWifi)); 296 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(shill::kTypeWifi));
302 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi)); 297 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi));
303 const size_t kNumShillManagerClientStubImplDevices = 2; 298 const size_t kNumShillManagerClientStubImplDevices = 2;
304 EXPECT_EQ(kNumShillManagerClientStubImplDevices, 299 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
305 listener_->entries(shill::kDevicesProperty).size()); 300 listener_->entries(shill::kDevicesProperty).size());
306 const size_t kNumShillManagerClientStubImplServices = 4; 301 const size_t kNumShillManagerClientStubImplServices = 4;
307 EXPECT_EQ(kNumShillManagerClientStubImplServices, 302 EXPECT_EQ(kNumShillManagerClientStubImplServices,
308 listener_->entries(shill::kServicesProperty).size()); 303 listener_->entries(shill::kServiceCompleteListProperty).size());
309 304
310 EXPECT_EQ(0, listener_->errors()); 305 EXPECT_EQ(0, listener_->errors());
311 } 306 }
312 307
313 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { 308 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) {
314 const int initial_technology_updates = 2; // Available and Enabled lists 309 const int initial_technology_updates = 2; // Available and Enabled lists
315 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates()); 310 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates());
316 311
317 // Remove an enabled technology. Updates both the Available and Enabled lists. 312 // Remove an enabled technology. Updates both the Available and Enabled lists.
318 listener_->reset_list_updates(); 313 listener_->reset_list_updates();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty)); 356 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
362 EXPECT_EQ(kNumShillManagerClientStubImplDevices, 357 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
363 listener_->entries(shill::kDevicesProperty).size()); 358 listener_->entries(shill::kDevicesProperty).size());
364 359
365 EXPECT_EQ(0, listener_->errors()); 360 EXPECT_EQ(0, listener_->errors());
366 } 361 }
367 362
368 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { 363 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) {
369 const size_t kNumShillManagerClientStubImplServices = 4; 364 const size_t kNumShillManagerClientStubImplServices = 4;
370 EXPECT_EQ(kNumShillManagerClientStubImplServices, 365 EXPECT_EQ(kNumShillManagerClientStubImplServices,
371 listener_->entries(shill::kServicesProperty).size()); 366 listener_->entries(shill::kServiceCompleteListProperty).size());
372 367
373 // Add a service. 368 // Add a service.
374 listener_->reset_list_updates(); 369 listener_->reset_list_updates();
375 const std::string kTestServicePath("test_wifi_service1"); 370 const std::string kTestServicePath("test_wifi_service1");
376 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle); 371 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle);
377 message_loop_.RunUntilIdle(); 372 message_loop_.RunUntilIdle();
378 // Add should trigger a service list update and update entries. 373 // Add should trigger a service list update and update entries.
379 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); 374 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
380 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, 375 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
381 listener_->entries(shill::kServicesProperty).size()); 376 listener_->entries(shill::kServiceCompleteListProperty).size());
382 // Service receives an initial property update. 377 // Service receives an initial property update.
383 EXPECT_EQ(1, listener_->initial_property_updates( 378 EXPECT_EQ(1, listener_->initial_property_updates(
384 shill::kServiceCompleteListProperty)[kTestServicePath]); 379 shill::kServiceCompleteListProperty)[kTestServicePath]);
385 // Change a property. 380 // Change a property.
386 base::FundamentalValue scan_interval(3); 381 base::FundamentalValue scan_interval(3);
387 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 382 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
388 dbus::ObjectPath(kTestServicePath), 383 dbus::ObjectPath(kTestServicePath),
389 shill::kScanIntervalProperty, 384 shill::kScanIntervalProperty,
390 scan_interval, 385 scan_interval,
391 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 386 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
392 message_loop_.RunUntilIdle(); 387 message_loop_.RunUntilIdle();
393 // Property change triggers an update (but not a service list update). 388 // Property change triggers an update (but not a service list update).
394 EXPECT_EQ(1, listener_->property_updates( 389 EXPECT_EQ(1, listener_->property_updates(
395 shill::kServiceCompleteListProperty)[kTestServicePath]); 390 shill::kServiceCompleteListProperty)[kTestServicePath]);
396 391
397 // Change the visibility of a service. This will signal two service list 392 // Change the visibility of a service. This will trigger a service list
398 // updates, one for the complete list and one for the visible list. 393 // updates.
399 listener_->reset_list_updates(); 394 listener_->reset_list_updates();
400 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 395 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
401 dbus::ObjectPath(kTestServicePath), 396 dbus::ObjectPath(kTestServicePath),
402 shill::kVisibleProperty, 397 shill::kVisibleProperty,
403 base::FundamentalValue(false), 398 base::FundamentalValue(false),
404 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 399 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
405 message_loop_.RunUntilIdle(); 400 message_loop_.RunUntilIdle();
406 EXPECT_EQ(2, listener_->list_updates(shill::kServiceCompleteListProperty)); 401 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
407 402
408 // Remove a service. This will update the entries and signal a service list 403 // Remove a service. This will update the entries and signal a service list
409 // update. 404 // update.
410 listener_->reset_list_updates(); 405 listener_->reset_list_updates();
411 RemoveService(kTestServicePath); 406 RemoveService(kTestServicePath);
412 message_loop_.RunUntilIdle(); 407 message_loop_.RunUntilIdle();
413 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); 408 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
414 EXPECT_EQ(kNumShillManagerClientStubImplServices, 409 EXPECT_EQ(kNumShillManagerClientStubImplServices,
415 listener_->entries(shill::kServicesProperty).size()); 410 listener_->entries(shill::kServiceCompleteListProperty).size());
416 411
417 EXPECT_EQ(0, listener_->errors()); 412 EXPECT_EQ(0, listener_->errors());
418 } 413 }
419 414
420 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) { 415 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) {
421 // Set the properties for an IP Config object. 416 // Set the properties for an IP Config object.
422 const std::string kTestIPConfigPath("test_ip_config_path"); 417 const std::string kTestIPConfigPath("test_ip_config_path");
423 418
424 base::StringValue ip_address("192.168.1.1"); 419 base::StringValue ip_address("192.168.1.1");
425 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( 420 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_EQ(2, listener_->property_updates( 468 EXPECT_EQ(2, listener_->property_updates(
474 shill::kIPConfigsProperty)[kTestIPConfigPath]); 469 shill::kIPConfigsProperty)[kTestIPConfigPath]);
475 } 470 }
476 471
477 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceList) { 472 TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceList) {
478 // Add an entry to the profile only. 473 // Add an entry to the profile only.
479 const std::string kTestServicePath1("stub_wifi_profile_only1"); 474 const std::string kTestServicePath1("stub_wifi_profile_only1");
480 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false /* visible */); 475 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false /* visible */);
481 message_loop_.RunUntilIdle(); 476 message_loop_.RunUntilIdle();
482 477
483 // Update the Manager properties. This should trigger a single list update 478 // Update the Manager properties. This should trigger a single list update,
484 // and a single initial property update. 479 // an initial property update, and a regular property update.
485 listener_->reset_list_updates(); 480 listener_->reset_list_updates();
486 shill_property_handler_->UpdateManagerProperties(); 481 shill_property_handler_->UpdateManagerProperties();
487 message_loop_.RunUntilIdle(); 482 message_loop_.RunUntilIdle();
488 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); 483 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
489 EXPECT_EQ(1, listener_->initial_property_updates( 484 EXPECT_EQ(1, listener_->initial_property_updates(
490 shill::kServiceCompleteListProperty)[kTestServicePath1]); 485 shill::kServiceCompleteListProperty)[kTestServicePath1]);
491 486 EXPECT_EQ(1, listener_->property_updates(
492 EXPECT_EQ(0, listener_->property_updates(
493 shill::kServiceCompleteListProperty)[kTestServicePath1]); 487 shill::kServiceCompleteListProperty)[kTestServicePath1]);
494 488
495 // Add a new entry to the services and the profile; should also trigger a 489 // Add a new entry to the services and the profile; should also trigger a
496 // service list update, and a property update. 490 // service list update, and a property update.
497 listener_->reset_list_updates(); 491 listener_->reset_list_updates();
498 const std::string kTestServicePath2("stub_wifi_profile_only2"); 492 const std::string kTestServicePath2("stub_wifi_profile_only2");
499 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true); 493 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true);
500 shill_property_handler_->UpdateManagerProperties(); 494 shill_property_handler_->UpdateManagerProperties();
501 message_loop_.RunUntilIdle(); 495 message_loop_.RunUntilIdle();
502 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty)); 496 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
503 EXPECT_EQ(1, listener_->initial_property_updates( 497 EXPECT_EQ(1, listener_->initial_property_updates(
504 shill::kServiceCompleteListProperty)[kTestServicePath2]); 498 shill::kServiceCompleteListProperty)[kTestServicePath2]);
505 EXPECT_EQ(1, listener_->property_updates( 499 EXPECT_EQ(1, listener_->property_updates(
506 shill::kServiceCompleteListProperty)[kTestServicePath2]); 500 shill::kServiceCompleteListProperty)[kTestServicePath2]);
507 } 501 }
508 502
509 } // namespace chromeos 503 } // 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