Index: device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc |
diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc |
index 553618e3f3d1956a67c996c3434804101e8ea85e..0102f138f3e3735eeb2bf8577e1fb9602fc7eb1f 100644 |
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc |
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc |
@@ -378,6 +378,45 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, |
} |
#endif // defined(OS_ANDROID) || defined(OS_WIN) |
+// TODO(crbug.com/621901): Enable test on all platforms. |
+#if defined(OS_MACOSX) |
+TEST_F(BluetoothRemoteGattCharacteristicTest, |
+ ReadRemoteCharacteristic_Disconnected) { |
+ if (!PlatformSupportsLowEnergy()) { |
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
+ return; |
+ } |
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
+ BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
+ |
+ characteristic1_->ReadRemoteCharacteristic( |
+ GetReadValueCallback(Call::NOT_EXPECTED), |
+ GetGattErrorCallback(Call::EXPECTED)); |
+ |
+// Set up for receiving a read response after disconnection. |
+// On macOS no events arrive after disconnection so there is no point |
+// in building the infrastructure to test this behavior. FYI |
+// the code CHECKs that responses arrive only when the device is connected. |
+#if !defined(OS_MACOSX) |
+ RememberCharacteristicForSubsequentAction(characteristic1_); |
+#endif |
+ |
+ ASSERT_EQ(1u, adapter_->GetDevices().size()); |
+ SimulateGattDisconnection(adapter_->GetDevices()[0]); |
+ |
+ EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
+ last_gatt_error_code_); |
+ |
+// Dispatch read response after disconnection. See above explanation for why |
+// we don't do this in macOS. |
+#if !defined(OS_MACOSX) |
+ std::vector<uint8_t> empty_vector; |
+ SimulateGattCharacteristicRead(nullptr /* use remembered characteristic */, |
+ empty_vector); |
+#endif |
+} |
+#endif // defined(OS_MACOSX) |
+ |
#if defined(OS_ANDROID) || defined(OS_WIN) |
// Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. |
// macOS: Not applicable: This can never happen if CBPeripheral delegate is set |
@@ -404,6 +443,44 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, |
} |
#endif // defined(OS_ANDROID) || defined(OS_WIN) |
+// TODO(crbug.com/621901): Enable test on all platforms. |
+#if defined(OS_MACOSX) |
+TEST_F(BluetoothRemoteGattCharacteristicTest, |
+ WriteRemoteCharacteristic_Disconnected) { |
+ if (!PlatformSupportsLowEnergy()) { |
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
+ return; |
+ } |
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
+ BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
+ |
+ std::vector<uint8_t> empty_vector; |
+ characteristic1_->WriteRemoteCharacteristic( |
+ empty_vector, GetCallback(Call::NOT_EXPECTED), |
+ GetGattErrorCallback(Call::EXPECTED)); |
+ |
+// Set up for receiving a write response after disconnection. |
+// On macOS no events arrive after disconnection so there is no point |
+// in building the infrastructure to test this behavior. FYI |
+// the code CHECKs that responses arrive only when the device is connected. |
+#if !defined(OS_MACOSX) |
+ RememberCharacteristicForSubsequentAction(characteristic1_); |
+#endif // !defined(OS_MACOSX) |
+ |
+ ASSERT_EQ(1u, adapter_->GetDevices().size()); |
+ SimulateGattDisconnection(adapter_->GetDevices()[0]); |
+ |
+ EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
+ last_gatt_error_code_); |
+ |
+// Dispatch write response after disconnection. See above explanation for why |
+// we don't do this in macOS. |
+#if !defined(OS_MACOSX) |
+ SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); |
+#endif // !defined(OS_MACOSX) |
+} |
+#endif // defined(OS_MACOSX) |
+ |
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
// Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. |
TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) { |