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

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

Issue 10134027: Reimplement RequestNetworkServiceConnect, RequestRequirePin, RequestEnterPin, RequestEnterPin, Requ… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove reinterpret_cast Created 8 years, 8 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
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/gvalue_util.h" 9 #include "chrome/browser/chromeos/cros/gvalue_util.h"
10 #include "chrome/browser/chromeos/cros/mock_chromeos_network.h" 10 #include "chrome/browser/chromeos/cros/mock_chromeos_network.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void* object) { 169 void* object) {
170 OnRequestNetworkProperties2(callback, object); 170 OnRequestNetworkProperties2(callback, object);
171 } 171 }
172 172
173 // Does nothing. Used as an argument. 173 // Does nothing. Used as an argument.
174 static void OnNetworkAction(void* object, 174 static void OnNetworkAction(void* object,
175 const char* path, 175 const char* path,
176 NetworkMethodErrorType error, 176 NetworkMethodErrorType error,
177 const char* error_message) {} 177 const char* error_message) {}
178 178
179 // Does nothing. Used as an argument.
180 static void OnDataPlansUpdate(void* object,
181 const char* modem_service_path,
182 const CellularDataPlanList* dataplan) {}
183
184 // Does nothing. Used as an argument.
185 static void OnSmsReceived(void* object,
186 const char* modem_device_path,
187 const SMS* message) {}
188
189
179 protected: 190 protected:
180 ScopedGValue argument_gvalue_; 191 ScopedGValue argument_gvalue_;
181 ScopedGHashTable argument_ghash_table_; 192 ScopedGHashTable argument_ghash_table_;
182 ScopedGHashTable result_ghash_table_; 193 ScopedGHashTable result_ghash_table_;
183 base::Callback<void(const char* path, 194 base::Callback<void(const char* path,
184 const char* key, 195 const char* key,
185 const GValue* gvalue)> property_changed_callback_; 196 const GValue* gvalue)> property_changed_callback_;
186 }; 197 };
187 198
188 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkServiceProperty) { 199 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkServiceProperty) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 g_value_set_int(gvalue.get(), kValue); 360 g_value_set_int(gvalue.get(), kValue);
350 property_changed_callback_.Run(path.c_str(), key.c_str(), gvalue.get()); 361 property_changed_callback_.Run(path.c_str(), key.c_str(), gvalue.get());
351 362
352 // Stop monitoring. 363 // Stop monitoring.
353 EXPECT_CALL(*MockChromeOSNetwork::Get(), 364 EXPECT_CALL(*MockChromeOSNetwork::Get(),
354 DisconnectNetworkPropertiesMonitor(_)).Times(1); 365 DisconnectNetworkPropertiesMonitor(_)).Times(1);
355 delete watcher; 366 delete watcher;
356 } 367 }
357 368
358 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorCellularDataPlan) { 369 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorCellularDataPlan) {
359 MonitorDataPlanCallback callback = 370 MonitorDataPlanCallback callback = &OnDataPlansUpdate;
satorux1 2012/04/24 06:05:55 maybe safer to add the class name ? &CrosNetworkF
hashimoto 2012/04/24 06:57:06 Done.
360 reinterpret_cast<MonitorDataPlanCallback>(42); // Dummy value. 371 void* object = this;
361 void* object = reinterpret_cast<void*>(84); // Dummy value.
362 372
363 // Start monitoring. 373 // Start monitoring.
364 EXPECT_CALL(*MockChromeOSNetwork::Get(), 374 EXPECT_CALL(*MockChromeOSNetwork::Get(),
365 MonitorCellularDataPlan(callback, object)).Times(1); 375 MonitorCellularDataPlan(callback, object)).Times(1);
366 CrosNetworkWatcher* watcher = CrosMonitorCellularDataPlan(callback, object); 376 CrosNetworkWatcher* watcher = CrosMonitorCellularDataPlan(callback, object);
367 377
368 // Stop monitoring. 378 // Stop monitoring.
369 EXPECT_CALL(*MockChromeOSNetwork::Get(), 379 EXPECT_CALL(*MockChromeOSNetwork::Get(),
370 DisconnectDataPlanUpdateMonitor(_)).Times(1); 380 DisconnectDataPlanUpdateMonitor(_)).Times(1);
371 delete watcher; 381 delete watcher;
372 } 382 }
373 383
374 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorSMS) { 384 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorSMS) {
375 const std::string modem_device_path = "/modem/device/path"; 385 const std::string modem_device_path = "/modem/device/path";
376 MonitorSMSCallback callback = 386 MonitorSMSCallback callback = &OnSmsReceived;
377 reinterpret_cast<MonitorSMSCallback>(42); // Dummy value. 387 void* object = this;
378 void* object = reinterpret_cast<void*>(84); // Dummy value.
379 388
380 // Start monitoring. 389 // Start monitoring.
381 EXPECT_CALL(*MockChromeOSNetwork::Get(), 390 EXPECT_CALL(*MockChromeOSNetwork::Get(),
382 MonitorSMS(StrEq(modem_device_path), callback, object)) 391 MonitorSMS(StrEq(modem_device_path), callback, object))
383 .Times(1); 392 .Times(1);
384 CrosNetworkWatcher* watcher = CrosMonitorSMS( 393 CrosNetworkWatcher* watcher = CrosMonitorSMS(
385 modem_device_path, callback, object); 394 modem_device_path, callback, object);
386 395
387 // Stop monitoring. 396 // Stop monitoring.
388 EXPECT_CALL(*MockChromeOSNetwork::Get(), 397 EXPECT_CALL(*MockChromeOSNetwork::Get(),
389 DisconnectSMSMonitor(_)).Times(1); 398 DisconnectSMSMonitor(_)).Times(1);
390 delete watcher; 399 delete watcher;
391 } 400 }
392 401
402 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkServiceConnect) {
403 const std::string service_path = "service path";
404 void* object = this;
satorux1 2012/04/24 06:05:55 I like this idea. cool
405 EXPECT_CALL(*MockChromeOSNetwork::Get(),
406 RequestNetworkServiceConnect(StrEq(service_path),
407 &OnNetworkAction,
408 object)).Times(1);
409 CrosRequestNetworkServiceConnect(service_path, &OnNetworkAction, object);
410 }
411
393 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkManagerProperties) { 412 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkManagerProperties) {
394 const std::string key1 = "key1"; 413 const std::string key1 = "key1";
395 const std::string value1 = "value1"; 414 const std::string value1 = "value1";
396 const std::string key2 = "key.2."; 415 const std::string key2 = "key.2.";
397 const std::string value2 = "value2"; 416 const std::string value2 = "value2";
398 // Create result value. 417 // Create result value.
399 base::DictionaryValue result; 418 base::DictionaryValue result;
400 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); 419 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1));
401 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); 420 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2));
402 result_ghash_table_.reset( 421 result_ghash_table_.reset(
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 608 }
590 609
591 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkDeviceEnable) { 610 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkDeviceEnable) {
592 const bool kEnable = true; 611 const bool kEnable = true;
593 EXPECT_CALL(*MockChromeOSNetwork::Get(), 612 EXPECT_CALL(*MockChromeOSNetwork::Get(),
594 RequestNetworkDeviceEnable(StrEq(flimflam::kTypeWifi), kEnable)) 613 RequestNetworkDeviceEnable(StrEq(flimflam::kTypeWifi), kEnable))
595 .Times(1); 614 .Times(1);
596 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable); 615 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable);
597 } 616 }
598 617
618 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestRequirePin) {
619 const std::string device_path = "/device/path";
620 const std::string pin = "123456";
621 const bool kEnable = true;
622 void* object = this;
623 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestRequirePin(
624 StrEq(device_path), StrEq(pin), kEnable, &OnNetworkAction, object))
625 .Times(1);
626 CrosRequestRequirePin(device_path, pin, kEnable, &OnNetworkAction, object);
627 }
628
629 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestEnterPin) {
630 const std::string device_path = "/device/path";
631 const std::string pin = "123456";
632 void* object = this;
633 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestEnterPin(
634 StrEq(device_path), StrEq(pin), &OnNetworkAction, object)).Times(1);
635 CrosRequestEnterPin(device_path, pin, &OnNetworkAction, object);
636 }
637
638 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestUnblockPin) {
639 const std::string device_path = "/device/path";
640 const std::string unblock_code = "987654";
641 const std::string pin = "123456";
642 void* object = this;
643 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestUnblockPin(
644 StrEq(device_path), StrEq(unblock_code), StrEq(pin), &OnNetworkAction,
645 object)).Times(1);
646 CrosRequestUnblockPin(device_path, unblock_code, pin, &OnNetworkAction,
647 object);
648 }
649
650 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestChangePin) {
651 const std::string device_path = "/device/path";
652 const std::string old_pin = "123456";
653 const std::string new_pin = "234567";
654 void* object = this;
655 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestChangePin(
656 StrEq(device_path), StrEq(old_pin), StrEq(new_pin), &OnNetworkAction,
657 object)).Times(1);
658 CrosRequestChangePin(device_path, old_pin, new_pin, &OnNetworkAction, object);
659 }
660
661 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestCellularRegister) {
662 const std::string device_path = "/device/path";
663 const std::string network_id = "networkid";
664 void* object = this;
665 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestCellularRegister(
666 StrEq(device_path), StrEq(network_id), &OnNetworkAction, object))
667 .Times(1);
668 CrosRequestCellularRegister(device_path, network_id, &OnNetworkAction,
669 object);
670 }
671
599 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosAddIPConfig) { 672 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosAddIPConfig) {
600 const std::string device_path = "/device/path"; 673 const std::string device_path = "/device/path";
601 EXPECT_CALL(*MockChromeOSNetwork::Get(), 674 EXPECT_CALL(*MockChromeOSNetwork::Get(),
602 AddIPConfig(StrEq(device_path), IPCONFIG_TYPE_DHCP)).Times(1); 675 AddIPConfig(StrEq(device_path), IPCONFIG_TYPE_DHCP)).Times(1);
603 CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP); 676 CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP);
604 } 677 }
605 678
606 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRemoveIPConfig) { 679 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRemoveIPConfig) {
607 IPConfig config = {}; 680 IPConfig config = {};
608 config.path = "/path"; 681 config.path = "/path";
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 788 }
716 789
717 // Handles responses for GetEntry method calls. 790 // Handles responses for GetEntry method calls.
718 void OnGetEntry( 791 void OnGetEntry(
719 const dbus::ObjectPath& profile_path, 792 const dbus::ObjectPath& profile_path,
720 const std::string& entry_path, 793 const std::string& entry_path,
721 const FlimflamClientHelper::DictionaryValueCallback& callback) { 794 const FlimflamClientHelper::DictionaryValueCallback& callback) {
722 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); 795 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
723 } 796 }
724 797
798 // Mock NetworkActionCallback.
799 MOCK_METHOD4(MockNetworkActionCallback, void(void* object,
800 const char* path,
801 NetworkMethodErrorType error,
802 const char* error_message));
803 static void MockNetworkActionCallbackThunk(void* object,
804 const char* path,
805 NetworkMethodErrorType error,
806 const char* error_message) {
807 static_cast<CrosNetworkFunctionsTest*>(object)->MockNetworkActionCallback(
808 object, path, error, error_message);
809 }
810
725 protected: 811 protected:
726 MockCashewClient* mock_cashew_client_; 812 MockCashewClient* mock_cashew_client_;
727 MockFlimflamDeviceClient* mock_device_client_; 813 MockFlimflamDeviceClient* mock_device_client_;
728 MockFlimflamIPConfigClient* mock_ipconfig_client_; 814 MockFlimflamIPConfigClient* mock_ipconfig_client_;
729 MockFlimflamManagerClient* mock_manager_client_; 815 MockFlimflamManagerClient* mock_manager_client_;
730 MockFlimflamProfileClient* mock_profile_client_; 816 MockFlimflamProfileClient* mock_profile_client_;
731 MockFlimflamServiceClient* mock_service_client_; 817 MockFlimflamServiceClient* mock_service_client_;
732 const base::DictionaryValue* dictionary_value_result_; 818 const base::DictionaryValue* dictionary_value_result_;
733 }; 819 };
734 820
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 EXPECT_CALL(*mock_manager_client_, 1179 EXPECT_CALL(*mock_manager_client_,
1094 EnableTechnology(flimflam::kTypeWifi, _)).Times(1); 1180 EnableTechnology(flimflam::kTypeWifi, _)).Times(1);
1095 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable); 1181 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable);
1096 1182
1097 const bool kDisable = false; 1183 const bool kDisable = false;
1098 EXPECT_CALL(*mock_manager_client_, 1184 EXPECT_CALL(*mock_manager_client_,
1099 DisableTechnology(flimflam::kTypeWifi, _)).Times(1); 1185 DisableTechnology(flimflam::kTypeWifi, _)).Times(1);
1100 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kDisable); 1186 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kDisable);
1101 } 1187 }
1102 1188
1189 TEST_F(CrosNetworkFunctionsTest, CrosRequestRequirePin) {
1190 const std::string device_path = "/device/path";
1191 const std::string pin = "123456";
1192 const bool kRequire = true;
1193 void* object = this;
1194
1195 // Set expectations.
1196 base::Closure callback;
1197 EXPECT_CALL(*mock_device_client_,
1198 RequirePin(dbus::ObjectPath(device_path), pin, kRequire, _, _))
1199 .WillOnce(SaveArg<3>(&callback));
1200 EXPECT_CALL(*this, MockNetworkActionCallback(
1201 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1202 CrosRequestRequirePin(device_path, pin, kRequire,
1203 &MockNetworkActionCallbackThunk, this);
1204 // Run saved callback.
1205 callback.Run();
1206 }
1207
1208 TEST_F(CrosNetworkFunctionsTest, CrosRequestEnterPin) {
1209 const std::string device_path = "/device/path";
1210 const std::string pin = "123456";
1211 void* object = this;
1212
1213 // Set expectations.
1214 base::Closure callback;
1215 EXPECT_CALL(*mock_device_client_,
1216 EnterPin(dbus::ObjectPath(device_path), pin, _, _))
1217 .WillOnce(SaveArg<2>(&callback));
1218 EXPECT_CALL(*this, MockNetworkActionCallback(
1219 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1220 CrosRequestEnterPin(device_path, pin, &MockNetworkActionCallbackThunk, this);
1221 // Run saved callback.
1222 callback.Run();
1223 }
1224
1225 TEST_F(CrosNetworkFunctionsTest, CrosRequestUnblockPin) {
1226 const std::string device_path = "/device/path";
1227 const std::string unblock_code = "987654";
1228 const std::string pin = "123456";
1229 void* object = this;
1230
1231 // Set expectations.
1232 base::Closure callback;
1233 EXPECT_CALL(
1234 *mock_device_client_,
1235 UnblockPin(dbus::ObjectPath(device_path), unblock_code, pin, _, _))
1236 .WillOnce(SaveArg<3>(&callback));
1237 EXPECT_CALL(*this, MockNetworkActionCallback(
1238 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1239 CrosRequestUnblockPin(device_path, unblock_code, pin,
1240 &MockNetworkActionCallbackThunk, object);
1241 // Run saved callback.
1242 callback.Run();
1243 }
1244
1245 TEST_F(CrosNetworkFunctionsTest, CrosRequestChangePin) {
1246 const std::string device_path = "/device/path";
1247 const std::string old_pin = "123456";
1248 const std::string new_pin = "234567";
1249 void* object = this;
1250
1251 // Set expectations.
1252 base::Closure callback;
1253 EXPECT_CALL(*mock_device_client_,
1254 ChangePin(dbus::ObjectPath(device_path), old_pin, new_pin, _, _))
1255 .WillOnce(SaveArg<3>(&callback));
1256 EXPECT_CALL(*this, MockNetworkActionCallback(
1257 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1258 CrosRequestChangePin(device_path, old_pin, new_pin,
1259 &MockNetworkActionCallbackThunk, object);
1260 // Run saved callback.
1261 callback.Run();
1262 }
1263
1264 TEST_F(CrosNetworkFunctionsTest, CrosRequestCellularRegister) {
1265 const std::string device_path = "/device/path";
1266 const std::string network_id = "networkid";
1267 void* object = this;
1268
1269 // Set expectations.
1270 base::Closure callback;
1271 EXPECT_CALL(*mock_device_client_,
1272 Register(dbus::ObjectPath(device_path), network_id, _, _))
1273 .WillOnce(SaveArg<2>(&callback));
1274 EXPECT_CALL(*this, MockNetworkActionCallback(
1275 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1276 CrosRequestCellularRegister(device_path, network_id,
1277 &MockNetworkActionCallbackThunk, object);
1278 // Run saved callback.
1279 callback.Run();
1280 }
1281
1103 TEST_F(CrosNetworkFunctionsTest, CrosAddIPConfig) { 1282 TEST_F(CrosNetworkFunctionsTest, CrosAddIPConfig) {
1104 const std::string device_path = "/device/path"; 1283 const std::string device_path = "/device/path";
1105 const dbus::ObjectPath result_path("/result/path"); 1284 const dbus::ObjectPath result_path("/result/path");
1106 EXPECT_CALL(*mock_device_client_, 1285 EXPECT_CALL(*mock_device_client_,
1107 CallAddIPConfigAndBlock(dbus::ObjectPath(device_path), 1286 CallAddIPConfigAndBlock(dbus::ObjectPath(device_path),
1108 flimflam::kTypeDHCP)) 1287 flimflam::kTypeDHCP))
1109 .WillOnce(Return(result_path)); 1288 .WillOnce(Return(result_path));
1110 EXPECT_TRUE(CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP)); 1289 EXPECT_TRUE(CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP));
1111 } 1290 }
1112 1291
(...skipping 12 matching lines...) Expand all
1125 const std::string string2 = "string2"; 1304 const std::string string2 = "string2";
1126 base::DictionaryValue value; 1305 base::DictionaryValue value;
1127 value.SetString(key1, string1); 1306 value.SetString(key1, string1);
1128 value.SetString(key2, string2); 1307 value.SetString(key2, string2);
1129 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _)) 1308 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _))
1130 .Times(1); 1309 .Times(1);
1131 CrosConfigureService(value); 1310 CrosConfigureService(value);
1132 } 1311 }
1133 1312
1134 } // namespace chromeos 1313 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/cros_network_functions.cc ('k') | chrome/browser/chromeos/cros/mock_chromeos_network.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698