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 d320f956062082ef61589bba6d8c84f303679d7b..05127c2c5d645417db9c4776ff4fe51d415c74a9 100644 |
| --- a/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc |
| +++ b/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc |
| @@ -98,9 +98,9 @@ class BluetoothGattCharacteristicTest : public BluetoothTest { |
| GetNotifyCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| EXPECT_EQ(0, callback_count_); |
| SimulateGattNotifySessionStarted(characteristic1_); |
| + EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
|
ortuno
2016/03/14 01:37:37
Since it's not related to notifications I think th
gogerald1
2016/03/15 00:48:19
Done. Mentioned in CL description.
|
| EXPECT_EQ(1, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| ASSERT_EQ(1u, notify_sessions_.size()); |
| @@ -273,13 +273,13 @@ TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { |
| characteristic1_->ReadRemoteCharacteristic( |
| GetReadValueCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| std::vector<uint8_t> empty_vector; |
| SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| // Duplicate read reported from OS shouldn't cause a problem: |
| SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| + EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| EXPECT_EQ(empty_vector, last_read_value_); |
| EXPECT_EQ(empty_vector, characteristic1_->GetValue()); |
| } |
| @@ -295,9 +295,9 @@ TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { |
| characteristic1_->WriteRemoteCharacteristic( |
| empty_vector, GetCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| SimulateGattCharacteristicWrite(characteristic1_); |
| + EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| EXPECT_EQ(empty_vector, last_write_value_); |
| } |
| #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| @@ -351,7 +351,6 @@ TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { |
| characteristic1_->ReadRemoteCharacteristic( |
| GetReadValueCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| @@ -361,6 +360,7 @@ TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { |
| std::vector<uint8_t> empty_vector; |
| SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| + EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| EXPECT_EQ(test_vector, last_read_value_); |
| EXPECT_EQ(test_vector, characteristic1_->GetValue()); |
| } |
| @@ -377,10 +377,10 @@ TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) { |
| characteristic1_->WriteRemoteCharacteristic( |
| test_vector, GetCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| SimulateGattCharacteristicWrite(characteristic1_); |
| + EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| EXPECT_EQ(test_vector, last_write_value_); |
| } |
| #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| @@ -394,11 +394,11 @@ TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { |
| characteristic1_->ReadRemoteCharacteristic( |
| GetReadValueCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| SimulateGattCharacteristicRead(characteristic1_, test_vector); |
| + EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| EXPECT_EQ(1, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| EXPECT_EQ(test_vector, last_read_value_); |
| @@ -409,9 +409,9 @@ TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { |
| characteristic1_->ReadRemoteCharacteristic( |
| GetReadValueCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| std::vector<uint8_t> empty_vector; |
| SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| + EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| EXPECT_EQ(1, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| EXPECT_EQ(empty_vector, last_read_value_); |
| @@ -430,9 +430,9 @@ TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { |
| characteristic1_->WriteRemoteCharacteristic( |
| test_vector, GetCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| SimulateGattCharacteristicWrite(characteristic1_); |
| + EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| EXPECT_EQ(1, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| EXPECT_EQ(test_vector, last_write_value_); |
| @@ -443,8 +443,9 @@ TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { |
| characteristic1_->WriteRemoteCharacteristic( |
| empty_vector, GetCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| + |
| SimulateGattCharacteristicWrite(characteristic1_); |
| + EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| EXPECT_EQ(1, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| EXPECT_EQ(empty_vector, last_write_value_); |
| @@ -464,7 +465,6 @@ TEST_F(BluetoothGattCharacteristicTest, |
| characteristic2_->ReadRemoteCharacteristic( |
| GetReadValueCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| - EXPECT_EQ(2, gatt_read_characteristic_attempts_); |
| EXPECT_EQ(0, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| @@ -478,6 +478,7 @@ TEST_F(BluetoothGattCharacteristicTest, |
| SimulateGattCharacteristicRead(characteristic2_, test_vector2); |
| EXPECT_EQ(test_vector2, last_read_value_); |
| + EXPECT_EQ(2, gatt_read_characteristic_attempts_); |
| EXPECT_EQ(2, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| @@ -510,7 +511,6 @@ TEST_F(BluetoothGattCharacteristicTest, |
| EXPECT_EQ(test_vector2, last_write_value_); |
| #endif |
| - EXPECT_EQ(2, gatt_write_characteristic_attempts_); |
| EXPECT_EQ(0, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| @@ -524,6 +524,7 @@ TEST_F(BluetoothGattCharacteristicTest, |
| EXPECT_EQ(test_vector2, last_write_value_); |
| #endif |
| + EXPECT_EQ(2, gatt_write_characteristic_attempts_); |
| EXPECT_EQ(2, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| @@ -743,7 +744,7 @@ TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_ReadPending) { |
| } |
| #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
|
ortuno
2016/03/14 01:37:37
I think you misunderstood the purpose of these tes
scheib
2016/03/14 17:54:46
I agree with everything above.
gogerald@ please ad
gogerald1
2016/03/15 00:48:19
Done.
gogerald1
2016/03/15 00:48:19
Done.
|
| // StartNotifySession fails if characteristic doesn't have Notify or Indicate |
| // property. |
| TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { |
| @@ -756,12 +757,12 @@ TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { |
| // The expected error callback is asynchronous: |
| EXPECT_EQ(0, error_callback_count_); |
| - base::RunLoop().RunUntilIdle(); |
| + RunUntilIdle(); |
| EXPECT_EQ(1, error_callback_count_); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // StartNotifySession fails if the characteristic is missing the Client |
| // Characteristic Configuration descriptor. |
| TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { |
| @@ -774,12 +775,12 @@ TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { |
| // The expected error callback is asynchronous: |
| EXPECT_EQ(0, error_callback_count_); |
| - base::RunLoop().RunUntilIdle(); |
| + RunUntilIdle(); |
| EXPECT_EQ(1, error_callback_count_); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // StartNotifySession fails synchronously when failing to set a characteristic |
| // to enable notifications. |
| // Android: This is mBluetoothGatt.setCharacteristicNotification failing. |
| @@ -792,15 +793,15 @@ TEST_F(BluetoothGattCharacteristicTest, |
| // The expected error callback is asynchronous: |
| EXPECT_EQ(0, error_callback_count_); |
| - base::RunLoop().RunUntilIdle(); |
| + RunUntilIdle(); |
| EXPECT_EQ(1, error_callback_count_); |
| EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| ASSERT_EQ(0u, notify_sessions_.size()); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // Tests StartNotifySession descriptor write synchronous failure. |
| TEST_F(BluetoothGattCharacteristicTest, |
| StartNotifySession_WriteDescriptorSynchronousError) { |
| @@ -811,33 +812,33 @@ TEST_F(BluetoothGattCharacteristicTest, |
| // The expected error callback is asynchronous: |
| EXPECT_EQ(0, error_callback_count_); |
| - base::RunLoop().RunUntilIdle(); |
| + RunUntilIdle(); |
| EXPECT_EQ(1, error_callback_count_); |
| EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| ASSERT_EQ(0u, notify_sessions_.size()); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // Tests StartNotifySession success on a characteristic enabling Notify. |
| TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { |
| ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| /* properties: NOTIFY */ 0x10, |
| /* expected_config_descriptor_value: NOTIFY */ 1)); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // Tests StartNotifySession success on a characteristic enabling Indicate. |
| TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_OnIndicate) { |
| ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| /* properties: INDICATE */ 0x20, |
| /* expected_config_descriptor_value: INDICATE */ 2)); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // Tests StartNotifySession success on a characteristic enabling Notify & |
| // Indicate. |
| TEST_F(BluetoothGattCharacteristicTest, |
| @@ -846,9 +847,9 @@ TEST_F(BluetoothGattCharacteristicTest, |
| /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| /* expected_config_descriptor_value: NOTIFY */ 1)); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // Tests Characteristic Value changes during a Notify Session. |
| TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { |
| ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| @@ -869,11 +870,13 @@ TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { |
| EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| #if defined(OS_ANDROID) |
| // Tests Characteristic Value changing after a Notify Session and objects being |
| // destroyed. |
| +// On Windows, characteristic changed notification is not available after |
| +// deleting the device. |
|
ortuno
2016/03/14 01:37:37
[...] after deleting the device because we synchro
gogerald1
2016/03/15 00:48:19
Done.
|
| TEST_F(BluetoothGattCharacteristicTest, |
| GattCharacteristicValueChanged_AfterDeleted) { |
| ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| @@ -890,7 +893,7 @@ TEST_F(BluetoothGattCharacteristicTest, |
| } |
| #endif // defined(OS_ANDROID) |
| -#if defined(OS_ANDROID) |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| // Tests multiple StartNotifySession success. |
| TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| ASSERT_NO_FATAL_FAILURE( |
| @@ -907,6 +910,9 @@ TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| characteristic1_->StartNotifySession( |
| GetNotifyCallback(Call::EXPECTED), |
| GetGattErrorCallback(Call::NOT_EXPECTED)); |
| + |
| + EXPECT_EQ(0, callback_count_); |
| + SimulateGattNotifySessionStarted(characteristic1_); |
| #if defined(OS_ANDROID) |
| // TODO(crbug.com/551634): Decide when implementing IsNotifying if Android |
| // should trust the notification request always worked, or if we should always |
| @@ -915,8 +921,6 @@ TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| #else |
| EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| #endif |
| - EXPECT_EQ(0, callback_count_); |
| - SimulateGattNotifySessionStarted(characteristic1_); |
| EXPECT_EQ(2, callback_count_); |
| EXPECT_EQ(0, error_callback_count_); |
| ASSERT_EQ(2u, notify_sessions_.size()); |
| @@ -929,7 +933,7 @@ TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| } |
| -#endif // defined(OS_ANDROID) |
| +#endif // defined(OS_ANDROID) || defined(OS_WIN) |
| #if defined(OS_ANDROID) || defined(OS_WIN) |
| TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { |