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

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

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Fix 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
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/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/shill_device_client.h" 16 #include "chromeos/dbus/shill_device_client.h"
17 #include "chromeos/dbus/shill_manager_client.h" 17 #include "chromeos/dbus/shill_manager_client.h"
18 #include "chromeos/dbus/shill_profile_client.h" 18 #include "chromeos/dbus/shill_profile_client.h"
19 #include "chromeos/dbus/shill_service_client.h" 19 #include "chromeos/dbus/shill_service_client.h"
20 #include "chromeos/network/favorite_state.h"
21 #include "chromeos/network/network_state.h" 20 #include "chromeos/network/network_state.h"
21 #include "chromeos/network/network_state_handler.h"
22 #include "chromeos/network/network_state_handler_observer.h" 22 #include "chromeos/network/network_state_handler_observer.h"
23 #include "dbus/object_path.h" 23 #include "dbus/object_path.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 25 #include "third_party/cros_system_api/dbus/service_constants.h"
26 26
27 namespace { 27 namespace {
28 28
29 void ErrorCallbackFunction(const std::string& error_name, 29 void ErrorCallbackFunction(const std::string& error_name,
30 const std::string& error_message) { 30 const std::string& error_message) {
31 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; 31 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message;
32 } 32 }
33 33
34 const std::string kShillManagerClientStubDefaultService = "/service/eth1"; 34 const std::string kShillManagerClientStubDefaultService = "/service/eth1";
35 const std::string kShillManagerClientStubDefaultWifi = "/service/wifi1"; 35 const std::string kShillManagerClientStubDefaultWifi = "/service/wifi1";
36 const std::string kShillManagerClientStubWifi2 = "/service/wifi2"; 36 const std::string kShillManagerClientStubWifi2 = "/service/wifi2";
37 const std::string kShillManagerClientStubCellular = "/service/cellular1"; 37 const std::string kShillManagerClientStubCellular = "/service/cellular1";
38 38
39 using chromeos::NetworkState; 39 using chromeos::NetworkState;
40 using chromeos::NetworkStateHandler; 40 using chromeos::NetworkStateHandler;
41 41
42 class TestObserver : public chromeos::NetworkStateHandlerObserver { 42 class TestObserver : public chromeos::NetworkStateHandlerObserver {
43 public: 43 public:
44 explicit TestObserver(NetworkStateHandler* handler) 44 explicit TestObserver(NetworkStateHandler* handler)
45 : handler_(handler), 45 : handler_(handler),
46 device_list_changed_count_(0), 46 device_list_changed_count_(0),
47 device_count_(0), 47 device_count_(0),
48 network_count_(0), 48 network_count_(0),
49 default_network_change_count_(0), 49 default_network_change_count_(0) {
50 favorite_count_(0) {
51 } 50 }
52 51
53 virtual ~TestObserver() { 52 virtual ~TestObserver() {
54 } 53 }
55 54
56 virtual void DeviceListChanged() OVERRIDE { 55 virtual void DeviceListChanged() OVERRIDE {
57 NetworkStateHandler::DeviceStateList devices; 56 NetworkStateHandler::DeviceStateList devices;
58 handler_->GetDeviceList(&devices); 57 handler_->GetDeviceList(&devices);
59 device_count_ = devices.size(); 58 device_count_ = devices.size();
60 ++device_list_changed_count_; 59 ++device_list_changed_count_;
61 } 60 }
62 61
63 virtual void NetworkListChanged() OVERRIDE { 62 virtual void NetworkListChanged() OVERRIDE {
64 NetworkStateHandler::NetworkStateList networks; 63 NetworkStateHandler::NetworkStateList networks;
65 handler_->GetNetworkList(&networks); 64 handler_->GetNetworkListByType(chromeos::NetworkTypePattern::Default(),
65 false /* configured_only */,
66 false /* visible_only */,
67 0 /* no limit */,
68 &networks);
66 network_count_ = networks.size(); 69 network_count_ = networks.size();
67 if (network_count_ == 0) { 70 if (network_count_ == 0) {
68 default_network_ = ""; 71 default_network_ = "";
69 default_network_connection_state_ = ""; 72 default_network_connection_state_ = "";
70 } 73 }
71 NetworkStateHandler::FavoriteStateList favorites;
72 handler_->GetFavoriteList(&favorites);
73 favorite_count_ = favorites.size();
74 } 74 }
75 75
76 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE { 76 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE {
77 ++default_network_change_count_; 77 ++default_network_change_count_;
78 default_network_ = network ? network->path() : ""; 78 default_network_ = network ? network->path() : "";
79 default_network_connection_state_ = 79 default_network_connection_state_ =
80 network ? network->connection_state() : ""; 80 network ? network->connection_state() : "";
81 DVLOG(1) << "DefaultNetworkChanged: " << default_network_ 81 DVLOG(1) << "DefaultNetworkChanged: " << default_network_
82 << " State: " << default_network_connection_state_; 82 << " State: " << default_network_connection_state_;
83 } 83 }
(...skipping 17 matching lines...) Expand all
101 } 101 }
102 void reset_change_counts() { 102 void reset_change_counts() {
103 DVLOG(1) << "=== RESET CHANGE COUNTS ==="; 103 DVLOG(1) << "=== RESET CHANGE COUNTS ===";
104 default_network_change_count_ = 0; 104 default_network_change_count_ = 0;
105 device_list_changed_count_ = 0; 105 device_list_changed_count_ = 0;
106 } 106 }
107 std::string default_network() { return default_network_; } 107 std::string default_network() { return default_network_; }
108 std::string default_network_connection_state() { 108 std::string default_network_connection_state() {
109 return default_network_connection_state_; 109 return default_network_connection_state_;
110 } 110 }
111 size_t favorite_count() { return favorite_count_; }
112 111
113 int PropertyUpdatesForService(const std::string& service_path) { 112 int PropertyUpdatesForService(const std::string& service_path) {
114 return property_updates_[service_path]; 113 return property_updates_[service_path];
115 } 114 }
116 115
117 int ConnectionStateChangesForService(const std::string& service_path) { 116 int ConnectionStateChangesForService(const std::string& service_path) {
118 return connection_state_changes_[service_path]; 117 return connection_state_changes_[service_path];
119 } 118 }
120 119
121 std::string NetworkConnectionStateForService( 120 std::string NetworkConnectionStateForService(
122 const std::string& service_path) { 121 const std::string& service_path) {
123 return network_connection_state_[service_path]; 122 return network_connection_state_[service_path];
124 } 123 }
125 124
126 private: 125 private:
127 NetworkStateHandler* handler_; 126 NetworkStateHandler* handler_;
128 size_t device_list_changed_count_; 127 size_t device_list_changed_count_;
129 size_t device_count_; 128 size_t device_count_;
130 size_t network_count_; 129 size_t network_count_;
131 size_t default_network_change_count_; 130 size_t default_network_change_count_;
132 std::string default_network_; 131 std::string default_network_;
133 std::string default_network_connection_state_; 132 std::string default_network_connection_state_;
134 size_t favorite_count_;
135 std::map<std::string, int> property_updates_; 133 std::map<std::string, int> property_updates_;
136 std::map<std::string, int> connection_state_changes_; 134 std::map<std::string, int> connection_state_changes_;
137 std::map<std::string, std::string> network_connection_state_; 135 std::map<std::string, std::string> network_connection_state_;
138 136
139 DISALLOW_COPY_AND_ASSIGN(TestObserver); 137 DISALLOW_COPY_AND_ASSIGN(TestObserver);
140 }; 138 };
141 139
142 } // namespace 140 } // namespace
143 141
144 namespace chromeos { 142 namespace chromeos {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 network_state_handler_->FirstNetworkByType( 263 network_state_handler_->FirstNetworkByType(
266 NetworkTypePattern::Mobile())->path()); 264 NetworkTypePattern::Mobile())->path());
267 EXPECT_EQ( 265 EXPECT_EQ(
268 kShillManagerClientStubCellular, 266 kShillManagerClientStubCellular,
269 network_state_handler_->FirstNetworkByType(NetworkTypePattern::Cellular()) 267 network_state_handler_->FirstNetworkByType(NetworkTypePattern::Cellular())
270 ->path()); 268 ->path());
271 EXPECT_EQ(shill::kStateOnline, 269 EXPECT_EQ(shill::kStateOnline,
272 test_observer_->default_network_connection_state()); 270 test_observer_->default_network_connection_state());
273 } 271 }
274 272
273 TEST_F(NetworkStateHandlerTest, GetNetworkList) {
274 // Ensure that the network list is the expected size.
275 const size_t kNumShillManagerClientStubImplServices = 4;
276 EXPECT_EQ(kNumShillManagerClientStubImplServices,
277 test_observer_->network_count());
278 // Add a non-visible network to the profile.
279 const std::string profile = "/profile/profile1";
280 const std::string wifi_favorite_path = "/service/wifi_faviorite";
281 service_test_->AddService(wifi_favorite_path, "wifi_faviorite",
282 shill::kTypeWifi, shill::kStateIdle,
283 false /* add_to_visible */);
284 profile_test_->AddProfile(profile, "" /* userhash */);
285 EXPECT_TRUE(profile_test_->AddService(profile, wifi_favorite_path));
286 UpdateManagerProperties();
287 message_loop_.RunUntilIdle();
288 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
289 test_observer_->network_count());
290
291 // Get all networks.
292 NetworkStateHandler::NetworkStateList networks;
293 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
294 false /* configured_only */,
295 false /* visible_only */,
296 0 /* no limit */,
297 &networks);
298 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, networks.size());
299 // Limit number of results.
300 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
301 false /* configured_only */,
302 false /* visible_only */,
303 2 /* limit */,
304 &networks);
305 EXPECT_EQ(2u, networks.size());
306 // Get all wifi networks.
307 network_state_handler_->GetNetworkListByType(NetworkTypePattern::WiFi(),
308 false /* configured_only */,
309 false /* visible_only */,
310 0 /* no limit */,
311 &networks);
312 EXPECT_EQ(3u, networks.size());
313 // Get visible networks.
314 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
315 false /* configured_only */,
316 true /* visible_only */,
317 0 /* no limit */,
318 &networks);
319 EXPECT_EQ(kNumShillManagerClientStubImplServices, networks.size());
320 network_state_handler_->GetVisibleNetworkList(&networks);
321 EXPECT_EQ(kNumShillManagerClientStubImplServices, networks.size());
322 // Get configured (profile) networks.
323 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
324 true /* configured_only */,
325 false /* visible_only */,
326 0 /* no limit */,
327 &networks);
328 EXPECT_EQ(1u, networks.size());
329 }
330
275 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { 331 TEST_F(NetworkStateHandlerTest, TechnologyChanged) {
276 // Disable a technology. Will immediately set the state to AVAILABLE and 332 // Disable a technology. Will immediately set the state to AVAILABLE and
277 // notify observers. 333 // notify observers.
278 network_state_handler_->SetTechnologyEnabled( 334 network_state_handler_->SetTechnologyEnabled(
279 NetworkTypePattern::WiFi(), false, network_handler::ErrorCallback()); 335 NetworkTypePattern::WiFi(), false, network_handler::ErrorCallback());
280 EXPECT_EQ(1u, test_observer_->device_list_changed_count()); 336 EXPECT_EQ(1u, test_observer_->device_list_changed_count());
281 EXPECT_EQ( 337 EXPECT_EQ(
282 NetworkStateHandler::TECHNOLOGY_AVAILABLE, 338 NetworkStateHandler::TECHNOLOGY_AVAILABLE,
283 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi())); 339 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi()));
284 340
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 428
373 TEST_F(NetworkStateHandlerTest, GetState) { 429 TEST_F(NetworkStateHandlerTest, GetState) {
374 const std::string profile = "/profile/profile1"; 430 const std::string profile = "/profile/profile1";
375 const std::string wifi_path = kShillManagerClientStubDefaultWifi; 431 const std::string wifi_path = kShillManagerClientStubDefaultWifi;
376 432
377 // Add a wifi service to a Profile. 433 // Add a wifi service to a Profile.
378 profile_test_->AddProfile(profile, "" /* userhash */); 434 profile_test_->AddProfile(profile, "" /* userhash */);
379 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); 435 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path));
380 UpdateManagerProperties(); 436 UpdateManagerProperties();
381 437
382 // Ensure that a NetworkState and corresponding FavoriteState exist. 438 // Ensure that a NetworkState exists.
383 const NetworkState* wifi_network = 439 const NetworkState* wifi_network =
384 network_state_handler_->GetNetworkState(wifi_path); 440 network_state_handler_->GetNetworkStateFromServicePath(
441 wifi_path, true /* configured_only */);
385 ASSERT_TRUE(wifi_network); 442 ASSERT_TRUE(wifi_network);
386 const FavoriteState* wifi_favorite =
387 network_state_handler_->GetFavoriteStateFromServicePath(
388 wifi_path, true /* configured_only */);
389 ASSERT_TRUE(wifi_favorite);
390 EXPECT_EQ(wifi_network->path(), wifi_favorite->path());
391
392 // Ensure that we are notified that a Favorite was added.
393 EXPECT_EQ(1u, test_observer_->favorite_count());
394 443
395 // Test looking up by GUID. 444 // Test looking up by GUID.
396 ASSERT_FALSE(wifi_favorite->guid().empty()); 445 ASSERT_FALSE(wifi_network->guid().empty());
397 const FavoriteState* wifi_favorite_guid = 446 const NetworkState* wifi_network_guid =
398 network_state_handler_->GetFavoriteStateFromGuid(wifi_favorite->guid()); 447 network_state_handler_->GetNetworkStateFromGuid(wifi_network->guid());
399 EXPECT_EQ(wifi_favorite, wifi_favorite_guid); 448 EXPECT_EQ(wifi_network, wifi_network_guid);
400 449
401 // Remove the service, verify that there is no longer a NetworkState for it. 450 // Remove the service, verify that there is no longer a NetworkState for it.
402 service_test_->RemoveService(wifi_path); 451 service_test_->RemoveService(wifi_path);
403 UpdateManagerProperties(); 452 UpdateManagerProperties();
404 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); 453 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
405 } 454 }
406 455
407 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { 456 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) {
408 // Change a network state. 457 // Change a network state.
409 const std::string eth1 = kShillManagerClientStubDefaultService; 458 const std::string eth1 = kShillManagerClientStubDefaultService;
410 base::StringValue connection_state_idle_value(shill::kStateIdle); 459 base::StringValue connection_state_idle_value(shill::kStateIdle);
411 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 460 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
412 connection_state_idle_value); 461 connection_state_idle_value);
413 message_loop_.RunUntilIdle(); 462 message_loop_.RunUntilIdle();
414 EXPECT_EQ(shill::kStateIdle, 463 EXPECT_EQ(shill::kStateIdle,
415 test_observer_->NetworkConnectionStateForService(eth1)); 464 test_observer_->NetworkConnectionStateForService(eth1));
416 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); 465 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1));
417 // Confirm that changing the connection state to the same value does *not* 466 // Confirm that changing the connection state to the same value does *not*
418 // signal the observer. 467 // signal the observer.
419 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 468 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
420 connection_state_idle_value); 469 connection_state_idle_value);
421 message_loop_.RunUntilIdle(); 470 message_loop_.RunUntilIdle();
422 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); 471 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1));
423 } 472 }
424 473
425 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) { 474 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) {
426 const std::string eth1 = kShillManagerClientStubDefaultService; 475 const std::string eth1 = kShillManagerClientStubDefaultService;
427 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 476 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
428 477
478 EXPECT_EQ(0u, test_observer_->default_network_change_count());
429 // Disconnect ethernet. 479 // Disconnect ethernet.
430 base::StringValue connection_state_idle_value(shill::kStateIdle); 480 base::StringValue connection_state_idle_value(shill::kStateIdle);
431 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 481 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
432 connection_state_idle_value); 482 connection_state_idle_value);
433 message_loop_.RunUntilIdle(); 483 message_loop_.RunUntilIdle();
434 // Expect two changes: first when eth1 becomes disconnected, second when 484 // Expect two changes: first when eth1 becomes disconnected, second when
435 // wifi1 becomes the default. 485 // wifi1 becomes the default.
436 EXPECT_EQ(2u, test_observer_->default_network_change_count()); 486 EXPECT_EQ(2u, test_observer_->default_network_change_count());
437 EXPECT_EQ(wifi1, test_observer_->default_network()); 487 EXPECT_EQ(wifi1, test_observer_->default_network());
438 488
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 wifi_guid, 587 wifi_guid,
538 wifi_path /* name */, 588 wifi_path /* name */,
539 shill::kTypeWifi, 589 shill::kTypeWifi,
540 shill::kStateOnline, 590 shill::kStateOnline,
541 "" /* ipconfig_path */, 591 "" /* ipconfig_path */,
542 true /* add_to_visible */); 592 true /* add_to_visible */);
543 profile_test_->AddProfile(profile, "" /* userhash */); 593 profile_test_->AddProfile(profile, "" /* userhash */);
544 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); 594 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path));
545 UpdateManagerProperties(); 595 UpdateManagerProperties();
546 596
547 // Verify that a FavoriteState exists with a matching GUID. 597 // Verify that a NetworkState exists with a matching GUID.
548 const FavoriteState* favorite = 598 const NetworkState* network =
549 network_state_handler_->GetFavoriteStateFromServicePath( 599 network_state_handler_->GetNetworkStateFromServicePath(
550 wifi_path, is_service_configured); 600 wifi_path, is_service_configured);
551 ASSERT_TRUE(favorite);
552 EXPECT_EQ(wifi_guid, favorite->guid());
553
554 // Verify that a NetworkState exists with the same GUID.
555 const NetworkState* network =
556 network_state_handler_->GetNetworkState(wifi_path);
557 ASSERT_TRUE(network); 601 ASSERT_TRUE(network);
558 EXPECT_EQ(wifi_guid, network->guid()); 602 EXPECT_EQ(wifi_guid, network->guid());
559 603
560 // Remove the service (simulating a network going out of range). 604 // Remove the service (simulating a network going out of range).
561 service_test_->RemoveService(wifi_path); 605 service_test_->RemoveService(wifi_path);
562 UpdateManagerProperties(); 606 UpdateManagerProperties();
563 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); 607 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
564 608
565 // Add the service (simulating a network coming back in range) and verify that 609 // Add the service (simulating a network coming back in range) and verify that
566 // the NetworkState was created with the same GUID. 610 // the NetworkState was created with the same GUID.
567 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); 611 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
568 UpdateManagerProperties(); 612 UpdateManagerProperties();
569 network = network_state_handler_->GetNetworkState(wifi_path); 613 network = network_state_handler_->GetNetworkStateFromServicePath(
614 wifi_path, is_service_configured);
570 ASSERT_TRUE(network); 615 ASSERT_TRUE(network);
571 EXPECT_EQ(wifi_guid, network->guid()); 616 EXPECT_EQ(wifi_guid, network->guid());
572
573 // Also verify FavoriteState (mostly to test the stub behavior).
574 favorite = network_state_handler_->GetFavoriteStateFromServicePath(
575 wifi_path, is_service_configured);
576 ASSERT_TRUE(favorite);
577 EXPECT_EQ(wifi_guid, favorite->guid());
578 } 617 }
579 618
580 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) { 619 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) {
581 const std::string wifi_path = "/service/wifi_with_guid"; 620 const std::string wifi_path = "/service/wifi_with_guid";
582 const bool is_service_configured = false; 621 const bool is_service_configured = false;
583 622
584 // Add a network without adding it to a profile. 623 // Add a network without adding it to a profile.
585 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); 624 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
586 UpdateManagerProperties(); 625 UpdateManagerProperties();
587 626
588 // Verify that a FavoriteState exists with an assigned GUID. 627 // Verify that a NetworkState exists with an assigned GUID.
589 const FavoriteState* favorite = 628 const NetworkState* network =
590 network_state_handler_->GetFavoriteStateFromServicePath( 629 network_state_handler_->GetNetworkStateFromServicePath(
591 wifi_path, is_service_configured); 630 wifi_path, is_service_configured);
592 ASSERT_TRUE(favorite); 631 ASSERT_TRUE(network);
593 std::string wifi_guid = favorite->guid(); 632 std::string wifi_guid = network->guid();
594 EXPECT_FALSE(wifi_guid.empty()); 633 EXPECT_FALSE(wifi_guid.empty());
595 634
596 // Verify that a NetworkState exists with the same GUID.
597 const NetworkState* network =
598 network_state_handler_->GetNetworkState(wifi_path);
599 ASSERT_TRUE(network);
600 EXPECT_EQ(wifi_guid, network->guid());
601
602 // Remove the service (simulating a network going out of range). 635 // Remove the service (simulating a network going out of range).
603 service_test_->RemoveService(wifi_path); 636 service_test_->RemoveService(wifi_path);
604 UpdateManagerProperties(); 637 UpdateManagerProperties();
605 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); 638 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
606 639
607 // Add the service (simulating a network coming back in range) and verify that 640 // Add the service (simulating a network coming back in range) and verify that
608 // the NetworkState was created with the same GUID. 641 // the NetworkState was created with the same GUID.
609 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); 642 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
610 UpdateManagerProperties(); 643 UpdateManagerProperties();
611 network = network_state_handler_->GetNetworkState(wifi_path); 644 network = network_state_handler_->GetNetworkStateFromServicePath(
645 wifi_path, is_service_configured);
612 ASSERT_TRUE(network); 646 ASSERT_TRUE(network);
613 EXPECT_EQ(wifi_guid, network->guid()); 647 EXPECT_EQ(wifi_guid, network->guid());
614
615 // Also verify FavoriteState (mostly to test the stub behavior).
616 favorite = network_state_handler_->GetFavoriteStateFromServicePath(
617 wifi_path, is_service_configured);
618 ASSERT_TRUE(favorite);
619 EXPECT_EQ(wifi_guid, favorite->guid());
620 } 648 }
621 649
622 } // namespace chromeos 650 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698