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

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

Issue 2094633003: Bluetooth: Mac: implementation for start notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@write_read_characteristicscan_servicescan_cleanup
Patch Set: Tests working Created 4 years, 5 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 .canonical_value()); 79 .canonical_value());
80 expected_descriptors_count++; 80 expected_descriptors_count++;
81 } 81 }
82 if (error == StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE) { 82 if (error == StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE) {
83 SimulateGattDescriptor( 83 SimulateGattDescriptor(
84 characteristic1_, 84 characteristic1_,
85 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 85 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
86 .canonical_value()); 86 .canonical_value());
87 expected_descriptors_count++; 87 expected_descriptors_count++;
88 } 88 }
89 #if !defined(OS_MACOSX)
ortuno 2016/06/28 16:24:50 Move this right before expected_descriptors_count
jlebel 2016/06/28 18:09:52 Done.
90 // TODO(jlebel) Need to implement descriptors.
ortuno 2016/06/28 16:24:50 I don't think we need the TODO as we don't need to
jlebel 2016/06/28 18:09:53 Done.
89 ASSERT_EQ(expected_descriptors_count, 91 ASSERT_EQ(expected_descriptors_count,
90 characteristic1_->GetDescriptors().size()); 92 characteristic1_->GetDescriptors().size());
93 #endif // !defined(OS_MACOSX)
91 94
92 if (error == StartNotifySetupError::SET_NOTIFY) { 95 if (error == StartNotifySetupError::SET_NOTIFY) {
93 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( 96 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
94 characteristic1_); 97 characteristic1_);
95 } 98 }
96 99
97 if (error == StartNotifySetupError::WRITE_DESCRIPTOR) { 100 if (error == StartNotifySetupError::WRITE_DESCRIPTOR) {
98 SimulateGattDescriptorWriteWillFailSynchronouslyOnce( 101 SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
99 characteristic1_->GetDescriptors()[0]); 102 characteristic1_->GetDescriptors()[0]);
100 } 103 }
(...skipping 14 matching lines...) Expand all
115 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 118 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
116 EXPECT_EQ(1, callback_count_); 119 EXPECT_EQ(1, callback_count_);
117 EXPECT_EQ(0, error_callback_count_); 120 EXPECT_EQ(0, error_callback_count_);
118 ASSERT_EQ(1u, notify_sessions_.size()); 121 ASSERT_EQ(1u, notify_sessions_.size());
119 ASSERT_TRUE(notify_sessions_[0]); 122 ASSERT_TRUE(notify_sessions_[0]);
120 EXPECT_EQ(characteristic1_->GetIdentifier(), 123 EXPECT_EQ(characteristic1_->GetIdentifier(),
121 notify_sessions_[0]->GetCharacteristicIdentifier()); 124 notify_sessions_[0]->GetCharacteristicIdentifier());
122 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 125 EXPECT_TRUE(notify_sessions_[0]->IsActive());
123 126
124 // Verify the Client Characteristic Configuration descriptor was written to. 127 // Verify the Client Characteristic Configuration descriptor was written to.
128 #if !defined(OS_MACOSX)
129 // TODO(jlebel) Need to implement descriptors.
ortuno 2016/06/28 16:24:50 No need for the TODO. Change to match the same com
jlebel 2016/06/28 18:09:53 Done.
125 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 130 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
126 EXPECT_EQ(2u, last_write_value_.size()); 131 EXPECT_EQ(2u, last_write_value_.size());
127 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF; 132 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF;
128 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF; 133 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF;
129 EXPECT_EQ(expected_byte0, last_write_value_[0]); 134 EXPECT_EQ(expected_byte0, last_write_value_[0]);
130 EXPECT_EQ(expected_byte1, last_write_value_[1]); 135 EXPECT_EQ(expected_byte1, last_write_value_[1]);
136 #endif // !defined(OS_MACOSX)
131 } 137 }
132 138
133 BluetoothDevice* device_ = nullptr; 139 BluetoothDevice* device_ = nullptr;
134 BluetoothRemoteGattService* service_ = nullptr; 140 BluetoothRemoteGattService* service_ = nullptr;
135 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr; 141 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr;
136 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr; 142 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr;
137 }; 143 };
138 #endif 144 #endif
139 145
140 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 146 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 342
337 // Duplicate write reported from OS shouldn't cause a problem: 343 // Duplicate write reported from OS shouldn't cause a problem:
338 SimulateGattCharacteristicWrite(characteristic1_); 344 SimulateGattCharacteristicWrite(characteristic1_);
339 345
340 EXPECT_EQ(empty_vector, last_write_value_); 346 EXPECT_EQ(empty_vector, last_write_value_);
341 } 347 }
342 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 348 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
343 349
344 #if defined(OS_ANDROID) || defined(OS_WIN) 350 #if defined(OS_ANDROID) || defined(OS_WIN)
345 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. 351 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted.
346 // This test is not relevant for macOS. This can never happen if CBPeripheral 352 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API.
ortuno 2016/06/28 16:24:50 I think you meant to use the comment on the follow
jlebel 2016/06/28 18:09:53 Done.
347 // delegate is set to nil.
348 TEST_F(BluetoothRemoteGattCharacteristicTest, 353 TEST_F(BluetoothRemoteGattCharacteristicTest,
349 ReadRemoteCharacteristic_AfterDeleted) { 354 ReadRemoteCharacteristic_AfterDeleted) {
350 if (!PlatformSupportsLowEnergy()) { 355 if (!PlatformSupportsLowEnergy()) {
351 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 356 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
352 return; 357 return;
353 } 358 }
354 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 359 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
355 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 360 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
356 361
357 characteristic1_->ReadRemoteCharacteristic( 362 characteristic1_->ReadRemoteCharacteristic(
358 GetReadValueCallback(Call::NOT_EXPECTED), 363 GetReadValueCallback(Call::NOT_EXPECTED),
359 GetGattErrorCallback(Call::NOT_EXPECTED)); 364 GetGattErrorCallback(Call::NOT_EXPECTED));
360 365
361 RememberCharacteristicForSubsequentAction(characteristic1_); 366 RememberCharacteristicForSubsequentAction(characteristic1_);
362 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 367 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
363 368
364 std::vector<uint8_t> empty_vector; 369 std::vector<uint8_t> empty_vector;
365 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, 370 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr,
366 empty_vector); 371 empty_vector);
367 EXPECT_TRUE("Did not crash!"); 372 EXPECT_TRUE("Did not crash!");
368 } 373 }
369 #endif // defined(OS_ANDROID) || defined(OS_WIN) 374 #endif // defined(OS_ANDROID) || defined(OS_WIN)
370 375
371 #if defined(OS_ANDROID) || defined(OS_WIN) 376 #if defined(OS_ANDROID) || defined(OS_WIN)
372 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. 377 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted.
373 // This test is not relevant for macOS. This can never happen if CBPeripheral 378 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set
374 // delegate is set to nil. 379 // to nil.
375 TEST_F(BluetoothRemoteGattCharacteristicTest, 380 TEST_F(BluetoothRemoteGattCharacteristicTest,
376 WriteRemoteCharacteristic_AfterDeleted) { 381 WriteRemoteCharacteristic_AfterDeleted) {
377 if (!PlatformSupportsLowEnergy()) { 382 if (!PlatformSupportsLowEnergy()) {
378 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 383 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
379 return; 384 return;
380 } 385 }
381 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 386 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
382 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 387 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
383 388
384 std::vector<uint8_t> empty_vector; 389 std::vector<uint8_t> empty_vector;
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 last_gatt_error_code_); 893 last_gatt_error_code_);
889 894
890 // Initial read should still succeed: 895 // Initial read should still succeed:
891 ResetEventCounts(); 896 ResetEventCounts();
892 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 897 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
893 EXPECT_EQ(1, callback_count_); 898 EXPECT_EQ(1, callback_count_);
894 EXPECT_EQ(0, error_callback_count_); 899 EXPECT_EQ(0, error_callback_count_);
895 } 900 }
896 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 901 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
897 902
898 #if defined(OS_ANDROID) || defined(OS_WIN) 903 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
899 // StartNotifySession fails if characteristic doesn't have Notify or Indicate 904 // StartNotifySession fails if characteristic doesn't have Notify or Indicate
900 // property. 905 // property.
901 TEST_F(BluetoothRemoteGattCharacteristicTest, 906 TEST_F(BluetoothRemoteGattCharacteristicTest,
902 StartNotifySession_NoNotifyOrIndicate) { 907 StartNotifySession_NoNotifyOrIndicate) {
903 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 908 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
904 /* properties: NOTIFY */ 0x10, 909 /* properties: NOTIFY */ 0x10,
905 /* expected_config_descriptor_value: NOTIFY */ 1, 910 /* expected_config_descriptor_value: NOTIFY */ 1,
906 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); 911 StartNotifySetupError::CHARACTERISTIC_PROPERTIES));
907 912
908 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 913 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
909 914
910 // The expected error callback is asynchronous: 915 // The expected error callback is asynchronous:
911 EXPECT_EQ(0, error_callback_count_); 916 EXPECT_EQ(0, error_callback_count_);
912 base::RunLoop().RunUntilIdle(); 917 base::RunLoop().RunUntilIdle();
913 EXPECT_EQ(1, error_callback_count_); 918 EXPECT_EQ(1, error_callback_count_);
914 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, 919 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
915 last_gatt_error_code_); 920 last_gatt_error_code_);
916 } 921 }
917 #endif // defined(OS_ANDROID) || defined(OS_WIN) 922 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
918 923
919 #if defined(OS_ANDROID) || defined(OS_WIN) 924 #if defined(OS_ANDROID) || defined(OS_WIN)
920 // StartNotifySession fails if the characteristic is missing the Client 925 // StartNotifySession fails if the characteristic is missing the Client
921 // Characteristic Configuration descriptor. 926 // Characteristic Configuration descriptor.
ortuno 2016/06/28 16:24:50 Add a TODO to enable this test on macOS if we get
jlebel 2016/06/28 18:09:53 Done.
922 TEST_F(BluetoothRemoteGattCharacteristicTest, 927 TEST_F(BluetoothRemoteGattCharacteristicTest,
923 StartNotifySession_NoConfigDescriptor) { 928 StartNotifySession_NoConfigDescriptor) {
924 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 929 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
925 /* properties: NOTIFY */ 0x10, 930 /* properties: NOTIFY */ 0x10,
926 /* expected_config_descriptor_value: NOTIFY */ 1, 931 /* expected_config_descriptor_value: NOTIFY */ 1,
927 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); 932 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING));
928 933
929 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 934 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
930 935
931 // The expected error callback is asynchronous: 936 // The expected error callback is asynchronous:
932 EXPECT_EQ(0, error_callback_count_); 937 EXPECT_EQ(0, error_callback_count_);
933 base::RunLoop().RunUntilIdle(); 938 base::RunLoop().RunUntilIdle();
934 EXPECT_EQ(1, error_callback_count_); 939 EXPECT_EQ(1, error_callback_count_);
935 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, 940 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
936 last_gatt_error_code_); 941 last_gatt_error_code_);
937 } 942 }
938 #endif // defined(OS_ANDROID) || defined(OS_WIN) 943 #endif // defined(OS_ANDROID) || defined(OS_WIN)
939 944
940 #if defined(OS_ANDROID) || defined(OS_WIN) 945 #if defined(OS_ANDROID) || defined(OS_WIN)
941 // StartNotifySession fails if the characteristic has multiple Client 946 // StartNotifySession fails if the characteristic has multiple Client
ortuno 2016/06/28 16:24:50 Same as above. Add TODO.
jlebel 2016/06/28 18:09:53 Done.
942 // Characteristic Configuration descriptors. 947 // Characteristic Configuration descriptors.
943 TEST_F(BluetoothRemoteGattCharacteristicTest, 948 TEST_F(BluetoothRemoteGattCharacteristicTest,
944 StartNotifySession_MultipleConfigDescriptor) { 949 StartNotifySession_MultipleConfigDescriptor) {
945 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 950 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
946 /* properties: NOTIFY */ 0x10, 951 /* properties: NOTIFY */ 0x10,
947 /* expected_config_descriptor_value: NOTIFY */ 1, 952 /* expected_config_descriptor_value: NOTIFY */ 1,
948 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); 953 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE));
949 954
950 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 955 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
951 956
952 // The expected error callback is asynchronous: 957 // The expected error callback is asynchronous:
953 EXPECT_EQ(0, error_callback_count_); 958 EXPECT_EQ(0, error_callback_count_);
954 base::RunLoop().RunUntilIdle(); 959 base::RunLoop().RunUntilIdle();
955 EXPECT_EQ(1, error_callback_count_); 960 EXPECT_EQ(1, error_callback_count_);
956 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, 961 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
957 last_gatt_error_code_); 962 last_gatt_error_code_);
958 } 963 }
959 #endif // defined(OS_ANDROID) || defined(OS_WIN) 964 #endif // defined(OS_ANDROID) || defined(OS_WIN)
960 965
961 #if defined(OS_ANDROID) 966 #if defined(OS_ANDROID)
962 // StartNotifySession fails synchronously when failing to set a characteristic 967 // StartNotifySession fails synchronously when failing to set a characteristic
963 // to enable notifications. 968 // to enable notifications.
964 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. 969 // Android: This is mBluetoothGatt.setCharacteristicNotification failing.
970 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API.
965 // Windows: Synchronous Test Not Applicable: OS calls are all made 971 // Windows: Synchronous Test Not Applicable: OS calls are all made
966 // asynchronously from BluetoothTaskManagerWin. 972 // asynchronously from BluetoothTaskManagerWin.
967 TEST_F(BluetoothRemoteGattCharacteristicTest, 973 TEST_F(BluetoothRemoteGattCharacteristicTest,
968 StartNotifySession_FailToSetCharacteristicNotification) { 974 StartNotifySession_FailToSetCharacteristicNotification) {
969 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 975 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
970 /* properties: NOTIFY */ 0x10, 976 /* properties: NOTIFY */ 0x10,
971 /* expected_config_descriptor_value: NOTIFY */ 1, 977 /* expected_config_descriptor_value: NOTIFY */ 1,
972 StartNotifySetupError::SET_NOTIFY)); 978 StartNotifySetupError::SET_NOTIFY));
973 979
974 // The expected error callback is asynchronous: 980 // The expected error callback is asynchronous:
975 EXPECT_EQ(0, error_callback_count_); 981 EXPECT_EQ(0, error_callback_count_);
976 base::RunLoop().RunUntilIdle(); 982 base::RunLoop().RunUntilIdle();
977 EXPECT_EQ(1, error_callback_count_); 983 EXPECT_EQ(1, error_callback_count_);
978 984
979 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 985 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
980 ASSERT_EQ(0u, notify_sessions_.size()); 986 ASSERT_EQ(0u, notify_sessions_.size());
981 } 987 }
982 #endif // defined(OS_ANDROID) 988 #endif // defined(OS_ANDROID)
983 989
984 #if defined(OS_ANDROID) 990 #if defined(OS_ANDROID)
985 // Tests StartNotifySession descriptor write synchronous failure. 991 // Tests StartNotifySession descriptor write synchronous failure.
992 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API.
ortuno 2016/06/28 16:24:50 I think this should be: macOS. Not applicable: No
jlebel 2016/06/28 18:09:52 Done.
986 // Windows: Synchronous Test Not Applicable: OS calls are all made 993 // Windows: Synchronous Test Not Applicable: OS calls are all made
987 // asynchronously from BluetoothTaskManagerWin. 994 // asynchronously from BluetoothTaskManagerWin.
988 TEST_F(BluetoothRemoteGattCharacteristicTest, 995 TEST_F(BluetoothRemoteGattCharacteristicTest,
989 StartNotifySession_WriteDescriptorSynchronousError) { 996 StartNotifySession_WriteDescriptorSynchronousError) {
990 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 997 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
991 /* properties: NOTIFY */ 0x10, 998 /* properties: NOTIFY */ 0x10,
992 /* expected_config_descriptor_value: NOTIFY */ 1, 999 /* expected_config_descriptor_value: NOTIFY */ 1,
993 StartNotifySetupError::WRITE_DESCRIPTOR)); 1000 StartNotifySetupError::WRITE_DESCRIPTOR));
994 1001
995 // The expected error callback is asynchronous: 1002 // The expected error callback is asynchronous:
996 EXPECT_EQ(0, error_callback_count_); 1003 EXPECT_EQ(0, error_callback_count_);
997 base::RunLoop().RunUntilIdle(); 1004 base::RunLoop().RunUntilIdle();
998 EXPECT_EQ(1, error_callback_count_); 1005 EXPECT_EQ(1, error_callback_count_);
999 1006
1000 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1007 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1001 ASSERT_EQ(0u, notify_sessions_.size()); 1008 ASSERT_EQ(0u, notify_sessions_.size());
1002 } 1009 }
1003 #endif // defined(OS_ANDROID) 1010 #endif // defined(OS_ANDROID)
1004 1011
1005 #if defined(OS_ANDROID) || defined(OS_WIN) 1012 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1006 // Tests StartNotifySession success on a characteristic enabling Notify. 1013 // Tests StartNotifySession success on a characteristic enabling Notify.
1007 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession) { 1014 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession) {
1008 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1015 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1009 /* properties: NOTIFY */ 0x10, 1016 /* properties: NOTIFY */ 0x10,
1010 /* expected_config_descriptor_value: NOTIFY */ 1)); 1017 /* expected_config_descriptor_value: NOTIFY */ 1));
1011 } 1018 }
1012 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1019 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1013 1020
1014 #if defined(OS_ANDROID) || defined(OS_WIN) 1021 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1015 // Tests StartNotifySession success on a characteristic enabling Indicate. 1022 // Tests StartNotifySession success on a characteristic enabling Indicate.
1016 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_OnIndicate) { 1023 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_OnIndicate) {
1017 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1024 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1018 /* properties: INDICATE */ 0x20, 1025 /* properties: INDICATE */ 0x20,
1019 /* expected_config_descriptor_value: INDICATE */ 2)); 1026 /* expected_config_descriptor_value: INDICATE */ 2));
1020 } 1027 }
1021 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1028 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1022 1029
1023 #if defined(OS_ANDROID) || defined(OS_WIN) 1030 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1024 // Tests StartNotifySession success on a characteristic enabling Notify & 1031 // Tests StartNotifySession success on a characteristic enabling Notify &
1025 // Indicate. 1032 // Indicate.
1026 TEST_F(BluetoothRemoteGattCharacteristicTest, 1033 TEST_F(BluetoothRemoteGattCharacteristicTest,
1027 StartNotifySession_OnNotifyAndIndicate) { 1034 StartNotifySession_OnNotifyAndIndicate) {
1028 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1035 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1029 /* properties: NOTIFY and INDICATE bits set */ 0x30, 1036 /* properties: NOTIFY and INDICATE bits set */ 0x30,
1030 /* expected_config_descriptor_value: NOTIFY */ 1)); 1037 /* expected_config_descriptor_value: NOTIFY */ 1));
1031 } 1038 }
1032 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1039 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1033 1040
1034 #if defined(OS_ANDROID) || defined(OS_WIN) 1041 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1035 // Tests multiple StartNotifySession success. 1042 // Tests multiple StartNotifySession success.
1036 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) { 1043 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) {
1037 ASSERT_NO_FATAL_FAILURE( 1044 ASSERT_NO_FATAL_FAILURE(
1038 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1045 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1039 SimulateGattDescriptor( 1046 SimulateGattDescriptor(
1040 characteristic1_, 1047 characteristic1_,
1041 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1048 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1042 .canonical_value()); 1049 .canonical_value());
1050 #if !defined(OS_MACOSX)
1051 // TODO(jlebel) Need to implement descriptors.
ortuno 2016/06/28 16:24:50 nit: open/point to an issue.
jlebel 2016/06/28 18:09:53 Done.
1043 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1052 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1053 #endif // !defined(OS_MACOSX)
1044 1054
1045 characteristic1_->StartNotifySession( 1055 characteristic1_->StartNotifySession(
1046 GetNotifyCallback(Call::EXPECTED), 1056 GetNotifyCallback(Call::EXPECTED),
1047 GetGattErrorCallback(Call::NOT_EXPECTED)); 1057 GetGattErrorCallback(Call::NOT_EXPECTED));
1048 characteristic1_->StartNotifySession( 1058 characteristic1_->StartNotifySession(
1049 GetNotifyCallback(Call::EXPECTED), 1059 GetNotifyCallback(Call::EXPECTED),
1050 GetGattErrorCallback(Call::NOT_EXPECTED)); 1060 GetGattErrorCallback(Call::NOT_EXPECTED));
1051 EXPECT_EQ(0, callback_count_); 1061 EXPECT_EQ(0, callback_count_);
1052 SimulateGattNotifySessionStarted(characteristic1_); 1062 SimulateGattNotifySessionStarted(characteristic1_);
1053 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1063 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1054 EXPECT_EQ(2, callback_count_); 1064 EXPECT_EQ(2, callback_count_);
1055 EXPECT_EQ(0, error_callback_count_); 1065 EXPECT_EQ(0, error_callback_count_);
1056 ASSERT_EQ(2u, notify_sessions_.size()); 1066 ASSERT_EQ(2u, notify_sessions_.size());
1057 ASSERT_TRUE(notify_sessions_[0]); 1067 ASSERT_TRUE(notify_sessions_[0]);
1058 ASSERT_TRUE(notify_sessions_[1]); 1068 ASSERT_TRUE(notify_sessions_[1]);
1059 EXPECT_EQ(characteristic1_->GetIdentifier(), 1069 EXPECT_EQ(characteristic1_->GetIdentifier(),
1060 notify_sessions_[0]->GetCharacteristicIdentifier()); 1070 notify_sessions_[0]->GetCharacteristicIdentifier());
1061 EXPECT_EQ(characteristic1_->GetIdentifier(), 1071 EXPECT_EQ(characteristic1_->GetIdentifier(),
1062 notify_sessions_[1]->GetCharacteristicIdentifier()); 1072 notify_sessions_[1]->GetCharacteristicIdentifier());
1063 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 1073 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1064 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 1074 EXPECT_TRUE(notify_sessions_[1]->IsActive());
1065 } 1075 }
1066 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1076 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1067 1077
1068 #if defined(OS_ANDROID) 1078 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1069 // Tests multiple StartNotifySessions pending and then an error. 1079 // Tests multiple StartNotifySessions pending and then an error.
1070 TEST_F(BluetoothRemoteGattCharacteristicTest, 1080 TEST_F(BluetoothRemoteGattCharacteristicTest,
1071 StartNotifySessionError_Multiple) { 1081 StartNotifySessionError_Multiple) {
1072 ASSERT_NO_FATAL_FAILURE( 1082 ASSERT_NO_FATAL_FAILURE(
1073 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1083 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1074 SimulateGattDescriptor( 1084 SimulateGattDescriptor(
1075 characteristic1_, 1085 characteristic1_,
1076 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1086 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1077 .canonical_value()); 1087 .canonical_value());
1088 #if !defined(OS_MACOSX)
1089 // TODO(jlebel) Need to implement descriptors.
ortuno 2016/06/28 16:24:50 nit: same here, point to an issue.
jlebel 2016/06/28 18:09:53 Done.
1078 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1090 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1091 #endif // !defined(OS_MACOSX)
1079 1092
1080 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 1093 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
1081 GetGattErrorCallback(Call::EXPECTED)); 1094 GetGattErrorCallback(Call::EXPECTED));
1082 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 1095 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
1083 GetGattErrorCallback(Call::EXPECTED)); 1096 GetGattErrorCallback(Call::EXPECTED));
1084 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1097 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1085 EXPECT_EQ(0, callback_count_); 1098 EXPECT_EQ(0, callback_count_);
1086 SimulateGattNotifySessionStartError( 1099 SimulateGattNotifySessionStartError(
1087 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 1100 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
1088 EXPECT_EQ(0, callback_count_); 1101 EXPECT_EQ(0, callback_count_);
1089 EXPECT_EQ(2, error_callback_count_); 1102 EXPECT_EQ(2, error_callback_count_);
1090 ASSERT_EQ(0u, notify_sessions_.size()); 1103 ASSERT_EQ(0u, notify_sessions_.size());
1091 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, 1104 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
1092 last_gatt_error_code_); 1105 last_gatt_error_code_);
1093 } 1106 }
1094 #endif // defined(OS_ANDROID) 1107 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1095 1108
1096 #if defined(OS_ANDROID) 1109 #if defined(OS_ANDROID)
1097 // Tests StartNotifySession completing after chrome objects are deleted. 1110 // Tests StartNotifySession completing after chrome objects are deleted.
1111 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set
1112 // to nil.
1098 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) { 1113 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) {
1099 ASSERT_NO_FATAL_FAILURE( 1114 ASSERT_NO_FATAL_FAILURE(
1100 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1115 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1101 SimulateGattDescriptor( 1116 SimulateGattDescriptor(
1102 characteristic1_, 1117 characteristic1_,
1103 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() 1118 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
1104 .canonical_value()); 1119 .canonical_value());
1120 #if !defined(OS_MACOSX)
ortuno 2016/06/28 16:24:50 You don't need this one since this test doesn't ap
jlebel 2016/06/28 18:09:52 Done.
1121 // TODO(jlebel) Need to implement descriptors.
1105 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1122 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1123 #endif // !defined(OS_MACOSX)
1106 1124
1107 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 1125 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
1108 GetGattErrorCallback(Call::EXPECTED)); 1126 GetGattErrorCallback(Call::EXPECTED));
1109 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1127 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1110 EXPECT_EQ(0, callback_count_); 1128 EXPECT_EQ(0, callback_count_);
1111 1129
1112 RememberCharacteristicForSubsequentAction(characteristic1_); 1130 RememberCharacteristicForSubsequentAction(characteristic1_);
1113 RememberCCCDescriptorForSubsequentAction(characteristic1_); 1131 RememberCCCDescriptorForSubsequentAction(characteristic1_);
1114 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1132 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1115 1133
1116 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); 1134 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr);
1117 EXPECT_EQ(0, callback_count_); 1135 EXPECT_EQ(0, callback_count_);
1118 EXPECT_EQ(1, error_callback_count_); 1136 EXPECT_EQ(1, error_callback_count_);
1119 ASSERT_EQ(0u, notify_sessions_.size()); 1137 ASSERT_EQ(0u, notify_sessions_.size());
1120 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, 1138 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
1121 last_gatt_error_code_); 1139 last_gatt_error_code_);
1122 } 1140 }
1123 #endif // defined(OS_ANDROID) 1141 #endif // defined(OS_ANDROID)
1124 1142
1125 #if defined(OS_WIN) 1143 #if defined(OS_MACOSX) || defined(OS_WIN)
1126 // Tests StartNotifySession reentrant in start notify session success callback 1144 // Tests StartNotifySession reentrant in start notify session success callback
1127 // and the reentrant start notify session success. 1145 // and the reentrant start notify session success.
1128 TEST_F(BluetoothRemoteGattCharacteristicTest, 1146 TEST_F(BluetoothRemoteGattCharacteristicTest,
1129 StartNotifySession_Reentrant_Success_Success) { 1147 StartNotifySession_Reentrant_Success_Success) {
1130 ASSERT_NO_FATAL_FAILURE( 1148 ASSERT_NO_FATAL_FAILURE(
1131 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1149 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1132 SimulateGattDescriptor( 1150 SimulateGattDescriptor(
1133 characteristic1_, 1151 characteristic1_,
1134 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value()); 1152 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1153 #if !defined(OS_MACOSX)
1154 // TODO(jlebel) Need to implement descriptors.
1135 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1155 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1156 #endif // !defined(OS_MACOSX)
1136 1157
1137 characteristic1_->StartNotifySession( 1158 characteristic1_->StartNotifySession(
1138 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, 1159 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED,
1139 characteristic1_), 1160 characteristic1_),
1140 GetReentrantStartNotifySessionErrorCallback( 1161 GetReentrantStartNotifySessionErrorCallback(
1141 Call::NOT_EXPECTED, characteristic1_, 1162 Call::NOT_EXPECTED, characteristic1_,
1142 false /* error_in_reentrant */)); 1163 false /* error_in_reentrant */));
1143 EXPECT_EQ(0, callback_count_); 1164 EXPECT_EQ(0, callback_count_);
1144 SimulateGattNotifySessionStarted(characteristic1_); 1165 SimulateGattNotifySessionStarted(characteristic1_);
1145 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1166 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1146 1167
1147 // Simulate reentrant StartNotifySession request from 1168 // Simulate reentrant StartNotifySession request from
1148 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback. 1169 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback.
1149 SimulateGattNotifySessionStarted(characteristic1_); 1170 base::RunLoop().RunUntilIdle();
1150 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 1171 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1151 EXPECT_EQ(2, callback_count_); 1172 EXPECT_EQ(2, callback_count_);
1152 EXPECT_EQ(0, error_callback_count_); 1173 EXPECT_EQ(0, error_callback_count_);
1153 ASSERT_EQ(2u, notify_sessions_.size()); 1174 ASSERT_EQ(2u, notify_sessions_.size());
1154 for (unsigned int i = 0; i < notify_sessions_.size(); i++) { 1175 for (unsigned int i = 0; i < notify_sessions_.size(); i++) {
1155 ASSERT_TRUE(notify_sessions_[i]); 1176 ASSERT_TRUE(notify_sessions_[i]);
1156 EXPECT_EQ(characteristic1_->GetIdentifier(), 1177 EXPECT_EQ(characteristic1_->GetIdentifier(),
1157 notify_sessions_[i]->GetCharacteristicIdentifier()); 1178 notify_sessions_[i]->GetCharacteristicIdentifier());
1158 EXPECT_TRUE(notify_sessions_[i]->IsActive()); 1179 EXPECT_TRUE(notify_sessions_[i]->IsActive());
1159 } 1180 }
1160 } 1181 }
1161 #endif // defined(OS_WIN) 1182 #endif // defined(OS_MACOSX) || defined(OS_WIN)
1162 1183
1163 #if defined(OS_WIN) 1184 #if defined(OS_WIN)
1164 // Tests StartNotifySession reentrant in start notify session error callback 1185 // Tests StartNotifySession reentrant in start notify session error callback
1165 // and the reentrant start notify session success. 1186 // and the reentrant start notify session success.
1166 TEST_F(BluetoothRemoteGattCharacteristicTest, 1187 TEST_F(BluetoothRemoteGattCharacteristicTest,
1167 StartNotifySession_Reentrant_Error_Success) { 1188 StartNotifySession_Reentrant_Error_Success) {
1168 ASSERT_NO_FATAL_FAILURE( 1189 ASSERT_NO_FATAL_FAILURE(
1169 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1190 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1170 SimulateGattDescriptor( 1191 SimulateGattDescriptor(
1171 characteristic1_, 1192 characteristic1_,
1172 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value()); 1193 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1194 #if !defined(OS_MACOSX)
1195 // TODO(jlebel) Need to implement descriptors.
ortuno 2016/06/28 16:24:50 Remove since this is not enabled on macOS yet.
jlebel 2016/06/28 18:09:52 Done.
1173 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1196 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1197 #endif // !defined(OS_MACOSX)
1174 1198
1175 SimulateGattNotifySessionStartError( 1199 SimulateGattNotifySessionStartError(
1176 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); 1200 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN);
1177 1201
1178 characteristic1_->StartNotifySession( 1202 characteristic1_->StartNotifySession(
1179 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, 1203 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED,
1180 characteristic1_), 1204 characteristic1_),
1181 GetReentrantStartNotifySessionErrorCallback( 1205 GetReentrantStartNotifySessionErrorCallback(
1182 Call::EXPECTED, characteristic1_, false /* error_in_reentrant */)); 1206 Call::EXPECTED, characteristic1_, false /* error_in_reentrant */));
1183 EXPECT_EQ(0, callback_count_); 1207 EXPECT_EQ(0, callback_count_);
(...skipping 18 matching lines...) Expand all
1202 #if defined(OS_WIN) 1226 #if defined(OS_WIN)
1203 // Tests StartNotifySession reentrant in start notify session error callback 1227 // Tests StartNotifySession reentrant in start notify session error callback
1204 // and the reentrant start notify session error. 1228 // and the reentrant start notify session error.
1205 TEST_F(BluetoothRemoteGattCharacteristicTest, 1229 TEST_F(BluetoothRemoteGattCharacteristicTest,
1206 StartNotifySession_Reentrant_Error_Error) { 1230 StartNotifySession_Reentrant_Error_Error) {
1207 ASSERT_NO_FATAL_FAILURE( 1231 ASSERT_NO_FATAL_FAILURE(
1208 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 1232 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1209 SimulateGattDescriptor( 1233 SimulateGattDescriptor(
1210 characteristic1_, 1234 characteristic1_,
1211 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value()); 1235 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1236 #if !defined(OS_MACOSX)
ortuno 2016/06/28 16:24:50 Remove since this is not enabled on macOS yet.
jlebel 2016/06/28 18:09:53 Done.
1237 // TODO(jlebel) Need to implement descriptors.
1212 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 1238 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1239 #endif // !defined(OS_MACOSX)
1213 1240
1214 SimulateGattNotifySessionStartError( 1241 SimulateGattNotifySessionStartError(
1215 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); 1242 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN);
1216 1243
1217 characteristic1_->StartNotifySession( 1244 characteristic1_->StartNotifySession(
1218 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, 1245 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED,
1219 characteristic1_), 1246 characteristic1_),
1220 GetReentrantStartNotifySessionErrorCallback( 1247 GetReentrantStartNotifySessionErrorCallback(
1221 Call::EXPECTED, characteristic1_, true /* error_in_reentrant */)); 1248 Call::EXPECTED, characteristic1_, true /* error_in_reentrant */));
1222 EXPECT_EQ(0, callback_count_); 1249 EXPECT_EQ(0, callback_count_);
1223 SimulateGattNotifySessionStarted(characteristic1_); 1250 SimulateGattNotifySessionStarted(characteristic1_);
1224 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 1251 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1225 1252
1226 // Simulate reentrant StartNotifySession request from 1253 // Simulate reentrant StartNotifySession request from
1227 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. 1254 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback.
1228 SimulateGattNotifySessionStarted(characteristic1_); 1255 SimulateGattNotifySessionStarted(characteristic1_);
1229 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 1256 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1230 EXPECT_EQ(0, callback_count_); 1257 EXPECT_EQ(0, callback_count_);
1231 EXPECT_EQ(2, error_callback_count_); 1258 EXPECT_EQ(2, error_callback_count_);
1232 ASSERT_EQ(0u, notify_sessions_.size()); 1259 ASSERT_EQ(0u, notify_sessions_.size());
1233 } 1260 }
1234 #endif // defined(OS_WIN) 1261 #endif // defined(OS_WIN)
1235 1262
1236 #if defined(OS_ANDROID) || defined(OS_WIN) 1263 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1237 // Tests Characteristic Value changes during a Notify Session. 1264 // Tests Characteristic Value changes during a Notify Session.
1238 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { 1265 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) {
1239 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1266 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1240 /* properties: NOTIFY */ 0x10, 1267 /* properties: NOTIFY */ 0x10,
1241 /* expected_config_descriptor_value: NOTIFY */ 1)); 1268 /* expected_config_descriptor_value: NOTIFY */ 1));
1242 1269
1243 TestBluetoothAdapterObserver observer(adapter_); 1270 TestBluetoothAdapterObserver observer(adapter_);
1244 1271
1245 std::vector<uint8_t> test_vector1, test_vector2; 1272 std::vector<uint8_t> test_vector1, test_vector2;
1246 test_vector1.push_back(111); 1273 test_vector1.push_back(111);
1247 test_vector2.push_back(222); 1274 test_vector2.push_back(222);
1248 1275
1249 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); 1276 SimulateGattCharacteristicChanged(characteristic1_, test_vector1);
1250 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1277 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1251 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); 1278 EXPECT_EQ(test_vector1, characteristic1_->GetValue());
1252 1279
1253 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); 1280 SimulateGattCharacteristicChanged(characteristic1_, test_vector2);
1254 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 1281 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count());
1255 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); 1282 EXPECT_EQ(test_vector2, characteristic1_->GetValue());
1256 } 1283 }
1257 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1284 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
1258 1285
1259 #if defined(OS_ANDROID) || defined(OS_WIN) 1286 #if defined(OS_ANDROID) || defined(OS_WIN)
1260 // Tests Characteristic Value changing after a Notify Session and objects being 1287 // Tests Characteristic Value changing after a Notify Session and objects being
1261 // destroyed. 1288 // destroyed.
1289 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set
1290 // to nil.
1262 TEST_F(BluetoothRemoteGattCharacteristicTest, 1291 TEST_F(BluetoothRemoteGattCharacteristicTest,
1263 GattCharacteristicValueChanged_AfterDeleted) { 1292 GattCharacteristicValueChanged_AfterDeleted) {
1264 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1293 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1265 /* properties: NOTIFY */ 0x10, 1294 /* properties: NOTIFY */ 0x10,
1266 /* expected_config_descriptor_value: NOTIFY */ 1)); 1295 /* expected_config_descriptor_value: NOTIFY */ 1));
1267 TestBluetoothAdapterObserver observer(adapter_); 1296 TestBluetoothAdapterObserver observer(adapter_);
1268 1297
1269 RememberCharacteristicForSubsequentAction(characteristic1_); 1298 RememberCharacteristicForSubsequentAction(characteristic1_);
1270 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1299 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1271 1300
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 1384 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
1356 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 1385 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
1357 1386
1358 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 1387 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
1359 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 1388 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
1360 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 1389 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
1361 } 1390 }
1362 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1391 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1363 1392
1364 } // namespace device 1393 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698