| 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 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 1091 EXPECT_EQ(0, gatt_write_descriptor_attempts_); |
| 1092 ASSERT_EQ(0u, last_write_value_.size()); |
| 1109 ASSERT_EQ(0u, notify_sessions_.size()); | 1093 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1110 } | 1094 } |
| 1111 #endif // defined(OS_ANDROID) | 1095 #endif // defined(OS_ANDROID) |
| 1112 | 1096 |
| 1113 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1097 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1114 // Tests StartNotifySession success on a characteristic that enabled Notify. | 1098 // Tests StartNotifySession success on a characteristic that enabled Notify. |
| 1115 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession) { | 1099 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession) { |
| 1116 if (!PlatformSupportsLowEnergy()) { | 1100 if (!PlatformSupportsLowEnergy()) { |
| 1117 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1101 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1118 return; | 1102 return; |
| 1119 } | 1103 } |
| 1120 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1104 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1121 /* properties: NOTIFY */ 0x10, | 1105 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1122 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1123 } | 1106 } |
| 1124 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1107 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1125 | 1108 |
| 1126 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1109 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1127 // Tests StartNotifySession success on a characteristic that enabled Indicate. | 1110 // Tests StartNotifySession success on a characteristic that enabled Indicate. |
| 1128 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_OnIndicate) { | 1111 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_OnIndicate) { |
| 1129 if (!PlatformSupportsLowEnergy()) { | 1112 if (!PlatformSupportsLowEnergy()) { |
| 1130 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1113 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1131 return; | 1114 return; |
| 1132 } | 1115 } |
| 1133 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1116 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1134 /* properties: INDICATE */ 0x20, | 1117 /* properties: INDICATE */ 0x20, NotifyValueState::INDICATE)); |
| 1135 /* expected_config_descriptor_value: INDICATE */ 2)); | |
| 1136 } | 1118 } |
| 1137 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1119 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1138 | 1120 |
| 1139 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1121 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1140 // Tests StartNotifySession success on a characteristic that enabled Notify & | 1122 // Tests StartNotifySession success on a characteristic that enabled Notify & |
| 1141 // Indicate. | 1123 // Indicate. |
| 1142 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1124 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1143 StartNotifySession_OnNotifyAndIndicate) { | 1125 StartNotifySession_OnNotifyAndIndicate) { |
| 1144 if (!PlatformSupportsLowEnergy()) { | 1126 if (!PlatformSupportsLowEnergy()) { |
| 1145 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1127 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1146 return; | 1128 return; |
| 1147 } | 1129 } |
| 1148 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1130 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1149 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 1131 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 1150 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1132 NotifyValueState::NOTIFY)); |
| 1151 } | 1133 } |
| 1152 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1134 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1153 | 1135 |
| 1154 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1136 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1155 // Tests multiple StartNotifySession success. | 1137 // Tests multiple StartNotifySession success. |
| 1156 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) { | 1138 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) { |
| 1157 if (!PlatformSupportsLowEnergy()) { | 1139 if (!PlatformSupportsLowEnergy()) { |
| 1158 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1140 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1159 return; | 1141 return; |
| 1160 } | 1142 } |
| 1161 ASSERT_NO_FATAL_FAILURE( | 1143 ASSERT_NO_FATAL_FAILURE( |
| 1162 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1144 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1163 SimulateGattDescriptor( | 1145 SimulateGattDescriptor( |
| 1164 characteristic1_, | 1146 characteristic1_, |
| 1165 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1147 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1166 .canonical_value()); | 1148 .canonical_value()); |
| 1167 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1149 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1168 | 1150 |
| 1169 characteristic1_->StartNotifySession( | 1151 characteristic1_->StartNotifySession( |
| 1170 GetNotifyCallback(Call::EXPECTED), | 1152 GetNotifyCallback(Call::EXPECTED), |
| 1171 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1153 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1172 characteristic1_->StartNotifySession( | 1154 characteristic1_->StartNotifySession( |
| 1173 GetNotifyCallback(Call::EXPECTED), | 1155 GetNotifyCallback(Call::EXPECTED), |
| 1174 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1156 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1175 EXPECT_EQ(0, callback_count_); | 1157 EXPECT_EQ(0, callback_count_); |
| 1176 SimulateGattNotifySessionStarted(characteristic1_); | 1158 SimulateGattNotifySessionStarted(characteristic1_); |
| 1177 base::RunLoop().RunUntilIdle(); | 1159 base::RunLoop().RunUntilIdle(); |
| 1178 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1160 ExpectedChangeNotifyValueAttempts(1); |
| 1161 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1179 EXPECT_EQ(2, callback_count_); | 1162 EXPECT_EQ(2, callback_count_); |
| 1180 EXPECT_EQ(0, error_callback_count_); | 1163 EXPECT_EQ(0, error_callback_count_); |
| 1181 ASSERT_EQ(2u, notify_sessions_.size()); | 1164 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1182 ASSERT_TRUE(notify_sessions_[0]); | 1165 ASSERT_TRUE(notify_sessions_[0]); |
| 1183 ASSERT_TRUE(notify_sessions_[1]); | 1166 ASSERT_TRUE(notify_sessions_[1]); |
| 1184 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1167 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1185 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1168 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1186 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1169 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1187 notify_sessions_[1]->GetCharacteristicIdentifier()); | 1170 notify_sessions_[1]->GetCharacteristicIdentifier()); |
| 1188 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1171 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1203 SimulateGattDescriptor( | 1186 SimulateGattDescriptor( |
| 1204 characteristic1_, | 1187 characteristic1_, |
| 1205 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1188 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1206 .canonical_value()); | 1189 .canonical_value()); |
| 1207 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1190 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1208 | 1191 |
| 1209 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1192 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1210 GetGattErrorCallback(Call::EXPECTED)); | 1193 GetGattErrorCallback(Call::EXPECTED)); |
| 1211 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1194 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1212 GetGattErrorCallback(Call::EXPECTED)); | 1195 GetGattErrorCallback(Call::EXPECTED)); |
| 1213 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1196 ExpectedChangeNotifyValueAttempts(1); |
| 1197 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1214 EXPECT_EQ(0, callback_count_); | 1198 EXPECT_EQ(0, callback_count_); |
| 1215 SimulateGattNotifySessionStartError( | 1199 SimulateGattNotifySessionStartError( |
| 1216 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); | 1200 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); |
| 1217 base::RunLoop().RunUntilIdle(); | 1201 base::RunLoop().RunUntilIdle(); |
| 1218 EXPECT_EQ(0, callback_count_); | 1202 EXPECT_EQ(0, callback_count_); |
| 1219 EXPECT_EQ(2, error_callback_count_); | 1203 EXPECT_EQ(2, error_callback_count_); |
| 1220 ASSERT_EQ(0u, notify_sessions_.size()); | 1204 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1221 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, | 1205 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
| 1222 last_gatt_error_code_); | 1206 last_gatt_error_code_); |
| 1223 } | 1207 } |
| 1224 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1208 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1225 | 1209 |
| 1226 #if defined(OS_ANDROID) | 1210 #if defined(OS_ANDROID) |
| 1227 // Tests StartNotifySession completing after chrome objects are deleted. | 1211 // Tests StartNotifySession completing after chrome objects are deleted. |
| 1228 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set | 1212 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set |
| 1229 // to nil. | 1213 // to nil. |
| 1230 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) { | 1214 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) { |
| 1231 ASSERT_NO_FATAL_FAILURE( | 1215 ASSERT_NO_FATAL_FAILURE( |
| 1232 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1216 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1233 SimulateGattDescriptor( | 1217 SimulateGattDescriptor( |
| 1234 characteristic1_, | 1218 characteristic1_, |
| 1235 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1219 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1236 .canonical_value()); | 1220 .canonical_value()); |
| 1237 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1221 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1238 | 1222 |
| 1239 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 1223 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 1240 GetGattErrorCallback(Call::EXPECTED)); | 1224 GetGattErrorCallback(Call::EXPECTED)); |
| 1241 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1225 ExpectedChangeNotifyValueAttempts(1); |
| 1226 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1242 EXPECT_EQ(0, callback_count_); | 1227 EXPECT_EQ(0, callback_count_); |
| 1243 | 1228 |
| 1244 RememberCharacteristicForSubsequentAction(characteristic1_); | 1229 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 1245 RememberCCCDescriptorForSubsequentAction(characteristic1_); | 1230 RememberCCCDescriptorForSubsequentAction(characteristic1_); |
| 1246 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1231 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1247 | 1232 |
| 1248 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); | 1233 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); |
| 1249 EXPECT_EQ(0, callback_count_); | 1234 EXPECT_EQ(0, callback_count_); |
| 1250 EXPECT_EQ(1, error_callback_count_); | 1235 EXPECT_EQ(1, error_callback_count_); |
| 1251 ASSERT_EQ(0u, notify_sessions_.size()); | 1236 ASSERT_EQ(0u, notify_sessions_.size()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1266 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 1251 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 1267 SimulateGattDescriptor( | 1252 SimulateGattDescriptor( |
| 1268 characteristic1_, | 1253 characteristic1_, |
| 1269 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() | 1254 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 1270 .canonical_value()); | 1255 .canonical_value()); |
| 1271 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1256 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1272 | 1257 |
| 1273 characteristic1_->StartNotifySession( | 1258 characteristic1_->StartNotifySession( |
| 1274 GetNotifyCallback(Call::EXPECTED), | 1259 GetNotifyCallback(Call::EXPECTED), |
| 1275 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1260 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1276 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1261 ExpectedChangeNotifyValueAttempts(1); |
| 1262 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1277 EXPECT_EQ(0, callback_count_); | 1263 EXPECT_EQ(0, callback_count_); |
| 1278 | 1264 |
| 1279 SimulateGattNotifySessionStarted(characteristic1_); | 1265 SimulateGattNotifySessionStarted(characteristic1_); |
| 1280 ASSERT_EQ(1u, notify_sessions_.size()); | 1266 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1281 | 1267 |
| 1282 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1268 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1283 | 1269 |
| 1284 EXPECT_EQ(characteristic_identifier, | 1270 EXPECT_EQ(characteristic_identifier, |
| 1285 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1271 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1286 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1272 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1314 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1300 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1315 | 1301 |
| 1316 characteristic1_->StartNotifySession( | 1302 characteristic1_->StartNotifySession( |
| 1317 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, | 1303 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED, |
| 1318 characteristic1_), | 1304 characteristic1_), |
| 1319 GetReentrantStartNotifySessionErrorCallback( | 1305 GetReentrantStartNotifySessionErrorCallback( |
| 1320 Call::NOT_EXPECTED, characteristic1_, | 1306 Call::NOT_EXPECTED, characteristic1_, |
| 1321 false /* error_in_reentrant */)); | 1307 false /* error_in_reentrant */)); |
| 1322 EXPECT_EQ(0, callback_count_); | 1308 EXPECT_EQ(0, callback_count_); |
| 1323 SimulateGattNotifySessionStarted(characteristic1_); | 1309 SimulateGattNotifySessionStarted(characteristic1_); |
| 1324 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1310 ExpectedChangeNotifyValueAttempts(1); |
| 1311 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1325 | 1312 |
| 1326 // Simulate reentrant StartNotifySession request from | 1313 // Simulate reentrant StartNotifySession request from |
| 1327 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback. | 1314 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback. |
| 1328 base::RunLoop().RunUntilIdle(); | 1315 base::RunLoop().RunUntilIdle(); |
| 1329 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1316 ExpectedChangeNotifyValueAttempts(1); |
| 1330 EXPECT_EQ(2, callback_count_); | 1317 EXPECT_EQ(2, callback_count_); |
| 1331 EXPECT_EQ(0, error_callback_count_); | 1318 EXPECT_EQ(0, error_callback_count_); |
| 1332 ASSERT_EQ(2u, notify_sessions_.size()); | 1319 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1333 for (unsigned int i = 0; i < notify_sessions_.size(); i++) { | 1320 for (unsigned int i = 0; i < notify_sessions_.size(); i++) { |
| 1334 ASSERT_TRUE(notify_sessions_[i]); | 1321 ASSERT_TRUE(notify_sessions_[i]); |
| 1335 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1322 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1336 notify_sessions_[i]->GetCharacteristicIdentifier()); | 1323 notify_sessions_[i]->GetCharacteristicIdentifier()); |
| 1337 EXPECT_TRUE(notify_sessions_[i]->IsActive()); | 1324 EXPECT_TRUE(notify_sessions_[i]->IsActive()); |
| 1338 } | 1325 } |
| 1339 } | 1326 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1354 SimulateGattNotifySessionStartError( | 1341 SimulateGattNotifySessionStartError( |
| 1355 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); | 1342 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); |
| 1356 | 1343 |
| 1357 characteristic1_->StartNotifySession( | 1344 characteristic1_->StartNotifySession( |
| 1358 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, | 1345 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, |
| 1359 characteristic1_), | 1346 characteristic1_), |
| 1360 GetReentrantStartNotifySessionErrorCallback( | 1347 GetReentrantStartNotifySessionErrorCallback( |
| 1361 Call::EXPECTED, characteristic1_, false /* error_in_reentrant */)); | 1348 Call::EXPECTED, characteristic1_, false /* error_in_reentrant */)); |
| 1362 EXPECT_EQ(0, callback_count_); | 1349 EXPECT_EQ(0, callback_count_); |
| 1363 SimulateGattNotifySessionStarted(characteristic1_); | 1350 SimulateGattNotifySessionStarted(characteristic1_); |
| 1364 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1351 ExpectedChangeNotifyValueAttempts(0); |
| 1365 EXPECT_EQ(1, error_callback_count_); | 1352 EXPECT_EQ(1, error_callback_count_); |
| 1366 | 1353 |
| 1367 // Simulate reentrant StartNotifySession request from | 1354 // Simulate reentrant StartNotifySession request from |
| 1368 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. | 1355 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. |
| 1369 SimulateGattNotifySessionStarted(characteristic1_); | 1356 SimulateGattNotifySessionStarted(characteristic1_); |
| 1370 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1357 ExpectedChangeNotifyValueAttempts(1); |
| 1358 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1371 EXPECT_EQ(1, callback_count_); | 1359 EXPECT_EQ(1, callback_count_); |
| 1372 EXPECT_EQ(1, error_callback_count_); | 1360 EXPECT_EQ(1, error_callback_count_); |
| 1373 ASSERT_EQ(1u, notify_sessions_.size()); | 1361 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1374 ASSERT_TRUE(notify_sessions_[0]); | 1362 ASSERT_TRUE(notify_sessions_[0]); |
| 1375 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1363 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1376 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1364 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1377 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1365 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1378 } | 1366 } |
| 1379 #endif // defined(OS_WIN) | 1367 #endif // defined(OS_WIN) |
| 1380 | 1368 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1393 SimulateGattNotifySessionStartError( | 1381 SimulateGattNotifySessionStartError( |
| 1394 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); | 1382 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); |
| 1395 | 1383 |
| 1396 characteristic1_->StartNotifySession( | 1384 characteristic1_->StartNotifySession( |
| 1397 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, | 1385 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED, |
| 1398 characteristic1_), | 1386 characteristic1_), |
| 1399 GetReentrantStartNotifySessionErrorCallback( | 1387 GetReentrantStartNotifySessionErrorCallback( |
| 1400 Call::EXPECTED, characteristic1_, true /* error_in_reentrant */)); | 1388 Call::EXPECTED, characteristic1_, true /* error_in_reentrant */)); |
| 1401 EXPECT_EQ(0, callback_count_); | 1389 EXPECT_EQ(0, callback_count_); |
| 1402 SimulateGattNotifySessionStarted(characteristic1_); | 1390 SimulateGattNotifySessionStarted(characteristic1_); |
| 1403 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1391 ExpectedChangeNotifyValueAttempts(0); |
| 1404 | 1392 |
| 1405 // Simulate reentrant StartNotifySession request from | 1393 // Simulate reentrant StartNotifySession request from |
| 1406 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. | 1394 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback. |
| 1407 SimulateGattNotifySessionStarted(characteristic1_); | 1395 SimulateGattNotifySessionStarted(characteristic1_); |
| 1408 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 1396 ExpectedChangeNotifyValueAttempts(0); |
| 1409 EXPECT_EQ(0, callback_count_); | 1397 EXPECT_EQ(0, callback_count_); |
| 1410 EXPECT_EQ(2, error_callback_count_); | 1398 EXPECT_EQ(2, error_callback_count_); |
| 1411 ASSERT_EQ(0u, notify_sessions_.size()); | 1399 ASSERT_EQ(0u, notify_sessions_.size()); |
| 1412 } | 1400 } |
| 1413 #endif // defined(OS_WIN) | 1401 #endif // defined(OS_WIN) |
| 1414 | 1402 |
| 1415 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1403 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1416 // Tests StopNotifySession success on a characteristic that enabled Notify. | 1404 // Tests StopNotifySession success on a characteristic that enabled Notify. |
| 1417 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { | 1405 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession) { |
| 1418 if (!PlatformSupportsLowEnergy()) { | 1406 if (!PlatformSupportsLowEnergy()) { |
| 1419 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1407 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1420 return; | 1408 return; |
| 1421 } | 1409 } |
| 1422 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1410 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1423 /* properties: NOTIFY */ 0x10, | 1411 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1424 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1412 ExpectedChangeNotifyValueAttempts(1); |
| 1425 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1413 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 | 1414 |
| 1435 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1415 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1436 SimulateGattNotifySessionStopped(characteristic1_); | 1416 SimulateGattNotifySessionStopped(characteristic1_); |
| 1437 base::RunLoop().RunUntilIdle(); | 1417 base::RunLoop().RunUntilIdle(); |
| 1438 | 1418 |
| 1439 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1419 ExpectedChangeNotifyValueAttempts(2); |
| 1440 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1420 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 | 1421 |
| 1453 // Check that the notify session is inactive. | 1422 // Check that the notify session is inactive. |
| 1454 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1423 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1455 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1424 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1456 } | 1425 } |
| 1457 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1426 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1458 | 1427 |
| 1459 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1428 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1460 // Tests that deleted sessions are stopped. | 1429 // Tests that deleted sessions are stopped. |
| 1461 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1430 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1462 StopNotifySession_SessionDeleted) { | 1431 StopNotifySession_SessionDeleted) { |
| 1463 if (!PlatformSupportsLowEnergy()) { | 1432 if (!PlatformSupportsLowEnergy()) { |
| 1464 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1433 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1465 return; | 1434 return; |
| 1466 } | 1435 } |
| 1467 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1436 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1468 /* properties: NOTIFY */ 0x10, | 1437 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1469 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1438 ExpectedChangeNotifyValueAttempts(1); |
| 1470 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1439 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 | 1440 |
| 1480 notify_sessions_.clear(); | 1441 notify_sessions_.clear(); |
| 1481 SimulateGattNotifySessionStopped(characteristic1_); | 1442 SimulateGattNotifySessionStopped(characteristic1_); |
| 1482 base::RunLoop().RunUntilIdle(); | 1443 base::RunLoop().RunUntilIdle(); |
| 1483 | 1444 |
| 1484 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1445 ExpectedChangeNotifyValueAttempts(2); |
| 1485 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1446 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 | 1447 |
| 1498 // Check that the notify session is inactive. | 1448 // Check that the notify session is inactive. |
| 1499 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1449 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1500 } | 1450 } |
| 1501 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1451 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1502 | 1452 |
| 1503 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1453 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1504 // Tests that deleting the sessions before the stop callbacks have been | 1454 // Tests that deleting the sessions before the stop callbacks have been |
| 1505 // invoked does not cause problems. | 1455 // invoked does not cause problems. |
| 1506 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1456 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1521 // Start notify sessions. | 1471 // Start notify sessions. |
| 1522 characteristic1_->StartNotifySession( | 1472 characteristic1_->StartNotifySession( |
| 1523 GetNotifyCheckForPrecedingCalls(0), | 1473 GetNotifyCheckForPrecedingCalls(0), |
| 1524 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1474 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1525 characteristic1_->StartNotifySession( | 1475 characteristic1_->StartNotifySession( |
| 1526 GetNotifyCheckForPrecedingCalls(1), | 1476 GetNotifyCheckForPrecedingCalls(1), |
| 1527 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1477 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1528 EXPECT_EQ(0, callback_count_); | 1478 EXPECT_EQ(0, callback_count_); |
| 1529 SimulateGattNotifySessionStarted(characteristic1_); | 1479 SimulateGattNotifySessionStarted(characteristic1_); |
| 1530 base::RunLoop().RunUntilIdle(); | 1480 base::RunLoop().RunUntilIdle(); |
| 1531 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1481 ExpectedChangeNotifyValueAttempts(1); |
| 1482 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1532 EXPECT_EQ(2, callback_count_); | 1483 EXPECT_EQ(2, callback_count_); |
| 1533 EXPECT_EQ(0, error_callback_count_); | 1484 EXPECT_EQ(0, error_callback_count_); |
| 1534 ASSERT_EQ(2u, notify_sessions_.size()); | 1485 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1535 ASSERT_TRUE(notify_sessions_[0]); | 1486 ASSERT_TRUE(notify_sessions_[0]); |
| 1536 ASSERT_TRUE(notify_sessions_[1]); | 1487 ASSERT_TRUE(notify_sessions_[1]); |
| 1537 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1488 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1538 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); | 1489 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); |
| 1539 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1490 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1540 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1491 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1541 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1492 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1561 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1512 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1562 // Tests that cancelling StopNotifySession works. | 1513 // Tests that cancelling StopNotifySession works. |
| 1563 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is | 1514 // TODO(crbug.com/636270): Enable on Windows when SubscribeToNotifications is |
| 1564 // implemented. | 1515 // implemented. |
| 1565 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { | 1516 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Cancelled) { |
| 1566 if (!PlatformSupportsLowEnergy()) { | 1517 if (!PlatformSupportsLowEnergy()) { |
| 1567 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1518 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1568 return; | 1519 return; |
| 1569 } | 1520 } |
| 1570 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1521 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1571 /* properties: NOTIFY */ 0x10, | 1522 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1572 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1573 | 1523 |
| 1574 // Check that the session is correctly setup. | 1524 // Check that the session is correctly setup. |
| 1575 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1525 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1576 EXPECT_EQ(characteristic_identifier, | 1526 EXPECT_EQ(characteristic_identifier, |
| 1577 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1527 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1578 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1528 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1579 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1529 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1580 | 1530 |
| 1581 // Queue a Stop request. | 1531 // Queue a Stop request. |
| 1582 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1532 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1583 | 1533 |
| 1584 // Cancel Stop by deleting the device before Stop finishes. | 1534 // Cancel Stop by deleting the device before Stop finishes. |
| 1585 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1535 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1586 } | 1536 } |
| 1587 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1537 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1588 | 1538 |
| 1589 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1539 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1590 // Tests that deleted sessions are stopped. | 1540 // Tests that deleted sessions are stopped. |
| 1591 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { | 1541 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_AfterDeleted) { |
| 1592 if (!PlatformSupportsLowEnergy()) { | 1542 if (!PlatformSupportsLowEnergy()) { |
| 1593 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1543 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1594 return; | 1544 return; |
| 1595 } | 1545 } |
| 1596 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1546 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1597 /* properties: NOTIFY */ 0x10, | 1547 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1598 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1599 | 1548 |
| 1600 // Check that the session is correctly setup | 1549 // Check that the session is correctly setup |
| 1601 std::string characteristic_identifier = characteristic1_->GetIdentifier(); | 1550 std::string characteristic_identifier = characteristic1_->GetIdentifier(); |
| 1602 EXPECT_EQ(characteristic_identifier, | 1551 EXPECT_EQ(characteristic_identifier, |
| 1603 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1552 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1604 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1553 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1605 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1554 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1606 | 1555 |
| 1607 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1556 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1608 | 1557 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1625 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1574 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1626 | 1575 |
| 1627 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1576 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1628 // Tests StopNotifySession success on a characteristic that enabled Indicate. | 1577 // Tests StopNotifySession success on a characteristic that enabled Indicate. |
| 1629 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { | 1578 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_OnIndicate) { |
| 1630 if (!PlatformSupportsLowEnergy()) { | 1579 if (!PlatformSupportsLowEnergy()) { |
| 1631 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1580 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1632 return; | 1581 return; |
| 1633 } | 1582 } |
| 1634 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1583 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1635 /* properties: INDICATE */ 0x20, | 1584 /* properties: INDICATE */ 0x20, NotifyValueState::INDICATE)); |
| 1636 /* expected_config_descriptor_value: INDICATE */ 2)); | 1585 ExpectedChangeNotifyValueAttempts(1); |
| 1637 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1586 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 | 1587 |
| 1647 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1588 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1648 SimulateGattNotifySessionStopped(characteristic1_); | 1589 SimulateGattNotifySessionStopped(characteristic1_); |
| 1649 base::RunLoop().RunUntilIdle(); | 1590 base::RunLoop().RunUntilIdle(); |
| 1650 | 1591 |
| 1651 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1592 ExpectedChangeNotifyValueAttempts(2); |
| 1652 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1593 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 | 1594 |
| 1665 // Check that the notify session is inactive. | 1595 // Check that the notify session is inactive. |
| 1666 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1596 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1667 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1597 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1668 } | 1598 } |
| 1669 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1599 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1670 | 1600 |
| 1671 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1601 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1672 // Tests StopNotifySession success on a characteristic that enabled Notify & | 1602 // Tests StopNotifySession success on a characteristic that enabled Notify & |
| 1673 // Indicate. | 1603 // Indicate. |
| 1674 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1604 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1675 StopNotifySession_OnNotifyAndIndicate) { | 1605 StopNotifySession_OnNotifyAndIndicate) { |
| 1676 if (!PlatformSupportsLowEnergy()) { | 1606 if (!PlatformSupportsLowEnergy()) { |
| 1677 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1607 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1678 return; | 1608 return; |
| 1679 } | 1609 } |
| 1680 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1610 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1681 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 1611 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 1682 /* expected_config_descriptor_value: INDICATE */ 1)); | 1612 NotifyValueState::NOTIFY)); |
| 1683 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1613 ExpectedChangeNotifyValueAttempts(1); |
| 1684 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1614 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 | 1615 |
| 1693 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1616 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1694 SimulateGattNotifySessionStopped(characteristic1_); | 1617 SimulateGattNotifySessionStopped(characteristic1_); |
| 1695 base::RunLoop().RunUntilIdle(); | 1618 base::RunLoop().RunUntilIdle(); |
| 1696 | 1619 |
| 1697 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1620 ExpectedChangeNotifyValueAttempts(2); |
| 1698 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1621 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 | 1622 |
| 1711 // Check that the notify session is inactive. | 1623 // Check that the notify session is inactive. |
| 1712 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1624 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 1713 EXPECT_FALSE(characteristic1_->IsNotifying()); | 1625 EXPECT_FALSE(characteristic1_->IsNotifying()); |
| 1714 } | 1626 } |
| 1715 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1627 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1716 | 1628 |
| 1717 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1629 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1718 // Tests StopNotifySession error | 1630 // Tests StopNotifySession error |
| 1719 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { | 1631 TEST_F(BluetoothRemoteGattCharacteristicTest, StopNotifySession_Error) { |
| 1720 if (!PlatformSupportsLowEnergy()) { | 1632 if (!PlatformSupportsLowEnergy()) { |
| 1721 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1633 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1722 return; | 1634 return; |
| 1723 } | 1635 } |
| 1724 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1636 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1725 /* properties: NOTIFY */ 0x10, | 1637 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1726 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1727 | 1638 |
| 1728 // Check that the notify session is active. | 1639 // Check that the notify session is active. |
| 1729 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1640 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1730 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1641 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1731 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1642 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1732 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1643 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1733 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1644 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1734 | 1645 |
| 1735 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); | 1646 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED)); |
| 1736 SimulateGattNotifySessionStopError( | 1647 SimulateGattNotifySessionStopError( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1759 .canonical_value()); | 1670 .canonical_value()); |
| 1760 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 1671 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 1761 | 1672 |
| 1762 // Start notify session | 1673 // Start notify session |
| 1763 characteristic1_->StartNotifySession( | 1674 characteristic1_->StartNotifySession( |
| 1764 GetNotifyCallback(Call::EXPECTED), | 1675 GetNotifyCallback(Call::EXPECTED), |
| 1765 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1676 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1766 EXPECT_EQ(0, callback_count_); | 1677 EXPECT_EQ(0, callback_count_); |
| 1767 SimulateGattNotifySessionStarted(characteristic1_); | 1678 SimulateGattNotifySessionStarted(characteristic1_); |
| 1768 base::RunLoop().RunUntilIdle(); | 1679 base::RunLoop().RunUntilIdle(); |
| 1769 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1680 ExpectedChangeNotifyValueAttempts(1); |
| 1681 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1770 EXPECT_EQ(1, callback_count_); | 1682 EXPECT_EQ(1, callback_count_); |
| 1771 EXPECT_EQ(0, error_callback_count_); | 1683 EXPECT_EQ(0, error_callback_count_); |
| 1772 ASSERT_EQ(1u, notify_sessions_.size()); | 1684 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1773 ASSERT_TRUE(notify_sessions_[0]); | 1685 ASSERT_TRUE(notify_sessions_[0]); |
| 1774 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1686 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1775 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1687 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1776 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1688 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1777 | 1689 |
| 1778 // Stop the notify session twice | 1690 // Stop the notify session twice |
| 1779 ResetEventCounts(); | 1691 ResetEventCounts(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1807 // Start notify sessions | 1719 // Start notify sessions |
| 1808 characteristic1_->StartNotifySession( | 1720 characteristic1_->StartNotifySession( |
| 1809 GetNotifyCheckForPrecedingCalls(0), | 1721 GetNotifyCheckForPrecedingCalls(0), |
| 1810 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1722 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1811 characteristic1_->StartNotifySession( | 1723 characteristic1_->StartNotifySession( |
| 1812 GetNotifyCheckForPrecedingCalls(1), | 1724 GetNotifyCheckForPrecedingCalls(1), |
| 1813 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1725 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1814 EXPECT_EQ(0, callback_count_); | 1726 EXPECT_EQ(0, callback_count_); |
| 1815 SimulateGattNotifySessionStarted(characteristic1_); | 1727 SimulateGattNotifySessionStarted(characteristic1_); |
| 1816 base::RunLoop().RunUntilIdle(); | 1728 base::RunLoop().RunUntilIdle(); |
| 1817 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 1729 ExpectedChangeNotifyValueAttempts(1); |
| 1730 ExpectedNotifyValue(NotifyValueState::NOTIFY); |
| 1818 EXPECT_EQ(2, callback_count_); | 1731 EXPECT_EQ(2, callback_count_); |
| 1819 EXPECT_EQ(0, error_callback_count_); | 1732 EXPECT_EQ(0, error_callback_count_); |
| 1820 ASSERT_EQ(2u, notify_sessions_.size()); | 1733 ASSERT_EQ(2u, notify_sessions_.size()); |
| 1821 ASSERT_TRUE(notify_sessions_[0]); | 1734 ASSERT_TRUE(notify_sessions_[0]); |
| 1822 ASSERT_TRUE(notify_sessions_[1]); | 1735 ASSERT_TRUE(notify_sessions_[1]); |
| 1823 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1736 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1824 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); | 1737 EXPECT_EQ(characteristic1_, notify_sessions_[1]->GetCharacteristic()); |
| 1825 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1738 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1826 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1739 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 1827 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1740 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) | 1808 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1896 | 1809 |
| 1897 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1810 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1898 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1811 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1899 StopNotifySession_StartStopStart) { | 1812 StopNotifySession_StartStopStart) { |
| 1900 if (!PlatformSupportsLowEnergy()) { | 1813 if (!PlatformSupportsLowEnergy()) { |
| 1901 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1814 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1902 return; | 1815 return; |
| 1903 } | 1816 } |
| 1904 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1817 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1905 /* properties: NOTIFY */ 0x10, | 1818 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 1906 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 1907 | 1819 |
| 1908 // Check that the initial notify session is active. | 1820 // Check that the initial notify session is active. |
| 1909 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1821 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1910 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1822 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 1911 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1823 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 1912 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1824 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 1913 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1825 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 1914 | 1826 |
| 1915 // Queue up the first event. | 1827 // Queue up the first event. |
| 1916 ResetEventCounts(); | 1828 ResetEventCounts(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1969 // Start notify session | 1881 // Start notify session |
| 1970 ResetEventCounts(); | 1882 ResetEventCounts(); |
| 1971 characteristic1_->StartNotifySession( | 1883 characteristic1_->StartNotifySession( |
| 1972 GetNotifyCheckForPrecedingCalls(0), | 1884 GetNotifyCheckForPrecedingCalls(0), |
| 1973 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1885 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 1974 SimulateGattNotifySessionStarted(characteristic1_); | 1886 SimulateGattNotifySessionStarted(characteristic1_); |
| 1975 base::RunLoop().RunUntilIdle(); | 1887 base::RunLoop().RunUntilIdle(); |
| 1976 ASSERT_EQ(1u, notify_sessions_.size()); | 1888 ASSERT_EQ(1u, notify_sessions_.size()); |
| 1977 ASSERT_TRUE(notify_sessions_[0]); | 1889 ASSERT_TRUE(notify_sessions_[0]); |
| 1978 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1890 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 1979 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1891 ExpectedChangeNotifyValueAttempts(1); |
| 1980 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1892 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 | 1893 |
| 1989 // Stop the notify session twice | 1894 // Stop the notify session twice |
| 1990 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); | 1895 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(1)); |
| 1991 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(2)); | 1896 notify_sessions_[0]->Stop(GetStopNotifyCheckForPrecedingCalls(2)); |
| 1992 | 1897 |
| 1993 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1898 ExpectedChangeNotifyValueAttempts(2); |
| 1994 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1899 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 | 1900 |
| 2007 // Start another notify session | 1901 // Start another notify session |
| 2008 characteristic1_->StartNotifySession( | 1902 characteristic1_->StartNotifySession( |
| 2009 GetNotifyCheckForPrecedingCalls(3), | 1903 GetNotifyCheckForPrecedingCalls(3), |
| 2010 GetGattErrorCallback(Call::NOT_EXPECTED)); | 1904 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 2011 | 1905 |
| 2012 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1906 ExpectedChangeNotifyValueAttempts(2); |
| 2013 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1907 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 | 1908 |
| 2022 SimulateGattNotifySessionStopped(characteristic1_); | 1909 SimulateGattNotifySessionStopped(characteristic1_); |
| 2023 base::RunLoop().RunUntilIdle(); | 1910 base::RunLoop().RunUntilIdle(); |
| 2024 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1911 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 2025 | 1912 |
| 2026 SimulateGattNotifySessionStarted(characteristic1_); | 1913 SimulateGattNotifySessionStarted(characteristic1_); |
| 2027 base::RunLoop().RunUntilIdle(); | 1914 base::RunLoop().RunUntilIdle(); |
| 2028 | 1915 |
| 2029 // macOS: Not applicable. CoreBluetooth exposes -[CBPeripheral | 1916 ExpectedChangeNotifyValueAttempts(3); |
| 2030 // setNotifyValue:forCharacteristic:] which handles all interactions with | 1917 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 | 1918 |
| 2043 // Check the notify state | 1919 // Check the notify state |
| 2044 ASSERT_EQ(2u, notify_sessions_.size()); | 1920 ASSERT_EQ(2u, notify_sessions_.size()); |
| 2045 ASSERT_TRUE(notify_sessions_[0]); | 1921 ASSERT_TRUE(notify_sessions_[0]); |
| 2046 EXPECT_FALSE(notify_sessions_[0]->IsActive()); | 1922 EXPECT_FALSE(notify_sessions_[0]->IsActive()); |
| 2047 ASSERT_TRUE(notify_sessions_[1]); | 1923 ASSERT_TRUE(notify_sessions_[1]); |
| 2048 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 1924 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 2049 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1925 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 2050 } | 1926 } |
| 2051 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1927 #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) | 1971 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2096 | 1972 |
| 2097 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1973 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2098 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1974 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2099 StopNotifySession_Reentrant_Stop_StartSuccess) { | 1975 StopNotifySession_Reentrant_Stop_StartSuccess) { |
| 2100 if (!PlatformSupportsLowEnergy()) { | 1976 if (!PlatformSupportsLowEnergy()) { |
| 2101 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1977 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2102 return; | 1978 return; |
| 2103 } | 1979 } |
| 2104 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1980 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2105 /* properties: NOTIFY */ 0x10, | 1981 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2106 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2107 | 1982 |
| 2108 // Check that the notify session is active. | 1983 // Check that the notify session is active. |
| 2109 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 1984 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 2110 EXPECT_EQ(characteristic1_->GetIdentifier(), | 1985 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 2111 notify_sessions_[0]->GetCharacteristicIdentifier()); | 1986 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 2112 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 1987 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 2113 EXPECT_TRUE(characteristic1_->IsNotifying()); | 1988 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 2114 | 1989 |
| 2115 notify_sessions_[0]->Stop(base::Bind( | 1990 notify_sessions_[0]->Stop(base::Bind( |
| 2116 [](BluetoothRemoteGattCharacteristic* characteristic, | 1991 [](BluetoothRemoteGattCharacteristic* characteristic, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2141 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 2016 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2142 | 2017 |
| 2143 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 2018 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2144 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2019 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2145 StopNotifySession_Reentrant_Stop_StartError) { | 2020 StopNotifySession_Reentrant_Stop_StartError) { |
| 2146 if (!PlatformSupportsLowEnergy()) { | 2021 if (!PlatformSupportsLowEnergy()) { |
| 2147 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 2022 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2148 return; | 2023 return; |
| 2149 } | 2024 } |
| 2150 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2025 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2151 /* properties: NOTIFY */ 0x10, | 2026 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2152 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2153 | 2027 |
| 2154 // Check that the notify session is active. | 2028 // Check that the notify session is active. |
| 2155 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 2029 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 2156 EXPECT_EQ(characteristic1_->GetIdentifier(), | 2030 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 2157 notify_sessions_[0]->GetCharacteristicIdentifier()); | 2031 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 2158 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); | 2032 EXPECT_EQ(characteristic1_, notify_sessions_[0]->GetCharacteristic()); |
| 2159 EXPECT_TRUE(characteristic1_->IsNotifying()); | 2033 EXPECT_TRUE(characteristic1_->IsNotifying()); |
| 2160 | 2034 |
| 2161 notify_sessions_[0]->Stop(base::Bind( | 2035 notify_sessions_[0]->Stop(base::Bind( |
| 2162 [](BluetoothRemoteGattCharacteristic* characteristic, | 2036 [](BluetoothRemoteGattCharacteristic* characteristic, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2185 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 2059 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 2186 | 2060 |
| 2187 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 2061 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 2188 // Tests Characteristic Value changes during a Notify Session. | 2062 // Tests Characteristic Value changes during a Notify Session. |
| 2189 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { | 2063 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { |
| 2190 if (!PlatformSupportsLowEnergy()) { | 2064 if (!PlatformSupportsLowEnergy()) { |
| 2191 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 2065 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2192 return; | 2066 return; |
| 2193 } | 2067 } |
| 2194 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2068 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2195 /* properties: NOTIFY */ 0x10, | 2069 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2196 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2197 | 2070 |
| 2198 TestBluetoothAdapterObserver observer(adapter_); | 2071 TestBluetoothAdapterObserver observer(adapter_); |
| 2199 | 2072 |
| 2200 std::vector<uint8_t> test_vector1, test_vector2; | 2073 std::vector<uint8_t> test_vector1, test_vector2; |
| 2201 test_vector1.push_back(111); | 2074 test_vector1.push_back(111); |
| 2202 test_vector2.push_back(222); | 2075 test_vector2.push_back(222); |
| 2203 | 2076 |
| 2204 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); | 2077 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); |
| 2205 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 2078 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 2206 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 2079 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 2207 | 2080 |
| 2208 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); | 2081 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); |
| 2209 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 2082 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| 2210 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); | 2083 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| 2211 } | 2084 } |
| 2212 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 2085 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 2213 | 2086 |
| 2214 #if defined(OS_ANDROID) || defined(OS_WIN) | 2087 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 2215 // Tests Characteristic Value changing after a Notify Session and objects being | 2088 // Tests Characteristic Value changing after a Notify Session and objects being |
| 2216 // destroyed. | 2089 // destroyed. |
| 2217 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set | 2090 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set |
| 2218 // to nil. | 2091 // to nil. |
| 2219 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2092 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2220 GattCharacteristicValueChanged_AfterDeleted) { | 2093 GattCharacteristicValueChanged_AfterDeleted) { |
| 2221 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2094 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2222 /* properties: NOTIFY */ 0x10, | 2095 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2223 /* expected_config_descriptor_value: NOTIFY */ 1)); | |
| 2224 TestBluetoothAdapterObserver observer(adapter_); | 2096 TestBluetoothAdapterObserver observer(adapter_); |
| 2225 | 2097 |
| 2226 RememberCharacteristicForSubsequentAction(characteristic1_); | 2098 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 2227 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 2099 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 2228 | 2100 |
| 2229 std::vector<uint8_t> empty_vector; | 2101 std::vector<uint8_t> empty_vector; |
| 2230 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, | 2102 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, |
| 2231 empty_vector); | 2103 empty_vector); |
| 2232 EXPECT_TRUE("Did not crash!"); | 2104 EXPECT_TRUE("Did not crash!"); |
| 2233 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 2105 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()); | 2184 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 2313 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 2185 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 2314 | 2186 |
| 2315 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 2187 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 2316 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 2188 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 2317 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 2189 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 2318 } | 2190 } |
| 2319 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 2191 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 2320 | 2192 |
| 2321 } // namespace device | 2193 } // namespace device |
| OLD | NEW |