| 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) { |
| 81 LOG(ERROR) << "ErrorCallback: " << error_name; |
| 75 result_ = error_name; | 82 result_ = error_name; |
| 76 } | 83 } |
| 77 | 84 |
| 78 void SuccessCallback() { | 85 void SuccessCallback() { |
| 79 result_ = kResultSuccess; | 86 result_ = kResultSuccess; |
| 80 } | 87 } |
| 81 | 88 |
| 82 void PropertiesSuccessCallback(const std::string& device_path, | 89 void PropertiesSuccessCallback(const std::string& device_path, |
| 83 const base::DictionaryValue& properties) { | 90 const base::DictionaryValue& properties) { |
| 84 result_ = kResultSuccess; | 91 result_ = kResultSuccess; |
| 85 properties_.reset(properties.DeepCopy()); | 92 properties_.reset(properties.DeepCopy()); |
| 86 } | 93 } |
| 87 | 94 |
| 95 void StringSuccessCallback(const std::string& result) { |
| 96 LOG(ERROR) << "StringSuccessCallback: " << result; |
| 97 result_ = kResultSuccess; |
| 98 } |
| 99 |
| 88 protected: | 100 protected: |
| 89 std::string result_; | 101 std::string result_; |
| 90 | 102 |
| 91 FakeShillDeviceClient* fake_device_client_; | 103 FakeShillDeviceClient* fake_device_client_; |
| 92 scoped_ptr<NetworkDeviceHandler> network_device_handler_; | 104 scoped_ptr<NetworkDeviceHandler> network_device_handler_; |
| 93 scoped_ptr<NetworkStateHandler> network_state_handler_; | 105 scoped_ptr<NetworkStateHandler> network_state_handler_; |
| 94 base::MessageLoopForUI message_loop_; | 106 base::MessageLoopForUI message_loop_; |
| 95 base::Closure success_callback_; | 107 base::Closure success_callback_; |
| 96 network_handler::DictionaryResultCallback properties_success_callback_; | 108 network_handler::DictionaryResultCallback properties_success_callback_; |
| 109 network_handler::StringResultCallback string_success_callback_; |
| 97 network_handler::ErrorCallback error_callback_; | 110 network_handler::ErrorCallback error_callback_; |
| 98 scoped_ptr<base::DictionaryValue> properties_; | 111 scoped_ptr<base::DictionaryValue> properties_; |
| 99 | 112 |
| 100 private: | 113 private: |
| 101 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); | 114 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); |
| 102 }; | 115 }; |
| 103 | 116 |
| 104 TEST_F(NetworkDeviceHandlerTest, GetDeviceProperties) { | 117 TEST_F(NetworkDeviceHandlerTest, GetDeviceProperties) { |
| 105 network_device_handler_->GetDeviceProperties( | 118 network_device_handler_->GetDeviceProperties( |
| 106 kDefaultWifiDevicePath, properties_success_callback_, error_callback_); | 119 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, | 215 network_device_handler_->GetDeviceProperties(kDefaultCellularDevicePath, |
| 203 properties_success_callback_, | 216 properties_success_callback_, |
| 204 error_callback_); | 217 error_callback_); |
| 205 message_loop_.RunUntilIdle(); | 218 message_loop_.RunUntilIdle(); |
| 206 EXPECT_EQ(kResultSuccess, result_); | 219 EXPECT_EQ(kResultSuccess, result_); |
| 207 EXPECT_TRUE(properties_->GetBooleanWithoutPathExpansion( | 220 EXPECT_TRUE(properties_->GetBooleanWithoutPathExpansion( |
| 208 shill::kCellularAllowRoamingProperty, &allow_roaming)); | 221 shill::kCellularAllowRoamingProperty, &allow_roaming)); |
| 209 EXPECT_FALSE(allow_roaming); | 222 EXPECT_FALSE(allow_roaming); |
| 210 } | 223 } |
| 211 | 224 |
| 225 TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabled) { |
| 226 // We add a wifi device by default, initial call should succeed. |
| 227 network_device_handler_->SetWifiTDLSEnabled( |
| 228 "fake_ip_address", true, string_success_callback_, error_callback_); |
| 229 message_loop_.RunUntilIdle(); |
| 230 EXPECT_EQ(kResultSuccess, result_); |
| 231 |
| 232 // Remove the wifi device. Call should fail with "device missing" error. |
| 233 fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath); |
| 234 message_loop_.RunUntilIdle(); |
| 235 network_device_handler_->SetWifiTDLSEnabled( |
| 236 "fake_ip_address", true, string_success_callback_, error_callback_); |
| 237 message_loop_.RunUntilIdle(); |
| 238 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_); |
| 239 } |
| 240 |
| 241 TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabledBusy) { |
| 242 // Set the busy count, call should succeed after repeat attempt. |
| 243 fake_device_client_->set_tdls_busy_count(1); |
| 244 network_device_handler_->SetWifiTDLSEnabled( |
| 245 "fake_ip_address", true, string_success_callback_, error_callback_); |
| 246 message_loop_.RunUntilIdle(); |
| 247 EXPECT_EQ(kResultSuccess, result_); |
| 248 |
| 249 // Set the busy count to a large number, call should fail after max number |
| 250 // of repeat attempt. |
| 251 fake_device_client_->set_tdls_busy_count(100000); |
| 252 network_device_handler_->SetWifiTDLSEnabled( |
| 253 "fake_ip_address", true, string_success_callback_, error_callback_); |
| 254 message_loop_.RunUntilIdle(); |
| 255 EXPECT_EQ(NetworkDeviceHandler::kErrorTimeout, result_); |
| 256 } |
| 257 |
| 258 TEST_F(NetworkDeviceHandlerTest, GetWifiTDLSStatus) { |
| 259 // We add a wifi device by default, initial call should succeed. |
| 260 network_device_handler_->GetWifiTDLSStatus( |
| 261 "fake_ip_address", string_success_callback_, error_callback_); |
| 262 message_loop_.RunUntilIdle(); |
| 263 EXPECT_EQ(kResultSuccess, result_); |
| 264 |
| 265 // Remove the wifi device. Call should fail with "device missing" error. |
| 266 fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath); |
| 267 message_loop_.RunUntilIdle(); |
| 268 network_device_handler_->GetWifiTDLSStatus( |
| 269 "fake_ip_address", string_success_callback_, error_callback_); |
| 270 message_loop_.RunUntilIdle(); |
| 271 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_); |
| 272 } |
| 273 |
| 212 TEST_F(NetworkDeviceHandlerTest, RequestRefreshIPConfigs) { | 274 TEST_F(NetworkDeviceHandlerTest, RequestRefreshIPConfigs) { |
| 213 network_device_handler_->RequestRefreshIPConfigs( | 275 network_device_handler_->RequestRefreshIPConfigs( |
| 214 kDefaultWifiDevicePath, success_callback_, error_callback_); | 276 kDefaultWifiDevicePath, success_callback_, error_callback_); |
| 215 message_loop_.RunUntilIdle(); | 277 message_loop_.RunUntilIdle(); |
| 216 EXPECT_EQ(kResultSuccess, result_); | 278 EXPECT_EQ(kResultSuccess, result_); |
| 217 // TODO(stevenjb): Add test interface to ShillIPConfigClient and test | 279 // TODO(stevenjb): Add test interface to ShillIPConfigClient and test |
| 218 // refresh calls. | 280 // refresh calls. |
| 219 } | 281 } |
| 220 | 282 |
| 221 TEST_F(NetworkDeviceHandlerTest, SetCarrier) { | 283 TEST_F(NetworkDeviceHandlerTest, SetCarrier) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 network_device_handler_->ChangePin(kUnknownCellularDevicePath, | 374 network_device_handler_->ChangePin(kUnknownCellularDevicePath, |
| 313 kOldPin, | 375 kOldPin, |
| 314 kNewPin, | 376 kNewPin, |
| 315 success_callback_, | 377 success_callback_, |
| 316 error_callback_); | 378 error_callback_); |
| 317 message_loop_.RunUntilIdle(); | 379 message_loop_.RunUntilIdle(); |
| 318 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); | 380 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); |
| 319 } | 381 } |
| 320 | 382 |
| 321 } // namespace chromeos | 383 } // namespace chromeos |
| OLD | NEW |