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 "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | |
6 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" | |
7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" | |
8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" | |
9 #include "chromeos/dbus/mock_bluetooth_adapter_client.h" | |
10 #include "chromeos/dbus/mock_bluetooth_manager_client.h" | |
11 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
12 #include "dbus/object_path.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 using ::testing::_; | |
16 using ::testing::InSequence; | |
17 using ::testing::Return; | |
18 using ::testing::SaveArg; | |
19 | |
20 namespace chromeos { | |
21 | |
22 class BluetoothAdapterChromeOsTest : public testing::Test { | |
23 public: | |
24 virtual void SetUp() { | |
25 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | |
26 | |
27 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | |
28 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | |
29 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | |
30 | |
31 mock_manager_client_ = | |
32 mock_dbus_thread_manager->mock_bluetooth_manager_client(); | |
33 mock_adapter_client_ = | |
34 mock_dbus_thread_manager->mock_bluetooth_adapter_client(); | |
35 | |
36 set_callback_called_ = false; | |
37 error_callback_called_ = false; | |
38 } | |
39 | |
40 virtual void TearDown() { | |
41 DBusThreadManager::Shutdown(); | |
42 } | |
43 | |
44 void SetCallback() { | |
45 set_callback_called_ = true; | |
46 } | |
47 | |
48 void ErrorCallback() { | |
49 error_callback_called_ = true; | |
50 } | |
51 | |
52 protected: | |
53 MockBluetoothManagerClient* mock_manager_client_; | |
54 MockBluetoothAdapterClient* mock_adapter_client_; | |
55 | |
56 bool set_callback_called_; | |
57 bool error_callback_called_; | |
58 }; | |
59 | |
60 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterNotPresent) { | |
61 // Create the default adapter instance; | |
62 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
63 // a callback to obtain the adapter path. | |
64 BluetoothManagerClient::AdapterCallback adapter_callback; | |
65 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
66 .WillOnce(SaveArg<0>(&adapter_callback)); | |
67 | |
68 scoped_refptr<BluetoothAdapter> adapter = | |
69 BluetoothAdapterFactory::DefaultAdapter(); | |
70 | |
71 // Call the adapter callback; make out it failed. | |
72 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | |
73 MockBluetoothAdapter::Observer adapter_observer; | |
74 adapter->AddObserver(&adapter_observer); | |
75 | |
76 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | |
77 .Times(0); | |
78 | |
79 adapter_callback.Run(dbus::ObjectPath(""), false); | |
80 | |
81 // Adapter should not be present. | |
82 EXPECT_FALSE(adapter->IsPresent()); | |
83 } | |
84 | |
85 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithAddress) { | |
86 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
87 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
88 | |
89 // Create the default adapter instance; | |
90 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
91 // a callback to obtain the adapter path. | |
92 BluetoothManagerClient::AdapterCallback adapter_callback; | |
93 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
94 .WillOnce(SaveArg<0>(&adapter_callback)); | |
95 | |
96 scoped_refptr<BluetoothAdapter> adapter = | |
97 BluetoothAdapterFactory::DefaultAdapter(); | |
98 | |
99 // Call the adapter callback; | |
100 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
101 // the property set. | |
102 MockBluetoothAdapterClient::Properties adapter_properties; | |
103 adapter_properties.address.ReplaceValue(adapter_address); | |
104 | |
105 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
106 .WillRepeatedly(Return(&adapter_properties)); | |
107 | |
108 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to | |
109 // indicate the adapter is now present. | |
110 MockBluetoothAdapter::Observer adapter_observer; | |
111 adapter->AddObserver(&adapter_observer); | |
112 | |
113 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
114 .Times(1); | |
115 | |
116 adapter_callback.Run(adapter_path, true); | |
117 | |
118 // Adapter should be present with the given address. | |
119 EXPECT_TRUE(adapter->IsPresent()); | |
120 EXPECT_EQ(adapter_address, adapter->address()); | |
121 } | |
122 | |
123 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithoutAddress) { | |
124 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
125 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
126 | |
127 // Create the default adapter instance; | |
128 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
129 // a callback to obtain the adapter path. | |
130 BluetoothManagerClient::AdapterCallback adapter_callback; | |
131 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
132 .WillOnce(SaveArg<0>(&adapter_callback)); | |
133 | |
134 scoped_refptr<BluetoothAdapter> adapter = | |
135 BluetoothAdapterFactory::DefaultAdapter(); | |
136 | |
137 // Call the adapter callback; | |
138 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
139 // the property set. | |
140 MockBluetoothAdapterClient::Properties adapter_properties; | |
141 | |
142 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
143 .WillRepeatedly(Return(&adapter_properties)); | |
144 | |
145 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | |
146 // yet. | |
147 MockBluetoothAdapter::Observer adapter_observer; | |
148 adapter->AddObserver(&adapter_observer); | |
149 | |
150 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | |
151 .Times(0); | |
152 | |
153 adapter_callback.Run(adapter_path, true); | |
154 | |
155 // Adapter should not be present yet. | |
156 EXPECT_FALSE(adapter->IsPresent()); | |
157 | |
158 // Tell the adapter the address now; | |
159 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | |
160 adapter_properties.address.ReplaceValue(adapter_address); | |
161 | |
162 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
163 .Times(1); | |
164 | |
165 BluetoothAdapterChromeOs* adapter_chromeos = | |
166 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
167 | |
168 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
169 ->AdapterPropertyChanged(adapter_path, | |
170 adapter_properties.address.name()); | |
171 | |
172 // Adapter should be present with the given address. | |
173 EXPECT_TRUE(adapter->IsPresent()); | |
174 EXPECT_EQ(adapter_address, adapter->address()); | |
175 } | |
176 | |
177 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterBecomesPresentWithAddress) { | |
178 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
179 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
180 | |
181 // Create the default adapter instance; | |
182 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
183 // a callback to obtain the adapter path. | |
184 BluetoothManagerClient::AdapterCallback adapter_callback; | |
185 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
186 .WillOnce(SaveArg<0>(&adapter_callback)); | |
187 | |
188 scoped_refptr<BluetoothAdapter> adapter = | |
189 BluetoothAdapterFactory::DefaultAdapter(); | |
190 | |
191 // Call the adapter callback; make out it failed. | |
192 adapter_callback.Run(dbus::ObjectPath(""), false); | |
193 | |
194 // Tell the adapter the default adapter changed; | |
195 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
196 // the property set. | |
197 MockBluetoothAdapterClient::Properties adapter_properties; | |
198 adapter_properties.address.ReplaceValue(adapter_address); | |
199 | |
200 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
201 .WillRepeatedly(Return(&adapter_properties)); | |
202 | |
203 // BluetoothAdapter::Observer::AdapterPresentChanged must be called. | |
204 MockBluetoothAdapter::Observer adapter_observer; | |
205 adapter->AddObserver(&adapter_observer); | |
206 | |
207 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
208 .Times(1); | |
209 | |
210 BluetoothAdapterChromeOs* adapter_chromeos = | |
211 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
212 | |
213 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
214 ->DefaultAdapterChanged(adapter_path); | |
215 | |
216 // Adapter should be present with the new address. | |
217 EXPECT_TRUE(adapter->IsPresent()); | |
218 EXPECT_EQ(adapter_address, adapter->address()); | |
219 } | |
220 | |
221 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterReplacedWithAddress) { | |
222 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
223 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
224 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
225 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
226 | |
227 // Create the default adapter instance; | |
228 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
229 // a callback to obtain the adapter path. | |
230 BluetoothManagerClient::AdapterCallback adapter_callback; | |
231 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
232 .WillOnce(SaveArg<0>(&adapter_callback)); | |
233 | |
234 scoped_refptr<BluetoothAdapter> adapter = | |
235 BluetoothAdapterFactory::DefaultAdapter(); | |
236 | |
237 // Call the adapter callback; | |
238 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
239 // the property set. | |
240 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
241 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
242 | |
243 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
244 .WillRepeatedly(Return(&initial_adapter_properties)); | |
245 | |
246 adapter_callback.Run(initial_adapter_path, true); | |
247 | |
248 // Tell the adapter the default adapter changed; | |
249 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
250 // the property set. | |
251 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
252 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
253 | |
254 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
255 .WillRepeatedly(Return(&new_adapter_properties)); | |
256 | |
257 // BluetoothAdapter::Observer::AdapterPresentChanged must be called once | |
258 // with false to indicate the old adapter being removed and once with true | |
259 // to announce the new adapter. | |
260 MockBluetoothAdapter::Observer adapter_observer; | |
261 adapter->AddObserver(&adapter_observer); | |
262 | |
263 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
264 .Times(1); | |
265 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
266 .Times(1); | |
267 | |
268 BluetoothAdapterChromeOs* adapter_chromeos = | |
269 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
270 | |
271 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
272 ->DefaultAdapterChanged(new_adapter_path); | |
273 | |
274 // Adapter should be present with the new address. | |
275 EXPECT_TRUE(adapter->IsPresent()); | |
276 EXPECT_EQ(new_adapter_address, adapter->address()); | |
277 } | |
278 | |
279 TEST_F(BluetoothAdapterChromeOsTest, | |
280 DefaultAdapterBecomesPresentWithoutAddress) { | |
281 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
282 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
283 | |
284 // Create the default adapter instance; | |
285 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
286 // a callback to obtain the adapter path. | |
287 BluetoothManagerClient::AdapterCallback adapter_callback; | |
288 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
289 .WillOnce(SaveArg<0>(&adapter_callback)); | |
290 | |
291 scoped_refptr<BluetoothAdapter> adapter = | |
292 BluetoothAdapterFactory::DefaultAdapter(); | |
293 | |
294 // Call the adapter callback; make out it failed. | |
295 adapter_callback.Run(dbus::ObjectPath(""), false); | |
296 | |
297 // Tell the adapter the default adapter changed; | |
298 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
299 // the property set. | |
300 MockBluetoothAdapterClient::Properties adapter_properties; | |
301 | |
302 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
303 .WillRepeatedly(Return(&adapter_properties)); | |
304 | |
305 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | |
306 MockBluetoothAdapter::Observer adapter_observer; | |
307 adapter->AddObserver(&adapter_observer); | |
308 | |
309 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | |
310 .Times(0); | |
311 | |
312 BluetoothAdapterChromeOs* adapter_chromeos = | |
313 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
314 | |
315 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
316 ->DefaultAdapterChanged(adapter_path); | |
317 | |
318 // Adapter should not be present yet. | |
319 EXPECT_FALSE(adapter->IsPresent()); | |
320 | |
321 // Tell the adapter the address now; | |
322 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | |
323 adapter_properties.address.ReplaceValue(adapter_address); | |
324 | |
325 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
326 .Times(1); | |
327 | |
328 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
329 ->AdapterPropertyChanged(adapter_path, | |
330 adapter_properties.address.name()); | |
331 | |
332 // Adapter should be present with the new address. | |
333 EXPECT_TRUE(adapter->IsPresent()); | |
334 EXPECT_EQ(adapter_address, adapter->address()); | |
335 } | |
336 | |
337 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterReplacedWithoutAddress) { | |
338 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
339 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
340 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
341 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
342 | |
343 // Create the default adapter instance; | |
344 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
345 // a callback to obtain the adapter path. | |
346 BluetoothManagerClient::AdapterCallback adapter_callback; | |
347 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
348 .WillOnce(SaveArg<0>(&adapter_callback)); | |
349 | |
350 scoped_refptr<BluetoothAdapter> adapter = | |
351 BluetoothAdapterFactory::DefaultAdapter(); | |
352 | |
353 // Call the adapter callback; | |
354 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
355 // the property set. | |
356 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
357 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
358 | |
359 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
360 .WillRepeatedly(Return(&initial_adapter_properties)); | |
361 | |
362 adapter_callback.Run(initial_adapter_path, true); | |
363 | |
364 // Tell the adapter the default adapter changed; | |
365 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
366 // the property set. | |
367 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
368 | |
369 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
370 .WillRepeatedly(Return(&new_adapter_properties)); | |
371 | |
372 // BluetoothAdapter::Observer::AdapterPresentChanged must be called to | |
373 // indicate the adapter has gone away. | |
374 MockBluetoothAdapter::Observer adapter_observer; | |
375 adapter->AddObserver(&adapter_observer); | |
376 | |
377 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
378 .Times(1); | |
379 | |
380 BluetoothAdapterChromeOs* adapter_chromeos = | |
381 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
382 | |
383 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
384 ->DefaultAdapterChanged(new_adapter_path); | |
385 | |
386 // Adapter should be now marked not present. | |
387 EXPECT_FALSE(adapter->IsPresent()); | |
388 | |
389 // Tell the adapter the address now; | |
390 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | |
391 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
392 | |
393 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
394 .Times(1); | |
395 | |
396 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
397 ->AdapterPropertyChanged(new_adapter_path, | |
398 new_adapter_properties.address.name()); | |
399 | |
400 // Adapter should be present with the new address. | |
401 EXPECT_TRUE(adapter->IsPresent()); | |
402 EXPECT_EQ(new_adapter_address, adapter->address()); | |
403 } | |
404 | |
405 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterRemoved) { | |
406 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
407 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
408 | |
409 // Create the default adapter instance; | |
410 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
411 // a callback to obtain the adapter path. | |
412 BluetoothManagerClient::AdapterCallback adapter_callback; | |
413 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
414 .WillOnce(SaveArg<0>(&adapter_callback)); | |
415 | |
416 scoped_refptr<BluetoothAdapter> adapter = | |
417 BluetoothAdapterFactory::DefaultAdapter(); | |
418 | |
419 // Call the adapter callback; | |
420 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
421 // the property set. | |
422 MockBluetoothAdapterClient::Properties adapter_properties; | |
423 adapter_properties.address.ReplaceValue(adapter_address); | |
424 | |
425 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
426 .WillRepeatedly(Return(&adapter_properties)); | |
427 | |
428 adapter_callback.Run(adapter_path, true); | |
429 | |
430 // Report that the adapter has been removed; | |
431 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to | |
432 // indicate the adapter is no longer present. | |
433 MockBluetoothAdapter::Observer adapter_observer; | |
434 adapter->AddObserver(&adapter_observer); | |
435 | |
436 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
437 .Times(1); | |
438 | |
439 BluetoothAdapterChromeOs* adapter_chromeos = | |
440 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
441 | |
442 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
443 ->AdapterRemoved(adapter_path); | |
444 | |
445 // Adapter should be no longer present. | |
446 EXPECT_FALSE(adapter->IsPresent()); | |
447 } | |
448 | |
449 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithoutAddressRemoved) { | |
450 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
451 | |
452 // Create the default adapter instance; | |
453 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
454 // a callback to obtain the adapter path. | |
455 BluetoothManagerClient::AdapterCallback adapter_callback; | |
456 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
457 .WillOnce(SaveArg<0>(&adapter_callback)); | |
458 | |
459 scoped_refptr<BluetoothAdapter> adapter = | |
460 BluetoothAdapterFactory::DefaultAdapter(); | |
461 | |
462 // Call the adapter callback; | |
463 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
464 // the property set. | |
465 MockBluetoothAdapterClient::Properties adapter_properties; | |
466 | |
467 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
468 .WillRepeatedly(Return(&adapter_properties)); | |
469 | |
470 adapter_callback.Run(adapter_path, true); | |
471 | |
472 // Report that the adapter has been removed; | |
473 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | |
474 // since we never should have announced it in the first place. | |
475 MockBluetoothAdapter::Observer adapter_observer; | |
476 adapter->AddObserver(&adapter_observer); | |
477 | |
478 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | |
479 .Times(0); | |
480 | |
481 BluetoothAdapterChromeOs* adapter_chromeos = | |
482 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
483 | |
484 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
485 ->AdapterRemoved(adapter_path); | |
486 | |
487 // Adapter should be still no longer present. | |
488 EXPECT_FALSE(adapter->IsPresent()); | |
489 } | |
490 | |
491 TEST_F(BluetoothAdapterChromeOsTest, | |
492 DefaultAdapterPoweredPropertyInitiallyFalse) { | |
493 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
494 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
495 | |
496 // Create the default adapter instance; | |
497 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
498 // a callback to obtain the adapter path. | |
499 BluetoothManagerClient::AdapterCallback adapter_callback; | |
500 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
501 .WillOnce(SaveArg<0>(&adapter_callback)); | |
502 | |
503 scoped_refptr<BluetoothAdapter> adapter = | |
504 BluetoothAdapterFactory::DefaultAdapter(); | |
505 | |
506 // Call the adapter callback; | |
507 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
508 // the property set. | |
509 MockBluetoothAdapterClient::Properties adapter_properties; | |
510 adapter_properties.address.ReplaceValue(adapter_address); | |
511 adapter_properties.powered.ReplaceValue(false); | |
512 | |
513 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
514 .WillRepeatedly(Return(&adapter_properties)); | |
515 | |
516 adapter_callback.Run(adapter_path, true); | |
517 | |
518 // Adapter should have the correct property value. | |
519 EXPECT_FALSE(adapter->IsPowered()); | |
520 } | |
521 | |
522 TEST_F(BluetoothAdapterChromeOsTest, | |
523 DefaultAdapterPoweredPropertyInitiallyTrue) { | |
524 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
525 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
526 | |
527 // Create the default adapter instance; | |
528 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
529 // a callback to obtain the adapter path. | |
530 BluetoothManagerClient::AdapterCallback adapter_callback; | |
531 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
532 .WillOnce(SaveArg<0>(&adapter_callback)); | |
533 | |
534 scoped_refptr<BluetoothAdapter> adapter = | |
535 BluetoothAdapterFactory::DefaultAdapter(); | |
536 | |
537 // Call the adapter callback; | |
538 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
539 // the property set. | |
540 MockBluetoothAdapterClient::Properties adapter_properties; | |
541 adapter_properties.address.ReplaceValue(adapter_address); | |
542 adapter_properties.powered.ReplaceValue(true); | |
543 | |
544 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
545 .WillRepeatedly(Return(&adapter_properties)); | |
546 | |
547 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
548 MockBluetoothAdapter::Observer adapter_observer; | |
549 adapter->AddObserver(&adapter_observer); | |
550 | |
551 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
552 .Times(1); | |
553 | |
554 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | |
555 .Times(1); | |
556 | |
557 adapter_callback.Run(adapter_path, true); | |
558 | |
559 // Adapter should have the correct property value. | |
560 EXPECT_TRUE(adapter->IsPowered()); | |
561 } | |
562 | |
563 TEST_F(BluetoothAdapterChromeOsTest, | |
564 DefaultAdapterPoweredPropertyInitiallyTrueWithoutAddress) { | |
565 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
566 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
567 | |
568 // Create the default adapter instance; | |
569 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
570 // a callback to obtain the adapter path. | |
571 BluetoothManagerClient::AdapterCallback adapter_callback; | |
572 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
573 .WillOnce(SaveArg<0>(&adapter_callback)); | |
574 | |
575 scoped_refptr<BluetoothAdapter> adapter = | |
576 BluetoothAdapterFactory::DefaultAdapter(); | |
577 | |
578 // Call the adapter callback; | |
579 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
580 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged | |
581 // should not yet be called. | |
582 MockBluetoothAdapterClient::Properties adapter_properties; | |
583 adapter_properties.powered.ReplaceValue(true); | |
584 | |
585 MockBluetoothAdapter::Observer adapter_observer; | |
586 adapter->AddObserver(&adapter_observer); | |
587 | |
588 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
589 .WillRepeatedly(Return(&adapter_properties)); | |
590 | |
591 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | |
592 .Times(0); | |
593 | |
594 adapter_callback.Run(adapter_path, true); | |
595 | |
596 // Adapter should not yet have the property value. | |
597 EXPECT_FALSE(adapter->IsPowered()); | |
598 | |
599 // Tell the adapter the address now, | |
600 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
601 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. | |
602 adapter_properties.address.ReplaceValue(adapter_address); | |
603 | |
604 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
605 .Times(1); | |
606 | |
607 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | |
608 .Times(1); | |
609 | |
610 BluetoothAdapterChromeOs* adapter_chromeos = | |
611 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
612 | |
613 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
614 ->AdapterPropertyChanged(adapter_path, | |
615 adapter_properties.address.name()); | |
616 | |
617 // Adapter should have the correct property value. | |
618 EXPECT_TRUE(adapter->IsPowered()); | |
619 } | |
620 | |
621 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterPoweredPropertyChanged) { | |
622 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
623 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
624 | |
625 // Create the default adapter instance; | |
626 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
627 // a callback to obtain the adapter path. | |
628 BluetoothManagerClient::AdapterCallback adapter_callback; | |
629 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
630 .WillOnce(SaveArg<0>(&adapter_callback)); | |
631 | |
632 scoped_refptr<BluetoothAdapter> adapter = | |
633 BluetoothAdapterFactory::DefaultAdapter(); | |
634 | |
635 // Call the adapter callback; | |
636 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
637 // the property set. | |
638 MockBluetoothAdapterClient::Properties adapter_properties; | |
639 adapter_properties.address.ReplaceValue(adapter_address); | |
640 adapter_properties.powered.ReplaceValue(false); | |
641 | |
642 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
643 .WillRepeatedly(Return(&adapter_properties)); | |
644 | |
645 adapter_callback.Run(adapter_path, true); | |
646 | |
647 // Adapter should have the correct property value. | |
648 EXPECT_FALSE(adapter->IsPowered()); | |
649 | |
650 // Report that the property has been changed; | |
651 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
652 MockBluetoothAdapter::Observer adapter_observer; | |
653 adapter->AddObserver(&adapter_observer); | |
654 | |
655 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | |
656 .Times(1); | |
657 | |
658 adapter_properties.powered.ReplaceValue(true); | |
659 | |
660 BluetoothAdapterChromeOs* adapter_chromeos = | |
661 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
662 | |
663 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
664 ->AdapterPropertyChanged(adapter_path, | |
665 adapter_properties.powered.name()); | |
666 | |
667 // Adapter should have the new property values. | |
668 EXPECT_TRUE(adapter->IsPowered()); | |
669 } | |
670 | |
671 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterPoweredPropertyUnchanged) { | |
672 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
673 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
674 | |
675 // Create the default adapter instance; | |
676 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
677 // a callback to obtain the adapter path. | |
678 BluetoothManagerClient::AdapterCallback adapter_callback; | |
679 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
680 .WillOnce(SaveArg<0>(&adapter_callback)); | |
681 | |
682 scoped_refptr<BluetoothAdapter> adapter = | |
683 BluetoothAdapterFactory::DefaultAdapter(); | |
684 | |
685 // Call the adapter callback; | |
686 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
687 // the property set. | |
688 MockBluetoothAdapterClient::Properties adapter_properties; | |
689 adapter_properties.address.ReplaceValue(adapter_address); | |
690 adapter_properties.powered.ReplaceValue(true); | |
691 | |
692 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
693 .WillRepeatedly(Return(&adapter_properties)); | |
694 | |
695 adapter_callback.Run(adapter_path, true); | |
696 | |
697 // Adapter should have the correct property value. | |
698 EXPECT_TRUE(adapter->IsPowered()); | |
699 | |
700 // Report that the property has been changed, but don't change the value; | |
701 // BluetoothAdapter::Observer::AdapterPoweredChanged should not be called. | |
702 MockBluetoothAdapter::Observer adapter_observer; | |
703 adapter->AddObserver(&adapter_observer); | |
704 | |
705 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | |
706 .Times(0); | |
707 | |
708 BluetoothAdapterChromeOs* adapter_chromeos = | |
709 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
710 | |
711 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
712 ->AdapterPropertyChanged(adapter_path, | |
713 adapter_properties.powered.name()); | |
714 | |
715 // Adapter should still have the same property values. | |
716 EXPECT_TRUE(adapter->IsPowered()); | |
717 } | |
718 | |
719 TEST_F(BluetoothAdapterChromeOsTest, | |
720 DefaultAdapterPoweredPropertyChangedWithoutAddress) { | |
721 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
722 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
723 | |
724 // Create the default adapter instance; | |
725 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
726 // a callback to obtain the adapter path. | |
727 BluetoothManagerClient::AdapterCallback adapter_callback; | |
728 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
729 .WillOnce(SaveArg<0>(&adapter_callback)); | |
730 | |
731 scoped_refptr<BluetoothAdapter> adapter = | |
732 BluetoothAdapterFactory::DefaultAdapter(); | |
733 | |
734 // Call the adapter callback; | |
735 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
736 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged | |
737 // should not yet be called. | |
738 MockBluetoothAdapterClient::Properties adapter_properties; | |
739 | |
740 MockBluetoothAdapter::Observer adapter_observer; | |
741 adapter->AddObserver(&adapter_observer); | |
742 | |
743 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
744 .WillRepeatedly(Return(&adapter_properties)); | |
745 | |
746 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | |
747 .Times(0); | |
748 | |
749 adapter_callback.Run(adapter_path, true); | |
750 | |
751 // Tell the adapter that its powered property changed, the observer | |
752 // method should still not be called because there is no address for | |
753 // the adapter so it is not present. | |
754 adapter_properties.powered.ReplaceValue(true); | |
755 | |
756 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | |
757 .Times(0); | |
758 | |
759 BluetoothAdapterChromeOs* adapter_chromeos = | |
760 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
761 | |
762 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
763 ->AdapterPropertyChanged(adapter_path, | |
764 adapter_properties.powered.name()); | |
765 | |
766 // Adapter should not yet have the property value. | |
767 EXPECT_FALSE(adapter->IsPowered()); | |
768 | |
769 // Tell the adapter the address now, | |
770 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
771 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. | |
772 adapter_properties.address.ReplaceValue(adapter_address); | |
773 | |
774 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
775 .Times(1); | |
776 | |
777 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | |
778 .Times(1); | |
779 | |
780 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
781 ->AdapterPropertyChanged(adapter_path, | |
782 adapter_properties.address.name()); | |
783 | |
784 // Adapter should now have the correct property value. | |
785 EXPECT_TRUE(adapter->IsPowered()); | |
786 } | |
787 | |
788 TEST_F(BluetoothAdapterChromeOsTest, | |
789 DefaultAdapterPoweredPropertyResetOnReplace) { | |
790 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
791 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
792 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
793 const std::string new_adapter_address = "00:C0:11:CO:FE:FE"; | |
794 | |
795 // Create the default adapter instance; | |
796 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
797 // a callback to obtain the adapter path. | |
798 BluetoothManagerClient::AdapterCallback adapter_callback; | |
799 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
800 .WillOnce(SaveArg<0>(&adapter_callback)); | |
801 | |
802 scoped_refptr<BluetoothAdapter> adapter = | |
803 BluetoothAdapterFactory::DefaultAdapter(); | |
804 | |
805 // Call the adapter callback; | |
806 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
807 // the property set. | |
808 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
809 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
810 initial_adapter_properties.powered.ReplaceValue(true); | |
811 | |
812 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
813 .WillRepeatedly(Return(&initial_adapter_properties)); | |
814 | |
815 adapter_callback.Run(initial_adapter_path, true); | |
816 | |
817 // Tell the adapter the default adapter changed; | |
818 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
819 // the property set. | |
820 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
821 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
822 | |
823 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
824 .WillRepeatedly(Return(&new_adapter_properties)); | |
825 | |
826 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
827 MockBluetoothAdapter::Observer adapter_observer; | |
828 adapter->AddObserver(&adapter_observer); | |
829 | |
830 { | |
831 InSequence s; | |
832 | |
833 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
834 .Times(1); | |
835 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
836 .Times(1); | |
837 } | |
838 | |
839 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), false)) | |
840 .Times(1); | |
841 | |
842 BluetoothAdapterChromeOs* adapter_chromeos = | |
843 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
844 | |
845 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
846 ->DefaultAdapterChanged(new_adapter_path); | |
847 | |
848 // Adapter should have the new property value. | |
849 EXPECT_FALSE(adapter->IsPowered()); | |
850 } | |
851 | |
852 TEST_F(BluetoothAdapterChromeOsTest, | |
853 DefaultAdapterPoweredPropertyResetOnReplaceWhenTrue) { | |
854 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
855 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
856 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
857 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
858 | |
859 // Create the default adapter instance; | |
860 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
861 // a callback to obtain the adapter path. | |
862 BluetoothManagerClient::AdapterCallback adapter_callback; | |
863 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
864 .WillOnce(SaveArg<0>(&adapter_callback)); | |
865 | |
866 scoped_refptr<BluetoothAdapter> adapter = | |
867 BluetoothAdapterFactory::DefaultAdapter(); | |
868 | |
869 // Call the adapter callback; | |
870 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
871 // the property set. | |
872 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
873 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
874 initial_adapter_properties.powered.ReplaceValue(true); | |
875 | |
876 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
877 .WillRepeatedly(Return(&initial_adapter_properties)); | |
878 | |
879 adapter_callback.Run(initial_adapter_path, true); | |
880 | |
881 // Tell the adapter the default adapter changed; | |
882 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
883 // the property set. | |
884 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
885 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
886 new_adapter_properties.powered.ReplaceValue(true); | |
887 | |
888 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
889 .WillRepeatedly(Return(&new_adapter_properties)); | |
890 | |
891 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called once | |
892 // to set the value to false for the previous adapter and once to set the | |
893 // value to true for the new adapter. | |
894 MockBluetoothAdapter::Observer adapter_observer; | |
895 adapter->AddObserver(&adapter_observer); | |
896 | |
897 { | |
898 InSequence s; | |
899 | |
900 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
901 .Times(1); | |
902 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
903 .Times(1); | |
904 } | |
905 | |
906 { | |
907 InSequence s; | |
908 | |
909 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), false)) | |
910 .Times(1); | |
911 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | |
912 .Times(1); | |
913 } | |
914 | |
915 BluetoothAdapterChromeOs* adapter_chromeos = | |
916 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
917 | |
918 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
919 ->DefaultAdapterChanged(new_adapter_path); | |
920 | |
921 // Adapter should have the new property value. | |
922 EXPECT_TRUE(adapter->IsPowered()); | |
923 } | |
924 | |
925 TEST_F(BluetoothAdapterChromeOsTest, | |
926 DefaultAdapterPoweredPropertyResetOnRemove) { | |
927 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
928 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
929 | |
930 // Create the default adapter instance; | |
931 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
932 // a callback to obtain the adapter path. | |
933 BluetoothManagerClient::AdapterCallback adapter_callback; | |
934 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
935 .WillOnce(SaveArg<0>(&adapter_callback)); | |
936 | |
937 scoped_refptr<BluetoothAdapter> adapter = | |
938 BluetoothAdapterFactory::DefaultAdapter(); | |
939 | |
940 // Call the adapter callback; | |
941 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
942 // the property set. | |
943 MockBluetoothAdapterClient::Properties adapter_properties; | |
944 adapter_properties.address.ReplaceValue(adapter_address); | |
945 adapter_properties.powered.ReplaceValue(true); | |
946 | |
947 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
948 .WillRepeatedly(Return(&adapter_properties)); | |
949 | |
950 adapter_callback.Run(adapter_path, true); | |
951 | |
952 // Report that the adapter has been removed; | |
953 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | |
954 MockBluetoothAdapter::Observer adapter_observer; | |
955 adapter->AddObserver(&adapter_observer); | |
956 | |
957 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
958 .Times(1); | |
959 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), false)) | |
960 .Times(1); | |
961 | |
962 BluetoothAdapterChromeOs* adapter_chromeos = | |
963 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
964 | |
965 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
966 ->AdapterRemoved(adapter_path); | |
967 | |
968 // Adapter should have the new property value. | |
969 EXPECT_FALSE(adapter->IsPowered()); | |
970 } | |
971 | |
972 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterSetPowered) { | |
973 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
974 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
975 | |
976 // Create the default adapter instance; | |
977 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
978 // a callback to obtain the adapter path. | |
979 BluetoothManagerClient::AdapterCallback adapter_callback; | |
980 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
981 .WillOnce(SaveArg<0>(&adapter_callback)); | |
982 | |
983 scoped_refptr<BluetoothAdapter> adapter = | |
984 BluetoothAdapterFactory::DefaultAdapter(); | |
985 | |
986 // Call the adapter callback; | |
987 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
988 // the property set. | |
989 MockBluetoothAdapterClient::Properties adapter_properties; | |
990 | |
991 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
992 .WillRepeatedly(Return(&adapter_properties)); | |
993 | |
994 adapter_callback.Run(adapter_path, true); | |
995 | |
996 // Request that the powered property be changed; | |
997 // MockBluetoothAdapterClient::Set should be called, passing the address | |
998 // of the powered property and a callback to receive the response. | |
999 dbus::PropertySet::SetCallback set_callback; | |
1000 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) | |
1001 .WillOnce(SaveArg<1>(&set_callback)); | |
1002 | |
1003 adapter->SetPowered(true, | |
1004 base::Bind(&BluetoothAdapterChromeOsTest::SetCallback, | |
1005 base::Unretained(this)), | |
1006 base::Bind(&BluetoothAdapterChromeOsTest::ErrorCallback, | |
1007 base::Unretained(this))); | |
1008 | |
1009 // Reply to the callback to indicate success, the set callback we provided | |
1010 // should be called but the properties should not be refetched. | |
1011 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1012 .Times(0); | |
1013 | |
1014 set_callback.Run(true); | |
1015 | |
1016 EXPECT_TRUE(set_callback_called_); | |
1017 EXPECT_FALSE(error_callback_called_); | |
1018 } | |
1019 | |
1020 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterSetPoweredError) { | |
1021 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1022 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1023 | |
1024 // Create the default adapter instance; | |
1025 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1026 // a callback to obtain the adapter path. | |
1027 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1028 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1029 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1030 | |
1031 scoped_refptr<BluetoothAdapter> adapter = | |
1032 BluetoothAdapterFactory::DefaultAdapter(); | |
1033 | |
1034 // Call the adapter callback; | |
1035 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1036 // the property set. | |
1037 MockBluetoothAdapterClient::Properties adapter_properties; | |
1038 | |
1039 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1040 .WillRepeatedly(Return(&adapter_properties)); | |
1041 | |
1042 adapter_callback.Run(adapter_path, true); | |
1043 | |
1044 // Request that the powered property be changed; | |
1045 // MockBluetoothAdapterClient::Set should be called, passing the address | |
1046 // of the powered property and a callback to receive the response. | |
1047 dbus::PropertySet::SetCallback set_callback; | |
1048 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) | |
1049 .WillOnce(SaveArg<1>(&set_callback)); | |
1050 | |
1051 adapter->SetPowered(true, | |
1052 base::Bind(&BluetoothAdapterChromeOsTest::SetCallback, | |
1053 base::Unretained(this)), | |
1054 base::Bind(&BluetoothAdapterChromeOsTest::ErrorCallback, | |
1055 base::Unretained(this))); | |
1056 | |
1057 // Reply to the callback to indicate failure, the error callback we provided | |
1058 // should be called but the properties should not be refetched. | |
1059 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1060 .Times(0); | |
1061 | |
1062 set_callback.Run(false); | |
1063 | |
1064 EXPECT_FALSE(set_callback_called_); | |
1065 EXPECT_TRUE(error_callback_called_); | |
1066 } | |
1067 | |
1068 TEST_F(BluetoothAdapterChromeOsTest, | |
1069 DefaultAdapterDiscoveringPropertyInitiallyFalse) { | |
1070 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1071 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1072 | |
1073 // Create the default adapter instance; | |
1074 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1075 // a callback to obtain the adapter path. | |
1076 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1077 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1078 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1079 | |
1080 scoped_refptr<BluetoothAdapter> adapter = | |
1081 BluetoothAdapterFactory::DefaultAdapter(); | |
1082 | |
1083 // Call the adapter callback; | |
1084 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1085 // the property set. | |
1086 MockBluetoothAdapterClient::Properties adapter_properties; | |
1087 adapter_properties.address.ReplaceValue(adapter_address); | |
1088 adapter_properties.discovering.ReplaceValue(false); | |
1089 | |
1090 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1091 .WillRepeatedly(Return(&adapter_properties)); | |
1092 | |
1093 adapter_callback.Run(adapter_path, true); | |
1094 | |
1095 // Adapter should have the correct property value. | |
1096 EXPECT_FALSE(adapter->IsDiscovering()); | |
1097 } | |
1098 | |
1099 TEST_F(BluetoothAdapterChromeOsTest, | |
1100 DefaultAdapterDiscoveringPropertyInitiallyTrue) { | |
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 scoped_refptr<BluetoothAdapter> adapter = | |
1112 BluetoothAdapterFactory::DefaultAdapter(); | |
1113 | |
1114 // Call the adapter callback; | |
1115 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1116 // the property set. | |
1117 MockBluetoothAdapterClient::Properties adapter_properties; | |
1118 adapter_properties.address.ReplaceValue(adapter_address); | |
1119 adapter_properties.discovering.ReplaceValue(true); | |
1120 | |
1121 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1122 .WillRepeatedly(Return(&adapter_properties)); | |
1123 | |
1124 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1125 MockBluetoothAdapter::Observer adapter_observer; | |
1126 adapter->AddObserver(&adapter_observer); | |
1127 | |
1128 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
1129 .Times(1); | |
1130 | |
1131 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | |
1132 .Times(1); | |
1133 | |
1134 adapter_callback.Run(adapter_path, true); | |
1135 | |
1136 // Adapter should have the correct property value. | |
1137 EXPECT_TRUE(adapter->IsDiscovering()); | |
1138 } | |
1139 | |
1140 TEST_F(BluetoothAdapterChromeOsTest, | |
1141 DefaultAdapterDiscoveringPropertyInitiallyTrueWithoutAddress) { | |
1142 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1143 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1144 | |
1145 // Create the default adapter instance; | |
1146 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1147 // a callback to obtain the adapter path. | |
1148 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1149 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1150 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1151 | |
1152 scoped_refptr<BluetoothAdapter> adapter = | |
1153 BluetoothAdapterFactory::DefaultAdapter(); | |
1154 | |
1155 // Call the adapter callback; | |
1156 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1157 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged | |
1158 // should not yet be called. | |
1159 MockBluetoothAdapterClient::Properties adapter_properties; | |
1160 adapter_properties.discovering.ReplaceValue(true); | |
1161 | |
1162 MockBluetoothAdapter::Observer adapter_observer; | |
1163 adapter->AddObserver(&adapter_observer); | |
1164 | |
1165 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1166 .WillRepeatedly(Return(&adapter_properties)); | |
1167 | |
1168 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | |
1169 .Times(0); | |
1170 | |
1171 adapter_callback.Run(adapter_path, true); | |
1172 | |
1173 // Adapter should not yet have the property value. | |
1174 EXPECT_FALSE(adapter->IsDiscovering()); | |
1175 | |
1176 // Tell the adapter the address now, | |
1177 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
1178 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. | |
1179 adapter_properties.address.ReplaceValue(adapter_address); | |
1180 | |
1181 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
1182 .Times(1); | |
1183 | |
1184 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | |
1185 .Times(1); | |
1186 | |
1187 BluetoothAdapterChromeOs* adapter_chromeos = | |
1188 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
1189 | |
1190 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1191 ->AdapterPropertyChanged(adapter_path, | |
1192 adapter_properties.address.name()); | |
1193 | |
1194 // Adapter should have the correct property value. | |
1195 EXPECT_TRUE(adapter->IsDiscovering()); | |
1196 } | |
1197 | |
1198 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterDiscoveringPropertyChanged) { | |
1199 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1200 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1201 | |
1202 // Create the default adapter instance; | |
1203 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1204 // a callback to obtain the adapter path. | |
1205 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1206 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1207 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1208 | |
1209 scoped_refptr<BluetoothAdapter> adapter = | |
1210 BluetoothAdapterFactory::DefaultAdapter(); | |
1211 | |
1212 // Call the adapter callback; | |
1213 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1214 // the property set. | |
1215 MockBluetoothAdapterClient::Properties adapter_properties; | |
1216 adapter_properties.address.ReplaceValue(adapter_address); | |
1217 adapter_properties.discovering.ReplaceValue(false); | |
1218 | |
1219 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1220 .WillRepeatedly(Return(&adapter_properties)); | |
1221 | |
1222 adapter_callback.Run(adapter_path, true); | |
1223 | |
1224 // Adapter should have the correct property value. | |
1225 EXPECT_FALSE(adapter->IsDiscovering()); | |
1226 | |
1227 // Report that the property has been changed; | |
1228 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1229 MockBluetoothAdapter::Observer adapter_observer; | |
1230 adapter->AddObserver(&adapter_observer); | |
1231 | |
1232 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | |
1233 .Times(1); | |
1234 | |
1235 adapter_properties.discovering.ReplaceValue(true); | |
1236 | |
1237 BluetoothAdapterChromeOs* adapter_chromeos = | |
1238 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
1239 | |
1240 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1241 ->AdapterPropertyChanged(adapter_path, | |
1242 adapter_properties.discovering.name()); | |
1243 | |
1244 // Adapter should have the new property values. | |
1245 EXPECT_TRUE(adapter->IsDiscovering()); | |
1246 } | |
1247 | |
1248 TEST_F(BluetoothAdapterChromeOsTest, | |
1249 DefaultAdapterDiscoveringPropertyUnchanged) { | |
1250 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1251 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1252 | |
1253 // Create the default adapter instance; | |
1254 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1255 // a callback to obtain the adapter path. | |
1256 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1257 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1258 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1259 | |
1260 scoped_refptr<BluetoothAdapter> adapter = | |
1261 BluetoothAdapterFactory::DefaultAdapter(); | |
1262 | |
1263 // Call the adapter callback; | |
1264 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1265 // the property set. | |
1266 MockBluetoothAdapterClient::Properties adapter_properties; | |
1267 adapter_properties.address.ReplaceValue(adapter_address); | |
1268 adapter_properties.discovering.ReplaceValue(true); | |
1269 | |
1270 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1271 .WillRepeatedly(Return(&adapter_properties)); | |
1272 | |
1273 adapter_callback.Run(adapter_path, true); | |
1274 | |
1275 // Adapter should have the correct property value. | |
1276 EXPECT_TRUE(adapter->IsDiscovering()); | |
1277 | |
1278 // Report that the property has been changed, but don't change the value; | |
1279 // BluetoothAdapter::Observer::AdapterDiscoveringChanged should not be | |
1280 // called. | |
1281 MockBluetoothAdapter::Observer adapter_observer; | |
1282 adapter->AddObserver(&adapter_observer); | |
1283 | |
1284 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | |
1285 .Times(0); | |
1286 | |
1287 BluetoothAdapterChromeOs* adapter_chromeos = | |
1288 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
1289 | |
1290 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1291 ->AdapterPropertyChanged(adapter_path, | |
1292 adapter_properties.discovering.name()); | |
1293 | |
1294 // Adapter should still have the same property values. | |
1295 EXPECT_TRUE(adapter->IsDiscovering()); | |
1296 } | |
1297 | |
1298 TEST_F(BluetoothAdapterChromeOsTest, | |
1299 DefaultAdapterDiscoveringPropertyChangedWithoutAddress) { | |
1300 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1301 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1302 | |
1303 // Create the default adapter instance; | |
1304 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1305 // a callback to obtain the adapter path. | |
1306 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1307 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1308 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1309 | |
1310 scoped_refptr<BluetoothAdapter> adapter = | |
1311 BluetoothAdapterFactory::DefaultAdapter(); | |
1312 | |
1313 // Call the adapter callback; | |
1314 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1315 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged | |
1316 // should not yet be called. | |
1317 MockBluetoothAdapterClient::Properties adapter_properties; | |
1318 | |
1319 MockBluetoothAdapter::Observer adapter_observer; | |
1320 adapter->AddObserver(&adapter_observer); | |
1321 | |
1322 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1323 .WillRepeatedly(Return(&adapter_properties)); | |
1324 | |
1325 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | |
1326 .Times(0); | |
1327 | |
1328 adapter_callback.Run(adapter_path, true); | |
1329 | |
1330 // Tell the adapter that its discovering property changed, the observer | |
1331 // method should still not be called because there is no address for | |
1332 // the adapter so it is not present. | |
1333 adapter_properties.discovering.ReplaceValue(true); | |
1334 | |
1335 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | |
1336 .Times(0); | |
1337 | |
1338 BluetoothAdapterChromeOs* adapter_chromeos = | |
1339 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
1340 | |
1341 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1342 ->AdapterPropertyChanged(adapter_path, | |
1343 adapter_properties.discovering.name()); | |
1344 | |
1345 // Adapter should not yet have the property value. | |
1346 EXPECT_FALSE(adapter->IsDiscovering()); | |
1347 | |
1348 // Tell the adapter the address now, | |
1349 // BluetoothAdapter::Observer::AdapterPresentChanged and | |
1350 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. | |
1351 adapter_properties.address.ReplaceValue(adapter_address); | |
1352 | |
1353 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
1354 .Times(1); | |
1355 | |
1356 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | |
1357 .Times(1); | |
1358 | |
1359 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | |
1360 ->AdapterPropertyChanged(adapter_path, | |
1361 adapter_properties.address.name()); | |
1362 | |
1363 // Adapter should now have the correct property value. | |
1364 EXPECT_TRUE(adapter->IsDiscovering()); | |
1365 } | |
1366 | |
1367 TEST_F(BluetoothAdapterChromeOsTest, | |
1368 DefaultAdapterDiscoveringPropertyResetOnReplace) { | |
1369 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
1370 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
1371 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1372 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
1373 | |
1374 // Create the default adapter instance; | |
1375 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1376 // a callback to obtain the adapter path. | |
1377 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1378 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1379 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1380 | |
1381 scoped_refptr<BluetoothAdapter> adapter = | |
1382 BluetoothAdapterFactory::DefaultAdapter(); | |
1383 | |
1384 // Call the adapter callback; | |
1385 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1386 // the property set. | |
1387 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
1388 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
1389 initial_adapter_properties.discovering.ReplaceValue(true); | |
1390 | |
1391 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
1392 .WillRepeatedly(Return(&initial_adapter_properties)); | |
1393 | |
1394 adapter_callback.Run(initial_adapter_path, true); | |
1395 | |
1396 // Tell the adapter the default adapter changed; | |
1397 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1398 // the property set. | |
1399 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
1400 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
1401 | |
1402 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
1403 .WillRepeatedly(Return(&new_adapter_properties)); | |
1404 | |
1405 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1406 MockBluetoothAdapter::Observer adapter_observer; | |
1407 adapter->AddObserver(&adapter_observer); | |
1408 | |
1409 { | |
1410 InSequence s; | |
1411 | |
1412 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
1413 .Times(1); | |
1414 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
1415 .Times(1); | |
1416 } | |
1417 | |
1418 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), false)) | |
1419 .Times(1); | |
1420 | |
1421 BluetoothAdapterChromeOs* adapter_chromeos = | |
1422 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
1423 | |
1424 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
1425 ->DefaultAdapterChanged(new_adapter_path); | |
1426 | |
1427 // Adapter should have the new property value. | |
1428 EXPECT_FALSE(adapter->IsDiscovering()); | |
1429 } | |
1430 | |
1431 TEST_F(BluetoothAdapterChromeOsTest, | |
1432 DefaultAdapterDiscoveringPropertyResetOnReplaceWhenTrue) { | |
1433 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | |
1434 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | |
1435 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1436 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | |
1437 | |
1438 // Create the default adapter instance; | |
1439 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1440 // a callback to obtain the adapter path. | |
1441 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1442 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1443 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1444 | |
1445 scoped_refptr<BluetoothAdapter> adapter = | |
1446 BluetoothAdapterFactory::DefaultAdapter(); | |
1447 | |
1448 // Call the adapter callback; | |
1449 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1450 // the property set. | |
1451 MockBluetoothAdapterClient::Properties initial_adapter_properties; | |
1452 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | |
1453 initial_adapter_properties.discovering.ReplaceValue(true); | |
1454 | |
1455 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | |
1456 .WillRepeatedly(Return(&initial_adapter_properties)); | |
1457 | |
1458 adapter_callback.Run(initial_adapter_path, true); | |
1459 | |
1460 // Tell the adapter the default adapter changed; | |
1461 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1462 // the property set. | |
1463 MockBluetoothAdapterClient::Properties new_adapter_properties; | |
1464 new_adapter_properties.address.ReplaceValue(new_adapter_address); | |
1465 new_adapter_properties.discovering.ReplaceValue(true); | |
1466 | |
1467 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | |
1468 .WillRepeatedly(Return(&new_adapter_properties)); | |
1469 | |
1470 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called once | |
1471 // to set the value to false for the previous adapter and once to set the | |
1472 // value to true for the new adapter. | |
1473 MockBluetoothAdapter::Observer adapter_observer; | |
1474 adapter->AddObserver(&adapter_observer); | |
1475 | |
1476 { | |
1477 InSequence s; | |
1478 | |
1479 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
1480 .Times(1); | |
1481 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | |
1482 .Times(1); | |
1483 } | |
1484 | |
1485 { | |
1486 InSequence s; | |
1487 | |
1488 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), | |
1489 false)) | |
1490 .Times(1); | |
1491 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), | |
1492 true)) | |
1493 .Times(1); | |
1494 } | |
1495 | |
1496 BluetoothAdapterChromeOs* adapter_chromeos = | |
1497 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
1498 | |
1499 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
1500 ->DefaultAdapterChanged(new_adapter_path); | |
1501 | |
1502 // Adapter should have the new property value. | |
1503 EXPECT_TRUE(adapter->IsDiscovering()); | |
1504 } | |
1505 | |
1506 TEST_F(BluetoothAdapterChromeOsTest, | |
1507 DefaultAdapterDiscoveringPropertyResetOnRemove) { | |
1508 const dbus::ObjectPath adapter_path("/fake/hci0"); | |
1509 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | |
1510 | |
1511 // Create the default adapter instance; | |
1512 // BluetoothManagerClient::DefaultAdapter will be called once, passing | |
1513 // a callback to obtain the adapter path. | |
1514 BluetoothManagerClient::AdapterCallback adapter_callback; | |
1515 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | |
1516 .WillOnce(SaveArg<0>(&adapter_callback)); | |
1517 | |
1518 scoped_refptr<BluetoothAdapter> adapter = | |
1519 BluetoothAdapterFactory::DefaultAdapter(); | |
1520 | |
1521 // Call the adapter callback; | |
1522 // BluetoothAdapterClient::GetProperties will be called once to obtain | |
1523 // the property set. | |
1524 MockBluetoothAdapterClient::Properties adapter_properties; | |
1525 adapter_properties.address.ReplaceValue(adapter_address); | |
1526 adapter_properties.discovering.ReplaceValue(true); | |
1527 | |
1528 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | |
1529 .WillRepeatedly(Return(&adapter_properties)); | |
1530 | |
1531 adapter_callback.Run(adapter_path, true); | |
1532 | |
1533 // Report that the adapter has been removed; | |
1534 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | |
1535 MockBluetoothAdapter::Observer adapter_observer; | |
1536 adapter->AddObserver(&adapter_observer); | |
1537 | |
1538 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | |
1539 .Times(1); | |
1540 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), false)) | |
1541 .Times(1); | |
1542 | |
1543 BluetoothAdapterChromeOs* adapter_chromeos = | |
1544 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
1545 | |
1546 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | |
1547 ->AdapterRemoved(adapter_path); | |
1548 | |
1549 // Adapter should have the new property value. | |
1550 EXPECT_FALSE(adapter->IsDiscovering()); | |
1551 } | |
1552 | |
1553 } // namespace chromeos | |
OLD | NEW |