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

Unified Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 2205693003: bluetooth: Replace old advertised uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Fix mac Created 4 years, 4 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_device_unittest.cc
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc
index 2232c7ce564f557c8cf262e594ac6581f07d0b57..cf307dda2be8abbe0adae20298ba509ffcb01c74 100644
--- a/device/bluetooth/bluetooth_device_unittest.cc
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -118,6 +118,63 @@ TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) {
#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
#if defined(OS_ANDROID) || defined(OS_MACOSX)
+// Tests GetUUIDs returns the right UUIDs when device connects and disconnects.
+TEST_F(BluetoothTest, GetUUIDs) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ InitWithFakeAdapter();
+ StartLowEnergyDiscoverySession();
+ BluetoothDevice* device = SimulateLowEnergyDevice(1);
+
+ // Check advertised UUIDs:
+ EXPECT_EQ(2u, device->GetUUIDs().size());
+ EXPECT_TRUE(
+ ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
+ EXPECT_TRUE(ContainsValue(device->GetUUIDs(),
+ BluetoothUUID(kTestUUIDGenericAttribute)));
+
+ // Connect.
+ device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
+ GetConnectErrorCallback(Call::NOT_EXPECTED));
+ TestBluetoothAdapterObserver observer(adapter_);
+ SimulateGattConnection(device);
+ ASSERT_TRUE(device->IsConnected());
+
+ // No UUIDs until services are completely discovered.
+ EXPECT_EQ(0u, device->GetUUIDs().size());
+
+ // Discover services.
+ std::vector<std::string> services;
+ services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value());
+ SimulateGattServicesDiscovered(device, services);
+
+ // GetUUIDs should return UUIDs of services in device.
+ EXPECT_EQ(1u, device->GetUUIDs().size());
+ EXPECT_TRUE(
+ ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
+
+ // Disconnect.
+ device->DisconnectGatt();
+ SimulateGattDisconnection(device);
+
+ // After disconnection we don't know what UUIDs the device has.
+ EXPECT_EQ(0u, device->GetUUIDs().size());
+
+ // Discover the device again with different UUIDs.
+ device = SimulateLowEnergyDevice(2);
+
+ // Check advertised UUIDs.
+ EXPECT_EQ(2u, device->GetUUIDs().size());
+ EXPECT_TRUE(ContainsValue(device->GetUUIDs(),
+ BluetoothUUID(kTestUUIDImmediateAlert)));
+ EXPECT_TRUE(
+ ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss)));
+}
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
+
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// GetName for Device with no name.
TEST_F(BluetoothTest, GetName_NullName) {
if (!PlatformSupportsLowEnergy()) {

Powered by Google App Engine
This is Rietveld 408576698