OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
| 329 TEST_F(NetworkStateHandlerTest, GetVisibleNetworks) { |
| 330 // Ensure that the network list is the expected size. |
| 331 const size_t kNumShillManagerClientStubImplServices = 4; |
| 332 EXPECT_EQ(kNumShillManagerClientStubImplServices, |
| 333 test_observer_->network_count()); |
| 334 // Add a non-visible network to the profile. |
| 335 const std::string profile = "/profile/profile1"; |
| 336 const std::string wifi_favorite_path = "/service/wifi_faviorite"; |
| 337 service_test_->AddService(wifi_favorite_path, "wifi_faviorite", |
| 338 shill::kTypeWifi, shill::kStateIdle, |
| 339 false /* add_to_visible */); |
| 340 message_loop_.RunUntilIdle(); |
| 341 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, |
| 342 test_observer_->network_count()); |
| 343 |
| 344 // Get visible networks. |
| 345 NetworkStateHandler::NetworkStateList networks; |
| 346 network_state_handler_->GetVisibleNetworkList(&networks); |
| 347 EXPECT_EQ(kNumShillManagerClientStubImplServices, networks.size()); |
| 348 |
| 349 // Change the visible state of a network. |
| 350 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 351 dbus::ObjectPath(kShillManagerClientStubWifi2), |
| 352 shill::kVisibleProperty, base::FundamentalValue(false), |
| 353 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 354 message_loop_.RunUntilIdle(); |
| 355 network_state_handler_->GetVisibleNetworkList(&networks); |
| 356 EXPECT_EQ(kNumShillManagerClientStubImplServices - 1, networks.size()); |
| 357 } |
| 358 |
275 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { | 359 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { |
276 // Disable a technology. Will immediately set the state to AVAILABLE and | 360 // Disable a technology. Will immediately set the state to AVAILABLE and |
277 // notify observers. | 361 // notify observers. |
278 network_state_handler_->SetTechnologyEnabled( | 362 network_state_handler_->SetTechnologyEnabled( |
279 NetworkTypePattern::WiFi(), false, network_handler::ErrorCallback()); | 363 NetworkTypePattern::WiFi(), false, network_handler::ErrorCallback()); |
280 EXPECT_EQ(1u, test_observer_->device_list_changed_count()); | 364 EXPECT_EQ(1u, test_observer_->device_list_changed_count()); |
281 EXPECT_EQ( | 365 EXPECT_EQ( |
282 NetworkStateHandler::TECHNOLOGY_AVAILABLE, | 366 NetworkStateHandler::TECHNOLOGY_AVAILABLE, |
283 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi())); | 367 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi())); |
284 | 368 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 456 |
373 TEST_F(NetworkStateHandlerTest, GetState) { | 457 TEST_F(NetworkStateHandlerTest, GetState) { |
374 const std::string profile = "/profile/profile1"; | 458 const std::string profile = "/profile/profile1"; |
375 const std::string wifi_path = kShillManagerClientStubDefaultWifi; | 459 const std::string wifi_path = kShillManagerClientStubDefaultWifi; |
376 | 460 |
377 // Add a wifi service to a Profile. | 461 // Add a wifi service to a Profile. |
378 profile_test_->AddProfile(profile, "" /* userhash */); | 462 profile_test_->AddProfile(profile, "" /* userhash */); |
379 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); | 463 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); |
380 UpdateManagerProperties(); | 464 UpdateManagerProperties(); |
381 | 465 |
382 // Ensure that a NetworkState and corresponding FavoriteState exist. | 466 // Ensure that a NetworkState exists. |
383 const NetworkState* wifi_network = | 467 const NetworkState* wifi_network = |
384 network_state_handler_->GetNetworkState(wifi_path); | 468 network_state_handler_->GetNetworkStateFromServicePath( |
| 469 wifi_path, true /* configured_only */); |
385 ASSERT_TRUE(wifi_network); | 470 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 | 471 |
395 // Test looking up by GUID. | 472 // Test looking up by GUID. |
396 ASSERT_FALSE(wifi_favorite->guid().empty()); | 473 ASSERT_FALSE(wifi_network->guid().empty()); |
397 const FavoriteState* wifi_favorite_guid = | 474 const NetworkState* wifi_network_guid = |
398 network_state_handler_->GetFavoriteStateFromGuid(wifi_favorite->guid()); | 475 network_state_handler_->GetNetworkStateFromGuid(wifi_network->guid()); |
399 EXPECT_EQ(wifi_favorite, wifi_favorite_guid); | 476 EXPECT_EQ(wifi_network, wifi_network_guid); |
400 | 477 |
401 // Remove the service, verify that there is no longer a NetworkState for it. | 478 // Remove the service, verify that there is no longer a NetworkState for it. |
402 service_test_->RemoveService(wifi_path); | 479 service_test_->RemoveService(wifi_path); |
403 UpdateManagerProperties(); | 480 UpdateManagerProperties(); |
404 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); | 481 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); |
405 } | 482 } |
406 | 483 |
407 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { | 484 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { |
408 // Change a network state. | 485 // Change a network state. |
409 const std::string eth1 = kShillManagerClientStubDefaultService; | 486 const std::string eth1 = kShillManagerClientStubDefaultService; |
410 base::StringValue connection_state_idle_value(shill::kStateIdle); | 487 base::StringValue connection_state_idle_value(shill::kStateIdle); |
411 service_test_->SetServiceProperty(eth1, shill::kStateProperty, | 488 service_test_->SetServiceProperty(eth1, shill::kStateProperty, |
412 connection_state_idle_value); | 489 connection_state_idle_value); |
413 message_loop_.RunUntilIdle(); | 490 message_loop_.RunUntilIdle(); |
414 EXPECT_EQ(shill::kStateIdle, | 491 EXPECT_EQ(shill::kStateIdle, |
415 test_observer_->NetworkConnectionStateForService(eth1)); | 492 test_observer_->NetworkConnectionStateForService(eth1)); |
416 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); | 493 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); |
417 // Confirm that changing the connection state to the same value does *not* | 494 // Confirm that changing the connection state to the same value does *not* |
418 // signal the observer. | 495 // signal the observer. |
419 service_test_->SetServiceProperty(eth1, shill::kStateProperty, | 496 service_test_->SetServiceProperty(eth1, shill::kStateProperty, |
420 connection_state_idle_value); | 497 connection_state_idle_value); |
421 message_loop_.RunUntilIdle(); | 498 message_loop_.RunUntilIdle(); |
422 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); | 499 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); |
423 } | 500 } |
424 | 501 |
425 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) { | 502 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) { |
426 const std::string eth1 = kShillManagerClientStubDefaultService; | 503 const std::string eth1 = kShillManagerClientStubDefaultService; |
427 const std::string wifi1 = kShillManagerClientStubDefaultWifi; | 504 const std::string wifi1 = kShillManagerClientStubDefaultWifi; |
428 | 505 |
| 506 EXPECT_EQ(0u, test_observer_->default_network_change_count()); |
429 // Disconnect ethernet. | 507 // Disconnect ethernet. |
430 base::StringValue connection_state_idle_value(shill::kStateIdle); | 508 base::StringValue connection_state_idle_value(shill::kStateIdle); |
431 service_test_->SetServiceProperty(eth1, shill::kStateProperty, | 509 service_test_->SetServiceProperty(eth1, shill::kStateProperty, |
432 connection_state_idle_value); | 510 connection_state_idle_value); |
433 message_loop_.RunUntilIdle(); | 511 message_loop_.RunUntilIdle(); |
434 // Expect two changes: first when eth1 becomes disconnected, second when | 512 // Expect two changes: first when eth1 becomes disconnected, second when |
435 // wifi1 becomes the default. | 513 // wifi1 becomes the default. |
436 EXPECT_EQ(2u, test_observer_->default_network_change_count()); | 514 EXPECT_EQ(2u, test_observer_->default_network_change_count()); |
437 EXPECT_EQ(wifi1, test_observer_->default_network()); | 515 EXPECT_EQ(wifi1, test_observer_->default_network()); |
438 | 516 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 wifi_guid, | 615 wifi_guid, |
538 wifi_path /* name */, | 616 wifi_path /* name */, |
539 shill::kTypeWifi, | 617 shill::kTypeWifi, |
540 shill::kStateOnline, | 618 shill::kStateOnline, |
541 "" /* ipconfig_path */, | 619 "" /* ipconfig_path */, |
542 true /* add_to_visible */); | 620 true /* add_to_visible */); |
543 profile_test_->AddProfile(profile, "" /* userhash */); | 621 profile_test_->AddProfile(profile, "" /* userhash */); |
544 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); | 622 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); |
545 UpdateManagerProperties(); | 623 UpdateManagerProperties(); |
546 | 624 |
547 // Verify that a FavoriteState exists with a matching GUID. | 625 // Verify that a NetworkState exists with a matching GUID. |
548 const FavoriteState* favorite = | 626 const NetworkState* network = |
549 network_state_handler_->GetFavoriteStateFromServicePath( | 627 network_state_handler_->GetNetworkStateFromServicePath( |
550 wifi_path, is_service_configured); | 628 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); | 629 ASSERT_TRUE(network); |
558 EXPECT_EQ(wifi_guid, network->guid()); | 630 EXPECT_EQ(wifi_guid, network->guid()); |
559 | 631 |
560 // Remove the service (simulating a network going out of range). | 632 // Remove the service (simulating a network going out of range). |
561 service_test_->RemoveService(wifi_path); | 633 service_test_->RemoveService(wifi_path); |
562 UpdateManagerProperties(); | 634 UpdateManagerProperties(); |
563 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); | 635 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); |
564 | 636 |
565 // Add the service (simulating a network coming back in range) and verify that | 637 // Add the service (simulating a network coming back in range) and verify that |
566 // the NetworkState was created with the same GUID. | 638 // the NetworkState was created with the same GUID. |
567 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | 639 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); |
568 UpdateManagerProperties(); | 640 UpdateManagerProperties(); |
569 network = network_state_handler_->GetNetworkState(wifi_path); | 641 network = network_state_handler_->GetNetworkStateFromServicePath( |
| 642 wifi_path, is_service_configured); |
570 ASSERT_TRUE(network); | 643 ASSERT_TRUE(network); |
571 EXPECT_EQ(wifi_guid, network->guid()); | 644 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 } | 645 } |
579 | 646 |
580 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) { | 647 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) { |
581 const std::string wifi_path = "/service/wifi_with_guid"; | 648 const std::string wifi_path = "/service/wifi_with_guid"; |
582 const bool is_service_configured = false; | 649 const bool is_service_configured = false; |
583 | 650 |
584 // Add a network without adding it to a profile. | 651 // Add a network without adding it to a profile. |
585 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | 652 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); |
586 UpdateManagerProperties(); | 653 UpdateManagerProperties(); |
587 | 654 |
588 // Verify that a FavoriteState exists with an assigned GUID. | 655 // Verify that a NetworkState exists with an assigned GUID. |
589 const FavoriteState* favorite = | 656 const NetworkState* network = |
590 network_state_handler_->GetFavoriteStateFromServicePath( | 657 network_state_handler_->GetNetworkStateFromServicePath( |
591 wifi_path, is_service_configured); | 658 wifi_path, is_service_configured); |
592 ASSERT_TRUE(favorite); | 659 ASSERT_TRUE(network); |
593 std::string wifi_guid = favorite->guid(); | 660 std::string wifi_guid = network->guid(); |
594 EXPECT_FALSE(wifi_guid.empty()); | 661 EXPECT_FALSE(wifi_guid.empty()); |
595 | 662 |
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). | 663 // Remove the service (simulating a network going out of range). |
603 service_test_->RemoveService(wifi_path); | 664 service_test_->RemoveService(wifi_path); |
604 UpdateManagerProperties(); | 665 UpdateManagerProperties(); |
605 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); | 666 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path)); |
606 | 667 |
607 // Add the service (simulating a network coming back in range) and verify that | 668 // Add the service (simulating a network coming back in range) and verify that |
608 // the NetworkState was created with the same GUID. | 669 // the NetworkState was created with the same GUID. |
609 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | 670 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); |
610 UpdateManagerProperties(); | 671 UpdateManagerProperties(); |
611 network = network_state_handler_->GetNetworkState(wifi_path); | 672 network = network_state_handler_->GetNetworkStateFromServicePath( |
| 673 wifi_path, is_service_configured); |
612 ASSERT_TRUE(network); | 674 ASSERT_TRUE(network); |
613 EXPECT_EQ(wifi_guid, network->guid()); | 675 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 } | 676 } |
621 | 677 |
622 } // namespace chromeos | 678 } // namespace chromeos |
OLD | NEW |