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