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

Side by Side Diff: chrome/browser/chromeos/cros/cros_network_functions_unittest.cc

Issue 11367048: This is the first pass at making GetIPConfigs asynchronous. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 "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 "chrome/browser/chromeos/cros/cros_network_functions.h" 8 #include "chrome/browser/chromeos/cros/cros_network_functions.h"
9 #include "chrome/browser/chromeos/cros/sms_watcher.h" 9 #include "chrome/browser/chromeos/cros/sms_watcher.h"
10 #include "chromeos/dbus/mock_cashew_client.h" 10 #include "chromeos/dbus/mock_cashew_client.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 const char kExamplePath[] = "/foo/bar/baz"; 48 const char kExamplePath[] = "/foo/bar/baz";
49 49
50 // A mock to check arguments of NetworkPropertiesCallback and ensure that the 50 // A mock to check arguments of NetworkPropertiesCallback and ensure that the
51 // callback is called exactly once. 51 // callback is called exactly once.
52 class MockNetworkPropertiesCallback { 52 class MockNetworkPropertiesCallback {
53 public: 53 public:
54 // Creates a NetworkPropertiesCallback with expectations. 54 // Creates a NetworkPropertiesCallback with expectations.
55 static NetworkPropertiesCallback CreateCallback( 55 static NetworkPropertiesCallback CreateCallback(
56 const std::string& expected_path, 56 const std::string& expected_path,
57 const base::DictionaryValue& expected_result) { 57 base::DictionaryValue& expected_result) {
58 MockNetworkPropertiesCallback* mock_callback = 58 MockNetworkPropertiesCallback* mock_callback =
59 new MockNetworkPropertiesCallback; 59 new MockNetworkPropertiesCallback;
60 60
61 EXPECT_CALL(*mock_callback, 61 EXPECT_CALL(*mock_callback,
62 Run(expected_path, Pointee(IsEqualTo(&expected_result)))) 62 RunMock(expected_path, Pointee(IsEqualTo(&expected_result))))
63 .Times(1); 63 .Times(1);
64 64
65 return base::Bind(&MockNetworkPropertiesCallback::Run, 65 return base::Bind(&MockNetworkPropertiesCallback::Run,
66 base::Owned(mock_callback)); 66 base::Owned(mock_callback));
67 } 67 }
68 68
69 MOCK_METHOD2(Run, void(const std::string& path, 69 // We have to implement this as a non-mock and call the mock function because
70 const base::DictionaryValue* result)); 70 // mocks don't play well with scoped_ptr arguments because they are movable
71 // but not copyable. Expectations are placed on the RunMock function instead.
72 void Run(const std::string& path,
73 scoped_ptr<base::DictionaryValue> result) {
74 RunMock(path, result.get());
75 }
76
77 MOCK_METHOD2(RunMock, void(const std::string& path,
78 base::DictionaryValue* result));
71 }; 79 };
72 80
73 // A mock to check arguments of NetworkPropertiesWatcherCallback and ensure that 81 // A mock to check arguments of NetworkPropertiesWatcherCallback and ensure that
74 // the callback is called exactly once. 82 // the callback is called exactly once.
75 class MockNetworkPropertiesWatcherCallback { 83 class MockNetworkPropertiesWatcherCallback {
76 public: 84 public:
77 // Creates a NetworkPropertiesWatcherCallback with expectations. 85 // Creates a NetworkPropertiesWatcherCallback with expectations.
78 static NetworkPropertiesWatcherCallback CreateCallback( 86 static NetworkPropertiesWatcherCallback CreateCallback(
79 const std::string& expected_path, 87 const std::string& expected_path,
80 const std::string& expected_key, 88 const std::string& expected_key,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 mock_gsm_sms_client_ = mock_dbus_thread_manager->mock_gsm_sms_client(); 182 mock_gsm_sms_client_ = mock_dbus_thread_manager->mock_gsm_sms_client();
175 } 183 }
176 184
177 virtual void TearDown() { 185 virtual void TearDown() {
178 DBusThreadManager::Shutdown(); 186 DBusThreadManager::Shutdown();
179 mock_profile_client_ = NULL; 187 mock_profile_client_ = NULL;
180 } 188 }
181 189
182 // Handles responses for GetProperties method calls for ShillManagerClient. 190 // Handles responses for GetProperties method calls for ShillManagerClient.
183 void OnGetManagerProperties( 191 void OnGetManagerProperties(
184 const ShillClientHelper::DictionaryValueCallback& callback) { 192 const ShillClientHelper::DictionaryValueCallback& callback) {
185 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); 193 scoped_ptr<base::DictionaryValue> result_copy(
194 dictionary_value_result_->DeepCopy());
195 callback.Run(DBUS_METHOD_CALL_SUCCESS, result_copy.Pass());
186 } 196 }
187 197
188 // Handles responses for GetProperties method calls. 198 // Handles responses for GetProperties method calls.
189 void OnGetProperties( 199 void OnGetProperties(
190 const dbus::ObjectPath& path, 200 const dbus::ObjectPath& path,
191 const ShillClientHelper::DictionaryValueCallback& callback) { 201 const ShillClientHelper::DictionaryValueCallback& callback) {
192 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); 202 scoped_ptr<base::DictionaryValue> result_copy(
203 dictionary_value_result_->DeepCopy());
204 callback.Run(DBUS_METHOD_CALL_SUCCESS, result_copy.Pass());
193 } 205 }
194 206
195 // Handles responses for GetProperties method calls that return 207 // Handles responses for GetProperties method calls that return
196 // errors in an error callback. 208 // errors in an error callback.
197 void OnGetPropertiesWithoutStatus( 209 void OnGetPropertiesWithoutStatus(
198 const dbus::ObjectPath& path, 210 const dbus::ObjectPath& path,
199 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback, 211 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
200 const ShillClientHelper::ErrorCallback& error_callback) { 212 const ShillClientHelper::ErrorCallback& error_callback) {
201 callback.Run(*dictionary_value_result_); 213 scoped_ptr<base::DictionaryValue> result_copy(
214 dictionary_value_result_->DeepCopy());
215 callback.Run(result_copy.Pass());
202 } 216 }
203 217
204 // Handles responses for GetEntry method calls. 218 // Handles responses for GetEntry method calls.
205 void OnGetEntry( 219 void OnGetEntry(
206 const dbus::ObjectPath& profile_path, 220 const dbus::ObjectPath& profile_path,
207 const std::string& entry_path, 221 const std::string& entry_path,
208 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback, 222 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
209 const ShillClientHelper::ErrorCallback& error_callback) { 223 const ShillClientHelper::ErrorCallback& error_callback) {
210 callback.Run(*dictionary_value_result_); 224 scoped_ptr<base::DictionaryValue> result_copy(
225 dictionary_value_result_->DeepCopy());
226 callback.Run(result_copy.Pass());
211 } 227 }
212 228
213 // Mock NetworkOperationCallback. 229 // Mock NetworkOperationCallback.
214 MOCK_METHOD3(MockNetworkOperationCallback, 230 MOCK_METHOD3(MockNetworkOperationCallback,
215 void(const std::string& path, 231 void(const std::string& path,
216 NetworkMethodErrorType error, 232 NetworkMethodErrorType error,
217 const std::string& error_message)); 233 const std::string& error_message));
218 234
219 // Mock MonitorSMSCallback. 235 // Mock MonitorSMSCallback.
220 MOCK_METHOD2(MockMonitorSMSCallback, 236 MOCK_METHOD2(MockMonitorSMSCallback,
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 EXPECT_CALL(*mock_gsm_sms_client_, 543 EXPECT_CALL(*mock_gsm_sms_client_,
528 Get(dbus_connection, object_path, kIndex, _)) 544 Get(dbus_connection, object_path, kIndex, _))
529 .WillOnce(SaveArg<3>(&get_callback)); 545 .WillOnce(SaveArg<3>(&get_callback));
530 546
531 // Start monitoring. 547 // Start monitoring.
532 CrosNetworkWatcher* watcher = CrosMonitorSMS( 548 CrosNetworkWatcher* watcher = CrosMonitorSMS(
533 modem_device_path, 549 modem_device_path,
534 base::Bind(&CrosNetworkFunctionsTest::MockMonitorSMSCallback, 550 base::Bind(&CrosNetworkFunctionsTest::MockMonitorSMSCallback,
535 base::Unretained(this))); 551 base::Unretained(this)));
536 // Return GetProperties() result. 552 // Return GetProperties() result.
537 get_properties_callback.Run(DBUS_METHOD_CALL_SUCCESS, device_properties); 553 scoped_ptr<base::DictionaryValue> properties_copy(
554 device_properties.DeepCopy());
555 get_properties_callback.Run(DBUS_METHOD_CALL_SUCCESS, properties_copy.Pass());
538 // Return List() result. 556 // Return List() result.
539 ASSERT_FALSE(list_callback.is_null()); 557 ASSERT_FALSE(list_callback.is_null());
540 list_callback.Run(sms_list); 558 list_callback.Run(sms_list);
541 // Return Delete() result. 559 // Return Delete() result.
542 ASSERT_FALSE(delete_callback.is_null()); 560 ASSERT_FALSE(delete_callback.is_null());
543 delete_callback.Run(); 561 delete_callback.Run();
544 // Send fake signal. 562 // Send fake signal.
545 ASSERT_FALSE(sms_received_handler.is_null()); 563 ASSERT_FALSE(sms_received_handler.is_null());
546 sms_received_handler.Run(kIndex, kComplete); 564 sms_received_handler.Run(kIndex, kComplete);
547 // Return Get() result. 565 // Return Get() result.
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 } 912 }
895 913
896 TEST_F(CrosNetworkFunctionsTest, CrosSetOfflineMode) { 914 TEST_F(CrosNetworkFunctionsTest, CrosSetOfflineMode) {
897 const bool kOffline = true; 915 const bool kOffline = true;
898 const base::FundamentalValue value(kOffline); 916 const base::FundamentalValue value(kOffline);
899 EXPECT_CALL(*mock_manager_client_, SetProperty( 917 EXPECT_CALL(*mock_manager_client_, SetProperty(
900 flimflam::kOfflineModeProperty, IsEqualTo(&value), _, _)).Times(1); 918 flimflam::kOfflineModeProperty, IsEqualTo(&value), _, _)).Times(1);
901 CrosSetOfflineMode(kOffline); 919 CrosSetOfflineMode(kOffline);
902 } 920 }
903 921
904 TEST_F(CrosNetworkFunctionsTest, CrosListIPConfigs) { 922 TEST_F(CrosNetworkFunctionsTest, CrosListIPConfigsAndBlock) {
905 const std::string device_path = "/device/path"; 923 const std::string device_path = "/device/path";
906 std::string ipconfig_path = "/ipconfig/path"; 924 std::string ipconfig_path = "/ipconfig/path";
907 925
908 const IPConfigType kType = IPCONFIG_TYPE_DHCP; 926 const IPConfigType kType = IPCONFIG_TYPE_DHCP;
909 const std::string address = "address"; 927 const std::string address = "address";
910 const int kMtu = 123; 928 const int kMtu = 123;
911 const int kPrefixlen = 24; 929 const int kPrefixlen = 24;
912 const std::string netmask = "255.255.255.0"; 930 const std::string netmask = "255.255.255.0";
913 const std::string broadcast = "broadcast"; 931 const std::string broadcast = "broadcast";
914 const std::string peer_address = "peer address"; 932 const std::string peer_address = "peer address";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 CallGetPropertiesAndBlock(dbus::ObjectPath(device_path))) 981 CallGetPropertiesAndBlock(dbus::ObjectPath(device_path)))
964 .WillOnce(Return(device_properties)); 982 .WillOnce(Return(device_properties));
965 EXPECT_CALL(*mock_ipconfig_client_, 983 EXPECT_CALL(*mock_ipconfig_client_,
966 CallGetPropertiesAndBlock(dbus::ObjectPath(ipconfig_path))) 984 CallGetPropertiesAndBlock(dbus::ObjectPath(ipconfig_path)))
967 .WillOnce(Return(ipconfig_properties)); 985 .WillOnce(Return(ipconfig_properties));
968 986
969 NetworkIPConfigVector result_ipconfigs; 987 NetworkIPConfigVector result_ipconfigs;
970 std::vector<std::string> result_ipconfig_paths; 988 std::vector<std::string> result_ipconfig_paths;
971 std::string result_hardware_address; 989 std::string result_hardware_address;
972 EXPECT_TRUE( 990 EXPECT_TRUE(
973 CrosListIPConfigs(device_path, &result_ipconfigs, &result_ipconfig_paths, 991 CrosListIPConfigsAndBlock(device_path,
974 &result_hardware_address)); 992 &result_ipconfigs,
993 &result_ipconfig_paths,
994 &result_hardware_address));
975 995
976 EXPECT_EQ(hardware_address, result_hardware_address); 996 EXPECT_EQ(hardware_address, result_hardware_address);
977 ASSERT_EQ(1U, result_ipconfigs.size()); 997 ASSERT_EQ(1U, result_ipconfigs.size());
978 EXPECT_EQ(device_path, result_ipconfigs[0].device_path); 998 EXPECT_EQ(device_path, result_ipconfigs[0].device_path);
979 EXPECT_EQ(kType, result_ipconfigs[0].type); 999 EXPECT_EQ(kType, result_ipconfigs[0].type);
980 EXPECT_EQ(address, result_ipconfigs[0].address); 1000 EXPECT_EQ(address, result_ipconfigs[0].address);
981 EXPECT_EQ(netmask, result_ipconfigs[0].netmask); 1001 EXPECT_EQ(netmask, result_ipconfigs[0].netmask);
982 EXPECT_EQ(gateway, result_ipconfigs[0].gateway); 1002 EXPECT_EQ(gateway, result_ipconfigs[0].gateway);
983 EXPECT_EQ(name_servers, result_ipconfigs[0].name_servers); 1003 EXPECT_EQ(name_servers, result_ipconfigs[0].name_servers);
984 ASSERT_EQ(1U, result_ipconfig_paths.size()); 1004 ASSERT_EQ(1U, result_ipconfig_paths.size());
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 EXPECT_EQ("192.0.0.0", CrosPrefixLengthToNetmask(2)); 1182 EXPECT_EQ("192.0.0.0", CrosPrefixLengthToNetmask(2));
1163 EXPECT_EQ("128.0.0.0", CrosPrefixLengthToNetmask(1)); 1183 EXPECT_EQ("128.0.0.0", CrosPrefixLengthToNetmask(1));
1164 EXPECT_EQ("0.0.0.0", CrosPrefixLengthToNetmask(0)); 1184 EXPECT_EQ("0.0.0.0", CrosPrefixLengthToNetmask(0));
1165 // Invalid Prefix Lengths 1185 // Invalid Prefix Lengths
1166 EXPECT_EQ("", CrosPrefixLengthToNetmask(-1)); 1186 EXPECT_EQ("", CrosPrefixLengthToNetmask(-1));
1167 EXPECT_EQ("", CrosPrefixLengthToNetmask(33)); 1187 EXPECT_EQ("", CrosPrefixLengthToNetmask(33));
1168 EXPECT_EQ("", CrosPrefixLengthToNetmask(255)); 1188 EXPECT_EQ("", CrosPrefixLengthToNetmask(255));
1169 } 1189 }
1170 1190
1171 } // namespace chromeos 1191 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698