Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7990)

Unified Diff: device/bluetooth/bluetooth_adapter_unittest.cc

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: Implementing RetrieveGattConnectedDevicesWithDiscoveryFilter() with tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698