Chromium Code Reviews| 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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 858 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 859 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 859 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 860 SimulateGattConnection(device); | 860 SimulateGattConnection(device); |
| 861 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 861 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 862 RemoveTimedOutDevices(); | 862 RemoveTimedOutDevices(); |
| 863 EXPECT_EQ(0, observer.device_removed_count()); | 863 EXPECT_EQ(0, observer.device_removed_count()); |
| 864 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 864 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 865 } | 865 } |
| 866 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 866 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 867 | 867 |
| 868 #if defined(OS_MACOSX) | |
| 869 // Simulate two devices being connected before starting discovery session with | |
| 870 // no service filter. | |
| 871 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithNoFilter) { | |
| 872 if (!PlatformSupportsLowEnergy()) { | |
| 873 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 874 return; | |
| 875 } | |
| 876 InitWithFakeAdapter(); | |
| 877 TestBluetoothAdapterObserver observer(adapter_); | |
| 878 | |
| 879 BluetoothDevice::UUIDSet uuidSet1; | |
| 880 uuidSet1.insert(device::BluetoothUUID("1800")); | |
| 881 SimulateConnectedLowEnergyDevice(1, uuidSet1); | |
| 882 BluetoothDevice::UUIDSet uuidSet2; | |
| 883 uuidSet2.insert(device::BluetoothUUID("1800")); | |
| 884 uuidSet2.insert(device::BluetoothUUID("1001")); | |
| 885 SimulateConnectedLowEnergyDevice(2, uuidSet2); | |
| 886 BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); | |
| 887 adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter(&discovery_filter); | |
| 888 | |
| 889 EXPECT_EQ(2, observer.device_added_count()); | |
| 890 EXPECT_EQ(2u, adapter_->GetDevices().size()); | |
|
ortuno
2016/10/31 04:30:51
Also check that the return value is correct:
std:
jlebel
2016/11/07 01:43:18
Done.
| |
| 891 } | |
| 892 | |
| 893 // Simulate two devices being connected before starting discovery session with | |
| 894 // one service filter. | |
| 895 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithFilter) { | |
| 896 if (!PlatformSupportsLowEnergy()) { | |
| 897 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 898 return; | |
| 899 } | |
| 900 InitWithFakeAdapter(); | |
| 901 TestBluetoothAdapterObserver observer(adapter_); | |
| 902 | |
| 903 BluetoothDevice::UUIDSet uuidSet1; | |
| 904 uuidSet1.insert(device::BluetoothUUID("1800")); | |
| 905 SimulateConnectedLowEnergyDevice(1, uuidSet1); | |
| 906 BluetoothDevice::UUIDSet uuidSet2; | |
| 907 uuidSet2.insert(device::BluetoothUUID("1800")); | |
| 908 uuidSet2.insert(device::BluetoothUUID("1001")); | |
| 909 SimulateConnectedLowEnergyDevice(2, uuidSet2); | |
| 910 BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); | |
| 911 discovery_filter.AddUUID(device::BluetoothUUID("1001")); | |
| 912 adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter(&discovery_filter); | |
| 913 | |
| 914 EXPECT_EQ(1, observer.device_added_count()); | |
| 915 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
|
ortuno
2016/10/31 04:30:51
Same here, please test the return value is correct
jlebel
2016/11/07 01:43:18
Done.
| |
| 916 } | |
| 917 | |
| 918 // Simulate two devices being connected before starting discovery session with | |
| 919 // one service filter that doesn't match. | |
| 920 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithWrongFilter) { | |
| 921 if (!PlatformSupportsLowEnergy()) { | |
| 922 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 923 return; | |
| 924 } | |
| 925 InitWithFakeAdapter(); | |
| 926 TestBluetoothAdapterObserver observer(adapter_); | |
| 927 | |
| 928 BluetoothDevice::UUIDSet uuidSet1; | |
| 929 uuidSet1.insert(device::BluetoothUUID("1800")); | |
| 930 SimulateConnectedLowEnergyDevice(1, uuidSet1); | |
| 931 BluetoothDevice::UUIDSet uuidSet2; | |
| 932 uuidSet2.insert(device::BluetoothUUID("1800")); | |
| 933 uuidSet2.insert(device::BluetoothUUID("1001")); | |
| 934 SimulateConnectedLowEnergyDevice(2, uuidSet2); | |
| 935 BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); | |
| 936 discovery_filter.AddUUID(device::BluetoothUUID("1002")); | |
| 937 adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter(&discovery_filter); | |
|
ortuno
2016/10/31 04:30:51
Add:
EXPECT_TRUE(result.empty());
jlebel
2016/11/07 01:43:18
Done.
| |
| 938 | |
| 939 EXPECT_EQ(0, observer.device_added_count()); | |
| 940 EXPECT_EQ(0u, adapter_->GetDevices().size()); | |
| 941 } | |
| 942 #endif // defined(OS_MACOSX) | |
|
ortuno
2016/10/31 04:30:51
Please add the following tests:
Filter with more
jlebel
2016/11/07 01:43:18
Done.
| |
| 943 | |
| 868 } // namespace device | 944 } // namespace device |
| OLD | NEW |