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

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: Created 3 years, 10 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 2143f2a447780758b229139ec4b47eff36ae05e2..c1e2ad2c54dbfe958d9fcf8c5af614187eac9b9f 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
@@ -2371,4 +2371,126 @@ 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_);
+ // Don't run the disconnect task.
scheib 2017/03/04 18:52:24 // Do not yet call RunUntilIdle() to process the d
ortuno 2017/03/07 05:06:47 Makes sense. Done.
+ 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_);
+ // Don't run 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,
+ /* expected_config_descriptor_value: NOTIFY */ 1));
+
+ 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,
+ /* expected_config_descriptor_value: NOTIFY */ 1));
+
+ 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