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

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

Issue 2634873002: Bluetooth: macOS: Implement BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications (Closed)
Patch Set: Fixing tests 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_WIN)
ortuno 2017/02/09 00:34:48 Enable this test as well.
jlebel 2017/02/09 01:20:18 Done.
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. 1016 // macOS: TODO(crbug.com/624017) Need to implement CCC descriptors.
1017 TEST_F(BluetoothRemoteGattCharacteristicTest, 1017 TEST_F(BluetoothRemoteGattCharacteristicTest,
1018 StartNotifySession_NoConfigDescriptor) { 1018 StartNotifySession_NoConfigDescriptor) {
1019 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1019 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1020 /* properties: NOTIFY */ 0x10, 1020 /* properties: NOTIFY */ 0x10,
1021 /* expected_config_descriptor_value: NOTIFY */ 1, 1021 /* expected_config_descriptor_value: NOTIFY */ 1,
1022 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); 1022 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING));
1023 1023
1024 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 1024 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1025 1025
1026 // The expected error callback is asynchronous: 1026 // The expected error callback is asynchronous:
1027 EXPECT_EQ(0, error_callback_count_); 1027 EXPECT_EQ(0, error_callback_count_);
1028 base::RunLoop().RunUntilIdle(); 1028 base::RunLoop().RunUntilIdle();
1029 EXPECT_EQ(1, error_callback_count_); 1029 EXPECT_EQ(1, error_callback_count_);
1030 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, 1030 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
1031 last_gatt_error_code_); 1031 last_gatt_error_code_);
1032 } 1032 }
1033 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1033 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1034 1034
1035 #if defined(OS_ANDROID) || defined(OS_WIN) 1035 #if defined(OS_ANDROID) || defined(OS_WIN)
ortuno 2017/02/09 00:34:48 Enable this test as well.
jlebel 2017/02/09 01:20:18 Done.
1036 // StartNotifySession fails if the characteristic has multiple Client 1036 // StartNotifySession fails if the characteristic has multiple Client
1037 // Characteristic Configuration descriptors. 1037 // Characteristic Configuration descriptors.
1038 // macOS: TODO(crbug.com/624017) Need to implement CCC descriptors. 1038 // macOS: TODO(crbug.com/624017) Need to implement CCC descriptors.
1039 TEST_F(BluetoothRemoteGattCharacteristicTest, 1039 TEST_F(BluetoothRemoteGattCharacteristicTest,
1040 StartNotifySession_MultipleConfigDescriptor) { 1040 StartNotifySession_MultipleConfigDescriptor) {
1041 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1041 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1042 /* properties: NOTIFY */ 0x10, 1042 /* properties: NOTIFY */ 0x10,
1043 /* expected_config_descriptor_value: NOTIFY */ 1, 1043 /* expected_config_descriptor_value: NOTIFY */ 1,
1044 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); 1044 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE));
1045 1045
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 if (!PlatformSupportsLowEnergy()) { 1148 if (!PlatformSupportsLowEnergy()) {
1149 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1149 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1150 return; 1150 return;
1151 } 1151 }
1152 ASSERT_NO_FATAL_FAILURE( 1152 ASSERT_NO_FATAL_FAILURE(
1153 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1153 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1154 SimulateGattDescriptor( 1154 SimulateGattDescriptor(
1155 characteristic1_, 1155 characteristic1_,
1156 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1156 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1157 .canonical_value()); 1157 .canonical_value());
1158 #if !defined(OS_MACOSX)
1159 // TODO(crbug.com/624017): Need implementation for descriptors.
1160 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1158 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1161 #endif // !defined(OS_MACOSX)
1162 1159
1163 characteristic1_->StartNotifySession( 1160 characteristic1_->StartNotifySession(
1164 GetNotifyCallback(Call::EXPECTED), 1161 GetNotifyCallback(Call::EXPECTED),
1165 GetGattErrorCallback(Call::NOT_EXPECTED)); 1162 GetGattErrorCallback(Call::NOT_EXPECTED));
1166 characteristic1_->StartNotifySession( 1163 characteristic1_->StartNotifySession(
1167 GetNotifyCallback(Call::EXPECTED), 1164 GetNotifyCallback(Call::EXPECTED),
1168 GetGattErrorCallback(Call::NOT_EXPECTED)); 1165 GetGattErrorCallback(Call::NOT_EXPECTED));
1169 EXPECT_EQ(0, callback_count_); 1166 EXPECT_EQ(0, callback_count_);
1170 SimulateGattNotifySessionStarted(characteristic1_); 1167 SimulateGattNotifySessionStarted(characteristic1_);
1171 base::RunLoop().RunUntilIdle(); 1168 base::RunLoop().RunUntilIdle();
(...skipping 19 matching lines...) Expand all
1191 if (!PlatformSupportsLowEnergy()) { 1188 if (!PlatformSupportsLowEnergy()) {
1192 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1189 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1193 return; 1190 return;
1194 } 1191 }
1195 ASSERT_NO_FATAL_FAILURE( 1192 ASSERT_NO_FATAL_FAILURE(
1196 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1193 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1197 SimulateGattDescriptor( 1194 SimulateGattDescriptor(
1198 characteristic1_, 1195 characteristic1_,
1199 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1196 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1200 .canonical_value()); 1197 .canonical_value());
1201 #if !defined(OS_MACOSX) 1198 #if !defined(OS_MACOSX)
ortuno 2017/02/09 00:34:48 You can remove this #if now.
jlebel 2017/02/09 01:20:18 Done.
1202 // TODO(crbug.com/624017): Need implementation for descriptors. 1199 // TODO(crbug.com/624017): Need implementation for descriptors.
1203 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1200 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1204 #endif // !defined(OS_MACOSX) 1201 #endif // !defined(OS_MACOSX)
1205 1202
1206 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 1203 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
1207 GetGattErrorCallback(Call::EXPECTED)); 1204 GetGattErrorCallback(Call::EXPECTED));
1208 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 1205 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
1209 GetGattErrorCallback(Call::EXPECTED)); 1206 GetGattErrorCallback(Call::EXPECTED));
1210 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1207 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1211 EXPECT_EQ(0, callback_count_); 1208 EXPECT_EQ(0, callback_count_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); 1242 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr);
1246 EXPECT_EQ(0, callback_count_); 1243 EXPECT_EQ(0, callback_count_);
1247 EXPECT_EQ(1, error_callback_count_); 1244 EXPECT_EQ(1, error_callback_count_);
1248 ASSERT_EQ(0u, notify_sessions_.size()); 1245 ASSERT_EQ(0u, notify_sessions_.size());
1249 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, 1246 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
1250 last_gatt_error_code_); 1247 last_gatt_error_code_);
1251 } 1248 }
1252 #endif // defined(OS_ANDROID) 1249 #endif // defined(OS_ANDROID)
1253 1250
1254 #if defined(OS_ANDROID) 1251 #if defined(OS_ANDROID)
1255 // Tests StartNotifySession completing before chrome objects are deleted. 1252 // Tests StartNotifySession completing before chrome objects are deleted.
ortuno 2017/02/09 00:34:48 Also enable this test.
jlebel 2017/02/09 01:20:17 Done.
1256 TEST_F(BluetoothRemoteGattCharacteristicTest, 1253 TEST_F(BluetoothRemoteGattCharacteristicTest,
1257 StartNotifySession_BeforeDeleted) { 1254 StartNotifySession_BeforeDeleted) {
1258 ASSERT_NO_FATAL_FAILURE( 1255 ASSERT_NO_FATAL_FAILURE(
1259 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1256 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1260 SimulateGattDescriptor( 1257 SimulateGattDescriptor(
1261 characteristic1_, 1258 characteristic1_,
1262 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1259 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1263 .canonical_value()); 1260 .canonical_value());
1264 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1261 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1265 1262
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 // Simulate reentrant StartNotifySession request from 1398 // Simulate reentrant StartNotifySession request from
1402 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. 1399 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback.
1403 SimulateGattNotifySessionStarted(characteristic1_); 1400 SimulateGattNotifySessionStarted(characteristic1_);
1404 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 1401 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1405 EXPECT_EQ(0, callback_count_); 1402 EXPECT_EQ(0, callback_count_);
1406 EXPECT_EQ(2, error_callback_count_); 1403 EXPECT_EQ(2, error_callback_count_);
1407 ASSERT_EQ(0u, notify_sessions_.size()); 1404 ASSERT_EQ(0u, notify_sessions_.size());
1408 } 1405 }
1409 #endif // defined(OS_WIN) 1406 #endif // defined(OS_WIN)
1410 1407
1411 #if defined(OS_ANDROID) 1408 #if defined(OS_ANDROID)
ortuno 2017/02/09 00:34:48 Also enable this one
jlebel 2017/02/09 01:20:18 I can't. Write is not implemented yet.
ortuno 2017/02/09 03:07:03 This is testing that: 1. We wrote the correct val
jlebel 2017/02/09 21:17:38 Done.
1412 // Tests StopNotifySession success on a characteristic that enabled Notify. 1409 // Tests StopNotifySession success on a characteristic that enabled Notify.
1413 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { 1410 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) {
1414 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1411 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1415 /* properties: NOTIFY */ 0x10, 1412 /* properties: NOTIFY */ 0x10,
1416 /* expected_config_descriptor_value: NOTIFY */ 1)); 1413 /* expected_config_descriptor_value: NOTIFY */ 1));
1417 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1414 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1418 1415
1419 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1416 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1420 SimulateGattNotifySessionStopped(characteristic1_); 1417 SimulateGattNotifySessionStopped(characteristic1_);
1421 base::RunLoop().RunUntilIdle(); 1418 base::RunLoop().RunUntilIdle();
1422 1419
1423 // Check that the right values were written to the descriptor. 1420 // Check that the right values were written to the descriptor.
1424 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1421 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
1425 ASSERT_EQ(2u, last_write_value_.size()); 1422 ASSERT_EQ(2u, last_write_value_.size());
1426 EXPECT_EQ(0, last_write_value_[0]); 1423 EXPECT_EQ(0, last_write_value_[0]);
1427 EXPECT_EQ(0, last_write_value_[1]); 1424 EXPECT_EQ(0, last_write_value_[1]);
1428 1425
1429 // Check that the notify session is inactive. 1426 // Check that the notify session is inactive.
1430 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1427 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1431 EXPECT_FALSE(characteristic1_->IsNotifying()); 1428 EXPECT_FALSE(characteristic1_->IsNotifying());
1432 } 1429 }
1433 #endif // defined(OS_ANDROID) 1430 #endif // defined(OS_ANDROID)
1434 1431
1435 #if defined(OS_ANDROID) 1432 #if defined(OS_ANDROID)
ortuno 2017/02/09 00:34:48 Also enable this test.
jlebel 2017/02/09 01:20:18 Same here.
ortuno 2017/02/09 03:07:03 Similarly here this tests that: 1. The correct va
jlebel 2017/02/09 21:17:38 Done.
1436 // Tests that deleted sessions are stopped. 1433 // Tests that deleted sessions are stopped.
1437 TEST_F(BluetoothRemoteGattCharacteristicTest, 1434 TEST_F(BluetoothRemoteGattCharacteristicTest,
1438 StopNotifySession_SessionDeleted) { 1435 StopNotifySession_SessionDeleted) {
1439 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1436 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1440 /* properties: NOTIFY */ 0x10, 1437 /* properties: NOTIFY */ 0x10,
1441 /* expected_config_descriptor_value: NOTIFY */ 1)); 1438 /* expected_config_descriptor_value: NOTIFY */ 1));
1442 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1439 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1443 1440
1444 notify_sessions_.clear(); 1441 notify_sessions_.clear();
1445 SimulateGattNotifySessionStopped(characteristic1_); 1442 SimulateGattNotifySessionStopped(characteristic1_);
1446 base::RunLoop().RunUntilIdle(); 1443 base::RunLoop().RunUntilIdle();
1447 1444
1448 // Check that the right values were written to the descriptor. 1445 // Check that the right values were written to the descriptor.
1449 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1446 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
1450 ASSERT_EQ(2u, last_write_value_.size()); 1447 ASSERT_EQ(2u, last_write_value_.size());
1451 EXPECT_EQ(0, last_write_value_[0]); 1448 EXPECT_EQ(0, last_write_value_[0]);
1452 EXPECT_EQ(0, last_write_value_[1]); 1449 EXPECT_EQ(0, last_write_value_[1]);
1453 1450
1454 // Check that the notify session is inactive. 1451 // Check that the notify session is inactive.
1455 EXPECT_FALSE(characteristic1_->IsNotifying()); 1452 EXPECT_FALSE(characteristic1_->IsNotifying());
1456 } 1453 }
1457 #endif // defined(OS_ANDROID) 1454 #endif // defined(OS_ANDROID)
1458 1455
1459 #if defined(OS_ANDROID) 1456 #if defined(OS_ANDROID)
ortuno 2017/02/09 00:34:48 You forgot to enable this test.
jlebel 2017/02/09 01:20:18 Done.
1460 // Tests that deleting the sessions before the stop callbacks have been 1457 // Tests that deleting the sessions before the stop callbacks have been
1461 // invoked does not cause problems. 1458 // invoked does not cause problems.
1462 TEST_F(BluetoothRemoteGattCharacteristicTest, 1459 TEST_F(BluetoothRemoteGattCharacteristicTest,
1463 StopNotifySession_SessionDeleted2) { 1460 StopNotifySession_SessionDeleted2) {
1464 ASSERT_NO_FATAL_FAILURE( 1461 ASSERT_NO_FATAL_FAILURE(
1465 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1462 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1466 1463
1467 #if !defined(OS_MACOSX) 1464 #if !defined(OS_MACOSX)
1468 // TODO(624017) enable for macosx 1465 // TODO(624017) enable for macosx
1469 SimulateGattDescriptor( 1466 SimulateGattDescriptor(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 base::RunLoop().RunUntilIdle(); 1503 base::RunLoop().RunUntilIdle();
1507 SimulateGattNotifySessionStopped(characteristic1_); 1504 SimulateGattNotifySessionStopped(characteristic1_);
1508 base::RunLoop().RunUntilIdle(); 1505 base::RunLoop().RunUntilIdle();
1509 1506
1510 // Check that the state is correct. 1507 // Check that the state is correct.
1511 EXPECT_TRUE("Did not crash!"); 1508 EXPECT_TRUE("Did not crash!");
1512 EXPECT_FALSE(characteristic1_->IsNotifying()); 1509 EXPECT_FALSE(characteristic1_->IsNotifying());
1513 } 1510 }
1514 #endif // defined(OS_ANDROID) 1511 #endif // defined(OS_ANDROID)
1515 1512
1516 #if defined(OS_ANDROID) 1513 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1517 // Tests that cancelling StopNotifySession works. 1514 // 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 1515 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is
1521 // implemented. 1516 // implemented.
1522 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { 1517 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) {
1518 if (!PlatformSupportsLowEnergy()) {
1519 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1520 return;
1521 }
1523 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1522 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1524 /* properties: NOTIFY */ 0x10, 1523 /* properties: NOTIFY */ 0x10,
1525 /* expected_config_descriptor_value: NOTIFY */ 1)); 1524 /* expected_config_descriptor_value: NOTIFY */ 1));
1526 1525
1527 // Check that the session is correctly setup. 1526 // Check that the session is correctly setup.
1528 std::string characteristic_identifier = characteristic1_->GetIdentifier(); 1527 std::string characteristic_identifier = characteristic1_->GetIdentifier();
1529 EXPECT_EQ(characteristic_identifier, 1528 EXPECT_EQ(characteristic_identifier,
1530 notify_sessions_[0]->GetCharacteristicIdentifier()); 1529 notify_sessions_[0]->GetCharacteristicIdentifier());
1531 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1530 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1532 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1531 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1533 1532
1534 // Queue a Stop request. 1533 // Queue a Stop request.
1535 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1534 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1536 1535
1537 // Cancel Stop by deleting the device before Stop finishes. 1536 // Cancel Stop by deleting the device before Stop finishes.
1538 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1537 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1539 } 1538 }
1540 #endif // defined(OS_ANDROID) 1539 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1541 1540
1542 #if defined(OS_ANDROID) 1541 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1543 // Tests that deleted sessions are stopped. 1542 // Tests that deleted sessions are stopped.
1544 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { 1543 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) {
1544 if (!PlatformSupportsLowEnergy()) {
1545 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1546 return;
1547 }
1545 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1548 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1546 /* properties: NOTIFY */ 0x10, 1549 /* properties: NOTIFY */ 0x10,
1547 /* expected_config_descriptor_value: NOTIFY */ 1)); 1550 /* expected_config_descriptor_value: NOTIFY */ 1));
1548 1551
1549 // Check that the session is correctly setup 1552 // Check that the session is correctly setup
1550 std::string characteristic_identifier = characteristic1_->GetIdentifier(); 1553 std::string characteristic_identifier = characteristic1_->GetIdentifier();
1551 EXPECT_EQ(characteristic_identifier, 1554 EXPECT_EQ(characteristic_identifier,
1552 notify_sessions_[0]->GetCharacteristicIdentifier()); 1555 notify_sessions_[0]->GetCharacteristicIdentifier());
1553 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1556 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1554 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1557 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1555 1558
1556 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1559 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1557 1560
1558 ResetEventCounts(); 1561 ResetEventCounts();
1559 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1562 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1560 1563
1561 // Check that the callback does not arrive synchronously. 1564 // Check that the callback does not arrive synchronously.
1562 EXPECT_EQ(0, callback_count_); 1565 EXPECT_EQ(0, callback_count_);
1563 1566
1564 // Trigger the stop callback 1567 // Trigger the stop callback
1565 base::RunLoop().RunUntilIdle(); 1568 base::RunLoop().RunUntilIdle();
1566 EXPECT_EQ(1, callback_count_); 1569 EXPECT_EQ(1, callback_count_);
1567 1570
1568 EXPECT_TRUE("Did not crash!"); 1571 EXPECT_TRUE("Did not crash!");
1569 ASSERT_TRUE(notify_sessions_[0]); 1572 ASSERT_TRUE(notify_sessions_[0]);
1570 EXPECT_EQ(characteristic_identifier, 1573 EXPECT_EQ(characteristic_identifier,
1571 notify_sessions_[0]->GetCharacteristicIdentifier()); 1574 notify_sessions_[0]->GetCharacteristicIdentifier());
1572 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1575 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1573 } 1576 }
1574 #endif // defined(OS_ANDROID) 1577 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1575 1578
1576 #if defined(OS_ANDROID) 1579 #if defined(OS_ANDROID)
ortuno 2017/02/09 00:34:48 Can you mention why this is not enabled on macOS?
jlebel 2017/02/09 01:20:18 Done.
1577 // Tests StopNotifySession success on a characteristic that enabled Indicate. 1580 // Tests StopNotifySession success on a characteristic that enabled Indicate.
1578 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { 1581 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) {
1579 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1582 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1580 /* properties: INDICATE */ 0x20, 1583 /* properties: INDICATE */ 0x20,
1581 /* expected_config_descriptor_value: INDICATE */ 2)); 1584 /* expected_config_descriptor_value: INDICATE */ 2));
1582 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1585 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1583 1586
1584 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1587 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1585 SimulateGattNotifySessionStopped(characteristic1_); 1588 SimulateGattNotifySessionStopped(characteristic1_);
1586 base::RunLoop().RunUntilIdle(); 1589 base::RunLoop().RunUntilIdle();
1587 1590
1588 // Check that the right values were written to the descriptor. 1591 // Check that the right values were written to the descriptor.
1589 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1592 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
1590 ASSERT_EQ(2u, last_write_value_.size()); 1593 ASSERT_EQ(2u, last_write_value_.size());
1591 EXPECT_EQ(0, last_write_value_[0]); 1594 EXPECT_EQ(0, last_write_value_[0]);
1592 EXPECT_EQ(0, last_write_value_[1]); 1595 EXPECT_EQ(0, last_write_value_[1]);
1593 1596
1594 // Check that the notify session is inactive. 1597 // Check that the notify session is inactive.
1595 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1598 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1596 EXPECT_FALSE(characteristic1_->IsNotifying()); 1599 EXPECT_FALSE(characteristic1_->IsNotifying());
1597 } 1600 }
1598 #endif // defined(OS_ANDROID) 1601 #endif // defined(OS_ANDROID)
1599 1602
1600 #if defined(OS_ANDROID) 1603 #if defined(OS_ANDROID)
1601 // Tests StopNotifySession success on a characteristic that enabled Notify & 1604 // Tests StopNotifySession success on a characteristic that enabled Notify &
ortuno 2017/02/09 00:34:48 Can you mention why this is not enabled on macOS?
jlebel 2017/02/09 01:20:18 Done.
1602 // Indicate. 1605 // Indicate.
1603 TEST_F(BluetoothRemoteGattCharacteristicTest, 1606 TEST_F(BluetoothRemoteGattCharacteristicTest,
1604 StopNotifySession_OnNotifyAndIndicate) { 1607 StopNotifySession_OnNotifyAndIndicate) {
1605 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1608 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1606 /* properties: NOTIFY and INDICATE bits set */ 0x30, 1609 /* properties: NOTIFY and INDICATE bits set */ 0x30,
1607 /* expected_config_descriptor_value: INDICATE */ 1)); 1610 /* expected_config_descriptor_value: INDICATE */ 1));
1608 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 1611 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
1609 1612
1610 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1613 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1611 SimulateGattNotifySessionStopped(characteristic1_); 1614 SimulateGattNotifySessionStopped(characteristic1_);
1612 base::RunLoop().RunUntilIdle(); 1615 base::RunLoop().RunUntilIdle();
1613 1616
1614 // Check that the right values were written to the descriptor. 1617 // Check that the right values were written to the descriptor.
1615 EXPECT_EQ(2, gatt_write_descriptor_attempts_); 1618 EXPECT_EQ(2, gatt_write_descriptor_attempts_);
1616 ASSERT_EQ(2u, last_write_value_.size()); 1619 ASSERT_EQ(2u, last_write_value_.size());
1617 EXPECT_EQ(0, last_write_value_[0]); 1620 EXPECT_EQ(0, last_write_value_[0]);
1618 EXPECT_EQ(0, last_write_value_[1]); 1621 EXPECT_EQ(0, last_write_value_[1]);
1619 1622
1620 // Check that the notify session is inactive. 1623 // Check that the notify session is inactive.
1621 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1624 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1622 EXPECT_FALSE(characteristic1_->IsNotifying()); 1625 EXPECT_FALSE(characteristic1_->IsNotifying());
1623 } 1626 }
1624 #endif // defined(OS_ANDROID) 1627 #endif // defined(OS_ANDROID)
1625 1628
1626 #if defined(OS_ANDROID) 1629 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1627 // Tests StopNotifySession error 1630 // Tests StopNotifySession error
1628 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { 1631 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) {
1632 if (!PlatformSupportsLowEnergy()) {
1633 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1634 return;
1635 }
1629 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1636 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1630 /* properties: NOTIFY */ 0x10, 1637 /* properties: NOTIFY */ 0x10,
1631 /* expected_config_descriptor_value: NOTIFY */ 1)); 1638 /* expected_config_descriptor_value: NOTIFY */ 1));
1632 1639
1633 // Check that the notify session is active. 1640 // Check that the notify session is active.
1634 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1641 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1635 EXPECT_EQ(characteristic1_->GetIdentifier(), 1642 EXPECT_EQ(characteristic1_->GetIdentifier(),
1636 notify_sessions_[0]->GetCharacteristicIdentifier()); 1643 notify_sessions_[0]->GetCharacteristicIdentifier());
1637 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1644 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1638 EXPECT_TRUE(characteristic1_->IsNotifying()); 1645 EXPECT_TRUE(characteristic1_->IsNotifying());
1639 1646
1640 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); 1647 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
1641 SimulateGattNotifySessionStopError( 1648 SimulateGattNotifySessionStopError(
1642 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); 1649 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN);
1643 base::RunLoop().RunUntilIdle(); 1650 base::RunLoop().RunUntilIdle();
1644 1651
1645 // Check that the notify session is inactive. 1652 // Check that the notify session is inactive.
1646 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1653 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1647 EXPECT_FALSE(characteristic1_->IsNotifying()); 1654 EXPECT_FALSE(characteristic1_->IsNotifying());
1648 } 1655 }
1649 #endif // defined(OS_ANDROID) 1656 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1650 1657
1651 #if defined(OS_ANDROID) 1658 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1652 // Tests multiple StopNotifySession calls for a single session. 1659 // Tests multiple StopNotifySession calls for a single session.
1653 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) { 1660 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple1) {
1661 if (!PlatformSupportsLowEnergy()) {
1662 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1663 return;
1664 }
1654 ASSERT_NO_FATAL_FAILURE( 1665 ASSERT_NO_FATAL_FAILURE(
1655 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1666 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1656 1667
1657 #if !defined(OS_MACOSX)
1658 // TODO(624017) enable for macosx
1659 SimulateGattDescriptor( 1668 SimulateGattDescriptor(
1660 characteristic1_, 1669 characteristic1_,
1661 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1670 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1662 .canonical_value()); 1671 .canonical_value());
1663 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1672 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1664 #endif
1665 1673
1666 // Start notify session 1674 // Start notify session
1667 characteristic1_->StartNotifySession( 1675 characteristic1_->StartNotifySession(
1668 GetNotifyCallback(Call::EXPECTED), 1676 GetNotifyCallback(Call::EXPECTED),
1669 GetGattErrorCallback(Call::NOT_EXPECTED)); 1677 GetGattErrorCallback(Call::NOT_EXPECTED));
1670 EXPECT_EQ(0, callback_count_); 1678 EXPECT_EQ(0, callback_count_);
1671 SimulateGattNotifySessionStarted(characteristic1_); 1679 SimulateGattNotifySessionStarted(characteristic1_);
1672 base::RunLoop().RunUntilIdle(); 1680 base::RunLoop().RunUntilIdle();
1673 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1681 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1674 EXPECT_EQ(1, callback_count_); 1682 EXPECT_EQ(1, callback_count_);
1675 EXPECT_EQ(0, error_callback_count_); 1683 EXPECT_EQ(0, error_callback_count_);
1676 ASSERT_EQ(1u, notify_sessions_.size()); 1684 ASSERT_EQ(1u, notify_sessions_.size());
1677 ASSERT_TRUE(notify_sessions_[0]); 1685 ASSERT_TRUE(notify_sessions_[0]);
1678 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1686 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1679 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1687 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1680 EXPECT_TRUE(characteristic1_->IsNotifying()); 1688 EXPECT_TRUE(characteristic1_->IsNotifying());
1681 1689
1682 // Stop the notify session twice 1690 // Stop the notify session twice
1683 ResetEventCounts(); 1691 ResetEventCounts();
1684 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(0)); 1692 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(0));
1685 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); 1693 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1));
1686 SimulateGattNotifySessionStopped(characteristic1_); 1694 SimulateGattNotifySessionStopped(characteristic1_);
1687 base::RunLoop().RunUntilIdle(); 1695 base::RunLoop().RunUntilIdle();
1688 1696
1689 // Check that the notify session is inactive. 1697 // Check that the notify session is inactive.
1690 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1698 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1691 EXPECT_FALSE(characteristic1_->IsNotifying()); 1699 EXPECT_FALSE(characteristic1_->IsNotifying());
1692 } 1700 }
1693 #endif // defined(OS_ANDROID) 1701 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1694 1702
1695 #if defined(OS_ANDROID) 1703 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1696 // Tests multiple StartNotifySession calls and multiple StopNotifySession calls. 1704 // Tests multiple StartNotifySession calls and multiple StopNotifySession calls.
1697 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) { 1705 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Multiple2) {
1706 if (!PlatformSupportsLowEnergy()) {
1707 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1708 return;
1709 }
1698 ASSERT_NO_FATAL_FAILURE( 1710 ASSERT_NO_FATAL_FAILURE(
1699 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1711 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1700 1712
1701 #if !defined(OS_MACOSX)
1702 // TODO(624017) enable for macosx 1713 // TODO(624017) enable for macosx
ortuno 2017/02/09 00:34:48 nit: remove the TODO.
jlebel 2017/02/09 01:20:18 Done.
1703 SimulateGattDescriptor( 1714 SimulateGattDescriptor(
1704 characteristic1_, 1715 characteristic1_,
1705 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1716 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1706 .canonical_value()); 1717 .canonical_value());
1707 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1718 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1708 #endif
1709 1719
1710 // Start notify sessions 1720 // Start notify sessions
1711 characteristic1_->StartNotifySession( 1721 characteristic1_->StartNotifySession(
1712 GetNotifyCheckForPrecedingCalls(0), 1722 GetNotifyCheckForPrecedingCalls(0),
1713 GetGattErrorCallback(Call::NOT_EXPECTED)); 1723 GetGattErrorCallback(Call::NOT_EXPECTED));
1714 characteristic1_->StartNotifySession( 1724 characteristic1_->StartNotifySession(
1715 GetNotifyCheckForPrecedingCalls(1), 1725 GetNotifyCheckForPrecedingCalls(1),
1716 GetGattErrorCallback(Call::NOT_EXPECTED)); 1726 GetGattErrorCallback(Call::NOT_EXPECTED));
1717 EXPECT_EQ(0, callback_count_); 1727 EXPECT_EQ(0, callback_count_);
1718 SimulateGattNotifySessionStarted(characteristic1_); 1728 SimulateGattNotifySessionStarted(characteristic1_);
(...skipping 19 matching lines...) Expand all
1738 1748
1739 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(3)); 1749 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(3));
1740 SimulateGattNotifySessionStopped(characteristic1_); 1750 SimulateGattNotifySessionStopped(characteristic1_);
1741 base::RunLoop().RunUntilIdle(); 1751 base::RunLoop().RunUntilIdle();
1742 1752
1743 // Check that the notify sessions is inactive. 1753 // Check that the notify sessions is inactive.
1744 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1754 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1745 EXPECT_FALSE(notify_sessions_[1]->IsActive()); 1755 EXPECT_FALSE(notify_sessions_[1]->IsActive());
1746 EXPECT_FALSE(characteristic1_->IsNotifying()); 1756 EXPECT_FALSE(characteristic1_->IsNotifying());
1747 } 1757 }
1748 #endif // defined(OS_ANDROID) 1758 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1749 1759
1750 #if defined(OS_ANDROID) 1760 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1751 // Tests starting a new notify session before the previous stop request 1761 // Tests starting a new notify session before the previous stop request
1752 // resolves. 1762 // resolves.
1753 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) { 1763 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStart) {
1764 if (!PlatformSupportsLowEnergy()) {
1765 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1766 return;
1767 }
1754 ASSERT_NO_FATAL_FAILURE( 1768 ASSERT_NO_FATAL_FAILURE(
1755 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1769 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1756 SimulateGattDescriptor( 1770 SimulateGattDescriptor(
1757 characteristic1_, 1771 characteristic1_,
1758 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1772 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1759 .canonical_value()); 1773 .canonical_value());
1760 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1774 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1761 1775
1762 // Start notify session 1776 // Start notify session
1763 ResetEventCounts(); 1777 ResetEventCounts();
(...skipping 20 matching lines...) Expand all
1784 1798
1785 SimulateGattNotifySessionStarted(characteristic1_); 1799 SimulateGattNotifySessionStarted(characteristic1_);
1786 base::RunLoop().RunUntilIdle(); 1800 base::RunLoop().RunUntilIdle();
1787 ASSERT_EQ(2u, notify_sessions_.size()); 1801 ASSERT_EQ(2u, notify_sessions_.size());
1788 ASSERT_TRUE(notify_sessions_[0]); 1802 ASSERT_TRUE(notify_sessions_[0]);
1789 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1803 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1790 ASSERT_TRUE(notify_sessions_[1]); 1804 ASSERT_TRUE(notify_sessions_[1]);
1791 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 1805 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1792 EXPECT_TRUE(characteristic1_->IsNotifying()); 1806 EXPECT_TRUE(characteristic1_->IsNotifying());
1793 } 1807 }
1794 #endif // defined(OS_ANDROID) 1808 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1795 1809
1796 #if defined(OS_ANDROID) 1810 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1797 TEST_F(BluetoothRemoteGattCharacteristicTest, 1811 TEST_F(BluetoothRemoteGattCharacteristicTest,
1798 StopNotifySession_StartStopStart) { 1812 StopNotifySession_StartStopStart) {
1813 if (!PlatformSupportsLowEnergy()) {
1814 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1815 return;
1816 }
1799 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1817 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1800 /* properties: NOTIFY */ 0x10, 1818 /* properties: NOTIFY */ 0x10,
1801 /* expected_config_descriptor_value: NOTIFY */ 1)); 1819 /* expected_config_descriptor_value: NOTIFY */ 1));
1802 1820
1803 // Check that the initial notify session is active. 1821 // Check that the initial notify session is active.
1804 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1822 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1805 EXPECT_EQ(characteristic1_->GetIdentifier(), 1823 EXPECT_EQ(characteristic1_->GetIdentifier(),
1806 notify_sessions_[0]->GetCharacteristicIdentifier()); 1824 notify_sessions_[0]->GetCharacteristicIdentifier());
1807 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1825 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1808 EXPECT_TRUE(characteristic1_->IsNotifying()); 1826 EXPECT_TRUE(characteristic1_->IsNotifying());
(...skipping 27 matching lines...) Expand all
1836 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); 1854 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic());
1837 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 1855 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1838 1856
1839 EXPECT_EQ(characteristic1_->GetIdentifier(), 1857 EXPECT_EQ(characteristic1_->GetIdentifier(),
1840 notify_sessions_[2]->GetCharacteristicIdentifier()); 1858 notify_sessions_[2]->GetCharacteristicIdentifier());
1841 EXPECT_EQ(characteristic1_, notify_sessions_[2]->GetCharacteristic()); 1859 EXPECT_EQ(characteristic1_, notify_sessions_[2]->GetCharacteristic());
1842 EXPECT_TRUE(notify_sessions_[2]->IsActive()); 1860 EXPECT_TRUE(notify_sessions_[2]->IsActive());
1843 1861
1844 EXPECT_TRUE(characteristic1_->IsNotifying()); 1862 EXPECT_TRUE(characteristic1_->IsNotifying());
1845 } 1863 }
1846 #endif 1864 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1847 1865
1848 #if defined(OS_ANDROID) 1866 #if defined(OS_ANDROID)
ortuno 2017/02/09 00:34:48 You are missing this one.
jlebel 2017/02/09 01:20:18 Write is still missing
ortuno 2017/02/09 03:07:03 Same here. Surround the part that checks for the d
jlebel 2017/02/09 21:17:38 Done.
1849 // Tests starting a new notify session before the previous stop requests 1867 // Tests starting a new notify session before the previous stop requests
1850 // resolve. 1868 // resolve.
1851 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) { 1869 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_StopStopStart) {
1852 ASSERT_NO_FATAL_FAILURE( 1870 ASSERT_NO_FATAL_FAILURE(
1853 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1871 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1854 SimulateGattDescriptor( 1872 SimulateGattDescriptor(
1855 characteristic1_, 1873 characteristic1_,
1856 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1874 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1857 .canonical_value()); 1875 .canonical_value());
1858 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1876 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 // Check the notify state 1921 // Check the notify state
1904 ASSERT_EQ(2u, notify_sessions_.size()); 1922 ASSERT_EQ(2u, notify_sessions_.size());
1905 ASSERT_TRUE(notify_sessions_[0]); 1923 ASSERT_TRUE(notify_sessions_[0]);
1906 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1924 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1907 ASSERT_TRUE(notify_sessions_[1]); 1925 ASSERT_TRUE(notify_sessions_[1]);
1908 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 1926 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1909 EXPECT_TRUE(characteristic1_->IsNotifying()); 1927 EXPECT_TRUE(characteristic1_->IsNotifying());
1910 } 1928 }
1911 #endif // defined(OS_ANDROID) 1929 #endif // defined(OS_ANDROID)
1912 1930
1913 #if defined(OS_ANDROID) 1931 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1914 TEST_F(BluetoothRemoteGattCharacteristicTest, 1932 TEST_F(BluetoothRemoteGattCharacteristicTest,
1915 StopNotifySession_Reentrant_Success_Stop) { 1933 StopNotifySession_Reentrant_Success_Stop) {
1934 if (!PlatformSupportsLowEnergy()) {
1935 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1936 return;
1937 }
1916 ASSERT_NO_FATAL_FAILURE( 1938 ASSERT_NO_FATAL_FAILURE(
1917 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1939 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1918 SimulateGattDescriptor( 1940 SimulateGattDescriptor(
1919 characteristic1_, 1941 characteristic1_,
1920 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1942 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1921 .canonical_value()); 1943 .canonical_value());
1922 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1944 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1923 1945
1924 // Start notify session 1946 // Start notify session
1925 characteristic1_->StartNotifySession( 1947 characteristic1_->StartNotifySession(
(...skipping 15 matching lines...) Expand all
1941 ASSERT_EQ(1u, notify_sessions_.size()); 1963 ASSERT_EQ(1u, notify_sessions_.size());
1942 ASSERT_TRUE(notify_sessions_[0]); 1964 ASSERT_TRUE(notify_sessions_[0]);
1943 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1965 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1944 EXPECT_TRUE(characteristic1_->IsNotifying()); 1966 EXPECT_TRUE(characteristic1_->IsNotifying());
1945 1967
1946 SimulateGattNotifySessionStopped(characteristic1_); 1968 SimulateGattNotifySessionStopped(characteristic1_);
1947 base::RunLoop().RunUntilIdle(); 1969 base::RunLoop().RunUntilIdle();
1948 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 1970 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1949 EXPECT_FALSE(characteristic1_->IsNotifying()); 1971 EXPECT_FALSE(characteristic1_->IsNotifying());
1950 } 1972 }
1951 #endif 1973 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1952 1974
1953 #if defined(OS_ANDROID) 1975 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1954 TEST_F(BluetoothRemoteGattCharacteristicTest, 1976 TEST_F(BluetoothRemoteGattCharacteristicTest,
1955 StopNotifySession_Reentrant_Stop_StartSuccess) { 1977 StopNotifySession_Reentrant_Stop_StartSuccess) {
1978 if (!PlatformSupportsLowEnergy()) {
1979 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1980 return;
1981 }
1956 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1982 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1957 /* properties: NOTIFY */ 0x10, 1983 /* properties: NOTIFY */ 0x10,
1958 /* expected_config_descriptor_value: NOTIFY */ 1)); 1984 /* expected_config_descriptor_value: NOTIFY */ 1));
1959 1985
1960 // Check that the notify session is active. 1986 // Check that the notify session is active.
1961 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1987 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1962 EXPECT_EQ(characteristic1_->GetIdentifier(), 1988 EXPECT_EQ(characteristic1_->GetIdentifier(),
1963 notify_sessions_[0]->GetCharacteristicIdentifier()); 1989 notify_sessions_[0]->GetCharacteristicIdentifier());
1964 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 1990 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1965 EXPECT_TRUE(characteristic1_->IsNotifying()); 1991 EXPECT_TRUE(characteristic1_->IsNotifying());
(...skipping 17 matching lines...) Expand all
1983 base::RunLoop().RunUntilIdle(); 2009 base::RunLoop().RunUntilIdle();
1984 ASSERT_EQ(2u, notify_sessions_.size()); 2010 ASSERT_EQ(2u, notify_sessions_.size());
1985 ASSERT_TRUE(notify_sessions_[0]); 2011 ASSERT_TRUE(notify_sessions_[0]);
1986 ASSERT_TRUE(notify_sessions_[1]); 2012 ASSERT_TRUE(notify_sessions_[1]);
1987 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 2013 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
1988 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); 2014 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic());
1989 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 2015 EXPECT_FALSE(notify_sessions_[0]->IsActive());
1990 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 2016 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1991 EXPECT_TRUE(characteristic1_->IsNotifying()); 2017 EXPECT_TRUE(characteristic1_->IsNotifying());
1992 } 2018 }
1993 #endif 2019 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1994 2020
1995 #if defined(OS_ANDROID) 2021 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1996 TEST_F(BluetoothRemoteGattCharacteristicTest, 2022 TEST_F(BluetoothRemoteGattCharacteristicTest,
1997 StopNotifySession_Reentrant_Stop_StartError) { 2023 StopNotifySession_Reentrant_Stop_StartError) {
2024 if (!PlatformSupportsLowEnergy()) {
2025 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2026 return;
2027 }
1998 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 2028 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1999 /* properties: NOTIFY */ 0x10, 2029 /* properties: NOTIFY */ 0x10,
2000 /* expected_config_descriptor_value: NOTIFY */ 1)); 2030 /* expected_config_descriptor_value: NOTIFY */ 1));
2001 2031
2002 // Check that the notify session is active. 2032 // Check that the notify session is active.
2003 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 2033 EXPECT_TRUE(notify_sessions_[0]->IsActive());
2004 EXPECT_EQ(characteristic1_->GetIdentifier(), 2034 EXPECT_EQ(characteristic1_->GetIdentifier(),
2005 notify_sessions_[0]->GetCharacteristicIdentifier()); 2035 notify_sessions_[0]->GetCharacteristicIdentifier());
2006 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 2036 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
2007 EXPECT_TRUE(characteristic1_->IsNotifying()); 2037 EXPECT_TRUE(characteristic1_->IsNotifying());
(...skipping 15 matching lines...) Expand all
2023 2053
2024 SimulateGattNotifySessionStartError( 2054 SimulateGattNotifySessionStartError(
2025 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 2055 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
2026 base::RunLoop().RunUntilIdle(); 2056 base::RunLoop().RunUntilIdle();
2027 ASSERT_EQ(1u, notify_sessions_.size()); 2057 ASSERT_EQ(1u, notify_sessions_.size());
2028 ASSERT_TRUE(notify_sessions_[0]); 2058 ASSERT_TRUE(notify_sessions_[0]);
2029 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); 2059 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic());
2030 EXPECT_FALSE(notify_sessions_[0]->IsActive()); 2060 EXPECT_FALSE(notify_sessions_[0]->IsActive());
2031 EXPECT_FALSE(characteristic1_->IsNotifying()); 2061 EXPECT_FALSE(characteristic1_->IsNotifying());
2032 } 2062 }
2033 #endif 2063 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
2034 2064
2035 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 2065 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
2036 // Tests Characteristic Value changes during a Notify Session. 2066 // Tests Characteristic Value changes during a Notify Session.
2037 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { 2067 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) {
2038 if (!PlatformSupportsLowEnergy()) { 2068 if (!PlatformSupportsLowEnergy()) {
2039 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 2069 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2040 return; 2070 return;
2041 } 2071 }
2042 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 2072 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
2043 /* properties: NOTIFY */ 0x10, 2073 /* properties: NOTIFY */ 0x10,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 2190 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
2161 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 2191 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
2162 2192
2163 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 2193 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
2164 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 2194 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
2165 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 2195 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
2166 } 2196 }
2167 #endif // defined(OS_ANDROID) || defined(OS_WIN) 2197 #endif // defined(OS_ANDROID) || defined(OS_WIN)
2168 2198
2169 } // namespace device 2199 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698