| 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 "device/bluetooth/bluetooth_adapter.h" | 5 #include "device/bluetooth/bluetooth_adapter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 observer.Reset(); | 614 observer.Reset(); |
| 615 SimulateLowEnergyDevice(1); | 615 SimulateLowEnergyDevice(1); |
| 616 base::RunLoop().RunUntilIdle(); | 616 base::RunLoop().RunUntilIdle(); |
| 617 EXPECT_EQ(0, observer.device_added_count()); | 617 EXPECT_EQ(0, observer.device_added_count()); |
| 618 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 618 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 619 } | 619 } |
| 620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 621 | 621 |
| 622 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 622 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 623 // Discovers a device, and then again with new Service UUIDs. | 623 // Discovers a device, and then again with new Service UUIDs. |
| 624 // Makes sure we don't create another device when we've found the |
| 625 // device in the past. |
| 624 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) { | 626 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) { |
| 625 if (!PlatformSupportsLowEnergy()) { | 627 if (!PlatformSupportsLowEnergy()) { |
| 626 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 628 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 627 return; | 629 return; |
| 628 } | 630 } |
| 629 InitWithFakeAdapter(); | 631 InitWithFakeAdapter(); |
| 630 TestBluetoothAdapterObserver observer(adapter_); | 632 TestBluetoothAdapterObserver observer(adapter_); |
| 631 | 633 |
| 632 // Start discovery and find a device. | 634 // Start discovery and find a device. |
| 633 StartLowEnergyDiscoverySession(); | 635 StartLowEnergyDiscoverySession(); |
| 634 BluetoothDevice* device = SimulateLowEnergyDevice(1); | 636 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 635 | 637 |
| 636 // Check the initial UUIDs: | |
| 637 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), | |
| 638 BluetoothUUID(kTestUUIDGenericAccess))); | |
| 639 EXPECT_FALSE(base::ContainsValue(device->GetUUIDs(), | |
| 640 BluetoothUUID(kTestUUIDImmediateAlert))); | |
| 641 | |
| 642 // Discover same device again with updated UUIDs: | 638 // Discover same device again with updated UUIDs: |
| 643 observer.Reset(); | 639 observer.Reset(); |
| 644 SimulateLowEnergyDevice(2); | 640 SimulateLowEnergyDevice(2); |
| 645 EXPECT_EQ(0, observer.device_added_count()); | 641 EXPECT_EQ(0, observer.device_added_count()); |
| 646 EXPECT_EQ(1, observer.device_changed_count()); | 642 EXPECT_EQ(1, observer.device_changed_count()); |
| 647 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 643 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 648 EXPECT_EQ(device, observer.last_device()); | 644 EXPECT_EQ(device, observer.last_device()); |
| 649 | 645 |
| 650 // Expect only new UUIDs: | |
| 651 EXPECT_FALSE(base::ContainsValue(device->GetUUIDs(), | |
| 652 BluetoothUUID(kTestUUIDGenericAccess))); | |
| 653 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), | |
| 654 BluetoothUUID(kTestUUIDImmediateAlert))); | |
| 655 | |
| 656 // Discover same device again with empty UUIDs: | 646 // Discover same device again with empty UUIDs: |
| 657 observer.Reset(); | 647 observer.Reset(); |
| 658 SimulateLowEnergyDevice(3); | 648 SimulateLowEnergyDevice(3); |
| 659 EXPECT_EQ(0, observer.device_added_count()); | 649 EXPECT_EQ(0, observer.device_added_count()); |
| 660 EXPECT_EQ(1, observer.device_changed_count()); | 650 EXPECT_EQ(1, observer.device_changed_count()); |
| 661 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 651 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 662 | |
| 663 // Expect no UUIDs: | |
| 664 EXPECT_EQ(0u, device->GetUUIDs().size()); | |
| 665 } | 652 } |
| 666 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 653 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 667 | 654 |
| 668 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 655 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 669 // Discovers multiple devices when addresses vary. | 656 // Discovers multiple devices when addresses vary. |
| 670 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) { | 657 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) { |
| 671 if (!PlatformSupportsLowEnergy()) { | 658 if (!PlatformSupportsLowEnergy()) { |
| 672 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 659 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 673 return; | 660 return; |
| 674 } | 661 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 848 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 862 SimulateGattConnection(device); | 849 SimulateGattConnection(device); |
| 863 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 850 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 864 RemoveTimedOutDevices(); | 851 RemoveTimedOutDevices(); |
| 865 EXPECT_EQ(0, observer.device_removed_count()); | 852 EXPECT_EQ(0, observer.device_removed_count()); |
| 866 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 853 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 867 } | 854 } |
| 868 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 855 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 869 | 856 |
| 870 } // namespace device | 857 } // namespace device |
| OLD | NEW |