Home | History | Annotate | Download | only in network
      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
      3 // found in the LICENSE file.
      4 
      5 #include "base/bind.h"
      6 #include "base/memory/scoped_ptr.h"
      7 #include "base/values.h"
      8 #include "chromeos/dbus/mock_dbus_thread_manager.h"
      9 #include "chromeos/dbus/mock_gsm_sms_client.h"
     10 #include "chromeos/dbus/mock_shill_device_client.h"
     11 #include "chromeos/dbus/mock_shill_ipconfig_client.h"
     12 #include "chromeos/dbus/mock_shill_manager_client.h"
     13 #include "chromeos/dbus/mock_shill_profile_client.h"
     14 #include "chromeos/dbus/mock_shill_service_client.h"
     15 #include "chromeos/network/cros_network_functions.h"
     16 #include "chromeos/network/sms_watcher.h"
     17 #include "testing/gtest/include/gtest/gtest.h"
     18 #include "third_party/cros_system_api/dbus/service_constants.h"
     19 
     20 using ::testing::_;
     21 using ::testing::Invoke;
     22 using ::testing::Pointee;
     23 using ::testing::Return;
     24 using ::testing::SaveArg;
     25 using ::testing::StrEq;
     26 
     27 // Matcher to match base::Value.
     28 MATCHER_P(IsEqualTo, value, "") { return arg.Equals(value); }
     29 
     30 // Matcher to match SMS.
     31 MATCHER_P(IsSMSEqualTo, sms, "") {
     32   return sms.timestamp == arg.timestamp &&
     33       std::string(sms.number) == arg.number &&
     34       std::string(sms.text) == arg.text &&
     35       sms.validity == arg.validity &&
     36       sms.msgclass == arg.msgclass;
     37 }
     38 
     39 // Matcher to match IPConfig::path
     40 MATCHER_P(IsIPConfigPathEqualTo, str, "") { return str == arg.path; }
     41 
     42 namespace chromeos {
     43 
     44 namespace {
     45 
     46 const char kExamplePath[] = "/foo/bar/baz";
     47 
     48 // A mock to check arguments of NetworkPropertiesCallback and ensure that the
     49 // callback is called exactly once.
     50 class MockNetworkPropertiesCallback {
     51  public:
     52   // Creates a NetworkPropertiesCallback with expectations.
     53   static NetworkPropertiesCallback CreateCallback(
     54       const std::string& expected_path,
     55       const base::DictionaryValue& expected_result) {
     56     MockNetworkPropertiesCallback* mock_callback =
     57         new MockNetworkPropertiesCallback;
     58 
     59     EXPECT_CALL(*mock_callback,
     60                 Run(expected_path, Pointee(IsEqualTo(&expected_result))))
     61         .Times(1);
     62 
     63     return base::Bind(&MockNetworkPropertiesCallback::Run,
     64                       base::Owned(mock_callback));
     65   }
     66 
     67   MOCK_METHOD2(Run, void(const std::string& path,
     68                          const base::DictionaryValue* result));
     69 };
     70 
     71 // A mock to check arguments of NetworkPropertiesWatcherCallback and ensure that
     72 // the callback is called exactly once.
     73 class MockNetworkPropertiesWatcherCallback {
     74  public:
     75   // Creates a NetworkPropertiesWatcherCallback with expectations.
     76   static NetworkPropertiesWatcherCallback CreateCallback(
     77       const std::string& expected_path,
     78       const std::string& expected_key,
     79       const base::Value& expected_value) {
     80     MockNetworkPropertiesWatcherCallback* mock_callback =
     81         new MockNetworkPropertiesWatcherCallback;
     82 
     83     EXPECT_CALL(*mock_callback,
     84                 Run(expected_path, expected_key, IsEqualTo(&expected_value)))
     85         .Times(1);
     86 
     87     return base::Bind(&MockNetworkPropertiesWatcherCallback::Run,
     88                       base::Owned(mock_callback));
     89   }
     90 
     91   MOCK_METHOD3(Run, void(const std::string& expected_path,
     92                          const std::string& expected_key,
     93                          const base::Value& value));
     94 };
     95 
     96 }  // namespace
     97 
     98 // Test for cros_network_functions.cc without Libcros.
     99 class CrosNetworkFunctionsTest : public testing::Test {
    100  public:
    101   CrosNetworkFunctionsTest() : mock_profile_client_(NULL),
    102                                dictionary_value_result_(NULL) {}
    103 
    104   virtual void SetUp() {
    105     MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
    106     EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
    107         .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
    108     DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
    109     mock_device_client_ =
    110         mock_dbus_thread_manager->mock_shill_device_client();
    111     mock_ipconfig_client_ =
    112         mock_dbus_thread_manager->mock_shill_ipconfig_client();
    113     mock_manager_client_ =
    114         mock_dbus_thread_manager->mock_shill_manager_client();
    115     mock_profile_client_ =
    116         mock_dbus_thread_manager->mock_shill_profile_client();
    117     mock_service_client_ =
    118         mock_dbus_thread_manager->mock_shill_service_client();
    119     mock_gsm_sms_client_ = mock_dbus_thread_manager->mock_gsm_sms_client();
    120   }
    121 
    122   virtual void TearDown() {
    123     DBusThreadManager::Shutdown();
    124     mock_profile_client_ = NULL;
    125   }
    126 
    127   // Handles responses for GetProperties method calls for ShillManagerClient.
    128   void OnGetManagerProperties(
    129       const ShillClientHelper::DictionaryValueCallback& callback) {
    130     callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
    131   }
    132 
    133   // Handles responses for GetProperties method calls.
    134   void OnGetProperties(
    135       const dbus::ObjectPath& path,
    136       const ShillClientHelper::DictionaryValueCallback& callback) {
    137     callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
    138   }
    139 
    140   // Handles responses for GetProperties method calls that return
    141   // errors in an error callback.
    142   void OnGetPropertiesWithoutStatus(
    143       const dbus::ObjectPath& path,
    144       const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
    145       const ShillClientHelper::ErrorCallback& error_callback) {
    146     callback.Run(*dictionary_value_result_);
    147   }
    148 
    149   // Handles responses for GetEntry method calls.
    150   void OnGetEntry(
    151       const dbus::ObjectPath& profile_path,
    152       const std::string& entry_path,
    153       const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
    154       const ShillClientHelper::ErrorCallback& error_callback) {
    155     callback.Run(*dictionary_value_result_);
    156   }
    157 
    158   // Mock NetworkOperationCallback.
    159   MOCK_METHOD3(MockNetworkOperationCallback,
    160                void(const std::string& path,
    161                     NetworkMethodErrorType error,
    162                     const std::string& error_message));
    163 
    164   // Mock MonitorSMSCallback.
    165   MOCK_METHOD2(MockMonitorSMSCallback,
    166                void(const std::string& modem_device_path, const SMS& message));
    167 
    168  protected:
    169   MockShillDeviceClient* mock_device_client_;
    170   MockShillIPConfigClient* mock_ipconfig_client_;
    171   MockShillManagerClient* mock_manager_client_;
    172   MockShillProfileClient* mock_profile_client_;
    173   MockShillServiceClient* mock_service_client_;
    174   MockGsmSMSClient* mock_gsm_sms_client_;
    175   const base::DictionaryValue* dictionary_value_result_;
    176 };
    177 
    178 TEST_F(CrosNetworkFunctionsTest, CrosActivateCellularModem) {
    179   const std::string service_path = "/";
    180   const std::string carrier = "carrier";
    181   EXPECT_CALL(*mock_service_client_,
    182               CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path),
    183                                                 carrier))
    184       .WillOnce(Return(true));
    185   EXPECT_TRUE(CrosActivateCellularModem(service_path, carrier));
    186 }
    187 
    188 TEST_F(CrosNetworkFunctionsTest, CrosCompleteCellularActivation) {
    189   const std::string service_path = "/";
    190   EXPECT_CALL(*mock_service_client_,
    191               CompleteCellularActivation(dbus::ObjectPath(service_path), _, _))
    192       .Times(1);
    193 
    194   CrosCompleteCellularActivation(service_path);
    195 }
    196 
    197 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkServiceProperty) {
    198   const std::string service_path = "/";
    199   const std::string property = "property";
    200   const std::string key1 = "key1";
    201   const std::string string1 = "string1";
    202   const std::string key2 = "key2";
    203   const std::string string2 = "string2";
    204   base::DictionaryValue value;
    205   value.SetString(key1, string1);
    206   value.SetString(key2, string2);
    207   EXPECT_CALL(*mock_service_client_,
    208               SetProperty(dbus::ObjectPath(service_path), property,
    209                           IsEqualTo(&value), _, _)).Times(1);
    210 
    211   CrosSetNetworkServiceProperty(service_path, property, value);
    212 }
    213 
    214 TEST_F(CrosNetworkFunctionsTest, CrosClearNetworkServiceProperty) {
    215   const std::string service_path = "/";
    216   const std::string property = "property";
    217   EXPECT_CALL(*mock_service_client_,
    218               ClearProperty(dbus::ObjectPath(service_path), property, _, _))
    219       .Times(1);
    220 
    221   CrosClearNetworkServiceProperty(service_path, property);
    222 }
    223 
    224 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkDeviceProperty) {
    225   const std::string device_path = "/";
    226   const std::string property = "property";
    227   const bool kBool = true;
    228   const base::FundamentalValue value(kBool);
    229   EXPECT_CALL(*mock_device_client_,
    230               SetProperty(dbus::ObjectPath(device_path), StrEq(property),
    231                           IsEqualTo(&value), _, _)).Times(1);
    232 
    233   CrosSetNetworkDeviceProperty(device_path, property, value);
    234 }
    235 
    236 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkIPConfigProperty) {
    237   const std::string ipconfig_path = "/";
    238   const std::string property = "property";
    239   const int kInt = 1234;
    240   const base::FundamentalValue value(kInt);
    241   EXPECT_CALL(*mock_ipconfig_client_,
    242               SetProperty(dbus::ObjectPath(ipconfig_path), property,
    243                           IsEqualTo(&value), _)).Times(1);
    244   CrosSetNetworkIPConfigProperty(ipconfig_path, property, value);
    245 }
    246 
    247 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkManagerProperty) {
    248   const std::string property = "property";
    249   const base::StringValue value("string");
    250   EXPECT_CALL(*mock_manager_client_,
    251               SetProperty(property, IsEqualTo(&value), _, _)).Times(1);
    252 
    253   CrosSetNetworkManagerProperty(property, value);
    254 }
    255 
    256 TEST_F(CrosNetworkFunctionsTest, CrosDeleteServiceFromProfile) {
    257   const std::string profile_path("/profile/path");
    258   const std::string service_path("/service/path");
    259   EXPECT_CALL(*mock_profile_client_,
    260               DeleteEntry(dbus::ObjectPath(profile_path), service_path, _, _))
    261       .Times(1);
    262   CrosDeleteServiceFromProfile(profile_path, service_path);
    263 }
    264 
    265 TEST_F(CrosNetworkFunctionsTest, CrosMonitorNetworkManagerProperties) {
    266   const std::string key = "key";
    267   const int kValue = 42;
    268   const base::FundamentalValue value(kValue);
    269 
    270   // Start monitoring.
    271   ShillPropertyChangedObserver* observer = NULL;
    272   EXPECT_CALL(*mock_manager_client_, AddPropertyChangedObserver(_))
    273       .WillOnce(SaveArg<0>(&observer));
    274   CrosNetworkWatcher* watcher = CrosMonitorNetworkManagerProperties(
    275       MockNetworkPropertiesWatcherCallback::CreateCallback(
    276           flimflam::kFlimflamServicePath, key, value));
    277   // Call callback.
    278   observer->OnPropertyChanged(key, value);
    279   // Stop monitoring.
    280   EXPECT_CALL(*mock_manager_client_,
    281               RemovePropertyChangedObserver(_)).Times(1);
    282   delete watcher;
    283 }
    284 
    285 TEST_F(CrosNetworkFunctionsTest, CrosMonitorNetworkServiceProperties) {
    286   const dbus::ObjectPath path("/path");
    287   const std::string key = "key";
    288   const int kValue = 42;
    289   const base::FundamentalValue value(kValue);
    290   // Start monitoring.
    291   ShillPropertyChangedObserver* observer = NULL;
    292   EXPECT_CALL(*mock_service_client_, AddPropertyChangedObserver(path, _))
    293       .WillOnce(SaveArg<1>(&observer));
    294   NetworkPropertiesWatcherCallback callback =
    295       MockNetworkPropertiesWatcherCallback::CreateCallback(path.value(),
    296                                                            key, value);
    297   CrosNetworkWatcher* watcher = CrosMonitorNetworkServiceProperties(
    298       callback, path.value());
    299   // Call callback.
    300   observer->OnPropertyChanged(key, value);
    301   // Stop monitoring.
    302   EXPECT_CALL(*mock_service_client_,
    303               RemovePropertyChangedObserver(path, _)).Times(1);
    304   delete watcher;
    305 }
    306 
    307 TEST_F(CrosNetworkFunctionsTest, CrosMonitorNetworkDeviceProperties) {
    308   const dbus::ObjectPath path("/path");
    309   const std::string key = "key";
    310   const int kValue = 42;
    311   const base::FundamentalValue value(kValue);
    312   // Start monitoring.
    313   ShillPropertyChangedObserver* observer = NULL;
    314   EXPECT_CALL(*mock_device_client_, AddPropertyChangedObserver(path, _))
    315       .WillOnce(SaveArg<1>(&observer));
    316   NetworkPropertiesWatcherCallback callback =
    317       MockNetworkPropertiesWatcherCallback::CreateCallback(path.value(),
    318                                                            key, value);
    319   CrosNetworkWatcher* watcher = CrosMonitorNetworkDeviceProperties(
    320       callback, path.value());
    321   // Call callback.
    322   observer->OnPropertyChanged(key, value);
    323   // Stop monitoring.
    324   EXPECT_CALL(*mock_device_client_,
    325               RemovePropertyChangedObserver(path, _)).Times(1);
    326   delete watcher;
    327 }
    328 
    329 TEST_F(CrosNetworkFunctionsTest, CrosMonitorSMS) {
    330   const std::string dbus_connection = ":1.1";
    331   const dbus::ObjectPath object_path("/object/path");
    332   base::DictionaryValue device_properties;
    333   device_properties.SetWithoutPathExpansion(
    334       flimflam::kDBusConnectionProperty,
    335       new base::StringValue(dbus_connection));
    336   device_properties.SetWithoutPathExpansion(
    337       flimflam::kDBusObjectProperty,
    338       new base::StringValue(object_path.value()));
    339 
    340   const std::string number = "0123456789";
    341   const std::string text = "Hello.";
    342   const std::string timestamp_string =
    343       "120424123456+00";  // 2012-04-24 12:34:56
    344   base::Time::Exploded timestamp_exploded = {};
    345   timestamp_exploded.year = 2012;
    346   timestamp_exploded.month = 4;
    347   timestamp_exploded.day_of_month = 24;
    348   timestamp_exploded.hour = 12;
    349   timestamp_exploded.minute = 34;
    350   timestamp_exploded.second = 56;
    351   const base::Time timestamp = base::Time::FromUTCExploded(timestamp_exploded);
    352   const std::string smsc = "9876543210";
    353   const uint32 kValidity = 1;
    354   const uint32 kMsgclass = 2;
    355   const uint32 kIndex = 0;
    356   const bool kComplete = true;
    357   base::DictionaryValue* sms_dictionary = new base::DictionaryValue;
    358   sms_dictionary->SetWithoutPathExpansion(
    359       SMSWatcher::kNumberKey, new base::StringValue(number));
    360   sms_dictionary->SetWithoutPathExpansion(
    361       SMSWatcher::kTextKey, new base::StringValue(text));
    362   sms_dictionary->SetWithoutPathExpansion(
    363       SMSWatcher::kTimestampKey,
    364       new base::StringValue(timestamp_string));
    365   sms_dictionary->SetWithoutPathExpansion(SMSWatcher::kSmscKey,
    366                                          new base::StringValue(smsc));
    367   sms_dictionary->SetWithoutPathExpansion(
    368       SMSWatcher::kValidityKey, base::Value::CreateDoubleValue(kValidity));
    369   sms_dictionary->SetWithoutPathExpansion(
    370       SMSWatcher::kClassKey, base::Value::CreateDoubleValue(kMsgclass));
    371   sms_dictionary->SetWithoutPathExpansion(
    372       SMSWatcher::kIndexKey, base::Value::CreateDoubleValue(kIndex));
    373 
    374   base::ListValue sms_list;
    375   sms_list.Append(sms_dictionary);
    376 
    377   SMS sms;
    378   sms.timestamp = timestamp;
    379   sms.number = number.c_str();
    380   sms.text = text.c_str();
    381   sms.smsc = smsc.c_str();
    382   sms.validity = kValidity;
    383   sms.msgclass = kMsgclass;
    384 
    385   const std::string modem_device_path = "/modem/device/path";
    386 
    387   // Set expectations.
    388   ShillDeviceClient::DictionaryValueCallback get_properties_callback;
    389   EXPECT_CALL(*mock_device_client_,
    390               GetProperties(dbus::ObjectPath(modem_device_path), _))
    391       .WillOnce(SaveArg<1>(&get_properties_callback));
    392   GsmSMSClient::SmsReceivedHandler sms_received_handler;
    393   EXPECT_CALL(*mock_gsm_sms_client_,
    394               SetSmsReceivedHandler(dbus_connection, object_path, _))
    395       .WillOnce(SaveArg<2>(&sms_received_handler));
    396 
    397   GsmSMSClient::ListCallback list_callback;
    398   EXPECT_CALL(*mock_gsm_sms_client_, List(dbus_connection, object_path, _))
    399       .WillOnce(SaveArg<2>(&list_callback));
    400 
    401   EXPECT_CALL(*this, MockMonitorSMSCallback(
    402       modem_device_path, IsSMSEqualTo(sms))).Times(2);
    403 
    404   GsmSMSClient::DeleteCallback delete_callback;
    405   EXPECT_CALL(*mock_gsm_sms_client_,
    406               Delete(dbus_connection, object_path, kIndex, _))
    407       .WillRepeatedly(SaveArg<3>(&delete_callback));
    408 
    409   GsmSMSClient::GetCallback get_callback;
    410   EXPECT_CALL(*mock_gsm_sms_client_,
    411               Get(dbus_connection, object_path, kIndex, _))
    412       .WillOnce(SaveArg<3>(&get_callback));
    413 
    414   // Start monitoring.
    415   CrosNetworkWatcher* watcher = CrosMonitorSMS(
    416       modem_device_path,
    417       base::Bind(&CrosNetworkFunctionsTest::MockMonitorSMSCallback,
    418                  base::Unretained(this)));
    419   // Return GetProperties() result.
    420   get_properties_callback.Run(DBUS_METHOD_CALL_SUCCESS, device_properties);
    421   // Return List() result.
    422   ASSERT_FALSE(list_callback.is_null());
    423   list_callback.Run(sms_list);
    424   // Return Delete() result.
    425   ASSERT_FALSE(delete_callback.is_null());
    426   delete_callback.Run();
    427   // Send fake signal.
    428   ASSERT_FALSE(sms_received_handler.is_null());
    429   sms_received_handler.Run(kIndex, kComplete);
    430   // Return Get() result.
    431   ASSERT_FALSE(get_callback.is_null());
    432   get_callback.Run(*sms_dictionary);
    433   // Return Delete() result.
    434   ASSERT_FALSE(delete_callback.is_null());
    435   delete_callback.Run();
    436   // Stop monitoring.
    437   EXPECT_CALL(*mock_gsm_sms_client_,
    438               ResetSmsReceivedHandler(dbus_connection, object_path)).Times(1);
    439   delete watcher;
    440 }
    441 
    442 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkManagerProperties) {
    443   const std::string key1 = "key1";
    444   const std::string value1 = "value1";
    445   const std::string key2 = "key.2.";
    446   const std::string value2 = "value2";
    447   // Create result value.
    448   base::DictionaryValue result;
    449   result.SetWithoutPathExpansion(key1, new base::StringValue(value1));
    450   result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
    451   // Set expectations.
    452   dictionary_value_result_ = &result;
    453   EXPECT_CALL(*mock_manager_client_,
    454               GetProperties(_)).WillOnce(
    455                   Invoke(this,
    456                          &CrosNetworkFunctionsTest::OnGetManagerProperties));
    457 
    458   CrosRequestNetworkManagerProperties(
    459       MockNetworkPropertiesCallback::CreateCallback(
    460           flimflam::kFlimflamServicePath, result));
    461 }
    462 
    463 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceProperties) {
    464   const std::string service_path = "/service/path";
    465   const std::string key1 = "key1";
    466   const std::string value1 = "value1";
    467   const std::string key2 = "key.2.";
    468   const std::string value2 = "value2";
    469   // Create result value.
    470   base::DictionaryValue result;
    471   result.SetWithoutPathExpansion(key1, new base::StringValue(value1));
    472   result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
    473   // Set expectations.
    474   dictionary_value_result_ = &result;
    475   EXPECT_CALL(*mock_service_client_,
    476               GetProperties(dbus::ObjectPath(service_path), _)).WillOnce(
    477                   Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
    478 
    479   CrosRequestNetworkServiceProperties(
    480       service_path,
    481       MockNetworkPropertiesCallback::CreateCallback(service_path, result));
    482 }
    483 
    484 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkDeviceProperties) {
    485   const std::string device_path = "/device/path";
    486   const std::string key1 = "key1";
    487   const std::string value1 = "value1";
    488   const std::string key2 = "key.2.";
    489   const std::string value2 = "value2";
    490   // Create result value.
    491   base::DictionaryValue result;
    492   result.SetWithoutPathExpansion(key1, new base::StringValue(value1));
    493   result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
    494   // Set expectations.
    495   dictionary_value_result_ = &result;
    496   EXPECT_CALL(*mock_device_client_,
    497               GetProperties(dbus::ObjectPath(device_path), _)).WillOnce(
    498                   Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
    499 
    500   CrosRequestNetworkDeviceProperties(
    501       device_path,
    502       MockNetworkPropertiesCallback::CreateCallback(device_path, result));
    503 }
    504 
    505 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileProperties) {
    506   const std::string profile_path = "/profile/path";
    507   const std::string key1 = "key1";
    508   const std::string value1 = "value1";
    509   const std::string key2 = "key.2.";
    510   const std::string value2 = "value2";
    511   // Create result value.
    512   base::DictionaryValue result;
    513   result.SetWithoutPathExpansion(key1, new base::StringValue(value1));
    514   result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
    515   // Set expectations.
    516   dictionary_value_result_ = &result;
    517   EXPECT_CALL(
    518       *mock_profile_client_,
    519       GetProperties(dbus::ObjectPath(profile_path), _, _)).WillOnce(
    520           Invoke(this,
    521                  &CrosNetworkFunctionsTest::OnGetPropertiesWithoutStatus));
    522 
    523   CrosRequestNetworkProfileProperties(
    524       profile_path,
    525       MockNetworkPropertiesCallback::CreateCallback(profile_path, result));
    526 }
    527 
    528 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) {
    529   const std::string profile_path = "profile path";
    530   const std::string profile_entry_path = "profile entry path";
    531   const std::string key1 = "key1";
    532   const std::string value1 = "value1";
    533   const std::string key2 = "key.2.";
    534   const std::string value2 = "value2";
    535   // Create result value.
    536   base::DictionaryValue result;
    537   result.SetWithoutPathExpansion(key1, new base::StringValue(value1));
    538   result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
    539   // Set expectations.
    540   dictionary_value_result_ = &result;
    541   EXPECT_CALL(*mock_profile_client_,
    542               GetEntry(dbus::ObjectPath(profile_path),
    543                        profile_entry_path, _, _))
    544       .WillOnce(Invoke(this, &CrosNetworkFunctionsTest::OnGetEntry));
    545 
    546   CrosRequestNetworkProfileEntryProperties(
    547       profile_path, profile_entry_path,
    548       MockNetworkPropertiesCallback::CreateCallback(profile_entry_path,
    549                                                     result));
    550 }
    551 
    552 TEST_F(CrosNetworkFunctionsTest, CrosRequestHiddenWifiNetworkProperties) {
    553   const std::string ssid = "ssid";
    554   const std::string security = "security";
    555   const std::string key1 = "key1";
    556   const std::string value1 = "value1";
    557   const std::string key2 = "key.2.";
    558   const std::string value2 = "value2";
    559   // Create result value.
    560   base::DictionaryValue result;
    561   result.SetWithoutPathExpansion(key1, new base::StringValue(value1));
    562   result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
    563   dictionary_value_result_ = &result;
    564   // Create expected argument to ShillManagerClient::GetService.
    565   base::DictionaryValue properties;
    566   properties.SetWithoutPathExpansion(
    567       flimflam::kModeProperty,
    568       new base::StringValue(flimflam::kModeManaged));
    569   properties.SetWithoutPathExpansion(
    570       flimflam::kTypeProperty,
    571       new base::StringValue(flimflam::kTypeWifi));
    572   properties.SetWithoutPathExpansion(
    573       flimflam::kSSIDProperty,
    574       new base::StringValue(ssid));
    575   properties.SetWithoutPathExpansion(
    576       flimflam::kSecurityProperty,
    577       new base::StringValue(security));
    578   // Set expectations.
    579   const dbus::ObjectPath service_path("/service/path");
    580   ObjectPathCallback callback;
    581   EXPECT_CALL(*mock_manager_client_, GetService(IsEqualTo(&properties), _, _))
    582       .WillOnce(SaveArg<1>(&callback));
    583   EXPECT_CALL(*mock_service_client_,
    584               GetProperties(service_path, _)).WillOnce(
    585                   Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
    586 
    587   // Call function.
    588   CrosRequestHiddenWifiNetworkProperties(
    589       ssid, security,
    590       MockNetworkPropertiesCallback::CreateCallback(service_path.value(),
    591                                                     result));
    592   // Run callback to invoke GetProperties.
    593   callback.Run(service_path);
    594 }
    595 
    596 TEST_F(CrosNetworkFunctionsTest, CrosRequestVirtualNetworkProperties) {
    597   const std::string service_name = "service name";
    598   const std::string server_hostname = "server hostname";
    599   const std::string provider_type = "provider type";
    600   const std::string key1 = "key1";
    601   const std::string value1 = "value1";
    602   const std::string key2 = "key.2.";
    603   const std::string value2 = "value2";
    604   // Create result value.
    605   base::DictionaryValue result;
    606   result.SetWithoutPathExpansion(key1, new base::StringValue(value1));
    607   result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
    608   dictionary_value_result_ = &result;
    609   // Create expected argument to ShillManagerClient::ConfigureService.
    610   base::DictionaryValue properties;
    611   properties.SetWithoutPathExpansion(
    612       flimflam::kTypeProperty, new base::StringValue("vpn"));
    613   properties.SetWithoutPathExpansion(
    614       flimflam::kNameProperty,
    615       new base::StringValue(service_name));
    616   properties.SetWithoutPathExpansion(
    617       flimflam::kProviderHostProperty,
    618       new base::StringValue(server_hostname));
    619   properties.SetWithoutPathExpansion(
    620       flimflam::kProviderTypeProperty,
    621       new base::StringValue(provider_type));
    622 
    623   // Set expectations.
    624   const dbus::ObjectPath service_path("/service/path");
    625   ObjectPathCallback callback;
    626   EXPECT_CALL(*mock_manager_client_,
    627               ConfigureService(IsEqualTo(&properties), _, _))
    628       .WillOnce(SaveArg<1>(&callback));
    629   EXPECT_CALL(*mock_service_client_,
    630               GetProperties(service_path, _)).WillOnce(
    631                   Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
    632 
    633   // Call function.
    634   CrosRequestVirtualNetworkProperties(
    635       service_name, server_hostname, provider_type,
    636       MockNetworkPropertiesCallback::CreateCallback(service_path.value(),
    637                                                     result));
    638   // Run callback to invoke GetProperties.
    639   callback.Run(service_path);
    640 }
    641 
    642 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceDisconnect) {
    643   const std::string service_path = "/service/path";
    644   EXPECT_CALL(*mock_service_client_,
    645               Disconnect(dbus::ObjectPath(service_path), _, _)).Times(1);
    646   CrosRequestNetworkServiceDisconnect(service_path);
    647 }
    648 
    649 TEST_F(CrosNetworkFunctionsTest, CrosRequestRemoveNetworkService) {
    650   const std::string service_path = "/service/path";
    651   EXPECT_CALL(*mock_service_client_,
    652               Remove(dbus::ObjectPath(service_path), _, _)).Times(1);
    653   CrosRequestRemoveNetworkService(service_path);
    654 }
    655 
    656 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkScan) {
    657   EXPECT_CALL(*mock_manager_client_,
    658               RequestScan(flimflam::kTypeWifi, _, _)).Times(1);
    659   CrosRequestNetworkScan(flimflam::kTypeWifi);
    660 }
    661 
    662 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkDeviceEnable) {
    663   const bool kEnable = true;
    664   EXPECT_CALL(*mock_manager_client_,
    665               EnableTechnology(flimflam::kTypeWifi, _, _)).Times(1);
    666   CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable);
    667 
    668   const bool kDisable = false;
    669   EXPECT_CALL(*mock_manager_client_,
    670               DisableTechnology(flimflam::kTypeWifi, _, _)).Times(1);
    671   CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kDisable);
    672 }
    673 
    674 TEST_F(CrosNetworkFunctionsTest, CrosRequestRequirePin) {
    675   const std::string device_path = "/device/path";
    676   const std::string pin = "123456";
    677   const bool kRequire = true;
    678 
    679   // Set expectations.
    680   base::Closure callback;
    681   EXPECT_CALL(*mock_device_client_,
    682               RequirePin(dbus::ObjectPath(device_path), pin, kRequire, _, _))
    683       .WillOnce(SaveArg<3>(&callback));
    684   EXPECT_CALL(*this, MockNetworkOperationCallback(
    685       device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
    686   CrosRequestRequirePin(
    687       device_path, pin, kRequire,
    688       base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
    689                  base::Unretained(this)));
    690   // Run saved callback.
    691   callback.Run();
    692 }
    693 
    694 TEST_F(CrosNetworkFunctionsTest, CrosRequestEnterPin) {
    695   const std::string device_path = "/device/path";
    696   const std::string pin = "123456";
    697 
    698   // Set expectations.
    699   base::Closure callback;
    700   EXPECT_CALL(*mock_device_client_,
    701               EnterPin(dbus::ObjectPath(device_path), pin, _, _))
    702       .WillOnce(SaveArg<2>(&callback));
    703   EXPECT_CALL(*this, MockNetworkOperationCallback(
    704       device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
    705   CrosRequestEnterPin(
    706       device_path, pin,
    707       base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
    708                  base::Unretained(this)));
    709   // Run saved callback.
    710   callback.Run();
    711 }
    712 
    713 TEST_F(CrosNetworkFunctionsTest, CrosRequestUnblockPin) {
    714   const std::string device_path = "/device/path";
    715   const std::string unblock_code = "987654";
    716   const std::string pin = "123456";
    717 
    718   // Set expectations.
    719   base::Closure callback;
    720   EXPECT_CALL(
    721       *mock_device_client_,
    722       UnblockPin(dbus::ObjectPath(device_path), unblock_code, pin, _, _))
    723       .WillOnce(SaveArg<3>(&callback));
    724   EXPECT_CALL(*this, MockNetworkOperationCallback(
    725       device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
    726   CrosRequestUnblockPin(device_path, unblock_code, pin,
    727       base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
    728                  base::Unretained(this)));
    729   // Run saved callback.
    730   callback.Run();
    731 }
    732 
    733 TEST_F(CrosNetworkFunctionsTest, CrosRequestChangePin) {
    734   const std::string device_path = "/device/path";
    735   const std::string old_pin = "123456";
    736   const std::string new_pin = "234567";
    737 
    738   // Set expectations.
    739   base::Closure callback;
    740   EXPECT_CALL(*mock_device_client_,
    741               ChangePin(dbus::ObjectPath(device_path), old_pin, new_pin,  _, _))
    742       .WillOnce(SaveArg<3>(&callback));
    743   EXPECT_CALL(*this, MockNetworkOperationCallback(
    744       device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
    745   CrosRequestChangePin(device_path, old_pin, new_pin,
    746       base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
    747                  base::Unretained(this)));
    748   // Run saved callback.
    749   callback.Run();
    750 }
    751 
    752 TEST_F(CrosNetworkFunctionsTest, CrosProposeScan) {
    753   const std::string device_path = "/device/path";
    754   EXPECT_CALL(*mock_device_client_,
    755               ProposeScan(dbus::ObjectPath(device_path), _)).Times(1);
    756   CrosProposeScan(device_path);
    757 }
    758 
    759 TEST_F(CrosNetworkFunctionsTest, CrosRequestCellularRegister) {
    760   const std::string device_path = "/device/path";
    761   const std::string network_id = "networkid";
    762 
    763   // Set expectations.
    764   base::Closure callback;
    765   EXPECT_CALL(*mock_device_client_,
    766               Register(dbus::ObjectPath(device_path), network_id, _, _))
    767       .WillOnce(SaveArg<2>(&callback));
    768   EXPECT_CALL(*this, MockNetworkOperationCallback(
    769       device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
    770   CrosRequestCellularRegister(device_path, network_id,
    771       base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
    772                  base::Unretained(this)));
    773   // Run saved callback.
    774   callback.Run();
    775 }
    776 
    777 TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) {
    778   const std::string key1 = "key1";
    779   const std::string string1 = "string1";
    780   const std::string key2 = "key2";
    781   const std::string string2 = "string2";
    782   base::DictionaryValue value;
    783   value.SetString(key1, string1);
    784   value.SetString(key2, string2);
    785   EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _, _))
    786       .Times(1);
    787   CrosConfigureService(value);
    788 }
    789 
    790 }  // namespace chromeos
    791