Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 SET_NOTIFY, | 57 SET_NOTIFY, |
| 58 WRITE_DESCRIPTOR, | 58 WRITE_DESCRIPTOR, |
| 59 NONE | 59 NONE |
| 60 }; | 60 }; |
| 61 // Constructs characteristics with |properties|, calls StartNotifySession, | 61 // Constructs characteristics with |properties|, calls StartNotifySession, |
| 62 // and verifies the appropriate |expected_config_descriptor_value| is written. | 62 // and verifies the appropriate |expected_config_descriptor_value| is written. |
| 63 // Error scenarios in this boilerplate are tested by setting |error| to the | 63 // Error scenarios in this boilerplate are tested by setting |error| to the |
| 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 NotifyValueState notify_value_state, |
| 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 size_t expected_descriptors_count = 0; | 74 size_t expected_descriptors_count = 0; |
| 75 if (error != StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING) { | 75 if (error != StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING) { |
| 76 SimulateGattDescriptor( | 76 SimulateGattDescriptor( |
| 77 characteristic1_, | 77 characteristic1_, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 105 GetGattErrorCallback(Call::EXPECTED)); | 105 GetGattErrorCallback(Call::EXPECTED)); |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 | 108 |
| 109 characteristic1_->StartNotifySession( | 109 characteristic1_->StartNotifySession( |
| 110 GetNotifyCallback(Call::EXPECTED), | 110 GetNotifyCallback(Call::EXPECTED), |
| 111 GetGattErrorCallback(Call::NOT_EXPECTED)); | 111 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 112 | 112 |
| 113 EXPECT_EQ(0, callback_count_); | 113 EXPECT_EQ(0, callback_count_); |
| 114 SimulateGattNotifySessionStarted(characteristic1_); | 114 SimulateGattNotifySessionStarted(characteristic1_); |
| 115 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 115 ExpectedChangeNotifyValueAttempts(1); |
| 116 EXPECT_EQ(1, callback_count_); | 116 EXPECT_EQ(1, callback_count_); |
| 117 EXPECT_EQ(0, error_callback_count_); | 117 EXPECT_EQ(0, error_callback_count_); |
| 118 ASSERT_EQ(1u, notify_sessions_.size()); | 118 ASSERT_EQ(1u, notify_sessions_.size()); |
| 119 ASSERT_TRUE(notify_sessions_[0]); | 119 ASSERT_TRUE(notify_sessions_[0]); |
| 120 EXPECT_EQ(characteristic1_->GetIdentifier(), | 120 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 121 notify_sessions_[0]->GetCharacteristicIdentifier()); | 121 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 122 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 122 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 123 | 123 |
| 124 // Verify the Client Characteristic Configuration descriptor was written to. | 124 // Verify the Client Characteristic Configuration descriptor was written to. |
| 125 #if !defined(OS_MACOSX) | 125 ExpectedNotifyValue(notify_value_state); |
| 126 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | |
| 127 // setNotifyValue:forCharacteristic:] which handles all interactions with | |
| 128 // the CCC descriptor. | |
| 129 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | |
| 130 EXPECT_EQ(2u, last_write_value_.size()); | |
| 131 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF; | |
| 132 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF; | |
| 133 EXPECT_EQ(expected_byte0, last_write_value_[0]); | |
| 134 EXPECT_EQ(expected_byte1, last_write_value_[1]); | |
| 135 #else | |
| 136 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 137 EXPECT_TRUE(last_notify_value); | |
| 138 #endif // !defined(OS_MACOSX) | |
| 139 } | 126 } |
| 140 | 127 |
| 141 BluetoothDevice* device_ = nullptr; | 128 BluetoothDevice* device_ = nullptr; |
| 142 BluetoothRemoteGattService* service_ = nullptr; | 129 BluetoothRemoteGattService* service_ = nullptr; |
| 143 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr; | 130 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr; |
| 144 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr; | 131 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr; |
| 145 }; | 132 }; |
| 146 #endif | 133 #endif |
| 147 | 134 |
| 148 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 135 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 978 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 992 // StartNotifySession fails if characteristic doesn't have Notify or Indicate | 979 // StartNotifySession fails if characteristic doesn't have Notify or Indicate |
| 993 // property. | 980 // property. |
| 994 TEST_F(BluetoothRemoteGattCharacteristicTest, | 981 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 995 StartNotifySession_NoNotifyOrIndicate) { | 982 StartNotifySession_NoNotifyOrIndicate) { |
| 996 if (!PlatformSupportsLowEnergy()) { | 983 if (!PlatformSupportsLowEnergy()) { |
| 997 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 984 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 998 return; | 985 return; |
| 999 } | 986 } |
| 1000 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 987 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1001 /* properties: NOTIFY */ 0x10, | 988 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY, |
| 1002 /* expected_config_descriptor_value: NOTIFY */ 1, | |
| 1003 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); | 989 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); |
| 1004 | 990 |
| 1005 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 991 ExpectedChangeNotifyValueAttempts(0); |
| 1006 | 992 |
| 1007 // The expected error callback is asynchronous: | 993 // The expected error callback is asynchronous: |
| 1008 EXPECT_EQ(0, error_callback_count_); | 994 EXPECT_EQ(0, error_callback_count_); |
| 1009 base::RunLoop().RunUntilIdle(); | 995 base::RunLoop().RunUntilIdle(); |
| 1010 EXPECT_EQ(1, error_callback_count_); | 996 EXPECT_EQ(1, error_callback_count_); |
| 1011 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, | 997 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, |
| 1012 last_gatt_error_code_); | 998 last_gatt_error_code_); |
| 1013 } | 999 } |
| 1014 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1000 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1015 | 1001 |
| 1016 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1002 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1017 // StartNotifySession fails if the characteristic is missing the Client | 1003 // StartNotifySession fails if the characteristic is missing the Client |
| 1018 // Characteristic Configuration descriptor. | 1004 // Characteristic Configuration descriptor. |
| 1019 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1005 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1020 StartNotifySession_NoConfigDescriptor) { | 1006 StartNotifySession_NoConfigDescriptor) { |
| 1021 if (!PlatformSupportsLowEnergy()) { | 1007 if (!PlatformSupportsLowEnergy()) { |
| 1022 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1008 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1023 return; | 1009 return; |
| 1024 } | 1010 } |
| 1025 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1011 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1026 /* properties: NOTIFY */ 0x10, | 1012 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY, |
| 1027 /* expected_config_descriptor_value: NOTIFY */ 1, | |
| 1028 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); | 1013 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); |
| 1029 | 1014 |
| 1030 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1015 ExpectedChangeNotifyValueAttempts(0); |
| 1031 | 1016 |
| 1032 // The expected error callback is asynchronous: | 1017 // The expected error callback is asynchronous: |
| 1033 EXPECT_EQ(0, error_callback_count_); | 1018 EXPECT_EQ(0, error_callback_count_); |
| 1034 base::RunLoop().RunUntilIdle(); | 1019 base::RunLoop().RunUntilIdle(); |
| 1035 EXPECT_EQ(1, error_callback_count_); | 1020 EXPECT_EQ(1, error_callback_count_); |
| 1036 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, | 1021 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED, |
| 1037 last_gatt_error_code_); | 1022 last_gatt_error_code_); |
| 1038 } | 1023 } |
| 1039 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1024 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1040 | 1025 |
| 1041 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1026 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1042 // StartNotifySession fails if the characteristic has multiple Client | 1027 // StartNotifySession fails if the characteristic has multiple Client |
| 1043 // Characteristic Configuration descriptors. | 1028 // Characteristic Configuration descriptors. |
| 1044 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1029 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1045 StartNotifySession_MultipleConfigDescriptor) { | 1030 StartNotifySession_MultipleConfigDescriptor) { |
| 1046 if (!PlatformSupportsLowEnergy()) { | 1031 if (!PlatformSupportsLowEnergy()) { |
| 1047 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1032 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1048 return; | 1033 return; |
| 1049 } | 1034 } |
| 1050 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1035 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1051 /* properties: NOTIFY */ 0x10, | 1036 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY, |
| 1052 /* expected_config_descriptor_value: NOTIFY */ 1, | |
| 1053 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); | 1037 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); |
| 1054 | 1038 |
| 1055 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1039 ExpectedChangeNotifyValueAttempts(0); |
| 1056 | 1040 |
| 1057 // The expected error callback is asynchronous: | 1041 // The expected error callback is asynchronous: |
| 1058 EXPECT_EQ(0, error_callback_count_); | 1042 EXPECT_EQ(0, error_callback_count_); |
| 1059 base::RunLoop().RunUntilIdle(); | 1043 base::RunLoop().RunUntilIdle(); |
| 1060 EXPECT_EQ(1, error_callback_count_); | 1044 EXPECT_EQ(1, error_callback_count_); |
| 1061 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, | 1045 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
| 1062 last_gatt_error_code_); | 1046 last_gatt_error_code_); |
| 1063 } | 1047 } |
| 1064 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1048 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1065 | 1049 |
| 1066 #if defined(OS_ANDROID) | 1050 #if defined(OS_ANDROID) |
| 1067 // StartNotifySession fails synchronously when failing to set a characteristic | 1051 // StartNotifySession fails synchronously when failing to set a characteristic |
| 1068 // to enable notifications. | 1052 // to enable notifications. |
| 1069 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. | 1053 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. |
| 1070 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API. | 1054 // macOS: Not applicable: CoreBluetooth doesn't support synchronous API. |
| 1071 // Windows: Synchronous Test Not Applicable: OS calls are all made | 1055 // Windows: Synchronous Test Not Applicable: OS calls are all made |
| 1072 // asynchronously from BluetoothTaskManagerWin. | 1056 // asynchronously from BluetoothTaskManagerWin. |
| 1073 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1057 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1074 StartNotifySession_FailToSetCharacteristicNotification) { | 1058 StartNotifySession_FailToSetCharacteristicNotification) { |
| 1075 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1059 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1076 /* properties: NOTIFY */ 0x10, | 1060 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY, |
| 1077 /* expected_config_descriptor_value: NOTIFY */ 1, | |
| 1078 StartNotifySetupError::SET_NOTIFY)); | 1061 StartNotifySetupError::SET_NOTIFY)); |
| 1079 | 1062 |
| 1080 // The expected error callback is asynchronous: | 1063 // The expected error callback is asynchronous: |
| 1081 EXPECT_EQ(0, error_callback_count_); | 1064 EXPECT_EQ(0, error_callback_count_); |
| 1082 base::RunLoop().RunUntilIdle(); | 1065 base::RunLoop().RunUntilIdle(); |
| 1083 EXPECT_EQ(1, error_callback_count_); | 1066 EXPECT_EQ(1, error_callback_count_); |
| 1084 | 1067 |
| 1085 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1068 ExpectedChangeNotifyValueAttempts(0); |
| 1086 ASSERT_EQ(0u, notify_sessions_.size()); | 1069 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1087 } | 1070 } |
| 1088 #endif // defined(OS_ANDROID) | 1071 #endif // defined(OS_ANDROID) |
| 1089 | 1072 |
| 1090 #if defined(OS_ANDROID) | 1073 #if defined(OS_ANDROID) |
| 1091 // Tests StartNotifySession descriptor write synchronous failure. | 1074 // Tests StartNotifySession descriptor write synchronous failure. |
| 1092 // macOS: Not applicable: No need to write to the descriptor manually. | 1075 // macOS: Not applicable: No need to write to the descriptor manually. |
| 1093 // -[CBPeripheral setNotifyValue:forCharacteristic:] takes care of it. | 1076 // -[CBPeripheral setNotifyValue:forCharacteristic:] takes care of it. |
| 1094 // Windows: Synchronous Test Not Applicable: OS calls are all made | 1077 // Windows: Synchronous Test Not Applicable: OS calls are all made |
| 1095 // asynchronously from BluetoothTaskManagerWin. | 1078 // asynchronously from BluetoothTaskManagerWin. |
| 1096 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1079 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1097 StartNotifySession_WriteDescriptorSynchronousError) { | 1080 StartNotifySession_WriteDescriptorSynchronousError) { |
| 1098 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1081 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1099 /* properties: NOTIFY */ 0x10, | 1082 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY, |
| 1100 /* expected_config_descriptor_value: NOTIFY */ 1, | |
| 1101 StartNotifySetupError::WRITE_DESCRIPTOR)); | 1083 StartNotifySetupError::WRITE_DESCRIPTOR)); |
| 1102 | 1084 |
| 1103 // The expected error callback is asynchronous: | 1085 // The expected error callback is asynchronous: |
| 1104 EXPECT_EQ(0, error_callback_count_); | 1086 EXPECT_EQ(0, error_callback_count_); |
| 1105 base::RunLoop().RunUntilIdle(); | 1087 base::RunLoop().RunUntilIdle(); |
| 1106 EXPECT_EQ(1, error_callback_count_); | 1088 EXPECT_EQ(1, error_callback_count_); |
| 1107 | 1089 |
| 1108 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1090 ExpectedChangeNotifyValueAttempts(1); |
| 1091 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
|
ortuno
2017/02/23 05:56:00
This is failing because we were unable to write to
jlebel
2017/02/23 18:40:32
Ah yes, that was obvious...
jlebel
2017/02/23 21:58:52
Well it was not that obvious:
EXPECT_EQ(1, gatt_no
| |
| 1109 ASSERT_EQ(0u, notify_sessions_.size()); | 1092 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1110 } | 1093 } |
| 1111 #endif // defined(OS_ANDROID) | 1094 #endif // defined(OS_ANDROID) |
| 1112 | 1095 |
| 1113 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1096 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1114 // Tests StartNotifySession success on a characteristic that enabled Notify. | 1097 // Tests StartNotifySession success on a characteristic that enabled Notify. |
| 1115 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession) { | 1098 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession) { |
| 1116 if (!PlatformSupportsLowEnergy()) { | 1099 if (!PlatformSupportsLowEnergy()) { |
| 1117 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1100 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1118 return; | 1101 return; |
| 1119 } | 1102 } |
| 1120 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1103 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1121 /* properties: NOTIFY */ 0x10, | 1104 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1122 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1123 } | 1105 } |
| 1124 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1106 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1125 | 1107 |
| 1126 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1108 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1127 // Tests StartNotifySession success on a characteristic that enabled Indicate. | 1109 // Tests StartNotifySession success on a characteristic that enabled Indicate. |
| 1128 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_OnIndicate) { | 1110 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_OnIndicate) { |
| 1129 if (!PlatformSupportsLowEnergy()) { | 1111 if (!PlatformSupportsLowEnergy()) { |
| 1130 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1112 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1131 return; | 1113 return; |
| 1132 } | 1114 } |
| 1133 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1115 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1134 /* properties: INDICATE */ 0x20, | 1116 /* properties: INDICATE */ 0x20, NotifyValueState::INDICATE)); |
| 1135 /* expected_config_descriptor_value: INDICATE */ 2)); | |
| 1136 } | 1117 } |
| 1137 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1118 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1138 | 1119 |
| 1139 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1120 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1140 // Tests StartNotifySession success on a characteristic that enabled Notify & | 1121 // Tests StartNotifySession success on a characteristic that enabled Notify & |
| 1141 // Indicate. | 1122 // Indicate. |
| 1142 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1123 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1143 StartNotifySession_OnNotifyAndIndicate) { | 1124 StartNotifySession_OnNotifyAndIndicate) { |
| 1144 if (!PlatformSupportsLowEnergy()) { | 1125 if (!PlatformSupportsLowEnergy()) { |
| 1145 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1126 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1146 return; | 1127 return; |
| 1147 } | 1128 } |
| 1148 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1129 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1149 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 1130 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 1150 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1131 NotifyValueState::NOTIFY)); |
| 1151 } | 1132 } |
| 1152 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1133 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1153 | 1134 |
| 1154 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1135 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1155 // Tests multiple StartNotifySession success. | 1136 // Tests multiple StartNotifySession success. |
| 1156 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) { | 1137 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) { |
| 1157 if (!PlatformSupportsLowEnergy()) { | 1138 if (!PlatformSupportsLowEnergy()) { |
| 1158 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1139 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1159 return; | 1140 return; |
| 1160 } | 1141 } |
| 1161 ASSERT_NO_FATAL_FAILURE( | 1142 ASSERT_NO_FATAL_FAILURE( |
| 1162 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1143 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1163 SimulateGattDescriptor( | 1144 SimulateGattDescriptor( |
| 1164 characteristic1_, | 1145 characteristic1_, |
| 1165 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1146 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1166 .canonical_value()); | 1147 .canonical_value()); |
| 1167 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1148 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1168 | 1149 |
| 1169 characteristic1_->StartNotifySession( | 1150 characteristic1_->StartNotifySession( |
| 1170 GetNotifyCallback(Call::EXPECTED), | 1151 GetNotifyCallback(Call::EXPECTED), |
| 1171 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1152 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1172 characteristic1_->StartNotifySession( | 1153 characteristic1_->StartNotifySession( |
| 1173 GetNotifyCallback(Call::EXPECTED), | 1154 GetNotifyCallback(Call::EXPECTED), |
| 1174 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1155 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1175 EXPECT_EQ(0, callback_count_); | 1156 EXPECT_EQ(0, callback_count_); |
| 1176 SimulateGattNotifySessionStarted(characteristic1_); | 1157 SimulateGattNotifySessionStarted(characteristic1_); |
| 1177 base::RunLoop().RunUntilIdle(); | 1158 base::RunLoop().RunUntilIdle(); |
| 1178 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1159 ExpectedChangeNotifyValueAttempts(1); |
| 1160 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1179 EXPECT_EQ(2, callback_count_); | 1161 EXPECT_EQ(2, callback_count_); |
| 1180 EXPECT_EQ(0, error_callback_count_); | 1162 EXPECT_EQ(0, error_callback_count_); |
| 1181 ASSERT_EQ(2u, notify_sessions_.size()); | 1163 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1182 ASSERT_TRUE(notify_sessions_[0]); | 1164 ASSERT_TRUE(notify_sessions_[0]); |
| 1183 ASSERT_TRUE(notify_sessions_[1]); | 1165 ASSERT_TRUE(notify_sessions_[1]); |
| 1184 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1166 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1185 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1167 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1186 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1168 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1187 notify_sessions_[1]->GetCharacteristicIdentifier()); | 1169 notify_sessions_[1]->GetCharacteristicIdentifier()); |
| 1188 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1170 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1203 SimulateGattDescriptor( | 1185 SimulateGattDescriptor( |
| 1204 characteristic1_, | 1186 characteristic1_, |
| 1205 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1187 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1206 .canonical_value()); | 1188 .canonical_value()); |
| 1207 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1189 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1208 | 1190 |
| 1209 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1191 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1210 GetGattErrorCallback(Call::EXPECTED)); | 1192 GetGattErrorCallback(Call::EXPECTED)); |
| 1211 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1193 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1212 GetGattErrorCallback(Call::EXPECTED)); | 1194 GetGattErrorCallback(Call::EXPECTED)); |
| 1213 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1195 ExpectedChangeNotifyValueAttempts(1); |
| 1196 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1214 EXPECT_EQ(0, callback_count_); | 1197 EXPECT_EQ(0, callback_count_); |
| 1215 SimulateGattNotifySessionStartError( | 1198 SimulateGattNotifySessionStartError( |
| 1216 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); | 1199 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); |
| 1217 base::RunLoop().RunUntilIdle(); | 1200 base::RunLoop().RunUntilIdle(); |
| 1218 EXPECT_EQ(0, callback_count_); | 1201 EXPECT_EQ(0, callback_count_); |
| 1219 EXPECT_EQ(2, error_callback_count_); | 1202 EXPECT_EQ(2, error_callback_count_); |
| 1220 ASSERT_EQ(0u, notify_sessions_.size()); | 1203 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1221 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, | 1204 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
| 1222 last_gatt_error_code_); | 1205 last_gatt_error_code_); |
| 1223 } | 1206 } |
| 1224 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1207 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1225 | 1208 |
| 1226 #if defined(OS_ANDROID) | 1209 #if defined(OS_ANDROID) |
| 1227 // Tests StartNotifySession completing after chrome objects are deleted. | 1210 // Tests StartNotifySession completing after chrome objects are deleted. |
| 1228 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set | 1211 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set |
| 1229 // to nil. | 1212 // to nil. |
| 1230 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) { | 1213 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) { |
| 1231 ASSERT_NO_FATAL_FAILURE( | 1214 ASSERT_NO_FATAL_FAILURE( |
| 1232 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1215 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1233 SimulateGattDescriptor( | 1216 SimulateGattDescriptor( |
| 1234 characteristic1_, | 1217 characteristic1_, |
| 1235 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1218 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1236 .canonical_value()); | 1219 .canonical_value()); |
| 1237 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1220 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1238 | 1221 |
| 1239 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1222 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1240 GetGattErrorCallback(Call::EXPECTED)); | 1223 GetGattErrorCallback(Call::EXPECTED)); |
| 1241 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1224 ExpectedChangeNotifyValueAttempts(1); |
| 1225 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1242 EXPECT_EQ(0, callback_count_); | 1226 EXPECT_EQ(0, callback_count_); |
| 1243 | 1227 |
| 1244 RememberCharacteristicForSubsequentAction(characteristic1_); | 1228 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 1245 RememberCCCDescriptorForSubsequentAction(characteristic1_); | 1229 RememberCCCDescriptorForSubsequentAction(characteristic1_); |
| 1246 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1230 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1247 | 1231 |
| 1248 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); | 1232 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); |
| 1249 EXPECT_EQ(0, callback_count_); | 1233 EXPECT_EQ(0, callback_count_); |
| 1250 EXPECT_EQ(1, error_callback_count_); | 1234 EXPECT_EQ(1, error_callback_count_); |
| 1251 ASSERT_EQ(0u, notify_sessions_.size()); | 1235 ASSERT_EQ(0u, notify_sessions_.size()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1266 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1250 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1267 SimulateGattDescriptor( | 1251 SimulateGattDescriptor( |
| 1268 characteristic1_, | 1252 characteristic1_, |
| 1269 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1253 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1270 .canonical_value()); | 1254 .canonical_value()); |
| 1271 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1255 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1272 | 1256 |
| 1273 characteristic1_->StartNotifySession( | 1257 characteristic1_->StartNotifySession( |
| 1274 GetNotifyCallback(Call::EXPECTED), | 1258 GetNotifyCallback(Call::EXPECTED), |
| 1275 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1259 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1276 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1260 ExpectedChangeNotifyValueAttempts(1); |
| 1261 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1277 EXPECT_EQ(0, callback_count_); | 1262 EXPECT_EQ(0, callback_count_); |
| 1278 | 1263 |
| 1279 SimulateGattNotifySessionStarted(characteristic1_); | 1264 SimulateGattNotifySessionStarted(characteristic1_); |
| 1280 ASSERT_EQ(1u, notify_sessions_.size()); | 1265 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1281 | 1266 |
| 1282 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1267 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1283 | 1268 |
| 1284 EXPECT_EQ(characteristic_identifier, | 1269 EXPECT_EQ(characteristic_identifier, |
| 1285 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1270 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1286 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1271 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1314 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1299 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1315 | 1300 |
| 1316 characteristic1_->StartNotifySession( | 1301 characteristic1_->StartNotifySession( |
| 1317 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, | 1302 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, |
| 1318 characteristic1_), | 1303 characteristic1_), |
| 1319 GetReentrantStartNotifySessionErrorCallback( | 1304 GetReentrantStartNotifySessionErrorCallback( |
| 1320 Call::NOT_EXPECTED, characteristic1_, | 1305 Call::NOT_EXPECTED, characteristic1_, |
| 1321 false /* error_in_reentrant */)); | 1306 false /* error_in_reentrant */)); |
| 1322 EXPECT_EQ(0, callback_count_); | 1307 EXPECT_EQ(0, callback_count_); |
| 1323 SimulateGattNotifySessionStarted(characteristic1_); | 1308 SimulateGattNotifySessionStarted(characteristic1_); |
| 1324 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1309 ExpectedChangeNotifyValueAttempts(1); |
| 1310 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1325 | 1311 |
| 1326 // Simulate reentrant StartNotifySession request from | 1312 // Simulate reentrant StartNotifySession request from |
| 1327 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback. | 1313 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback. |
| 1328 base::RunLoop().RunUntilIdle(); | 1314 base::RunLoop().RunUntilIdle(); |
| 1329 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1315 ExpectedChangeNotifyValueAttempts(1); |
| 1330 EXPECT_EQ(2, callback_count_); | 1316 EXPECT_EQ(2, callback_count_); |
| 1331 EXPECT_EQ(0, error_callback_count_); | 1317 EXPECT_EQ(0, error_callback_count_); |
| 1332 ASSERT_EQ(2u, notify_sessions_.size()); | 1318 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1333 for (unsigned int i = 0; i < notify_sessions_.size(); i++) { | 1319 for (unsigned int i = 0; i < notify_sessions_.size(); i++) { |
| 1334 ASSERT_TRUE(notify_sessions_[i]); | 1320 ASSERT_TRUE(notify_sessions_[i]); |
| 1335 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1321 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1336 notify_sessions_[i]->GetCharacteristicIdentifier()); | 1322 notify_sessions_[i]->GetCharacteristicIdentifier()); |
| 1337 EXPECT_TRUE(notify_sessions_[i]->IsActive()); | 1323 EXPECT_TRUE(notify_sessions_[i]->IsActive()); |
| 1338 } | 1324 } |
| 1339 } | 1325 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1354 SimulateGattNotifySessionStartError( | 1340 SimulateGattNotifySessionStartError( |
| 1355 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); | 1341 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); |
| 1356 | 1342 |
| 1357 characteristic1_->StartNotifySession( | 1343 characteristic1_->StartNotifySession( |
| 1358 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, | 1344 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, |
| 1359 characteristic1_), | 1345 characteristic1_), |
| 1360 GetReentrantStartNotifySessionErrorCallback( | 1346 GetReentrantStartNotifySessionErrorCallback( |
| 1361 Call::EXPECTED, characteristic1_, false /* error_in_reentrant */)); | 1347 Call::EXPECTED, characteristic1_, false /* error_in_reentrant */)); |
| 1362 EXPECT_EQ(0, callback_count_); | 1348 EXPECT_EQ(0, callback_count_); |
| 1363 SimulateGattNotifySessionStarted(characteristic1_); | 1349 SimulateGattNotifySessionStarted(characteristic1_); |
| 1364 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1350 ExpectedChangeNotifyValueAttempts(0); |
| 1365 EXPECT_EQ(1, error_callback_count_); | 1351 EXPECT_EQ(1, error_callback_count_); |
| 1366 | 1352 |
| 1367 // Simulate reentrant StartNotifySession request from | 1353 // Simulate reentrant StartNotifySession request from |
| 1368 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. | 1354 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. |
| 1369 SimulateGattNotifySessionStarted(characteristic1_); | 1355 SimulateGattNotifySessionStarted(characteristic1_); |
| 1370 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1356 ExpectedChangeNotifyValueAttempts(1); |
| 1357 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1371 EXPECT_EQ(1, callback_count_); | 1358 EXPECT_EQ(1, callback_count_); |
| 1372 EXPECT_EQ(1, error_callback_count_); | 1359 EXPECT_EQ(1, error_callback_count_); |
| 1373 ASSERT_EQ(1u, notify_sessions_.size()); | 1360 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1374 ASSERT_TRUE(notify_sessions_[0]); | 1361 ASSERT_TRUE(notify_sessions_[0]); |
| 1375 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1362 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1376 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1363 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1377 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1364 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1378 } | 1365 } |
| 1379 #endif // defined(OS_WIN) | 1366 #endif // defined(OS_WIN) |
| 1380 | 1367 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1393 SimulateGattNotifySessionStartError( | 1380 SimulateGattNotifySessionStartError( |
| 1394 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); | 1381 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); |
| 1395 | 1382 |
| 1396 characteristic1_->StartNotifySession( | 1383 characteristic1_->StartNotifySession( |
| 1397 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, | 1384 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, |
| 1398 characteristic1_), | 1385 characteristic1_), |
| 1399 GetReentrantStartNotifySessionErrorCallback( | 1386 GetReentrantStartNotifySessionErrorCallback( |
| 1400 Call::EXPECTED, characteristic1_, true /* error_in_reentrant */)); | 1387 Call::EXPECTED, characteristic1_, true /* error_in_reentrant */)); |
| 1401 EXPECT_EQ(0, callback_count_); | 1388 EXPECT_EQ(0, callback_count_); |
| 1402 SimulateGattNotifySessionStarted(characteristic1_); | 1389 SimulateGattNotifySessionStarted(characteristic1_); |
| 1403 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1390 ExpectedChangeNotifyValueAttempts(0); |
| 1404 | 1391 |
| 1405 // Simulate reentrant StartNotifySession request from | 1392 // Simulate reentrant StartNotifySession request from |
| 1406 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. | 1393 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. |
| 1407 SimulateGattNotifySessionStarted(characteristic1_); | 1394 SimulateGattNotifySessionStarted(characteristic1_); |
| 1408 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1395 ExpectedChangeNotifyValueAttempts(0); |
| 1409 EXPECT_EQ(0, callback_count_); | 1396 EXPECT_EQ(0, callback_count_); |
| 1410 EXPECT_EQ(2, error_callback_count_); | 1397 EXPECT_EQ(2, error_callback_count_); |
| 1411 ASSERT_EQ(0u, notify_sessions_.size()); | 1398 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1412 } | 1399 } |
| 1413 #endif // defined(OS_WIN) | 1400 #endif // defined(OS_WIN) |
| 1414 | 1401 |
| 1415 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1402 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1416 // Tests StopNotifySession success on a characteristic that enabled Notify. | 1403 // Tests StopNotifySession success on a characteristic that enabled Notify. |
| 1417 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { | 1404 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { |
| 1418 if (!PlatformSupportsLowEnergy()) { | 1405 if (!PlatformSupportsLowEnergy()) { |
| 1419 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1406 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1420 return; | 1407 return; |
| 1421 } | 1408 } |
| 1422 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1409 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1423 /* properties: NOTIFY */ 0x10, | 1410 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1424 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1411 ExpectedChangeNotifyValueAttempts(1); |
| 1425 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1412 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1426 // setNotifyValue:forCharacteristic:] which handles all interactions with | |
| 1427 // the CCC descriptor. | |
| 1428 #if !defined(OS_MACOSX) | |
| 1429 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | |
| 1430 #else | |
| 1431 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 1432 EXPECT_TRUE(last_notify_value); | |
| 1433 #endif // !defined(OS_MACOSX) | |
| 1434 | 1413 |
| 1435 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1414 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1436 SimulateGattNotifySessionStopped(characteristic1_); | 1415 SimulateGattNotifySessionStopped(characteristic1_); |
| 1437 base::RunLoop().RunUntilIdle(); | 1416 base::RunLoop().RunUntilIdle(); |
| 1438 | 1417 |
| 1439 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1418 ExpectedChangeNotifyValueAttempts(2); |
| 1440 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1419 ExpectedNotifyValue(NotifyValueState::NONE); |
| 1441 // the CCC descriptor. | |
| 1442 #if !defined(OS_MACOSX) | |
| 1443 // Check that the right values were written to the descriptor. | |
| 1444 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | |
| 1445 ASSERT_EQ(2u, last_write_value_.size()); | |
| 1446 EXPECT_EQ(0, last_write_value_[0]); | |
| 1447 EXPECT_EQ(0, last_write_value_[1]); | |
| 1448 #else | |
| 1449 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); | |
| 1450 EXPECT_FALSE(last_notify_value); | |
| 1451 #endif // !defined(OS_MACOSX) | |
| 1452 | 1420 |
| 1453 // Check that the notify session is inactive. | 1421 // Check that the notify session is inactive. |
| 1454 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1422 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1455 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1423 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1456 } | 1424 } |
| 1457 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1425 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1458 | 1426 |
| 1459 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1427 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1460 // Tests that deleted sessions are stopped. | 1428 // Tests that deleted sessions are stopped. |
| 1461 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1429 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1462 StopNotifySession_SessionDeleted) { | 1430 StopNotifySession_SessionDeleted) { |
| 1463 if (!PlatformSupportsLowEnergy()) { | 1431 if (!PlatformSupportsLowEnergy()) { |
| 1464 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1432 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1465 return; | 1433 return; |
| 1466 } | 1434 } |
| 1467 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1435 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1468 /* properties: NOTIFY */ 0x10, | 1436 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1469 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1437 ExpectedChangeNotifyValueAttempts(1); |
| 1470 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1438 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1471 // setNotifyValue:forCharacteristic:] which handles all interactions with | |
| 1472 // the CCC descriptor. | |
| 1473 #if !defined(OS_MACOSX) | |
| 1474 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | |
| 1475 #else | |
| 1476 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 1477 EXPECT_TRUE(last_notify_value); | |
| 1478 #endif // !defined(OS_MACOSX) | |
| 1479 | 1439 |
| 1480 notify_sessions_.clear(); | 1440 notify_sessions_.clear(); |
| 1481 SimulateGattNotifySessionStopped(characteristic1_); | 1441 SimulateGattNotifySessionStopped(characteristic1_); |
| 1482 base::RunLoop().RunUntilIdle(); | 1442 base::RunLoop().RunUntilIdle(); |
| 1483 | 1443 |
| 1484 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1444 ExpectedChangeNotifyValueAttempts(2); |
| 1485 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1445 ExpectedNotifyValue(NotifyValueState::NONE); |
| 1486 // the CCC descriptor. | |
| 1487 #if !defined(OS_MACOSX) | |
| 1488 // Check that the right values were written to the descriptor. | |
| 1489 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | |
| 1490 ASSERT_EQ(2u, last_write_value_.size()); | |
| 1491 EXPECT_EQ(0, last_write_value_[0]); | |
| 1492 EXPECT_EQ(0, last_write_value_[1]); | |
| 1493 #else | |
| 1494 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); | |
| 1495 EXPECT_FALSE(last_notify_value); | |
| 1496 #endif // !defined(OS_MACOSX) | |
| 1497 | 1446 |
| 1498 // Check that the notify session is inactive. | 1447 // Check that the notify session is inactive. |
| 1499 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1448 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1500 } | 1449 } |
| 1501 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1450 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1502 | 1451 |
| 1503 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1452 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1504 // Tests that deleting the sessions before the stop callbacks have been | 1453 // Tests that deleting the sessions before the stop callbacks have been |
| 1505 // invoked does not cause problems. | 1454 // invoked does not cause problems. |
| 1506 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1455 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1521 // Start notify sessions. | 1470 // Start notify sessions. |
| 1522 characteristic1_->StartNotifySession( | 1471 characteristic1_->StartNotifySession( |
| 1523 GetNotifyCheckForPrecedingCalls(0), | 1472 GetNotifyCheckForPrecedingCalls(0), |
| 1524 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1473 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1525 characteristic1_->StartNotifySession( | 1474 characteristic1_->StartNotifySession( |
| 1526 GetNotifyCheckForPrecedingCalls(1), | 1475 GetNotifyCheckForPrecedingCalls(1), |
| 1527 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1476 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1528 EXPECT_EQ(0, callback_count_); | 1477 EXPECT_EQ(0, callback_count_); |
| 1529 SimulateGattNotifySessionStarted(characteristic1_); | 1478 SimulateGattNotifySessionStarted(characteristic1_); |
| 1530 base::RunLoop().RunUntilIdle(); | 1479 base::RunLoop().RunUntilIdle(); |
| 1531 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1480 ExpectedChangeNotifyValueAttempts(1); |
| 1481 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1532 EXPECT_EQ(2, callback_count_); | 1482 EXPECT_EQ(2, callback_count_); |
| 1533 EXPECT_EQ(0, error_callback_count_); | 1483 EXPECT_EQ(0, error_callback_count_); |
| 1534 ASSERT_EQ(2u, notify_sessions_.size()); | 1484 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1535 ASSERT_TRUE(notify_sessions_[0]); | 1485 ASSERT_TRUE(notify_sessions_[0]); |
| 1536 ASSERT_TRUE(notify_sessions_[1]); | 1486 ASSERT_TRUE(notify_sessions_[1]); |
| 1537 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1487 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1538 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); | 1488 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); |
| 1539 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1489 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1540 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1490 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1541 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1491 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1561 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1511 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1562 // Tests that cancelling StopNotifySession works. | 1512 // Tests that cancelling StopNotifySession works. |
| 1563 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is | 1513 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is |
| 1564 // implemented. | 1514 // implemented. |
| 1565 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { | 1515 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { |
| 1566 if (!PlatformSupportsLowEnergy()) { | 1516 if (!PlatformSupportsLowEnergy()) { |
| 1567 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1517 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1568 return; | 1518 return; |
| 1569 } | 1519 } |
| 1570 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1520 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1571 /* properties: NOTIFY */ 0x10, | 1521 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1572 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1573 | 1522 |
| 1574 // Check that the session is correctly setup. | 1523 // Check that the session is correctly setup. |
| 1575 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1524 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1576 EXPECT_EQ(characteristic_identifier, | 1525 EXPECT_EQ(characteristic_identifier, |
| 1577 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1526 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1578 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1527 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1579 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1528 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1580 | 1529 |
| 1581 // Queue a Stop request. | 1530 // Queue a Stop request. |
| 1582 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1531 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1583 | 1532 |
| 1584 // Cancel Stop by deleting the device before Stop finishes. | 1533 // Cancel Stop by deleting the device before Stop finishes. |
| 1585 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1534 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1586 } | 1535 } |
| 1587 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1536 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1588 | 1537 |
| 1589 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1538 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1590 // Tests that deleted sessions are stopped. | 1539 // Tests that deleted sessions are stopped. |
| 1591 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { | 1540 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { |
| 1592 if (!PlatformSupportsLowEnergy()) { | 1541 if (!PlatformSupportsLowEnergy()) { |
| 1593 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1542 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1594 return; | 1543 return; |
| 1595 } | 1544 } |
| 1596 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1545 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1597 /* properties: NOTIFY */ 0x10, | 1546 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1598 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1599 | 1547 |
| 1600 // Check that the session is correctly setup | 1548 // Check that the session is correctly setup |
| 1601 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1549 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1602 EXPECT_EQ(characteristic_identifier, | 1550 EXPECT_EQ(characteristic_identifier, |
| 1603 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1551 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1604 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1552 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1605 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1553 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1606 | 1554 |
| 1607 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1555 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1608 | 1556 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1625 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1573 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1626 | 1574 |
| 1627 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1575 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1628 // Tests StopNotifySession success on a characteristic that enabled Indicate. | 1576 // Tests StopNotifySession success on a characteristic that enabled Indicate. |
| 1629 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { | 1577 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { |
| 1630 if (!PlatformSupportsLowEnergy()) { | 1578 if (!PlatformSupportsLowEnergy()) { |
| 1631 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1579 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1632 return; | 1580 return; |
| 1633 } | 1581 } |
| 1634 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1582 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1635 /* properties: INDICATE */ 0x20, | 1583 /* properties: INDICATE */ 0x20, NotifyValueState::INDICATE)); |
| 1636 /* expected_config_descriptor_value: INDICATE */ 2)); | 1584 ExpectedChangeNotifyValueAttempts(1); |
| 1637 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1585 ExpectedNotifyValue(NotifyValueState::INDICATE); |
| 1638 // setNotifyValue:forCharacteristic:] which handles all interactions with | |
| 1639 // the CCC descriptor. | |
| 1640 #if !defined(OS_MACOSX) | |
| 1641 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | |
| 1642 #else | |
| 1643 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 1644 EXPECT_TRUE(last_notify_value); | |
| 1645 #endif // !defined(OS_MACOSX) | |
| 1646 | 1586 |
| 1647 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1587 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1648 SimulateGattNotifySessionStopped(characteristic1_); | 1588 SimulateGattNotifySessionStopped(characteristic1_); |
| 1649 base::RunLoop().RunUntilIdle(); | 1589 base::RunLoop().RunUntilIdle(); |
| 1650 | 1590 |
| 1651 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1591 ExpectedChangeNotifyValueAttempts(2); |
| 1652 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1592 ExpectedNotifyValue(NotifyValueState::NONE); |
| 1653 // the CCC descriptor. | |
| 1654 #if !defined(OS_MACOSX) | |
| 1655 // Check that the right values were written to the descriptor. | |
| 1656 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | |
| 1657 ASSERT_EQ(2u, last_write_value_.size()); | |
| 1658 EXPECT_EQ(0, last_write_value_[0]); | |
| 1659 EXPECT_EQ(0, last_write_value_[1]); | |
| 1660 #else | |
| 1661 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); | |
| 1662 EXPECT_FALSE(last_notify_value); | |
| 1663 #endif // !defined(OS_MACOSX) | |
| 1664 | 1593 |
| 1665 // Check that the notify session is inactive. | 1594 // Check that the notify session is inactive. |
| 1666 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1595 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1667 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1596 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1668 } | 1597 } |
| 1669 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1598 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1670 | 1599 |
| 1671 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1600 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1672 // Tests StopNotifySession success on a characteristic that enabled Notify & | 1601 // Tests StopNotifySession success on a characteristic that enabled Notify & |
| 1673 // Indicate. | 1602 // Indicate. |
| 1674 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1603 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1675 StopNotifySession_OnNotifyAndIndicate) { | 1604 StopNotifySession_OnNotifyAndIndicate) { |
| 1676 if (!PlatformSupportsLowEnergy()) { | 1605 if (!PlatformSupportsLowEnergy()) { |
| 1677 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1606 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1678 return; | 1607 return; |
| 1679 } | 1608 } |
| 1680 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1609 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1681 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 1610 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 1682 /* expected_config_descriptor_value: INDICATE */ 1)); | 1611 NotifyValueState::NOTIFY)); |
| 1683 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1612 ExpectedChangeNotifyValueAttempts(1); |
| 1684 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1613 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1685 // the CCC descriptor. | |
| 1686 #if !defined(OS_MACOSX) | |
| 1687 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | |
| 1688 #else | |
| 1689 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 1690 EXPECT_TRUE(last_notify_value); | |
| 1691 #endif // !defined(OS_MACOSX) | |
| 1692 | 1614 |
| 1693 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1615 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1694 SimulateGattNotifySessionStopped(characteristic1_); | 1616 SimulateGattNotifySessionStopped(characteristic1_); |
| 1695 base::RunLoop().RunUntilIdle(); | 1617 base::RunLoop().RunUntilIdle(); |
| 1696 | 1618 |
| 1697 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1619 ExpectedChangeNotifyValueAttempts(2); |
| 1698 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1620 ExpectedNotifyValue(NotifyValueState::NONE); |
| 1699 // the CCC descriptor. | |
| 1700 #if !defined(OS_MACOSX) | |
| 1701 // Check that the right values were written to the descriptor. | |
| 1702 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | |
| 1703 ASSERT_EQ(2u, last_write_value_.size()); | |
| 1704 EXPECT_EQ(0, last_write_value_[0]); | |
| 1705 EXPECT_EQ(0, last_write_value_[1]); | |
| 1706 #else | |
| 1707 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); | |
| 1708 EXPECT_FALSE(last_notify_value); | |
| 1709 #endif // !defined(OS_MACOSX) | |
| 1710 | 1621 |
| 1711 // Check that the notify session is inactive. | 1622 // Check that the notify session is inactive. |
| 1712 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1623 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1713 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1624 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1714 } | 1625 } |
| 1715 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1626 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1716 | 1627 |
| 1717 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1628 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1718 // Tests StopNotifySession error | 1629 // Tests StopNotifySession error |
| 1719 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { | 1630 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { |
| 1720 if (!PlatformSupportsLowEnergy()) { | 1631 if (!PlatformSupportsLowEnergy()) { |
| 1721 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1632 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1722 return; | 1633 return; |
| 1723 } | 1634 } |
| 1724 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1635 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1725 /* properties: NOTIFY */ 0x10, | 1636 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1726 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1727 | 1637 |
| 1728 // Check that the notify session is active. | 1638 // Check that the notify session is active. |
| 1729 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1639 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1730 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1640 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1731 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1641 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1732 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1642 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1733 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1643 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1734 | 1644 |
| 1735 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1645 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1736 SimulateGattNotifySessionStopError( | 1646 SimulateGattNotifySessionStopError( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1759 .canonical_value()); | 1669 .canonical_value()); |
| 1760 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1670 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1761 | 1671 |
| 1762 // Start notify session | 1672 // Start notify session |
| 1763 characteristic1_->StartNotifySession( | 1673 characteristic1_->StartNotifySession( |
| 1764 GetNotifyCallback(Call::EXPECTED), | 1674 GetNotifyCallback(Call::EXPECTED), |
| 1765 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1675 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1766 EXPECT_EQ(0, callback_count_); | 1676 EXPECT_EQ(0, callback_count_); |
| 1767 SimulateGattNotifySessionStarted(characteristic1_); | 1677 SimulateGattNotifySessionStarted(characteristic1_); |
| 1768 base::RunLoop().RunUntilIdle(); | 1678 base::RunLoop().RunUntilIdle(); |
| 1769 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1679 ExpectedChangeNotifyValueAttempts(1); |
| 1680 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1770 EXPECT_EQ(1, callback_count_); | 1681 EXPECT_EQ(1, callback_count_); |
| 1771 EXPECT_EQ(0, error_callback_count_); | 1682 EXPECT_EQ(0, error_callback_count_); |
| 1772 ASSERT_EQ(1u, notify_sessions_.size()); | 1683 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1773 ASSERT_TRUE(notify_sessions_[0]); | 1684 ASSERT_TRUE(notify_sessions_[0]); |
| 1774 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1685 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1775 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1686 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1776 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1687 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1777 | 1688 |
| 1778 // Stop the notify session twice | 1689 // Stop the notify session twice |
| 1779 ResetEventCounts(); | 1690 ResetEventCounts(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1807 // Start notify sessions | 1718 // Start notify sessions |
| 1808 characteristic1_->StartNotifySession( | 1719 characteristic1_->StartNotifySession( |
| 1809 GetNotifyCheckForPrecedingCalls(0), | 1720 GetNotifyCheckForPrecedingCalls(0), |
| 1810 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1721 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1811 characteristic1_->StartNotifySession( | 1722 characteristic1_->StartNotifySession( |
| 1812 GetNotifyCheckForPrecedingCalls(1), | 1723 GetNotifyCheckForPrecedingCalls(1), |
| 1813 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1724 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1814 EXPECT_EQ(0, callback_count_); | 1725 EXPECT_EQ(0, callback_count_); |
| 1815 SimulateGattNotifySessionStarted(characteristic1_); | 1726 SimulateGattNotifySessionStarted(characteristic1_); |
| 1816 base::RunLoop().RunUntilIdle(); | 1727 base::RunLoop().RunUntilIdle(); |
| 1817 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1728 ExpectedChangeNotifyValueAttempts(1); |
| 1729 ExpectedNotifyValue(NotifyValueState::NOTIFY); | |
| 1818 EXPECT_EQ(2, callback_count_); | 1730 EXPECT_EQ(2, callback_count_); |
| 1819 EXPECT_EQ(0, error_callback_count_); | 1731 EXPECT_EQ(0, error_callback_count_); |
| 1820 ASSERT_EQ(2u, notify_sessions_.size()); | 1732 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1821 ASSERT_TRUE(notify_sessions_[0]); | 1733 ASSERT_TRUE(notify_sessions_[0]); |
| 1822 ASSERT_TRUE(notify_sessions_[1]); | 1734 ASSERT_TRUE(notify_sessions_[1]); |
| 1823 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1735 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1824 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); | 1736 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); |
| 1825 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1737 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1826 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1738 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1827 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1739 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1895 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1807 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1896 | 1808 |
| 1897 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1809 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1898 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1810 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1899 StopNotifySession_StartStopStart) { | 1811 StopNotifySession_StartStopStart) { |
| 1900 if (!PlatformSupportsLowEnergy()) { | 1812 if (!PlatformSupportsLowEnergy()) { |
| 1901 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1813 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1902 return; | 1814 return; |
| 1903 } | 1815 } |
| 1904 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1816 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1905 /* properties: NOTIFY */ 0x10, | 1817 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1906 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1907 | 1818 |
| 1908 // Check that the initial notify session is active. | 1819 // Check that the initial notify session is active. |
| 1909 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1820 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1910 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1821 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1911 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1822 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1912 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1823 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1913 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1824 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1914 | 1825 |
| 1915 // Queue up the first event. | 1826 // Queue up the first event. |
| 1916 ResetEventCounts(); | 1827 ResetEventCounts(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1969 // Start notify session | 1880 // Start notify session |
| 1970 ResetEventCounts(); | 1881 ResetEventCounts(); |
| 1971 characteristic1_->StartNotifySession( | 1882 characteristic1_->StartNotifySession( |
| 1972 GetNotifyCheckForPrecedingCalls(0), | 1883 GetNotifyCheckForPrecedingCalls(0), |
| 1973 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1884 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1974 SimulateGattNotifySessionStarted(characteristic1_); | 1885 SimulateGattNotifySessionStarted(characteristic1_); |
| 1975 base::RunLoop().RunUntilIdle(); | 1886 base::RunLoop().RunUntilIdle(); |
| 1976 ASSERT_EQ(1u, notify_sessions_.size()); | 1887 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1977 ASSERT_TRUE(notify_sessions_[0]); | 1888 ASSERT_TRUE(notify_sessions_[0]); |
| 1978 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1889 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1979 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1890 ExpectedChangeNotifyValueAttempts(1); |
| 1980 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1891 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1981 // the CCC descriptor. | |
| 1982 #if !defined(OS_MACOSX) | |
| 1983 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | |
| 1984 #else | |
| 1985 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 1986 EXPECT_TRUE(last_notify_value); | |
| 1987 #endif // !defined(OS_MACOSX) | |
| 1988 | 1892 |
| 1989 // Stop the notify session twice | 1893 // Stop the notify session twice |
| 1990 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); | 1894 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); |
| 1991 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(2)); | 1895 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(2)); |
| 1992 | 1896 |
| 1993 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1897 ExpectedChangeNotifyValueAttempts(2); |
| 1994 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1898 ExpectedNotifyValue(NotifyValueState::NONE); |
| 1995 // the CCC descriptor. | |
| 1996 #if !defined(OS_MACOSX) | |
| 1997 // Check that the right values were written to the descriptor. | |
| 1998 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | |
| 1999 ASSERT_EQ(2u, last_write_value_.size()); | |
| 2000 EXPECT_EQ(0, last_write_value_[0]); | |
| 2001 EXPECT_EQ(0, last_write_value_[1]); | |
| 2002 #else | |
| 2003 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); | |
| 2004 EXPECT_FALSE(last_notify_value); | |
| 2005 #endif // !defined(OS_MACOSX) | |
| 2006 | 1899 |
| 2007 // Start another notify session | 1900 // Start another notify session |
| 2008 characteristic1_->StartNotifySession( | 1901 characteristic1_->StartNotifySession( |
| 2009 GetNotifyCheckForPrecedingCalls(3), | 1902 GetNotifyCheckForPrecedingCalls(3), |
| 2010 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1903 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 2011 | 1904 |
| 2012 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1905 ExpectedChangeNotifyValueAttempts(2); |
| 2013 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1906 ExpectedNotifyValue(NotifyValueState::NONE); |
| 2014 // the CCC descriptor. | |
| 2015 #if !defined(OS_MACOSX) | |
| 2016 // Check that nothing was written by the StartNotifySession call above | |
| 2017 EXPECT_EQ(2, gatt_write_descriptor_attempts_); | |
| 2018 #else | |
| 2019 EXPECT_EQ(2, gatt_notify_characteristic_attempts_); | |
| 2020 #endif // !defined(OS_MACOSX) | |
| 2021 | 1907 |
| 2022 SimulateGattNotifySessionStopped(characteristic1_); | 1908 SimulateGattNotifySessionStopped(characteristic1_); |
| 2023 base::RunLoop().RunUntilIdle(); | 1909 base::RunLoop().RunUntilIdle(); |
| 2024 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1910 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 2025 | 1911 |
| 2026 SimulateGattNotifySessionStarted(characteristic1_); | 1912 SimulateGattNotifySessionStarted(characteristic1_); |
| 2027 base::RunLoop().RunUntilIdle(); | 1913 base::RunLoop().RunUntilIdle(); |
| 2028 | 1914 |
| 2029 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1915 ExpectedChangeNotifyValueAttempts(3); |
| 2030 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1916 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 2031 // the CCC descriptor. | |
| 2032 #if !defined(OS_MACOSX) | |
| 2033 // Check that the right values were written to the descriptor. | |
| 2034 EXPECT_EQ(3, gatt_write_descriptor_attempts_); | |
| 2035 ASSERT_EQ(2u, last_write_value_.size()); | |
| 2036 EXPECT_EQ(1, last_write_value_[0]); | |
| 2037 EXPECT_EQ(0, last_write_value_[1]); | |
| 2038 #else | |
| 2039 EXPECT_EQ(3, gatt_notify_characteristic_attempts_); | |
| 2040 EXPECT_TRUE(last_notify_value); | |
| 2041 #endif // !defined(OS_MACOSX) | |
| 2042 | 1917 |
| 2043 // Check the notify state | 1918 // Check the notify state |
| 2044 ASSERT_EQ(2u, notify_sessions_.size()); | 1919 ASSERT_EQ(2u, notify_sessions_.size()); |
| 2045 ASSERT_TRUE(notify_sessions_[0]); | 1920 ASSERT_TRUE(notify_sessions_[0]); |
| 2046 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1921 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 2047 ASSERT_TRUE(notify_sessions_[1]); | 1922 ASSERT_TRUE(notify_sessions_[1]); |
| 2048 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1923 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 2049 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1924 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 2050 } | 1925 } |
| 2051 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1926 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2095 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1970 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2096 | 1971 |
| 2097 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1972 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2098 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1973 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2099 StopNotifySession_Reentrant_Stop_StartSuccess) { | 1974 StopNotifySession_Reentrant_Stop_StartSuccess) { |
| 2100 if (!PlatformSupportsLowEnergy()) { | 1975 if (!PlatformSupportsLowEnergy()) { |
| 2101 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1976 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2102 return; | 1977 return; |
| 2103 } | 1978 } |
| 2104 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1979 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2105 /* properties: NOTIFY */ 0x10, | 1980 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2106 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2107 | 1981 |
| 2108 // Check that the notify session is active. | 1982 // Check that the notify session is active. |
| 2109 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1983 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 2110 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1984 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 2111 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1985 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 2112 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1986 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 2113 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1987 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 2114 | 1988 |
| 2115 notify_sessions_[0]->Stop(base::Bind( | 1989 notify_sessions_[0]->Stop(base::Bind( |
| 2116 [](BluetoothRemoteGattCharacteristic* characteristic, | 1990 [](BluetoothRemoteGattCharacteristic* characteristic, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2141 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 2015 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2142 | 2016 |
| 2143 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 2017 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2144 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2018 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2145 StopNotifySession_Reentrant_Stop_StartError) { | 2019 StopNotifySession_Reentrant_Stop_StartError) { |
| 2146 if (!PlatformSupportsLowEnergy()) { | 2020 if (!PlatformSupportsLowEnergy()) { |
| 2147 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 2021 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2148 return; | 2022 return; |
| 2149 } | 2023 } |
| 2150 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2024 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2151 /* properties: NOTIFY */ 0x10, | 2025 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2152 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2153 | 2026 |
| 2154 // Check that the notify session is active. | 2027 // Check that the notify session is active. |
| 2155 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 2028 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 2156 EXPECT_EQ(characteristic1_->GetIdentifier(), | 2029 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 2157 notify_sessions_[0]->GetCharacteristicIdentifier()); | 2030 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 2158 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 2031 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 2159 EXPECT_TRUE(characteristic1_->IsNotifying()); | 2032 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 2160 | 2033 |
| 2161 notify_sessions_[0]->Stop(base::Bind( | 2034 notify_sessions_[0]->Stop(base::Bind( |
| 2162 [](BluetoothRemoteGattCharacteristic* characteristic, | 2035 [](BluetoothRemoteGattCharacteristic* characteristic, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2185 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 2058 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2186 | 2059 |
| 2187 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 2060 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 2188 // Tests Characteristic Value changes during a Notify Session. | 2061 // Tests Characteristic Value changes during a Notify Session. |
| 2189 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { | 2062 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { |
| 2190 if (!PlatformSupportsLowEnergy()) { | 2063 if (!PlatformSupportsLowEnergy()) { |
| 2191 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 2064 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2192 return; | 2065 return; |
| 2193 } | 2066 } |
| 2194 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2067 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2195 /* properties: NOTIFY */ 0x10, | 2068 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2196 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2197 | 2069 |
| 2198 TestBluetoothAdapterObserver observer(adapter_); | 2070 TestBluetoothAdapterObserver observer(adapter_); |
| 2199 | 2071 |
| 2200 std::vector<uint8_t> test_vector1, test_vector2; | 2072 std::vector<uint8_t> test_vector1, test_vector2; |
| 2201 test_vector1.push_back(111); | 2073 test_vector1.push_back(111); |
| 2202 test_vector2.push_back(222); | 2074 test_vector2.push_back(222); |
| 2203 | 2075 |
| 2204 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); | 2076 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); |
| 2205 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 2077 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 2206 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 2078 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 2207 | 2079 |
| 2208 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); | 2080 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); |
| 2209 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 2081 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| 2210 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); | 2082 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| 2211 } | 2083 } |
| 2212 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 2084 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 2213 | 2085 |
| 2214 #if defined(OS_ANDROID) || defined(OS_WIN) | 2086 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 2215 // Tests Characteristic Value changing after a Notify Session and objects being | 2087 // Tests Characteristic Value changing after a Notify Session and objects being |
| 2216 // destroyed. | 2088 // destroyed. |
| 2217 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set | 2089 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set |
| 2218 // to nil. | 2090 // to nil. |
| 2219 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2091 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2220 GattCharacteristicValueChanged_AfterDeleted) { | 2092 GattCharacteristicValueChanged_AfterDeleted) { |
| 2221 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2093 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2222 /* properties: NOTIFY */ 0x10, | 2094 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2223 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2224 TestBluetoothAdapterObserver observer(adapter_); | 2095 TestBluetoothAdapterObserver observer(adapter_); |
| 2225 | 2096 |
| 2226 RememberCharacteristicForSubsequentAction(characteristic1_); | 2097 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 2227 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 2098 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 2228 | 2099 |
| 2229 std::vector<uint8_t> empty_vector; | 2100 std::vector<uint8_t> empty_vector; |
| 2230 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, | 2101 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, |
| 2231 empty_vector); | 2102 empty_vector); |
| 2232 EXPECT_TRUE("Did not crash!"); | 2103 EXPECT_TRUE("Did not crash!"); |
| 2233 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 2104 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2312 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); | 2183 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 2313 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 2184 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 2314 | 2185 |
| 2315 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 2186 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 2316 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 2187 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 2317 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 2188 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 2318 } | 2189 } |
| 2319 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 2190 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 2320 | 2191 |
| 2321 } // namespace device | 2192 } // namespace device |
| OLD | NEW |