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

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: Elim UpdateManagerProperties, feedback 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 shill::kTypeWifi, 216 shill::kTypeWifi,
219 shill::kStateIdle); 217 shill::kStateIdle);
220 AddService(kShillManagerClientStubCellular, 218 AddService(kShillManagerClientStubCellular,
221 "cellular1", 219 "cellular1",
222 shill::kTypeCellular, 220 shill::kTypeCellular,
223 shill::kStateIdle); 221 shill::kStateIdle);
224 } 222 }
225 223
226 void UpdateManagerProperties() { 224 void UpdateManagerProperties() {
227 message_loop_.RunUntilIdle(); 225 message_loop_.RunUntilIdle();
228 network_state_handler_->UpdateManagerProperties();
229 message_loop_.RunUntilIdle();
230 } 226 }
231 227
232 base::MessageLoopForUI message_loop_; 228 base::MessageLoopForUI message_loop_;
233 scoped_ptr<NetworkStateHandler> network_state_handler_; 229 scoped_ptr<NetworkStateHandler> network_state_handler_;
234 scoped_ptr<TestObserver> test_observer_; 230 scoped_ptr<TestObserver> test_observer_;
235 ShillDeviceClient::TestInterface* device_test_; 231 ShillDeviceClient::TestInterface* device_test_;
236 ShillManagerClient::TestInterface* manager_test_; 232 ShillManagerClient::TestInterface* manager_test_;
237 ShillProfileClient::TestInterface* profile_test_; 233 ShillProfileClient::TestInterface* profile_test_;
238 ShillServiceClient::TestInterface* service_test_; 234 ShillServiceClient::TestInterface* service_test_;
239 235
(...skipping 25 matching lines...) Expand all
265 network_state_handler_->FirstNetworkByType( 261 network_state_handler_->FirstNetworkByType(
266 NetworkTypePattern::Mobile())->path()); 262 NetworkTypePattern::Mobile())->path());
267 EXPECT_EQ( 263 EXPECT_EQ(
268 kShillManagerClientStubCellular, 264 kShillManagerClientStubCellular,
269 network_state_handler_->FirstNetworkByType(NetworkTypePattern::Cellular()) 265 network_state_handler_->FirstNetworkByType(NetworkTypePattern::Cellular())
270 ->path()); 266 ->path());
271 EXPECT_EQ(shill::kStateOnline, 267 EXPECT_EQ(shill::kStateOnline,
272 test_observer_->default_network_connection_state()); 268 test_observer_->default_network_connection_state());
273 } 269 }
274 270
271 TEST_F(NetworkStateHandlerTest, GetNetworkList) {
272 // Ensure that the network list is the expected size.
273 const size_t kNumShillManagerClientStubImplServices = 4;
274 EXPECT_EQ(kNumShillManagerClientStubImplServices,
275 test_observer_->network_count());
276 // Add a non-visible network to the profile.
277 const std::string profile = "/profile/profile1";
278 const std::string wifi_favorite_path = "/service/wifi_faviorite";
279 service_test_->AddService(wifi_favorite_path, "wifi_faviorite",
280 shill::kTypeWifi, shill::kStateIdle,
281 false /* add_to_visible */);
282 profile_test_->AddProfile(profile, "" /* userhash */);
283 EXPECT_TRUE(profile_test_->AddService(profile, wifi_favorite_path));
284 UpdateManagerProperties();
285 message_loop_.RunUntilIdle();
286 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
287 test_observer_->network_count());
288
289 // Get all networks.
290 NetworkStateHandler::NetworkStateList networks;
291 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
292 false /* configured_only */,
293 false /* visible_only */,
294 0 /* no limit */,
295 &networks);
296 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, networks.size());
297 // Limit number of results.
298 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
299 false /* configured_only */,
300 false /* visible_only */,
301 2 /* limit */,
302 &networks);
303 EXPECT_EQ(2u, networks.size());
304 // Get all wifi networks.
305 network_state_handler_->GetNetworkListByType(NetworkTypePattern::WiFi(),
306 false /* configured_only */,
307 false /* visible_only */,
308 0 /* no limit */,
309 &networks);
310 EXPECT_EQ(3u, networks.size());
311 // Get visible networks.
312 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
313 false /* configured_only */,
314 true /* visible_only */,
315 0 /* no limit */,
316 &networks);
317 EXPECT_EQ(kNumShillManagerClientStubImplServices, networks.size());
318 network_state_handler_->GetVisibleNetworkList(&networks);
319 EXPECT_EQ(kNumShillManagerClientStubImplServices, networks.size());
320 // Get configured (profile) networks.
321 network_state_handler_->GetNetworkListByType(NetworkTypePattern::Default(),
322 true /* configured_only */,
323 false /* visible_only */,
324 0 /* no limit */,
325 &networks);
326 EXPECT_EQ(1u, networks.size());
327 }
328
275 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { 329 TEST_F(NetworkStateHandlerTest, TechnologyChanged) {
276 // Disable a technology. Will immediately set the state to AVAILABLE and 330 // Disable a technology. Will immediately set the state to AVAILABLE and
277 // notify observers. 331 // notify observers.
278 network_state_handler_->SetTechnologyEnabled( 332 network_state_handler_->SetTechnologyEnabled(
279 NetworkTypePattern::WiFi(), false, network_handler::ErrorCallback()); 333 NetworkTypePattern::WiFi(), false, network_handler::ErrorCallback());
280 EXPECT_EQ(1u, test_observer_->device_list_changed_count()); 334 EXPECT_EQ(1u, test_observer_->device_list_changed_count());
281 EXPECT_EQ( 335 EXPECT_EQ(
282 NetworkStateHandler::TECHNOLOGY_AVAILABLE, 336 NetworkStateHandler::TECHNOLOGY_AVAILABLE,
283 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi())); 337 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi()));
284 338
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 426
373 TEST_F(NetworkStateHandlerTest, GetState) { 427 TEST_F(NetworkStateHandlerTest, GetState) {
374 const std::string profile = "/profile/profile1"; 428 const std::string profile = "/profile/profile1";
375 const std::string wifi_path = kShillManagerClientStubDefaultWifi; 429 const std::string wifi_path = kShillManagerClientStubDefaultWifi;
376 430
377 // Add a wifi service to a Profile. 431 // Add a wifi service to a Profile.
378 profile_test_->AddProfile(profile, "" /* userhash */); 432 profile_test_->AddProfile(profile, "" /* userhash */);
379 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); 433 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path));
380 UpdateManagerProperties(); 434 UpdateManagerProperties();
381 435
382 // Ensure that a NetworkState and corresponding FavoriteState exist. 436 // Ensure that a NetworkState exists.
383 const NetworkState* wifi_network = 437 const NetworkState* wifi_network =
384 network_state_handler_->GetNetworkState(wifi_path); 438 network_state_handler_->GetNetworkStateFromServicePath(
439 wifi_path, true /* configured_only */);
385 ASSERT_TRUE(wifi_network); 440 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 441
395 // Test looking up by GUID. 442 // Test looking up by GUID.
396 ASSERT_FALSE(wifi_favorite->guid().empty()); 443 ASSERT_FALSE(wifi_network->guid().empty());
397 const FavoriteState* wifi_favorite_guid = 444 const NetworkState* wifi_network_guid =
398 network_state_handler_->GetFavoriteStateFromGuid(wifi_favorite->guid()); 445 network_state_handler_->GetNetworkStateFromGuid(wifi_network->guid());
399 EXPECT_EQ(wifi_favorite, wifi_favorite_guid); 446 EXPECT_EQ(wifi_network, wifi_network_guid);
400 447
401 // Remove the service, verify that there is no longer a NetworkState for it. 448 // Remove the service, verify that there is no longer a NetworkState for it.
402 service_test_->RemoveService(wifi_path); 449 service_test_->RemoveService(wifi_path);
403 UpdateManagerProperties(); 450 UpdateManagerProperties();
404 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); 451 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
405 } 452 }
406 453
407 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { 454 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) {
408 // Change a network state. 455 // Change a network state.
409 const std::string eth1 = kShillManagerClientStubDefaultService; 456 const std::string eth1 = kShillManagerClientStubDefaultService;
410 base::StringValue connection_state_idle_value(shill::kStateIdle); 457 base::StringValue connection_state_idle_value(shill::kStateIdle);
411 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 458 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
412 connection_state_idle_value); 459 connection_state_idle_value);
413 message_loop_.RunUntilIdle(); 460 message_loop_.RunUntilIdle();
414 EXPECT_EQ(shill::kStateIdle, 461 EXPECT_EQ(shill::kStateIdle,
415 test_observer_->NetworkConnectionStateForService(eth1)); 462 test_observer_->NetworkConnectionStateForService(eth1));
416 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); 463 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1));
417 // Confirm that changing the connection state to the same value does *not* 464 // Confirm that changing the connection state to the same value does *not*
418 // signal the observer. 465 // signal the observer.
419 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 466 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
420 connection_state_idle_value); 467 connection_state_idle_value);
421 message_loop_.RunUntilIdle(); 468 message_loop_.RunUntilIdle();
422 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); 469 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1));
423 } 470 }
424 471
425 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) { 472 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) {
426 const std::string eth1 = kShillManagerClientStubDefaultService; 473 const std::string eth1 = kShillManagerClientStubDefaultService;
427 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 474 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
428 475
476 EXPECT_EQ(0u, test_observer_->default_network_change_count());
429 // Disconnect ethernet. 477 // Disconnect ethernet.
430 base::StringValue connection_state_idle_value(shill::kStateIdle); 478 base::StringValue connection_state_idle_value(shill::kStateIdle);
431 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 479 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
432 connection_state_idle_value); 480 connection_state_idle_value);
433 message_loop_.RunUntilIdle(); 481 message_loop_.RunUntilIdle();
434 // Expect two changes: first when eth1 becomes disconnected, second when 482 // Expect two changes: first when eth1 becomes disconnected, second when
435 // wifi1 becomes the default. 483 // wifi1 becomes the default.
436 EXPECT_EQ(2u, test_observer_->default_network_change_count()); 484 EXPECT_EQ(2u, test_observer_->default_network_change_count());
437 EXPECT_EQ(wifi1, test_observer_->default_network()); 485 EXPECT_EQ(wifi1, test_observer_->default_network());
438 486
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 wifi_guid, 585 wifi_guid,
538 wifi_path /* name */, 586 wifi_path /* name */,
539 shill::kTypeWifi, 587 shill::kTypeWifi,
540 shill::kStateOnline, 588 shill::kStateOnline,
541 "" /* ipconfig_path */, 589 "" /* ipconfig_path */,
542 true /* add_to_visible */); 590 true /* add_to_visible */);
543 profile_test_->AddProfile(profile, "" /* userhash */); 591 profile_test_->AddProfile(profile, "" /* userhash */);
544 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); 592 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path));
545 UpdateManagerProperties(); 593 UpdateManagerProperties();
546 594
547 // Verify that a FavoriteState exists with a matching GUID. 595 // Verify that a NetworkState exists with a matching GUID.
548 const FavoriteState* favorite = 596 const NetworkState* network =
549 network_state_handler_->GetFavoriteStateFromServicePath( 597 network_state_handler_->GetNetworkStateFromServicePath(
550 wifi_path, is_service_configured); 598 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); 599 ASSERT_TRUE(network);
558 EXPECT_EQ(wifi_guid, network->guid()); 600 EXPECT_EQ(wifi_guid, network->guid());
559 601
560 // Remove the service (simulating a network going out of range). 602 // Remove the service (simulating a network going out of range).
561 service_test_->RemoveService(wifi_path); 603 service_test_->RemoveService(wifi_path);
562 UpdateManagerProperties(); 604 UpdateManagerProperties();
563 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); 605 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
564 606
565 // Add the service (simulating a network coming back in range) and verify that 607 // Add the service (simulating a network coming back in range) and verify that
566 // the NetworkState was created with the same GUID. 608 // the NetworkState was created with the same GUID.
567 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); 609 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
568 UpdateManagerProperties(); 610 UpdateManagerProperties();
569 network = network_state_handler_->GetNetworkState(wifi_path); 611 network = network_state_handler_->GetNetworkStateFromServicePath(
612 wifi_path, is_service_configured);
570 ASSERT_TRUE(network); 613 ASSERT_TRUE(network);
571 EXPECT_EQ(wifi_guid, network->guid()); 614 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 } 615 }
579 616
580 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) { 617 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) {
581 const std::string wifi_path = "/service/wifi_with_guid"; 618 const std::string wifi_path = "/service/wifi_with_guid";
582 const bool is_service_configured = false; 619 const bool is_service_configured = false;
583 620
584 // Add a network without adding it to a profile. 621 // Add a network without adding it to a profile.
585 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); 622 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
586 UpdateManagerProperties(); 623 UpdateManagerProperties();
587 624
588 // Verify that a FavoriteState exists with an assigned GUID. 625 // Verify that a NetworkState exists with an assigned GUID.
589 const FavoriteState* favorite = 626 const NetworkState* network =
590 network_state_handler_->GetFavoriteStateFromServicePath( 627 network_state_handler_->GetNetworkStateFromServicePath(
591 wifi_path, is_service_configured); 628 wifi_path, is_service_configured);
592 ASSERT_TRUE(favorite); 629 ASSERT_TRUE(network);
593 std::string wifi_guid = favorite->guid(); 630 std::string wifi_guid = network->guid();
594 EXPECT_FALSE(wifi_guid.empty()); 631 EXPECT_FALSE(wifi_guid.empty());
595 632
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). 633 // Remove the service (simulating a network going out of range).
603 service_test_->RemoveService(wifi_path); 634 service_test_->RemoveService(wifi_path);
604 UpdateManagerProperties(); 635 UpdateManagerProperties();
605 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); 636 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
606 637
607 // Add the service (simulating a network coming back in range) and verify that 638 // Add the service (simulating a network coming back in range) and verify that
608 // the NetworkState was created with the same GUID. 639 // the NetworkState was created with the same GUID.
609 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); 640 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
610 UpdateManagerProperties(); 641 UpdateManagerProperties();
611 network = network_state_handler_->GetNetworkState(wifi_path); 642 network = network_state_handler_->GetNetworkStateFromServicePath(
643 wifi_path, is_service_configured);
612 ASSERT_TRUE(network); 644 ASSERT_TRUE(network);
613 EXPECT_EQ(wifi_guid, network->guid()); 645 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 } 646 }
621 647
622 } // namespace chromeos 648 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698