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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc

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