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

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

Issue 275543005: Use GUID instead of ServicePath in networkingPrivate API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More Feedback Created 6 years, 7 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/network_state_handler.cc ('k') | chromeos/network/network_util.h » ('j') | 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/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"
20 #include "chromeos/network/network_state.h" 21 #include "chromeos/network/network_state.h"
21 #include "chromeos/network/network_state_handler_observer.h" 22 #include "chromeos/network/network_state_handler_observer.h"
22 #include "chromeos/network/shill_property_util.h" 23 #include "chromeos/network/shill_property_util.h"
23 #include "dbus/object_path.h" 24 #include "dbus/object_path.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 26 #include "third_party/cros_system_api/dbus/service_constants.h"
26 27
27 namespace { 28 namespace {
28 29
29 void ErrorCallbackFunction(const std::string& error_name, 30 void ErrorCallbackFunction(const std::string& error_name,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 dbus::ObjectPath(eth1), 354 dbus::ObjectPath(eth1),
354 shill::kSecurityProperty, security_value, 355 shill::kSecurityProperty, security_value,
355 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 356 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
356 message_loop_.RunUntilIdle(); 357 message_loop_.RunUntilIdle();
357 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1)); 358 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1));
358 } 359 }
359 360
360 TEST_F(NetworkStateHandlerTest, FavoriteState) { 361 TEST_F(NetworkStateHandlerTest, FavoriteState) {
361 // Set the profile entry of a service 362 // Set the profile entry of a service
362 const std::string profile = "/profile/profile1"; 363 const std::string profile = "/profile/profile1";
363 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 364 const std::string wifi_path = kShillManagerClientStubDefaultWifi;
364 profile_test_->AddProfile(profile, "" /* userhash */); 365 profile_test_->AddProfile(profile, "" /* userhash */);
365 EXPECT_TRUE(profile_test_->AddService(profile, wifi1)); 366 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path));
366 UpdateManagerProperties(); 367 UpdateManagerProperties();
367 EXPECT_EQ(1u, test_observer_->favorite_count()); 368 EXPECT_EQ(1u, test_observer_->favorite_count());
369 const FavoriteState* favorite =
370 network_state_handler_->GetFavoriteStateFromServicePath(
371 wifi_path, true /* is_configured */);
372 ASSERT_TRUE(favorite);
373
374 // Remove the service, verify that there is no longer a FavoriteState for it.
375 service_test_->RemoveService(wifi_path);
376 UpdateManagerProperties();
377 EXPECT_FALSE(network_state_handler_->GetFavoriteStateFromServicePath(
378 wifi_path, false /* configured_only */));
379 }
380
381 TEST_F(NetworkStateHandlerTest, GetState) {
pneubeck (no reviews) 2014/05/14 08:46:07 Looking at the names 'GetState' vs. 'FavoriteState
stevenjb 2014/05/14 17:31:56 I combined these and cleaned them up a little. I d
382 const std::string profile = "/profile/profile1";
383 profile_test_->AddProfile(profile, "" /* userhash */);
384 base::StringValue profile_value(profile);
385 EXPECT_TRUE(service_test_->SetServiceProperty(
386 kShillManagerClientStubWifi2, shill::kProfileProperty, profile_value));
387 UpdateManagerProperties();
388
389 const NetworkState* wifi_network =
390 network_state_handler_->GetNetworkState(kShillManagerClientStubWifi2);
391 ASSERT_TRUE(wifi_network);
392 const FavoriteState* wifi_favorite =
393 network_state_handler_->GetFavoriteStateFromServicePath(
394 kShillManagerClientStubWifi2, true /* configured_only */);
395 ASSERT_TRUE(wifi_favorite);
396 EXPECT_EQ(wifi_network->path(), wifi_favorite->path());
397 ASSERT_FALSE(wifi_favorite->guid().empty());
398 const FavoriteState* wifi_favorite_guid =
399 network_state_handler_->GetFavoriteStateFromGuid(wifi_favorite->guid());
400 EXPECT_EQ(wifi_favorite, wifi_favorite_guid);
368 } 401 }
369 402
370 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { 403 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) {
371 // Change a network state. 404 // Change a network state.
372 const std::string eth1 = kShillManagerClientStubDefaultService; 405 const std::string eth1 = kShillManagerClientStubDefaultService;
373 base::StringValue connection_state_idle_value(shill::kStateIdle); 406 base::StringValue connection_state_idle_value(shill::kStateIdle);
374 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 407 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
375 connection_state_idle_value); 408 connection_state_idle_value);
376 message_loop_.RunUntilIdle(); 409 message_loop_.RunUntilIdle();
377 EXPECT_EQ(shill::kStateIdle, 410 EXPECT_EQ(shill::kStateIdle,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 TEST_F(NetworkStateHandlerTest, RequestUpdate) { 515 TEST_F(NetworkStateHandlerTest, RequestUpdate) {
483 // Request an update for kShillManagerClientStubDefaultWifi. 516 // Request an update for kShillManagerClientStubDefaultWifi.
484 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( 517 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(
485 kShillManagerClientStubDefaultWifi)); 518 kShillManagerClientStubDefaultWifi));
486 network_state_handler_->RequestUpdateForNetwork( 519 network_state_handler_->RequestUpdateForNetwork(
487 kShillManagerClientStubDefaultWifi); 520 kShillManagerClientStubDefaultWifi);
488 message_loop_.RunUntilIdle(); 521 message_loop_.RunUntilIdle();
489 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( 522 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(
490 kShillManagerClientStubDefaultWifi)); 523 kShillManagerClientStubDefaultWifi));
491 } 524 }
525
526 TEST_F(NetworkStateHandlerTest, NetworkGuidInProfile) {
527 const std::string profile = "/profile/profile1";
528 const std::string wifi_path = "wifi_with_guid";
529 const std::string wifi_guid = "WIFI_GUID";
530 const bool is_service_configured = true;
531
532 // And a network to the default Profile with a specified GUID.
pneubeck (no reviews) 2014/05/14 08:46:07 typo: And -> Add
stevenjb 2014/05/14 17:31:56 Done.
533 service_test_->AddServiceWithIPConfig(
534 wifi_path,
535 wifi_guid,
536 wifi_path /* name */,
537 shill::kTypeWifi,
538 shill::kStateOnline,
539 "" /* ipconfig_path */,
540 true /* add_to_visible */,
541 true /* add_to_watchlist */);
542 profile_test_->AddProfile(profile, "" /* userhash */);
543 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path));
544 UpdateManagerProperties();
545
546 // Verify that a FavoriteState exists with a matching GUID.
547 const FavoriteState* favorite =
548 network_state_handler_->GetFavoriteStateFromServicePath(
549 wifi_path, is_service_configured);
550 ASSERT_TRUE(favorite);
551 EXPECT_EQ(wifi_guid, favorite->guid());
552
553 // Verify that a NetworkState exists with the same GUID.
554 const NetworkState* network =
555 network_state_handler_->GetNetworkState(wifi_path);
556 ASSERT_TRUE(network);
557 EXPECT_EQ(wifi_guid, network->guid());
558
559 // Remove the service (simulating a network going out of range).
560 service_test_->RemoveService(wifi_path);
561 UpdateManagerProperties();
562 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
pneubeck (no reviews) 2014/05/14 08:46:07 this EXPECT should also be moved to test 'Favorite
stevenjb 2014/05/14 17:31:56 See above.
563
564 // Add the service (simulating a network coming back in range) and verify that
565 // the NetworkState was created with the same GUID.
566 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
567 UpdateManagerProperties();
568 network = network_state_handler_->GetNetworkState(wifi_path);
569 ASSERT_TRUE(network);
570 EXPECT_EQ(wifi_guid, network->guid());
571 }
pneubeck (no reviews) 2014/05/14 08:46:07 optional: at the end of this test and the next one
stevenjb 2014/05/14 17:31:56 Done.
572
573 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) {
574 const std::string wifi_path = "wifi_with_guid";
575 const bool is_service_configured = false;
576
577 // And a network without adding it to a profile.
pneubeck (no reviews) 2014/05/14 08:46:07 typo: And -> Add
stevenjb 2014/05/14 17:31:56 Done.
578 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
579 UpdateManagerProperties();
580
581 // Verify that a FavoriteState exists with an assigned GUID.
582 const FavoriteState* favorite =
583 network_state_handler_->GetFavoriteStateFromServicePath(
584 wifi_path, is_service_configured);
585 ASSERT_TRUE(favorite);
586 std::string wifi_guid = favorite->guid();
587 EXPECT_FALSE(wifi_guid.empty());
588
589 // Verify that a NetworkState exists with the same GUID.
590 const NetworkState* network =
591 network_state_handler_->GetNetworkState(wifi_path);
592 ASSERT_TRUE(network);
593 EXPECT_EQ(wifi_guid, network->guid());
594
595 // Remove the service (simulating a network going out of range).
596 service_test_->RemoveService(wifi_path);
597 UpdateManagerProperties();
598 EXPECT_FALSE(network_state_handler_->GetNetworkState(wifi_path));
pneubeck (no reviews) 2014/05/14 08:46:07 remove
stevenjb 2014/05/14 17:31:56 It may be redundant, but I think it makes the test
599
600 // Add the service (simulating a network coming back in range) and verify that
601 // the NetworkState was created with the same GUID.
602 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
603 UpdateManagerProperties();
604 network = network_state_handler_->GetNetworkState(wifi_path);
605 ASSERT_TRUE(network);
606 EXPECT_EQ(wifi_guid, network->guid());
607 }
608
492 } // namespace chromeos 609 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler.cc ('k') | chromeos/network/network_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698