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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc

Issue 2347133002: bluetooth: Call error callback when characteristics get destroyed during a GATT Event (mac) (Closed)
Patch Set: Improve comments Created 4 years, 3 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
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698