Chromium Code Reviews| Index: device/bluetooth/bluetooth_gatt_characteristic_unittest.cc |
| diff --git a/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc b/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc |
| index 00ecba11bb200e0444b8648b2a089ba82df5f9c5..fdb804e05980853ad5d17825e3d280a4b33f20ef 100644 |
| --- a/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc |
| +++ b/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc |
| @@ -72,8 +72,8 @@ class BluetoothGattCharacteristicTest : public BluetoothTest { |
| if (error != StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING) { |
| SimulateGattDescriptor( |
| characteristic1_, |
| - /* Client Characteristic Configuration descriptor's standard UUID: */ |
| - "00002902-0000-1000-8000-00805F9B34FB"); |
| + BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| + .canonical_value()); |
| ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| } |
| @@ -298,6 +298,9 @@ TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { |
| EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| SimulateGattCharacteristicWrite(characteristic1_); |
| + // Duplicate write reported from OS shouldn't cause a problem: |
| + SimulateGattCharacteristicWrite(characteristic1_); |
| + |
| EXPECT_EQ(empty_vector, last_write_value_); |
| } |
| #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| @@ -313,7 +316,7 @@ TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_AfterDeleted) { |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| RememberCharacteristicForSubsequentAction(characteristic1_); |
| - DeleteDevice(device_); |
| + DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
|
ortuno
2016/03/13 22:45:03
nit: This should follow the same pattern as other
scheib
2016/03/14 20:00:16
Done, by fixing the other TODOs to the shorter for
|
| std::vector<uint8_t> empty_vector; |
| SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, |
| @@ -335,7 +338,7 @@ TEST_F(BluetoothGattCharacteristicTest, |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| RememberCharacteristicForSubsequentAction(characteristic1_); |
| - DeleteDevice(device_); |
| + DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
|
ortuno
2016/03/13 22:45:03
Same here. TODO should follow same pattern as othe
scheib
2016/03/14 20:00:16
Done.
|
| SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); |
| EXPECT_TRUE("Did not crash!"); |
| @@ -849,6 +852,93 @@ TEST_F(BluetoothGattCharacteristicTest, |
| #endif // defined(OS_ANDROID) |
| #if defined(OS_ANDROID) |
| +// Tests multiple StartNotifySession success. |
| +TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| + ASSERT_NO_FATAL_FAILURE( |
| + FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| + SimulateGattDescriptor( |
| + characteristic1_, |
| + BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| + .canonical_value()); |
| + ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| + |
| + characteristic1_->StartNotifySession( |
| + GetNotifyCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + characteristic1_->StartNotifySession( |
| + GetNotifyCallback(Call::EXPECTED), |
| + GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| + EXPECT_EQ(0, callback_count_); |
| + SimulateGattNotifySessionStarted(characteristic1_); |
| + EXPECT_EQ(2, callback_count_); |
| + EXPECT_EQ(0, error_callback_count_); |
| + ASSERT_EQ(2u, notify_sessions_.size()); |
| + ASSERT_TRUE(notify_sessions_[0]); |
| + ASSERT_TRUE(notify_sessions_[1]); |
| + EXPECT_EQ(characteristic1_->GetIdentifier(), |
| + notify_sessions_[0]->GetCharacteristicIdentifier()); |
| + EXPECT_EQ(characteristic1_->GetIdentifier(), |
| + notify_sessions_[1]->GetCharacteristicIdentifier()); |
| + EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| + EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests multiple StartNotifySession success. |
| +TEST_F(BluetoothGattCharacteristicTest, StartNotifySessionError_Multiple) { |
| + ASSERT_NO_FATAL_FAILURE( |
| + FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| + SimulateGattDescriptor( |
| + characteristic1_, |
| + BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| + .canonical_value()); |
| + ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| + |
| + characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| + EXPECT_EQ(0, callback_count_); |
| + SimulateGattNotifySessionStartError(characteristic1_, |
| + BluetoothGattService::GATT_ERROR_FAILED); |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(2, error_callback_count_); |
| + ASSERT_EQ(0u, notify_sessions_.size()); |
| + EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +// Tests multiple StartNotifySession success. |
|
ortuno
2016/03/13 22:45:03
Wrong test description.
scheib
2016/03/14 20:00:16
Done.
|
| +TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_AfterDeleted) { |
| + ASSERT_NO_FATAL_FAILURE( |
| + FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| + SimulateGattDescriptor( |
| + characteristic1_, |
| + BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| + .canonical_value()); |
| + ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| + |
| + characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| + GetGattErrorCallback(Call::EXPECTED)); |
| + EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| + EXPECT_EQ(0, callback_count_); |
| + |
| + RememberCharacteristicForSubsequentAction(characteristic1_); |
| + RememberCCCDescriptorForSubsequentAction(characteristic1_); |
| + DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| + |
| + SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); |
| + EXPECT_EQ(0, callback_count_); |
| + EXPECT_EQ(1, error_callback_count_); |
| + ASSERT_EQ(0u, notify_sessions_.size()); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| // Tests Characteristic Value changes during a Notify Session. |
| TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { |
| ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| @@ -881,7 +971,7 @@ TEST_F(BluetoothGattCharacteristicTest, |
| /* expected_config_descriptor_value: NOTIFY */ 1)); |
| RememberCharacteristicForSubsequentAction(characteristic1_); |
| - DeleteDevice(device_); |
| + DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| std::vector<uint8_t> empty_vector; |
| SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, |
| @@ -890,40 +980,6 @@ TEST_F(BluetoothGattCharacteristicTest, |
| } |
| #endif // defined(OS_ANDROID) |
| -#if defined(OS_ANDROID) |
| -// Tests multiple StartNotifySession success. |
| -TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| - ASSERT_NO_FATAL_FAILURE( |
| - FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| - SimulateGattDescriptor( |
| - characteristic1_, |
| - BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| - .canonical_value()); |
| - ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| - |
| - characteristic1_->StartNotifySession( |
| - GetNotifyCallback(Call::EXPECTED), |
| - GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - characteristic1_->StartNotifySession( |
| - GetNotifyCallback(Call::EXPECTED), |
| - GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| - EXPECT_EQ(0, callback_count_); |
| - SimulateGattNotifySessionStarted(characteristic1_); |
| - EXPECT_EQ(2, callback_count_); |
| - EXPECT_EQ(0, error_callback_count_); |
| - ASSERT_EQ(2u, notify_sessions_.size()); |
| - ASSERT_TRUE(notify_sessions_[0]); |
| - ASSERT_TRUE(notify_sessions_[1]); |
| - EXPECT_EQ(characteristic1_->GetIdentifier(), |
| - notify_sessions_[0]->GetCharacteristicIdentifier()); |
| - EXPECT_EQ(characteristic1_->GetIdentifier(), |
| - notify_sessions_[1]->GetCharacteristicIdentifier()); |
| - EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| - EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| -} |
| -#endif // defined(OS_ANDROID) |
| - |
| #if defined(OS_ANDROID) || defined(OS_WIN) |
| TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { |
| ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |