| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 #if !defined(OS_MACOSX) | 125 #if !defined(OS_MACOSX) |
| 126 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 126 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 127 // setNotifyValue:forCharacteristic:] which handles all interactions with | 127 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 128 // the CCC descriptor. | 128 // the CCC descriptor. |
| 129 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | 129 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| 130 EXPECT_EQ(2u, last_write_value_.size()); | 130 EXPECT_EQ(2u, last_write_value_.size()); |
| 131 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF; | 131 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF; |
| 132 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF; | 132 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF; |
| 133 EXPECT_EQ(expected_byte0, last_write_value_[0]); | 133 EXPECT_EQ(expected_byte0, last_write_value_[0]); |
| 134 EXPECT_EQ(expected_byte1, last_write_value_[1]); | 134 EXPECT_EQ(expected_byte1, last_write_value_[1]); |
| 135 #else |
| 136 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 137 EXPECT_TRUE(last_notify_value); |
| 135 #endif // !defined(OS_MACOSX) | 138 #endif // !defined(OS_MACOSX) |
| 136 } | 139 } |
| 137 | 140 |
| 138 BluetoothDevice* device_ = nullptr; | 141 BluetoothDevice* device_ = nullptr; |
| 139 BluetoothRemoteGattService* service_ = nullptr; | 142 BluetoothRemoteGattService* service_ = nullptr; |
| 140 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr; | 143 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr; |
| 141 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr; | 144 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr; |
| 142 }; | 145 }; |
| 143 #endif | 146 #endif |
| 144 | 147 |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 | 1006 |
| 1004 // The expected error callback is asynchronous: | 1007 // The expected error callback is asynchronous: |
| 1005 EXPECT_EQ(0, error_callback_count_); | 1008 EXPECT_EQ(0, error_callback_count_); |
| 1006 base::RunLoop().RunUntilIdle(); | 1009 base::RunLoop().RunUntilIdle(); |
| 1007 EXPECT_EQ(1, error_callback_count_); | 1010 EXPECT_EQ(1, error_callback_count_); |
| 1008 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, | 1011 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, |
| 1009 last_gatt_error_code_); | 1012 last_gatt_error_code_); |
| 1010 } | 1013 } |
| 1011 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1014 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1012 | 1015 |
| 1013 #if defined(OS_ANDROID) || defined(OS_WIN) | 1016 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1014 // StartNotifySession fails if the characteristic is missing the Client | 1017 // StartNotifySession fails if the characteristic is missing the Client |
| 1015 // Characteristic Configuration descriptor. | 1018 // Characteristic Configuration descriptor. |
| 1016 // macOS: TODO(crbug.com/624017) Need to implement CCC descriptors. | |
| 1017 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1019 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1018 StartNotifySession_NoConfigDescriptor) { | 1020 StartNotifySession_NoConfigDescriptor) { |
| 1021 if (!PlatformSupportsLowEnergy()) { |
| 1022 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1023 return; |
| 1024 } |
| 1019 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1025 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1020 /* properties: NOTIFY */ 0x10, | 1026 /* properties: NOTIFY */ 0x10, |
| 1021 /* expected_config_descriptor_value: NOTIFY */ 1, | 1027 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 1022 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); | 1028 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); |
| 1023 | 1029 |
| 1024 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1030 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 1025 | 1031 |
| 1026 // The expected error callback is asynchronous: | 1032 // The expected error callback is asynchronous: |
| 1027 EXPECT_EQ(0, error_callback_count_); | 1033 EXPECT_EQ(0, error_callback_count_); |
| 1028 base::RunLoop().RunUntilIdle(); | 1034 base::RunLoop().RunUntilIdle(); |
| 1029 EXPECT_EQ(1, error_callback_count_); | 1035 EXPECT_EQ(1, error_callback_count_); |
| 1030 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, | 1036 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, |
| 1031 last_gatt_error_code_); | 1037 last_gatt_error_code_); |
| 1032 } | 1038 } |
| 1033 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1039 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1034 | 1040 |
| 1035 #if defined(OS_ANDROID) || defined(OS_WIN) | 1041 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1036 // StartNotifySession fails if the characteristic has multiple Client | 1042 // StartNotifySession fails if the characteristic has multiple Client |
| 1037 // Characteristic Configuration descriptors. | 1043 // Characteristic Configuration descriptors. |
| 1038 // macOS: TODO(crbug.com/624017) Need to implement CCC descriptors. | |
| 1039 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1044 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1040 StartNotifySession_MultipleConfigDescriptor) { | 1045 StartNotifySession_MultipleConfigDescriptor) { |
| 1046 if (!PlatformSupportsLowEnergy()) { |
| 1047 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1048 return; |
| 1049 } |
| 1041 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1050 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1042 /* properties: NOTIFY */ 0x10, | 1051 /* properties: NOTIFY */ 0x10, |
| 1043 /* expected_config_descriptor_value: NOTIFY */ 1, | 1052 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 1044 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); | 1053 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); |
| 1045 | 1054 |
| 1046 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1055 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 1047 | 1056 |
| 1048 // The expected error callback is asynchronous: | 1057 // The expected error callback is asynchronous: |
| 1049 EXPECT_EQ(0, error_callback_count_); | 1058 EXPECT_EQ(0, error_callback_count_); |
| 1050 base::RunLoop().RunUntilIdle(); | 1059 base::RunLoop().RunUntilIdle(); |
| 1051 EXPECT_EQ(1, error_callback_count_); | 1060 EXPECT_EQ(1, error_callback_count_); |
| 1052 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, | 1061 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
| 1053 last_gatt_error_code_); | 1062 last_gatt_error_code_); |
| 1054 } | 1063 } |
| 1055 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1064 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1056 | 1065 |
| 1057 #if defined(OS_ANDROID) | 1066 #if defined(OS_ANDROID) |
| 1058 // StartNotifySession fails synchronously when failing to set a characteristic | 1067 // StartNotifySession fails synchronously when failing to set a characteristic |
| 1059 // to enable notifications. | 1068 // to enable notifications. |
| 1060 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. | 1069 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. |
| 1061 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API. | 1070 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API. |
| 1062 // Windows: Synchronous Test Not Applicable: OS calls are all made | 1071 // Windows: Synchronous Test Not Applicable: OS calls are all made |
| 1063 // asynchronously from BluetoothTaskManagerWin. | 1072 // asynchronously from BluetoothTaskManagerWin. |
| 1064 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1073 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1065 StartNotifySession_FailToSetCharacteristicNotification) { | 1074 StartNotifySession_FailToSetCharacteristicNotification) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 if (!PlatformSupportsLowEnergy()) { | 1157 if (!PlatformSupportsLowEnergy()) { |
| 1149 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1158 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1150 return; | 1159 return; |
| 1151 } | 1160 } |
| 1152 ASSERT_NO_FATAL_FAILURE( | 1161 ASSERT_NO_FATAL_FAILURE( |
| 1153 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1162 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1154 SimulateGattDescriptor( | 1163 SimulateGattDescriptor( |
| 1155 characteristic1_, | 1164 characteristic1_, |
| 1156 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1165 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1157 .canonical_value()); | 1166 .canonical_value()); |
| 1158 #if !defined(OS_MACOSX) | |
| 1159 // TODO(crbug.com/624017): Need implementation for descriptors. | |
| 1160 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1167 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1161 #endif // !defined(OS_MACOSX) | |
| 1162 | 1168 |
| 1163 characteristic1_->StartNotifySession( | 1169 characteristic1_->StartNotifySession( |
| 1164 GetNotifyCallback(Call::EXPECTED), | 1170 GetNotifyCallback(Call::EXPECTED), |
| 1165 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1171 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1166 characteristic1_->StartNotifySession( | 1172 characteristic1_->StartNotifySession( |
| 1167 GetNotifyCallback(Call::EXPECTED), | 1173 GetNotifyCallback(Call::EXPECTED), |
| 1168 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1174 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1169 EXPECT_EQ(0, callback_count_); | 1175 EXPECT_EQ(0, callback_count_); |
| 1170 SimulateGattNotifySessionStarted(characteristic1_); | 1176 SimulateGattNotifySessionStarted(characteristic1_); |
| 1171 base::RunLoop().RunUntilIdle(); | 1177 base::RunLoop().RunUntilIdle(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1191 if (!PlatformSupportsLowEnergy()) { | 1197 if (!PlatformSupportsLowEnergy()) { |
| 1192 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1198 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1193 return; | 1199 return; |
| 1194 } | 1200 } |
| 1195 ASSERT_NO_FATAL_FAILURE( | 1201 ASSERT_NO_FATAL_FAILURE( |
| 1196 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1202 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1197 SimulateGattDescriptor( | 1203 SimulateGattDescriptor( |
| 1198 characteristic1_, | 1204 characteristic1_, |
| 1199 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1205 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1200 .canonical_value()); | 1206 .canonical_value()); |
| 1201 #if !defined(OS_MACOSX) | |
| 1202 // TODO(crbug.com/624017): Need implementation for descriptors. | |
| 1203 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1207 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1204 #endif // !defined(OS_MACOSX) | |
| 1205 | 1208 |
| 1206 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1209 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1207 GetGattErrorCallback(Call::EXPECTED)); | 1210 GetGattErrorCallback(Call::EXPECTED)); |
| 1208 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1211 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1209 GetGattErrorCallback(Call::EXPECTED)); | 1212 GetGattErrorCallback(Call::EXPECTED)); |
| 1210 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1213 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1211 EXPECT_EQ(0, callback_count_); | 1214 EXPECT_EQ(0, callback_count_); |
| 1212 SimulateGattNotifySessionStartError( | 1215 SimulateGattNotifySessionStartError( |
| 1213 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); | 1216 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); |
| 1214 base::RunLoop().RunUntilIdle(); | 1217 base::RunLoop().RunUntilIdle(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1244 | 1247 |
| 1245 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); | 1248 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); |
| 1246 EXPECT_EQ(0, callback_count_); | 1249 EXPECT_EQ(0, callback_count_); |
| 1247 EXPECT_EQ(1, error_callback_count_); | 1250 EXPECT_EQ(1, error_callback_count_); |
| 1248 ASSERT_EQ(0u, notify_sessions_.size()); | 1251 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1249 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, | 1252 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
| 1250 last_gatt_error_code_); | 1253 last_gatt_error_code_); |
| 1251 } | 1254 } |
| 1252 #endif // defined(OS_ANDROID) | 1255 #endif // defined(OS_ANDROID) |
| 1253 | 1256 |
| 1254 #if defined(OS_ANDROID) | 1257 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1255 // Tests StartNotifySession completing before chrome objects are deleted. | 1258 // Tests StartNotifySession completing before chrome objects are deleted. |
| 1256 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1259 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1257 StartNotifySession_BeforeDeleted) { | 1260 StartNotifySession_BeforeDeleted) { |
| 1261 if (!PlatformSupportsLowEnergy()) { |
| 1262 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1263 return; |
| 1264 } |
| 1258 ASSERT_NO_FATAL_FAILURE( | 1265 ASSERT_NO_FATAL_FAILURE( |
| 1259 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1266 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1260 SimulateGattDescriptor( | 1267 SimulateGattDescriptor( |
| 1261 characteristic1_, | 1268 characteristic1_, |
| 1262 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1269 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1263 .canonical_value()); | 1270 .canonical_value()); |
| 1264 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1271 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1265 | 1272 |
| 1266 characteristic1_->StartNotifySession( | 1273 characteristic1_->StartNotifySession( |
| 1267 GetNotifyCallback(Call::EXPECTED), | 1274 GetNotifyCallback(Call::EXPECTED), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1281 | 1288 |
| 1282 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1289 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1283 | 1290 |
| 1284 base::RunLoop().RunUntilIdle(); | 1291 base::RunLoop().RunUntilIdle(); |
| 1285 EXPECT_TRUE("Did not crash!"); | 1292 EXPECT_TRUE("Did not crash!"); |
| 1286 ASSERT_TRUE(notify_sessions_[0]); | 1293 ASSERT_TRUE(notify_sessions_[0]); |
| 1287 EXPECT_EQ(characteristic_identifier, | 1294 EXPECT_EQ(characteristic_identifier, |
| 1288 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1295 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1289 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1296 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1290 } | 1297 } |
| 1291 #endif // defined(OS_ANDROID) | 1298 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1292 | 1299 |
| 1293 #if defined(OS_MACOSX) || defined(OS_WIN) | 1300 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 1294 // Tests StartNotifySession reentrant in start notify session success callback | 1301 // Tests StartNotifySession reentrant in start notify session success callback |
| 1295 // and the reentrant start notify session success. | 1302 // and the reentrant start notify session success. |
| 1296 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1303 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1297 StartNotifySession_Reentrant_Success_Success) { | 1304 StartNotifySession_Reentrant_Success_Success) { |
| 1298 if (!PlatformSupportsLowEnergy()) { | 1305 if (!PlatformSupportsLowEnergy()) { |
| 1299 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1306 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1300 return; | 1307 return; |
| 1301 } | 1308 } |
| 1302 ASSERT_NO_FATAL_FAILURE( | 1309 ASSERT_NO_FATAL_FAILURE( |
| 1303 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1310 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1304 SimulateGattDescriptor( | 1311 SimulateGattDescriptor( |
| 1305 characteristic1_, | 1312 characteristic1_, |
| 1306 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value()); | 1313 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value()); |
| 1307 #if !defined(OS_MACOSX) | |
| 1308 // TODO(crbug.com/624017): Need implementation for descriptors. | |
| 1309 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1314 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1310 #endif // !defined(OS_MACOSX) | |
| 1311 | 1315 |
| 1312 characteristic1_->StartNotifySession( | 1316 characteristic1_->StartNotifySession( |
| 1313 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, | 1317 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, |
| 1314 characteristic1_), | 1318 characteristic1_), |
| 1315 GetReentrantStartNotifySessionErrorCallback( | 1319 GetReentrantStartNotifySessionErrorCallback( |
| 1316 Call::NOT_EXPECTED, characteristic1_, | 1320 Call::NOT_EXPECTED, characteristic1_, |
| 1317 false /* error_in_reentrant */)); | 1321 false /* error_in_reentrant */)); |
| 1318 EXPECT_EQ(0, callback_count_); | 1322 EXPECT_EQ(0, callback_count_); |
| 1319 SimulateGattNotifySessionStarted(characteristic1_); | 1323 SimulateGattNotifySessionStarted(characteristic1_); |
| 1320 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1324 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 // Simulate reentrant StartNotifySession request from | 1405 // Simulate reentrant StartNotifySession request from |
| 1402 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. | 1406 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. |
| 1403 SimulateGattNotifySessionStarted(characteristic1_); | 1407 SimulateGattNotifySessionStarted(characteristic1_); |
| 1404 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1408 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 1405 EXPECT_EQ(0, callback_count_); | 1409 EXPECT_EQ(0, callback_count_); |
| 1406 EXPECT_EQ(2, error_callback_count_); | 1410 EXPECT_EQ(2, error_callback_count_); |
| 1407 ASSERT_EQ(0u, notify_sessions_.size()); | 1411 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1408 } | 1412 } |
| 1409 #endif // defined(OS_WIN) | 1413 #endif // defined(OS_WIN) |
| 1410 | 1414 |
| 1411 #if defined(OS_ANDROID) | 1415 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1412 // Tests StopNotifySession success on a characteristic that enabled Notify. | 1416 // Tests StopNotifySession success on a characteristic that enabled Notify. |
| 1413 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { | 1417 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { |
| 1418 if (!PlatformSupportsLowEnergy()) { |
| 1419 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1420 return; |
| 1421 } |
| 1414 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1422 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1415 /* properties: NOTIFY */ 0x10, | 1423 /* properties: NOTIFY */ 0x10, |
| 1416 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1424 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1425 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1426 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1427 // the CCC descriptor. |
| 1428 #if !defined(OS_MACOSX) |
| 1417 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | 1429 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| 1430 #else |
| 1431 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1432 EXPECT_TRUE(last_notify_value); |
| 1433 #endif // !defined(OS_MACOSX) |
| 1418 | 1434 |
| 1419 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1435 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1420 SimulateGattNotifySessionStopped(characteristic1_); | 1436 SimulateGattNotifySessionStopped(characteristic1_); |
| 1421 base::RunLoop().RunUntilIdle(); | 1437 base::RunLoop().RunUntilIdle(); |
| 1422 | 1438 |
| 1439 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1440 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1441 // the CCC descriptor. |
| 1442 #if !defined(OS_MACOSX) |
| 1423 // Check that the right values were written to the descriptor. | 1443 // Check that the right values were written to the descriptor. |
| 1424 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | 1444 EXPECT_EQ(2, gatt_write_descriptor_attempts_); |
| 1425 ASSERT_EQ(2u, last_write_value_.size()); | 1445 ASSERT_EQ(2u, last_write_value_.size()); |
| 1426 EXPECT_EQ(0, last_write_value_[0]); | 1446 EXPECT_EQ(0, last_write_value_[0]); |
| 1427 EXPECT_EQ(0, last_write_value_[1]); | 1447 EXPECT_EQ(0, last_write_value_[1]); |
| 1448 #else |
| 1449 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); |
| 1450 EXPECT_FALSE(last_notify_value); |
| 1451 #endif // !defined(OS_MACOSX) |
| 1428 | 1452 |
| 1429 // Check that the notify session is inactive. | 1453 // Check that the notify session is inactive. |
| 1430 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1454 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1431 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1455 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1432 } | 1456 } |
| 1433 #endif // defined(OS_ANDROID) | 1457 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1434 | 1458 |
| 1435 #if defined(OS_ANDROID) | 1459 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1436 // Tests that deleted sessions are stopped. | 1460 // Tests that deleted sessions are stopped. |
| 1437 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1461 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1438 StopNotifySession_SessionDeleted) { | 1462 StopNotifySession_SessionDeleted) { |
| 1463 if (!PlatformSupportsLowEnergy()) { |
| 1464 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1465 return; |
| 1466 } |
| 1439 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1467 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1440 /* properties: NOTIFY */ 0x10, | 1468 /* properties: NOTIFY */ 0x10, |
| 1441 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1469 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1470 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1471 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1472 // the CCC descriptor. |
| 1473 #if !defined(OS_MACOSX) |
| 1442 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | 1474 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| 1475 #else |
| 1476 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1477 EXPECT_TRUE(last_notify_value); |
| 1478 #endif // !defined(OS_MACOSX) |
| 1443 | 1479 |
| 1444 notify_sessions_.clear(); | 1480 notify_sessions_.clear(); |
| 1445 SimulateGattNotifySessionStopped(characteristic1_); | 1481 SimulateGattNotifySessionStopped(characteristic1_); |
| 1446 base::RunLoop().RunUntilIdle(); | 1482 base::RunLoop().RunUntilIdle(); |
| 1447 | 1483 |
| 1484 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1485 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1486 // the CCC descriptor. |
| 1487 #if !defined(OS_MACOSX) |
| 1448 // Check that the right values were written to the descriptor. | 1488 // Check that the right values were written to the descriptor. |
| 1449 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | 1489 EXPECT_EQ(2, gatt_write_descriptor_attempts_); |
| 1450 ASSERT_EQ(2u, last_write_value_.size()); | 1490 ASSERT_EQ(2u, last_write_value_.size()); |
| 1451 EXPECT_EQ(0, last_write_value_[0]); | 1491 EXPECT_EQ(0, last_write_value_[0]); |
| 1452 EXPECT_EQ(0, last_write_value_[1]); | 1492 EXPECT_EQ(0, last_write_value_[1]); |
| 1493 #else |
| 1494 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); |
| 1495 EXPECT_FALSE(last_notify_value); |
| 1496 #endif // !defined(OS_MACOSX) |
| 1453 | 1497 |
| 1454 // Check that the notify session is inactive. | 1498 // Check that the notify session is inactive. |
| 1455 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1499 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1456 } | 1500 } |
| 1457 #endif // defined(OS_ANDROID) | 1501 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1458 | 1502 |
| 1459 #if defined(OS_ANDROID) | 1503 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1460 // Tests that deleting the sessions before the stop callbacks have been | 1504 // Tests that deleting the sessions before the stop callbacks have been |
| 1461 // invoked does not cause problems. | 1505 // invoked does not cause problems. |
| 1462 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1506 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1463 StopNotifySession_SessionDeleted2) { | 1507 StopNotifySession_SessionDeleted2) { |
| 1508 if (!PlatformSupportsLowEnergy()) { |
| 1509 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1510 return; |
| 1511 } |
| 1464 ASSERT_NO_FATAL_FAILURE( | 1512 ASSERT_NO_FATAL_FAILURE( |
| 1465 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1513 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1466 | 1514 |
| 1467 #if !defined(OS_MACOSX) | |
| 1468 // TODO(624017) enable for macosx | |
| 1469 SimulateGattDescriptor( | 1515 SimulateGattDescriptor( |
| 1470 characteristic1_, | 1516 characteristic1_, |
| 1471 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1517 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1472 .canonical_value()); | 1518 .canonical_value()); |
| 1473 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1519 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1474 #endif | |
| 1475 | 1520 |
| 1476 // Start notify sessions. | 1521 // Start notify sessions. |
| 1477 characteristic1_->StartNotifySession( | 1522 characteristic1_->StartNotifySession( |
| 1478 GetNotifyCheckForPrecedingCalls(0), | 1523 GetNotifyCheckForPrecedingCalls(0), |
| 1479 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1524 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1480 characteristic1_->StartNotifySession( | 1525 characteristic1_->StartNotifySession( |
| 1481 GetNotifyCheckForPrecedingCalls(1), | 1526 GetNotifyCheckForPrecedingCalls(1), |
| 1482 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1527 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1483 EXPECT_EQ(0, callback_count_); | 1528 EXPECT_EQ(0, callback_count_); |
| 1484 SimulateGattNotifySessionStarted(characteristic1_); | 1529 SimulateGattNotifySessionStarted(characteristic1_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1504 | 1549 |
| 1505 // Run the stop events. | 1550 // Run the stop events. |
| 1506 base::RunLoop().RunUntilIdle(); | 1551 base::RunLoop().RunUntilIdle(); |
| 1507 SimulateGattNotifySessionStopped(characteristic1_); | 1552 SimulateGattNotifySessionStopped(characteristic1_); |
| 1508 base::RunLoop().RunUntilIdle(); | 1553 base::RunLoop().RunUntilIdle(); |
| 1509 | 1554 |
| 1510 // Check that the state is correct. | 1555 // Check that the state is correct. |
| 1511 EXPECT_TRUE("Did not crash!"); | 1556 EXPECT_TRUE("Did not crash!"); |
| 1512 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1557 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1513 } | 1558 } |
| 1514 #endif // defined(OS_ANDROID) | 1559 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1515 | 1560 |
| 1516 #if defined(OS_ANDROID) | 1561 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1517 // Tests that cancelling StopNotifySession works. | 1562 // Tests that cancelling StopNotifySession works. |
| 1518 // TODO(crbug.com/633191): Enable on macOS when SubscribeToNotifications is | |
| 1519 // implemented. | |
| 1520 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is | 1563 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is |
| 1521 // implemented. | 1564 // implemented. |
| 1522 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { | 1565 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { |
| 1566 if (!PlatformSupportsLowEnergy()) { |
| 1567 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1568 return; |
| 1569 } |
| 1523 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1570 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1524 /* properties: NOTIFY */ 0x10, | 1571 /* properties: NOTIFY */ 0x10, |
| 1525 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1572 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1526 | 1573 |
| 1527 // Check that the session is correctly setup. | 1574 // Check that the session is correctly setup. |
| 1528 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1575 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1529 EXPECT_EQ(characteristic_identifier, | 1576 EXPECT_EQ(characteristic_identifier, |
| 1530 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1577 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1531 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1578 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1532 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1579 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1533 | 1580 |
| 1534 // Queue a Stop request. | 1581 // Queue a Stop request. |
| 1535 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1582 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1536 | 1583 |
| 1537 // Cancel Stop by deleting the device before Stop finishes. | 1584 // Cancel Stop by deleting the device before Stop finishes. |
| 1538 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1585 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1539 } | 1586 } |
| 1540 #endif // defined(OS_ANDROID) | 1587 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1541 | 1588 |
| 1542 #if defined(OS_ANDROID) | 1589 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1543 // Tests that deleted sessions are stopped. | 1590 // Tests that deleted sessions are stopped. |
| 1544 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { | 1591 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { |
| 1592 if (!PlatformSupportsLowEnergy()) { |
| 1593 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1594 return; |
| 1595 } |
| 1545 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1596 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1546 /* properties: NOTIFY */ 0x10, | 1597 /* properties: NOTIFY */ 0x10, |
| 1547 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1598 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1548 | 1599 |
| 1549 // Check that the session is correctly setup | 1600 // Check that the session is correctly setup |
| 1550 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1601 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1551 EXPECT_EQ(characteristic_identifier, | 1602 EXPECT_EQ(characteristic_identifier, |
| 1552 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1603 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1553 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1604 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1554 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1605 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1555 | 1606 |
| 1556 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1607 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1557 | 1608 |
| 1558 ResetEventCounts(); | 1609 ResetEventCounts(); |
| 1559 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1610 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1560 | 1611 |
| 1561 // Check that the callback does not arrive synchronously. | 1612 // Check that the callback does not arrive synchronously. |
| 1562 EXPECT_EQ(0, callback_count_); | 1613 EXPECT_EQ(0, callback_count_); |
| 1563 | 1614 |
| 1564 // Trigger the stop callback | 1615 // Trigger the stop callback |
| 1565 base::RunLoop().RunUntilIdle(); | 1616 base::RunLoop().RunUntilIdle(); |
| 1566 EXPECT_EQ(1, callback_count_); | 1617 EXPECT_EQ(1, callback_count_); |
| 1567 | 1618 |
| 1568 EXPECT_TRUE("Did not crash!"); | 1619 EXPECT_TRUE("Did not crash!"); |
| 1569 ASSERT_TRUE(notify_sessions_[0]); | 1620 ASSERT_TRUE(notify_sessions_[0]); |
| 1570 EXPECT_EQ(characteristic_identifier, | 1621 EXPECT_EQ(characteristic_identifier, |
| 1571 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1622 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1572 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1623 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1573 } | 1624 } |
| 1574 #endif // defined(OS_ANDROID) | 1625 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1575 | 1626 |
| 1576 #if defined(OS_ANDROID) | 1627 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1577 // Tests StopNotifySession success on a characteristic that enabled Indicate. | 1628 // Tests StopNotifySession success on a characteristic that enabled Indicate. |
| 1578 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { | 1629 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { |
| 1630 if (!PlatformSupportsLowEnergy()) { |
| 1631 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1632 return; |
| 1633 } |
| 1579 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1634 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1580 /* properties: INDICATE */ 0x20, | 1635 /* properties: INDICATE */ 0x20, |
| 1581 /* expected_config_descriptor_value: INDICATE */ 2)); | 1636 /* expected_config_descriptor_value: INDICATE */ 2)); |
| 1637 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1638 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1639 // the CCC descriptor. |
| 1640 #if !defined(OS_MACOSX) |
| 1582 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | 1641 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| 1642 #else |
| 1643 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1644 EXPECT_TRUE(last_notify_value); |
| 1645 #endif // !defined(OS_MACOSX) |
| 1583 | 1646 |
| 1584 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1647 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1585 SimulateGattNotifySessionStopped(characteristic1_); | 1648 SimulateGattNotifySessionStopped(characteristic1_); |
| 1586 base::RunLoop().RunUntilIdle(); | 1649 base::RunLoop().RunUntilIdle(); |
| 1587 | 1650 |
| 1651 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1652 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1653 // the CCC descriptor. |
| 1654 #if !defined(OS_MACOSX) |
| 1588 // Check that the right values were written to the descriptor. | 1655 // Check that the right values were written to the descriptor. |
| 1589 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | 1656 EXPECT_EQ(2, gatt_write_descriptor_attempts_); |
| 1590 ASSERT_EQ(2u, last_write_value_.size()); | 1657 ASSERT_EQ(2u, last_write_value_.size()); |
| 1591 EXPECT_EQ(0, last_write_value_[0]); | 1658 EXPECT_EQ(0, last_write_value_[0]); |
| 1592 EXPECT_EQ(0, last_write_value_[1]); | 1659 EXPECT_EQ(0, last_write_value_[1]); |
| 1660 #else |
| 1661 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); |
| 1662 EXPECT_FALSE(last_notify_value); |
| 1663 #endif // !defined(OS_MACOSX) |
| 1593 | 1664 |
| 1594 // Check that the notify session is inactive. | 1665 // Check that the notify session is inactive. |
| 1595 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1666 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1596 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1667 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1597 } | 1668 } |
| 1598 #endif // defined(OS_ANDROID) | 1669 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1599 | 1670 |
| 1600 #if defined(OS_ANDROID) | 1671 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1601 // Tests StopNotifySession success on a characteristic that enabled Notify & | 1672 // Tests StopNotifySession success on a characteristic that enabled Notify & |
| 1602 // Indicate. | 1673 // Indicate. |
| 1603 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1674 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1604 StopNotifySession_OnNotifyAndIndicate) { | 1675 StopNotifySession_OnNotifyAndIndicate) { |
| 1676 if (!PlatformSupportsLowEnergy()) { |
| 1677 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1678 return; |
| 1679 } |
| 1605 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1680 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1606 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 1681 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 1607 /* expected_config_descriptor_value: INDICATE */ 1)); | 1682 /* expected_config_descriptor_value: INDICATE */ 1)); |
| 1683 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1684 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1685 // the CCC descriptor. |
| 1686 #if !defined(OS_MACOSX) |
| 1608 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | 1687 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| 1688 #else |
| 1689 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1690 EXPECT_TRUE(last_notify_value); |
| 1691 #endif // !defined(OS_MACOSX) |
| 1609 | 1692 |
| 1610 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1693 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1611 SimulateGattNotifySessionStopped(characteristic1_); | 1694 SimulateGattNotifySessionStopped(characteristic1_); |
| 1612 base::RunLoop().RunUntilIdle(); | 1695 base::RunLoop().RunUntilIdle(); |
| 1613 | 1696 |
| 1697 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1698 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1699 // the CCC descriptor. |
| 1700 #if !defined(OS_MACOSX) |
| 1614 // Check that the right values were written to the descriptor. | 1701 // Check that the right values were written to the descriptor. |
| 1615 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | 1702 EXPECT_EQ(2, gatt_write_descriptor_attempts_); |
| 1616 ASSERT_EQ(2u, last_write_value_.size()); | 1703 ASSERT_EQ(2u, last_write_value_.size()); |
| 1617 EXPECT_EQ(0, last_write_value_[0]); | 1704 EXPECT_EQ(0, last_write_value_[0]); |
| 1618 EXPECT_EQ(0, last_write_value_[1]); | 1705 EXPECT_EQ(0, last_write_value_[1]); |
| 1706 #else |
| 1707 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); |
| 1708 EXPECT_FALSE(last_notify_value); |
| 1709 #endif // !defined(OS_MACOSX) |
| 1619 | 1710 |
| 1620 // Check that the notify session is inactive. | 1711 // Check that the notify session is inactive. |
| 1621 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1712 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1622 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1713 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1623 } | 1714 } |
| 1624 #endif // defined(OS_ANDROID) | 1715 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1625 | 1716 |
| 1626 #if defined(OS_ANDROID) | 1717 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1627 // Tests StopNotifySession error | 1718 // Tests StopNotifySession error |
| 1628 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { | 1719 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { |
| 1720 if (!PlatformSupportsLowEnergy()) { |
| 1721 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1722 return; |
| 1723 } |
| 1629 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1724 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1630 /* properties: NOTIFY */ 0x10, | 1725 /* properties: NOTIFY */ 0x10, |
| 1631 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1726 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1632 | 1727 |
| 1633 // Check that the notify session is active. | 1728 // Check that the notify session is active. |
| 1634 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1729 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1635 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1730 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1636 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1731 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1637 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1732 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1638 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1733 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1639 | 1734 |
| 1640 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1735 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1641 SimulateGattNotifySessionStopError( | 1736 SimulateGattNotifySessionStopError( |
| 1642 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); | 1737 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); |
| 1643 base::RunLoop().RunUntilIdle(); | 1738 base::RunLoop().RunUntilIdle(); |
| 1644 | 1739 |
| 1645 // Check that the notify session is inactive. | 1740 // Check that the notify session is inactive. |
| 1646 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1741 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1647 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1742 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1648 } | 1743 } |
| 1649 #endif // defined(OS_ANDROID) | 1744 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1650 | 1745 |
| 1651 #if defined(OS_ANDROID) | 1746 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1652 // Tests multiple StopNotifySession calls for a single session. | 1747 // Tests multiple StopNotifySession calls for a single session. |
| 1653 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) { | 1748 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) { |
| 1749 if (!PlatformSupportsLowEnergy()) { |
| 1750 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1751 return; |
| 1752 } |
| 1654 ASSERT_NO_FATAL_FAILURE( | 1753 ASSERT_NO_FATAL_FAILURE( |
| 1655 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1754 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1656 | 1755 |
| 1657 #if !defined(OS_MACOSX) | |
| 1658 // TODO(624017) enable for macosx | |
| 1659 SimulateGattDescriptor( | 1756 SimulateGattDescriptor( |
| 1660 characteristic1_, | 1757 characteristic1_, |
| 1661 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1758 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1662 .canonical_value()); | 1759 .canonical_value()); |
| 1663 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1760 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1664 #endif | |
| 1665 | 1761 |
| 1666 // Start notify session | 1762 // Start notify session |
| 1667 characteristic1_->StartNotifySession( | 1763 characteristic1_->StartNotifySession( |
| 1668 GetNotifyCallback(Call::EXPECTED), | 1764 GetNotifyCallback(Call::EXPECTED), |
| 1669 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1765 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1670 EXPECT_EQ(0, callback_count_); | 1766 EXPECT_EQ(0, callback_count_); |
| 1671 SimulateGattNotifySessionStarted(characteristic1_); | 1767 SimulateGattNotifySessionStarted(characteristic1_); |
| 1672 base::RunLoop().RunUntilIdle(); | 1768 base::RunLoop().RunUntilIdle(); |
| 1673 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1769 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1674 EXPECT_EQ(1, callback_count_); | 1770 EXPECT_EQ(1, callback_count_); |
| 1675 EXPECT_EQ(0, error_callback_count_); | 1771 EXPECT_EQ(0, error_callback_count_); |
| 1676 ASSERT_EQ(1u, notify_sessions_.size()); | 1772 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1677 ASSERT_TRUE(notify_sessions_[0]); | 1773 ASSERT_TRUE(notify_sessions_[0]); |
| 1678 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1774 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1679 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1775 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1680 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1776 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1681 | 1777 |
| 1682 // Stop the notify session twice | 1778 // Stop the notify session twice |
| 1683 ResetEventCounts(); | 1779 ResetEventCounts(); |
| 1684 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(0)); | 1780 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(0)); |
| 1685 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); | 1781 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); |
| 1686 SimulateGattNotifySessionStopped(characteristic1_); | 1782 SimulateGattNotifySessionStopped(characteristic1_); |
| 1687 base::RunLoop().RunUntilIdle(); | 1783 base::RunLoop().RunUntilIdle(); |
| 1688 | 1784 |
| 1689 // Check that the notify session is inactive. | 1785 // Check that the notify session is inactive. |
| 1690 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1786 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1691 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1787 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1692 } | 1788 } |
| 1693 #endif // defined(OS_ANDROID) | 1789 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1694 | 1790 |
| 1695 #if defined(OS_ANDROID) | 1791 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1696 // Tests multiple StartNotifySession calls and multiple StopNotifySession calls. | 1792 // Tests multiple StartNotifySession calls and multiple StopNotifySession calls. |
| 1697 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) { | 1793 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) { |
| 1794 if (!PlatformSupportsLowEnergy()) { |
| 1795 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1796 return; |
| 1797 } |
| 1698 ASSERT_NO_FATAL_FAILURE( | 1798 ASSERT_NO_FATAL_FAILURE( |
| 1699 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1799 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1700 | 1800 |
| 1701 #if !defined(OS_MACOSX) | |
| 1702 // TODO(624017) enable for macosx | |
| 1703 SimulateGattDescriptor( | 1801 SimulateGattDescriptor( |
| 1704 characteristic1_, | 1802 characteristic1_, |
| 1705 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1803 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1706 .canonical_value()); | 1804 .canonical_value()); |
| 1707 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1805 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1708 #endif | |
| 1709 | 1806 |
| 1710 // Start notify sessions | 1807 // Start notify sessions |
| 1711 characteristic1_->StartNotifySession( | 1808 characteristic1_->StartNotifySession( |
| 1712 GetNotifyCheckForPrecedingCalls(0), | 1809 GetNotifyCheckForPrecedingCalls(0), |
| 1713 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1810 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1714 characteristic1_->StartNotifySession( | 1811 characteristic1_->StartNotifySession( |
| 1715 GetNotifyCheckForPrecedingCalls(1), | 1812 GetNotifyCheckForPrecedingCalls(1), |
| 1716 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1813 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1717 EXPECT_EQ(0, callback_count_); | 1814 EXPECT_EQ(0, callback_count_); |
| 1718 SimulateGattNotifySessionStarted(characteristic1_); | 1815 SimulateGattNotifySessionStarted(characteristic1_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1738 | 1835 |
| 1739 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(3)); | 1836 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(3)); |
| 1740 SimulateGattNotifySessionStopped(characteristic1_); | 1837 SimulateGattNotifySessionStopped(characteristic1_); |
| 1741 base::RunLoop().RunUntilIdle(); | 1838 base::RunLoop().RunUntilIdle(); |
| 1742 | 1839 |
| 1743 // Check that the notify sessions is inactive. | 1840 // Check that the notify sessions is inactive. |
| 1744 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1841 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1745 EXPECT_FALSE(notify_sessions_[1]->IsActive()); | 1842 EXPECT_FALSE(notify_sessions_[1]->IsActive()); |
| 1746 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1843 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1747 } | 1844 } |
| 1748 #endif // defined(OS_ANDROID) | 1845 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1749 | 1846 |
| 1750 #if defined(OS_ANDROID) | 1847 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1751 // Tests starting a new notify session before the previous stop request | 1848 // Tests starting a new notify session before the previous stop request |
| 1752 // resolves. | 1849 // resolves. |
| 1753 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) { | 1850 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) { |
| 1851 if (!PlatformSupportsLowEnergy()) { |
| 1852 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1853 return; |
| 1854 } |
| 1754 ASSERT_NO_FATAL_FAILURE( | 1855 ASSERT_NO_FATAL_FAILURE( |
| 1755 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1856 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1756 SimulateGattDescriptor( | 1857 SimulateGattDescriptor( |
| 1757 characteristic1_, | 1858 characteristic1_, |
| 1758 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1859 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1759 .canonical_value()); | 1860 .canonical_value()); |
| 1760 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1861 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1761 | 1862 |
| 1762 // Start notify session | 1863 // Start notify session |
| 1763 ResetEventCounts(); | 1864 ResetEventCounts(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1784 | 1885 |
| 1785 SimulateGattNotifySessionStarted(characteristic1_); | 1886 SimulateGattNotifySessionStarted(characteristic1_); |
| 1786 base::RunLoop().RunUntilIdle(); | 1887 base::RunLoop().RunUntilIdle(); |
| 1787 ASSERT_EQ(2u, notify_sessions_.size()); | 1888 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1788 ASSERT_TRUE(notify_sessions_[0]); | 1889 ASSERT_TRUE(notify_sessions_[0]); |
| 1789 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1890 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1790 ASSERT_TRUE(notify_sessions_[1]); | 1891 ASSERT_TRUE(notify_sessions_[1]); |
| 1791 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1892 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1792 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1893 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1793 } | 1894 } |
| 1794 #endif // defined(OS_ANDROID) | 1895 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1795 | 1896 |
| 1796 #if defined(OS_ANDROID) | 1897 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1797 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1898 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1798 StopNotifySession_StartStopStart) { | 1899 StopNotifySession_StartStopStart) { |
| 1900 if (!PlatformSupportsLowEnergy()) { |
| 1901 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1902 return; |
| 1903 } |
| 1799 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1904 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1800 /* properties: NOTIFY */ 0x10, | 1905 /* properties: NOTIFY */ 0x10, |
| 1801 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1906 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1802 | 1907 |
| 1803 // Check that the initial notify session is active. | 1908 // Check that the initial notify session is active. |
| 1804 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1909 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1805 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1910 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1806 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1911 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1807 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1912 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1808 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1913 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1836 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); | 1941 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); |
| 1837 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1942 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1838 | 1943 |
| 1839 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1944 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1840 notify_sessions_[2]->GetCharacteristicIdentifier()); | 1945 notify_sessions_[2]->GetCharacteristicIdentifier()); |
| 1841 EXPECT_EQ(characteristic1_, notify_sessions_[2]->GetCharacteristic()); | 1946 EXPECT_EQ(characteristic1_, notify_sessions_[2]->GetCharacteristic()); |
| 1842 EXPECT_TRUE(notify_sessions_[2]->IsActive()); | 1947 EXPECT_TRUE(notify_sessions_[2]->IsActive()); |
| 1843 | 1948 |
| 1844 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1949 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1845 } | 1950 } |
| 1846 #endif | 1951 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1847 | 1952 |
| 1848 #if defined(OS_ANDROID) | 1953 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1849 // Tests starting a new notify session before the previous stop requests | 1954 // Tests starting a new notify session before the previous stop requests |
| 1850 // resolve. | 1955 // resolve. |
| 1851 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) { | 1956 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) { |
| 1957 if (!PlatformSupportsLowEnergy()) { |
| 1958 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1959 return; |
| 1960 } |
| 1852 ASSERT_NO_FATAL_FAILURE( | 1961 ASSERT_NO_FATAL_FAILURE( |
| 1853 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1962 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1854 SimulateGattDescriptor( | 1963 SimulateGattDescriptor( |
| 1855 characteristic1_, | 1964 characteristic1_, |
| 1856 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1965 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1857 .canonical_value()); | 1966 .canonical_value()); |
| 1858 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1967 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1859 | 1968 |
| 1860 // Start notify session | 1969 // Start notify session |
| 1861 ResetEventCounts(); | 1970 ResetEventCounts(); |
| 1862 characteristic1_->StartNotifySession( | 1971 characteristic1_->StartNotifySession( |
| 1863 GetNotifyCheckForPrecedingCalls(0), | 1972 GetNotifyCheckForPrecedingCalls(0), |
| 1864 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1973 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1865 SimulateGattNotifySessionStarted(characteristic1_); | 1974 SimulateGattNotifySessionStarted(characteristic1_); |
| 1866 base::RunLoop().RunUntilIdle(); | 1975 base::RunLoop().RunUntilIdle(); |
| 1867 ASSERT_EQ(1u, notify_sessions_.size()); | 1976 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1868 ASSERT_TRUE(notify_sessions_[0]); | 1977 ASSERT_TRUE(notify_sessions_[0]); |
| 1869 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1978 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1979 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1980 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1981 // the CCC descriptor. |
| 1982 #if !defined(OS_MACOSX) |
| 1870 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | 1983 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| 1984 #else |
| 1985 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1986 EXPECT_TRUE(last_notify_value); |
| 1987 #endif // !defined(OS_MACOSX) |
| 1871 | 1988 |
| 1872 // Stop the notify session twice | 1989 // Stop the notify session twice |
| 1873 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); | 1990 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); |
| 1874 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(2)); | 1991 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(2)); |
| 1875 | 1992 |
| 1993 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 1994 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 1995 // the CCC descriptor. |
| 1996 #if !defined(OS_MACOSX) |
| 1876 // Check that the right values were written to the descriptor. | 1997 // Check that the right values were written to the descriptor. |
| 1877 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | 1998 EXPECT_EQ(2, gatt_write_descriptor_attempts_); |
| 1878 ASSERT_EQ(2u, last_write_value_.size()); | 1999 ASSERT_EQ(2u, last_write_value_.size()); |
| 1879 EXPECT_EQ(0, last_write_value_[0]); | 2000 EXPECT_EQ(0, last_write_value_[0]); |
| 1880 EXPECT_EQ(0, last_write_value_[1]); | 2001 EXPECT_EQ(0, last_write_value_[1]); |
| 2002 #else |
| 2003 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); |
| 2004 EXPECT_FALSE(last_notify_value); |
| 2005 #endif // !defined(OS_MACOSX) |
| 1881 | 2006 |
| 1882 // Start another notify session | 2007 // Start another notify session |
| 1883 characteristic1_->StartNotifySession( | 2008 characteristic1_->StartNotifySession( |
| 1884 GetNotifyCheckForPrecedingCalls(3), | 2009 GetNotifyCheckForPrecedingCalls(3), |
| 1885 GetGattErrorCallback(Call::NOT_EXPECTED)); | 2010 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1886 | 2011 |
| 2012 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 2013 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 2014 // the CCC descriptor. |
| 2015 #if !defined(OS_MACOSX) |
| 1887 // Check that nothing was written by the StartNotifySession call above | 2016 // Check that nothing was written by the StartNotifySession call above |
| 1888 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | 2017 EXPECT_EQ(2, gatt_write_descriptor_attempts_); |
| 2018 #else |
| 2019 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); |
| 2020 #endif // !defined(OS_MACOSX) |
| 1889 | 2021 |
| 1890 SimulateGattNotifySessionStopped(characteristic1_); | 2022 SimulateGattNotifySessionStopped(characteristic1_); |
| 1891 base::RunLoop().RunUntilIdle(); | 2023 base::RunLoop().RunUntilIdle(); |
| 1892 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 2024 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1893 | 2025 |
| 1894 SimulateGattNotifySessionStarted(characteristic1_); | 2026 SimulateGattNotifySessionStarted(characteristic1_); |
| 1895 base::RunLoop().RunUntilIdle(); | 2027 base::RunLoop().RunUntilIdle(); |
| 1896 | 2028 |
| 2029 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral |
| 2030 // setNotifyValue:forCharacteristic:] which handles all interactions with |
| 2031 // the CCC descriptor. |
| 2032 #if !defined(OS_MACOSX) |
| 1897 // Check that the right values were written to the descriptor. | 2033 // Check that the right values were written to the descriptor. |
| 1898 EXPECT_EQ(3, gatt_write_descriptor_attempts_); | 2034 EXPECT_EQ(3, gatt_write_descriptor_attempts_); |
| 1899 ASSERT_EQ(2u, last_write_value_.size()); | 2035 ASSERT_EQ(2u, last_write_value_.size()); |
| 1900 EXPECT_EQ(1, last_write_value_[0]); | 2036 EXPECT_EQ(1, last_write_value_[0]); |
| 1901 EXPECT_EQ(0, last_write_value_[1]); | 2037 EXPECT_EQ(0, last_write_value_[1]); |
| 2038 #else |
| 2039 EXPECT_EQ(3, gatt_notify_characteristic_attempts_); |
| 2040 EXPECT_TRUE(last_notify_value); |
| 2041 #endif // !defined(OS_MACOSX) |
| 1902 | 2042 |
| 1903 // Check the notify state | 2043 // Check the notify state |
| 1904 ASSERT_EQ(2u, notify_sessions_.size()); | 2044 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1905 ASSERT_TRUE(notify_sessions_[0]); | 2045 ASSERT_TRUE(notify_sessions_[0]); |
| 1906 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 2046 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1907 ASSERT_TRUE(notify_sessions_[1]); | 2047 ASSERT_TRUE(notify_sessions_[1]); |
| 1908 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 2048 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1909 EXPECT_TRUE(characteristic1_->IsNotifying()); | 2049 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1910 } | 2050 } |
| 1911 #endif // defined(OS_ANDROID) | 2051 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1912 | 2052 |
| 1913 #if defined(OS_ANDROID) | 2053 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1914 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2054 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1915 StopNotifySession_Reentrant_Success_Stop) { | 2055 StopNotifySession_Reentrant_Success_Stop) { |
| 2056 if (!PlatformSupportsLowEnergy()) { |
| 2057 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2058 return; |
| 2059 } |
| 1916 ASSERT_NO_FATAL_FAILURE( | 2060 ASSERT_NO_FATAL_FAILURE( |
| 1917 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 2061 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1918 SimulateGattDescriptor( | 2062 SimulateGattDescriptor( |
| 1919 characteristic1_, | 2063 characteristic1_, |
| 1920 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 2064 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1921 .canonical_value()); | 2065 .canonical_value()); |
| 1922 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 2066 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1923 | 2067 |
| 1924 // Start notify session | 2068 // Start notify session |
| 1925 characteristic1_->StartNotifySession( | 2069 characteristic1_->StartNotifySession( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1941 ASSERT_EQ(1u, notify_sessions_.size()); | 2085 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1942 ASSERT_TRUE(notify_sessions_[0]); | 2086 ASSERT_TRUE(notify_sessions_[0]); |
| 1943 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 2087 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1944 EXPECT_TRUE(characteristic1_->IsNotifying()); | 2088 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1945 | 2089 |
| 1946 SimulateGattNotifySessionStopped(characteristic1_); | 2090 SimulateGattNotifySessionStopped(characteristic1_); |
| 1947 base::RunLoop().RunUntilIdle(); | 2091 base::RunLoop().RunUntilIdle(); |
| 1948 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 2092 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1949 EXPECT_FALSE(characteristic1_->IsNotifying()); | 2093 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1950 } | 2094 } |
| 1951 #endif | 2095 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1952 | 2096 |
| 1953 #if defined(OS_ANDROID) | 2097 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1954 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2098 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1955 StopNotifySession_Reentrant_Stop_StartSuccess) { | 2099 StopNotifySession_Reentrant_Stop_StartSuccess) { |
| 2100 if (!PlatformSupportsLowEnergy()) { |
| 2101 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2102 return; |
| 2103 } |
| 1956 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2104 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1957 /* properties: NOTIFY */ 0x10, | 2105 /* properties: NOTIFY */ 0x10, |
| 1958 /* expected_config_descriptor_value: NOTIFY */ 1)); | 2106 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1959 | 2107 |
| 1960 // Check that the notify session is active. | 2108 // Check that the notify session is active. |
| 1961 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 2109 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1962 EXPECT_EQ(characteristic1_->GetIdentifier(), | 2110 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1963 notify_sessions_[0]->GetCharacteristicIdentifier()); | 2111 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1964 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 2112 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1965 EXPECT_TRUE(characteristic1_->IsNotifying()); | 2113 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1983 base::RunLoop().RunUntilIdle(); | 2131 base::RunLoop().RunUntilIdle(); |
| 1984 ASSERT_EQ(2u, notify_sessions_.size()); | 2132 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1985 ASSERT_TRUE(notify_sessions_[0]); | 2133 ASSERT_TRUE(notify_sessions_[0]); |
| 1986 ASSERT_TRUE(notify_sessions_[1]); | 2134 ASSERT_TRUE(notify_sessions_[1]); |
| 1987 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 2135 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1988 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); | 2136 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); |
| 1989 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 2137 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1990 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 2138 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1991 EXPECT_TRUE(characteristic1_->IsNotifying()); | 2139 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1992 } | 2140 } |
| 1993 #endif | 2141 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1994 | 2142 |
| 1995 #if defined(OS_ANDROID) | 2143 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1996 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2144 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1997 StopNotifySession_Reentrant_Stop_StartError) { | 2145 StopNotifySession_Reentrant_Stop_StartError) { |
| 2146 if (!PlatformSupportsLowEnergy()) { |
| 2147 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2148 return; |
| 2149 } |
| 1998 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2150 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1999 /* properties: NOTIFY */ 0x10, | 2151 /* properties: NOTIFY */ 0x10, |
| 2000 /* expected_config_descriptor_value: NOTIFY */ 1)); | 2152 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 2001 | 2153 |
| 2002 // Check that the notify session is active. | 2154 // Check that the notify session is active. |
| 2003 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 2155 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 2004 EXPECT_EQ(characteristic1_->GetIdentifier(), | 2156 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 2005 notify_sessions_[0]->GetCharacteristicIdentifier()); | 2157 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 2006 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 2158 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 2007 EXPECT_TRUE(characteristic1_->IsNotifying()); | 2159 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2023 | 2175 |
| 2024 SimulateGattNotifySessionStartError( | 2176 SimulateGattNotifySessionStartError( |
| 2025 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); | 2177 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); |
| 2026 base::RunLoop().RunUntilIdle(); | 2178 base::RunLoop().RunUntilIdle(); |
| 2027 ASSERT_EQ(1u, notify_sessions_.size()); | 2179 ASSERT_EQ(1u, notify_sessions_.size()); |
| 2028 ASSERT_TRUE(notify_sessions_[0]); | 2180 ASSERT_TRUE(notify_sessions_[0]); |
| 2029 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 2181 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 2030 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 2182 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 2031 EXPECT_FALSE(characteristic1_->IsNotifying()); | 2183 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 2032 } | 2184 } |
| 2033 #endif | 2185 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2034 | 2186 |
| 2035 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 2187 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 2036 // Tests Characteristic Value changes during a Notify Session. | 2188 // Tests Characteristic Value changes during a Notify Session. |
| 2037 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { | 2189 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { |
| 2038 if (!PlatformSupportsLowEnergy()) { | 2190 if (!PlatformSupportsLowEnergy()) { |
| 2039 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 2191 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2040 return; | 2192 return; |
| 2041 } | 2193 } |
| 2042 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2194 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2043 /* properties: NOTIFY */ 0x10, | 2195 /* properties: NOTIFY */ 0x10, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2160 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); | 2312 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 2161 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 2313 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 2162 | 2314 |
| 2163 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 2315 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 2164 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 2316 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 2165 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 2317 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 2166 } | 2318 } |
| 2167 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 2319 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 2168 | 2320 |
| 2169 } // namespace device | 2321 } // namespace device |
| OLD | NEW |