OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "device/bluetooth/bluetooth_adapter.h" | 8 #include "device/bluetooth/bluetooth_adapter.h" |
9 #include "device/bluetooth/bluetooth_device.h" | 9 #include "device/bluetooth/bluetooth_device.h" |
10 #include "device/bluetooth/bluetooth_discovery_session.h" | 10 #include "device/bluetooth/bluetooth_discovery_session.h" |
11 #include "device/bluetooth/test/bluetooth_test.h" | 11 #include "device/bluetooth/test/bluetooth_test.h" |
12 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
15 #include "device/bluetooth/test/bluetooth_test_android.h" | 16 #include "device/bluetooth/test/bluetooth_test_android.h" |
16 #endif | 17 #endif |
17 | 18 |
18 using device::BluetoothDevice; | 19 using device::BluetoothDevice; |
19 | 20 |
20 namespace device { | 21 namespace device { |
21 | 22 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 EXPECT_EQ(adapter_->GetName(), "FakeBluetoothAdapter"); | 440 EXPECT_EQ(adapter_->GetName(), "FakeBluetoothAdapter"); |
440 EXPECT_TRUE(adapter_->IsPresent()); | 441 EXPECT_TRUE(adapter_->IsPresent()); |
441 EXPECT_TRUE(adapter_->IsPowered()); | 442 EXPECT_TRUE(adapter_->IsPowered()); |
442 EXPECT_FALSE(adapter_->IsDiscoverable()); | 443 EXPECT_FALSE(adapter_->IsDiscoverable()); |
443 EXPECT_FALSE(adapter_->IsDiscovering()); | 444 EXPECT_FALSE(adapter_->IsDiscovering()); |
444 } | 445 } |
445 #endif // defined(OS_ANDROID) | 446 #endif // defined(OS_ANDROID) |
446 | 447 |
447 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. | 448 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. |
448 #if defined(OS_ANDROID) | 449 #if defined(OS_ANDROID) |
450 // Starts and Stops a discovery session. | |
449 TEST_F(BluetoothTest, DiscoverySession) { | 451 TEST_F(BluetoothTest, DiscoverySession) { |
450 InitWithFakeAdapter(); | 452 InitWithFakeAdapter(); |
451 EXPECT_FALSE(adapter_->IsDiscovering()); | 453 EXPECT_FALSE(adapter_->IsDiscovering()); |
452 | 454 |
453 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), | 455 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), |
454 GetErrorCallback()); | 456 GetErrorCallback()); |
455 base::RunLoop().RunUntilIdle(); | 457 base::RunLoop().RunUntilIdle(); |
456 EXPECT_EQ(1, callback_count_--); | 458 EXPECT_EQ(1, callback_count_--); |
457 EXPECT_EQ(0, error_callback_count_); | 459 EXPECT_EQ(0, error_callback_count_); |
458 EXPECT_TRUE(adapter_->IsDiscovering()); | 460 EXPECT_TRUE(adapter_->IsDiscovering()); |
459 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 461 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
460 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 462 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
461 | 463 |
462 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); | 464 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
463 base::RunLoop().RunUntilIdle(); | 465 base::RunLoop().RunUntilIdle(); |
464 EXPECT_EQ(1, callback_count_--); | 466 EXPECT_EQ(1, callback_count_--); |
465 EXPECT_EQ(0, error_callback_count_); | 467 EXPECT_EQ(0, error_callback_count_); |
466 EXPECT_FALSE(adapter_->IsDiscovering()); | 468 EXPECT_FALSE(adapter_->IsDiscovering()); |
467 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 469 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
468 } | 470 } |
469 #endif // defined(OS_ANDROID) | 471 #endif // defined(OS_ANDROID) |
470 | 472 |
473 #if defined(OS_ANDROID) | |
474 // Discovers a device. | |
475 TEST_F(BluetoothTest, DiscoverDevice) { | |
476 InitWithFakeAdapter(); | |
477 TestBluetoothAdapterObserver observer(adapter_); | |
478 | |
479 // Start discovery and find a device. | |
480 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), | |
481 GetErrorCallback()); | |
482 base::RunLoop().RunUntilIdle(); | |
483 DiscoverLowEnergyDevice(1); | |
484 base::RunLoop().RunUntilIdle(); | |
485 EXPECT_EQ(1, observer.device_added_count()); | |
486 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); | |
487 EXPECT_TRUE(device); | |
488 } | |
489 #endif // defined(OS_ANDROID) | |
490 | |
491 #if defined(OS_ANDROID) | |
492 // Discovers the same device multiple times. | |
493 TEST_F(BluetoothTest, DiscoverDeviceTwice) { | |
494 InitWithFakeAdapter(); | |
495 TestBluetoothAdapterObserver observer(adapter_); | |
496 | |
497 // Start discovery and find a device. | |
498 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), | |
499 GetErrorCallback()); | |
500 base::RunLoop().RunUntilIdle(); | |
501 DiscoverLowEnergyDevice(1); | |
502 base::RunLoop().RunUntilIdle(); | |
503 EXPECT_EQ(1, observer.device_added_count()); | |
504 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); | |
505 EXPECT_TRUE(device); | |
506 | |
507 // Find the same device again. This should not create a new device object. | |
508 observer.Reset(); | |
509 DiscoverLowEnergyDevice(1); | |
510 base::RunLoop().RunUntilIdle(); | |
511 EXPECT_EQ(0, observer.device_added_count()); | |
512 EXPECT_EQ(0, observer.device_changed_count()); | |
513 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
514 } | |
515 #endif // defined(OS_ANDROID) | |
516 | |
517 #if defined(OS_ANDROID) | |
518 // Discovers a device, and then again with new Service UUIDs. | |
519 TEST_F(BluetoothTest, DiscoverDeviceWithUpdatedUUIDs) { | |
520 InitWithFakeAdapter(); | |
521 TestBluetoothAdapterObserver observer(adapter_); | |
522 | |
523 // Start discovery and find a device. | |
524 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), | |
525 GetErrorCallback()); | |
526 base::RunLoop().RunUntilIdle(); | |
527 DiscoverLowEnergyDevice(1); | |
528 base::RunLoop().RunUntilIdle(); | |
529 BluetoothDevice* device = observer.last_device(); | |
530 | |
531 // Check the initial UUIDs: | |
532 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1800"))); | |
533 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1802"))); | |
534 | |
535 // Discover same device again with updated UUIDs: | |
536 observer.Reset(); | |
537 DiscoverLowEnergyDevice(2); | |
538 base::RunLoop().RunUntilIdle(); | |
539 EXPECT_EQ(0, observer.device_added_count()); | |
540 EXPECT_EQ(1, observer.device_changed_count()); | |
541 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
542 EXPECT_EQ(device, observer.last_device()); | |
543 | |
544 // Expect new UUIDs: | |
545 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1800"))); | |
546 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1802"))); | |
547 | |
548 // Discover same device again with empty UUIDs: | |
549 observer.Reset(); | |
550 DiscoverLowEnergyDevice(3); | |
551 base::RunLoop().RunUntilIdle(); | |
552 EXPECT_EQ(0, observer.device_added_count()); | |
553 EXPECT_EQ(1, observer.device_changed_count()); | |
554 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
555 EXPECT_EQ(device, observer.last_device()); | |
556 | |
557 // Expect empty UUIDs: | |
scheib
2015/07/08 00:54:09
armansito, confirm this is what you believe should
armansito
2015/07/08 03:12:09
On Chrome OS this will be populated with the compl
scheib
2015/07/08 05:09:10
On Android, device.getUuids() will be empty unless
armansito
2015/07/08 06:00:13
SDP is a Bluetooth classic protocol, so it wouldn'
scheib
2015/07/08 16:42:51
OK, to be clear, upon a DiscoverySession we only e
Jeffrey Yasskin
2015/07/08 17:19:39
You're not really testing that situation here. You
scheib
2015/07/08 23:02:35
I don't know what Android does for sure. Our test
Jeffrey Yasskin
2015/07/08 23:18:24
I think that's right, until someone files a bug wi
| |
558 EXPECT_EQ(0u, device->GetUUIDs().size()); | |
559 } | |
560 #endif // defined(OS_ANDROID) | |
561 | |
562 #if defined(OS_ANDROID) | |
563 // Discovers multiple devices when addresses vary. | |
564 TEST_F(BluetoothTest, DiscoverMultipleDevices) { | |
565 InitWithFakeAdapter(); | |
566 TestBluetoothAdapterObserver observer(adapter_); | |
567 | |
568 // Start discovery and find a device. | |
569 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), | |
570 GetErrorCallback()); | |
571 base::RunLoop().RunUntilIdle(); | |
572 DiscoverLowEnergyDevice(1); | |
573 DiscoverLowEnergyDevice(4); | |
574 base::RunLoop().RunUntilIdle(); | |
575 EXPECT_EQ(2, observer.device_added_count()); | |
576 EXPECT_EQ(2u, adapter_->GetDevices().size()); | |
577 } | |
578 #endif // defined(OS_ANDROID) | |
579 | |
471 } // namespace device | 580 } // namespace device |
OLD | NEW |