Chromium Code Reviews| Index: device/bluetooth/bluetooth_adapter_unittest.cc |
| diff --git a/device/bluetooth/bluetooth_adapter_unittest.cc b/device/bluetooth/bluetooth_adapter_unittest.cc |
| index 06829a88dd6d1887fcf14d537b923cb42bd52a56..516b971474dd2dce7ea6343654bf504477dd37d9 100644 |
| --- a/device/bluetooth/bluetooth_adapter_unittest.cc |
| +++ b/device/bluetooth/bluetooth_adapter_unittest.cc |
| @@ -865,4 +865,80 @@ TEST_F(BluetoothTest, RemoveOutdatedDeviceGattConnect) { |
| } |
| #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| +#if defined(OS_MACOSX) |
| +// Simulate two devices being connected before starting discovery session with |
| +// no service filter. |
| +TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithNoFilter) { |
| + if (!PlatformSupportsLowEnergy()) { |
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| + return; |
| + } |
| + InitWithFakeAdapter(); |
| + TestBluetoothAdapterObserver observer(adapter_); |
| + |
| + BluetoothDevice::UUIDSet uuidSet1; |
| + uuidSet1.insert(device::BluetoothUUID("1800")); |
| + SimulateConnectedLowEnergyDevice(1, uuidSet1); |
| + BluetoothDevice::UUIDSet uuidSet2; |
| + uuidSet2.insert(device::BluetoothUUID("1800")); |
| + uuidSet2.insert(device::BluetoothUUID("1001")); |
| + SimulateConnectedLowEnergyDevice(2, uuidSet2); |
| + BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); |
| + adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter(&discovery_filter); |
| + |
| + EXPECT_EQ(2, observer.device_added_count()); |
| + 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.
|
| +} |
| + |
| +// Simulate two devices being connected before starting discovery session with |
| +// one service filter. |
| +TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithFilter) { |
| + if (!PlatformSupportsLowEnergy()) { |
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| + return; |
| + } |
| + InitWithFakeAdapter(); |
| + TestBluetoothAdapterObserver observer(adapter_); |
| + |
| + BluetoothDevice::UUIDSet uuidSet1; |
| + uuidSet1.insert(device::BluetoothUUID("1800")); |
| + SimulateConnectedLowEnergyDevice(1, uuidSet1); |
| + BluetoothDevice::UUIDSet uuidSet2; |
| + uuidSet2.insert(device::BluetoothUUID("1800")); |
| + uuidSet2.insert(device::BluetoothUUID("1001")); |
| + SimulateConnectedLowEnergyDevice(2, uuidSet2); |
| + BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); |
| + discovery_filter.AddUUID(device::BluetoothUUID("1001")); |
| + adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter(&discovery_filter); |
| + |
| + EXPECT_EQ(1, observer.device_added_count()); |
| + 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.
|
| +} |
| + |
| +// Simulate two devices being connected before starting discovery session with |
| +// one service filter that doesn't match. |
| +TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithWrongFilter) { |
| + if (!PlatformSupportsLowEnergy()) { |
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| + return; |
| + } |
| + InitWithFakeAdapter(); |
| + TestBluetoothAdapterObserver observer(adapter_); |
| + |
| + BluetoothDevice::UUIDSet uuidSet1; |
| + uuidSet1.insert(device::BluetoothUUID("1800")); |
| + SimulateConnectedLowEnergyDevice(1, uuidSet1); |
| + BluetoothDevice::UUIDSet uuidSet2; |
| + uuidSet2.insert(device::BluetoothUUID("1800")); |
| + uuidSet2.insert(device::BluetoothUUID("1001")); |
| + SimulateConnectedLowEnergyDevice(2, uuidSet2); |
| + BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); |
| + discovery_filter.AddUUID(device::BluetoothUUID("1002")); |
| + adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter(&discovery_filter); |
|
ortuno
2016/10/31 04:30:51
Add:
EXPECT_TRUE(result.empty());
jlebel
2016/11/07 01:43:18
Done.
|
| + |
| + EXPECT_EQ(0, observer.device_added_count()); |
| + EXPECT_EQ(0u, adapter_->GetDevices().size()); |
| +} |
| +#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.
|
| + |
| } // namespace device |