OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chromeos/dbus/mock_bluetooth_adapter_client.h" | |
6 #include "chromeos/dbus/mock_bluetooth_manager_client.h" | |
7 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
8 #include "dbus/object_path.h" | |
9 #include "device/bluetooth/bluetooth_adapter.h" | |
10 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | |
11 #include "device/bluetooth/bluetooth_adapter_factory.h" | |
12 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 using device::BluetoothAdapter; | |
16 using device::BluetoothAdapterFactory; | |
17 using device::MockBluetoothAdapter; | |
18 using ::testing::_; | |
19 using ::testing::InSequence; | |
20 using ::testing::Return; | |
21 using ::testing::SaveArg; | |
22 | |
23 namespace chromeos { | |
24 | |
25 class BluetoothAdapterChromeOSTest : public testing::Test { | |
26 public: | |
27 virtual void SetUp() { | |
28 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | |
29 | |
30 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | |
31 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | |
32 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | |
33 | |
34 mock_manager_client_ = | |
35 mock_dbus_thread_manager->mock_bluetooth_manager_client(); | |
36 mock_adapter_client_ = | |
37 mock_dbus_thread_manager->mock_bluetooth_adapter_client(); | |
38 | |
39 callback_called_ = false; | |
40 error_callback_called_ = false; | |
41 } | |
42 | |
43 virtual void TearDown() { | |
44 adapter_ = NULL; | |
45 DBusThreadManager::Shutdown(); | |
46 } | |
47 | |
48 void Callback() { | |
49 callback_called_ = true; | |
50 } | |
51 | |
52 void ErrorCallback() { | |
53 error_callback_called_ = true; | |
54 } | |
55 | |
56 void SetAdapter(scoped_refptr<device::BluetoothAdapter> adapter) { | |
57 adapter_ = adapter; | |
58 } | |
59 | |
60 protected: | |
61 MockBluetoothManagerClient* mock_manager_client_; | |
62 MockBluetoothAdapterClient* mock_adapter_client_; | |
63 | |
64 bool callback_called_; | |
65 bool error_callback_called_; | |
66 | |
67 scoped_refptr<BluetoothAdapter> adapter_; | |
68 }; | |
69 | |
70 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterNotPresent) { | |
71 // Create the default adapter instance; | |
72 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
73 // a callback to obtain the adapter path. | |
74 BluetoothManagerClient::AdapterCallback adapter_callback; | |
75 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
76 .WillOnce(SaveArg<0>(&adapter_callback)); | |
77 | |
78 BluetoothAdapterFactory::GetAdapter( | |
79 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
80 base::Unretained(this))); | |
81 ASSERT_TRUE(adapter_ != NULL); | |
82 | |
83 // Call the adapter callback; make out it failed. | |
84 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | |
85 MockBluetoothAdapter::Observer adapter_observer; | |
86 adapter_->AddObserver(&adapter_observer); | |
87 | |
88 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) | |
89 .Times(0); | |
90 | |
91 adapter_callback.Run(dbus::ObjectPath(""), false); | |
92 | |
93 // Adapter should not be present. | |
94 EXPECT_FALSE(adapter_->IsPresent()); | |
95 } | |
96 | |
97 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithAddress) { | |
98 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
99 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
100 | |
101 // Create the default adapter instance; | |
102 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
103 // a callback to obtain the adapter path. | |
104 BluetoothManagerClient::AdapterCallback adapter_callback; | |
105 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
106 .WillOnce(SaveArg<0>(&adapter_callback)); | |
107 | |
108 BluetoothAdapterFactory::GetAdapter( | |
109 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
110 base::Unretained(this))); | |
111 | |
112 // Call the adapter callback; | |
113 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
114 // the property set. | |
115 MockBluetoothAdapterClient::Properties adapter_properties; | |
116 adapter_properties.address.ReplaceValue(adapter_address); | |
117 | |
118 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
119 .WillRepeatedly(Return(&adapter_properties)); | |
120 | |
121 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to | |
122 // indicate the adapter is now present. | |
123 MockBluetoothAdapter::Observer adapter_observer; | |
124 adapter_->AddObserver(&adapter_observer); | |
125 | |
126 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
127 .Times(1); | |
128 | |
129 adapter_callback.Run(adapter_path, true); | |
130 | |
131 // Adapter should be present with the given address. | |
132 EXPECT_TRUE(adapter_->IsPresent()); | |
133 EXPECT_EQ(adapter_address, adapter_->GetAddress()); | |
134 } | |
135 | |
136 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithoutAddress) { | |
137 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
138 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
139 | |
140 // Create the default adapter instance; | |
141 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
142 // a callback to obtain the adapter path. | |
143 BluetoothManagerClient::AdapterCallback adapter_callback; | |
144 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
145 .WillOnce(SaveArg<0>(&adapter_callback)); | |
146 | |
147 BluetoothAdapterFactory::GetAdapter( | |
148 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
149 base::Unretained(this))); | |
150 | |
151 // Call the adapter callback; | |
152 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
153 // the property set. | |
154 MockBluetoothAdapterClient::Properties adapter_properties; | |
155 | |
156 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
157 .WillRepeatedly(Return(&adapter_properties)); | |
158 | |
159 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | |
160 // yet. | |
161 MockBluetoothAdapter::Observer adapter_observer; | |
162 adapter_->AddObserver(&adapter_observer); | |
163 | |
164 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) | |
165 .Times(0); | |
166 | |
167 adapter_callback.Run(adapter_path, true); | |
168 | |
169 // Adapter should not be present yet. | |
170 EXPECT_FALSE(adapter_->IsPresent()); | |
171 | |
172 // Tell the adapter the address now; | |
173 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | |
174 adapter_properties.address.ReplaceValue(adapter_address); | |
175 | |
176 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
177 .Times(1); | |
178 | |
179 BluetoothAdapterChromeOS* adapter_chromeos = | |
180 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
181 | |
182 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
183 ->AdapterPropertyChanged(adapter_path, | |
184 adapter_properties.address.name()); | |
185 | |
186 // Adapter should be present with the given address. | |
187 EXPECT_TRUE(adapter_->IsPresent()); | |
188 EXPECT_EQ(adapter_address, adapter_->GetAddress()); | |
189 } | |
190 | |
191 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterBecomesPresentWithAddress) { | |
192 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
193 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
194 | |
195 // Create the default adapter instance; | |
196 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
197 // a callback to obtain the adapter path. | |
198 BluetoothManagerClient::AdapterCallback adapter_callback; | |
199 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
200 .WillOnce(SaveArg<0>(&adapter_callback)); | |
201 | |
202 BluetoothAdapterFactory::GetAdapter( | |
203 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
204 base::Unretained(this))); | |
205 | |
206 // Call the adapter callback; make out it failed. | |
207 adapter_callback.Run(dbus::ObjectPath(""), false); | |
208 | |
209 // Tell the adapter the default adapter changed; | |
210 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
211 // the property set. | |
212 MockBluetoothAdapterClient::Properties adapter_properties; | |
213 adapter_properties.address.ReplaceValue(adapter_address); | |
214 | |
215 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
216 .WillRepeatedly(Return(&adapter_properties)); | |
217 | |
218 // BluetoothAdapter::Observer::AdapterPresentChanged must be called. | |
219 MockBluetoothAdapter::Observer adapter_observer; | |
220 adapter_->AddObserver(&adapter_observer); | |
221 | |
222 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
223 .Times(1); | |
224 | |
225 BluetoothAdapterChromeOS* adapter_chromeos = | |
226 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
227 | |
228 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
229 ->DefaultAdapterChanged(adapter_path); | |
230 | |
231 // Adapter should be present with the new address. | |
232 EXPECT_TRUE(adapter_->IsPresent()); | |
233 EXPECT_EQ(adapter_address, adapter_->GetAddress()); | |
234 } | |
235 | |
236 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterReplacedWithAddress) { | |
237 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
238 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
239 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
240 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
241 | |
242 // Create the default adapter instance; | |
243 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
244 // a callback to obtain the adapter path. | |
245 BluetoothManagerClient::AdapterCallback adapter_callback; | |
246 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
247 .WillOnce(SaveArg<0>(&adapter_callback)); | |
248 | |
249 BluetoothAdapterFactory::GetAdapter( | |
250 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
251 base::Unretained(this))); | |
252 | |
253 // Call the adapter callback; | |
254 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
255 // the property set. | |
256 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
257 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
258 | |
259 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
260 .WillRepeatedly(Return(&initial_adapter_properties)); | |
261 | |
262 adapter_callback.Run(initial_adapter_path, true); | |
263 | |
264 // Tell the adapter the default adapter changed; | |
265 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
266 // the property set. | |
267 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
268 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
269 | |
270 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
271 .WillRepeatedly(Return(&new_adapter_properties)); | |
272 | |
273 // BluetoothAdapter::Observer::AdapterPresentChanged must be called once | |
274 // with false to indicate the old adapter being removed and once with true | |
275 // to announce the new adapter. | |
276 MockBluetoothAdapter::Observer adapter_observer; | |
277 adapter_->AddObserver(&adapter_observer); | |
278 | |
279 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
280 .Times(1); | |
281 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
282 .Times(1); | |
283 | |
284 BluetoothAdapterChromeOS* adapter_chromeos = | |
285 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
286 | |
287 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
288 ->DefaultAdapterChanged(new_adapter_path); | |
289 | |
290 // Adapter should be present with the new address. | |
291 EXPECT_TRUE(adapter_->IsPresent()); | |
292 EXPECT_EQ(new_adapter_address, adapter_->GetAddress()); | |
293 } | |
294 | |
295 TEST_F(BluetoothAdapterChromeOSTest, | |
296 DefaultAdapterBecomesPresentWithoutAddress) { | |
297 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
298 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
299 | |
300 // Create the default adapter instance; | |
301 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
302 // a callback to obtain the adapter path. | |
303 BluetoothManagerClient::AdapterCallback adapter_callback; | |
304 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
305 .WillOnce(SaveArg<0>(&adapter_callback)); | |
306 | |
307 BluetoothAdapterFactory::GetAdapter( | |
308 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
309 base::Unretained(this))); | |
310 | |
311 // Call the adapter callback; make out it failed. | |
312 adapter_callback.Run(dbus::ObjectPath(""), false); | |
313 | |
314 // Tell the adapter the default adapter changed; | |
315 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
316 // the property set. | |
317 MockBluetoothAdapterClient::Properties adapter_properties; | |
318 | |
319 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
320 .WillRepeatedly(Return(&adapter_properties)); | |
321 | |
322 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | |
323 MockBluetoothAdapter::Observer adapter_observer; | |
324 adapter_->AddObserver(&adapter_observer); | |
325 | |
326 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) | |
327 .Times(0); | |
328 | |
329 BluetoothAdapterChromeOS* adapter_chromeos = | |
330 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
331 | |
332 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
333 ->DefaultAdapterChanged(adapter_path); | |
334 | |
335 // Adapter should not be present yet. | |
336 EXPECT_FALSE(adapter_->IsPresent()); | |
337 | |
338 // Tell the adapter the address now; | |
339 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | |
340 adapter_properties.address.ReplaceValue(adapter_address); | |
341 | |
342 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
343 .Times(1); | |
344 | |
345 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
346 ->AdapterPropertyChanged(adapter_path, | |
347 adapter_properties.address.name()); | |
348 | |
349 // Adapter should be present with the new address. | |
350 EXPECT_TRUE(adapter_->IsPresent()); | |
351 EXPECT_EQ(adapter_address, adapter_->GetAddress()); | |
352 } | |
353 | |
354 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterReplacedWithoutAddress) { | |
355 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
356 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
357 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
358 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
359 | |
360 // Create the default adapter instance; | |
361 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
362 // a callback to obtain the adapter path. | |
363 BluetoothManagerClient::AdapterCallback adapter_callback; | |
364 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
365 .WillOnce(SaveArg<0>(&adapter_callback)); | |
366 | |
367 BluetoothAdapterFactory::GetAdapter( | |
368 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
369 base::Unretained(this))); | |
370 | |
371 // Call the adapter callback; | |
372 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
373 // the property set. | |
374 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
375 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
376 | |
377 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
378 .WillRepeatedly(Return(&initial_adapter_properties)); | |
379 | |
380 adapter_callback.Run(initial_adapter_path, true); | |
381 | |
382 // Tell the adapter the default adapter changed; | |
383 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
384 // the property set. | |
385 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
386 | |
387 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
388 .WillRepeatedly(Return(&new_adapter_properties)); | |
389 | |
390 // BluetoothAdapter::Observer::AdapterPresentChanged must be called to | |
391 // indicate the adapter has gone away. | |
392 MockBluetoothAdapter::Observer adapter_observer; | |
393 adapter_->AddObserver(&adapter_observer); | |
394 | |
395 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
396 .Times(1); | |
397 | |
398 BluetoothAdapterChromeOS* adapter_chromeos = | |
399 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
400 | |
401 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
402 ->DefaultAdapterChanged(new_adapter_path); | |
403 | |
404 // Adapter should be now marked not present. | |
405 EXPECT_FALSE(adapter_->IsPresent()); | |
406 | |
407 // Tell the adapter the address now; | |
408 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | |
409 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
410 | |
411 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
412 .Times(1); | |
413 | |
414 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
415 ->AdapterPropertyChanged(new_adapter_path, | |
416 new_adapter_properties.address.name()); | |
417 | |
418 // Adapter should be present with the new address. | |
419 EXPECT_TRUE(adapter_->IsPresent()); | |
420 EXPECT_EQ(new_adapter_address, adapter_->GetAddress()); | |
421 } | |
422 | |
423 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterRemoved) { | |
424 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
425 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
426 | |
427 // Create the default adapter instance; | |
428 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
429 // a callback to obtain the adapter path. | |
430 BluetoothManagerClient::AdapterCallback adapter_callback; | |
431 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
432 .WillOnce(SaveArg<0>(&adapter_callback)); | |
433 | |
434 BluetoothAdapterFactory::GetAdapter( | |
435 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
436 base::Unretained(this))); | |
437 | |
438 // Call the adapter callback; | |
439 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
440 // the property set. | |
441 MockBluetoothAdapterClient::Properties adapter_properties; | |
442 adapter_properties.address.ReplaceValue(adapter_address); | |
443 | |
444 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
445 .WillRepeatedly(Return(&adapter_properties)); | |
446 | |
447 adapter_callback.Run(adapter_path, true); | |
448 | |
449 // Report that the adapter has been removed; | |
450 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to | |
451 // indicate the adapter is no longer present. | |
452 MockBluetoothAdapter::Observer adapter_observer; | |
453 adapter_->AddObserver(&adapter_observer); | |
454 | |
455 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
456 .Times(1); | |
457 | |
458 BluetoothAdapterChromeOS* adapter_chromeos = | |
459 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
460 | |
461 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
462 ->AdapterRemoved(adapter_path); | |
463 | |
464 // Adapter should be no longer present. | |
465 EXPECT_FALSE(adapter_->IsPresent()); | |
466 } | |
467 | |
468 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithoutAddressRemoved) { | |
469 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
470 | |
471 // Create the default adapter instance; | |
472 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
473 // a callback to obtain the adapter path. | |
474 BluetoothManagerClient::AdapterCallback adapter_callback; | |
475 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
476 .WillOnce(SaveArg<0>(&adapter_callback)); | |
477 | |
478 BluetoothAdapterFactory::GetAdapter( | |
479 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
480 base::Unretained(this))); | |
481 | |
482 // Call the adapter callback; | |
483 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
484 // the property set. | |
485 MockBluetoothAdapterClient::Properties adapter_properties; | |
486 | |
487 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
488 .WillRepeatedly(Return(&adapter_properties)); | |
489 | |
490 adapter_callback.Run(adapter_path, true); | |
491 | |
492 // Report that the adapter has been removed; | |
493 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | |
494 // since we never should have announced it in the first place. | |
495 MockBluetoothAdapter::Observer adapter_observer; | |
496 adapter_->AddObserver(&adapter_observer); | |
497 | |
498 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) | |
499 .Times(0); | |
500 | |
501 BluetoothAdapterChromeOS* adapter_chromeos = | |
502 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
503 | |
504 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
505 ->AdapterRemoved(adapter_path); | |
506 | |
507 // Adapter should be still no longer present. | |
508 EXPECT_FALSE(adapter_->IsPresent()); | |
509 } | |
510 | |
511 TEST_F(BluetoothAdapterChromeOSTest, | |
512 DefaultAdapterPoweredPropertyInitiallyFalse) { | |
513 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
514 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
515 | |
516 // Create the default adapter instance; | |
517 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
518 // a callback to obtain the adapter path. | |
519 BluetoothManagerClient::AdapterCallback adapter_callback; | |
520 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
521 .WillOnce(SaveArg<0>(&adapter_callback)); | |
522 | |
523 BluetoothAdapterFactory::GetAdapter( | |
524 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
525 base::Unretained(this))); | |
526 | |
527 // Call the adapter callback; | |
528 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
529 // the property set. | |
530 MockBluetoothAdapterClient::Properties adapter_properties; | |
531 adapter_properties.address.ReplaceValue(adapter_address); | |
532 adapter_properties.powered.ReplaceValue(false); | |
533 | |
534 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
535 .WillRepeatedly(Return(&adapter_properties)); | |
536 | |
537 adapter_callback.Run(adapter_path, true); | |
538 | |
539 // Adapter should have the correct property value. | |
540 EXPECT_FALSE(adapter_->IsPowered()); | |
541 } | |
542 | |
543 TEST_F(BluetoothAdapterChromeOSTest, | |
544 DefaultAdapterPoweredPropertyInitiallyTrue) { | |
545 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
546 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
547 | |
548 // Create the default adapter instance; | |
549 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
550 // a callback to obtain the adapter path. | |
551 BluetoothManagerClient::AdapterCallback adapter_callback; | |
552 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
553 .WillOnce(SaveArg<0>(&adapter_callback)); | |
554 | |
555 BluetoothAdapterFactory::GetAdapter( | |
556 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
557 base::Unretained(this))); | |
558 | |
559 // Call the adapter callback; | |
560 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
561 // the property set. | |
562 MockBluetoothAdapterClient::Properties adapter_properties; | |
563 adapter_properties.address.ReplaceValue(adapter_address); | |
564 adapter_properties.powered.ReplaceValue(true); | |
565 | |
566 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
567 .WillRepeatedly(Return(&adapter_properties)); | |
568 | |
569 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
570 MockBluetoothAdapter::Observer adapter_observer; | |
571 adapter_->AddObserver(&adapter_observer); | |
572 | |
573 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
574 .Times(1); | |
575 | |
576 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) | |
577 .Times(1); | |
578 | |
579 adapter_callback.Run(adapter_path, true); | |
580 | |
581 // Adapter should have the correct property value. | |
582 EXPECT_TRUE(adapter_->IsPowered()); | |
583 } | |
584 | |
585 TEST_F(BluetoothAdapterChromeOSTest, | |
586 DefaultAdapterPoweredPropertyInitiallyTrueWithoutAddress) { | |
587 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
588 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
589 | |
590 // Create the default adapter instance; | |
591 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
592 // a callback to obtain the adapter path. | |
593 BluetoothManagerClient::AdapterCallback adapter_callback; | |
594 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
595 .WillOnce(SaveArg<0>(&adapter_callback)); | |
596 | |
597 BluetoothAdapterFactory::GetAdapter( | |
598 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
599 base::Unretained(this))); | |
600 | |
601 // Call the adapter callback; | |
602 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
603 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged | |
604 // should not yet be called. | |
605 MockBluetoothAdapterClient::Properties adapter_properties; | |
606 adapter_properties.powered.ReplaceValue(true); | |
607 | |
608 MockBluetoothAdapter::Observer adapter_observer; | |
609 adapter_->AddObserver(&adapter_observer); | |
610 | |
611 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
612 .WillRepeatedly(Return(&adapter_properties)); | |
613 | |
614 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) | |
615 .Times(0); | |
616 | |
617 adapter_callback.Run(adapter_path, true); | |
618 | |
619 // Adapter should not yet have the property value. | |
620 EXPECT_FALSE(adapter_->IsPowered()); | |
621 | |
622 // Tell the adapter the address now, | |
623 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
624 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. | |
625 adapter_properties.address.ReplaceValue(adapter_address); | |
626 | |
627 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
628 .Times(1); | |
629 | |
630 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) | |
631 .Times(1); | |
632 | |
633 BluetoothAdapterChromeOS* adapter_chromeos = | |
634 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
635 | |
636 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
637 ->AdapterPropertyChanged(adapter_path, | |
638 adapter_properties.address.name()); | |
639 | |
640 // Adapter should have the correct property value. | |
641 EXPECT_TRUE(adapter_->IsPowered()); | |
642 } | |
643 | |
644 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterPoweredPropertyChanged) { | |
645 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
646 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
647 | |
648 // Create the default adapter instance; | |
649 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
650 // a callback to obtain the adapter path. | |
651 BluetoothManagerClient::AdapterCallback adapter_callback; | |
652 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
653 .WillOnce(SaveArg<0>(&adapter_callback)); | |
654 | |
655 BluetoothAdapterFactory::GetAdapter( | |
656 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
657 base::Unretained(this))); | |
658 | |
659 // Call the adapter callback; | |
660 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
661 // the property set. | |
662 MockBluetoothAdapterClient::Properties adapter_properties; | |
663 adapter_properties.address.ReplaceValue(adapter_address); | |
664 adapter_properties.powered.ReplaceValue(false); | |
665 | |
666 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
667 .WillRepeatedly(Return(&adapter_properties)); | |
668 | |
669 adapter_callback.Run(adapter_path, true); | |
670 | |
671 // Adapter should have the correct property value. | |
672 EXPECT_FALSE(adapter_->IsPowered()); | |
673 | |
674 // Report that the property has been changed; | |
675 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
676 MockBluetoothAdapter::Observer adapter_observer; | |
677 adapter_->AddObserver(&adapter_observer); | |
678 | |
679 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) | |
680 .Times(1); | |
681 | |
682 adapter_properties.powered.ReplaceValue(true); | |
683 | |
684 BluetoothAdapterChromeOS* adapter_chromeos = | |
685 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
686 | |
687 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
688 ->AdapterPropertyChanged(adapter_path, | |
689 adapter_properties.powered.name()); | |
690 | |
691 // Adapter should have the new property values. | |
692 EXPECT_TRUE(adapter_->IsPowered()); | |
693 } | |
694 | |
695 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterPoweredPropertyUnchanged) { | |
696 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
697 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
698 | |
699 // Create the default adapter instance; | |
700 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
701 // a callback to obtain the adapter path. | |
702 BluetoothManagerClient::AdapterCallback adapter_callback; | |
703 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
704 .WillOnce(SaveArg<0>(&adapter_callback)); | |
705 | |
706 BluetoothAdapterFactory::GetAdapter( | |
707 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
708 base::Unretained(this))); | |
709 | |
710 // Call the adapter callback; | |
711 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
712 // the property set. | |
713 MockBluetoothAdapterClient::Properties adapter_properties; | |
714 adapter_properties.address.ReplaceValue(adapter_address); | |
715 adapter_properties.powered.ReplaceValue(true); | |
716 | |
717 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
718 .WillRepeatedly(Return(&adapter_properties)); | |
719 | |
720 adapter_callback.Run(adapter_path, true); | |
721 | |
722 // Adapter should have the correct property value. | |
723 EXPECT_TRUE(adapter_->IsPowered()); | |
724 | |
725 // Report that the property has been changed, but don't change the value; | |
726 // BluetoothAdapter::Observer::AdapterPoweredChanged should not be called. | |
727 MockBluetoothAdapter::Observer adapter_observer; | |
728 adapter_->AddObserver(&adapter_observer); | |
729 | |
730 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) | |
731 .Times(0); | |
732 | |
733 BluetoothAdapterChromeOS* adapter_chromeos = | |
734 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
735 | |
736 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
737 ->AdapterPropertyChanged(adapter_path, | |
738 adapter_properties.powered.name()); | |
739 | |
740 // Adapter should still have the same property values. | |
741 EXPECT_TRUE(adapter_->IsPowered()); | |
742 } | |
743 | |
744 TEST_F(BluetoothAdapterChromeOSTest, | |
745 DefaultAdapterPoweredPropertyChangedWithoutAddress) { | |
746 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
747 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
748 | |
749 // Create the default adapter instance; | |
750 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
751 // a callback to obtain the adapter path. | |
752 BluetoothManagerClient::AdapterCallback adapter_callback; | |
753 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
754 .WillOnce(SaveArg<0>(&adapter_callback)); | |
755 | |
756 BluetoothAdapterFactory::GetAdapter( | |
757 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
758 base::Unretained(this))); | |
759 | |
760 // Call the adapter callback; | |
761 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
762 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged | |
763 // should not yet be called. | |
764 MockBluetoothAdapterClient::Properties adapter_properties; | |
765 | |
766 MockBluetoothAdapter::Observer adapter_observer; | |
767 adapter_->AddObserver(&adapter_observer); | |
768 | |
769 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
770 .WillRepeatedly(Return(&adapter_properties)); | |
771 | |
772 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) | |
773 .Times(0); | |
774 | |
775 adapter_callback.Run(adapter_path, true); | |
776 | |
777 // Tell the adapter that its powered property changed, the observer | |
778 // method should still not be called because there is no address for | |
779 // the adapter so it is not present. | |
780 adapter_properties.powered.ReplaceValue(true); | |
781 | |
782 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) | |
783 .Times(0); | |
784 | |
785 BluetoothAdapterChromeOS* adapter_chromeos = | |
786 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
787 | |
788 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
789 ->AdapterPropertyChanged(adapter_path, | |
790 adapter_properties.powered.name()); | |
791 | |
792 // Adapter should not yet have the property value. | |
793 EXPECT_FALSE(adapter_->IsPowered()); | |
794 | |
795 // Tell the adapter the address now, | |
796 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
797 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. | |
798 adapter_properties.address.ReplaceValue(adapter_address); | |
799 | |
800 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
801 .Times(1); | |
802 | |
803 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) | |
804 .Times(1); | |
805 | |
806 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
807 ->AdapterPropertyChanged(adapter_path, | |
808 adapter_properties.address.name()); | |
809 | |
810 // Adapter should now have the correct property value. | |
811 EXPECT_TRUE(adapter_->IsPowered()); | |
812 } | |
813 | |
814 TEST_F(BluetoothAdapterChromeOSTest, | |
815 DefaultAdapterPoweredPropertyResetOnReplace) { | |
816 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
817 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
818 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
819 const std::string new_adapter_address = "00:C0:11:CO:FE:FE"; | |
820 | |
821 // Create the default adapter instance; | |
822 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
823 // a callback to obtain the adapter path. | |
824 BluetoothManagerClient::AdapterCallback adapter_callback; | |
825 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
826 .WillOnce(SaveArg<0>(&adapter_callback)); | |
827 | |
828 BluetoothAdapterFactory::GetAdapter( | |
829 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
830 base::Unretained(this))); | |
831 | |
832 // Call the adapter callback; | |
833 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
834 // the property set. | |
835 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
836 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
837 initial_adapter_properties.powered.ReplaceValue(true); | |
838 | |
839 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
840 .WillRepeatedly(Return(&initial_adapter_properties)); | |
841 | |
842 adapter_callback.Run(initial_adapter_path, true); | |
843 | |
844 // Tell the adapter the default adapter changed; | |
845 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
846 // the property set. | |
847 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
848 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
849 | |
850 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
851 .WillRepeatedly(Return(&new_adapter_properties)); | |
852 | |
853 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
854 MockBluetoothAdapter::Observer adapter_observer; | |
855 adapter_->AddObserver(&adapter_observer); | |
856 | |
857 { | |
858 InSequence s; | |
859 | |
860 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
861 .Times(1); | |
862 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
863 .Times(1); | |
864 } | |
865 | |
866 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false)) | |
867 .Times(1); | |
868 | |
869 BluetoothAdapterChromeOS* adapter_chromeos = | |
870 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
871 | |
872 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
873 ->DefaultAdapterChanged(new_adapter_path); | |
874 | |
875 // Adapter should have the new property value. | |
876 EXPECT_FALSE(adapter_->IsPowered()); | |
877 } | |
878 | |
879 TEST_F(BluetoothAdapterChromeOSTest, | |
880 DefaultAdapterPoweredPropertyResetOnReplaceWhenTrue) { | |
881 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
882 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
883 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
884 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
885 | |
886 // Create the default adapter instance; | |
887 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
888 // a callback to obtain the adapter path. | |
889 BluetoothManagerClient::AdapterCallback adapter_callback; | |
890 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
891 .WillOnce(SaveArg<0>(&adapter_callback)); | |
892 | |
893 BluetoothAdapterFactory::GetAdapter( | |
894 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
895 base::Unretained(this))); | |
896 | |
897 // Call the adapter callback; | |
898 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
899 // the property set. | |
900 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
901 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
902 initial_adapter_properties.powered.ReplaceValue(true); | |
903 | |
904 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
905 .WillRepeatedly(Return(&initial_adapter_properties)); | |
906 | |
907 adapter_callback.Run(initial_adapter_path, true); | |
908 | |
909 // Tell the adapter the default adapter changed; | |
910 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
911 // the property set. | |
912 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
913 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
914 new_adapter_properties.powered.ReplaceValue(true); | |
915 | |
916 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
917 .WillRepeatedly(Return(&new_adapter_properties)); | |
918 | |
919 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called once | |
920 // to set the value to false for the previous adapter and once to set the | |
921 // value to true for the new adapter. | |
922 MockBluetoothAdapter::Observer adapter_observer; | |
923 adapter_->AddObserver(&adapter_observer); | |
924 | |
925 { | |
926 InSequence s; | |
927 | |
928 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
929 .Times(1); | |
930 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
931 .Times(1); | |
932 } | |
933 | |
934 { | |
935 InSequence s; | |
936 | |
937 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false)) | |
938 .Times(1); | |
939 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) | |
940 .Times(1); | |
941 } | |
942 | |
943 BluetoothAdapterChromeOS* adapter_chromeos = | |
944 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
945 | |
946 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
947 ->DefaultAdapterChanged(new_adapter_path); | |
948 | |
949 // Adapter should have the new property value. | |
950 EXPECT_TRUE(adapter_->IsPowered()); | |
951 } | |
952 | |
953 TEST_F(BluetoothAdapterChromeOSTest, | |
954 DefaultAdapterPoweredPropertyResetOnRemove) { | |
955 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
956 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
957 | |
958 // Create the default adapter instance; | |
959 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
960 // a callback to obtain the adapter path. | |
961 BluetoothManagerClient::AdapterCallback adapter_callback; | |
962 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
963 .WillOnce(SaveArg<0>(&adapter_callback)); | |
964 | |
965 BluetoothAdapterFactory::GetAdapter( | |
966 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
967 base::Unretained(this))); | |
968 | |
969 // Call the adapter callback; | |
970 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
971 // the property set. | |
972 MockBluetoothAdapterClient::Properties adapter_properties; | |
973 adapter_properties.address.ReplaceValue(adapter_address); | |
974 adapter_properties.powered.ReplaceValue(true); | |
975 | |
976 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
977 .WillRepeatedly(Return(&adapter_properties)); | |
978 | |
979 adapter_callback.Run(adapter_path, true); | |
980 | |
981 // Report that the adapter has been removed; | |
982 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
983 MockBluetoothAdapter::Observer adapter_observer; | |
984 adapter_->AddObserver(&adapter_observer); | |
985 | |
986 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
987 .Times(1); | |
988 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false)) | |
989 .Times(1); | |
990 | |
991 BluetoothAdapterChromeOS* adapter_chromeos = | |
992 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
993 | |
994 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
995 ->AdapterRemoved(adapter_path); | |
996 | |
997 // Adapter should have the new property value. | |
998 EXPECT_FALSE(adapter_->IsPowered()); | |
999 } | |
1000 | |
1001 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSetPowered) { | |
1002 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1003 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1004 | |
1005 // Create the default adapter instance; | |
1006 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1007 // a callback to obtain the adapter path. | |
1008 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1009 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1010 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1011 | |
1012 BluetoothAdapterFactory::GetAdapter( | |
1013 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1014 base::Unretained(this))); | |
1015 | |
1016 // Call the adapter callback; | |
1017 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1018 // the property set. | |
1019 MockBluetoothAdapterClient::Properties adapter_properties; | |
1020 | |
1021 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1022 .WillRepeatedly(Return(&adapter_properties)); | |
1023 | |
1024 adapter_callback.Run(adapter_path, true); | |
1025 | |
1026 // Request that the powered property be changed; | |
1027 // MockBluetoothAdapterClient::Set should be called, passing the address | |
1028 // of the powered property and a callback to receive the response. | |
1029 dbus::PropertySet::SetCallback set_callback; | |
1030 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) | |
1031 .WillOnce(SaveArg<1>(&set_callback)); | |
1032 | |
1033 adapter_->SetPowered(true, | |
1034 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1035 base::Unretained(this)), | |
1036 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1037 base::Unretained(this))); | |
1038 | |
1039 // Reply to the callback to indicate success, the set callback we provided | |
1040 // should be called but the properties should not be refetched. | |
1041 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1042 .Times(0); | |
1043 | |
1044 set_callback.Run(true); | |
1045 | |
1046 EXPECT_TRUE(callback_called_); | |
1047 EXPECT_FALSE(error_callback_called_); | |
1048 } | |
1049 | |
1050 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSetPoweredError) { | |
1051 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1052 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1053 | |
1054 // Create the default adapter instance; | |
1055 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1056 // a callback to obtain the adapter path. | |
1057 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1058 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1059 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1060 | |
1061 BluetoothAdapterFactory::GetAdapter( | |
1062 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1063 base::Unretained(this))); | |
1064 | |
1065 // Call the adapter callback; | |
1066 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1067 // the property set. | |
1068 MockBluetoothAdapterClient::Properties adapter_properties; | |
1069 | |
1070 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1071 .WillRepeatedly(Return(&adapter_properties)); | |
1072 | |
1073 adapter_callback.Run(adapter_path, true); | |
1074 | |
1075 // Request that the powered property be changed; | |
1076 // MockBluetoothAdapterClient::Set should be called, passing the address | |
1077 // of the powered property and a callback to receive the response. | |
1078 dbus::PropertySet::SetCallback set_callback; | |
1079 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) | |
1080 .WillOnce(SaveArg<1>(&set_callback)); | |
1081 | |
1082 adapter_->SetPowered(true, | |
1083 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1084 base::Unretained(this)), | |
1085 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1086 base::Unretained(this))); | |
1087 | |
1088 // Reply to the callback to indicate failure, the error callback we provided | |
1089 // should be called but the properties should not be refetched. | |
1090 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1091 .Times(0); | |
1092 | |
1093 set_callback.Run(false); | |
1094 | |
1095 EXPECT_FALSE(callback_called_); | |
1096 EXPECT_TRUE(error_callback_called_); | |
1097 } | |
1098 | |
1099 TEST_F(BluetoothAdapterChromeOSTest, | |
1100 DefaultAdapterDiscoveringPropertyInitiallyFalse) { | |
1101 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1102 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1103 | |
1104 // Create the default adapter instance; | |
1105 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1106 // a callback to obtain the adapter path. | |
1107 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1108 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1109 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1110 | |
1111 BluetoothAdapterFactory::GetAdapter( | |
1112 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1113 base::Unretained(this))); | |
1114 | |
1115 // Call the adapter callback; | |
1116 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1117 // the property set. | |
1118 MockBluetoothAdapterClient::Properties adapter_properties; | |
1119 adapter_properties.address.ReplaceValue(adapter_address); | |
1120 adapter_properties.discovering.ReplaceValue(false); | |
1121 | |
1122 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1123 .WillRepeatedly(Return(&adapter_properties)); | |
1124 | |
1125 adapter_callback.Run(adapter_path, true); | |
1126 | |
1127 // Adapter should have the correct property value. | |
1128 EXPECT_FALSE(adapter_->IsDiscovering()); | |
1129 } | |
1130 | |
1131 TEST_F(BluetoothAdapterChromeOSTest, | |
1132 DefaultAdapterDiscoveringPropertyInitiallyTrue) { | |
1133 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1134 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1135 | |
1136 // Create the default adapter instance; | |
1137 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1138 // a callback to obtain the adapter path. | |
1139 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1140 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1141 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1142 | |
1143 BluetoothAdapterFactory::GetAdapter( | |
1144 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1145 base::Unretained(this))); | |
1146 | |
1147 // Call the adapter callback; | |
1148 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1149 // the property set. | |
1150 MockBluetoothAdapterClient::Properties adapter_properties; | |
1151 adapter_properties.address.ReplaceValue(adapter_address); | |
1152 adapter_properties.discovering.ReplaceValue(true); | |
1153 | |
1154 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1155 .WillRepeatedly(Return(&adapter_properties)); | |
1156 | |
1157 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1158 MockBluetoothAdapter::Observer adapter_observer; | |
1159 adapter_->AddObserver(&adapter_observer); | |
1160 | |
1161 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
1162 .Times(1); | |
1163 | |
1164 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) | |
1165 .Times(1); | |
1166 | |
1167 adapter_callback.Run(adapter_path, true); | |
1168 | |
1169 // Adapter should have the correct property value. | |
1170 EXPECT_TRUE(adapter_->IsDiscovering()); | |
1171 } | |
1172 | |
1173 TEST_F(BluetoothAdapterChromeOSTest, | |
1174 DefaultAdapterDiscoveringPropertyInitiallyTrueWithoutAddress) { | |
1175 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1176 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1177 | |
1178 // Create the default adapter instance; | |
1179 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1180 // a callback to obtain the adapter path. | |
1181 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1182 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1183 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1184 | |
1185 BluetoothAdapterFactory::GetAdapter( | |
1186 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1187 base::Unretained(this))); | |
1188 | |
1189 // Call the adapter callback; | |
1190 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1191 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged | |
1192 // should not yet be called. | |
1193 MockBluetoothAdapterClient::Properties adapter_properties; | |
1194 adapter_properties.discovering.ReplaceValue(true); | |
1195 | |
1196 MockBluetoothAdapter::Observer adapter_observer; | |
1197 adapter_->AddObserver(&adapter_observer); | |
1198 | |
1199 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1200 .WillRepeatedly(Return(&adapter_properties)); | |
1201 | |
1202 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) | |
1203 .Times(0); | |
1204 | |
1205 adapter_callback.Run(adapter_path, true); | |
1206 | |
1207 // Adapter should not yet have the property value. | |
1208 EXPECT_FALSE(adapter_->IsDiscovering()); | |
1209 | |
1210 // Tell the adapter the address now, | |
1211 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
1212 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. | |
1213 adapter_properties.address.ReplaceValue(adapter_address); | |
1214 | |
1215 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
1216 .Times(1); | |
1217 | |
1218 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) | |
1219 .Times(1); | |
1220 | |
1221 BluetoothAdapterChromeOS* adapter_chromeos = | |
1222 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
1223 | |
1224 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1225 ->AdapterPropertyChanged(adapter_path, | |
1226 adapter_properties.address.name()); | |
1227 | |
1228 // Adapter should have the correct property value. | |
1229 EXPECT_TRUE(adapter_->IsDiscovering()); | |
1230 } | |
1231 | |
1232 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterDiscoveringPropertyChanged) { | |
1233 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1234 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1235 | |
1236 // Create the default adapter instance; | |
1237 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1238 // a callback to obtain the adapter path. | |
1239 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1240 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1241 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1242 | |
1243 BluetoothAdapterFactory::GetAdapter( | |
1244 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1245 base::Unretained(this))); | |
1246 | |
1247 // Call the adapter callback; | |
1248 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1249 // the property set. | |
1250 MockBluetoothAdapterClient::Properties adapter_properties; | |
1251 adapter_properties.address.ReplaceValue(adapter_address); | |
1252 adapter_properties.discovering.ReplaceValue(false); | |
1253 | |
1254 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1255 .WillRepeatedly(Return(&adapter_properties)); | |
1256 | |
1257 adapter_callback.Run(adapter_path, true); | |
1258 | |
1259 // Adapter should have the correct property value. | |
1260 EXPECT_FALSE(adapter_->IsDiscovering()); | |
1261 | |
1262 // Report that the property has been changed; | |
1263 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1264 MockBluetoothAdapter::Observer adapter_observer; | |
1265 adapter_->AddObserver(&adapter_observer); | |
1266 | |
1267 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) | |
1268 .Times(1); | |
1269 | |
1270 adapter_properties.discovering.ReplaceValue(true); | |
1271 | |
1272 BluetoothAdapterChromeOS* adapter_chromeos = | |
1273 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
1274 | |
1275 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1276 ->AdapterPropertyChanged(adapter_path, | |
1277 adapter_properties.discovering.name()); | |
1278 | |
1279 // Adapter should have the new property values. | |
1280 EXPECT_TRUE(adapter_->IsDiscovering()); | |
1281 } | |
1282 | |
1283 TEST_F(BluetoothAdapterChromeOSTest, | |
1284 DefaultAdapterDiscoveringPropertyUnchanged) { | |
1285 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1286 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1287 | |
1288 // Create the default adapter instance; | |
1289 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1290 // a callback to obtain the adapter path. | |
1291 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1292 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1293 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1294 | |
1295 BluetoothAdapterFactory::GetAdapter( | |
1296 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1297 base::Unretained(this))); | |
1298 | |
1299 // Call the adapter callback; | |
1300 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1301 // the property set. | |
1302 MockBluetoothAdapterClient::Properties adapter_properties; | |
1303 adapter_properties.address.ReplaceValue(adapter_address); | |
1304 adapter_properties.discovering.ReplaceValue(true); | |
1305 | |
1306 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1307 .WillRepeatedly(Return(&adapter_properties)); | |
1308 | |
1309 adapter_callback.Run(adapter_path, true); | |
1310 | |
1311 // Adapter should have the correct property value. | |
1312 EXPECT_TRUE(adapter_->IsDiscovering()); | |
1313 | |
1314 // Report that the property has been changed, but don't change the value; | |
1315 // BluetoothAdapter::Observer::AdapterDiscoveringChanged should not be | |
1316 // called. | |
1317 MockBluetoothAdapter::Observer adapter_observer; | |
1318 adapter_->AddObserver(&adapter_observer); | |
1319 | |
1320 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) | |
1321 .Times(0); | |
1322 | |
1323 BluetoothAdapterChromeOS* adapter_chromeos = | |
1324 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
1325 | |
1326 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1327 ->AdapterPropertyChanged(adapter_path, | |
1328 adapter_properties.discovering.name()); | |
1329 | |
1330 // Adapter should still have the same property values. | |
1331 EXPECT_TRUE(adapter_->IsDiscovering()); | |
1332 } | |
1333 | |
1334 TEST_F(BluetoothAdapterChromeOSTest, | |
1335 DefaultAdapterDiscoveringPropertyChangedWithoutAddress) { | |
1336 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1337 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1338 | |
1339 // Create the default adapter instance; | |
1340 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1341 // a callback to obtain the adapter path. | |
1342 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1343 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1344 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1345 | |
1346 BluetoothAdapterFactory::GetAdapter( | |
1347 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1348 base::Unretained(this))); | |
1349 | |
1350 // Call the adapter callback; | |
1351 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1352 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged | |
1353 // should not yet be called. | |
1354 MockBluetoothAdapterClient::Properties adapter_properties; | |
1355 | |
1356 MockBluetoothAdapter::Observer adapter_observer; | |
1357 adapter_->AddObserver(&adapter_observer); | |
1358 | |
1359 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1360 .WillRepeatedly(Return(&adapter_properties)); | |
1361 | |
1362 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) | |
1363 .Times(0); | |
1364 | |
1365 adapter_callback.Run(adapter_path, true); | |
1366 | |
1367 // Tell the adapter that its discovering property changed, the observer | |
1368 // method should still not be called because there is no address for | |
1369 // the adapter so it is not present. | |
1370 adapter_properties.discovering.ReplaceValue(true); | |
1371 | |
1372 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) | |
1373 .Times(0); | |
1374 | |
1375 BluetoothAdapterChromeOS* adapter_chromeos = | |
1376 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
1377 | |
1378 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1379 ->AdapterPropertyChanged(adapter_path, | |
1380 adapter_properties.discovering.name()); | |
1381 | |
1382 // Adapter should not yet have the property value. | |
1383 EXPECT_FALSE(adapter_->IsDiscovering()); | |
1384 | |
1385 // Tell the adapter the address now, | |
1386 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
1387 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. | |
1388 adapter_properties.address.ReplaceValue(adapter_address); | |
1389 | |
1390 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
1391 .Times(1); | |
1392 | |
1393 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) | |
1394 .Times(1); | |
1395 | |
1396 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1397 ->AdapterPropertyChanged(adapter_path, | |
1398 adapter_properties.address.name()); | |
1399 | |
1400 // Adapter should now have the correct property value. | |
1401 EXPECT_TRUE(adapter_->IsDiscovering()); | |
1402 } | |
1403 | |
1404 TEST_F(BluetoothAdapterChromeOSTest, | |
1405 DefaultAdapterDiscoveringPropertyResetOnReplace) { | |
1406 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
1407 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
1408 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1409 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
1410 | |
1411 // Create the default adapter instance; | |
1412 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1413 // a callback to obtain the adapter path. | |
1414 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1415 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1416 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1417 | |
1418 BluetoothAdapterFactory::GetAdapter( | |
1419 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1420 base::Unretained(this))); | |
1421 | |
1422 // Call the adapter callback; | |
1423 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1424 // the property set. | |
1425 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
1426 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
1427 initial_adapter_properties.discovering.ReplaceValue(true); | |
1428 | |
1429 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
1430 .WillRepeatedly(Return(&initial_adapter_properties)); | |
1431 | |
1432 adapter_callback.Run(initial_adapter_path, true); | |
1433 | |
1434 // Tell the adapter the default adapter changed; | |
1435 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1436 // the property set. | |
1437 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
1438 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
1439 | |
1440 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
1441 .WillRepeatedly(Return(&new_adapter_properties)); | |
1442 | |
1443 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1444 MockBluetoothAdapter::Observer adapter_observer; | |
1445 adapter_->AddObserver(&adapter_observer); | |
1446 | |
1447 { | |
1448 InSequence s; | |
1449 | |
1450 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
1451 .Times(1); | |
1452 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
1453 .Times(1); | |
1454 } | |
1455 | |
1456 EXPECT_CALL(adapter_observer, | |
1457 AdapterDiscoveringChanged(adapter_.get(), false)) | |
1458 .Times(1); | |
1459 | |
1460 BluetoothAdapterChromeOS* adapter_chromeos = | |
1461 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
1462 | |
1463 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
1464 ->DefaultAdapterChanged(new_adapter_path); | |
1465 | |
1466 // Adapter should have the new property value. | |
1467 EXPECT_FALSE(adapter_->IsDiscovering()); | |
1468 } | |
1469 | |
1470 TEST_F(BluetoothAdapterChromeOSTest, | |
1471 DefaultAdapterDiscoveringPropertyResetOnReplaceWhenTrue) { | |
1472 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
1473 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
1474 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1475 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
1476 | |
1477 // Create the default adapter instance; | |
1478 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1479 // a callback to obtain the adapter path. | |
1480 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1481 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1482 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1483 | |
1484 BluetoothAdapterFactory::GetAdapter( | |
1485 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1486 base::Unretained(this))); | |
1487 | |
1488 // Call the adapter callback; | |
1489 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1490 // the property set. | |
1491 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
1492 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
1493 initial_adapter_properties.discovering.ReplaceValue(true); | |
1494 | |
1495 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
1496 .WillRepeatedly(Return(&initial_adapter_properties)); | |
1497 | |
1498 adapter_callback.Run(initial_adapter_path, true); | |
1499 | |
1500 // Tell the adapter the default adapter changed; | |
1501 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1502 // the property set. | |
1503 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
1504 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
1505 new_adapter_properties.discovering.ReplaceValue(true); | |
1506 | |
1507 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
1508 .WillRepeatedly(Return(&new_adapter_properties)); | |
1509 | |
1510 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called once | |
1511 // to set the value to false for the previous adapter and once to set the | |
1512 // value to true for the new adapter. | |
1513 MockBluetoothAdapter::Observer adapter_observer; | |
1514 adapter_->AddObserver(&adapter_observer); | |
1515 | |
1516 { | |
1517 InSequence s; | |
1518 | |
1519 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
1520 .Times(1); | |
1521 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) | |
1522 .Times(1); | |
1523 } | |
1524 | |
1525 { | |
1526 InSequence s; | |
1527 | |
1528 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), | |
1529 false)) | |
1530 .Times(1); | |
1531 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), | |
1532 true)) | |
1533 .Times(1); | |
1534 } | |
1535 | |
1536 BluetoothAdapterChromeOS* adapter_chromeos = | |
1537 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
1538 | |
1539 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
1540 ->DefaultAdapterChanged(new_adapter_path); | |
1541 | |
1542 // Adapter should have the new property value. | |
1543 EXPECT_TRUE(adapter_->IsDiscovering()); | |
1544 } | |
1545 | |
1546 TEST_F(BluetoothAdapterChromeOSTest, | |
1547 DefaultAdapterDiscoveringPropertyResetOnRemove) { | |
1548 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1549 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1550 | |
1551 // Create the default adapter instance; | |
1552 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1553 // a callback to obtain the adapter path. | |
1554 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1555 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1556 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1557 | |
1558 BluetoothAdapterFactory::GetAdapter( | |
1559 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1560 base::Unretained(this))); | |
1561 | |
1562 // Call the adapter callback; | |
1563 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1564 // the property set. | |
1565 MockBluetoothAdapterClient::Properties adapter_properties; | |
1566 adapter_properties.address.ReplaceValue(adapter_address); | |
1567 adapter_properties.discovering.ReplaceValue(true); | |
1568 | |
1569 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1570 .WillRepeatedly(Return(&adapter_properties)); | |
1571 | |
1572 adapter_callback.Run(adapter_path, true); | |
1573 | |
1574 // Report that the adapter has been removed; | |
1575 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1576 MockBluetoothAdapter::Observer adapter_observer; | |
1577 adapter_->AddObserver(&adapter_observer); | |
1578 | |
1579 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) | |
1580 .Times(1); | |
1581 EXPECT_CALL(adapter_observer, | |
1582 AdapterDiscoveringChanged(adapter_.get(), false)) | |
1583 .Times(1); | |
1584 | |
1585 BluetoothAdapterChromeOS* adapter_chromeos = | |
1586 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | |
1587 | |
1588 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
1589 ->AdapterRemoved(adapter_path); | |
1590 | |
1591 // Adapter should have the new property value. | |
1592 EXPECT_FALSE(adapter_->IsDiscovering()); | |
1593 } | |
1594 | |
1595 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterNotInitiallyDiscovering) { | |
1596 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1597 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1598 | |
1599 // Create the default adapter instance; | |
1600 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1601 // a callback to obtain the adapter path. | |
1602 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1603 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1604 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1605 | |
1606 BluetoothAdapterFactory::GetAdapter( | |
1607 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1608 base::Unretained(this))); | |
1609 | |
1610 // Call the adapter callback; | |
1611 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1612 // the property set. | |
1613 MockBluetoothAdapterClient::Properties adapter_properties; | |
1614 adapter_properties.address.ReplaceValue(adapter_address); | |
1615 | |
1616 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1617 .WillRepeatedly(Return(&adapter_properties)); | |
1618 | |
1619 adapter_callback.Run(adapter_path, true); | |
1620 | |
1621 // Adapter should have the correct property value. | |
1622 EXPECT_FALSE(adapter_->IsDiscovering()); | |
1623 } | |
1624 | |
1625 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStartDiscovering) { | |
1626 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1627 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1628 | |
1629 // Create the default adapter instance; | |
1630 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1631 // a callback to obtain the adapter path. | |
1632 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1633 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1634 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1635 | |
1636 BluetoothAdapterFactory::GetAdapter( | |
1637 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1638 base::Unretained(this))); | |
1639 | |
1640 // Call the adapter callback; | |
1641 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1642 // the property set. | |
1643 MockBluetoothAdapterClient::Properties adapter_properties; | |
1644 adapter_properties.address.ReplaceValue(adapter_address); | |
1645 | |
1646 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1647 .WillRepeatedly(Return(&adapter_properties)); | |
1648 | |
1649 adapter_callback.Run(adapter_path, true); | |
1650 | |
1651 // Ask the adapter to start discovering devices; | |
1652 // BluetoothAdapterClient::StartDiscovery will be called. | |
1653 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
1654 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1655 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1656 | |
1657 adapter_->StartDiscovering( | |
1658 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1659 base::Unretained(this)), | |
1660 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1661 base::Unretained(this))); | |
1662 | |
1663 // Return indicate success. | |
1664 start_discovery_callback.Run(adapter_path, true); | |
1665 | |
1666 EXPECT_TRUE(callback_called_); | |
1667 EXPECT_FALSE(error_callback_called_); | |
1668 } | |
1669 | |
1670 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStartDiscoveringError) { | |
1671 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1672 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1673 | |
1674 // Create the default adapter instance; | |
1675 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1676 // a callback to obtain the adapter path. | |
1677 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1678 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1679 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1680 | |
1681 BluetoothAdapterFactory::GetAdapter( | |
1682 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1683 base::Unretained(this))); | |
1684 | |
1685 // Call the adapter callback; | |
1686 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1687 // the property set. | |
1688 MockBluetoothAdapterClient::Properties adapter_properties; | |
1689 adapter_properties.address.ReplaceValue(adapter_address); | |
1690 | |
1691 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1692 .WillRepeatedly(Return(&adapter_properties)); | |
1693 | |
1694 adapter_callback.Run(adapter_path, true); | |
1695 | |
1696 // Ask the adapter to start discovering devices; | |
1697 // BluetoothAdapterClient::StartDiscovery will be called. | |
1698 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
1699 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1700 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1701 | |
1702 adapter_->StartDiscovering( | |
1703 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1704 base::Unretained(this)), | |
1705 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1706 base::Unretained(this))); | |
1707 | |
1708 // Return to indicate failure. | |
1709 start_discovery_callback.Run(adapter_path, false); | |
1710 | |
1711 EXPECT_FALSE(callback_called_); | |
1712 EXPECT_TRUE(error_callback_called_); | |
1713 } | |
1714 | |
1715 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSecondStartDiscovering) { | |
1716 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1717 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1718 | |
1719 // Create the default adapter instance; | |
1720 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1721 // a callback to obtain the adapter path. | |
1722 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1723 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1724 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1725 | |
1726 BluetoothAdapterFactory::GetAdapter( | |
1727 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1728 base::Unretained(this))); | |
1729 | |
1730 // Call the adapter callback; | |
1731 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1732 // the property set. | |
1733 MockBluetoothAdapterClient::Properties adapter_properties; | |
1734 adapter_properties.address.ReplaceValue(adapter_address); | |
1735 | |
1736 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1737 .WillRepeatedly(Return(&adapter_properties)); | |
1738 | |
1739 adapter_callback.Run(adapter_path, true); | |
1740 | |
1741 // Ask the adapter to start discovering devices; | |
1742 // BluetoothAdapterClient::StartDiscovery will be called. | |
1743 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
1744 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1745 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1746 | |
1747 adapter_->StartDiscovering( | |
1748 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1749 base::Unretained(this)), | |
1750 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1751 base::Unretained(this))); | |
1752 | |
1753 // Return to indicate success. | |
1754 start_discovery_callback.Run(adapter_path, true); | |
1755 | |
1756 // Ask the adapter to start discovering devices again; | |
1757 // BluetoothAdapterClient::StartDiscovery will be called again. | |
1758 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1759 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1760 | |
1761 callback_called_ = false; | |
1762 error_callback_called_ = false; | |
1763 | |
1764 adapter_->StartDiscovering( | |
1765 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1766 base::Unretained(this)), | |
1767 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1768 base::Unretained(this))); | |
1769 | |
1770 // Return to indicate success again. | |
1771 start_discovery_callback.Run(adapter_path, true); | |
1772 | |
1773 EXPECT_TRUE(callback_called_); | |
1774 EXPECT_FALSE(error_callback_called_); | |
1775 } | |
1776 | |
1777 TEST_F(BluetoothAdapterChromeOSTest, | |
1778 DefaultAdapterSecondStartDiscoveringError) { | |
1779 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1780 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1781 | |
1782 // Create the default adapter instance; | |
1783 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1784 // a callback to obtain the adapter path. | |
1785 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1786 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1787 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1788 | |
1789 BluetoothAdapterFactory::GetAdapter( | |
1790 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1791 base::Unretained(this))); | |
1792 | |
1793 // Call the adapter callback; | |
1794 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1795 // the property set. | |
1796 MockBluetoothAdapterClient::Properties adapter_properties; | |
1797 adapter_properties.address.ReplaceValue(adapter_address); | |
1798 | |
1799 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1800 .WillRepeatedly(Return(&adapter_properties)); | |
1801 | |
1802 adapter_callback.Run(adapter_path, true); | |
1803 | |
1804 // Ask the adapter to start discovering devices; | |
1805 // BluetoothAdapterClient::StartDiscovery will be called. | |
1806 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
1807 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1808 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1809 | |
1810 adapter_->StartDiscovering( | |
1811 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1812 base::Unretained(this)), | |
1813 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1814 base::Unretained(this))); | |
1815 | |
1816 // Return to indicate success. | |
1817 start_discovery_callback.Run(adapter_path, true); | |
1818 | |
1819 // Ask the adapter to start discovering devices again; | |
1820 // BluetoothAdapterClient::StartDiscovery will be called again. | |
1821 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1822 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1823 | |
1824 callback_called_ = false; | |
1825 error_callback_called_ = false; | |
1826 | |
1827 adapter_->StartDiscovering( | |
1828 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1829 base::Unretained(this)), | |
1830 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1831 base::Unretained(this))); | |
1832 | |
1833 // Return to indicate failure. | |
1834 start_discovery_callback.Run(adapter_path, false); | |
1835 | |
1836 EXPECT_FALSE(callback_called_); | |
1837 EXPECT_TRUE(error_callback_called_); | |
1838 } | |
1839 | |
1840 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStopDiscovering) { | |
1841 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1842 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1843 | |
1844 // Create the default adapter instance; | |
1845 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1846 // a callback to obtain the adapter path. | |
1847 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1848 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1849 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1850 | |
1851 BluetoothAdapterFactory::GetAdapter( | |
1852 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1853 base::Unretained(this))); | |
1854 | |
1855 // Call the adapter callback; | |
1856 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1857 // the property set. | |
1858 MockBluetoothAdapterClient::Properties adapter_properties; | |
1859 adapter_properties.address.ReplaceValue(adapter_address); | |
1860 | |
1861 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1862 .WillRepeatedly(Return(&adapter_properties)); | |
1863 | |
1864 adapter_callback.Run(adapter_path, true); | |
1865 | |
1866 // Ask the adapter to start discovering devices; | |
1867 // BluetoothAdapterClient::StartDiscovery will be called. | |
1868 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
1869 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1870 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1871 | |
1872 adapter_->StartDiscovering( | |
1873 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1874 base::Unretained(this)), | |
1875 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1876 base::Unretained(this))); | |
1877 | |
1878 // Return to indicate success. | |
1879 start_discovery_callback.Run(adapter_path, true); | |
1880 | |
1881 // Ask the adapter to stop discovering devices; | |
1882 // BluetoothAdapterClient::StopDiscovery will be called. | |
1883 BluetoothAdapterClient::AdapterCallback stop_discovery_callback; | |
1884 EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _)) | |
1885 .WillOnce(SaveArg<1>(&stop_discovery_callback)); | |
1886 | |
1887 callback_called_ = false; | |
1888 error_callback_called_ = false; | |
1889 | |
1890 adapter_->StopDiscovering( | |
1891 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1892 base::Unretained(this)), | |
1893 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1894 base::Unretained(this))); | |
1895 | |
1896 // Return to indicate success. | |
1897 stop_discovery_callback.Run(adapter_path, true); | |
1898 | |
1899 EXPECT_TRUE(callback_called_); | |
1900 EXPECT_FALSE(error_callback_called_); | |
1901 } | |
1902 | |
1903 TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStopDiscoveringError) { | |
1904 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1905 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1906 | |
1907 // Create the default adapter instance; | |
1908 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1909 // a callback to obtain the adapter path. | |
1910 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1911 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1912 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1913 | |
1914 BluetoothAdapterFactory::GetAdapter( | |
1915 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1916 base::Unretained(this))); | |
1917 | |
1918 // Call the adapter callback; | |
1919 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1920 // the property set. | |
1921 MockBluetoothAdapterClient::Properties adapter_properties; | |
1922 adapter_properties.address.ReplaceValue(adapter_address); | |
1923 | |
1924 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1925 .WillRepeatedly(Return(&adapter_properties)); | |
1926 | |
1927 adapter_callback.Run(adapter_path, true); | |
1928 | |
1929 // Ask the adapter to start discovering devices; | |
1930 // BluetoothAdapterClient::StartDiscovery will be called. | |
1931 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
1932 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1933 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1934 | |
1935 adapter_->StartDiscovering( | |
1936 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1937 base::Unretained(this)), | |
1938 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1939 base::Unretained(this))); | |
1940 | |
1941 // Return to indicate success. | |
1942 start_discovery_callback.Run(adapter_path, true); | |
1943 | |
1944 // Ask the adapter to stop discovering devices; | |
1945 // BluetoothAdapterClient::StopDiscovery will be called. | |
1946 BluetoothAdapterClient::AdapterCallback stop_discovery_callback; | |
1947 EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _)) | |
1948 .WillOnce(SaveArg<1>(&stop_discovery_callback)); | |
1949 | |
1950 callback_called_ = false; | |
1951 error_callback_called_ = false; | |
1952 | |
1953 adapter_->StopDiscovering( | |
1954 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
1955 base::Unretained(this)), | |
1956 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
1957 base::Unretained(this))); | |
1958 | |
1959 // Return to indicate failure. | |
1960 stop_discovery_callback.Run(adapter_path, false); | |
1961 | |
1962 EXPECT_FALSE(callback_called_); | |
1963 EXPECT_TRUE(error_callback_called_); | |
1964 } | |
1965 | |
1966 TEST_F(BluetoothAdapterChromeOSTest, | |
1967 DefaultAdapterStopDiscoveringAfterSecondStart) { | |
1968 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1969 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1970 | |
1971 // Create the default adapter instance; | |
1972 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1973 // a callback to obtain the adapter path. | |
1974 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1975 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1976 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1977 | |
1978 BluetoothAdapterFactory::GetAdapter( | |
1979 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
1980 base::Unretained(this))); | |
1981 | |
1982 // Call the adapter callback; | |
1983 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1984 // the property set. | |
1985 MockBluetoothAdapterClient::Properties adapter_properties; | |
1986 adapter_properties.address.ReplaceValue(adapter_address); | |
1987 | |
1988 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1989 .WillRepeatedly(Return(&adapter_properties)); | |
1990 | |
1991 adapter_callback.Run(adapter_path, true); | |
1992 | |
1993 // Ask the adapter to start discovering devices; | |
1994 // BluetoothAdapterClient::StartDiscovery will be called. | |
1995 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
1996 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
1997 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
1998 | |
1999 adapter_->StartDiscovering( | |
2000 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2001 base::Unretained(this)), | |
2002 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2003 base::Unretained(this))); | |
2004 | |
2005 // Return to indicate success. | |
2006 start_discovery_callback.Run(adapter_path, true); | |
2007 | |
2008 // Ask the adapter to start discovering devices again; | |
2009 // BluetoothAdapterClient::StartDiscovery will be called again. | |
2010 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
2011 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
2012 | |
2013 callback_called_ = false; | |
2014 error_callback_called_ = false; | |
2015 | |
2016 adapter_->StartDiscovering( | |
2017 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2018 base::Unretained(this)), | |
2019 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2020 base::Unretained(this))); | |
2021 | |
2022 // Return to indicate success. | |
2023 start_discovery_callback.Run(adapter_path, true); | |
2024 | |
2025 // Ask the adapter to stop discovering devices; | |
2026 // BluetoothAdapterClient::StopDiscovery will be called. | |
2027 BluetoothAdapterClient::AdapterCallback stop_discovery_callback; | |
2028 EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _)) | |
2029 .WillOnce(SaveArg<1>(&stop_discovery_callback)); | |
2030 | |
2031 callback_called_ = false; | |
2032 error_callback_called_ = false; | |
2033 | |
2034 adapter_->StopDiscovering( | |
2035 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2036 base::Unretained(this)), | |
2037 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2038 base::Unretained(this))); | |
2039 | |
2040 // Return to indicate success. | |
2041 stop_discovery_callback.Run(adapter_path, true); | |
2042 | |
2043 EXPECT_TRUE(callback_called_); | |
2044 EXPECT_FALSE(error_callback_called_); | |
2045 } | |
2046 | |
2047 TEST_F(BluetoothAdapterChromeOSTest, | |
2048 DefaultAdapterStopDiscoveringAfterSecondStartError) { | |
2049 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
2050 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
2051 | |
2052 // Create the default adapter instance; | |
2053 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
2054 // a callback to obtain the adapter path. | |
2055 BluetoothManagerClient::AdapterCallback adapter_callback; | |
2056 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
2057 .WillOnce(SaveArg<0>(&adapter_callback)); | |
2058 | |
2059 BluetoothAdapterFactory::GetAdapter( | |
2060 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
2061 base::Unretained(this))); | |
2062 | |
2063 // Call the adapter callback; | |
2064 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
2065 // the property set. | |
2066 MockBluetoothAdapterClient::Properties adapter_properties; | |
2067 adapter_properties.address.ReplaceValue(adapter_address); | |
2068 | |
2069 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
2070 .WillRepeatedly(Return(&adapter_properties)); | |
2071 | |
2072 adapter_callback.Run(adapter_path, true); | |
2073 | |
2074 // Ask the adapter to start discovering devices; | |
2075 // BluetoothAdapterClient::StartDiscovery will be called. | |
2076 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
2077 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
2078 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
2079 | |
2080 adapter_->StartDiscovering( | |
2081 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2082 base::Unretained(this)), | |
2083 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2084 base::Unretained(this))); | |
2085 | |
2086 // Return to indicate success. | |
2087 start_discovery_callback.Run(adapter_path, true); | |
2088 | |
2089 // Ask the adapter to start discovering devices again; | |
2090 // BluetoothAdapterClient::StartDiscovery will be called again. | |
2091 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
2092 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
2093 | |
2094 callback_called_ = false; | |
2095 error_callback_called_ = false; | |
2096 | |
2097 adapter_->StartDiscovering( | |
2098 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2099 base::Unretained(this)), | |
2100 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2101 base::Unretained(this))); | |
2102 | |
2103 // Return to indicate failure. | |
2104 start_discovery_callback.Run(adapter_path, false); | |
2105 | |
2106 // Ask the adapter to stop discovering devices; | |
2107 // BluetoothAdapterClient::StopDiscovery will be called. | |
2108 BluetoothAdapterClient::AdapterCallback stop_discovery_callback; | |
2109 EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _)) | |
2110 .WillOnce(SaveArg<1>(&stop_discovery_callback)); | |
2111 | |
2112 callback_called_ = false; | |
2113 error_callback_called_ = false; | |
2114 | |
2115 adapter_->StopDiscovering( | |
2116 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2117 base::Unretained(this)), | |
2118 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2119 base::Unretained(this))); | |
2120 | |
2121 // Return to indicate success. | |
2122 stop_discovery_callback.Run(adapter_path, true); | |
2123 | |
2124 EXPECT_TRUE(callback_called_); | |
2125 EXPECT_FALSE(error_callback_called_); | |
2126 } | |
2127 | |
2128 TEST_F(BluetoothAdapterChromeOSTest, | |
2129 DefaultAdapterSecondStopDiscoveringAfterSecondStart) { | |
2130 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
2131 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
2132 | |
2133 // Create the default adapter instance; | |
2134 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
2135 // a callback to obtain the adapter path. | |
2136 BluetoothManagerClient::AdapterCallback adapter_callback; | |
2137 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
2138 .WillOnce(SaveArg<0>(&adapter_callback)); | |
2139 | |
2140 BluetoothAdapterFactory::GetAdapter( | |
2141 base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter, | |
2142 base::Unretained(this))); | |
2143 | |
2144 // Call the adapter callback; | |
2145 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
2146 // the property set. | |
2147 MockBluetoothAdapterClient::Properties adapter_properties; | |
2148 adapter_properties.address.ReplaceValue(adapter_address); | |
2149 | |
2150 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
2151 .WillRepeatedly(Return(&adapter_properties)); | |
2152 | |
2153 adapter_callback.Run(adapter_path, true); | |
2154 | |
2155 // Ask the adapter to start discovering devices; | |
2156 // BluetoothAdapterClient::StartDiscovery will be called. | |
2157 BluetoothAdapterClient::AdapterCallback start_discovery_callback; | |
2158 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
2159 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
2160 | |
2161 adapter_->StartDiscovering( | |
2162 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2163 base::Unretained(this)), | |
2164 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2165 base::Unretained(this))); | |
2166 | |
2167 // Return to indicate success. | |
2168 start_discovery_callback.Run(adapter_path, true); | |
2169 | |
2170 // Ask the adapter to start discovering devices again; | |
2171 // BluetoothAdapterClient::StartDiscovery will be called again. | |
2172 EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _)) | |
2173 .WillOnce(SaveArg<1>(&start_discovery_callback)); | |
2174 | |
2175 callback_called_ = false; | |
2176 error_callback_called_ = false; | |
2177 | |
2178 adapter_->StartDiscovering( | |
2179 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2180 base::Unretained(this)), | |
2181 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2182 base::Unretained(this))); | |
2183 | |
2184 // Return to indicate success. | |
2185 start_discovery_callback.Run(adapter_path, true); | |
2186 | |
2187 // Ask the adapter to stop discovering devices; | |
2188 // BluetoothAdapterClient::StopDiscovery will be called. | |
2189 BluetoothAdapterClient::AdapterCallback stop_discovery_callback; | |
2190 EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _)) | |
2191 .WillOnce(SaveArg<1>(&stop_discovery_callback)); | |
2192 | |
2193 callback_called_ = false; | |
2194 error_callback_called_ = false; | |
2195 | |
2196 adapter_->StopDiscovering( | |
2197 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2198 base::Unretained(this)), | |
2199 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2200 base::Unretained(this))); | |
2201 | |
2202 // Return to indicate success. | |
2203 stop_discovery_callback.Run(adapter_path, true); | |
2204 | |
2205 // Ask the adapter to stop discovering devices again; | |
2206 // BluetoothAdapterClient::StopDiscovery will be called. | |
2207 EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _)) | |
2208 .WillOnce(SaveArg<1>(&stop_discovery_callback)); | |
2209 | |
2210 callback_called_ = false; | |
2211 error_callback_called_ = false; | |
2212 | |
2213 adapter_->StopDiscovering( | |
2214 base::Bind(&BluetoothAdapterChromeOSTest::Callback, | |
2215 base::Unretained(this)), | |
2216 base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback, | |
2217 base::Unretained(this))); | |
2218 | |
2219 // Return to indicate success. | |
2220 stop_discovery_callback.Run(adapter_path, true); | |
2221 | |
2222 EXPECT_TRUE(callback_called_); | |
2223 EXPECT_FALSE(error_callback_called_); | |
2224 } | |
2225 | |
2226 } // namespace chromeos | |
OLD | NEW |