Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc

Issue 2702163002: bluetooth: Close and null out BluetoothGatt on the UI Thread (Closed)
Patch Set: Fix test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a1bd087993b730985f41faaa9e705b8e8586b30b..957230a8e5753f0987a41f95b7ad3ca2544dc9d7 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
@@ -2243,4 +2243,124 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetDescriptorsByUUID) {
}
#endif // defined(OS_ANDROID) || defined(OS_WIN)
+#if defined(OS_ANDROID)
+// Tests that read requests after a device disconnects but before the disconnect
+// task has a chance to run result in an error.
+// macOS: Does not apply. All events arrive on the UI Thread.
+// TODO(crbug.com/694102): Enable this test on Windows.
+TEST_F(BluetoothRemoteGattCharacteristicTest, ReadDuringDisconnect) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
+ BluetoothRemoteGattCharacteristic::PROPERTY_READ));
+
+ SimulateGattDisconnection(device_);
+ // Do not yet call RunUntilIdle() to process the disconnect task.
+ characteristic1_->ReadRemoteCharacteristic(
+ GetReadValueCallback(Call::NOT_EXPECTED),
+ GetGattErrorCallback(Call::EXPECTED));
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
+ last_gatt_error_code_);
+}
+#endif
+
+#if defined(OS_ANDROID)
+// Tests that write requests after a device disconnects but before the
+// disconnect task runs result in an error.
+// macOS: Does not apply. All events arrive on the UI Thread.
+// TODO(crbug.com/694102): Enable this test on Windows.
+TEST_F(BluetoothRemoteGattCharacteristicTest, WriteDuringDisconnect) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
+ BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
+
+ SimulateGattDisconnection(device_);
+ // Do not yet call RunUntilIdle() to process the disconnect task.
+ characteristic1_->WriteRemoteCharacteristic(
+ std::vector<uint8_t>(), GetCallback(Call::NOT_EXPECTED),
+ GetGattErrorCallback(Call::EXPECTED));
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
+ last_gatt_error_code_);
+}
+#endif
+
+#if defined(OS_ANDROID)
+// Tests that start notifications requests after a device disconnects but before
+// the disconnect task runs result in an error.
+// macOS: Does not apply. All events arrive on the UI Thread.
+// TODO(crbug.com/694102): Enable this test on Windows.
+TEST_F(BluetoothRemoteGattCharacteristicTest,
+ StartNotifySessionDuringDisconnect) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
+ BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
+ SimulateGattDescriptor(
+ characteristic1_,
+ BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
+ .canonical_value());
+
+ SimulateGattDisconnection(device_);
+ // Don't run the disconnect task.
+ characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
+ GetGattErrorCallback(Call::EXPECTED));
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
+ last_gatt_error_code_);
+}
+#endif
+
+#if defined(OS_ANDROID)
+// Tests that stop notifications requests after a device disconnects but before
+// the disconnect task runs do not result in a crash.
+// macOS: Does not apply. All events arrive on the UI Thread.
+// TODO(crbug.com/694102): Enable this test on Windows.
+TEST_F(BluetoothRemoteGattCharacteristicTest,
+ StopNotifySessionDuringDisconnect) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
+ /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY));
+
+ SimulateGattDisconnection(device_);
+ // Don't run the disconnect task.
+ notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
+ base::RunLoop().RunUntilIdle();
+}
+#endif
+
+#if defined(OS_ANDROID)
+// Tests that deleting notify sessions after a device disconnects but before the
+// disconnect task runs do not result in a crash.
+// macOS: Does not apply. All events arrive on the UI Thread.
+// TODO(crbug.com/694102): Enable this test on Windows.
+TEST_F(BluetoothRemoteGattCharacteristicTest,
+ DeleteNotifySessionDuringDisconnect) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
+ /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY));
+
+ SimulateGattDisconnection(device_);
+ // Don't run the disconnect task.
+ notify_sessions_.clear();
+ base::RunLoop().RunUntilIdle();
+}
+#endif
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698