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 "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" |
11 #include "chromeos/dbus/mock_cashew_client.h" | 11 #include "chromeos/dbus/mock_cashew_client.h" |
12 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 12 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
13 #include "chromeos/dbus/mock_flimflam_device_client.h" | 13 #include "chromeos/dbus/mock_flimflam_device_client.h" |
14 #include "chromeos/dbus/mock_flimflam_ipconfig_client.h" | 14 #include "chromeos/dbus/mock_flimflam_ipconfig_client.h" |
15 #include "chromeos/dbus/mock_flimflam_manager_client.h" | 15 #include "chromeos/dbus/mock_flimflam_manager_client.h" |
| 16 #include "chromeos/dbus/mock_flimflam_network_client.h" |
16 #include "chromeos/dbus/mock_flimflam_profile_client.h" | 17 #include "chromeos/dbus/mock_flimflam_profile_client.h" |
17 #include "chromeos/dbus/mock_flimflam_service_client.h" | 18 #include "chromeos/dbus/mock_flimflam_service_client.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 | 21 |
21 using ::testing::_; | 22 using ::testing::_; |
22 using ::testing::Invoke; | 23 using ::testing::Invoke; |
23 using ::testing::Pointee; | 24 using ::testing::Pointee; |
24 using ::testing::Return; | 25 using ::testing::Return; |
25 using ::testing::SaveArg; | 26 using ::testing::SaveArg; |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 virtual void SetUp() { | 772 virtual void SetUp() { |
772 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | 773 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; |
773 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 774 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
774 mock_cashew_client_ = mock_dbus_thread_manager->mock_cashew_client(); | 775 mock_cashew_client_ = mock_dbus_thread_manager->mock_cashew_client(); |
775 mock_device_client_ = | 776 mock_device_client_ = |
776 mock_dbus_thread_manager->mock_flimflam_device_client(); | 777 mock_dbus_thread_manager->mock_flimflam_device_client(); |
777 mock_ipconfig_client_ = | 778 mock_ipconfig_client_ = |
778 mock_dbus_thread_manager->mock_flimflam_ipconfig_client(); | 779 mock_dbus_thread_manager->mock_flimflam_ipconfig_client(); |
779 mock_manager_client_ = | 780 mock_manager_client_ = |
780 mock_dbus_thread_manager->mock_flimflam_manager_client(); | 781 mock_dbus_thread_manager->mock_flimflam_manager_client(); |
| 782 mock_network_client_ = |
| 783 mock_dbus_thread_manager->mock_flimflam_network_client(); |
781 mock_profile_client_ = | 784 mock_profile_client_ = |
782 mock_dbus_thread_manager->mock_flimflam_profile_client(); | 785 mock_dbus_thread_manager->mock_flimflam_profile_client(); |
783 mock_service_client_ = | 786 mock_service_client_ = |
784 mock_dbus_thread_manager->mock_flimflam_service_client(); | 787 mock_dbus_thread_manager->mock_flimflam_service_client(); |
785 SetLibcrosNetworkFunctionsEnabled(false); | 788 SetLibcrosNetworkFunctionsEnabled(false); |
786 } | 789 } |
787 | 790 |
788 virtual void TearDown() { | 791 virtual void TearDown() { |
789 DBusThreadManager::Shutdown(); | 792 DBusThreadManager::Shutdown(); |
790 mock_profile_client_ = NULL; | 793 mock_profile_client_ = NULL; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 const char* error_message) { | 825 const char* error_message) { |
823 static_cast<CrosNetworkFunctionsTest*>(object)->MockNetworkActionCallback( | 826 static_cast<CrosNetworkFunctionsTest*>(object)->MockNetworkActionCallback( |
824 object, path, error, error_message); | 827 object, path, error, error_message); |
825 } | 828 } |
826 | 829 |
827 protected: | 830 protected: |
828 MockCashewClient* mock_cashew_client_; | 831 MockCashewClient* mock_cashew_client_; |
829 MockFlimflamDeviceClient* mock_device_client_; | 832 MockFlimflamDeviceClient* mock_device_client_; |
830 MockFlimflamIPConfigClient* mock_ipconfig_client_; | 833 MockFlimflamIPConfigClient* mock_ipconfig_client_; |
831 MockFlimflamManagerClient* mock_manager_client_; | 834 MockFlimflamManagerClient* mock_manager_client_; |
| 835 MockFlimflamNetworkClient* mock_network_client_; |
832 MockFlimflamProfileClient* mock_profile_client_; | 836 MockFlimflamProfileClient* mock_profile_client_; |
833 MockFlimflamServiceClient* mock_service_client_; | 837 MockFlimflamServiceClient* mock_service_client_; |
834 const base::DictionaryValue* dictionary_value_result_; | 838 const base::DictionaryValue* dictionary_value_result_; |
835 }; | 839 }; |
836 | 840 |
837 TEST_F(CrosNetworkFunctionsTest, CrosActivateCellularModem) { | 841 TEST_F(CrosNetworkFunctionsTest, CrosActivateCellularModem) { |
838 const std::string service_path = "/"; | 842 const std::string service_path = "/"; |
839 const std::string carrier = "carrier"; | 843 const std::string carrier = "carrier"; |
840 EXPECT_CALL(*mock_service_client_, | 844 EXPECT_CALL(*mock_service_client_, |
841 CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path), | 845 CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path), |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 } | 1327 } |
1324 | 1328 |
1325 TEST_F(CrosNetworkFunctionsTest, CrosRemoveIPConfig) { | 1329 TEST_F(CrosNetworkFunctionsTest, CrosRemoveIPConfig) { |
1326 IPConfig config = {}; | 1330 IPConfig config = {}; |
1327 config.path = "/path"; | 1331 config.path = "/path"; |
1328 EXPECT_CALL(*mock_ipconfig_client_, | 1332 EXPECT_CALL(*mock_ipconfig_client_, |
1329 CallRemoveAndBlock(dbus::ObjectPath(config.path))).Times(1); | 1333 CallRemoveAndBlock(dbus::ObjectPath(config.path))).Times(1); |
1330 CrosRemoveIPConfig(&config); | 1334 CrosRemoveIPConfig(&config); |
1331 } | 1335 } |
1332 | 1336 |
| 1337 TEST_F(CrosNetworkFunctionsTest, CrosGetWifiAccessPoints) { |
| 1338 const std::string device_path = "/device/path"; |
| 1339 base::ListValue* devices = new base::ListValue; |
| 1340 devices->Append(base::Value::CreateStringValue(device_path)); |
| 1341 base::DictionaryValue* manager_properties = new base::DictionaryValue; |
| 1342 manager_properties->SetWithoutPathExpansion( |
| 1343 flimflam::kDevicesProperty, devices); |
| 1344 |
| 1345 const int kScanInterval = 42; |
| 1346 const std::string network_path = "/network/path"; |
| 1347 base::ListValue* networks = new base::ListValue; |
| 1348 networks->Append(base::Value::CreateStringValue(network_path)); |
| 1349 base::DictionaryValue* device_properties = new base::DictionaryValue; |
| 1350 device_properties->SetWithoutPathExpansion( |
| 1351 flimflam::kNetworksProperty, networks); |
| 1352 device_properties->SetWithoutPathExpansion( |
| 1353 flimflam::kPoweredProperty, base::Value::CreateBooleanValue(true)); |
| 1354 device_properties->SetWithoutPathExpansion( |
| 1355 flimflam::kScanIntervalProperty, |
| 1356 base::Value::CreateIntegerValue(kScanInterval)); |
| 1357 |
| 1358 const int kSignalStrength = 10; |
| 1359 const int kWifiChannel = 3; |
| 1360 const std::string address = "address"; |
| 1361 const std::string name = "name"; |
| 1362 const base::Time expected_timestamp = |
| 1363 base::Time::Now() - base::TimeDelta::FromSeconds(kScanInterval); |
| 1364 const base::TimeDelta acceptable_timestamp_range = |
| 1365 base::TimeDelta::FromSeconds(1); |
| 1366 |
| 1367 base::DictionaryValue* network_properties = new base::DictionaryValue; |
| 1368 network_properties->SetWithoutPathExpansion( |
| 1369 flimflam::kAddressProperty, base::Value::CreateStringValue(address)); |
| 1370 network_properties->SetWithoutPathExpansion( |
| 1371 flimflam::kNameProperty, base::Value::CreateStringValue(name)); |
| 1372 network_properties->SetWithoutPathExpansion( |
| 1373 flimflam::kSignalStrengthProperty, |
| 1374 base::Value::CreateIntegerValue(kSignalStrength)); |
| 1375 network_properties->SetWithoutPathExpansion( |
| 1376 flimflam::kWifiChannelProperty, |
| 1377 base::Value::CreateIntegerValue(kWifiChannel)); |
| 1378 |
| 1379 // Set expectations. |
| 1380 EXPECT_CALL(*mock_manager_client_, CallGetPropertiesAndBlock()) |
| 1381 .WillOnce(Return(manager_properties)); |
| 1382 EXPECT_CALL(*mock_device_client_, |
| 1383 CallGetPropertiesAndBlock(dbus::ObjectPath(device_path))) |
| 1384 .WillOnce(Return(device_properties)); |
| 1385 EXPECT_CALL(*mock_network_client_, |
| 1386 CallGetPropertiesAndBlock(dbus::ObjectPath(network_path))) |
| 1387 .WillOnce(Return(network_properties)); |
| 1388 |
| 1389 // Call function. |
| 1390 WifiAccessPointVector aps; |
| 1391 ASSERT_TRUE(CrosGetWifiAccessPoints(&aps)); |
| 1392 ASSERT_EQ(1U, aps.size()); |
| 1393 EXPECT_EQ(address, aps[0].mac_address); |
| 1394 EXPECT_EQ(name, aps[0].name); |
| 1395 EXPECT_LE(expected_timestamp - acceptable_timestamp_range, aps[0].timestamp); |
| 1396 EXPECT_GE(expected_timestamp + acceptable_timestamp_range, aps[0].timestamp); |
| 1397 EXPECT_EQ(kSignalStrength, aps[0].signal_strength); |
| 1398 EXPECT_EQ(kWifiChannel, aps[0].channel); |
| 1399 } |
| 1400 |
1333 TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) { | 1401 TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) { |
1334 const std::string key1 = "key1"; | 1402 const std::string key1 = "key1"; |
1335 const std::string string1 = "string1"; | 1403 const std::string string1 = "string1"; |
1336 const std::string key2 = "key2"; | 1404 const std::string key2 = "key2"; |
1337 const std::string string2 = "string2"; | 1405 const std::string string2 = "string2"; |
1338 base::DictionaryValue value; | 1406 base::DictionaryValue value; |
1339 value.SetString(key1, string1); | 1407 value.SetString(key1, string1); |
1340 value.SetString(key2, string2); | 1408 value.SetString(key2, string2); |
1341 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _)) | 1409 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _)) |
1342 .Times(1); | 1410 .Times(1); |
1343 CrosConfigureService(value); | 1411 CrosConfigureService(value); |
1344 } | 1412 } |
1345 | 1413 |
1346 } // namespace chromeos | 1414 } // namespace chromeos |
OLD | NEW |