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

Side by Side Diff: chromeos/network/network_device_handler_unittest.cc

Issue 156353002: Implement networkingPrivate.setWifiTDLSEnabledState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable TDLS tests on non-chromeos Created 6 years, 10 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
« no previous file with comments | « chromeos/network/network_device_handler_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 shill::kScanIntervalProperty, &interval)); 164 shill::kScanIntervalProperty, &interval));
152 EXPECT_EQ(2, interval); 165 EXPECT_EQ(2, interval);
153 166
154 // Set property on an invalid path. 167 // Set property on an invalid path.
155 network_device_handler_->SetDeviceProperty(kUnknownCellularDevicePath, 168 network_device_handler_->SetDeviceProperty(kUnknownCellularDevicePath,
156 shill::kScanIntervalProperty, 169 shill::kScanIntervalProperty,
157 base::FundamentalValue(1), 170 base::FundamentalValue(1),
158 success_callback_, 171 success_callback_,
159 error_callback_); 172 error_callback_);
160 message_loop_.RunUntilIdle(); 173 message_loop_.RunUntilIdle();
161 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); 174 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
162 175
163 // Setting a owner-protected device property through SetDeviceProperty must 176 // Setting a owner-protected device property through SetDeviceProperty must
164 // fail. 177 // fail.
165 network_device_handler_->SetDeviceProperty( 178 network_device_handler_->SetDeviceProperty(
166 kDefaultCellularDevicePath, 179 kDefaultCellularDevicePath,
167 shill::kCellularAllowRoamingProperty, 180 shill::kCellularAllowRoamingProperty,
168 base::FundamentalValue(true), 181 base::FundamentalValue(true),
169 success_callback_, 182 success_callback_,
170 error_callback_); 183 error_callback_);
171 message_loop_.RunUntilIdle(); 184 message_loop_.RunUntilIdle();
(...skipping 30 matching lines...) Expand all
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
233 TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabledMissing) {
234 // Remove the wifi device. Call should fail with "device missing" error.
235 fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath);
236 message_loop_.RunUntilIdle();
237 network_device_handler_->SetWifiTDLSEnabled(
238 "fake_ip_address", true, string_success_callback_, error_callback_);
239 message_loop_.RunUntilIdle();
240 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
241 }
242
243 TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabledBusy) {
244 // Set the busy count, call should succeed after repeat attempt.
245 fake_device_client_->set_tdls_busy_count(1);
246 network_device_handler_->SetWifiTDLSEnabled(
247 "fake_ip_address", true, string_success_callback_, error_callback_);
248 message_loop_.RunUntilIdle();
249 EXPECT_EQ(kResultSuccess, result_);
250
251 // Set the busy count to a large number, call should fail after max number
252 // of repeat attempt.
253 fake_device_client_->set_tdls_busy_count(100000);
254 network_device_handler_->SetWifiTDLSEnabled(
255 "fake_ip_address", true, string_success_callback_, error_callback_);
256 message_loop_.RunUntilIdle();
257 EXPECT_EQ(NetworkDeviceHandler::kErrorTimeout, result_);
258 }
259
260 TEST_F(NetworkDeviceHandlerTest, GetWifiTDLSStatus) {
261 // We add a wifi device by default, initial call should succeed.
262 network_device_handler_->GetWifiTDLSStatus(
263 "fake_ip_address", string_success_callback_, error_callback_);
264 message_loop_.RunUntilIdle();
265 EXPECT_EQ(kResultSuccess, result_);
266
267 // Remove the wifi device. Call should fail with "device missing" error.
268 fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath);
269 message_loop_.RunUntilIdle();
270 network_device_handler_->GetWifiTDLSStatus(
271 "fake_ip_address", string_success_callback_, error_callback_);
272 message_loop_.RunUntilIdle();
273 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
274 }
275
212 TEST_F(NetworkDeviceHandlerTest, RequestRefreshIPConfigs) { 276 TEST_F(NetworkDeviceHandlerTest, RequestRefreshIPConfigs) {
213 network_device_handler_->RequestRefreshIPConfigs( 277 network_device_handler_->RequestRefreshIPConfigs(
214 kDefaultWifiDevicePath, success_callback_, error_callback_); 278 kDefaultWifiDevicePath, success_callback_, error_callback_);
215 message_loop_.RunUntilIdle(); 279 message_loop_.RunUntilIdle();
216 EXPECT_EQ(kResultSuccess, result_); 280 EXPECT_EQ(kResultSuccess, result_);
217 // TODO(stevenjb): Add test interface to ShillIPConfigClient and test 281 // TODO(stevenjb): Add test interface to ShillIPConfigClient and test
218 // refresh calls. 282 // refresh calls.
219 } 283 }
220 284
221 TEST_F(NetworkDeviceHandlerTest, SetCarrier) { 285 TEST_F(NetworkDeviceHandlerTest, SetCarrier) {
222 const char kCarrier[] = "carrier"; 286 const char kCarrier[] = "carrier";
223 287
224 // Test that the success callback gets called. 288 // Test that the success callback gets called.
225 network_device_handler_->SetCarrier( 289 network_device_handler_->SetCarrier(
226 kDefaultCellularDevicePath, kCarrier, success_callback_, error_callback_); 290 kDefaultCellularDevicePath, kCarrier, success_callback_, error_callback_);
227 message_loop_.RunUntilIdle(); 291 message_loop_.RunUntilIdle();
228 EXPECT_EQ(kResultSuccess, result_); 292 EXPECT_EQ(kResultSuccess, result_);
229 293
230 // Test that the shill error propagates to the error callback. 294 // Test that the shill error propagates to the error callback.
231 network_device_handler_->SetCarrier( 295 network_device_handler_->SetCarrier(
232 kUnknownCellularDevicePath, kCarrier, success_callback_, error_callback_); 296 kUnknownCellularDevicePath, kCarrier, success_callback_, error_callback_);
233 message_loop_.RunUntilIdle(); 297 message_loop_.RunUntilIdle();
234 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); 298 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
235 } 299 }
236 300
237 TEST_F(NetworkDeviceHandlerTest, RequirePin) { 301 TEST_F(NetworkDeviceHandlerTest, RequirePin) {
238 const char kPin[] = "1234"; 302 const char kPin[] = "1234";
239 303
240 // Test that the success callback gets called. 304 // Test that the success callback gets called.
241 network_device_handler_->RequirePin(kDefaultCellularDevicePath, 305 network_device_handler_->RequirePin(kDefaultCellularDevicePath,
242 true, 306 true,
243 kPin, 307 kPin,
244 success_callback_, 308 success_callback_,
245 error_callback_); 309 error_callback_);
246 message_loop_.RunUntilIdle(); 310 message_loop_.RunUntilIdle();
247 EXPECT_EQ(kResultSuccess, result_); 311 EXPECT_EQ(kResultSuccess, result_);
248 312
249 // Test that the shill error propagates to the error callback. 313 // Test that the shill error propagates to the error callback.
250 network_device_handler_->RequirePin(kUnknownCellularDevicePath, 314 network_device_handler_->RequirePin(kUnknownCellularDevicePath,
251 true, 315 true,
252 kPin, 316 kPin,
253 success_callback_, 317 success_callback_,
254 error_callback_); 318 error_callback_);
255 message_loop_.RunUntilIdle(); 319 message_loop_.RunUntilIdle();
256 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); 320 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
257 } 321 }
258 322
259 TEST_F(NetworkDeviceHandlerTest, EnterPin) { 323 TEST_F(NetworkDeviceHandlerTest, EnterPin) {
260 const char kPin[] = "1234"; 324 const char kPin[] = "1234";
261 325
262 // Test that the success callback gets called. 326 // Test that the success callback gets called.
263 network_device_handler_->EnterPin( 327 network_device_handler_->EnterPin(
264 kDefaultCellularDevicePath, kPin, success_callback_, error_callback_); 328 kDefaultCellularDevicePath, kPin, success_callback_, error_callback_);
265 message_loop_.RunUntilIdle(); 329 message_loop_.RunUntilIdle();
266 EXPECT_EQ(kResultSuccess, result_); 330 EXPECT_EQ(kResultSuccess, result_);
267 331
268 // Test that the shill error propagates to the error callback. 332 // Test that the shill error propagates to the error callback.
269 network_device_handler_->EnterPin( 333 network_device_handler_->EnterPin(
270 kUnknownCellularDevicePath, kPin, success_callback_, error_callback_); 334 kUnknownCellularDevicePath, kPin, success_callback_, error_callback_);
271 message_loop_.RunUntilIdle(); 335 message_loop_.RunUntilIdle();
272 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); 336 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
273 } 337 }
274 338
275 TEST_F(NetworkDeviceHandlerTest, UnblockPin) { 339 TEST_F(NetworkDeviceHandlerTest, UnblockPin) {
276 const char kPuk[] = "12345678"; 340 const char kPuk[] = "12345678";
277 const char kPin[] = "1234"; 341 const char kPin[] = "1234";
278 342
279 // Test that the success callback gets called. 343 // Test that the success callback gets called.
280 network_device_handler_->UnblockPin(kDefaultCellularDevicePath, 344 network_device_handler_->UnblockPin(kDefaultCellularDevicePath,
281 kPin, 345 kPin,
282 kPuk, 346 kPuk,
283 success_callback_, 347 success_callback_,
284 error_callback_); 348 error_callback_);
285 message_loop_.RunUntilIdle(); 349 message_loop_.RunUntilIdle();
286 EXPECT_EQ(kResultSuccess, result_); 350 EXPECT_EQ(kResultSuccess, result_);
287 351
288 // Test that the shill error propagates to the error callback. 352 // Test that the shill error propagates to the error callback.
289 network_device_handler_->UnblockPin(kUnknownCellularDevicePath, 353 network_device_handler_->UnblockPin(kUnknownCellularDevicePath,
290 kPin, 354 kPin,
291 kPuk, 355 kPuk,
292 success_callback_, 356 success_callback_,
293 error_callback_); 357 error_callback_);
294 message_loop_.RunUntilIdle(); 358 message_loop_.RunUntilIdle();
295 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); 359 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
296 } 360 }
297 361
298 TEST_F(NetworkDeviceHandlerTest, ChangePin) { 362 TEST_F(NetworkDeviceHandlerTest, ChangePin) {
299 const char kOldPin[] = "4321"; 363 const char kOldPin[] = "4321";
300 const char kNewPin[] = "1234"; 364 const char kNewPin[] = "1234";
301 365
302 // Test that the success callback gets called. 366 // Test that the success callback gets called.
303 network_device_handler_->ChangePin(kDefaultCellularDevicePath, 367 network_device_handler_->ChangePin(kDefaultCellularDevicePath,
304 kOldPin, 368 kOldPin,
305 kNewPin, 369 kNewPin,
306 success_callback_, 370 success_callback_,
307 error_callback_); 371 error_callback_);
308 message_loop_.RunUntilIdle(); 372 message_loop_.RunUntilIdle();
309 EXPECT_EQ(kResultSuccess, result_); 373 EXPECT_EQ(kResultSuccess, result_);
310 374
311 // Test that the shill error propagates to the error callback. 375 // Test that the shill error propagates to the error callback.
312 network_device_handler_->ChangePin(kUnknownCellularDevicePath, 376 network_device_handler_->ChangePin(kUnknownCellularDevicePath,
313 kOldPin, 377 kOldPin,
314 kNewPin, 378 kNewPin,
315 success_callback_, 379 success_callback_,
316 error_callback_); 380 error_callback_);
317 message_loop_.RunUntilIdle(); 381 message_loop_.RunUntilIdle();
318 EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_); 382 EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
319 } 383 }
320 384
321 } // namespace chromeos 385 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_device_handler_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698