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 using testing::ByRef; |
| 17 |
15 namespace chromeos { | 18 namespace chromeos { |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 const char kExampleDevicePath[] = "/foo/bar"; | 22 const char kExampleDevicePath[] = "/foo/bar"; |
20 | 23 |
21 // Expects the reader to have a string and a bool. | 24 // Expects the reader to have a string and a bool. |
22 void ExpectStringAndBoolArguments(const std::string& expected_string, | 25 void ExpectStringAndBoolArguments(const std::string& expected_string, |
23 bool expected_bool, | 26 bool expected_bool, |
24 dbus::MessageReader* reader) { | 27 dbus::MessageReader* reader) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const bool kValue = true; | 77 const bool kValue = true; |
75 // Create a signal. | 78 // Create a signal. |
76 dbus::Signal signal(flimflam::kFlimflamDeviceInterface, | 79 dbus::Signal signal(flimflam::kFlimflamDeviceInterface, |
77 flimflam::kMonitorPropertyChanged); | 80 flimflam::kMonitorPropertyChanged); |
78 dbus::MessageWriter writer(&signal); | 81 dbus::MessageWriter writer(&signal); |
79 writer.AppendString(flimflam::kCellularAllowRoamingProperty); | 82 writer.AppendString(flimflam::kCellularAllowRoamingProperty); |
80 writer.AppendVariantOfBool(kValue); | 83 writer.AppendVariantOfBool(kValue); |
81 | 84 |
82 // Set expectations. | 85 // Set expectations. |
83 const base::FundamentalValue value(kValue); | 86 const base::FundamentalValue value(kValue); |
84 client_->SetPropertyChangedHandler( | 87 MockPropertyChangeObserver observer; |
| 88 EXPECT_CALL(observer, |
| 89 OnPropertyChanged( |
| 90 flimflam::kCellularAllowRoamingProperty, |
| 91 ValueEq(ByRef(value)))).Times(1); |
| 92 |
| 93 // Add the observer |
| 94 client_->AddPropertyChangedObserver( |
85 dbus::ObjectPath(kExampleDevicePath), | 95 dbus::ObjectPath(kExampleDevicePath), |
86 base::Bind(&ExpectPropertyChanged, | 96 &observer); |
87 flimflam::kCellularAllowRoamingProperty, | 97 |
88 &value)); | |
89 // Run the signal callback. | 98 // Run the signal callback. |
90 SendPropertyChangedSignal(&signal); | 99 SendPropertyChangedSignal(&signal); |
91 | 100 |
92 // Reset the handler. | 101 // Remove the observer. |
93 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleDevicePath)); | 102 client_->RemovePropertyChangedObserver( |
| 103 dbus::ObjectPath(kExampleDevicePath), |
| 104 &observer); |
| 105 |
| 106 EXPECT_CALL(observer, |
| 107 OnPropertyChanged( |
| 108 flimflam::kCellularAllowRoamingProperty, |
| 109 ValueEq(ByRef(value)))).Times(0); |
| 110 |
| 111 // Run the signal callback again and make sure the observer isn't called. |
| 112 SendPropertyChangedSignal(&signal); |
94 } | 113 } |
95 | 114 |
96 TEST_F(ShillDeviceClientTest, GetProperties) { | 115 TEST_F(ShillDeviceClientTest, GetProperties) { |
97 const bool kValue = true; | 116 const bool kValue = true; |
98 // Create response. | 117 // Create response. |
99 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 118 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
100 dbus::MessageWriter writer(response.get()); | 119 dbus::MessageWriter writer(response.get()); |
101 dbus::MessageWriter array_writer(NULL); | 120 dbus::MessageWriter array_writer(NULL); |
102 writer.OpenArray("{sv}", &array_writer); | 121 writer.OpenArray("{sv}", &array_writer); |
103 dbus::MessageWriter entry_writer(NULL); | 122 dbus::MessageWriter entry_writer(NULL); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 189 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
171 | 190 |
172 // Set expectations. | 191 // Set expectations. |
173 const base::FundamentalValue value(kValue); | 192 const base::FundamentalValue value(kValue); |
174 PrepareForMethodCall(flimflam::kSetPropertyFunction, | 193 PrepareForMethodCall(flimflam::kSetPropertyFunction, |
175 base::Bind(&ExpectStringAndValueArguments, | 194 base::Bind(&ExpectStringAndValueArguments, |
176 flimflam::kCellularAllowRoamingProperty, | 195 flimflam::kCellularAllowRoamingProperty, |
177 &value), | 196 &value), |
178 response.get()); | 197 response.get()); |
179 // Call method. | 198 // Call method. |
| 199 MockClosure mock_closure; |
| 200 MockErrorCallback mock_error_callback; |
180 client_->SetProperty(dbus::ObjectPath(kExampleDevicePath), | 201 client_->SetProperty(dbus::ObjectPath(kExampleDevicePath), |
181 flimflam::kCellularAllowRoamingProperty, | 202 flimflam::kCellularAllowRoamingProperty, |
182 value, | 203 value, |
183 base::Bind(&ExpectNoResultValue)); | 204 mock_closure.GetCallback(), |
| 205 mock_error_callback.GetCallback()); |
| 206 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 207 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 208 |
184 // Run the message loop. | 209 // Run the message loop. |
185 message_loop_.RunAllPending(); | 210 message_loop_.RunAllPending(); |
186 } | 211 } |
187 | 212 |
188 TEST_F(ShillDeviceClientTest, ClearProperty) { | 213 TEST_F(ShillDeviceClientTest, ClearProperty) { |
189 // Create response. | 214 // Create response. |
190 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 215 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
191 | 216 |
192 // Set expectations. | 217 // Set expectations. |
193 PrepareForMethodCall(flimflam::kClearPropertyFunction, | 218 PrepareForMethodCall(flimflam::kClearPropertyFunction, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 271 |
247 // Set expectations. | 272 // Set expectations. |
248 MockClosure mock_closure; | 273 MockClosure mock_closure; |
249 MockErrorCallback mock_error_callback; | 274 MockErrorCallback mock_error_callback; |
250 PrepareForMethodCall(flimflam::kRequirePinFunction, | 275 PrepareForMethodCall(flimflam::kRequirePinFunction, |
251 base::Bind(&ExpectStringAndBoolArguments, | 276 base::Bind(&ExpectStringAndBoolArguments, |
252 kPin, | 277 kPin, |
253 kRequired), | 278 kRequired), |
254 response.get()); | 279 response.get()); |
255 EXPECT_CALL(mock_closure, Run()).Times(1); | 280 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 281 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
256 // Call method. | 282 // Call method. |
257 client_->RequirePin(dbus::ObjectPath(kExampleDevicePath), | 283 client_->RequirePin(dbus::ObjectPath(kExampleDevicePath), |
258 kPin, | 284 kPin, |
259 kRequired, | 285 kRequired, |
260 mock_closure.GetCallback(), | 286 mock_closure.GetCallback(), |
261 mock_error_callback.GetCallback()); | 287 mock_error_callback.GetCallback()); |
262 // Run the message loop. | 288 // Run the message loop. |
263 message_loop_.RunAllPending(); | 289 message_loop_.RunAllPending(); |
264 } | 290 } |
265 | 291 |
266 TEST_F(ShillDeviceClientTest, EnterPin) { | 292 TEST_F(ShillDeviceClientTest, EnterPin) { |
267 const char kPin[] = "123456"; | 293 const char kPin[] = "123456"; |
268 // Create response. | 294 // Create response. |
269 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 295 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
270 | 296 |
271 // Set expectations. | 297 // Set expectations. |
272 MockClosure mock_closure; | 298 MockClosure mock_closure; |
273 MockErrorCallback mock_error_callback; | 299 MockErrorCallback mock_error_callback; |
274 PrepareForMethodCall(flimflam::kEnterPinFunction, | 300 PrepareForMethodCall(flimflam::kEnterPinFunction, |
275 base::Bind(&ExpectStringArgument, | 301 base::Bind(&ExpectStringArgument, |
276 kPin), | 302 kPin), |
277 response.get()); | 303 response.get()); |
278 EXPECT_CALL(mock_closure, Run()).Times(1); | 304 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 305 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 306 |
279 // Call method. | 307 // Call method. |
280 client_->EnterPin(dbus::ObjectPath(kExampleDevicePath), | 308 client_->EnterPin(dbus::ObjectPath(kExampleDevicePath), |
281 kPin, | 309 kPin, |
282 mock_closure.GetCallback(), | 310 mock_closure.GetCallback(), |
283 mock_error_callback.GetCallback()); | 311 mock_error_callback.GetCallback()); |
284 // Run the message loop. | 312 // Run the message loop. |
285 message_loop_.RunAllPending(); | 313 message_loop_.RunAllPending(); |
286 } | 314 } |
287 | 315 |
288 TEST_F(ShillDeviceClientTest, UnblockPin) { | 316 TEST_F(ShillDeviceClientTest, UnblockPin) { |
289 const char kPuk[] = "987654"; | 317 const char kPuk[] = "987654"; |
290 const char kPin[] = "123456"; | 318 const char kPin[] = "123456"; |
291 // Create response. | 319 // Create response. |
292 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 320 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
293 | 321 |
294 // Set expectations. | 322 // Set expectations. |
295 MockClosure mock_closure; | 323 MockClosure mock_closure; |
296 MockErrorCallback mock_error_callback; | 324 MockErrorCallback mock_error_callback; |
297 PrepareForMethodCall(flimflam::kUnblockPinFunction, | 325 PrepareForMethodCall(flimflam::kUnblockPinFunction, |
298 base::Bind(&ExpectTwoStringArguments, kPuk, kPin), | 326 base::Bind(&ExpectTwoStringArguments, kPuk, kPin), |
299 response.get()); | 327 response.get()); |
300 EXPECT_CALL(mock_closure, Run()).Times(1); | 328 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 329 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 330 |
301 // Call method. | 331 // Call method. |
302 client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath), | 332 client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath), |
303 kPuk, | 333 kPuk, |
304 kPin, | 334 kPin, |
305 mock_closure.GetCallback(), | 335 mock_closure.GetCallback(), |
306 mock_error_callback.GetCallback()); | 336 mock_error_callback.GetCallback()); |
307 // Run the message loop. | 337 // Run the message loop. |
308 message_loop_.RunAllPending(); | 338 message_loop_.RunAllPending(); |
309 } | 339 } |
310 | 340 |
311 TEST_F(ShillDeviceClientTest, ChangePin) { | 341 TEST_F(ShillDeviceClientTest, ChangePin) { |
312 const char kOldPin[] = "123456"; | 342 const char kOldPin[] = "123456"; |
313 const char kNewPin[] = "234567"; | 343 const char kNewPin[] = "234567"; |
314 // Create response. | 344 // Create response. |
315 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 345 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
316 | 346 |
317 // Set expectations. | 347 // Set expectations. |
318 MockClosure mock_closure; | 348 MockClosure mock_closure; |
319 MockErrorCallback mock_error_callback; | 349 MockErrorCallback mock_error_callback; |
320 PrepareForMethodCall(flimflam::kChangePinFunction, | 350 PrepareForMethodCall(flimflam::kChangePinFunction, |
321 base::Bind(&ExpectTwoStringArguments, | 351 base::Bind(&ExpectTwoStringArguments, |
322 kOldPin, | 352 kOldPin, |
323 kNewPin), | 353 kNewPin), |
324 response.get()); | 354 response.get()); |
325 EXPECT_CALL(mock_closure, Run()).Times(1); | 355 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 356 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 357 |
326 // Call method. | 358 // Call method. |
327 client_->ChangePin(dbus::ObjectPath(kExampleDevicePath), | 359 client_->ChangePin(dbus::ObjectPath(kExampleDevicePath), |
328 kOldPin, | 360 kOldPin, |
329 kNewPin, | 361 kNewPin, |
330 mock_closure.GetCallback(), | 362 mock_closure.GetCallback(), |
331 mock_error_callback.GetCallback()); | 363 mock_error_callback.GetCallback()); |
332 // Run the message loop. | 364 // Run the message loop. |
333 message_loop_.RunAllPending(); | 365 message_loop_.RunAllPending(); |
334 } | 366 } |
335 | 367 |
336 TEST_F(ShillDeviceClientTest, Register) { | 368 TEST_F(ShillDeviceClientTest, Register) { |
337 const char kNetworkId[] = "networkid"; | 369 const char kNetworkId[] = "networkid"; |
338 // Create response. | 370 // Create response. |
339 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 371 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
340 | 372 |
341 // Set expectations. | 373 // Set expectations. |
342 MockClosure mock_closure; | 374 MockClosure mock_closure; |
343 MockErrorCallback mock_error_callback; | 375 MockErrorCallback mock_error_callback; |
344 PrepareForMethodCall(flimflam::kRegisterFunction, | 376 PrepareForMethodCall(flimflam::kRegisterFunction, |
345 base::Bind(&ExpectStringArgument, kNetworkId), | 377 base::Bind(&ExpectStringArgument, kNetworkId), |
346 response.get()); | 378 response.get()); |
347 EXPECT_CALL(mock_closure, Run()).Times(1); | 379 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 380 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 381 |
348 // Call method. | 382 // Call method. |
349 client_->Register(dbus::ObjectPath(kExampleDevicePath), | 383 client_->Register(dbus::ObjectPath(kExampleDevicePath), |
350 kNetworkId, | 384 kNetworkId, |
351 mock_closure.GetCallback(), | 385 mock_closure.GetCallback(), |
352 mock_error_callback.GetCallback()); | 386 mock_error_callback.GetCallback()); |
353 // Run the message loop. | 387 // Run the message loop. |
354 message_loop_.RunAllPending(); | 388 message_loop_.RunAllPending(); |
355 } | 389 } |
356 | 390 |
357 } // namespace chromeos | 391 } // namespace chromeos |
OLD | NEW |