| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 9 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 10 #include "chromeos/dbus/fake_shill_device_client.h" | 10 #include "chromeos/dbus/fake_shill_device_client.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 virtual void SetUp() OVERRIDE { | 33 virtual void SetUp() OVERRIDE { |
| 34 FakeDBusThreadManager* dbus_manager = new FakeDBusThreadManager; | 34 FakeDBusThreadManager* dbus_manager = new FakeDBusThreadManager; |
| 35 dbus_manager->SetFakeShillClients(); | 35 dbus_manager->SetFakeShillClients(); |
| 36 | 36 |
| 37 fake_device_client_ = new FakeShillDeviceClient; | 37 fake_device_client_ = new FakeShillDeviceClient; |
| 38 dbus_manager->SetShillDeviceClient( | 38 dbus_manager->SetShillDeviceClient( |
| 39 scoped_ptr<ShillDeviceClient>(fake_device_client_)); | 39 scoped_ptr<ShillDeviceClient>(fake_device_client_)); |
| 40 DBusThreadManager::InitializeForTesting(dbus_manager); | 40 DBusThreadManager::InitializeForTesting(dbus_manager); |
| 41 | 41 |
| 42 ShillDeviceClient::TestInterface* device_test = | |
| 43 fake_device_client_->GetTestInterface(); | |
| 44 device_test->AddDevice( | |
| 45 kDefaultCellularDevicePath, shill::kTypeCellular, "cellular1"); | |
| 46 device_test->AddDevice(kDefaultWifiDevicePath, shill::kTypeWifi, "wifi1"); | |
| 47 | |
| 48 base::ListValue test_ip_configs; | |
| 49 test_ip_configs.AppendString("ip_config1"); | |
| 50 device_test->SetDeviceProperty( | |
| 51 kDefaultWifiDevicePath, shill::kIPConfigsProperty, test_ip_configs); | |
| 52 | |
| 53 success_callback_ = base::Bind(&NetworkDeviceHandlerTest::SuccessCallback, | 42 success_callback_ = base::Bind(&NetworkDeviceHandlerTest::SuccessCallback, |
| 54 base::Unretained(this)); | 43 base::Unretained(this)); |
| 55 properties_success_callback_ = | 44 properties_success_callback_ = |
| 56 base::Bind(&NetworkDeviceHandlerTest::PropertiesSuccessCallback, | 45 base::Bind(&NetworkDeviceHandlerTest::PropertiesSuccessCallback, |
| 57 base::Unretained(this)); | 46 base::Unretained(this)); |
| 47 string_success_callback_ = |
| 48 base::Bind(&NetworkDeviceHandlerTest::StringSuccessCallback, |
| 49 base::Unretained(this)); |
| 58 error_callback_ = base::Bind(&NetworkDeviceHandlerTest::ErrorCallback, | 50 error_callback_ = base::Bind(&NetworkDeviceHandlerTest::ErrorCallback, |
| 59 base::Unretained(this)); | 51 base::Unretained(this)); |
| 60 | 52 |
| 61 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); | 53 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); |
| 62 NetworkDeviceHandlerImpl* device_handler = new NetworkDeviceHandlerImpl; | 54 NetworkDeviceHandlerImpl* device_handler = new NetworkDeviceHandlerImpl; |
| 63 device_handler->Init(network_state_handler_.get()); | 55 device_handler->Init(network_state_handler_.get()); |
| 64 network_device_handler_.reset(device_handler); | 56 network_device_handler_.reset(device_handler); |
| 57 |
| 58 // Add devices after handlers have been initialized. |
| 59 ShillDeviceClient::TestInterface* device_test = |
| 60 fake_device_client_->GetTestInterface(); |
| 61 device_test->AddDevice( |
| 62 kDefaultCellularDevicePath, shill::kTypeCellular, "cellular1"); |
| 63 device_test->AddDevice(kDefaultWifiDevicePath, shill::kTypeWifi, "wifi1"); |
| 64 |
| 65 base::ListValue test_ip_configs; |
| 66 test_ip_configs.AppendString("ip_config1"); |
| 67 device_test->SetDeviceProperty( |
| 68 kDefaultWifiDevicePath, shill::kIPConfigsProperty, test_ip_configs); |
| 69 |
| 70 message_loop_.RunUntilIdle(); |
| 65 } | 71 } |
| 66 | 72 |
| 67 virtual void TearDown() OVERRIDE { | 73 virtual void TearDown() OVERRIDE { |
| 68 network_device_handler_.reset(); | 74 network_device_handler_.reset(); |
| 69 network_state_handler_.reset(); | 75 network_state_handler_.reset(); |
| 70 DBusThreadManager::Shutdown(); | 76 DBusThreadManager::Shutdown(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 void ErrorCallback(const std::string& error_name, | 79 void ErrorCallback(const std::string& error_name, |
| 74 scoped_ptr<base::DictionaryValue> error_data) { | 80 scoped_ptr<base::DictionaryValue> error_data) { |
| 75 result_ = error_name; | 81 result_ = error_name; |
| 76 } | 82 } |
| 77 | 83 |
| 78 void SuccessCallback() { | 84 void SuccessCallback() { |
| 79 result_ = kResultSuccess; | 85 result_ = kResultSuccess; |
| 80 } | 86 } |
| 81 | 87 |
| 82 void PropertiesSuccessCallback(const std::string& device_path, | 88 void PropertiesSuccessCallback(const std::string& device_path, |
| 83 const base::DictionaryValue& properties) { | 89 const base::DictionaryValue& properties) { |
| 84 result_ = kResultSuccess; | 90 result_ = kResultSuccess; |
| 85 properties_.reset(properties.DeepCopy()); | 91 properties_.reset(properties.DeepCopy()); |
| 86 } | 92 } |
| 87 | 93 |
| 94 void StringSuccessCallback(const std::string& result) { |
| 95 result_ = kResultSuccess; |
| 96 } |
| 97 |
| 88 protected: | 98 protected: |
| 89 std::string result_; | 99 std::string result_; |
| 90 | 100 |
| 91 FakeShillDeviceClient* fake_device_client_; | 101 FakeShillDeviceClient* fake_device_client_; |
| 92 scoped_ptr<NetworkDeviceHandler> network_device_handler_; | 102 scoped_ptr<NetworkDeviceHandler> network_device_handler_; |
| 93 scoped_ptr<NetworkStateHandler> network_state_handler_; | 103 scoped_ptr<NetworkStateHandler> network_state_handler_; |
| 94 base::MessageLoopForUI message_loop_; | 104 base::MessageLoopForUI message_loop_; |
| 95 base::Closure success_callback_; | 105 base::Closure success_callback_; |
| 96 network_handler::DictionaryResultCallback properties_success_callback_; | 106 network_handler::DictionaryResultCallback properties_success_callback_; |
| 107 network_handler::StringResultCallback string_success_callback_; |
| 97 network_handler::ErrorCallback error_callback_; | 108 network_handler::ErrorCallback error_callback_; |
| 98 scoped_ptr<base::DictionaryValue> properties_; | 109 scoped_ptr<base::DictionaryValue> properties_; |
| 99 | 110 |
| 100 private: | 111 private: |
| 101 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); | 112 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); |
| 102 }; | 113 }; |
| 103 | 114 |
| 104 TEST_F(NetworkDeviceHandlerTest, GetDeviceProperties) { | 115 TEST_F(NetworkDeviceHandlerTest, GetDeviceProperties) { |
| 105 network_device_handler_->GetDeviceProperties( | 116 network_device_handler_->GetDeviceProperties( |
| 106 kDefaultWifiDevicePath, properties_success_callback_, error_callback_); | 117 kDefaultWifiDevicePath, properties_success_callback_, error_callback_); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 network_device_handler_->GetDeviceProperties(kDefaultCellularDevicePath, | 213 network_device_handler_->GetDeviceProperties(kDefaultCellularDevicePath, |
| 203 properties_success_callback_, | 214 properties_success_callback_, |
| 204 error_callback_); | 215 error_callback_); |
| 205 message_loop_.RunUntilIdle(); | 216 message_loop_.RunUntilIdle(); |
| 206 EXPECT_EQ(kResultSuccess, result_); | 217 EXPECT_EQ(kResultSuccess, result_); |
| 207 EXPECT_TRUE(properties_->GetBooleanWithoutPathExpansion( | 218 EXPECT_TRUE(properties_->GetBooleanWithoutPathExpansion( |
| 208 shill::kCellularAllowRoamingProperty, &allow_roaming)); | 219 shill::kCellularAllowRoamingProperty, &allow_roaming)); |
| 209 EXPECT_FALSE(allow_roaming); | 220 EXPECT_FALSE(allow_roaming); |
| 210 } | 221 } |
| 211 | 222 |
| 223 TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabled) { |
| 224 // We add a wifi device by default, initial call should succed. |
| 225 network_device_handler_->SetWifiTDLSEnabled( |
| 226 "fake_ip_address", true, string_success_callback_, error_callback_); |
| 227 message_loop_.RunUntilIdle(); |
| 228 EXPECT_EQ(kResultSuccess, result_); |
| 229 |
| 230 // Remove the wifi device. Call should fail with "device missing" error. |
| 231 fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath); |
| 232 message_loop_.RunUntilIdle(); |
| 233 network_device_handler_->SetWifiTDLSEnabled( |
| 234 "fake_ip_address", true, string_success_callback_, error_callback_); |
| 235 message_loop_.RunUntilIdle(); |
| 236 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_); |
| 237 } |
| 238 |
| 239 TEST_F(NetworkDeviceHandlerTest, GetWifiTDLSStatus) { |
| 240 // We add a wifi device by default, initial call should succed. |
| 241 network_device_handler_->GetWifiTDLSStatus( |
| 242 "fake_ip_address", string_success_callback_, error_callback_); |
| 243 message_loop_.RunUntilIdle(); |
| 244 EXPECT_EQ(kResultSuccess, result_); |
| 245 |
| 246 // Remove the wifi device. Call should fail with "device missing" error. |
| 247 fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath); |
| 248 message_loop_.RunUntilIdle(); |
| 249 network_device_handler_->GetWifiTDLSStatus( |
| 250 "fake_ip_address", string_success_callback_, error_callback_); |
| 251 message_loop_.RunUntilIdle(); |
| 252 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_); |
| 253 } |
| 254 |
| 212 TEST_F(NetworkDeviceHandlerTest, RequestRefreshIPConfigs) { | 255 TEST_F(NetworkDeviceHandlerTest, RequestRefreshIPConfigs) { |
| 213 network_device_handler_->RequestRefreshIPConfigs( | 256 network_device_handler_->RequestRefreshIPConfigs( |
| 214 kDefaultWifiDevicePath, success_callback_, error_callback_); | 257 kDefaultWifiDevicePath, success_callback_, error_callback_); |
| 215 message_loop_.RunUntilIdle(); | 258 message_loop_.RunUntilIdle(); |
| 216 EXPECT_EQ(kResultSuccess, result_); | 259 EXPECT_EQ(kResultSuccess, result_); |
| 217 // TODO(stevenjb): Add test interface to ShillIPConfigClient and test | 260 // TODO(stevenjb): Add test interface to ShillIPConfigClient and test |
| 218 // refresh calls. | 261 // refresh calls. |
| 219 } | 262 } |
| 220 | 263 |
| 221 TEST_F(NetworkDeviceHandlerTest, SetCarrier) { | 264 TEST_F(NetworkDeviceHandlerTest, SetCarrier) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 network_device_handler_->ChangePin(kUnknownCellularDevicePath, | 355 network_device_handler_->ChangePin(kUnknownCellularDevicePath, |
| 313 kOldPin, | 356 kOldPin, |
| 314 kNewPin, | 357 kNewPin, |
| 315 success_callback_, | 358 success_callback_, |
| 316 error_callback_); | 359 error_callback_); |
| 317 message_loop_.RunUntilIdle(); | 360 message_loop_.RunUntilIdle(); |
| 318 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); | 361 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); |
| 319 } | 362 } |
| 320 | 363 |
| 321 } // namespace chromeos | 364 } // namespace chromeos |
| OLD | NEW |