Chromium Code Reviews| Index: device/bluetooth/bluetooth_gatt_descriptor_unittest.cc |
| diff --git a/device/bluetooth/bluetooth_gatt_descriptor_unittest.cc b/device/bluetooth/bluetooth_gatt_descriptor_unittest.cc |
| index a2c0bd97ad53323f58e14c7cc0a6c1db9eff321a..190de7dbc645ed2a8f7ad6a362cec889351f922d 100644 |
| --- a/device/bluetooth/bluetooth_gatt_descriptor_unittest.cc |
| +++ b/device/bluetooth/bluetooth_gatt_descriptor_unittest.cc |
| @@ -16,7 +16,42 @@ |
| namespace device { |
| #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| -class BluetoothGattDescriptorTest : public BluetoothTest {}; |
| +class BluetoothGattDescriptorTest : public BluetoothTest { |
| + public: |
| + // Creates adapter_, device_, service_, characteristic_, |
| + // descriptor1_, & descriptor2_. |
| + void FakeDescriptorBoilerplate() { |
| + InitWithFakeAdapter(); |
| + StartLowEnergyDiscoverySession(); |
| + device_ = DiscoverLowEnergyDevice(3); |
| + device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| + GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| + SimulateGattConnection(device_); |
| + std::vector<std::string> services; |
| + std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); |
| + services.push_back(uuid); |
| + SimulateGattServicesDiscovered(device_, services); |
| + ASSERT_EQ(1u, device_->GetGattServices().size()); |
| + service_ = device_->GetGattServices()[0]; |
| + SimulateGattCharacteristic(service_, uuid, 0); |
| + ASSERT_EQ(1u, service_->GetCharacteristics().size()); |
| + characteristic_ = service_->GetCharacteristics()[0]; |
| + SimulateGattDescriptor(characteristic_, |
| + "00000001-0000-1000-8000-00805f9b34fb"); |
| + SimulateGattDescriptor(characteristic_, |
| + "00000002-0000-1000-8000-00805f9b34fb"); |
| + ASSERT_EQ(2u, characteristic_->GetDescriptors().size()); |
| + descriptor1_ = characteristic_->GetDescriptors()[0]; |
| + descriptor2_ = characteristic_->GetDescriptors()[1]; |
| + ResetEventCounts(); |
| + } |
| + |
| + BluetoothDevice* device_ = nullptr; |
| + BluetoothGattService* service_ = nullptr; |
| + BluetoothGattCharacteristic* characteristic_ = nullptr; |
| + BluetoothGattDescriptor* descriptor1_ = nullptr; |
| + BluetoothGattDescriptor* descriptor2_ = nullptr; |
| +}; |
| #endif |
| #if defined(OS_ANDROID) |
| @@ -137,4 +172,425 @@ TEST_F(BluetoothGattDescriptorTest, GetUUID) { |
| } |
| #endif // defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor and GetValue with empty value buffer. |
| +TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_Empty) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
| + std::vector<uint8_t> empty_vector; |
| + SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| + |
| + // Duplicate read reported from OS shouldn't cause a problem: |
| + SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| + |
| + EXPECT_EQ(empty_vector, last_read_value_); |
| + EXPECT_EQ(empty_vector, descriptor1_->GetValue()); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor with empty value buffer. |
| +TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_Empty) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| + SimulateGattDescriptorWrite(descriptor1_); |
|
ortuno
2016/03/04 17:39:47
Shouldn't we test that duplicated write reported d
scheib
2016/03/11 03:17:30
Done.
|
| + |
| + EXPECT_EQ(empty_vector, last_write_value_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor completing after Chrome objects are deleted. |
| +TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_AfterDeleted) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + |
| + RememberDescriptorForSubsequentAction(descriptor1_); |
| + DeleteDevice(device_); |
|
ortuno
2016/03/04 17:39:47
I wonder if we should explicitly delete the descri
scheib
2016/03/11 03:17:31
We don't test deletions of GATT objects yet. Andro
|
| + |
| + std::vector<uint8_t> empty_vector; |
| + SimulateGattDescriptorRead(/* use remembered descriptor */ nullptr, |
| + empty_vector); |
| + EXPECT_TRUE("Did not crash!"); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor completing after Chrome objects are deleted. |
| +TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_AfterDeleted) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, |
| + GetCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + |
| + RememberDescriptorForSubsequentAction(descriptor1_); |
| + DeleteDevice(device_); |
| + |
| + SimulateGattDescriptorWrite(/* use remembered descriptor */ nullptr); |
| + EXPECT_TRUE("Did not crash!"); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor and GetValue with non-empty value buffer. |
| +TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
| + |
| + 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); |
| + |
| + // Duplicate read reported from OS shouldn't cause a problem: |
| + std::vector<uint8_t> empty_vector; |
| + SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| + |
| + EXPECT_EQ(test_vector, last_read_value_); |
| + EXPECT_EQ(test_vector, descriptor1_->GetValue()); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor with non-empty value buffer. |
| +TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| + std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| + descriptor1_->WriteRemoteDescriptor(test_vector, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| + |
| + SimulateGattDescriptorWrite(descriptor1_); |
| + |
| + EXPECT_EQ(test_vector, last_write_value_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor and GetValue multiple times. |
| +TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_Twice) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
| + |
| + 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); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + EXPECT_EQ(test_vector, last_read_value_); |
| + EXPECT_EQ(test_vector, descriptor1_->GetValue()); |
| + |
| + // Read again, with different value: |
| + ResetEventCounts(); |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
| + std::vector<uint8_t> empty_vector; |
| + SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + EXPECT_EQ(empty_vector, last_read_value_); |
| + EXPECT_EQ(empty_vector, descriptor1_->GetValue()); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor multiple times. |
| +TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_Twice) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| + std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| + descriptor1_->WriteRemoteDescriptor(test_vector, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| + |
| + SimulateGattDescriptorWrite(descriptor1_); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + EXPECT_EQ(test_vector, last_write_value_); |
| + |
| + // Write again, with different value: |
| + ResetEventCounts(); |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| + SimulateGattDescriptorWrite(descriptor1_); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + EXPECT_EQ(empty_vector, last_write_value_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor on two descriptors. |
| +TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_MultipleDescriptors) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + descriptor2_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(2, gatt_read_descriptor_attempts_); |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + |
| + std::vector<uint8_t> test_vector1; |
| + test_vector1.push_back(111); |
| + SimulateGattDescriptorRead(descriptor1_, test_vector1); |
| + EXPECT_EQ(test_vector1, last_read_value_); |
| + |
| + std::vector<uint8_t> test_vector2; |
| + test_vector2.push_back(222); |
| + SimulateGattDescriptorRead(descriptor2_, test_vector2); |
| + EXPECT_EQ(test_vector2, last_read_value_); |
| + |
| + EXPECT_EQ(2, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + EXPECT_EQ(test_vector1, descriptor1_->GetValue()); |
| + EXPECT_EQ(test_vector2, descriptor2_->GetValue()); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor on two descriptors. |
| +TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_MultipleDescriptors) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + std::vector<uint8_t> test_vector1; |
| + test_vector1.push_back(111); |
| + descriptor1_->WriteRemoteDescriptor(test_vector1, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(test_vector1, last_write_value_); |
| + |
| + std::vector<uint8_t> test_vector2; |
| + test_vector2.push_back(222); |
| + descriptor2_->WriteRemoteDescriptor(test_vector2, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(test_vector2, last_write_value_); |
| + |
| + EXPECT_EQ(2, gatt_write_descriptor_attempts_); |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + |
| + SimulateGattDescriptorWrite(descriptor1_); |
| + SimulateGattDescriptorWrite(descriptor2_); |
| + |
| + EXPECT_EQ(2, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor asynchronous error. |
| +TEST_F(BluetoothGattDescriptorTest, ReadError) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + SimulateGattDescriptorReadError( |
| + descriptor1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); |
| + SimulateGattDescriptorReadError(descriptor1_, |
| + BluetoothGattService::GATT_ERROR_FAILED); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, |
| + last_gatt_error_code_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor asynchronous error. |
| +TEST_F(BluetoothGattDescriptorTest, WriteError) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, |
| + GetCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + SimulateGattDescriptorWriteError( |
| + descriptor1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); |
| + SimulateGattDescriptorWriteError(descriptor1_, |
| + BluetoothGattService::GATT_ERROR_FAILED); |
| + |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, |
| + last_gatt_error_code_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor synchronous error. |
| +TEST_F(BluetoothGattDescriptorTest, ReadSynchronousError) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + SimulateGattDescriptorReadWillFailSynchronouslyOnce(descriptor1_); |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + EXPECT_EQ(0, gatt_read_descriptor_attempts_); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(1, error_callback_count_); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); |
| + |
| + // After failing once, can succeed: |
| + ResetEventCounts(); |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
| + std::vector<uint8_t> empty_vector; |
| + SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor synchronous error. |
| +TEST_F(BluetoothGattDescriptorTest, WriteSynchronousError) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + SimulateGattDescriptorWriteWillFailSynchronouslyOnce(descriptor1_); |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, |
| + GetCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + EXPECT_EQ(0, gatt_write_descriptor_attempts_); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(1, error_callback_count_); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); |
| + |
| + // After failing once, can succeed: |
| + ResetEventCounts(); |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| + SimulateGattDescriptorWrite(descriptor1_); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor error with a pending read operation. |
| +TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_ReadPending) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(1, error_callback_count_); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| + last_gatt_error_code_); |
| + |
| + // Initial read should still succeed: |
| + ResetEventCounts(); |
| + std::vector<uint8_t> empty_vector; |
| + SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor error with a pending write operation. |
| +TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_WritePending) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, |
| + GetCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(1, error_callback_count_); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| + last_gatt_error_code_); |
| + |
| + // Initial write should still succeed: |
| + ResetEventCounts(); |
| + SimulateGattDescriptorWrite(descriptor1_); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests ReadRemoteDescriptor error with a pending write operation. |
| +TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_WritePending) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, GetCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(1, error_callback_count_); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| + last_gatt_error_code_); |
| + |
| + // Initial write should still succeed: |
| + ResetEventCounts(); |
| + SimulateGattDescriptorWrite(descriptor1_); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests WriteRemoteDescriptor error with a pending Read operation. |
| +TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_ReadPending) { |
| + ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| + |
| + std::vector<uint8_t> empty_vector; |
| + descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + descriptor1_->WriteRemoteDescriptor(empty_vector, |
| + GetCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(1, error_callback_count_); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| + last_gatt_error_code_); |
| + |
| + // Initial read should still succeed: |
| + ResetEventCounts(); |
| + SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| + EXPECT_EQ(1, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| } // namespace device |