Index: device/bluetooth/bluetooth_device_unittest.cc |
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc |
index ab478fc7386df4a49d9bf91a0645488354e48239..8c531d074808496bf973ea3cea8bfe0bd802eb48 100644 |
--- a/device/bluetooth/bluetooth_device_unittest.cc |
+++ b/device/bluetooth/bluetooth_device_unittest.cc |
@@ -46,9 +46,13 @@ int8_t ToInt8(BluetoothTest::TestTxPower tx_power) { |
using UUIDSet = BluetoothDevice::UUIDSet; |
using ServiceDataMap = BluetoothDevice::ServiceDataMap; |
-class BluetoothGetServiceOrCharacteristicTest : public BluetoothTest { |
+class BluetoothGetServiceTest : public BluetoothTest { |
public: |
- // Creates |device_|, |services_|. |
+ BluetoothGetServiceTest() |
+ : unique_service_uuid_(kTestUUIDGenericAccess), |
+ duplicate_service_uuid_(kTestUUIDHeartRate) {} |
+ |
+ // Creates |device_|, |service_uuids_|. |
void FakeServiceBoilerplate() { |
InitWithFakeAdapter(); |
StartLowEnergyDiscoverySession(); |
@@ -62,21 +66,32 @@ class BluetoothGetServiceOrCharacteristicTest : public BluetoothTest { |
TestBluetoothAdapterObserver observer(adapter_); |
SimulateGattConnection(device_); |
base::RunLoop().RunUntilIdle(); |
+#if defined(OS_WIN) |
ortuno
2017/04/04 22:14:12
// TODO(crbug.com/507419): Check connection once C
juncai
2017/04/05 00:36:45
Done.
|
+ EXPECT_FALSE(device_->IsConnected()); |
+#else |
EXPECT_TRUE(device_->IsConnected()); |
+#endif // defined(OS_WIN) |
// Discover services. |
- services_.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
+ service_uuids_.push_back(unique_service_uuid_.value()); |
ortuno
2017/04/04 22:14:12
nit: use canonical_value. value() can change depen
juncai
2017/04/05 00:36:45
Done.
|
// 2 duplicate UUIDs creating 2 instances. |
- services_.push_back("00000001-0000-1000-8000-00805f9b34fb"); |
- services_.push_back("00000001-0000-1000-8000-00805f9b34fb"); |
- SimulateGattServicesDiscovered(device_, services_); |
+ service_uuids_.push_back(duplicate_service_uuid_.value()); |
+ service_uuids_.push_back(duplicate_service_uuid_.value()); |
+ SimulateGattServicesDiscovered(device_, service_uuids_); |
base::RunLoop().RunUntilIdle(); |
+#if defined(OS_WIN) |
+ EXPECT_FALSE(device_->IsGattServicesDiscoveryComplete()); |
+#else |
EXPECT_TRUE(device_->IsGattServicesDiscoveryComplete()); |
+#endif // defined(OS_WIN) |
} |
protected: |
+ BluetoothUUID unique_service_uuid_; |
+ BluetoothUUID duplicate_service_uuid_; |
+ |
BluetoothDevice* device_ = nullptr; |
- std::vector<std::string> services_; |
+ std::vector<std::string> service_uuids_; |
}; |
TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) { |
@@ -1516,8 +1531,8 @@ TEST_F(BluetoothTest, GetDeviceTransportType) { |
} |
#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
-#if defined(OS_ANDROID) || defined(OS_MACOSX) |
-TEST_F(BluetoothGetServiceOrCharacteristicTest, GetPrimaryServices) { |
+#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
+TEST_F(BluetoothGetServiceTest, GetPrimaryServices) { |
if (!PlatformSupportsLowEnergy()) { |
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
return; |
@@ -1527,96 +1542,35 @@ TEST_F(BluetoothGetServiceOrCharacteristicTest, GetPrimaryServices) { |
EXPECT_EQ(3u, device_->GetPrimaryServices().size()); |
} |
-TEST_F(BluetoothGetServiceOrCharacteristicTest, GetPrimaryServicesByUUID) { |
+TEST_F(BluetoothGetServiceTest, GetPrimaryServicesByUUID) { |
if (!PlatformSupportsLowEnergy()) { |
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
return; |
} |
ASSERT_NO_FATAL_FAILURE(FakeServiceBoilerplate()); |
- EXPECT_EQ( |
- 1u, |
- device_->GetPrimaryServicesByUUID(BluetoothUUID(services_[0])).size()); |
- EXPECT_EQ( |
- 2u, |
- device_->GetPrimaryServicesByUUID(BluetoothUUID(services_[1])).size()); |
- std::string service_uuid_not_exist_in_setup = |
- "00000002-0000-1000-8000-00805f9b34fb"; |
- EXPECT_TRUE(device_ |
- ->GetPrimaryServicesByUUID( |
- BluetoothUUID(service_uuid_not_exist_in_setup)) |
- .empty()); |
-} |
- |
-TEST_F(BluetoothGetServiceOrCharacteristicTest, GetCharacteristicsByUUID) { |
- if (!PlatformSupportsLowEnergy()) { |
- LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
- return; |
+ { |
+ std::vector<BluetoothRemoteGattService*> services = |
+ device_->GetPrimaryServicesByUUID(unique_service_uuid_); |
+ EXPECT_EQ(1u, services.size()); |
+ EXPECT_EQ(unique_service_uuid_, services[0]->GetUUID()); |
} |
- ASSERT_NO_FATAL_FAILURE(FakeServiceBoilerplate()); |
- std::vector<BluetoothRemoteGattService*> primary_services = |
- device_->GetPrimaryServices(); |
- std::string service_instance_id0 = primary_services[0]->GetIdentifier(); |
- std::string service_instance_id1 = primary_services[1]->GetIdentifier(); |
- std::string service_instance_id2 = primary_services[2]->GetIdentifier(); |
- |
- std::string characteristic_uuid0 = "00000002-0000-1000-8000-00805f9b34fb"; |
- std::string characteristic_uuid1 = "00000003-0000-1000-8000-00805f9b34fb"; |
- SimulateGattCharacteristic(primary_services[0], characteristic_uuid0, |
- 0 /* properties */); |
- SimulateGattCharacteristic(primary_services[1], characteristic_uuid1, |
- 0 /* properties */); |
- SimulateGattCharacteristic(primary_services[2], characteristic_uuid1, |
- 0 /* properties */); |
- |
- EXPECT_EQ(1u, |
- device_ |
- ->GetCharacteristicsByUUID(service_instance_id0, |
- BluetoothUUID(characteristic_uuid0)) |
- .size()); |
- EXPECT_EQ(1u, |
- device_ |
- ->GetCharacteristicsByUUID(service_instance_id1, |
- BluetoothUUID(characteristic_uuid1)) |
- .size()); |
- EXPECT_EQ(1u, |
- device_ |
- ->GetCharacteristicsByUUID(service_instance_id2, |
- BluetoothUUID(characteristic_uuid1)) |
- .size()); |
- |
- std::string service_instance_id_not_exist_in_setup = |
- "non-existent platform specific service instance id"; |
- EXPECT_TRUE( |
- device_ |
- ->GetCharacteristicsByUUID(service_instance_id_not_exist_in_setup, |
- BluetoothUUID(characteristic_uuid0)) |
- .empty()); |
- EXPECT_TRUE( |
- device_ |
- ->GetCharacteristicsByUUID(service_instance_id_not_exist_in_setup, |
- BluetoothUUID(characteristic_uuid1)) |
- .empty()); |
- |
- std::string characteristic_uuid_not_exist_in_setup = |
- "00000005-0000-1000-8000-00805f9b34fb"; |
- EXPECT_TRUE(device_ |
- ->GetCharacteristicsByUUID( |
- service_instance_id0, |
- BluetoothUUID(characteristic_uuid_not_exist_in_setup)) |
- .empty()); |
- EXPECT_TRUE(device_ |
- ->GetCharacteristicsByUUID( |
- service_instance_id1, |
- BluetoothUUID(characteristic_uuid_not_exist_in_setup)) |
- .empty()); |
- EXPECT_TRUE(device_ |
- ->GetCharacteristicsByUUID( |
- service_instance_id2, |
- BluetoothUUID(characteristic_uuid_not_exist_in_setup)) |
- .empty()); |
+ { |
+ std::vector<BluetoothRemoteGattService*> services = |
+ device_->GetPrimaryServicesByUUID(duplicate_service_uuid_); |
+ EXPECT_EQ(2u, services.size()); |
+ EXPECT_EQ(duplicate_service_uuid_, services[0]->GetUUID()); |
+ EXPECT_EQ(duplicate_service_uuid_, services[1]->GetUUID()); |
+ |
+ EXPECT_TRUE(device_ |
+ ->GetPrimaryServicesByUUID(BluetoothUUID( |
+ BluetoothTestBase::kTestUUIDGenericAttribute)) |
+ .empty()); |
+ |
+ EXPECT_NE(services[0]->GetIdentifier(), services[1]->GetIdentifier()); |
+ } |
} |
-#endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
} // namespace device |