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

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: _ 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 property_changed_callback_.Run(path.c_str(), key.c_str(), gvalue.get()); 350 property_changed_callback_.Run(path.c_str(), key.c_str(), gvalue.get());
351 351
352 // Stop monitoring. 352 // Stop monitoring.
353 EXPECT_CALL(*MockChromeOSNetwork::Get(), 353 EXPECT_CALL(*MockChromeOSNetwork::Get(),
354 DisconnectNetworkPropertiesMonitor(_)).Times(1); 354 DisconnectNetworkPropertiesMonitor(_)).Times(1);
355 delete watcher; 355 delete watcher;
356 } 356 }
357 357
358 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorCellularDataPlan) { 358 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorCellularDataPlan) {
359 MonitorDataPlanCallback callback = 359 MonitorDataPlanCallback callback =
360 reinterpret_cast<MonitorDataPlanCallback>(42); // Dummy value. 360 reinterpret_cast<MonitorDataPlanCallback>(42); // Dummy value.
satorux1 2012/04/23 17:15:20 casting 42 to a callback object looks scary...
hashimoto 2012/04/24 04:29:46 Done.
361 void* object = reinterpret_cast<void*>(84); // Dummy value. 361 void* object = reinterpret_cast<void*>(84); // Dummy value.
362 362
363 // Start monitoring. 363 // Start monitoring.
364 EXPECT_CALL(*MockChromeOSNetwork::Get(), 364 EXPECT_CALL(*MockChromeOSNetwork::Get(),
365 MonitorCellularDataPlan(callback, object)).Times(1); 365 MonitorCellularDataPlan(callback, object)).Times(1);
366 CrosNetworkWatcher* watcher = CrosMonitorCellularDataPlan(callback, object); 366 CrosNetworkWatcher* watcher = CrosMonitorCellularDataPlan(callback, object);
367 367
368 // Stop monitoring. 368 // Stop monitoring.
369 EXPECT_CALL(*MockChromeOSNetwork::Get(), 369 EXPECT_CALL(*MockChromeOSNetwork::Get(),
370 DisconnectDataPlanUpdateMonitor(_)).Times(1); 370 DisconnectDataPlanUpdateMonitor(_)).Times(1);
(...skipping 12 matching lines...) Expand all
383 .Times(1); 383 .Times(1);
384 CrosNetworkWatcher* watcher = CrosMonitorSMS( 384 CrosNetworkWatcher* watcher = CrosMonitorSMS(
385 modem_device_path, callback, object); 385 modem_device_path, callback, object);
386 386
387 // Stop monitoring. 387 // Stop monitoring.
388 EXPECT_CALL(*MockChromeOSNetwork::Get(), 388 EXPECT_CALL(*MockChromeOSNetwork::Get(),
389 DisconnectSMSMonitor(_)).Times(1); 389 DisconnectSMSMonitor(_)).Times(1);
390 delete watcher; 390 delete watcher;
391 } 391 }
392 392
393 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkServiceConnect) {
394 const std::string service_path = "service path";
395 void* object = reinterpret_cast<void*>(42); // dummy
satorux1 2012/04/23 17:15:20 I'm guessing that you are using 42 because you can
hashimoto 2012/04/24 04:29:46 I can pass NULL, but I just want to make sure that
396 EXPECT_CALL(*MockChromeOSNetwork::Get(),
397 RequestNetworkServiceConnect(StrEq(service_path),
398 &OnNetworkAction,
399 object)).Times(1);
400 CrosRequestNetworkServiceConnect(service_path, &OnNetworkAction, object);
401 }
402
393 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkManagerProperties) { 403 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkManagerProperties) {
394 const std::string key1 = "key1"; 404 const std::string key1 = "key1";
395 const std::string value1 = "value1"; 405 const std::string value1 = "value1";
396 const std::string key2 = "key.2."; 406 const std::string key2 = "key.2.";
397 const std::string value2 = "value2"; 407 const std::string value2 = "value2";
398 // Create result value. 408 // Create result value.
399 base::DictionaryValue result; 409 base::DictionaryValue result;
400 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); 410 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1));
401 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); 411 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2));
402 result_ghash_table_.reset( 412 result_ghash_table_.reset(
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 599 }
590 600
591 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkDeviceEnable) { 601 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkDeviceEnable) {
592 const bool kEnable = true; 602 const bool kEnable = true;
593 EXPECT_CALL(*MockChromeOSNetwork::Get(), 603 EXPECT_CALL(*MockChromeOSNetwork::Get(),
594 RequestNetworkDeviceEnable(StrEq(flimflam::kTypeWifi), kEnable)) 604 RequestNetworkDeviceEnable(StrEq(flimflam::kTypeWifi), kEnable))
595 .Times(1); 605 .Times(1);
596 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable); 606 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable);
597 } 607 }
598 608
609 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestRequirePin) {
610 const std::string device_path = "/device/path";
611 const std::string pin = "123456";
612 const bool kEnable = true;
613 void* object = reinterpret_cast<void*>(42); // dummy
614 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestRequirePin(
615 StrEq(device_path), StrEq(pin), kEnable, &OnNetworkAction, object))
616 .Times(1);
617 CrosRequestRequirePin(device_path, pin, kEnable, &OnNetworkAction, object);
618 }
619
620 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestEnterPin) {
621 const std::string device_path = "/device/path";
622 const std::string pin = "123456";
623 void* object = reinterpret_cast<void*>(42); // dummy
624 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestEnterPin(
625 StrEq(device_path), StrEq(pin), &OnNetworkAction, object)).Times(1);
626 CrosRequestEnterPin(device_path, pin, &OnNetworkAction, object);
627 }
628
629 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestUnblockPin) {
630 const std::string device_path = "/device/path";
631 const std::string unblock_code = "987654";
632 const std::string pin = "123456";
633 void* object = reinterpret_cast<void*>(42); // dummy
634 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestUnblockPin(
635 StrEq(device_path), StrEq(unblock_code), StrEq(pin), &OnNetworkAction,
636 object)).Times(1);
637 CrosRequestUnblockPin(device_path, unblock_code, pin, &OnNetworkAction,
638 object);
639 }
640
641 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestChangePin) {
642 const std::string device_path = "/device/path";
643 const std::string old_pin = "123456";
644 const std::string new_pin = "234567";
645 void* object = reinterpret_cast<void*>(42); // dummy
646 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestChangePin(
647 StrEq(device_path), StrEq(old_pin), StrEq(new_pin), &OnNetworkAction,
648 object)).Times(1);
649 CrosRequestChangePin(device_path, old_pin, new_pin, &OnNetworkAction, object);
650 }
651
652 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestCellularRegister) {
653 const std::string device_path = "/device/path";
654 const std::string network_id = "networkid";
655 void* object = reinterpret_cast<void*>(42); // dummy
656 EXPECT_CALL(*MockChromeOSNetwork::Get(), RequestCellularRegister(
657 StrEq(device_path), StrEq(network_id), &OnNetworkAction, object))
658 .Times(1);
659 CrosRequestCellularRegister(device_path, network_id, &OnNetworkAction,
660 object);
661 }
662
599 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosAddIPConfig) { 663 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosAddIPConfig) {
600 const std::string device_path = "/device/path"; 664 const std::string device_path = "/device/path";
601 EXPECT_CALL(*MockChromeOSNetwork::Get(), 665 EXPECT_CALL(*MockChromeOSNetwork::Get(),
602 AddIPConfig(StrEq(device_path), IPCONFIG_TYPE_DHCP)).Times(1); 666 AddIPConfig(StrEq(device_path), IPCONFIG_TYPE_DHCP)).Times(1);
603 CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP); 667 CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP);
604 } 668 }
605 669
606 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRemoveIPConfig) { 670 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRemoveIPConfig) {
607 IPConfig config = {}; 671 IPConfig config = {};
608 config.path = "/path"; 672 config.path = "/path";
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 779 }
716 780
717 // Handles responses for GetEntry method calls. 781 // Handles responses for GetEntry method calls.
718 void OnGetEntry( 782 void OnGetEntry(
719 const dbus::ObjectPath& profile_path, 783 const dbus::ObjectPath& profile_path,
720 const std::string& entry_path, 784 const std::string& entry_path,
721 const FlimflamClientHelper::DictionaryValueCallback& callback) { 785 const FlimflamClientHelper::DictionaryValueCallback& callback) {
722 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); 786 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
723 } 787 }
724 788
789 // Mock NetworkActionCallback.
790 MOCK_METHOD4(MockNetworkActionCallback, void(void* object,
791 const char* path,
792 NetworkMethodErrorType error,
793 const char* error_message));
794 static void MockNetworkActionCallbackThunk(void* object,
795 const char* path,
796 NetworkMethodErrorType error,
797 const char* error_message) {
798 static_cast<CrosNetworkFunctionsTest*>(object)->MockNetworkActionCallback(
799 object, path, error, error_message);
800 }
801
725 protected: 802 protected:
726 MockCashewClient* mock_cashew_client_; 803 MockCashewClient* mock_cashew_client_;
727 MockFlimflamDeviceClient* mock_device_client_; 804 MockFlimflamDeviceClient* mock_device_client_;
728 MockFlimflamIPConfigClient* mock_ipconfig_client_; 805 MockFlimflamIPConfigClient* mock_ipconfig_client_;
729 MockFlimflamManagerClient* mock_manager_client_; 806 MockFlimflamManagerClient* mock_manager_client_;
730 MockFlimflamProfileClient* mock_profile_client_; 807 MockFlimflamProfileClient* mock_profile_client_;
731 MockFlimflamServiceClient* mock_service_client_; 808 MockFlimflamServiceClient* mock_service_client_;
732 const base::DictionaryValue* dictionary_value_result_; 809 const base::DictionaryValue* dictionary_value_result_;
733 }; 810 };
734 811
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 EXPECT_CALL(*mock_manager_client_, 1078 EXPECT_CALL(*mock_manager_client_,
1002 EnableTechnology(flimflam::kTypeWifi, _)).Times(1); 1079 EnableTechnology(flimflam::kTypeWifi, _)).Times(1);
1003 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable); 1080 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable);
1004 1081
1005 const bool kDisable = false; 1082 const bool kDisable = false;
1006 EXPECT_CALL(*mock_manager_client_, 1083 EXPECT_CALL(*mock_manager_client_,
1007 DisableTechnology(flimflam::kTypeWifi, _)).Times(1); 1084 DisableTechnology(flimflam::kTypeWifi, _)).Times(1);
1008 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kDisable); 1085 CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kDisable);
1009 } 1086 }
1010 1087
1088 TEST_F(CrosNetworkFunctionsTest, CrosRequestRequirePin) {
1089 const std::string device_path = "/device/path";
1090 const std::string pin = "123456";
1091 const bool kRequire = true;
1092 void* object = this;
1093
1094 // Set expectations.
1095 base::Closure callback;
1096 EXPECT_CALL(*mock_device_client_,
1097 RequirePin(dbus::ObjectPath(device_path), pin, kRequire, _, _))
1098 .WillOnce(SaveArg<3>(&callback));
1099 EXPECT_CALL(*this, MockNetworkActionCallback(
1100 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1101 CrosRequestRequirePin(device_path, pin, kRequire,
1102 &MockNetworkActionCallbackThunk, this);
1103 // Run saved callback.
1104 callback.Run();
1105 }
1106
1107 TEST_F(CrosNetworkFunctionsTest, CrosRequestEnterPin) {
1108 const std::string device_path = "/device/path";
1109 const std::string pin = "123456";
1110 void* object = this;
1111
1112 // Set expectations.
1113 base::Closure callback;
1114 EXPECT_CALL(*mock_device_client_,
1115 EnterPin(dbus::ObjectPath(device_path), pin, _, _))
1116 .WillOnce(SaveArg<2>(&callback));
1117 EXPECT_CALL(*this, MockNetworkActionCallback(
1118 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1119 CrosRequestEnterPin(device_path, pin, &MockNetworkActionCallbackThunk, this);
1120 // Run saved callback.
1121 callback.Run();
1122 }
1123
1124 TEST_F(CrosNetworkFunctionsTest, CrosRequestUnblockPin) {
1125 const std::string device_path = "/device/path";
1126 const std::string unblock_code = "987654";
1127 const std::string pin = "123456";
1128 void* object = this;
1129
1130 // Set expectations.
1131 base::Closure callback;
1132 EXPECT_CALL(
1133 *mock_device_client_,
1134 UnblockPin(dbus::ObjectPath(device_path), unblock_code, pin, _, _))
1135 .WillOnce(SaveArg<3>(&callback));
1136 EXPECT_CALL(*this, MockNetworkActionCallback(
1137 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1138 CrosRequestUnblockPin(device_path, unblock_code, pin,
1139 &MockNetworkActionCallbackThunk, object);
1140 // Run saved callback.
1141 callback.Run();
1142 }
1143
1144 TEST_F(CrosNetworkFunctionsTest, CrosRequestChangePin) {
1145 const std::string device_path = "/device/path";
1146 const std::string old_pin = "123456";
1147 const std::string new_pin = "234567";
1148 void* object = this;
1149
1150 // Set expectations.
1151 base::Closure callback;
1152 EXPECT_CALL(*mock_device_client_,
1153 ChangePin(dbus::ObjectPath(device_path), old_pin, new_pin, _, _))
1154 .WillOnce(SaveArg<3>(&callback));
1155 EXPECT_CALL(*this, MockNetworkActionCallback(
1156 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1157 CrosRequestChangePin(device_path, old_pin, new_pin,
1158 &MockNetworkActionCallbackThunk, object);
1159 // Run saved callback.
1160 callback.Run();
1161 }
1162
1163 TEST_F(CrosNetworkFunctionsTest, CrosRequestCellularRegister) {
1164 const std::string device_path = "/device/path";
1165 const std::string network_id = "networkid";
1166 void* object = this;
1167
1168 // Set expectations.
1169 base::Closure callback;
1170 EXPECT_CALL(*mock_device_client_,
1171 Register(dbus::ObjectPath(device_path), network_id, _, _))
1172 .WillOnce(SaveArg<2>(&callback));
1173 EXPECT_CALL(*this, MockNetworkActionCallback(
1174 object, StrEq(device_path), NETWORK_METHOD_ERROR_NONE, _)).Times(1);
1175 CrosRequestCellularRegister(device_path, network_id,
1176 &MockNetworkActionCallbackThunk, object);
1177 // Run saved callback.
1178 callback.Run();
1179 }
1180
1011 TEST_F(CrosNetworkFunctionsTest, CrosAddIPConfig) { 1181 TEST_F(CrosNetworkFunctionsTest, CrosAddIPConfig) {
1012 const std::string device_path = "/device/path"; 1182 const std::string device_path = "/device/path";
1013 const dbus::ObjectPath result_path("/result/path"); 1183 const dbus::ObjectPath result_path("/result/path");
1014 EXPECT_CALL(*mock_device_client_, 1184 EXPECT_CALL(*mock_device_client_,
1015 CallAddIPConfigAndBlock(dbus::ObjectPath(device_path), 1185 CallAddIPConfigAndBlock(dbus::ObjectPath(device_path),
1016 flimflam::kTypeDHCP)) 1186 flimflam::kTypeDHCP))
1017 .WillOnce(Return(result_path)); 1187 .WillOnce(Return(result_path));
1018 EXPECT_TRUE(CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP)); 1188 EXPECT_TRUE(CrosAddIPConfig(device_path, IPCONFIG_TYPE_DHCP));
1019 } 1189 }
1020 1190
(...skipping 12 matching lines...) Expand all
1033 const std::string string2 = "string2"; 1203 const std::string string2 = "string2";
1034 base::DictionaryValue value; 1204 base::DictionaryValue value;
1035 value.SetString(key1, string1); 1205 value.SetString(key1, string1);
1036 value.SetString(key2, string2); 1206 value.SetString(key2, string2);
1037 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _)) 1207 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _))
1038 .Times(1); 1208 .Times(1);
1039 CrosConfigureService(value); 1209 CrosConfigureService(value);
1040 } 1210 }
1041 1211
1042 } // namespace chromeos 1212 } // 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