| Index: device/bluetooth/bluetooth_remote_gatt_descriptor_unittest.cc
|
| diff --git a/device/bluetooth/bluetooth_remote_gatt_descriptor_unittest.cc b/device/bluetooth/bluetooth_remote_gatt_descriptor_unittest.cc
|
| index 10198f9d9c5de09da53e3af854ec08f8424e9fe6..87aad25bcd2e309086c7fb8de5edd9e53bb239ed 100644
|
| --- a/device/bluetooth/bluetooth_remote_gatt_descriptor_unittest.cc
|
| +++ b/device/bluetooth/bluetooth_remote_gatt_descriptor_unittest.cc
|
| @@ -27,10 +27,12 @@ class BluetoothRemoteGattDescriptorTest : public BluetoothTest {
|
| device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
|
| GetConnectErrorCallback(Call::NOT_EXPECTED));
|
| SimulateGattConnection(device_);
|
| + base::RunLoop().RunUntilIdle();
|
| std::vector<std::string> services;
|
| std::string uuid("00000000-0000-1000-8000-00805f9b34fb");
|
| services.push_back(uuid);
|
| SimulateGattServicesDiscovered(device_, services);
|
| + base::RunLoop().RunUntilIdle();
|
| ASSERT_EQ(1u, device_->GetGattServices().size());
|
| service_ = device_->GetGattServices()[0];
|
| SimulateGattCharacteristic(service_, uuid, 0);
|
| @@ -71,6 +73,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) {
|
| GetConnectErrorCallback(Call::NOT_EXPECTED));
|
| SimulateGattConnection(device1);
|
| SimulateGattConnection(device2);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // 3 services (all with same UUID).
|
| // 1 on the first device (to test characteristic instances across devices).
|
| @@ -79,8 +82,10 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) {
|
| std::string uuid = "00000000-0000-1000-8000-00805f9b34fb";
|
| services.push_back(uuid);
|
| SimulateGattServicesDiscovered(device1, services);
|
| + base::RunLoop().RunUntilIdle();
|
| services.push_back(uuid);
|
| SimulateGattServicesDiscovered(device2, services);
|
| + base::RunLoop().RunUntilIdle();
|
| BluetoothRemoteGattService* service1 = device1->GetGattServices()[0];
|
| BluetoothRemoteGattService* service2 = device2->GetGattServices()[0];
|
| BluetoothRemoteGattService* service3 = device2->GetGattServices()[1];
|
| @@ -151,6 +156,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetUUID) {
|
| std::vector<std::string> services;
|
| services.push_back("00000000-0000-1000-8000-00805f9b34fb");
|
| SimulateGattServicesDiscovered(device, services);
|
| + base::RunLoop().RunUntilIdle();
|
| ASSERT_EQ(1u, device->GetGattServices().size());
|
| BluetoothRemoteGattService* service = device->GetGattServices()[0];
|
|
|
| @@ -192,9 +198,11 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_Empty) {
|
| EXPECT_EQ(1, gatt_read_descriptor_attempts_);
|
| std::vector<uint8_t> empty_vector;
|
| SimulateGattDescriptorRead(descriptor1_, empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // Duplicate read reported from OS shouldn't cause a problem:
|
| SimulateGattDescriptorRead(descriptor1_, empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(empty_vector, last_read_value_);
|
| EXPECT_EQ(empty_vector, descriptor1_->GetValue());
|
| @@ -211,9 +219,11 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteRemoteDescriptor_Empty) {
|
| GetGattErrorCallback(Call::NOT_EXPECTED));
|
| EXPECT_EQ(1, gatt_write_descriptor_attempts_);
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // Duplicate write reported from OS shouldn't cause a problem:
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(empty_vector, last_write_value_);
|
| }
|
| @@ -233,6 +243,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_AfterDeleted) {
|
| std::vector<uint8_t> empty_vector;
|
| SimulateGattDescriptorRead(/* use remembered descriptor */ nullptr,
|
| empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE("Did not crash!");
|
| }
|
| #endif // defined(OS_ANDROID)
|
| @@ -251,6 +262,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteRemoteDescriptor_AfterDeleted) {
|
| DeleteDevice(device_); // TODO(576906) delete only the descriptor.
|
|
|
| SimulateGattDescriptorWrite(/* use remembered descriptor */ nullptr);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE("Did not crash!");
|
| }
|
| #endif // defined(OS_ANDROID)
|
| @@ -267,10 +279,12 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor) {
|
| uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
|
| std::vector<uint8_t> test_vector(values, values + arraysize(values));
|
| SimulateGattDescriptorRead(descriptor1_, test_vector);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // Duplicate read reported from OS shouldn't cause a problem:
|
| std::vector<uint8_t> empty_vector;
|
| SimulateGattDescriptorRead(descriptor1_, empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(test_vector, last_read_value_);
|
| EXPECT_EQ(test_vector, descriptor1_->GetValue());
|
| @@ -289,6 +303,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteRemoteDescriptor) {
|
| EXPECT_EQ(1, gatt_write_descriptor_attempts_);
|
|
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(test_vector, last_write_value_);
|
| }
|
| @@ -306,6 +321,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_Twice) {
|
| uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
|
| std::vector<uint8_t> test_vector(values, values + arraysize(values));
|
| SimulateGattDescriptorRead(descriptor1_, test_vector);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| EXPECT_EQ(test_vector, last_read_value_);
|
| @@ -318,6 +334,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_Twice) {
|
| EXPECT_EQ(1, gatt_read_descriptor_attempts_);
|
| std::vector<uint8_t> empty_vector;
|
| SimulateGattDescriptorRead(descriptor1_, empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| EXPECT_EQ(empty_vector, last_read_value_);
|
| @@ -337,6 +354,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteRemoteDescriptor_Twice) {
|
| EXPECT_EQ(1, gatt_write_descriptor_attempts_);
|
|
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| EXPECT_EQ(test_vector, last_write_value_);
|
| @@ -348,6 +366,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteRemoteDescriptor_Twice) {
|
| GetGattErrorCallback(Call::NOT_EXPECTED));
|
| EXPECT_EQ(1, gatt_write_descriptor_attempts_);
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| EXPECT_EQ(empty_vector, last_write_value_);
|
| @@ -371,11 +390,13 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
|
| std::vector<uint8_t> test_vector1;
|
| test_vector1.push_back(111);
|
| SimulateGattDescriptorRead(descriptor1_, test_vector1);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(test_vector1, last_read_value_);
|
|
|
| std::vector<uint8_t> test_vector2;
|
| test_vector2.push_back(222);
|
| SimulateGattDescriptorRead(descriptor2_, test_vector2);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(test_vector2, last_read_value_);
|
|
|
| EXPECT_EQ(2, callback_count_);
|
| @@ -409,6 +430,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
|
|
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| SimulateGattDescriptorWrite(descriptor2_);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(2, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| @@ -426,6 +448,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadError) {
|
| descriptor1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
|
| SimulateGattDescriptorReadError(
|
| descriptor1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
|
| last_gatt_error_code_);
|
| }
|
| @@ -444,6 +467,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteError) {
|
| descriptor1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
|
| SimulateGattDescriptorWriteError(
|
| descriptor1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
|
| last_gatt_error_code_);
|
| @@ -472,6 +496,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadSynchronousError) {
|
| EXPECT_EQ(1, gatt_read_descriptor_attempts_);
|
| std::vector<uint8_t> empty_vector;
|
| SimulateGattDescriptorRead(descriptor1_, empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| }
|
| @@ -500,6 +525,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteSynchronousError) {
|
| GetGattErrorCallback(Call::NOT_EXPECTED));
|
| EXPECT_EQ(1, gatt_write_descriptor_attempts_);
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| }
|
| @@ -526,6 +552,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_ReadPending) {
|
| ResetEventCounts();
|
| std::vector<uint8_t> empty_vector;
|
| SimulateGattDescriptorRead(descriptor1_, empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| }
|
| @@ -553,6 +580,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteRemoteDescriptor_WritePending) {
|
| // Initial write should still succeed:
|
| ResetEventCounts();
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| }
|
| @@ -579,6 +607,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_WritePending) {
|
| // Initial write should still succeed:
|
| ResetEventCounts();
|
| SimulateGattDescriptorWrite(descriptor1_);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| }
|
| @@ -605,6 +634,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, WriteRemoteDescriptor_ReadPending) {
|
| // Initial read should still succeed:
|
| ResetEventCounts();
|
| SimulateGattDescriptorRead(descriptor1_, empty_vector);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, callback_count_);
|
| EXPECT_EQ(0, error_callback_count_);
|
| }
|
|
|