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

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

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 network_state_handler_->GetTechnologyState(NetworkTypePattern::Tether())); 539 network_state_handler_->GetTechnologyState(NetworkTypePattern::Tether()));
540 } 540 }
541 541
542 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { 542 TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) {
543 // Set a service property. 543 // Set a service property.
544 const std::string eth1 = kShillManagerClientStubDefaultService; 544 const std::string eth1 = kShillManagerClientStubDefaultService;
545 const NetworkState* ethernet = network_state_handler_->GetNetworkState(eth1); 545 const NetworkState* ethernet = network_state_handler_->GetNetworkState(eth1);
546 ASSERT_TRUE(ethernet); 546 ASSERT_TRUE(ethernet);
547 EXPECT_EQ("", ethernet->security_class()); 547 EXPECT_EQ("", ethernet->security_class());
548 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth1)); 548 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth1));
549 base::StringValue security_class_value("TestSecurityClass"); 549 base::Value security_class_value("TestSecurityClass");
550 SetServiceProperty(eth1, shill::kSecurityClassProperty, security_class_value); 550 SetServiceProperty(eth1, shill::kSecurityClassProperty, security_class_value);
551 base::RunLoop().RunUntilIdle(); 551 base::RunLoop().RunUntilIdle();
552 ethernet = network_state_handler_->GetNetworkState(eth1); 552 ethernet = network_state_handler_->GetNetworkState(eth1);
553 EXPECT_EQ("TestSecurityClass", ethernet->security_class()); 553 EXPECT_EQ("TestSecurityClass", ethernet->security_class());
554 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1)); 554 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1));
555 555
556 // Changing a service to the existing value should not trigger an update. 556 // Changing a service to the existing value should not trigger an update.
557 SetServiceProperty(eth1, shill::kSecurityClassProperty, security_class_value); 557 SetServiceProperty(eth1, shill::kSecurityClassProperty, security_class_value);
558 base::RunLoop().RunUntilIdle(); 558 base::RunLoop().RunUntilIdle();
559 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1)); 559 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 network_state_handler_->SetTetherNetworkStateDisconnected(kTetherGuid1); 627 network_state_handler_->SetTetherNetworkStateDisconnected(kTetherGuid1);
628 EXPECT_FALSE(tether_network->IsConnectingState()); 628 EXPECT_FALSE(tether_network->IsConnectingState());
629 EXPECT_FALSE(tether_network->IsConnectedState()); 629 EXPECT_FALSE(tether_network->IsConnectedState());
630 } 630 }
631 631
632 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { 632 TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) {
633 const std::string eth1 = kShillManagerClientStubDefaultService; 633 const std::string eth1 = kShillManagerClientStubDefaultService;
634 EXPECT_EQ(0, test_observer_->ConnectionStateChangesForService(eth1)); 634 EXPECT_EQ(0, test_observer_->ConnectionStateChangesForService(eth1));
635 635
636 // Change a network state. 636 // Change a network state.
637 base::StringValue connection_state_idle_value(shill::kStateIdle); 637 base::Value connection_state_idle_value(shill::kStateIdle);
638 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 638 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
639 connection_state_idle_value); 639 connection_state_idle_value);
640 base::RunLoop().RunUntilIdle(); 640 base::RunLoop().RunUntilIdle();
641 EXPECT_EQ(shill::kStateIdle, 641 EXPECT_EQ(shill::kStateIdle,
642 test_observer_->NetworkConnectionStateForService(eth1)); 642 test_observer_->NetworkConnectionStateForService(eth1));
643 EXPECT_EQ(1, test_observer_->ConnectionStateChangesForService(eth1)); 643 EXPECT_EQ(1, test_observer_->ConnectionStateChangesForService(eth1));
644 // Confirm that changing the connection state to the same value does *not* 644 // Confirm that changing the connection state to the same value does *not*
645 // signal the observer. 645 // signal the observer.
646 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 646 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
647 connection_state_idle_value); 647 connection_state_idle_value);
648 base::RunLoop().RunUntilIdle(); 648 base::RunLoop().RunUntilIdle();
649 EXPECT_EQ(1, test_observer_->ConnectionStateChangesForService(eth1)); 649 EXPECT_EQ(1, test_observer_->ConnectionStateChangesForService(eth1));
650 } 650 }
651 651
652 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) { 652 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) {
653 const std::string eth1 = kShillManagerClientStubDefaultService; 653 const std::string eth1 = kShillManagerClientStubDefaultService;
654 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 654 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
655 655
656 EXPECT_EQ(0u, test_observer_->default_network_change_count()); 656 EXPECT_EQ(0u, test_observer_->default_network_change_count());
657 // Disconnect ethernet. 657 // Disconnect ethernet.
658 base::StringValue connection_state_idle_value(shill::kStateIdle); 658 base::Value connection_state_idle_value(shill::kStateIdle);
659 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 659 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
660 connection_state_idle_value); 660 connection_state_idle_value);
661 base::RunLoop().RunUntilIdle(); 661 base::RunLoop().RunUntilIdle();
662 // Expect two changes: first when eth1 becomes disconnected, second when 662 // Expect two changes: first when eth1 becomes disconnected, second when
663 // wifi1 becomes the default. 663 // wifi1 becomes the default.
664 EXPECT_EQ(2u, test_observer_->default_network_change_count()); 664 EXPECT_EQ(2u, test_observer_->default_network_change_count());
665 EXPECT_EQ(wifi1, test_observer_->default_network()); 665 EXPECT_EQ(wifi1, test_observer_->default_network());
666 666
667 // Disconnect wifi. 667 // Disconnect wifi.
668 test_observer_->reset_change_counts(); 668 test_observer_->reset_change_counts();
669 service_test_->SetServiceProperty(wifi1, shill::kStateProperty, 669 service_test_->SetServiceProperty(wifi1, shill::kStateProperty,
670 connection_state_idle_value); 670 connection_state_idle_value);
671 base::RunLoop().RunUntilIdle(); 671 base::RunLoop().RunUntilIdle();
672 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 672 EXPECT_EQ(1u, test_observer_->default_network_change_count());
673 EXPECT_EQ("", test_observer_->default_network()); 673 EXPECT_EQ("", test_observer_->default_network());
674 } 674 }
675 675
676 TEST_F(NetworkStateHandlerTest, DefaultServiceConnected) { 676 TEST_F(NetworkStateHandlerTest, DefaultServiceConnected) {
677 const std::string eth1 = kShillManagerClientStubDefaultService; 677 const std::string eth1 = kShillManagerClientStubDefaultService;
678 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 678 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
679 679
680 // Disconnect ethernet and wifi. 680 // Disconnect ethernet and wifi.
681 base::StringValue connection_state_idle_value(shill::kStateIdle); 681 base::Value connection_state_idle_value(shill::kStateIdle);
682 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 682 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
683 connection_state_idle_value); 683 connection_state_idle_value);
684 service_test_->SetServiceProperty(wifi1, shill::kStateProperty, 684 service_test_->SetServiceProperty(wifi1, shill::kStateProperty,
685 connection_state_idle_value); 685 connection_state_idle_value);
686 base::RunLoop().RunUntilIdle(); 686 base::RunLoop().RunUntilIdle();
687 EXPECT_EQ(std::string(), test_observer_->default_network()); 687 EXPECT_EQ(std::string(), test_observer_->default_network());
688 688
689 // Connect ethernet, should become the default network. 689 // Connect ethernet, should become the default network.
690 test_observer_->reset_change_counts(); 690 test_observer_->reset_change_counts();
691 base::StringValue connection_state_ready_value(shill::kStateReady); 691 base::Value connection_state_ready_value(shill::kStateReady);
692 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 692 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
693 connection_state_ready_value); 693 connection_state_ready_value);
694 base::RunLoop().RunUntilIdle(); 694 base::RunLoop().RunUntilIdle();
695 EXPECT_EQ(eth1, test_observer_->default_network()); 695 EXPECT_EQ(eth1, test_observer_->default_network());
696 EXPECT_EQ(shill::kStateReady, 696 EXPECT_EQ(shill::kStateReady,
697 test_observer_->default_network_connection_state()); 697 test_observer_->default_network_connection_state());
698 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 698 EXPECT_EQ(1u, test_observer_->default_network_change_count());
699 } 699 }
700 700
701 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { 701 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) {
702 const std::string eth1 = kShillManagerClientStubDefaultService; 702 const std::string eth1 = kShillManagerClientStubDefaultService;
703 // The default service should be eth1. 703 // The default service should be eth1.
704 EXPECT_EQ(eth1, test_observer_->default_network()); 704 EXPECT_EQ(eth1, test_observer_->default_network());
705 705
706 // Change the default network by changing Manager.DefaultService. 706 // Change the default network by changing Manager.DefaultService.
707 // This should only generate one default network notification when the 707 // This should only generate one default network notification when the
708 // DefaultService property changes. 708 // DefaultService property changes.
709 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 709 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
710 SetServiceProperty(eth1, shill::kStateProperty, 710 SetServiceProperty(eth1, shill::kStateProperty,
711 base::StringValue(shill::kStateIdle)); 711 base::Value(shill::kStateIdle));
712 manager_test_->SetManagerProperty(shill::kDefaultServiceProperty, 712 manager_test_->SetManagerProperty(shill::kDefaultServiceProperty,
713 base::StringValue(wifi1)); 713 base::Value(wifi1));
714 base::RunLoop().RunUntilIdle(); 714 base::RunLoop().RunUntilIdle();
715 EXPECT_EQ(wifi1, test_observer_->default_network()); 715 EXPECT_EQ(wifi1, test_observer_->default_network());
716 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 716 EXPECT_EQ(1u, test_observer_->default_network_change_count());
717 717
718 // Change the state of the default network. This should generate a 718 // Change the state of the default network. This should generate a
719 // default network notification. 719 // default network notification.
720 test_observer_->reset_change_counts(); 720 test_observer_->reset_change_counts();
721 service_test_->SetServiceProperty(wifi1, shill::kStateProperty, 721 service_test_->SetServiceProperty(wifi1, shill::kStateProperty,
722 base::StringValue(shill::kStateReady)); 722 base::Value(shill::kStateReady));
723 base::RunLoop().RunUntilIdle(); 723 base::RunLoop().RunUntilIdle();
724 EXPECT_EQ(shill::kStateReady, 724 EXPECT_EQ(shill::kStateReady,
725 test_observer_->default_network_connection_state()); 725 test_observer_->default_network_connection_state());
726 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 726 EXPECT_EQ(1u, test_observer_->default_network_change_count());
727 727
728 // Updating a property on the default network should also trigger 728 // Updating a property on the default network should also trigger
729 // a default network change. 729 // a default network change.
730 test_observer_->reset_change_counts(); 730 test_observer_->reset_change_counts();
731 SetServiceProperty(wifi1, shill::kSecurityClassProperty, 731 SetServiceProperty(wifi1, shill::kSecurityClassProperty,
732 base::StringValue("TestSecurityClass")); 732 base::Value("TestSecurityClass"));
733 base::RunLoop().RunUntilIdle(); 733 base::RunLoop().RunUntilIdle();
734 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 734 EXPECT_EQ(1u, test_observer_->default_network_change_count());
735 735
736 // No default network updates for signal strength changes. 736 // No default network updates for signal strength changes.
737 test_observer_->reset_change_counts(); 737 test_observer_->reset_change_counts();
738 SetServiceProperty(wifi1, shill::kSignalStrengthProperty, base::Value(32)); 738 SetServiceProperty(wifi1, shill::kSignalStrengthProperty, base::Value(32));
739 base::RunLoop().RunUntilIdle(); 739 base::RunLoop().RunUntilIdle();
740 EXPECT_EQ(0u, test_observer_->default_network_change_count()); 740 EXPECT_EQ(0u, test_observer_->default_network_change_count());
741 741
742 // Change the default network to a Connecting network, then set the 742 // Change the default network to a Connecting network, then set the
743 // state to Connected. The DefaultNetworkChange notification should only 743 // state to Connected. The DefaultNetworkChange notification should only
744 // fire once when the network is connected. 744 // fire once when the network is connected.
745 test_observer_->reset_change_counts(); 745 test_observer_->reset_change_counts();
746 SetServiceProperty(wifi1, shill::kStateProperty, 746 SetServiceProperty(wifi1, shill::kStateProperty,
747 base::StringValue(shill::kStateIdle)); 747 base::Value(shill::kStateIdle));
748 base::RunLoop().RunUntilIdle(); 748 base::RunLoop().RunUntilIdle();
749 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 749 EXPECT_EQ(1u, test_observer_->default_network_change_count());
750 EXPECT_EQ(std::string(), test_observer_->default_network()); 750 EXPECT_EQ(std::string(), test_observer_->default_network());
751 751
752 const std::string wifi2 = kShillManagerClientStubWifi2; 752 const std::string wifi2 = kShillManagerClientStubWifi2;
753 manager_test_->SetManagerProperty(shill::kDefaultServiceProperty, 753 manager_test_->SetManagerProperty(shill::kDefaultServiceProperty,
754 base::StringValue(wifi2)); 754 base::Value(wifi2));
755 base::RunLoop().RunUntilIdle(); 755 base::RunLoop().RunUntilIdle();
756 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 756 EXPECT_EQ(1u, test_observer_->default_network_change_count());
757 // Change the connection state of the default network, observer should fire. 757 // Change the connection state of the default network, observer should fire.
758 SetServiceProperty(wifi2, shill::kStateProperty, 758 SetServiceProperty(wifi2, shill::kStateProperty,
759 base::StringValue(shill::kStateReady)); 759 base::Value(shill::kStateReady));
760 base::RunLoop().RunUntilIdle(); 760 base::RunLoop().RunUntilIdle();
761 EXPECT_EQ(wifi2, test_observer_->default_network()); 761 EXPECT_EQ(wifi2, test_observer_->default_network());
762 EXPECT_EQ(2u, test_observer_->default_network_change_count()); 762 EXPECT_EQ(2u, test_observer_->default_network_change_count());
763 } 763 }
764 764
765 TEST_F(NetworkStateHandlerTest, RequestUpdate) { 765 TEST_F(NetworkStateHandlerTest, RequestUpdate) {
766 // Request an update for kShillManagerClientStubDefaultWifi. 766 // Request an update for kShillManagerClientStubDefaultWifi.
767 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( 767 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(
768 kShillManagerClientStubDefaultWifi)); 768 kShillManagerClientStubDefaultWifi));
769 network_state_handler_->RequestUpdateForNetwork( 769 network_state_handler_->RequestUpdateForNetwork(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 ShillIPConfigClient::TestInterface* ip_config_test = 871 ShillIPConfigClient::TestInterface* ip_config_test =
872 DBusThreadManager::Get()->GetShillIPConfigClient()->GetTestInterface(); 872 DBusThreadManager::Get()->GetShillIPConfigClient()->GetTestInterface();
873 const std::string kIPConfigPath = "test_ip_config"; 873 const std::string kIPConfigPath = "test_ip_config";
874 base::DictionaryValue ip_config_properties; 874 base::DictionaryValue ip_config_properties;
875 ip_config_test->AddIPConfig(kIPConfigPath, ip_config_properties); 875 ip_config_test->AddIPConfig(kIPConfigPath, ip_config_properties);
876 base::ListValue device_ip_configs; 876 base::ListValue device_ip_configs;
877 device_ip_configs.AppendString(kIPConfigPath); 877 device_ip_configs.AppendString(kIPConfigPath);
878 device_test_->SetDeviceProperty( 878 device_test_->SetDeviceProperty(
879 kShillManagerClientStubWifiDevice, shill::kIPConfigsProperty, 879 kShillManagerClientStubWifiDevice, shill::kIPConfigsProperty,
880 device_ip_configs); 880 device_ip_configs);
881 service_test_->SetServiceProperty( 881 service_test_->SetServiceProperty(kShillManagerClientStubDefaultWifi,
882 kShillManagerClientStubDefaultWifi, shill::kIPConfigProperty, 882 shill::kIPConfigProperty,
883 base::StringValue(kIPConfigPath)); 883 base::Value(kIPConfigPath));
884 UpdateManagerProperties(); 884 UpdateManagerProperties();
885 EXPECT_EQ(1, test_observer_->PropertyUpdatesForDevice( 885 EXPECT_EQ(1, test_observer_->PropertyUpdatesForDevice(
886 kShillManagerClientStubWifiDevice)); 886 kShillManagerClientStubWifiDevice));
887 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( 887 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(
888 kShillManagerClientStubDefaultWifi)); 888 kShillManagerClientStubDefaultWifi));
889 } 889 }
890 890
891 } // namespace chromeos 891 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_connect_unittest.cc ('k') | chromeos/network/onc/onc_translator_onc_to_shill.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698