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

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

Issue 2634873002: Bluetooth: macOS: Implement BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications (Closed)
Patch Set: 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 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 1003
1004 // The expected error callback is asynchronous: 1004 // The expected error callback is asynchronous:
1005 EXPECT_EQ(0, error_callback_count_); 1005 EXPECT_EQ(0, error_callback_count_);
1006 base::RunLoop().RunUntilIdle(); 1006 base::RunLoop().RunUntilIdle();
1007 EXPECT_EQ(1, error_callback_count_); 1007 EXPECT_EQ(1, error_callback_count_);
1008 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, 1008 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
1009 last_gatt_error_code_); 1009 last_gatt_error_code_);
1010 } 1010 }
1011 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 1011 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1012 1012
1013 #if defined(OS_ANDROID) || defined(OS_WIN) 1013 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1014 // StartNotifySession fails if the characteristic is missing the Client 1014 // StartNotifySession fails if the characteristic is missing the Client
1015 // Characteristic Configuration descriptor. 1015 // Characteristic Configuration descriptor.
1016 // macOS: TODO(crbug.com/624017) Need to implement CCC descriptors.
1017 TEST_F(BluetoothRemoteGattCharacteristicTest, 1016 TEST_F(BluetoothRemoteGattCharacteristicTest,
1018 StartNotifySession_NoConfigDescriptor) { 1017 StartNotifySession_NoConfigDescriptor) {
1018 if (!PlatformSupportsLowEnergy()) {
1019 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1020 return;
1021 }
1019 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1022 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1020 /* properties: NOTIFY */ 0x10, 1023 /* properties: NOTIFY */ 0x10,
1021 /* expected_config_descriptor_value: NOTIFY */ 1, 1024 /* expected_config_descriptor_value: NOTIFY */ 1,
1022 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); 1025 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING));
1023 1026
1024 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 1027 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1025 1028
1026 // The expected error callback is asynchronous: 1029 // The expected error callback is asynchronous:
1027 EXPECT_EQ(0, error_callback_count_); 1030 EXPECT_EQ(0, error_callback_count_);
1028 base::RunLoop().RunUntilIdle(); 1031 base::RunLoop().RunUntilIdle();
1029 EXPECT_EQ(1, error_callback_count_); 1032 EXPECT_EQ(1, error_callback_count_);
1030 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, 1033 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
1031 last_gatt_error_code_); 1034 last_gatt_error_code_);
1032 } 1035 }
1033 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1036 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1034 1037
1035 #if defined(OS_ANDROID) || defined(OS_WIN) 1038 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1036 // StartNotifySession fails if the characteristic has multiple Client 1039 // StartNotifySession fails if the characteristic has multiple Client
1037 // Characteristic Configuration descriptors. 1040 // Characteristic Configuration descriptors.
1038 // macOS: TODO(crbug.com/624017) Need to implement CCC descriptors.
1039 TEST_F(BluetoothRemoteGattCharacteristicTest, 1041 TEST_F(BluetoothRemoteGattCharacteristicTest,
1040 StartNotifySession_MultipleConfigDescriptor) { 1042 StartNotifySession_MultipleConfigDescriptor) {
1043 if (!PlatformSupportsLowEnergy()) {
1044 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1045 return;
1046 }
1041 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1047 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1042 /* properties: NOTIFY */ 0x10, 1048 /* properties: NOTIFY */ 0x10,
1043 /* expected_config_descriptor_value: NOTIFY */ 1, 1049 /* expected_config_descriptor_value: NOTIFY */ 1,
1044 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); 1050 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE));
1045 1051
1046 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 1052 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1047 1053
1048 // The expected error callback is asynchronous: 1054 // The expected error callback is asynchronous:
1049 EXPECT_EQ(0, error_callback_count_); 1055 EXPECT_EQ(0, error_callback_count_);
1050 base::RunLoop().RunUntilIdle(); 1056 base::RunLoop().RunUntilIdle();
1051 EXPECT_EQ(1, error_callback_count_); 1057 EXPECT_EQ(1, error_callback_count_);
1052 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, 1058 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
1053 last_gatt_error_code_); 1059 last_gatt_error_code_);
1054 } 1060 }
1055 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1061 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1056 1062
1057 #if defined(OS_ANDROID) 1063 #if defined(OS_ANDROID)
1058 // StartNotifySession fails synchronously when failing to set a characteristic 1064 // StartNotifySession fails synchronously when failing to set a characteristic
1059 // to enable notifications. 1065 // to enable notifications.
1060 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. 1066 // Android: This is mBluetoothGatt.setCharacteristicNotification failing.
1061 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API. 1067 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API.
1062 // Windows: Synchronous Test Not Applicable: OS calls are all made 1068 // Windows: Synchronous Test Not Applicable: OS calls are all made
1063 // asynchronously from BluetoothTaskManagerWin. 1069 // asynchronously from BluetoothTaskManagerWin.
1064 TEST_F(BluetoothRemoteGattCharacteristicTest, 1070 TEST_F(BluetoothRemoteGattCharacteristicTest,
1065 StartNotifySession_FailToSetCharacteristicNotification) { 1071 StartNotifySession_FailToSetCharacteristicNotification) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 if (!PlatformSupportsLowEnergy()) { 1154 if (!PlatformSupportsLowEnergy()) {
1149 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1155 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1150 return; 1156 return;
1151 } 1157 }
1152 ASSERT_NO_FATAL_FAILURE( 1158 ASSERT_NO_FATAL_FAILURE(
1153 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1159 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1154 SimulateGattDescriptor( 1160 SimulateGattDescriptor(
1155 characteristic1_, 1161 characteristic1_,
1156 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1162 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1157 .canonical_value()); 1163 .canonical_value());
1158 #if !defined(OS_MACOSX)
1159 // TODO(crbug.com/624017): Need implementation for descriptors.
1160 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1164 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1161 #endif // !defined(OS_MACOSX)
1162 1165
1163 characteristic1_->StartNotifySession( 1166 characteristic1_->StartNotifySession(
1164 GetNotifyCallback(Call::EXPECTED), 1167 GetNotifyCallback(Call::EXPECTED),
1165 GetGattErrorCallback(Call::NOT_EXPECTED)); 1168 GetGattErrorCallback(Call::NOT_EXPECTED));
1166 characteristic1_->StartNotifySession( 1169 characteristic1_->StartNotifySession(
1167 GetNotifyCallback(Call::EXPECTED), 1170 GetNotifyCallback(Call::EXPECTED),
1168 GetGattErrorCallback(Call::NOT_EXPECTED)); 1171 GetGattErrorCallback(Call::NOT_EXPECTED));
1169 EXPECT_EQ(0, callback_count_); 1172 EXPECT_EQ(0, callback_count_);
1170 SimulateGattNotifySessionStarted(characteristic1_); 1173 SimulateGattNotifySessionStarted(characteristic1_);
1171 base::RunLoop().RunUntilIdle(); 1174 base::RunLoop().RunUntilIdle();
(...skipping 19 matching lines...) Expand all
1191 if (!PlatformSupportsLowEnergy()) { 1194 if (!PlatformSupportsLowEnergy()) {
1192 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1195 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1193 return; 1196 return;
1194 } 1197 }
1195 ASSERT_NO_FATAL_FAILURE( 1198 ASSERT_NO_FATAL_FAILURE(
1196 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1199 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1197 SimulateGattDescriptor( 1200 SimulateGattDescriptor(
1198 characteristic1_, 1201 characteristic1_,
1199 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1202 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1200 .canonical_value()); 1203 .canonical_value());
1201 #if !defined(OS_MACOSX)
1202 // TODO(crbug.com/624017): Need implementation for descriptors.
1203 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1204 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1204 #endif // !defined(OS_MACOSX)
1205 1205
1206 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 1206 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
1207 GetGattErrorCallback(Call::EXPECTED)); 1207 GetGattErrorCallback(Call::EXPECTED));
1208 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 1208 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
1209 GetGattErrorCallback(Call::EXPECTED)); 1209 GetGattErrorCallback(Call::EXPECTED));
1210 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1210 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1211 EXPECT_EQ(0, callback_count_); 1211 EXPECT_EQ(0, callback_count_);
1212 SimulateGattNotifySessionStartError( 1212 SimulateGattNotifySessionStartError(
1213 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 1213 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
1214 base::RunLoop().RunUntilIdle(); 1214 base::RunLoop().RunUntilIdle();
(...skipping 29 matching lines...) Expand all
1244 1244
1245 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); 1245 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr);
1246 EXPECT_EQ(0, callback_count_); 1246 EXPECT_EQ(0, callback_count_);
1247 EXPECT_EQ(1, error_callback_count_); 1247 EXPECT_EQ(1, error_callback_count_);
1248 ASSERT_EQ(0u, notify_sessions_.size()); 1248 ASSERT_EQ(0u, notify_sessions_.size());
1249 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, 1249 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
1250 last_gatt_error_code_); 1250 last_gatt_error_code_);
1251 } 1251 }
1252 #endif // defined(OS_ANDROID) 1252 #endif // defined(OS_ANDROID)
1253 1253
1254 #if defined(OS_ANDROID) 1254 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1255 // Tests StartNotifySession completing before chrome objects are deleted. 1255 // Tests StartNotifySession completing before chrome objects are deleted.
1256 TEST_F(BluetoothRemoteGattCharacteristicTest, 1256 TEST_F(BluetoothRemoteGattCharacteristicTest,
1257 StartNotifySession_BeforeDeleted) { 1257 StartNotifySession_BeforeDeleted) {
1258 if (!PlatformSupportsLowEnergy()) {
1259 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1260 return;
1261 }
1258 ASSERT_NO_FATAL_FAILURE( 1262 ASSERT_NO_FATAL_FAILURE(
1259 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1263 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1260 SimulateGattDescriptor( 1264 SimulateGattDescriptor(
1261 characteristic1_, 1265 characteristic1_,
1262 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1266 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1263 .canonical_value()); 1267 .canonical_value());
1264 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1268 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1265 1269
1266 characteristic1_->StartNotifySession( 1270 characteristic1_->StartNotifySession(
1267 GetNotifyCallback(Call::EXPECTED), 1271 GetNotifyCallback(Call::EXPECTED),
(...skipping 13 matching lines...) Expand all
1281 1285
1282 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1286 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1283 1287
1284 base::RunLoop().RunUntilIdle(); 1288 base::RunLoop().RunUntilIdle();
1285 EXPECT_TRUE("Did not crash!"); 1289 EXPECT_TRUE("Did not crash!");
1286 ASSERT_TRUE(notify_sessions_[0]); 1290 ASSERT_TRUE(notify_sessions_[0]);
1287 EXPECT_EQ(characteristic_identifier, 1291 EXPECT_EQ(characteristic_identifier,
1288 notify_sessions_[0]->GetCharacteristicIdentifier()); 1292 notify_sessions_[0]->GetCharacteristicIdentifier());
1289 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1293 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1290 } 1294 }
1291 #endif // defined(OS_ANDROID) 1295 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1292 1296
1293 #if defined(OS_MACOSX) || defined(OS_WIN) 1297 #if defined(OS_MACOSX) || defined(OS_WIN)
1294 // Tests StartNotifySession reentrant in start notify session success callback 1298 // Tests StartNotifySession reentrant in start notify session success callback
1295 // and the reentrant start notify session success. 1299 // and the reentrant start notify session success.
1296 TEST_F(BluetoothRemoteGattCharacteristicTest, 1300 TEST_F(BluetoothRemoteGattCharacteristicTest,
1297 StartNotifySession_Reentrant_Success_Success) { 1301 StartNotifySession_Reentrant_Success_Success) {
1298 if (!PlatformSupportsLowEnergy()) { 1302 if (!PlatformSupportsLowEnergy()) {
1299 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1303 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1300 return; 1304 return;
1301 } 1305 }
1302 ASSERT_NO_FATAL_FAILURE( 1306 ASSERT_NO_FATAL_FAILURE(
1303 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1307 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1304 SimulateGattDescriptor( 1308 SimulateGattDescriptor(
1305 characteristic1_, 1309 characteristic1_,
1306 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value()); 1310 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1307 #if !defined(OS_MACOSX)
1308 // TODO(crbug.com/624017): Need implementation for descriptors.
1309 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1311 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1310 #endif // !defined(OS_MACOSX)
1311 1312
1312 characteristic1_->StartNotifySession( 1313 characteristic1_->StartNotifySession(
1313 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, 1314 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED,
1314 characteristic1_), 1315 characteristic1_),
1315 GetReentrantStartNotifySessionErrorCallback( 1316 GetReentrantStartNotifySessionErrorCallback(
1316 Call::NOT_EXPECTED, characteristic1_, 1317 Call::NOT_EXPECTED, characteristic1_,
1317 false /* error_in_reentrant */)); 1318 false /* error_in_reentrant */));
1318 EXPECT_EQ(0, callback_count_); 1319 EXPECT_EQ(0, callback_count_);
1319 SimulateGattNotifySessionStarted(characteristic1_); 1320 SimulateGattNotifySessionStarted(characteristic1_);
1320 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1321 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 SimulateGattNotifySessionStarted(characteristic1_); 1404 SimulateGattNotifySessionStarted(characteristic1_);
1404 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 1405 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1405 EXPECT_EQ(0, callback_count_); 1406 EXPECT_EQ(0, callback_count_);
1406 EXPECT_EQ(2, error_callback_count_); 1407 EXPECT_EQ(2, error_callback_count_);
1407 ASSERT_EQ(0u, notify_sessions_.size()); 1408 ASSERT_EQ(0u, notify_sessions_.size());
1408 } 1409 }
1409 #endif // defined(OS_WIN) 1410 #endif // defined(OS_WIN)
1410 1411
1411 #if defined(OS_ANDROID) 1412 #if defined(OS_ANDROID)
1412 // Tests StopNotifySession success on a characteristic that enabled Notify. 1413 // Tests StopNotifySession success on a characteristic that enabled Notify.
1414 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
ortuno 2017/02/09 22:46:27 Ah sorry to be confusing. I meant that only the pa
jlebel 2017/02/13 19:22:22 Done.
1415 // setNotifyValue:forCharacteristic:] which handles all interactions with
1416 // the CCC descriptor.
1417 #if !defined(OS_MACOSX)
1413 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { 1418 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) {
1419 if (!PlatformSupportsLowEnergy()) {
1420 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1421 return;
1422 }
1414 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1423 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1415 /* properties: NOTIFY */ 0x10, 1424 /* properties: NOTIFY */ 0x10,
1416 /* expected_config_descriptor_value: NOTIFY */ 1)); 1425 /* expected_config_descriptor_value: NOTIFY */ 1));
1417 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1426 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1418 1427
1419 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1428 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1420 SimulateGattNotifySessionStopped(characteristic1_); 1429 SimulateGattNotifySessionStopped(characteristic1_);
1421 base::RunLoop().RunUntilIdle(); 1430 base::RunLoop().RunUntilIdle();
1422 1431
1423 // Check that the right values were written to the descriptor. 1432 // Check that the right values were written to the descriptor.
1424 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1433 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
ortuno 2017/02/09 22:46:27 Only these four statements should be surrounded by
jlebel 2017/02/13 19:22:22 Done.
1425 ASSERT_EQ(2u, last_write_value_.size()); 1434 ASSERT_EQ(2u, last_write_value_.size());
1426 EXPECT_EQ(0, last_write_value_[0]); 1435 EXPECT_EQ(0, last_write_value_[0]);
1427 EXPECT_EQ(0, last_write_value_[1]); 1436 EXPECT_EQ(0, last_write_value_[1]);
1428 1437
1429 // Check that the notify session is inactive. 1438 // Check that the notify session is inactive.
1430 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1439 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1431 EXPECT_FALSE(characteristic1_->IsNotifying()); 1440 EXPECT_FALSE(characteristic1_->IsNotifying());
1432 } 1441 }
1442 #endif // !defined(OS_MACOSX)
1433 #endif // defined(OS_ANDROID) 1443 #endif // defined(OS_ANDROID)
1434 1444
1435 #if defined(OS_ANDROID) 1445 #if defined(OS_ANDROID)
1436 // Tests that deleted sessions are stopped. 1446 // Tests that deleted sessions are stopped.
1447 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
1448 // setNotifyValue:forCharacteristic:] which handles all interactions with
1449 // the CCC descriptor.
1450 #if !defined(OS_MACOSX)
1437 TEST_F(BluetoothRemoteGattCharacteristicTest, 1451 TEST_F(BluetoothRemoteGattCharacteristicTest,
1438 StopNotifySession_SessionDeleted) { 1452 StopNotifySession_SessionDeleted) {
1453 if (!PlatformSupportsLowEnergy()) {
1454 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1455 return;
1456 }
1439 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1457 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1440 /* properties: NOTIFY */ 0x10, 1458 /* properties: NOTIFY */ 0x10,
1441 /* expected_config_descriptor_value: NOTIFY */ 1)); 1459 /* expected_config_descriptor_value: NOTIFY */ 1));
1442 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1460 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1443 1461
1444 notify_sessions_.clear(); 1462 notify_sessions_.clear();
1445 SimulateGattNotifySessionStopped(characteristic1_); 1463 SimulateGattNotifySessionStopped(characteristic1_);
1446 base::RunLoop().RunUntilIdle(); 1464 base::RunLoop().RunUntilIdle();
1447 1465
1448 // Check that the right values were written to the descriptor. 1466 // Check that the right values were written to the descriptor.
1449 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1467 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
1450 ASSERT_EQ(2u, last_write_value_.size()); 1468 ASSERT_EQ(2u, last_write_value_.size());
1451 EXPECT_EQ(0, last_write_value_[0]); 1469 EXPECT_EQ(0, last_write_value_[0]);
1452 EXPECT_EQ(0, last_write_value_[1]); 1470 EXPECT_EQ(0, last_write_value_[1]);
1453 1471
1454 // Check that the notify session is inactive. 1472 // Check that the notify session is inactive.
1455 EXPECT_FALSE(characteristic1_->IsNotifying()); 1473 EXPECT_FALSE(characteristic1_->IsNotifying());
1456 } 1474 }
1475 #endif // !defined(OS_MACOSX)
1457 #endif // defined(OS_ANDROID) 1476 #endif // defined(OS_ANDROID)
1458 1477
1459 #if defined(OS_ANDROID) 1478 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1460 // Tests that deleting the sessions before the stop callbacks have been 1479 // Tests that deleting the sessions before the stop callbacks have been
1461 // invoked does not cause problems. 1480 // invoked does not cause problems.
1462 TEST_F(BluetoothRemoteGattCharacteristicTest, 1481 TEST_F(BluetoothRemoteGattCharacteristicTest,
1463 StopNotifySession_SessionDeleted2) { 1482 StopNotifySession_SessionDeleted2) {
1483 if (!PlatformSupportsLowEnergy()) {
1484 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1485 return;
1486 }
1464 ASSERT_NO_FATAL_FAILURE( 1487 ASSERT_NO_FATAL_FAILURE(
1465 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1488 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1466 1489
1467 #if !defined(OS_MACOSX)
1468 // TODO(624017) enable for macosx
1469 SimulateGattDescriptor( 1490 SimulateGattDescriptor(
1470 characteristic1_, 1491 characteristic1_,
1471 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1492 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1472 .canonical_value()); 1493 .canonical_value());
1473 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1494 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1474 #endif
1475 1495
1476 // Start notify sessions. 1496 // Start notify sessions.
1477 characteristic1_->StartNotifySession( 1497 characteristic1_->StartNotifySession(
1478 GetNotifyCheckForPrecedingCalls(0), 1498 GetNotifyCheckForPrecedingCalls(0),
1479 GetGattErrorCallback(Call::NOT_EXPECTED)); 1499 GetGattErrorCallback(Call::NOT_EXPECTED));
1480 characteristic1_->StartNotifySession( 1500 characteristic1_->StartNotifySession(
1481 GetNotifyCheckForPrecedingCalls(1), 1501 GetNotifyCheckForPrecedingCalls(1),
1482 GetGattErrorCallback(Call::NOT_EXPECTED)); 1502 GetGattErrorCallback(Call::NOT_EXPECTED));
1483 EXPECT_EQ(0, callback_count_); 1503 EXPECT_EQ(0, callback_count_);
1484 SimulateGattNotifySessionStarted(characteristic1_); 1504 SimulateGattNotifySessionStarted(characteristic1_);
(...skipping 19 matching lines...) Expand all
1504 1524
1505 // Run the stop events. 1525 // Run the stop events.
1506 base::RunLoop().RunUntilIdle(); 1526 base::RunLoop().RunUntilIdle();
1507 SimulateGattNotifySessionStopped(characteristic1_); 1527 SimulateGattNotifySessionStopped(characteristic1_);
1508 base::RunLoop().RunUntilIdle(); 1528 base::RunLoop().RunUntilIdle();
1509 1529
1510 // Check that the state is correct. 1530 // Check that the state is correct.
1511 EXPECT_TRUE("Did not crash!"); 1531 EXPECT_TRUE("Did not crash!");
1512 EXPECT_FALSE(characteristic1_->IsNotifying()); 1532 EXPECT_FALSE(characteristic1_->IsNotifying());
1513 } 1533 }
1514 #endif // defined(OS_ANDROID) 1534 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1515 1535
1516 #if defined(OS_ANDROID) 1536 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1517 // Tests that cancelling StopNotifySession works. 1537 // 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 1538 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is
1521 // implemented. 1539 // implemented.
1522 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { 1540 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) {
1541 if (!PlatformSupportsLowEnergy()) {
1542 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1543 return;
1544 }
1523 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1545 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1524 /* properties: NOTIFY */ 0x10, 1546 /* properties: NOTIFY */ 0x10,
1525 /* expected_config_descriptor_value: NOTIFY */ 1)); 1547 /* expected_config_descriptor_value: NOTIFY */ 1));
1526 1548
1527 // Check that the session is correctly setup. 1549 // Check that the session is correctly setup.
1528 std::string characteristic_identifier = characteristic1_->GetIdentifier(); 1550 std::string characteristic_identifier = characteristic1_->GetIdentifier();
1529 EXPECT_EQ(characteristic_identifier, 1551 EXPECT_EQ(characteristic_identifier,
1530 notify_sessions_[0]->GetCharacteristicIdentifier()); 1552 notify_sessions_[0]->GetCharacteristicIdentifier());
1531 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1553 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1532 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1554 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1533 1555
1534 // Queue a Stop request. 1556 // Queue a Stop request.
1535 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1557 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1536 1558
1537 // Cancel Stop by deleting the device before Stop finishes. 1559 // Cancel Stop by deleting the device before Stop finishes.
1538 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1560 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1539 } 1561 }
1540 #endif // defined(OS_ANDROID) 1562 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1541 1563
1542 #if defined(OS_ANDROID) 1564 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1543 // Tests that deleted sessions are stopped. 1565 // Tests that deleted sessions are stopped.
1544 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { 1566 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) {
1567 if (!PlatformSupportsLowEnergy()) {
1568 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1569 return;
1570 }
1545 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1571 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1546 /* properties: NOTIFY */ 0x10, 1572 /* properties: NOTIFY */ 0x10,
1547 /* expected_config_descriptor_value: NOTIFY */ 1)); 1573 /* expected_config_descriptor_value: NOTIFY */ 1));
1548 1574
1549 // Check that the session is correctly setup 1575 // Check that the session is correctly setup
1550 std::string characteristic_identifier = characteristic1_->GetIdentifier(); 1576 std::string characteristic_identifier = characteristic1_->GetIdentifier();
1551 EXPECT_EQ(characteristic_identifier, 1577 EXPECT_EQ(characteristic_identifier,
1552 notify_sessions_[0]->GetCharacteristicIdentifier()); 1578 notify_sessions_[0]->GetCharacteristicIdentifier());
1553 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1579 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1554 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1580 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1555 1581
1556 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1582 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1557 1583
1558 ResetEventCounts(); 1584 ResetEventCounts();
1559 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1585 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1560 1586
1561 // Check that the callback does not arrive synchronously. 1587 // Check that the callback does not arrive synchronously.
1562 EXPECT_EQ(0, callback_count_); 1588 EXPECT_EQ(0, callback_count_);
1563 1589
1564 // Trigger the stop callback 1590 // Trigger the stop callback
1565 base::RunLoop().RunUntilIdle(); 1591 base::RunLoop().RunUntilIdle();
1566 EXPECT_EQ(1, callback_count_); 1592 EXPECT_EQ(1, callback_count_);
1567 1593
1568 EXPECT_TRUE("Did not crash!"); 1594 EXPECT_TRUE("Did not crash!");
1569 ASSERT_TRUE(notify_sessions_[0]); 1595 ASSERT_TRUE(notify_sessions_[0]);
1570 EXPECT_EQ(characteristic_identifier, 1596 EXPECT_EQ(characteristic_identifier,
1571 notify_sessions_[0]->GetCharacteristicIdentifier()); 1597 notify_sessions_[0]->GetCharacteristicIdentifier());
1572 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1598 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1573 } 1599 }
1574 #endif // defined(OS_ANDROID) 1600 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1575 1601
1576 #if defined(OS_ANDROID) 1602 #if defined(OS_ANDROID)
1577 // Tests StopNotifySession success on a characteristic that enabled Indicate. 1603 // Tests StopNotifySession success on a characteristic that enabled Indicate.
1604 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
1605 // setNotifyValue:forCharacteristic:] which handles all interactions with
1606 // the CCC descriptor.
1607 #if !defined(OS_MACOSX)
1578 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { 1608 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) {
1609 if (!PlatformSupportsLowEnergy()) {
1610 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1611 return;
1612 }
1579 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1613 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1580 /* properties: INDICATE */ 0x20, 1614 /* properties: INDICATE */ 0x20,
1581 /* expected_config_descriptor_value: INDICATE */ 2)); 1615 /* expected_config_descriptor_value: INDICATE */ 2));
1582 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1616 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1583 1617
1584 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1618 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1585 SimulateGattNotifySessionStopped(characteristic1_); 1619 SimulateGattNotifySessionStopped(characteristic1_);
1586 base::RunLoop().RunUntilIdle(); 1620 base::RunLoop().RunUntilIdle();
1587 1621
1588 // Check that the right values were written to the descriptor. 1622 // Check that the right values were written to the descriptor.
1589 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1623 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
1590 ASSERT_EQ(2u, last_write_value_.size()); 1624 ASSERT_EQ(2u, last_write_value_.size());
1591 EXPECT_EQ(0, last_write_value_[0]); 1625 EXPECT_EQ(0, last_write_value_[0]);
1592 EXPECT_EQ(0, last_write_value_[1]); 1626 EXPECT_EQ(0, last_write_value_[1]);
1593 1627
1594 // Check that the notify session is inactive. 1628 // Check that the notify session is inactive.
1595 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1629 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1596 EXPECT_FALSE(characteristic1_->IsNotifying()); 1630 EXPECT_FALSE(characteristic1_->IsNotifying());
1597 } 1631 }
1632 #endif // !defined(OS_MACOSX)
1598 #endif // defined(OS_ANDROID) 1633 #endif // defined(OS_ANDROID)
1599 1634
1600 #if defined(OS_ANDROID) 1635 #if defined(OS_ANDROID)
1601 // Tests StopNotifySession success on a characteristic that enabled Notify & 1636 // Tests StopNotifySession success on a characteristic that enabled Notify &
1602 // Indicate. 1637 // Indicate.
1638 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
1639 // setNotifyValue:forCharacteristic:] which handles all interactions with
1640 // the CCC descriptor.
1641 #if !defined(OS_MACOSX)
1603 TEST_F(BluetoothRemoteGattCharacteristicTest, 1642 TEST_F(BluetoothRemoteGattCharacteristicTest,
1604 StopNotifySession_OnNotifyAndIndicate) { 1643 StopNotifySession_OnNotifyAndIndicate) {
1644 if (!PlatformSupportsLowEnergy()) {
1645 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1646 return;
1647 }
1605 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1648 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1606 /* properties: NOTIFY and INDICATE bits set */ 0x30, 1649 /* properties: NOTIFY and INDICATE bits set */ 0x30,
1607 /* expected_config_descriptor_value: INDICATE */ 1)); 1650 /* expected_config_descriptor_value: INDICATE */ 1));
1608 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1651 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1609 1652
1610 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1653 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1611 SimulateGattNotifySessionStopped(characteristic1_); 1654 SimulateGattNotifySessionStopped(characteristic1_);
1612 base::RunLoop().RunUntilIdle(); 1655 base::RunLoop().RunUntilIdle();
1613 1656
1614 // Check that the right values were written to the descriptor. 1657 // Check that the right values were written to the descriptor.
1615 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1658 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
1616 ASSERT_EQ(2u, last_write_value_.size()); 1659 ASSERT_EQ(2u, last_write_value_.size());
1617 EXPECT_EQ(0, last_write_value_[0]); 1660 EXPECT_EQ(0, last_write_value_[0]);
1618 EXPECT_EQ(0, last_write_value_[1]); 1661 EXPECT_EQ(0, last_write_value_[1]);
1619 1662
1620 // Check that the notify session is inactive. 1663 // Check that the notify session is inactive.
1621 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1664 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1622 EXPECT_FALSE(characteristic1_->IsNotifying()); 1665 EXPECT_FALSE(characteristic1_->IsNotifying());
1623 } 1666 }
1667 #endif // !defined(OS_MACOSX)
1624 #endif // defined(OS_ANDROID) 1668 #endif // defined(OS_ANDROID)
1625 1669
1626 #if defined(OS_ANDROID) 1670 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1627 // Tests StopNotifySession error 1671 // Tests StopNotifySession error
1628 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { 1672 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) {
1673 if (!PlatformSupportsLowEnergy()) {
1674 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1675 return;
1676 }
1629 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1677 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1630 /* properties: NOTIFY */ 0x10, 1678 /* properties: NOTIFY */ 0x10,
1631 /* expected_config_descriptor_value: NOTIFY */ 1)); 1679 /* expected_config_descriptor_value: NOTIFY */ 1));
1632 1680
1633 // Check that the notify session is active. 1681 // Check that the notify session is active.
1634 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1682 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1635 EXPECT_EQ(characteristic1_->GetIdentifier(), 1683 EXPECT_EQ(characteristic1_->GetIdentifier(),
1636 notify_sessions_[0]->GetCharacteristicIdentifier()); 1684 notify_sessions_[0]->GetCharacteristicIdentifier());
1637 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1685 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1638 EXPECT_TRUE(characteristic1_->IsNotifying()); 1686 EXPECT_TRUE(characteristic1_->IsNotifying());
1639 1687
1640 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1688 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1641 SimulateGattNotifySessionStopError( 1689 SimulateGattNotifySessionStopError(
1642 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); 1690 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN);
1643 base::RunLoop().RunUntilIdle(); 1691 base::RunLoop().RunUntilIdle();
1644 1692
1645 // Check that the notify session is inactive. 1693 // Check that the notify session is inactive.
1646 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1694 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1647 EXPECT_FALSE(characteristic1_->IsNotifying()); 1695 EXPECT_FALSE(characteristic1_->IsNotifying());
1648 } 1696 }
1649 #endif // defined(OS_ANDROID) 1697 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1650 1698
1651 #if defined(OS_ANDROID) 1699 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1652 // Tests multiple StopNotifySession calls for a single session. 1700 // Tests multiple StopNotifySession calls for a single session.
1653 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) { 1701 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) {
1702 if (!PlatformSupportsLowEnergy()) {
1703 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1704 return;
1705 }
1654 ASSERT_NO_FATAL_FAILURE( 1706 ASSERT_NO_FATAL_FAILURE(
1655 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1707 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1656 1708
1657 #if !defined(OS_MACOSX)
1658 // TODO(624017) enable for macosx
1659 SimulateGattDescriptor( 1709 SimulateGattDescriptor(
1660 characteristic1_, 1710 characteristic1_,
1661 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1711 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1662 .canonical_value()); 1712 .canonical_value());
1663 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1713 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1664 #endif
1665 1714
1666 // Start notify session 1715 // Start notify session
1667 characteristic1_->StartNotifySession( 1716 characteristic1_->StartNotifySession(
1668 GetNotifyCallback(Call::EXPECTED), 1717 GetNotifyCallback(Call::EXPECTED),
1669 GetGattErrorCallback(Call::NOT_EXPECTED)); 1718 GetGattErrorCallback(Call::NOT_EXPECTED));
1670 EXPECT_EQ(0, callback_count_); 1719 EXPECT_EQ(0, callback_count_);
1671 SimulateGattNotifySessionStarted(characteristic1_); 1720 SimulateGattNotifySessionStarted(characteristic1_);
1672 base::RunLoop().RunUntilIdle(); 1721 base::RunLoop().RunUntilIdle();
1673 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1722 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1674 EXPECT_EQ(1, callback_count_); 1723 EXPECT_EQ(1, callback_count_);
1675 EXPECT_EQ(0, error_callback_count_); 1724 EXPECT_EQ(0, error_callback_count_);
1676 ASSERT_EQ(1u, notify_sessions_.size()); 1725 ASSERT_EQ(1u, notify_sessions_.size());
1677 ASSERT_TRUE(notify_sessions_[0]); 1726 ASSERT_TRUE(notify_sessions_[0]);
1678 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1727 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1679 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1728 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1680 EXPECT_TRUE(characteristic1_->IsNotifying()); 1729 EXPECT_TRUE(characteristic1_->IsNotifying());
1681 1730
1682 // Stop the notify session twice 1731 // Stop the notify session twice
1683 ResetEventCounts(); 1732 ResetEventCounts();
1684 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(0)); 1733 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(0));
1685 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); 1734 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1));
1686 SimulateGattNotifySessionStopped(characteristic1_); 1735 SimulateGattNotifySessionStopped(characteristic1_);
1687 base::RunLoop().RunUntilIdle(); 1736 base::RunLoop().RunUntilIdle();
1688 1737
1689 // Check that the notify session is inactive. 1738 // Check that the notify session is inactive.
1690 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1739 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1691 EXPECT_FALSE(characteristic1_->IsNotifying()); 1740 EXPECT_FALSE(characteristic1_->IsNotifying());
1692 } 1741 }
1693 #endif // defined(OS_ANDROID) 1742 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1694 1743
1695 #if defined(OS_ANDROID) 1744 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1696 // Tests multiple StartNotifySession calls and multiple StopNotifySession calls. 1745 // Tests multiple StartNotifySession calls and multiple StopNotifySession calls.
1697 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) { 1746 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) {
1747 if (!PlatformSupportsLowEnergy()) {
1748 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1749 return;
1750 }
1698 ASSERT_NO_FATAL_FAILURE( 1751 ASSERT_NO_FATAL_FAILURE(
1699 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1752 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1700 1753
1701 #if !defined(OS_MACOSX)
1702 // TODO(624017) enable for macosx
1703 SimulateGattDescriptor( 1754 SimulateGattDescriptor(
1704 characteristic1_, 1755 characteristic1_,
1705 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1756 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1706 .canonical_value()); 1757 .canonical_value());
1707 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1758 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1708 #endif
1709 1759
1710 // Start notify sessions 1760 // Start notify sessions
1711 characteristic1_->StartNotifySession( 1761 characteristic1_->StartNotifySession(
1712 GetNotifyCheckForPrecedingCalls(0), 1762 GetNotifyCheckForPrecedingCalls(0),
1713 GetGattErrorCallback(Call::NOT_EXPECTED)); 1763 GetGattErrorCallback(Call::NOT_EXPECTED));
1714 characteristic1_->StartNotifySession( 1764 characteristic1_->StartNotifySession(
1715 GetNotifyCheckForPrecedingCalls(1), 1765 GetNotifyCheckForPrecedingCalls(1),
1716 GetGattErrorCallback(Call::NOT_EXPECTED)); 1766 GetGattErrorCallback(Call::NOT_EXPECTED));
1717 EXPECT_EQ(0, callback_count_); 1767 EXPECT_EQ(0, callback_count_);
1718 SimulateGattNotifySessionStarted(characteristic1_); 1768 SimulateGattNotifySessionStarted(characteristic1_);
(...skipping 19 matching lines...) Expand all
1738 1788
1739 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(3)); 1789 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(3));
1740 SimulateGattNotifySessionStopped(characteristic1_); 1790 SimulateGattNotifySessionStopped(characteristic1_);
1741 base::RunLoop().RunUntilIdle(); 1791 base::RunLoop().RunUntilIdle();
1742 1792
1743 // Check that the notify sessions is inactive. 1793 // Check that the notify sessions is inactive.
1744 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1794 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1745 EXPECT_FALSE(notify_sessions_[1]->IsActive()); 1795 EXPECT_FALSE(notify_sessions_[1]->IsActive());
1746 EXPECT_FALSE(characteristic1_->IsNotifying()); 1796 EXPECT_FALSE(characteristic1_->IsNotifying());
1747 } 1797 }
1748 #endif // defined(OS_ANDROID) 1798 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1749 1799
1750 #if defined(OS_ANDROID) 1800 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1751 // Tests starting a new notify session before the previous stop request 1801 // Tests starting a new notify session before the previous stop request
1752 // resolves. 1802 // resolves.
1753 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) { 1803 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) {
1804 if (!PlatformSupportsLowEnergy()) {
1805 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1806 return;
1807 }
1754 ASSERT_NO_FATAL_FAILURE( 1808 ASSERT_NO_FATAL_FAILURE(
1755 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1809 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1756 SimulateGattDescriptor( 1810 SimulateGattDescriptor(
1757 characteristic1_, 1811 characteristic1_,
1758 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1812 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1759 .canonical_value()); 1813 .canonical_value());
1760 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1814 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1761 1815
1762 // Start notify session 1816 // Start notify session
1763 ResetEventCounts(); 1817 ResetEventCounts();
(...skipping 20 matching lines...) Expand all
1784 1838
1785 SimulateGattNotifySessionStarted(characteristic1_); 1839 SimulateGattNotifySessionStarted(characteristic1_);
1786 base::RunLoop().RunUntilIdle(); 1840 base::RunLoop().RunUntilIdle();
1787 ASSERT_EQ(2u, notify_sessions_.size()); 1841 ASSERT_EQ(2u, notify_sessions_.size());
1788 ASSERT_TRUE(notify_sessions_[0]); 1842 ASSERT_TRUE(notify_sessions_[0]);
1789 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1843 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1790 ASSERT_TRUE(notify_sessions_[1]); 1844 ASSERT_TRUE(notify_sessions_[1]);
1791 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 1845 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1792 EXPECT_TRUE(characteristic1_->IsNotifying()); 1846 EXPECT_TRUE(characteristic1_->IsNotifying());
1793 } 1847 }
1794 #endif // defined(OS_ANDROID) 1848 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1795 1849
1796 #if defined(OS_ANDROID) 1850 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1797 TEST_F(BluetoothRemoteGattCharacteristicTest, 1851 TEST_F(BluetoothRemoteGattCharacteristicTest,
1798 StopNotifySession_StartStopStart) { 1852 StopNotifySession_StartStopStart) {
1853 if (!PlatformSupportsLowEnergy()) {
1854 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1855 return;
1856 }
1799 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1857 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1800 /* properties: NOTIFY */ 0x10, 1858 /* properties: NOTIFY */ 0x10,
1801 /* expected_config_descriptor_value: NOTIFY */ 1)); 1859 /* expected_config_descriptor_value: NOTIFY */ 1));
1802 1860
1803 // Check that the initial notify session is active. 1861 // Check that the initial notify session is active.
1804 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1862 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1805 EXPECT_EQ(characteristic1_->GetIdentifier(), 1863 EXPECT_EQ(characteristic1_->GetIdentifier(),
1806 notify_sessions_[0]->GetCharacteristicIdentifier()); 1864 notify_sessions_[0]->GetCharacteristicIdentifier());
1807 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1865 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1808 EXPECT_TRUE(characteristic1_->IsNotifying()); 1866 EXPECT_TRUE(characteristic1_->IsNotifying());
(...skipping 27 matching lines...) Expand all
1836 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); 1894 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic());
1837 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 1895 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1838 1896
1839 EXPECT_EQ(characteristic1_->GetIdentifier(), 1897 EXPECT_EQ(characteristic1_->GetIdentifier(),
1840 notify_sessions_[2]->GetCharacteristicIdentifier()); 1898 notify_sessions_[2]->GetCharacteristicIdentifier());
1841 EXPECT_EQ(characteristic1_, notify_sessions_[2]->GetCharacteristic()); 1899 EXPECT_EQ(characteristic1_, notify_sessions_[2]->GetCharacteristic());
1842 EXPECT_TRUE(notify_sessions_[2]->IsActive()); 1900 EXPECT_TRUE(notify_sessions_[2]->IsActive());
1843 1901
1844 EXPECT_TRUE(characteristic1_->IsNotifying()); 1902 EXPECT_TRUE(characteristic1_->IsNotifying());
1845 } 1903 }
1846 #endif 1904 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1847 1905
1848 #if defined(OS_ANDROID) 1906 #if defined(OS_ANDROID)
1849 // Tests starting a new notify session before the previous stop requests 1907 // Tests starting a new notify session before the previous stop requests
1850 // resolve. 1908 // resolve.
1909 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral
1910 // setNotifyValue:forCharacteristic:] which handles all interactions with
1911 // the CCC descriptor.
1912 #if !defined(OS_MACOSX)
1851 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) { 1913 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) {
1914 if (!PlatformSupportsLowEnergy()) {
1915 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1916 return;
1917 }
1852 ASSERT_NO_FATAL_FAILURE( 1918 ASSERT_NO_FATAL_FAILURE(
1853 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1919 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1854 SimulateGattDescriptor( 1920 SimulateGattDescriptor(
1855 characteristic1_, 1921 characteristic1_,
1856 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1922 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1857 .canonical_value()); 1923 .canonical_value());
1858 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1924 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1859 1925
1860 // Start notify session 1926 // Start notify session
1861 ResetEventCounts(); 1927 ResetEventCounts();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 EXPECT_EQ(0, last_write_value_[1]); 1967 EXPECT_EQ(0, last_write_value_[1]);
1902 1968
1903 // Check the notify state 1969 // Check the notify state
1904 ASSERT_EQ(2u, notify_sessions_.size()); 1970 ASSERT_EQ(2u, notify_sessions_.size());
1905 ASSERT_TRUE(notify_sessions_[0]); 1971 ASSERT_TRUE(notify_sessions_[0]);
1906 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1972 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1907 ASSERT_TRUE(notify_sessions_[1]); 1973 ASSERT_TRUE(notify_sessions_[1]);
1908 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 1974 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1909 EXPECT_TRUE(characteristic1_->IsNotifying()); 1975 EXPECT_TRUE(characteristic1_->IsNotifying());
1910 } 1976 }
1977 #endif // !defined(OS_MACOSX)
1911 #endif // defined(OS_ANDROID) 1978 #endif // defined(OS_ANDROID)
1912 1979
1913 #if defined(OS_ANDROID) 1980 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1914 TEST_F(BluetoothRemoteGattCharacteristicTest, 1981 TEST_F(BluetoothRemoteGattCharacteristicTest,
1915 StopNotifySession_Reentrant_Success_Stop) { 1982 StopNotifySession_Reentrant_Success_Stop) {
1983 if (!PlatformSupportsLowEnergy()) {
1984 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1985 return;
1986 }
1916 ASSERT_NO_FATAL_FAILURE( 1987 ASSERT_NO_FATAL_FAILURE(
1917 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1988 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1918 SimulateGattDescriptor( 1989 SimulateGattDescriptor(
1919 characteristic1_, 1990 characteristic1_,
1920 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1991 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1921 .canonical_value()); 1992 .canonical_value());
1922 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1993 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1923 1994
1924 // Start notify session 1995 // Start notify session
1925 characteristic1_->StartNotifySession( 1996 characteristic1_->StartNotifySession(
(...skipping 15 matching lines...) Expand all
1941 ASSERT_EQ(1u, notify_sessions_.size()); 2012 ASSERT_EQ(1u, notify_sessions_.size());
1942 ASSERT_TRUE(notify_sessions_[0]); 2013 ASSERT_TRUE(notify_sessions_[0]);
1943 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 2014 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1944 EXPECT_TRUE(characteristic1_->IsNotifying()); 2015 EXPECT_TRUE(characteristic1_->IsNotifying());
1945 2016
1946 SimulateGattNotifySessionStopped(characteristic1_); 2017 SimulateGattNotifySessionStopped(characteristic1_);
1947 base::RunLoop().RunUntilIdle(); 2018 base::RunLoop().RunUntilIdle();
1948 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 2019 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1949 EXPECT_FALSE(characteristic1_->IsNotifying()); 2020 EXPECT_FALSE(characteristic1_->IsNotifying());
1950 } 2021 }
1951 #endif 2022 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1952 2023
1953 #if defined(OS_ANDROID) 2024 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1954 TEST_F(BluetoothRemoteGattCharacteristicTest, 2025 TEST_F(BluetoothRemoteGattCharacteristicTest,
1955 StopNotifySession_Reentrant_Stop_StartSuccess) { 2026 StopNotifySession_Reentrant_Stop_StartSuccess) {
2027 if (!PlatformSupportsLowEnergy()) {
2028 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2029 return;
2030 }
1956 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 2031 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1957 /* properties: NOTIFY */ 0x10, 2032 /* properties: NOTIFY */ 0x10,
1958 /* expected_config_descriptor_value: NOTIFY */ 1)); 2033 /* expected_config_descriptor_value: NOTIFY */ 1));
1959 2034
1960 // Check that the notify session is active. 2035 // Check that the notify session is active.
1961 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 2036 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1962 EXPECT_EQ(characteristic1_->GetIdentifier(), 2037 EXPECT_EQ(characteristic1_->GetIdentifier(),
1963 notify_sessions_[0]->GetCharacteristicIdentifier()); 2038 notify_sessions_[0]->GetCharacteristicIdentifier());
1964 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 2039 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1965 EXPECT_TRUE(characteristic1_->IsNotifying()); 2040 EXPECT_TRUE(characteristic1_->IsNotifying());
(...skipping 17 matching lines...) Expand all
1983 base::RunLoop().RunUntilIdle(); 2058 base::RunLoop().RunUntilIdle();
1984 ASSERT_EQ(2u, notify_sessions_.size()); 2059 ASSERT_EQ(2u, notify_sessions_.size());
1985 ASSERT_TRUE(notify_sessions_[0]); 2060 ASSERT_TRUE(notify_sessions_[0]);
1986 ASSERT_TRUE(notify_sessions_[1]); 2061 ASSERT_TRUE(notify_sessions_[1]);
1987 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 2062 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1988 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); 2063 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic());
1989 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 2064 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1990 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 2065 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1991 EXPECT_TRUE(characteristic1_->IsNotifying()); 2066 EXPECT_TRUE(characteristic1_->IsNotifying());
1992 } 2067 }
1993 #endif 2068 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1994 2069
1995 #if defined(OS_ANDROID) 2070 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1996 TEST_F(BluetoothRemoteGattCharacteristicTest, 2071 TEST_F(BluetoothRemoteGattCharacteristicTest,
1997 StopNotifySession_Reentrant_Stop_StartError) { 2072 StopNotifySession_Reentrant_Stop_StartError) {
2073 if (!PlatformSupportsLowEnergy()) {
2074 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2075 return;
2076 }
1998 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 2077 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1999 /* properties: NOTIFY */ 0x10, 2078 /* properties: NOTIFY */ 0x10,
2000 /* expected_config_descriptor_value: NOTIFY */ 1)); 2079 /* expected_config_descriptor_value: NOTIFY */ 1));
2001 2080
2002 // Check that the notify session is active. 2081 // Check that the notify session is active.
2003 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 2082 EXPECT_TRUE(notify_sessions_[0]->IsActive());
2004 EXPECT_EQ(characteristic1_->GetIdentifier(), 2083 EXPECT_EQ(characteristic1_->GetIdentifier(),
2005 notify_sessions_[0]->GetCharacteristicIdentifier()); 2084 notify_sessions_[0]->GetCharacteristicIdentifier());
2006 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 2085 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
2007 EXPECT_TRUE(characteristic1_->IsNotifying()); 2086 EXPECT_TRUE(characteristic1_->IsNotifying());
(...skipping 15 matching lines...) Expand all
2023 2102
2024 SimulateGattNotifySessionStartError( 2103 SimulateGattNotifySessionStartError(
2025 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 2104 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
2026 base::RunLoop().RunUntilIdle(); 2105 base::RunLoop().RunUntilIdle();
2027 ASSERT_EQ(1u, notify_sessions_.size()); 2106 ASSERT_EQ(1u, notify_sessions_.size());
2028 ASSERT_TRUE(notify_sessions_[0]); 2107 ASSERT_TRUE(notify_sessions_[0]);
2029 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 2108 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
2030 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 2109 EXPECT_FALSE(notify_sessions_[0]->IsActive());
2031 EXPECT_FALSE(characteristic1_->IsNotifying()); 2110 EXPECT_FALSE(characteristic1_->IsNotifying());
2032 } 2111 }
2033 #endif 2112 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
2034 2113
2035 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 2114 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
2036 // Tests Characteristic Value changes during a Notify Session. 2115 // Tests Characteristic Value changes during a Notify Session.
2037 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { 2116 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) {
2038 if (!PlatformSupportsLowEnergy()) { 2117 if (!PlatformSupportsLowEnergy()) {
2039 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 2118 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2040 return; 2119 return;
2041 } 2120 }
2042 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 2121 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
2043 /* properties: NOTIFY */ 0x10, 2122 /* properties: NOTIFY */ 0x10,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 2239 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
2161 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 2240 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
2162 2241
2163 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 2242 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
2164 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 2243 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
2165 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 2244 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
2166 } 2245 }
2167 #endif // defined(OS_ANDROID) || defined(OS_WIN) 2246 #endif // defined(OS_ANDROID) || defined(OS_WIN)
2168 2247
2169 } // namespace device 2248 } // 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