| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 8 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/mock_gsm_sms_client.h" | 9 #include "chromeos/dbus/mock_gsm_sms_client.h" |
| 10 #include "chromeos/dbus/mock_shill_device_client.h" | 10 #include "chromeos/dbus/mock_shill_device_client.h" |
| 11 #include "chromeos/dbus/mock_shill_ipconfig_client.h" | 11 #include "chromeos/dbus/mock_shill_ipconfig_client.h" |
| 12 #include "chromeos/dbus/mock_shill_manager_client.h" | 12 #include "chromeos/dbus/mock_shill_manager_client.h" |
| 13 #include "chromeos/dbus/mock_shill_network_client.h" | |
| 14 #include "chromeos/dbus/mock_shill_profile_client.h" | 13 #include "chromeos/dbus/mock_shill_profile_client.h" |
| 15 #include "chromeos/dbus/mock_shill_service_client.h" | 14 #include "chromeos/dbus/mock_shill_service_client.h" |
| 16 #include "chromeos/network/cros_network_functions.h" | 15 #include "chromeos/network/cros_network_functions.h" |
| 17 #include "chromeos/network/sms_watcher.h" | 16 #include "chromeos/network/sms_watcher.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 20 | 19 |
| 21 using ::testing::_; | 20 using ::testing::_; |
| 22 using ::testing::Invoke; | 21 using ::testing::Invoke; |
| 23 using ::testing::Pointee; | 22 using ::testing::Pointee; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | 105 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; |
| 107 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | 106 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) |
| 108 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | 107 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); |
| 109 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 108 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
| 110 mock_device_client_ = | 109 mock_device_client_ = |
| 111 mock_dbus_thread_manager->mock_shill_device_client(); | 110 mock_dbus_thread_manager->mock_shill_device_client(); |
| 112 mock_ipconfig_client_ = | 111 mock_ipconfig_client_ = |
| 113 mock_dbus_thread_manager->mock_shill_ipconfig_client(); | 112 mock_dbus_thread_manager->mock_shill_ipconfig_client(); |
| 114 mock_manager_client_ = | 113 mock_manager_client_ = |
| 115 mock_dbus_thread_manager->mock_shill_manager_client(); | 114 mock_dbus_thread_manager->mock_shill_manager_client(); |
| 116 mock_network_client_ = | |
| 117 mock_dbus_thread_manager->mock_shill_network_client(); | |
| 118 mock_profile_client_ = | 115 mock_profile_client_ = |
| 119 mock_dbus_thread_manager->mock_shill_profile_client(); | 116 mock_dbus_thread_manager->mock_shill_profile_client(); |
| 120 mock_service_client_ = | 117 mock_service_client_ = |
| 121 mock_dbus_thread_manager->mock_shill_service_client(); | 118 mock_dbus_thread_manager->mock_shill_service_client(); |
| 122 mock_gsm_sms_client_ = mock_dbus_thread_manager->mock_gsm_sms_client(); | 119 mock_gsm_sms_client_ = mock_dbus_thread_manager->mock_gsm_sms_client(); |
| 123 } | 120 } |
| 124 | 121 |
| 125 virtual void TearDown() { | 122 virtual void TearDown() { |
| 126 DBusThreadManager::Shutdown(); | 123 DBusThreadManager::Shutdown(); |
| 127 mock_profile_client_ = NULL; | 124 mock_profile_client_ = NULL; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const std::string& error_message)); | 162 const std::string& error_message)); |
| 166 | 163 |
| 167 // Mock MonitorSMSCallback. | 164 // Mock MonitorSMSCallback. |
| 168 MOCK_METHOD2(MockMonitorSMSCallback, | 165 MOCK_METHOD2(MockMonitorSMSCallback, |
| 169 void(const std::string& modem_device_path, const SMS& message)); | 166 void(const std::string& modem_device_path, const SMS& message)); |
| 170 | 167 |
| 171 protected: | 168 protected: |
| 172 MockShillDeviceClient* mock_device_client_; | 169 MockShillDeviceClient* mock_device_client_; |
| 173 MockShillIPConfigClient* mock_ipconfig_client_; | 170 MockShillIPConfigClient* mock_ipconfig_client_; |
| 174 MockShillManagerClient* mock_manager_client_; | 171 MockShillManagerClient* mock_manager_client_; |
| 175 MockShillNetworkClient* mock_network_client_; | |
| 176 MockShillProfileClient* mock_profile_client_; | 172 MockShillProfileClient* mock_profile_client_; |
| 177 MockShillServiceClient* mock_service_client_; | 173 MockShillServiceClient* mock_service_client_; |
| 178 MockGsmSMSClient* mock_gsm_sms_client_; | 174 MockGsmSMSClient* mock_gsm_sms_client_; |
| 179 const base::DictionaryValue* dictionary_value_result_; | 175 const base::DictionaryValue* dictionary_value_result_; |
| 180 }; | 176 }; |
| 181 | 177 |
| 182 TEST_F(CrosNetworkFunctionsTest, CrosActivateCellularModem) { | 178 TEST_F(CrosNetworkFunctionsTest, CrosActivateCellularModem) { |
| 183 const std::string service_path = "/"; | 179 const std::string service_path = "/"; |
| 184 const std::string carrier = "carrier"; | 180 const std::string carrier = "carrier"; |
| 185 EXPECT_CALL(*mock_service_client_, | 181 EXPECT_CALL(*mock_service_client_, |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 EXPECT_EQ(device_path, result_ipconfigs[0].device_path); | 854 EXPECT_EQ(device_path, result_ipconfigs[0].device_path); |
| 859 EXPECT_EQ(kType, result_ipconfigs[0].type); | 855 EXPECT_EQ(kType, result_ipconfigs[0].type); |
| 860 EXPECT_EQ(address, result_ipconfigs[0].address); | 856 EXPECT_EQ(address, result_ipconfigs[0].address); |
| 861 EXPECT_EQ(netmask, result_ipconfigs[0].netmask); | 857 EXPECT_EQ(netmask, result_ipconfigs[0].netmask); |
| 862 EXPECT_EQ(gateway, result_ipconfigs[0].gateway); | 858 EXPECT_EQ(gateway, result_ipconfigs[0].gateway); |
| 863 EXPECT_EQ(name_servers, result_ipconfigs[0].name_servers); | 859 EXPECT_EQ(name_servers, result_ipconfigs[0].name_servers); |
| 864 ASSERT_EQ(1U, result_ipconfig_paths.size()); | 860 ASSERT_EQ(1U, result_ipconfig_paths.size()); |
| 865 EXPECT_EQ(ipconfig_path, result_ipconfig_paths[0]); | 861 EXPECT_EQ(ipconfig_path, result_ipconfig_paths[0]); |
| 866 } | 862 } |
| 867 | 863 |
| 868 TEST_F(CrosNetworkFunctionsTest, CrosGetWifiAccessPoints) { | |
| 869 const std::string device_path = "/device/path"; | |
| 870 base::ListValue* devices = new base::ListValue; | |
| 871 devices->Append(new base::StringValue(device_path)); | |
| 872 base::DictionaryValue* manager_properties = new base::DictionaryValue; | |
| 873 manager_properties->SetWithoutPathExpansion( | |
| 874 flimflam::kDevicesProperty, devices); | |
| 875 | |
| 876 const int kScanInterval = 42; | |
| 877 const std::string network_path = "/network/path"; | |
| 878 base::ListValue* networks = new base::ListValue; | |
| 879 networks->Append(new base::StringValue(network_path)); | |
| 880 base::DictionaryValue* device_properties = new base::DictionaryValue; | |
| 881 device_properties->SetWithoutPathExpansion( | |
| 882 flimflam::kNetworksProperty, networks); | |
| 883 device_properties->SetWithoutPathExpansion( | |
| 884 flimflam::kPoweredProperty, base::Value::CreateBooleanValue(true)); | |
| 885 device_properties->SetWithoutPathExpansion( | |
| 886 flimflam::kScanIntervalProperty, | |
| 887 base::Value::CreateIntegerValue(kScanInterval)); | |
| 888 | |
| 889 const int kSignalStrength = 10; | |
| 890 const int kWifiChannel = 3; | |
| 891 const std::string address = "address"; | |
| 892 const std::string name = "name"; | |
| 893 const base::Time expected_timestamp = | |
| 894 base::Time::Now() - base::TimeDelta::FromSeconds(kScanInterval); | |
| 895 const base::TimeDelta acceptable_timestamp_range = | |
| 896 base::TimeDelta::FromSeconds(1); | |
| 897 | |
| 898 base::DictionaryValue* network_properties = new base::DictionaryValue; | |
| 899 network_properties->SetWithoutPathExpansion( | |
| 900 flimflam::kAddressProperty, new base::StringValue(address)); | |
| 901 network_properties->SetWithoutPathExpansion( | |
| 902 flimflam::kNameProperty, new base::StringValue(name)); | |
| 903 network_properties->SetWithoutPathExpansion( | |
| 904 flimflam::kSignalStrengthProperty, | |
| 905 base::Value::CreateIntegerValue(kSignalStrength)); | |
| 906 network_properties->SetWithoutPathExpansion( | |
| 907 flimflam::kWifiChannelProperty, | |
| 908 base::Value::CreateIntegerValue(kWifiChannel)); | |
| 909 | |
| 910 // Set expectations. | |
| 911 EXPECT_CALL(*mock_manager_client_, CallGetPropertiesAndBlock()) | |
| 912 .WillOnce(Return(manager_properties)); | |
| 913 EXPECT_CALL(*mock_device_client_, | |
| 914 CallGetPropertiesAndBlock(dbus::ObjectPath(device_path))) | |
| 915 .WillOnce(Return(device_properties)); | |
| 916 EXPECT_CALL(*mock_network_client_, | |
| 917 CallGetPropertiesAndBlock(dbus::ObjectPath(network_path))) | |
| 918 .WillOnce(Return(network_properties)); | |
| 919 | |
| 920 // Call function. | |
| 921 WifiAccessPointVector aps; | |
| 922 ASSERT_TRUE(CrosGetWifiAccessPoints(&aps)); | |
| 923 ASSERT_EQ(1U, aps.size()); | |
| 924 EXPECT_EQ(address, aps[0].mac_address); | |
| 925 EXPECT_EQ(name, aps[0].name); | |
| 926 EXPECT_LE(expected_timestamp - acceptable_timestamp_range, aps[0].timestamp); | |
| 927 EXPECT_GE(expected_timestamp + acceptable_timestamp_range, aps[0].timestamp); | |
| 928 EXPECT_EQ(kSignalStrength, aps[0].signal_strength); | |
| 929 EXPECT_EQ(kWifiChannel, aps[0].channel); | |
| 930 } | |
| 931 | |
| 932 TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) { | 864 TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) { |
| 933 const std::string key1 = "key1"; | 865 const std::string key1 = "key1"; |
| 934 const std::string string1 = "string1"; | 866 const std::string string1 = "string1"; |
| 935 const std::string key2 = "key2"; | 867 const std::string key2 = "key2"; |
| 936 const std::string string2 = "string2"; | 868 const std::string string2 = "string2"; |
| 937 base::DictionaryValue value; | 869 base::DictionaryValue value; |
| 938 value.SetString(key1, string1); | 870 value.SetString(key1, string1); |
| 939 value.SetString(key2, string2); | 871 value.SetString(key2, string2); |
| 940 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _, _)) | 872 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _, _)) |
| 941 .Times(1); | 873 .Times(1); |
| 942 CrosConfigureService(value); | 874 CrosConfigureService(value); |
| 943 } | 875 } |
| 944 | 876 |
| 945 } // namespace chromeos | 877 } // namespace chromeos |
| OLD | NEW |