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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc

Issue 2634873002: Bluetooth: macOS: Implement BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications (Closed)
Patch Set: Adding last_notify_value for macOS 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 a0ee705f9173ccb1c95a6afb6f176a3ef30cfc37..52fabd3edfc592e64380f751c093ddcfd6b3cd42 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
@@ -132,6 +132,9 @@ class BluetoothRemoteGattCharacteristicTest : public BluetoothTest {
uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF;
EXPECT_EQ(expected_byte0, last_write_value_[0]);
EXPECT_EQ(expected_byte1, last_write_value_[1]);
+#else
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+ EXPECT_TRUE(last_notify_value);
#endif // !defined(OS_MACOSX)
}
@@ -1010,12 +1013,15 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
-#if defined(OS_ANDROID) || defined(OS_WIN)
+#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
// StartNotifySession fails if the characteristic is missing the Client
// Characteristic Configuration descriptor.
-// macOS: TODO(crbug.com/624017) Need to implement CCC descriptors.
TEST_F(BluetoothRemoteGattCharacteristicTest,
StartNotifySession_NoConfigDescriptor) {
+ 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,
@@ -1030,14 +1036,17 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
last_gatt_error_code_);
}
-#endif // defined(OS_ANDROID) || defined(OS_WIN)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
-#if defined(OS_ANDROID) || defined(OS_WIN)
+#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
// StartNotifySession fails if the characteristic has multiple Client
// Characteristic Configuration descriptors.
-// macOS: TODO(crbug.com/624017) Need to implement CCC descriptors.
TEST_F(BluetoothRemoteGattCharacteristicTest,
StartNotifySession_MultipleConfigDescriptor) {
+ 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,
@@ -1052,7 +1061,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
last_gatt_error_code_);
}
-#endif // defined(OS_ANDROID) || defined(OS_WIN)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
#if defined(OS_ANDROID)
// StartNotifySession fails synchronously when failing to set a characteristic
@@ -1155,10 +1164,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) {
characteristic1_,
BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
.canonical_value());
-#if !defined(OS_MACOSX)
- // TODO(crbug.com/624017): Need implementation for descriptors.
ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
-#endif // !defined(OS_MACOSX)
characteristic1_->StartNotifySession(
GetNotifyCallback(Call::EXPECTED),
@@ -1198,10 +1204,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
characteristic1_,
BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
.canonical_value());
-#if !defined(OS_MACOSX)
- // TODO(crbug.com/624017): Need implementation for descriptors.
ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
-#endif // !defined(OS_MACOSX)
characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
GetGattErrorCallback(Call::EXPECTED));
@@ -1251,10 +1254,14 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) {
}
#endif // defined(OS_ANDROID)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests StartNotifySession completing before chrome objects are deleted.
TEST_F(BluetoothRemoteGattCharacteristicTest,
StartNotifySession_BeforeDeleted) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(
FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
SimulateGattDescriptor(
@@ -1288,7 +1295,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
notify_sessions_[0]->GetCharacteristicIdentifier());
EXPECT_FALSE(notify_sessions_[0]->IsActive());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
#if defined(OS_MACOSX) || defined(OS_WIN)
// Tests StartNotifySession reentrant in start notify session success callback
@@ -1304,10 +1311,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
SimulateGattDescriptor(
characteristic1_,
BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
-#if !defined(OS_MACOSX)
- // TODO(crbug.com/624017): Need implementation for descriptors.
ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
-#endif // !defined(OS_MACOSX)
characteristic1_->StartNotifySession(
GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED,
@@ -1408,70 +1412,111 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
}
#endif // defined(OS_WIN)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests StopNotifySession success on a characteristic that enabled Notify.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) {
+ 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));
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
EXPECT_EQ(1, gatt_write_descriptor_attempts_);
+#else
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+ EXPECT_TRUE(last_notify_value);
+#endif // !defined(OS_MACOSX)
notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
SimulateGattNotifySessionStopped(characteristic1_);
base::RunLoop().RunUntilIdle();
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
// Check that the right values were written to the descriptor.
EXPECT_EQ(2, gatt_write_descriptor_attempts_);
ASSERT_EQ(2u, last_write_value_.size());
EXPECT_EQ(0, last_write_value_[0]);
EXPECT_EQ(0, last_write_value_[1]);
+#else
+ EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
+ EXPECT_FALSE(last_notify_value);
+#endif // !defined(OS_MACOSX)
// Check that the notify session is inactive.
EXPECT_FALSE(notify_sessions_[0]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests that deleted sessions are stopped.
TEST_F(BluetoothRemoteGattCharacteristicTest,
StopNotifySession_SessionDeleted) {
+ 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));
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
EXPECT_EQ(1, gatt_write_descriptor_attempts_);
+#else
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+ EXPECT_TRUE(last_notify_value);
+#endif // !defined(OS_MACOSX)
notify_sessions_.clear();
SimulateGattNotifySessionStopped(characteristic1_);
base::RunLoop().RunUntilIdle();
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
// Check that the right values were written to the descriptor.
EXPECT_EQ(2, gatt_write_descriptor_attempts_);
ASSERT_EQ(2u, last_write_value_.size());
EXPECT_EQ(0, last_write_value_[0]);
EXPECT_EQ(0, last_write_value_[1]);
+#else
+ EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
+ EXPECT_FALSE(last_notify_value);
+#endif // !defined(OS_MACOSX)
// Check that the notify session is inactive.
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests that deleting the sessions before the stop callbacks have been
// invoked does not cause problems.
TEST_F(BluetoothRemoteGattCharacteristicTest,
StopNotifySession_SessionDeleted2) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(
FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
-#if !defined(OS_MACOSX)
- // TODO(624017) enable for macosx
SimulateGattDescriptor(
characteristic1_,
BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
.canonical_value());
ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
-#endif
// Start notify sessions.
characteristic1_->StartNotifySession(
@@ -1511,15 +1556,17 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
EXPECT_TRUE("Did not crash!");
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests that cancelling StopNotifySession works.
-// TODO(crbug.com/633191): Enable on macOS when SubscribeToNotifications is
-// implemented.
// TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is
// implemented.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) {
+ 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));
@@ -1537,11 +1584,15 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) {
// Cancel Stop by deleting the device before Stop finishes.
DeleteDevice(device_); // TODO(576906) delete only the characteristic.
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests that deleted sessions are stopped.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) {
+ 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));
@@ -1571,61 +1622,105 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) {
notify_sessions_[0]->GetCharacteristicIdentifier());
EXPECT_FALSE(notify_sessions_[0]->IsActive());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests StopNotifySession success on a characteristic that enabled Indicate.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
/* properties: INDICATE */ 0x20,
/* expected_config_descriptor_value: INDICATE */ 2));
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
EXPECT_EQ(1, gatt_write_descriptor_attempts_);
+#else
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+ EXPECT_TRUE(last_notify_value);
+#endif // !defined(OS_MACOSX)
notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
SimulateGattNotifySessionStopped(characteristic1_);
base::RunLoop().RunUntilIdle();
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
// Check that the right values were written to the descriptor.
EXPECT_EQ(2, gatt_write_descriptor_attempts_);
ASSERT_EQ(2u, last_write_value_.size());
EXPECT_EQ(0, last_write_value_[0]);
EXPECT_EQ(0, last_write_value_[1]);
+#else
+ EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
+ EXPECT_FALSE(last_notify_value);
+#endif // !defined(OS_MACOSX)
// Check that the notify session is inactive.
EXPECT_FALSE(notify_sessions_[0]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests StopNotifySession success on a characteristic that enabled Notify &
// Indicate.
TEST_F(BluetoothRemoteGattCharacteristicTest,
StopNotifySession_OnNotifyAndIndicate) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
/* properties: NOTIFY and INDICATE bits set */ 0x30,
/* expected_config_descriptor_value: INDICATE */ 1));
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
EXPECT_EQ(1, gatt_write_descriptor_attempts_);
+#else
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+ EXPECT_TRUE(last_notify_value);
+#endif // !defined(OS_MACOSX)
notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
SimulateGattNotifySessionStopped(characteristic1_);
base::RunLoop().RunUntilIdle();
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
// Check that the right values were written to the descriptor.
EXPECT_EQ(2, gatt_write_descriptor_attempts_);
ASSERT_EQ(2u, last_write_value_.size());
EXPECT_EQ(0, last_write_value_[0]);
EXPECT_EQ(0, last_write_value_[1]);
+#else
+ EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
+ EXPECT_FALSE(last_notify_value);
+#endif // !defined(OS_MACOSX)
// Check that the notify session is inactive.
EXPECT_FALSE(notify_sessions_[0]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests StopNotifySession error
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) {
+ 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));
@@ -1646,22 +1741,23 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) {
EXPECT_FALSE(notify_sessions_[0]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests multiple StopNotifySession calls for a single session.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(
FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
-#if !defined(OS_MACOSX)
- // TODO(624017) enable for macosx
SimulateGattDescriptor(
characteristic1_,
BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
.canonical_value());
ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
-#endif
// Start notify session
characteristic1_->StartNotifySession(
@@ -1690,22 +1786,23 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) {
EXPECT_FALSE(notify_sessions_[0]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests multiple StartNotifySession calls and multiple StopNotifySession calls.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(
FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
-#if !defined(OS_MACOSX)
- // TODO(624017) enable for macosx
SimulateGattDescriptor(
characteristic1_,
BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
.canonical_value());
ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
-#endif
// Start notify sessions
characteristic1_->StartNotifySession(
@@ -1745,12 +1842,16 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) {
EXPECT_FALSE(notify_sessions_[1]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests starting a new notify session before the previous stop request
// resolves.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(
FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
SimulateGattDescriptor(
@@ -1791,11 +1892,15 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) {
EXPECT_TRUE(notify_sessions_[1]->IsActive());
EXPECT_TRUE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
TEST_F(BluetoothRemoteGattCharacteristicTest,
StopNotifySession_StartStopStart) {
+ 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));
@@ -1843,12 +1948,16 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
EXPECT_TRUE(characteristic1_->IsNotifying());
}
-#endif
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests starting a new notify session before the previous stop requests
// resolve.
TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(
FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
SimulateGattDescriptor(
@@ -1867,25 +1976,48 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) {
ASSERT_EQ(1u, notify_sessions_.size());
ASSERT_TRUE(notify_sessions_[0]);
EXPECT_TRUE(notify_sessions_[0]->IsActive());
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
EXPECT_EQ(1, gatt_write_descriptor_attempts_);
+#else
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+ EXPECT_TRUE(last_notify_value);
+#endif // !defined(OS_MACOSX)
// Stop the notify session twice
notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1));
notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(2));
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
// Check that the right values were written to the descriptor.
EXPECT_EQ(2, gatt_write_descriptor_attempts_);
ASSERT_EQ(2u, last_write_value_.size());
EXPECT_EQ(0, last_write_value_[0]);
EXPECT_EQ(0, last_write_value_[1]);
+#else
+ EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
+ EXPECT_FALSE(last_notify_value);
+#endif // !defined(OS_MACOSX)
// Start another notify session
characteristic1_->StartNotifySession(
GetNotifyCheckForPrecedingCalls(3),
GetGattErrorCallback(Call::NOT_EXPECTED));
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
// Check that nothing was written by the StartNotifySession call above
EXPECT_EQ(2, gatt_write_descriptor_attempts_);
+#else
+ EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
+#endif // !defined(OS_MACOSX)
SimulateGattNotifySessionStopped(characteristic1_);
base::RunLoop().RunUntilIdle();
@@ -1894,11 +2026,19 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) {
SimulateGattNotifySessionStarted(characteristic1_);
base::RunLoop().RunUntilIdle();
+// macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
+// setNotifyValue:forCharacteristic:] which handles all interactions with
+// the CCC descriptor.
+#if !defined(OS_MACOSX)
// Check that the right values were written to the descriptor.
EXPECT_EQ(3, gatt_write_descriptor_attempts_);
ASSERT_EQ(2u, last_write_value_.size());
EXPECT_EQ(1, last_write_value_[0]);
EXPECT_EQ(0, last_write_value_[1]);
+#else
+ EXPECT_EQ(3, gatt_notify_characteristic_attempts_);
+ EXPECT_TRUE(last_notify_value);
+#endif // !defined(OS_MACOSX)
// Check the notify state
ASSERT_EQ(2u, notify_sessions_.size());
@@ -1908,11 +2048,15 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) {
EXPECT_TRUE(notify_sessions_[1]->IsActive());
EXPECT_TRUE(characteristic1_->IsNotifying());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
TEST_F(BluetoothRemoteGattCharacteristicTest,
StopNotifySession_Reentrant_Success_Stop) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
ASSERT_NO_FATAL_FAILURE(
FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
SimulateGattDescriptor(
@@ -1948,11 +2092,15 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
EXPECT_FALSE(notify_sessions_[0]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
TEST_F(BluetoothRemoteGattCharacteristicTest,
StopNotifySession_Reentrant_Stop_StartSuccess) {
+ 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));
@@ -1990,11 +2138,15 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
EXPECT_TRUE(notify_sessions_[1]->IsActive());
EXPECT_TRUE(characteristic1_->IsNotifying());
}
-#endif
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
TEST_F(BluetoothRemoteGattCharacteristicTest,
StopNotifySession_Reentrant_Stop_StartError) {
+ 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));
@@ -2030,7 +2182,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
EXPECT_FALSE(notify_sessions_[0]->IsActive());
EXPECT_FALSE(characteristic1_->IsNotifying());
}
-#endif
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
// Tests Characteristic Value changes during a Notify Session.
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm ('k') | device/bluetooth/test/bluetooth_test_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698