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/values.h" | 6 #include "base/values.h" |
7 #include "chromeos/dbus/shill_client_unittest_base.h" | 7 #include "chromeos/dbus/shill_client_unittest_base.h" |
8 #include "chromeos/dbus/shill_device_client.h" | 8 #include "chromeos/dbus/shill_device_client.h" |
9 #include "dbus/message.h" | 9 #include "dbus/message.h" |
10 #include "dbus/object_path.h" | 10 #include "dbus/object_path.h" |
11 #include "dbus/values_util.h" | 11 #include "dbus/values_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
14 | 14 |
| 15 using testing::_; |
| 16 |
15 namespace chromeos { | 17 namespace chromeos { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 const char kExampleDevicePath[] = "/foo/bar"; | 21 const char kExampleDevicePath[] = "/foo/bar"; |
20 | 22 |
21 // Expects the reader to have a string and a bool. | 23 // Expects the reader to have a string and a bool. |
22 void ExpectStringAndBoolArguments(const std::string& expected_string, | 24 void ExpectStringAndBoolArguments(const std::string& expected_string, |
23 bool expected_bool, | 25 bool expected_bool, |
24 dbus::MessageReader* reader) { | 26 dbus::MessageReader* reader) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 172 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
171 | 173 |
172 // Set expectations. | 174 // Set expectations. |
173 const base::FundamentalValue value(kValue); | 175 const base::FundamentalValue value(kValue); |
174 PrepareForMethodCall(flimflam::kSetPropertyFunction, | 176 PrepareForMethodCall(flimflam::kSetPropertyFunction, |
175 base::Bind(&ExpectStringAndValueArguments, | 177 base::Bind(&ExpectStringAndValueArguments, |
176 flimflam::kCellularAllowRoamingProperty, | 178 flimflam::kCellularAllowRoamingProperty, |
177 &value), | 179 &value), |
178 response.get()); | 180 response.get()); |
179 // Call method. | 181 // Call method. |
| 182 MockClosure mock_closure; |
| 183 MockErrorCallback mock_error_callback; |
180 client_->SetProperty(dbus::ObjectPath(kExampleDevicePath), | 184 client_->SetProperty(dbus::ObjectPath(kExampleDevicePath), |
181 flimflam::kCellularAllowRoamingProperty, | 185 flimflam::kCellularAllowRoamingProperty, |
182 value, | 186 value, |
183 base::Bind(&ExpectNoResultValue)); | 187 mock_closure.GetCallback(), |
| 188 mock_error_callback.GetCallback()); |
| 189 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 190 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 191 |
184 // Run the message loop. | 192 // Run the message loop. |
185 message_loop_.RunAllPending(); | 193 message_loop_.RunAllPending(); |
186 } | 194 } |
187 | 195 |
188 TEST_F(ShillDeviceClientTest, ClearProperty) { | 196 TEST_F(ShillDeviceClientTest, ClearProperty) { |
189 // Create response. | 197 // Create response. |
190 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 198 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
191 | 199 |
192 // Set expectations. | 200 // Set expectations. |
193 PrepareForMethodCall(flimflam::kClearPropertyFunction, | 201 PrepareForMethodCall(flimflam::kClearPropertyFunction, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 254 |
247 // Set expectations. | 255 // Set expectations. |
248 MockClosure mock_closure; | 256 MockClosure mock_closure; |
249 MockErrorCallback mock_error_callback; | 257 MockErrorCallback mock_error_callback; |
250 PrepareForMethodCall(flimflam::kRequirePinFunction, | 258 PrepareForMethodCall(flimflam::kRequirePinFunction, |
251 base::Bind(&ExpectStringAndBoolArguments, | 259 base::Bind(&ExpectStringAndBoolArguments, |
252 kPin, | 260 kPin, |
253 kRequired), | 261 kRequired), |
254 response.get()); | 262 response.get()); |
255 EXPECT_CALL(mock_closure, Run()).Times(1); | 263 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 264 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
256 // Call method. | 265 // Call method. |
257 client_->RequirePin(dbus::ObjectPath(kExampleDevicePath), | 266 client_->RequirePin(dbus::ObjectPath(kExampleDevicePath), |
258 kPin, | 267 kPin, |
259 kRequired, | 268 kRequired, |
260 mock_closure.GetCallback(), | 269 mock_closure.GetCallback(), |
261 mock_error_callback.GetCallback()); | 270 mock_error_callback.GetCallback()); |
262 // Run the message loop. | 271 // Run the message loop. |
263 message_loop_.RunAllPending(); | 272 message_loop_.RunAllPending(); |
264 } | 273 } |
265 | 274 |
266 TEST_F(ShillDeviceClientTest, EnterPin) { | 275 TEST_F(ShillDeviceClientTest, EnterPin) { |
267 const char kPin[] = "123456"; | 276 const char kPin[] = "123456"; |
268 // Create response. | 277 // Create response. |
269 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 278 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
270 | 279 |
271 // Set expectations. | 280 // Set expectations. |
272 MockClosure mock_closure; | 281 MockClosure mock_closure; |
273 MockErrorCallback mock_error_callback; | 282 MockErrorCallback mock_error_callback; |
274 PrepareForMethodCall(flimflam::kEnterPinFunction, | 283 PrepareForMethodCall(flimflam::kEnterPinFunction, |
275 base::Bind(&ExpectStringArgument, | 284 base::Bind(&ExpectStringArgument, |
276 kPin), | 285 kPin), |
277 response.get()); | 286 response.get()); |
278 EXPECT_CALL(mock_closure, Run()).Times(1); | 287 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 288 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 289 |
279 // Call method. | 290 // Call method. |
280 client_->EnterPin(dbus::ObjectPath(kExampleDevicePath), | 291 client_->EnterPin(dbus::ObjectPath(kExampleDevicePath), |
281 kPin, | 292 kPin, |
282 mock_closure.GetCallback(), | 293 mock_closure.GetCallback(), |
283 mock_error_callback.GetCallback()); | 294 mock_error_callback.GetCallback()); |
284 // Run the message loop. | 295 // Run the message loop. |
285 message_loop_.RunAllPending(); | 296 message_loop_.RunAllPending(); |
286 } | 297 } |
287 | 298 |
288 TEST_F(ShillDeviceClientTest, UnblockPin) { | 299 TEST_F(ShillDeviceClientTest, UnblockPin) { |
289 const char kPuk[] = "987654"; | 300 const char kPuk[] = "987654"; |
290 const char kPin[] = "123456"; | 301 const char kPin[] = "123456"; |
291 // Create response. | 302 // Create response. |
292 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 303 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
293 | 304 |
294 // Set expectations. | 305 // Set expectations. |
295 MockClosure mock_closure; | 306 MockClosure mock_closure; |
296 MockErrorCallback mock_error_callback; | 307 MockErrorCallback mock_error_callback; |
297 PrepareForMethodCall(flimflam::kUnblockPinFunction, | 308 PrepareForMethodCall(flimflam::kUnblockPinFunction, |
298 base::Bind(&ExpectTwoStringArguments, kPuk, kPin), | 309 base::Bind(&ExpectTwoStringArguments, kPuk, kPin), |
299 response.get()); | 310 response.get()); |
300 EXPECT_CALL(mock_closure, Run()).Times(1); | 311 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 312 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 313 |
301 // Call method. | 314 // Call method. |
302 client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath), | 315 client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath), |
303 kPuk, | 316 kPuk, |
304 kPin, | 317 kPin, |
305 mock_closure.GetCallback(), | 318 mock_closure.GetCallback(), |
306 mock_error_callback.GetCallback()); | 319 mock_error_callback.GetCallback()); |
307 // Run the message loop. | 320 // Run the message loop. |
308 message_loop_.RunAllPending(); | 321 message_loop_.RunAllPending(); |
309 } | 322 } |
310 | 323 |
311 TEST_F(ShillDeviceClientTest, ChangePin) { | 324 TEST_F(ShillDeviceClientTest, ChangePin) { |
312 const char kOldPin[] = "123456"; | 325 const char kOldPin[] = "123456"; |
313 const char kNewPin[] = "234567"; | 326 const char kNewPin[] = "234567"; |
314 // Create response. | 327 // Create response. |
315 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 328 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
316 | 329 |
317 // Set expectations. | 330 // Set expectations. |
318 MockClosure mock_closure; | 331 MockClosure mock_closure; |
319 MockErrorCallback mock_error_callback; | 332 MockErrorCallback mock_error_callback; |
320 PrepareForMethodCall(flimflam::kChangePinFunction, | 333 PrepareForMethodCall(flimflam::kChangePinFunction, |
321 base::Bind(&ExpectTwoStringArguments, | 334 base::Bind(&ExpectTwoStringArguments, |
322 kOldPin, | 335 kOldPin, |
323 kNewPin), | 336 kNewPin), |
324 response.get()); | 337 response.get()); |
325 EXPECT_CALL(mock_closure, Run()).Times(1); | 338 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 339 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 340 |
326 // Call method. | 341 // Call method. |
327 client_->ChangePin(dbus::ObjectPath(kExampleDevicePath), | 342 client_->ChangePin(dbus::ObjectPath(kExampleDevicePath), |
328 kOldPin, | 343 kOldPin, |
329 kNewPin, | 344 kNewPin, |
330 mock_closure.GetCallback(), | 345 mock_closure.GetCallback(), |
331 mock_error_callback.GetCallback()); | 346 mock_error_callback.GetCallback()); |
332 // Run the message loop. | 347 // Run the message loop. |
333 message_loop_.RunAllPending(); | 348 message_loop_.RunAllPending(); |
334 } | 349 } |
335 | 350 |
336 TEST_F(ShillDeviceClientTest, Register) { | 351 TEST_F(ShillDeviceClientTest, Register) { |
337 const char kNetworkId[] = "networkid"; | 352 const char kNetworkId[] = "networkid"; |
338 // Create response. | 353 // Create response. |
339 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 354 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
340 | 355 |
341 // Set expectations. | 356 // Set expectations. |
342 MockClosure mock_closure; | 357 MockClosure mock_closure; |
343 MockErrorCallback mock_error_callback; | 358 MockErrorCallback mock_error_callback; |
344 PrepareForMethodCall(flimflam::kRegisterFunction, | 359 PrepareForMethodCall(flimflam::kRegisterFunction, |
345 base::Bind(&ExpectStringArgument, kNetworkId), | 360 base::Bind(&ExpectStringArgument, kNetworkId), |
346 response.get()); | 361 response.get()); |
347 EXPECT_CALL(mock_closure, Run()).Times(1); | 362 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 363 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 364 |
348 // Call method. | 365 // Call method. |
349 client_->Register(dbus::ObjectPath(kExampleDevicePath), | 366 client_->Register(dbus::ObjectPath(kExampleDevicePath), |
350 kNetworkId, | 367 kNetworkId, |
351 mock_closure.GetCallback(), | 368 mock_closure.GetCallback(), |
352 mock_error_callback.GetCallback()); | 369 mock_error_callback.GetCallback()); |
353 // Run the message loop. | 370 // Run the message loop. |
354 message_loop_.RunAllPending(); | 371 message_loop_.RunAllPending(); |
355 } | 372 } |
356 | 373 |
357 TEST_F(ShillDeviceClientTest, SetCarrier) { | 374 TEST_F(ShillDeviceClientTest, SetCarrier) { |
(...skipping 11 matching lines...) Expand all Loading... |
369 // Call method. | 386 // Call method. |
370 client_->SetCarrier(dbus::ObjectPath(kExampleDevicePath), | 387 client_->SetCarrier(dbus::ObjectPath(kExampleDevicePath), |
371 kCarrier, | 388 kCarrier, |
372 mock_closure.GetCallback(), | 389 mock_closure.GetCallback(), |
373 mock_error_callback.GetCallback()); | 390 mock_error_callback.GetCallback()); |
374 // Run the message loop. | 391 // Run the message loop. |
375 message_loop_.RunAllPending(); | 392 message_loop_.RunAllPending(); |
376 } | 393 } |
377 | 394 |
378 } // namespace chromeos | 395 } // namespace chromeos |
OLD | NEW |