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

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

Issue 1898643002: Refactor device::BluetoothGattXXX classes to split into remote/local. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
6
7 #include <stdint.h> 5 #include <stdint.h>
6 #include <utility>
8 7
9 #include "base/macros.h" 8 #include "base/macros.h"
10 #include "base/run_loop.h" 9 #include "base/run_loop.h"
11 #include "build/build_config.h" 10 #include "build/build_config.h"
12 #include "device/bluetooth/bluetooth_gatt_service.h" 11 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
12 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
13 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 13 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #if defined(OS_ANDROID) 16 #if defined(OS_ANDROID)
17 #include "device/bluetooth/test/bluetooth_test_android.h" 17 #include "device/bluetooth/test/bluetooth_test_android.h"
18 #elif defined(OS_MACOSX) 18 #elif defined(OS_MACOSX)
19 #include "device/bluetooth/test/bluetooth_test_mac.h" 19 #include "device/bluetooth/test/bluetooth_test_mac.h"
20 #elif defined(OS_WIN) 20 #elif defined(OS_WIN)
21 #include "device/bluetooth/test/bluetooth_test_win.h" 21 #include "device/bluetooth/test/bluetooth_test_win.h"
22 #endif 22 #endif
23 23
24 namespace device { 24 namespace device {
25 25
26 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 26 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
27 class BluetoothGattCharacteristicTest : public BluetoothTest { 27 class BluetoothRemoteGattCharacteristicTest : public BluetoothTest {
28 public: 28 public:
29 // Creates adapter_, device_, service_, characteristic1_, & characteristic2_. 29 // Creates adapter_, device_, service_, characteristic1_, & characteristic2_.
30 // |properties| will be used for each characteristic. 30 // |properties| will be used for each characteristic.
31 void FakeCharacteristicBoilerplate(int properties = 0) { 31 void FakeCharacteristicBoilerplate(int properties = 0) {
32 InitWithFakeAdapter(); 32 InitWithFakeAdapter();
33 StartLowEnergyDiscoverySession(); 33 StartLowEnergyDiscoverySession();
34 device_ = DiscoverLowEnergyDevice(3); 34 device_ = DiscoverLowEnergyDevice(3);
35 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 35 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
36 GetConnectErrorCallback(Call::NOT_EXPECTED)); 36 GetConnectErrorCallback(Call::NOT_EXPECTED));
37 SimulateGattConnection(device_); 37 SimulateGattConnection(device_);
(...skipping 29 matching lines...) Expand all
67 StartNotifySetupError error = StartNotifySetupError::NONE) { 67 StartNotifySetupError error = StartNotifySetupError::NONE) {
68 if (error == StartNotifySetupError::CHARACTERISTIC_PROPERTIES) { 68 if (error == StartNotifySetupError::CHARACTERISTIC_PROPERTIES) {
69 properties = 0; 69 properties = 0;
70 } 70 }
71 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(properties)); 71 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(properties));
72 72
73 size_t expected_descriptors_count = 0; 73 size_t expected_descriptors_count = 0;
74 if (error != StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING) { 74 if (error != StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING) {
75 SimulateGattDescriptor( 75 SimulateGattDescriptor(
76 characteristic1_, 76 characteristic1_,
77 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() 77 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
78 .canonical_value()); 78 .canonical_value());
79 expected_descriptors_count++; 79 expected_descriptors_count++;
80 } 80 }
81 if (error == StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE) { 81 if (error == StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE) {
82 SimulateGattDescriptor( 82 SimulateGattDescriptor(
83 characteristic1_, 83 characteristic1_,
84 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() 84 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
85 .canonical_value()); 85 .canonical_value());
86 expected_descriptors_count++; 86 expected_descriptors_count++;
87 } 87 }
88 ASSERT_EQ(expected_descriptors_count, 88 ASSERT_EQ(expected_descriptors_count,
89 characteristic1_->GetDescriptors().size()); 89 characteristic1_->GetDescriptors().size());
90 90
91 if (error == StartNotifySetupError::SET_NOTIFY) { 91 if (error == StartNotifySetupError::SET_NOTIFY) {
92 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( 92 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
93 characteristic1_); 93 characteristic1_);
94 } 94 }
(...skipping 28 matching lines...) Expand all
123 // Verify the Client Characteristic Configuration descriptor was written to. 123 // Verify the Client Characteristic Configuration descriptor was written to.
124 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 124 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
125 EXPECT_EQ(2u, last_write_value_.size()); 125 EXPECT_EQ(2u, last_write_value_.size());
126 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF; 126 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF;
127 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF; 127 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF;
128 EXPECT_EQ(expected_byte0, last_write_value_[0]); 128 EXPECT_EQ(expected_byte0, last_write_value_[0]);
129 EXPECT_EQ(expected_byte1, last_write_value_[1]); 129 EXPECT_EQ(expected_byte1, last_write_value_[1]);
130 } 130 }
131 131
132 BluetoothDevice* device_ = nullptr; 132 BluetoothDevice* device_ = nullptr;
133 BluetoothGattService* service_ = nullptr; 133 BluetoothRemoteGattService* service_ = nullptr;
134 BluetoothGattCharacteristic* characteristic1_ = nullptr; 134 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr;
135 BluetoothGattCharacteristic* characteristic2_ = nullptr; 135 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr;
136 }; 136 };
137 #endif 137 #endif
138 138
139 #if defined(OS_ANDROID) || defined(OS_WIN) 139 #if defined(OS_ANDROID) || defined(OS_WIN)
140 TEST_F(BluetoothGattCharacteristicTest, GetIdentifier) { 140 TEST_F(BluetoothRemoteGattCharacteristicTest, GetIdentifier) {
141 InitWithFakeAdapter(); 141 InitWithFakeAdapter();
142 StartLowEnergyDiscoverySession(); 142 StartLowEnergyDiscoverySession();
143 // 2 devices to verify unique IDs across them. 143 // 2 devices to verify unique IDs across them.
144 BluetoothDevice* device1 = DiscoverLowEnergyDevice(3); 144 BluetoothDevice* device1 = DiscoverLowEnergyDevice(3);
145 BluetoothDevice* device2 = DiscoverLowEnergyDevice(4); 145 BluetoothDevice* device2 = DiscoverLowEnergyDevice(4);
146 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 146 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
147 GetConnectErrorCallback(Call::NOT_EXPECTED)); 147 GetConnectErrorCallback(Call::NOT_EXPECTED));
148 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 148 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
149 GetConnectErrorCallback(Call::NOT_EXPECTED)); 149 GetConnectErrorCallback(Call::NOT_EXPECTED));
150 SimulateGattConnection(device1); 150 SimulateGattConnection(device1);
151 SimulateGattConnection(device2); 151 SimulateGattConnection(device2);
152 152
153 // 3 services (all with same UUID). 153 // 3 services (all with same UUID).
154 // 1 on the first device (to test characteristic instances across devices). 154 // 1 on the first device (to test characteristic instances across devices).
155 // 2 on the second device (to test same device, multiple service instances). 155 // 2 on the second device (to test same device, multiple service instances).
156 std::vector<std::string> services; 156 std::vector<std::string> services;
157 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; 157 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb";
158 services.push_back(uuid); 158 services.push_back(uuid);
159 SimulateGattServicesDiscovered(device1, services); 159 SimulateGattServicesDiscovered(device1, services);
160 services.push_back(uuid); 160 services.push_back(uuid);
161 SimulateGattServicesDiscovered(device2, services); 161 SimulateGattServicesDiscovered(device2, services);
162 BluetoothGattService* service1 = device1->GetGattServices()[0]; 162 BluetoothRemoteGattService* service1 = device1->GetGattServices()[0];
163 BluetoothGattService* service2 = device2->GetGattServices()[0]; 163 BluetoothRemoteGattService* service2 = device2->GetGattServices()[0];
164 BluetoothGattService* service3 = device2->GetGattServices()[1]; 164 BluetoothRemoteGattService* service3 = device2->GetGattServices()[1];
165 // 6 characteristics (same UUID), 2 on each service. 165 // 6 characteristics (same UUID), 2 on each service.
166 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); 166 SimulateGattCharacteristic(service1, uuid, /* properties */ 0);
167 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); 167 SimulateGattCharacteristic(service1, uuid, /* properties */ 0);
168 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); 168 SimulateGattCharacteristic(service2, uuid, /* properties */ 0);
169 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); 169 SimulateGattCharacteristic(service2, uuid, /* properties */ 0);
170 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 170 SimulateGattCharacteristic(service3, uuid, /* properties */ 0);
171 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 171 SimulateGattCharacteristic(service3, uuid, /* properties */ 0);
172 BluetoothGattCharacteristic* char1 = service1->GetCharacteristics()[0]; 172 BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0];
173 BluetoothGattCharacteristic* char2 = service1->GetCharacteristics()[1]; 173 BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1];
174 BluetoothGattCharacteristic* char3 = service2->GetCharacteristics()[0]; 174 BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0];
175 BluetoothGattCharacteristic* char4 = service2->GetCharacteristics()[1]; 175 BluetoothRemoteGattCharacteristic* char4 = service2->GetCharacteristics()[1];
176 BluetoothGattCharacteristic* char5 = service3->GetCharacteristics()[0]; 176 BluetoothRemoteGattCharacteristic* char5 = service3->GetCharacteristics()[0];
177 BluetoothGattCharacteristic* char6 = service3->GetCharacteristics()[1]; 177 BluetoothRemoteGattCharacteristic* char6 = service3->GetCharacteristics()[1];
178 178
179 // All IDs are unique, even though they have the same UUID. 179 // All IDs are unique, even though they have the same UUID.
180 EXPECT_NE(char1->GetIdentifier(), char2->GetIdentifier()); 180 EXPECT_NE(char1->GetIdentifier(), char2->GetIdentifier());
181 EXPECT_NE(char1->GetIdentifier(), char3->GetIdentifier()); 181 EXPECT_NE(char1->GetIdentifier(), char3->GetIdentifier());
182 EXPECT_NE(char1->GetIdentifier(), char4->GetIdentifier()); 182 EXPECT_NE(char1->GetIdentifier(), char4->GetIdentifier());
183 EXPECT_NE(char1->GetIdentifier(), char5->GetIdentifier()); 183 EXPECT_NE(char1->GetIdentifier(), char5->GetIdentifier());
184 EXPECT_NE(char1->GetIdentifier(), char6->GetIdentifier()); 184 EXPECT_NE(char1->GetIdentifier(), char6->GetIdentifier());
185 185
186 EXPECT_NE(char2->GetIdentifier(), char3->GetIdentifier()); 186 EXPECT_NE(char2->GetIdentifier(), char3->GetIdentifier());
187 EXPECT_NE(char2->GetIdentifier(), char4->GetIdentifier()); 187 EXPECT_NE(char2->GetIdentifier(), char4->GetIdentifier());
188 EXPECT_NE(char2->GetIdentifier(), char5->GetIdentifier()); 188 EXPECT_NE(char2->GetIdentifier(), char5->GetIdentifier());
189 EXPECT_NE(char2->GetIdentifier(), char6->GetIdentifier()); 189 EXPECT_NE(char2->GetIdentifier(), char6->GetIdentifier());
190 190
191 EXPECT_NE(char3->GetIdentifier(), char4->GetIdentifier()); 191 EXPECT_NE(char3->GetIdentifier(), char4->GetIdentifier());
192 EXPECT_NE(char3->GetIdentifier(), char5->GetIdentifier()); 192 EXPECT_NE(char3->GetIdentifier(), char5->GetIdentifier());
193 EXPECT_NE(char3->GetIdentifier(), char6->GetIdentifier()); 193 EXPECT_NE(char3->GetIdentifier(), char6->GetIdentifier());
194 194
195 EXPECT_NE(char4->GetIdentifier(), char5->GetIdentifier()); 195 EXPECT_NE(char4->GetIdentifier(), char5->GetIdentifier());
196 EXPECT_NE(char4->GetIdentifier(), char6->GetIdentifier()); 196 EXPECT_NE(char4->GetIdentifier(), char6->GetIdentifier());
197 197
198 EXPECT_NE(char5->GetIdentifier(), char6->GetIdentifier()); 198 EXPECT_NE(char5->GetIdentifier(), char6->GetIdentifier());
199 } 199 }
200 #endif // defined(OS_ANDROID) || defined(OS_WIN) 200 #endif // defined(OS_ANDROID) || defined(OS_WIN)
201 201
202 #if defined(OS_ANDROID) || defined(OS_WIN) 202 #if defined(OS_ANDROID) || defined(OS_WIN)
203 TEST_F(BluetoothGattCharacteristicTest, GetUUID) { 203 TEST_F(BluetoothRemoteGattCharacteristicTest, GetUUID) {
204 InitWithFakeAdapter(); 204 InitWithFakeAdapter();
205 StartLowEnergyDiscoverySession(); 205 StartLowEnergyDiscoverySession();
206 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 206 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
207 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 207 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
208 GetConnectErrorCallback(Call::NOT_EXPECTED)); 208 GetConnectErrorCallback(Call::NOT_EXPECTED));
209 SimulateGattConnection(device); 209 SimulateGattConnection(device);
210 std::vector<std::string> services; 210 std::vector<std::string> services;
211 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); 211 services.push_back("00000000-0000-1000-8000-00805f9b34fb");
212 SimulateGattServicesDiscovered(device, services); 212 SimulateGattServicesDiscovered(device, services);
213 BluetoothGattService* service = device->GetGattServices()[0]; 213 BluetoothRemoteGattService* service = device->GetGattServices()[0];
214 214
215 // Create 3 characteristics. Two of them are duplicates. 215 // Create 3 characteristics. Two of them are duplicates.
216 std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); 216 std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb");
217 std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); 217 std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb");
218 BluetoothUUID uuid1(uuid_str1); 218 BluetoothUUID uuid1(uuid_str1);
219 BluetoothUUID uuid2(uuid_str2); 219 BluetoothUUID uuid2(uuid_str2);
220 SimulateGattCharacteristic(service, uuid_str1, /* properties */ 0); 220 SimulateGattCharacteristic(service, uuid_str1, /* properties */ 0);
221 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0); 221 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0);
222 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0); 222 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0);
223 BluetoothGattCharacteristic* char1 = service->GetCharacteristics()[0]; 223 BluetoothRemoteGattCharacteristic* char1 = service->GetCharacteristics()[0];
224 BluetoothGattCharacteristic* char2 = service->GetCharacteristics()[1]; 224 BluetoothRemoteGattCharacteristic* char2 = service->GetCharacteristics()[1];
225 BluetoothGattCharacteristic* char3 = service->GetCharacteristics()[2]; 225 BluetoothRemoteGattCharacteristic* char3 = service->GetCharacteristics()[2];
226 226
227 // Swap as needed to have char1 point to the the characteristic with uuid1. 227 // Swap as needed to have char1 point to the the characteristic with uuid1.
228 if (char2->GetUUID() == uuid1) { 228 if (char2->GetUUID() == uuid1) {
229 std::swap(char1, char2); 229 std::swap(char1, char2);
230 } else if (char3->GetUUID() == uuid1) { 230 } else if (char3->GetUUID() == uuid1) {
231 std::swap(char1, char3); 231 std::swap(char1, char3);
232 } 232 }
233 233
234 EXPECT_EQ(uuid1, char1->GetUUID()); 234 EXPECT_EQ(uuid1, char1->GetUUID());
235 EXPECT_EQ(uuid2, char2->GetUUID()); 235 EXPECT_EQ(uuid2, char2->GetUUID());
236 EXPECT_EQ(uuid2, char3->GetUUID()); 236 EXPECT_EQ(uuid2, char3->GetUUID());
237 } 237 }
238 #endif // defined(OS_ANDROID) || defined(OS_WIN) 238 #endif // defined(OS_ANDROID) || defined(OS_WIN)
239 239
240 #if defined(OS_ANDROID) || defined(OS_WIN) 240 #if defined(OS_ANDROID) || defined(OS_WIN)
241 TEST_F(BluetoothGattCharacteristicTest, GetProperties) { 241 TEST_F(BluetoothRemoteGattCharacteristicTest, GetProperties) {
242 InitWithFakeAdapter(); 242 InitWithFakeAdapter();
243 StartLowEnergyDiscoverySession(); 243 StartLowEnergyDiscoverySession();
244 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 244 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
245 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 245 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
246 GetConnectErrorCallback(Call::NOT_EXPECTED)); 246 GetConnectErrorCallback(Call::NOT_EXPECTED));
247 SimulateGattConnection(device); 247 SimulateGattConnection(device);
248 std::vector<std::string> services; 248 std::vector<std::string> services;
249 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); 249 std::string uuid("00000000-0000-1000-8000-00805f9b34fb");
250 services.push_back(uuid); 250 services.push_back(uuid);
251 SimulateGattServicesDiscovered(device, services); 251 SimulateGattServicesDiscovered(device, services);
252 BluetoothGattService* service = device->GetGattServices()[0]; 252 BluetoothRemoteGattService* service = device->GetGattServices()[0];
253 253
254 // Create two characteristics with different properties: 254 // Create two characteristics with different properties:
255 SimulateGattCharacteristic(service, uuid, /* properties */ 0); 255 SimulateGattCharacteristic(service, uuid, /* properties */ 0);
256 SimulateGattCharacteristic(service, uuid, /* properties */ 7); 256 SimulateGattCharacteristic(service, uuid, /* properties */ 7);
257 257
258 // Read the properties. Because ordering is unknown swap as necessary. 258 // Read the properties. Because ordering is unknown swap as necessary.
259 int properties1 = service->GetCharacteristics()[0]->GetProperties(); 259 int properties1 = service->GetCharacteristics()[0]->GetProperties();
260 int properties2 = service->GetCharacteristics()[1]->GetProperties(); 260 int properties2 = service->GetCharacteristics()[1]->GetProperties();
261 if (properties2 == 0) 261 if (properties2 == 0)
262 std::swap(properties1, properties2); 262 std::swap(properties1, properties2);
263 EXPECT_EQ(0, properties1); 263 EXPECT_EQ(0, properties1);
264 EXPECT_EQ(7, properties2); 264 EXPECT_EQ(7, properties2);
265 } 265 }
266 #endif // defined(OS_ANDROID) || defined(OS_WIN) 266 #endif // defined(OS_ANDROID) || defined(OS_WIN)
267 267
268 #if defined(OS_ANDROID) || defined(OS_WIN) 268 #if defined(OS_ANDROID) || defined(OS_WIN)
269 // Tests GetService. 269 // Tests GetService.
270 TEST_F(BluetoothGattCharacteristicTest, GetService) { 270 TEST_F(BluetoothRemoteGattCharacteristicTest, GetService) {
271 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 271 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
272 272
273 EXPECT_EQ(service_, characteristic1_->GetService()); 273 EXPECT_EQ(service_, characteristic1_->GetService());
274 EXPECT_EQ(service_, characteristic2_->GetService()); 274 EXPECT_EQ(service_, characteristic2_->GetService());
275 } 275 }
276 #endif // defined(OS_ANDROID) || defined(OS_WIN) 276 #endif // defined(OS_ANDROID) || defined(OS_WIN)
277 277
278 #if defined(OS_ANDROID) || defined(OS_WIN) 278 #if defined(OS_ANDROID) || defined(OS_WIN)
279 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. 279 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer.
280 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { 280 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Empty) {
281 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 281 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
282 BluetoothGattCharacteristic::PROPERTY_READ)); 282 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
283 283
284 characteristic1_->ReadRemoteCharacteristic( 284 characteristic1_->ReadRemoteCharacteristic(
285 GetReadValueCallback(Call::EXPECTED), 285 GetReadValueCallback(Call::EXPECTED),
286 GetGattErrorCallback(Call::NOT_EXPECTED)); 286 GetGattErrorCallback(Call::NOT_EXPECTED));
287 std::vector<uint8_t> empty_vector; 287 std::vector<uint8_t> empty_vector;
288 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 288 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
289 289
290 // Duplicate read reported from OS shouldn't cause a problem: 290 // Duplicate read reported from OS shouldn't cause a problem:
291 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 291 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
292 292
293 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 293 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
294 EXPECT_EQ(empty_vector, last_read_value_); 294 EXPECT_EQ(empty_vector, last_read_value_);
295 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 295 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
296 } 296 }
297 #endif // defined(OS_ANDROID) || defined(OS_WIN) 297 #endif // defined(OS_ANDROID) || defined(OS_WIN)
298 298
299 #if defined(OS_ANDROID) || defined(OS_WIN) 299 #if defined(OS_ANDROID) || defined(OS_WIN)
300 // Tests WriteRemoteCharacteristic with empty value buffer. 300 // Tests WriteRemoteCharacteristic with empty value buffer.
301 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { 301 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Empty) {
302 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 302 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
303 BluetoothGattCharacteristic::PROPERTY_WRITE)); 303 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
304 304
305 std::vector<uint8_t> empty_vector; 305 std::vector<uint8_t> empty_vector;
306 characteristic1_->WriteRemoteCharacteristic( 306 characteristic1_->WriteRemoteCharacteristic(
307 empty_vector, GetCallback(Call::EXPECTED), 307 empty_vector, GetCallback(Call::EXPECTED),
308 GetGattErrorCallback(Call::NOT_EXPECTED)); 308 GetGattErrorCallback(Call::NOT_EXPECTED));
309 SimulateGattCharacteristicWrite(characteristic1_); 309 SimulateGattCharacteristicWrite(characteristic1_);
310 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 310 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
311 311
312 // Duplicate write reported from OS shouldn't cause a problem: 312 // Duplicate write reported from OS shouldn't cause a problem:
313 SimulateGattCharacteristicWrite(characteristic1_); 313 SimulateGattCharacteristicWrite(characteristic1_);
314 314
315 EXPECT_EQ(empty_vector, last_write_value_); 315 EXPECT_EQ(empty_vector, last_write_value_);
316 } 316 }
317 #endif // defined(OS_ANDROID) || defined(OS_WIN) 317 #endif // defined(OS_ANDROID) || defined(OS_WIN)
318 318
319 #if defined(OS_ANDROID) || defined(OS_WIN) 319 #if defined(OS_ANDROID) || defined(OS_WIN)
320 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. 320 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted.
321 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_AfterDeleted) { 321 TEST_F(BluetoothRemoteGattCharacteristicTest,
322 ReadRemoteCharacteristic_AfterDeleted) {
322 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 323 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
323 BluetoothGattCharacteristic::PROPERTY_READ)); 324 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
324 325
325 characteristic1_->ReadRemoteCharacteristic( 326 characteristic1_->ReadRemoteCharacteristic(
326 GetReadValueCallback(Call::NOT_EXPECTED), 327 GetReadValueCallback(Call::NOT_EXPECTED),
327 GetGattErrorCallback(Call::NOT_EXPECTED)); 328 GetGattErrorCallback(Call::NOT_EXPECTED));
328 329
329 RememberCharacteristicForSubsequentAction(characteristic1_); 330 RememberCharacteristicForSubsequentAction(characteristic1_);
330 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 331 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
331 332
332 std::vector<uint8_t> empty_vector; 333 std::vector<uint8_t> empty_vector;
333 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, 334 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr,
334 empty_vector); 335 empty_vector);
335 EXPECT_TRUE("Did not crash!"); 336 EXPECT_TRUE("Did not crash!");
336 } 337 }
337 #endif // defined(OS_ANDROID) || defined(OS_WIN) 338 #endif // defined(OS_ANDROID) || defined(OS_WIN)
338 339
339 #if defined(OS_ANDROID) || defined(OS_WIN) 340 #if defined(OS_ANDROID) || defined(OS_WIN)
340 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. 341 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted.
341 TEST_F(BluetoothGattCharacteristicTest, 342 TEST_F(BluetoothRemoteGattCharacteristicTest,
342 WriteRemoteCharacteristic_AfterDeleted) { 343 WriteRemoteCharacteristic_AfterDeleted) {
343 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 344 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
344 BluetoothGattCharacteristic::PROPERTY_WRITE)); 345 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
345 346
346 std::vector<uint8_t> empty_vector; 347 std::vector<uint8_t> empty_vector;
347 characteristic1_->WriteRemoteCharacteristic( 348 characteristic1_->WriteRemoteCharacteristic(
348 empty_vector, GetCallback(Call::NOT_EXPECTED), 349 empty_vector, GetCallback(Call::NOT_EXPECTED),
349 GetGattErrorCallback(Call::NOT_EXPECTED)); 350 GetGattErrorCallback(Call::NOT_EXPECTED));
350 351
351 RememberCharacteristicForSubsequentAction(characteristic1_); 352 RememberCharacteristicForSubsequentAction(characteristic1_);
352 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 353 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
353 354
354 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); 355 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr);
355 EXPECT_TRUE("Did not crash!"); 356 EXPECT_TRUE("Did not crash!");
356 } 357 }
357 #endif // defined(OS_ANDROID) || defined(OS_WIN) 358 #endif // defined(OS_ANDROID) || defined(OS_WIN)
358 359
359 #if defined(OS_ANDROID) || defined(OS_WIN) 360 #if defined(OS_ANDROID) || defined(OS_WIN)
360 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. 361 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer.
361 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { 362 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) {
362 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 363 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
363 BluetoothGattCharacteristic::PROPERTY_READ)); 364 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
364 365
365 characteristic1_->ReadRemoteCharacteristic( 366 characteristic1_->ReadRemoteCharacteristic(
366 GetReadValueCallback(Call::EXPECTED), 367 GetReadValueCallback(Call::EXPECTED),
367 GetGattErrorCallback(Call::NOT_EXPECTED)); 368 GetGattErrorCallback(Call::NOT_EXPECTED));
368 369
369 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 370 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
370 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 371 std::vector<uint8_t> test_vector(values, values + arraysize(values));
371 SimulateGattCharacteristicRead(characteristic1_, test_vector); 372 SimulateGattCharacteristicRead(characteristic1_, test_vector);
372 373
373 // Duplicate read reported from OS shouldn't cause a problem: 374 // Duplicate read reported from OS shouldn't cause a problem:
374 std::vector<uint8_t> empty_vector; 375 std::vector<uint8_t> empty_vector;
375 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 376 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
376 377
377 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 378 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
378 EXPECT_EQ(test_vector, last_read_value_); 379 EXPECT_EQ(test_vector, last_read_value_);
379 EXPECT_EQ(test_vector, characteristic1_->GetValue()); 380 EXPECT_EQ(test_vector, characteristic1_->GetValue());
380 } 381 }
381 #endif // defined(OS_ANDROID) || defined(OS_WIN) 382 #endif // defined(OS_ANDROID) || defined(OS_WIN)
382 383
383 #if defined(OS_ANDROID) || defined(OS_WIN) 384 #if defined(OS_ANDROID) || defined(OS_WIN)
384 // Tests WriteRemoteCharacteristic with non-empty value buffer. 385 // Tests WriteRemoteCharacteristic with non-empty value buffer.
385 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) { 386 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) {
386 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 387 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
387 BluetoothGattCharacteristic::PROPERTY_WRITE)); 388 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
388 389
389 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 390 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
390 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 391 std::vector<uint8_t> test_vector(values, values + arraysize(values));
391 characteristic1_->WriteRemoteCharacteristic( 392 characteristic1_->WriteRemoteCharacteristic(
392 test_vector, GetCallback(Call::EXPECTED), 393 test_vector, GetCallback(Call::EXPECTED),
393 GetGattErrorCallback(Call::NOT_EXPECTED)); 394 GetGattErrorCallback(Call::NOT_EXPECTED));
394 395
395 SimulateGattCharacteristicWrite(characteristic1_); 396 SimulateGattCharacteristicWrite(characteristic1_);
396 397
397 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 398 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
398 EXPECT_EQ(test_vector, last_write_value_); 399 EXPECT_EQ(test_vector, last_write_value_);
399 } 400 }
400 #endif // defined(OS_ANDROID) || defined(OS_WIN) 401 #endif // defined(OS_ANDROID) || defined(OS_WIN)
401 402
402 #if defined(OS_ANDROID) || defined(OS_WIN) 403 #if defined(OS_ANDROID) || defined(OS_WIN)
403 // Tests ReadRemoteCharacteristic and GetValue multiple times. 404 // Tests ReadRemoteCharacteristic and GetValue multiple times.
404 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { 405 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Twice) {
405 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 406 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
406 BluetoothGattCharacteristic::PROPERTY_READ)); 407 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
407 408
408 characteristic1_->ReadRemoteCharacteristic( 409 characteristic1_->ReadRemoteCharacteristic(
409 GetReadValueCallback(Call::EXPECTED), 410 GetReadValueCallback(Call::EXPECTED),
410 GetGattErrorCallback(Call::NOT_EXPECTED)); 411 GetGattErrorCallback(Call::NOT_EXPECTED));
411 412
412 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 413 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
413 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 414 std::vector<uint8_t> test_vector(values, values + arraysize(values));
414 SimulateGattCharacteristicRead(characteristic1_, test_vector); 415 SimulateGattCharacteristicRead(characteristic1_, test_vector);
415 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 416 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
416 EXPECT_EQ(1, callback_count_); 417 EXPECT_EQ(1, callback_count_);
(...skipping 11 matching lines...) Expand all
428 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 429 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
429 EXPECT_EQ(1, callback_count_); 430 EXPECT_EQ(1, callback_count_);
430 EXPECT_EQ(0, error_callback_count_); 431 EXPECT_EQ(0, error_callback_count_);
431 EXPECT_EQ(empty_vector, last_read_value_); 432 EXPECT_EQ(empty_vector, last_read_value_);
432 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 433 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
433 } 434 }
434 #endif // defined(OS_ANDROID) || defined(OS_WIN) 435 #endif // defined(OS_ANDROID) || defined(OS_WIN)
435 436
436 #if defined(OS_ANDROID) || defined(OS_WIN) 437 #if defined(OS_ANDROID) || defined(OS_WIN)
437 // Tests WriteRemoteCharacteristic multiple times. 438 // Tests WriteRemoteCharacteristic multiple times.
438 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { 439 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Twice) {
439 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 440 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
440 BluetoothGattCharacteristic::PROPERTY_WRITE)); 441 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
441 442
442 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 443 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
443 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 444 std::vector<uint8_t> test_vector(values, values + arraysize(values));
444 characteristic1_->WriteRemoteCharacteristic( 445 characteristic1_->WriteRemoteCharacteristic(
445 test_vector, GetCallback(Call::EXPECTED), 446 test_vector, GetCallback(Call::EXPECTED),
446 GetGattErrorCallback(Call::NOT_EXPECTED)); 447 GetGattErrorCallback(Call::NOT_EXPECTED));
447 448
448 SimulateGattCharacteristicWrite(characteristic1_); 449 SimulateGattCharacteristicWrite(characteristic1_);
449 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 450 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
450 EXPECT_EQ(1, callback_count_); 451 EXPECT_EQ(1, callback_count_);
(...skipping 10 matching lines...) Expand all
461 SimulateGattCharacteristicWrite(characteristic1_); 462 SimulateGattCharacteristicWrite(characteristic1_);
462 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 463 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
463 EXPECT_EQ(1, callback_count_); 464 EXPECT_EQ(1, callback_count_);
464 EXPECT_EQ(0, error_callback_count_); 465 EXPECT_EQ(0, error_callback_count_);
465 EXPECT_EQ(empty_vector, last_write_value_); 466 EXPECT_EQ(empty_vector, last_write_value_);
466 } 467 }
467 #endif // defined(OS_ANDROID) || defined(OS_WIN) 468 #endif // defined(OS_ANDROID) || defined(OS_WIN)
468 469
469 #if defined(OS_ANDROID) || defined(OS_WIN) 470 #if defined(OS_ANDROID) || defined(OS_WIN)
470 // Tests ReadRemoteCharacteristic on two characteristics. 471 // Tests ReadRemoteCharacteristic on two characteristics.
471 TEST_F(BluetoothGattCharacteristicTest, 472 TEST_F(BluetoothRemoteGattCharacteristicTest,
472 ReadRemoteCharacteristic_MultipleCharacteristics) { 473 ReadRemoteCharacteristic_MultipleCharacteristics) {
473 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 474 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
474 BluetoothGattCharacteristic::PROPERTY_READ)); 475 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
475 476
476 characteristic1_->ReadRemoteCharacteristic( 477 characteristic1_->ReadRemoteCharacteristic(
477 GetReadValueCallback(Call::EXPECTED), 478 GetReadValueCallback(Call::EXPECTED),
478 GetGattErrorCallback(Call::NOT_EXPECTED)); 479 GetGattErrorCallback(Call::NOT_EXPECTED));
479 characteristic2_->ReadRemoteCharacteristic( 480 characteristic2_->ReadRemoteCharacteristic(
480 GetReadValueCallback(Call::EXPECTED), 481 GetReadValueCallback(Call::EXPECTED),
481 GetGattErrorCallback(Call::NOT_EXPECTED)); 482 GetGattErrorCallback(Call::NOT_EXPECTED));
482 EXPECT_EQ(0, callback_count_); 483 EXPECT_EQ(0, callback_count_);
483 EXPECT_EQ(0, error_callback_count_); 484 EXPECT_EQ(0, error_callback_count_);
484 485
(...skipping 10 matching lines...) Expand all
495 EXPECT_EQ(2, gatt_read_characteristic_attempts_); 496 EXPECT_EQ(2, gatt_read_characteristic_attempts_);
496 EXPECT_EQ(2, callback_count_); 497 EXPECT_EQ(2, callback_count_);
497 EXPECT_EQ(0, error_callback_count_); 498 EXPECT_EQ(0, error_callback_count_);
498 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); 499 EXPECT_EQ(test_vector1, characteristic1_->GetValue());
499 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); 500 EXPECT_EQ(test_vector2, characteristic2_->GetValue());
500 } 501 }
501 #endif // defined(OS_ANDROID) || defined(OS_WIN) 502 #endif // defined(OS_ANDROID) || defined(OS_WIN)
502 503
503 #if defined(OS_ANDROID) || defined(OS_WIN) 504 #if defined(OS_ANDROID) || defined(OS_WIN)
504 // Tests WriteRemoteCharacteristic on two characteristics. 505 // Tests WriteRemoteCharacteristic on two characteristics.
505 TEST_F(BluetoothGattCharacteristicTest, 506 TEST_F(BluetoothRemoteGattCharacteristicTest,
506 WriteRemoteCharacteristic_MultipleCharacteristics) { 507 WriteRemoteCharacteristic_MultipleCharacteristics) {
507 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 508 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
508 BluetoothGattCharacteristic::PROPERTY_WRITE)); 509 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
509 510
510 std::vector<uint8_t> test_vector1; 511 std::vector<uint8_t> test_vector1;
511 test_vector1.push_back(111); 512 test_vector1.push_back(111);
512 characteristic1_->WriteRemoteCharacteristic( 513 characteristic1_->WriteRemoteCharacteristic(
513 test_vector1, GetCallback(Call::EXPECTED), 514 test_vector1, GetCallback(Call::EXPECTED),
514 GetGattErrorCallback(Call::NOT_EXPECTED)); 515 GetGattErrorCallback(Call::NOT_EXPECTED));
515 #ifdef OS_ANDROID 516 #ifdef OS_ANDROID
516 EXPECT_EQ(test_vector1, last_write_value_); 517 EXPECT_EQ(test_vector1, last_write_value_);
517 #endif 518 #endif
518 519
(...skipping 22 matching lines...) Expand all
541 EXPECT_EQ(2, gatt_write_characteristic_attempts_); 542 EXPECT_EQ(2, gatt_write_characteristic_attempts_);
542 EXPECT_EQ(2, callback_count_); 543 EXPECT_EQ(2, callback_count_);
543 EXPECT_EQ(0, error_callback_count_); 544 EXPECT_EQ(0, error_callback_count_);
544 545
545 // TODO(591740): Remove if define for OS_ANDROID in this test. 546 // TODO(591740): Remove if define for OS_ANDROID in this test.
546 } 547 }
547 #endif // defined(OS_ANDROID) || defined(OS_WIN) 548 #endif // defined(OS_ANDROID) || defined(OS_WIN)
548 549
549 #if defined(OS_ANDROID) || defined(OS_WIN) 550 #if defined(OS_ANDROID) || defined(OS_WIN)
550 // Tests ReadRemoteCharacteristic asynchronous error. 551 // Tests ReadRemoteCharacteristic asynchronous error.
551 TEST_F(BluetoothGattCharacteristicTest, ReadError) { 552 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadError) {
552 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 553 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
553 BluetoothGattCharacteristic::PROPERTY_READ)); 554 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
554 555
555 characteristic1_->ReadRemoteCharacteristic( 556 characteristic1_->ReadRemoteCharacteristic(
556 GetReadValueCallback(Call::NOT_EXPECTED), 557 GetReadValueCallback(Call::NOT_EXPECTED),
557 GetGattErrorCallback(Call::EXPECTED)); 558 GetGattErrorCallback(Call::EXPECTED));
558 SimulateGattCharacteristicReadError( 559 SimulateGattCharacteristicReadError(
559 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); 560 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
560 SimulateGattCharacteristicReadError(characteristic1_, 561 SimulateGattCharacteristicReadError(
561 BluetoothGattService::GATT_ERROR_FAILED); 562 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
562 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, 563 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
563 last_gatt_error_code_); 564 last_gatt_error_code_);
564 } 565 }
565 #endif // defined(OS_ANDROID) || defined(OS_WIN) 566 #endif // defined(OS_ANDROID) || defined(OS_WIN)
566 567
567 #if defined(OS_ANDROID) || defined(OS_WIN) 568 #if defined(OS_ANDROID) || defined(OS_WIN)
568 // Tests WriteRemoteCharacteristic asynchronous error. 569 // Tests WriteRemoteCharacteristic asynchronous error.
569 TEST_F(BluetoothGattCharacteristicTest, WriteError) { 570 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteError) {
570 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 571 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
571 BluetoothGattCharacteristic::PROPERTY_WRITE)); 572 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
572 573
573 std::vector<uint8_t> empty_vector; 574 std::vector<uint8_t> empty_vector;
574 characteristic1_->WriteRemoteCharacteristic( 575 characteristic1_->WriteRemoteCharacteristic(
575 empty_vector, GetCallback(Call::NOT_EXPECTED), 576 empty_vector, GetCallback(Call::NOT_EXPECTED),
576 GetGattErrorCallback(Call::EXPECTED)); 577 GetGattErrorCallback(Call::EXPECTED));
577 SimulateGattCharacteristicWriteError( 578 SimulateGattCharacteristicWriteError(
578 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); 579 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
579 SimulateGattCharacteristicWriteError(characteristic1_, 580 SimulateGattCharacteristicWriteError(
580 BluetoothGattService::GATT_ERROR_FAILED); 581 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
581 582
582 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, 583 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
583 last_gatt_error_code_); 584 last_gatt_error_code_);
584 } 585 }
585 #endif // defined(OS_ANDROID) || defined(OS_WIN) 586 #endif // defined(OS_ANDROID) || defined(OS_WIN)
586 587
587 #if defined(OS_ANDROID) 588 #if defined(OS_ANDROID)
588 // Tests ReadRemoteCharacteristic synchronous error. 589 // Tests ReadRemoteCharacteristic synchronous error.
589 TEST_F(BluetoothGattCharacteristicTest, ReadSynchronousError) { 590 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadSynchronousError) {
590 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 591 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
591 592
592 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); 593 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_);
593 characteristic1_->ReadRemoteCharacteristic( 594 characteristic1_->ReadRemoteCharacteristic(
594 GetReadValueCallback(Call::NOT_EXPECTED), 595 GetReadValueCallback(Call::NOT_EXPECTED),
595 GetGattErrorCallback(Call::EXPECTED)); 596 GetGattErrorCallback(Call::EXPECTED));
596 EXPECT_EQ(0, gatt_read_characteristic_attempts_); 597 EXPECT_EQ(0, gatt_read_characteristic_attempts_);
597 base::RunLoop().RunUntilIdle(); 598 base::RunLoop().RunUntilIdle();
598 EXPECT_EQ(0, callback_count_); 599 EXPECT_EQ(0, callback_count_);
599 EXPECT_EQ(1, error_callback_count_); 600 EXPECT_EQ(1, error_callback_count_);
600 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); 601 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
602 last_gatt_error_code_);
601 603
602 // After failing once, can succeed: 604 // After failing once, can succeed:
603 ResetEventCounts(); 605 ResetEventCounts();
604 characteristic1_->ReadRemoteCharacteristic( 606 characteristic1_->ReadRemoteCharacteristic(
605 GetReadValueCallback(Call::EXPECTED), 607 GetReadValueCallback(Call::EXPECTED),
606 GetGattErrorCallback(Call::NOT_EXPECTED)); 608 GetGattErrorCallback(Call::NOT_EXPECTED));
607 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 609 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
608 std::vector<uint8_t> empty_vector; 610 std::vector<uint8_t> empty_vector;
609 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 611 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
610 EXPECT_EQ(1, callback_count_); 612 EXPECT_EQ(1, callback_count_);
611 EXPECT_EQ(0, error_callback_count_); 613 EXPECT_EQ(0, error_callback_count_);
612 } 614 }
613 #endif // defined(OS_ANDROID) 615 #endif // defined(OS_ANDROID)
614 616
615 #if defined(OS_ANDROID) 617 #if defined(OS_ANDROID)
616 // Tests WriteRemoteCharacteristic synchronous error. 618 // Tests WriteRemoteCharacteristic synchronous error.
617 TEST_F(BluetoothGattCharacteristicTest, WriteSynchronousError) { 619 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteSynchronousError) {
618 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 620 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
619 621
620 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(characteristic1_); 622 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(characteristic1_);
621 std::vector<uint8_t> empty_vector; 623 std::vector<uint8_t> empty_vector;
622 characteristic1_->WriteRemoteCharacteristic( 624 characteristic1_->WriteRemoteCharacteristic(
623 empty_vector, GetCallback(Call::NOT_EXPECTED), 625 empty_vector, GetCallback(Call::NOT_EXPECTED),
624 GetGattErrorCallback(Call::EXPECTED)); 626 GetGattErrorCallback(Call::EXPECTED));
625 EXPECT_EQ(0, gatt_write_characteristic_attempts_); 627 EXPECT_EQ(0, gatt_write_characteristic_attempts_);
626 base::RunLoop().RunUntilIdle(); 628 base::RunLoop().RunUntilIdle();
627 EXPECT_EQ(0, callback_count_); 629 EXPECT_EQ(0, callback_count_);
628 EXPECT_EQ(1, error_callback_count_); 630 EXPECT_EQ(1, error_callback_count_);
629 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); 631 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
632 last_gatt_error_code_);
630 633
631 // After failing once, can succeed: 634 // After failing once, can succeed:
632 ResetEventCounts(); 635 ResetEventCounts();
633 characteristic1_->WriteRemoteCharacteristic( 636 characteristic1_->WriteRemoteCharacteristic(
634 empty_vector, GetCallback(Call::EXPECTED), 637 empty_vector, GetCallback(Call::EXPECTED),
635 GetGattErrorCallback(Call::NOT_EXPECTED)); 638 GetGattErrorCallback(Call::NOT_EXPECTED));
636 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 639 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
637 SimulateGattCharacteristicWrite(characteristic1_); 640 SimulateGattCharacteristicWrite(characteristic1_);
638 EXPECT_EQ(1, callback_count_); 641 EXPECT_EQ(1, callback_count_);
639 EXPECT_EQ(0, error_callback_count_); 642 EXPECT_EQ(0, error_callback_count_);
640 } 643 }
641 #endif // defined(OS_ANDROID) 644 #endif // defined(OS_ANDROID)
642 645
643 #if defined(OS_ANDROID) || defined(OS_WIN) 646 #if defined(OS_ANDROID) || defined(OS_WIN)
644 // Tests ReadRemoteCharacteristic error with a pending read operation. 647 // Tests ReadRemoteCharacteristic error with a pending read operation.
645 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_ReadPending) { 648 TEST_F(BluetoothRemoteGattCharacteristicTest,
649 ReadRemoteCharacteristic_ReadPending) {
646 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 650 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
647 BluetoothGattCharacteristic::PROPERTY_READ)); 651 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
648 652
649 characteristic1_->ReadRemoteCharacteristic( 653 characteristic1_->ReadRemoteCharacteristic(
650 GetReadValueCallback(Call::EXPECTED), 654 GetReadValueCallback(Call::EXPECTED),
651 GetGattErrorCallback(Call::NOT_EXPECTED)); 655 GetGattErrorCallback(Call::NOT_EXPECTED));
652 characteristic1_->ReadRemoteCharacteristic( 656 characteristic1_->ReadRemoteCharacteristic(
653 GetReadValueCallback(Call::NOT_EXPECTED), 657 GetReadValueCallback(Call::NOT_EXPECTED),
654 GetGattErrorCallback(Call::EXPECTED)); 658 GetGattErrorCallback(Call::EXPECTED));
655 659
656 base::RunLoop().RunUntilIdle(); 660 base::RunLoop().RunUntilIdle();
657 661
658 EXPECT_EQ(0, callback_count_); 662 EXPECT_EQ(0, callback_count_);
659 EXPECT_EQ(1, error_callback_count_); 663 EXPECT_EQ(1, error_callback_count_);
660 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 664 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
661 last_gatt_error_code_); 665 last_gatt_error_code_);
662 666
663 // Initial read should still succeed: 667 // Initial read should still succeed:
664 ResetEventCounts(); 668 ResetEventCounts();
665 std::vector<uint8_t> empty_vector; 669 std::vector<uint8_t> empty_vector;
666 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 670 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
667 EXPECT_EQ(1, callback_count_); 671 EXPECT_EQ(1, callback_count_);
668 EXPECT_EQ(0, error_callback_count_); 672 EXPECT_EQ(0, error_callback_count_);
669 } 673 }
670 #endif // defined(OS_ANDROID) || defined(OS_WIN) 674 #endif // defined(OS_ANDROID) || defined(OS_WIN)
671 675
672 #if defined(OS_ANDROID) || defined(OS_WIN) 676 #if defined(OS_ANDROID) || defined(OS_WIN)
673 // Tests WriteRemoteCharacteristic error with a pending write operation. 677 // Tests WriteRemoteCharacteristic error with a pending write operation.
674 TEST_F(BluetoothGattCharacteristicTest, 678 TEST_F(BluetoothRemoteGattCharacteristicTest,
675 WriteRemoteCharacteristic_WritePending) { 679 WriteRemoteCharacteristic_WritePending) {
676 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 680 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
677 BluetoothGattCharacteristic::PROPERTY_WRITE)); 681 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
678 682
679 std::vector<uint8_t> empty_vector; 683 std::vector<uint8_t> empty_vector;
680 characteristic1_->WriteRemoteCharacteristic( 684 characteristic1_->WriteRemoteCharacteristic(
681 empty_vector, GetCallback(Call::EXPECTED), 685 empty_vector, GetCallback(Call::EXPECTED),
682 GetGattErrorCallback(Call::NOT_EXPECTED)); 686 GetGattErrorCallback(Call::NOT_EXPECTED));
683 characteristic1_->WriteRemoteCharacteristic( 687 characteristic1_->WriteRemoteCharacteristic(
684 empty_vector, GetCallback(Call::NOT_EXPECTED), 688 empty_vector, GetCallback(Call::NOT_EXPECTED),
685 GetGattErrorCallback(Call::EXPECTED)); 689 GetGattErrorCallback(Call::EXPECTED));
686 690
687 base::RunLoop().RunUntilIdle(); 691 base::RunLoop().RunUntilIdle();
688 692
689 EXPECT_EQ(0, callback_count_); 693 EXPECT_EQ(0, callback_count_);
690 EXPECT_EQ(1, error_callback_count_); 694 EXPECT_EQ(1, error_callback_count_);
691 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 695 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
692 last_gatt_error_code_); 696 last_gatt_error_code_);
693 697
694 // Initial write should still succeed: 698 // Initial write should still succeed:
695 ResetEventCounts(); 699 ResetEventCounts();
696 SimulateGattCharacteristicWrite(characteristic1_); 700 SimulateGattCharacteristicWrite(characteristic1_);
697 EXPECT_EQ(1, callback_count_); 701 EXPECT_EQ(1, callback_count_);
698 EXPECT_EQ(0, error_callback_count_); 702 EXPECT_EQ(0, error_callback_count_);
699 } 703 }
700 #endif // defined(OS_ANDROID) || defined(OS_WIN) 704 #endif // defined(OS_ANDROID) || defined(OS_WIN)
701 705
702 #if defined(OS_ANDROID) || defined(OS_WIN) 706 #if defined(OS_ANDROID) || defined(OS_WIN)
703 // Tests ReadRemoteCharacteristic error with a pending write operation. 707 // Tests ReadRemoteCharacteristic error with a pending write operation.
704 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_WritePending) { 708 TEST_F(BluetoothRemoteGattCharacteristicTest,
709 ReadRemoteCharacteristic_WritePending) {
705 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 710 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
706 BluetoothGattCharacteristic::PROPERTY_READ | 711 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
707 BluetoothGattCharacteristic::PROPERTY_WRITE)); 712 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
708 713
709 std::vector<uint8_t> empty_vector; 714 std::vector<uint8_t> empty_vector;
710 characteristic1_->WriteRemoteCharacteristic( 715 characteristic1_->WriteRemoteCharacteristic(
711 empty_vector, GetCallback(Call::EXPECTED), 716 empty_vector, GetCallback(Call::EXPECTED),
712 GetGattErrorCallback(Call::NOT_EXPECTED)); 717 GetGattErrorCallback(Call::NOT_EXPECTED));
713 characteristic1_->ReadRemoteCharacteristic( 718 characteristic1_->ReadRemoteCharacteristic(
714 GetReadValueCallback(Call::NOT_EXPECTED), 719 GetReadValueCallback(Call::NOT_EXPECTED),
715 GetGattErrorCallback(Call::EXPECTED)); 720 GetGattErrorCallback(Call::EXPECTED));
716 721
717 base::RunLoop().RunUntilIdle(); 722 base::RunLoop().RunUntilIdle();
718 723
719 EXPECT_EQ(0, callback_count_); 724 EXPECT_EQ(0, callback_count_);
720 EXPECT_EQ(1, error_callback_count_); 725 EXPECT_EQ(1, error_callback_count_);
721 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 726 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
722 last_gatt_error_code_); 727 last_gatt_error_code_);
723 728
724 // Initial write should still succeed: 729 // Initial write should still succeed:
725 ResetEventCounts(); 730 ResetEventCounts();
726 SimulateGattCharacteristicWrite(characteristic1_); 731 SimulateGattCharacteristicWrite(characteristic1_);
727 EXPECT_EQ(1, callback_count_); 732 EXPECT_EQ(1, callback_count_);
728 EXPECT_EQ(0, error_callback_count_); 733 EXPECT_EQ(0, error_callback_count_);
729 } 734 }
730 #endif // defined(OS_ANDROID) || defined(OS_WIN) 735 #endif // defined(OS_ANDROID) || defined(OS_WIN)
731 736
732 #if defined(OS_ANDROID) || defined(OS_WIN) 737 #if defined(OS_ANDROID) || defined(OS_WIN)
733 // Tests WriteRemoteCharacteristic error with a pending Read operation. 738 // Tests WriteRemoteCharacteristic error with a pending Read operation.
734 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_ReadPending) { 739 TEST_F(BluetoothRemoteGattCharacteristicTest,
740 WriteRemoteCharacteristic_ReadPending) {
735 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 741 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
736 BluetoothGattCharacteristic::PROPERTY_READ | 742 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
737 BluetoothGattCharacteristic::PROPERTY_WRITE)); 743 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
738 744
739 std::vector<uint8_t> empty_vector; 745 std::vector<uint8_t> empty_vector;
740 characteristic1_->ReadRemoteCharacteristic( 746 characteristic1_->ReadRemoteCharacteristic(
741 GetReadValueCallback(Call::EXPECTED), 747 GetReadValueCallback(Call::EXPECTED),
742 GetGattErrorCallback(Call::NOT_EXPECTED)); 748 GetGattErrorCallback(Call::NOT_EXPECTED));
743 characteristic1_->WriteRemoteCharacteristic( 749 characteristic1_->WriteRemoteCharacteristic(
744 empty_vector, GetCallback(Call::NOT_EXPECTED), 750 empty_vector, GetCallback(Call::NOT_EXPECTED),
745 GetGattErrorCallback(Call::EXPECTED)); 751 GetGattErrorCallback(Call::EXPECTED));
746 base::RunLoop().RunUntilIdle(); 752 base::RunLoop().RunUntilIdle();
747 753
748 EXPECT_EQ(0, callback_count_); 754 EXPECT_EQ(0, callback_count_);
749 EXPECT_EQ(1, error_callback_count_); 755 EXPECT_EQ(1, error_callback_count_);
750 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 756 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
751 last_gatt_error_code_); 757 last_gatt_error_code_);
752 758
753 // Initial read should still succeed: 759 // Initial read should still succeed:
754 ResetEventCounts(); 760 ResetEventCounts();
755 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 761 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
756 EXPECT_EQ(1, callback_count_); 762 EXPECT_EQ(1, callback_count_);
757 EXPECT_EQ(0, error_callback_count_); 763 EXPECT_EQ(0, error_callback_count_);
758 } 764 }
759 #endif // defined(OS_ANDROID) || defined(OS_WIN) 765 #endif // defined(OS_ANDROID) || defined(OS_WIN)
760 766
761 #if defined(OS_ANDROID) || defined(OS_WIN) 767 #if defined(OS_ANDROID) || defined(OS_WIN)
762 // StartNotifySession fails if characteristic doesn't have Notify or Indicate 768 // StartNotifySession fails if characteristic doesn't have Notify or Indicate
763 // property. 769 // property.
764 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { 770 TEST_F(BluetoothRemoteGattCharacteristicTest,
771 StartNotifySession_NoNotifyOrIndicate) {
765 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 772 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
766 /* properties: NOTIFY */ 0x10, 773 /* properties: NOTIFY */ 0x10,
767 /* expected_config_descriptor_value: NOTIFY */ 1, 774 /* expected_config_descriptor_value: NOTIFY */ 1,
768 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); 775 StartNotifySetupError::CHARACTERISTIC_PROPERTIES));
769 776
770 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 777 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
771 778
772 // The expected error callback is asynchronous: 779 // The expected error callback is asynchronous:
773 EXPECT_EQ(0, error_callback_count_); 780 EXPECT_EQ(0, error_callback_count_);
774 base::RunLoop().RunUntilIdle(); 781 base::RunLoop().RunUntilIdle();
775 EXPECT_EQ(1, error_callback_count_); 782 EXPECT_EQ(1, error_callback_count_);
776 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, 783 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
777 last_gatt_error_code_); 784 last_gatt_error_code_);
778 } 785 }
779 #endif // defined(OS_ANDROID) || defined(OS_WIN) 786 #endif // defined(OS_ANDROID) || defined(OS_WIN)
780 787
781 #if defined(OS_ANDROID) || defined(OS_WIN) 788 #if defined(OS_ANDROID) || defined(OS_WIN)
782 // StartNotifySession fails if the characteristic is missing the Client 789 // StartNotifySession fails if the characteristic is missing the Client
783 // Characteristic Configuration descriptor. 790 // Characteristic Configuration descriptor.
784 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { 791 TEST_F(BluetoothRemoteGattCharacteristicTest,
792 StartNotifySession_NoConfigDescriptor) {
785 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 793 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
786 /* properties: NOTIFY */ 0x10, 794 /* properties: NOTIFY */ 0x10,
787 /* expected_config_descriptor_value: NOTIFY */ 1, 795 /* expected_config_descriptor_value: NOTIFY */ 1,
788 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); 796 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING));
789 797
790 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 798 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
791 799
792 // The expected error callback is asynchronous: 800 // The expected error callback is asynchronous:
793 EXPECT_EQ(0, error_callback_count_); 801 EXPECT_EQ(0, error_callback_count_);
794 base::RunLoop().RunUntilIdle(); 802 base::RunLoop().RunUntilIdle();
795 EXPECT_EQ(1, error_callback_count_); 803 EXPECT_EQ(1, error_callback_count_);
796 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, 804 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED,
797 last_gatt_error_code_); 805 last_gatt_error_code_);
798 } 806 }
799 #endif // defined(OS_ANDROID) || defined(OS_WIN) 807 #endif // defined(OS_ANDROID) || defined(OS_WIN)
800 808
801 #if defined(OS_ANDROID) || defined(OS_WIN) 809 #if defined(OS_ANDROID) || defined(OS_WIN)
802 // StartNotifySession fails if the characteristic has multiple Client 810 // StartNotifySession fails if the characteristic has multiple Client
803 // Characteristic Configuration descriptors. 811 // Characteristic Configuration descriptors.
804 TEST_F(BluetoothGattCharacteristicTest, 812 TEST_F(BluetoothRemoteGattCharacteristicTest,
805 StartNotifySession_MultipleConfigDescriptor) { 813 StartNotifySession_MultipleConfigDescriptor) {
806 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 814 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
807 /* properties: NOTIFY */ 0x10, 815 /* properties: NOTIFY */ 0x10,
808 /* expected_config_descriptor_value: NOTIFY */ 1, 816 /* expected_config_descriptor_value: NOTIFY */ 1,
809 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); 817 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE));
810 818
811 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 819 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
812 820
813 // The expected error callback is asynchronous: 821 // The expected error callback is asynchronous:
814 EXPECT_EQ(0, error_callback_count_); 822 EXPECT_EQ(0, error_callback_count_);
815 base::RunLoop().RunUntilIdle(); 823 base::RunLoop().RunUntilIdle();
816 EXPECT_EQ(1, error_callback_count_); 824 EXPECT_EQ(1, error_callback_count_);
817 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); 825 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
826 last_gatt_error_code_);
818 } 827 }
819 #endif // defined(OS_ANDROID) || defined(OS_WIN) 828 #endif // defined(OS_ANDROID) || defined(OS_WIN)
820 829
821 #if defined(OS_ANDROID) 830 #if defined(OS_ANDROID)
822 // StartNotifySession fails synchronously when failing to set a characteristic 831 // StartNotifySession fails synchronously when failing to set a characteristic
823 // to enable notifications. 832 // to enable notifications.
824 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. 833 // Android: This is mBluetoothGatt.setCharacteristicNotification failing.
825 // Windows: Synchronous Test Not Applicable: OS calls are all made 834 // Windows: Synchronous Test Not Applicable: OS calls are all made
826 // asynchronously from BluetoothTaskManagerWin. 835 // asynchronously from BluetoothTaskManagerWin.
827 TEST_F(BluetoothGattCharacteristicTest, 836 TEST_F(BluetoothRemoteGattCharacteristicTest,
828 StartNotifySession_FailToSetCharacteristicNotification) { 837 StartNotifySession_FailToSetCharacteristicNotification) {
829 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 838 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
830 /* properties: NOTIFY */ 0x10, 839 /* properties: NOTIFY */ 0x10,
831 /* expected_config_descriptor_value: NOTIFY */ 1, 840 /* expected_config_descriptor_value: NOTIFY */ 1,
832 StartNotifySetupError::SET_NOTIFY)); 841 StartNotifySetupError::SET_NOTIFY));
833 842
834 // The expected error callback is asynchronous: 843 // The expected error callback is asynchronous:
835 EXPECT_EQ(0, error_callback_count_); 844 EXPECT_EQ(0, error_callback_count_);
836 base::RunLoop().RunUntilIdle(); 845 base::RunLoop().RunUntilIdle();
837 EXPECT_EQ(1, error_callback_count_); 846 EXPECT_EQ(1, error_callback_count_);
838 847
839 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); 848 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
840 ASSERT_EQ(0u, notify_sessions_.size()); 849 ASSERT_EQ(0u, notify_sessions_.size());
841 } 850 }
842 #endif // defined(OS_ANDROID) 851 #endif // defined(OS_ANDROID)
843 852
844 #if defined(OS_ANDROID) 853 #if defined(OS_ANDROID)
845 // Tests StartNotifySession descriptor write synchronous failure. 854 // Tests StartNotifySession descriptor write synchronous failure.
846 // Windows: Synchronous Test Not Applicable: OS calls are all made 855 // Windows: Synchronous Test Not Applicable: OS calls are all made
847 // asynchronously from BluetoothTaskManagerWin. 856 // asynchronously from BluetoothTaskManagerWin.
848 TEST_F(BluetoothGattCharacteristicTest, 857 TEST_F(BluetoothRemoteGattCharacteristicTest,
849 StartNotifySession_WriteDescriptorSynchronousError) { 858 StartNotifySession_WriteDescriptorSynchronousError) {
850 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 859 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
851 /* properties: NOTIFY */ 0x10, 860 /* properties: NOTIFY */ 0x10,
852 /* expected_config_descriptor_value: NOTIFY */ 1, 861 /* expected_config_descriptor_value: NOTIFY */ 1,
853 StartNotifySetupError::WRITE_DESCRIPTOR)); 862 StartNotifySetupError::WRITE_DESCRIPTOR));
854 863
855 // The expected error callback is asynchronous: 864 // The expected error callback is asynchronous:
856 EXPECT_EQ(0, error_callback_count_); 865 EXPECT_EQ(0, error_callback_count_);
857 base::RunLoop().RunUntilIdle(); 866 base::RunLoop().RunUntilIdle();
858 EXPECT_EQ(1, error_callback_count_); 867 EXPECT_EQ(1, error_callback_count_);
859 868
860 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 869 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
861 ASSERT_EQ(0u, notify_sessions_.size()); 870 ASSERT_EQ(0u, notify_sessions_.size());
862 } 871 }
863 #endif // defined(OS_ANDROID) 872 #endif // defined(OS_ANDROID)
864 873
865 #if defined(OS_ANDROID) || defined(OS_WIN) 874 #if defined(OS_ANDROID) || defined(OS_WIN)
866 // Tests StartNotifySession success on a characteristic enabling Notify. 875 // Tests StartNotifySession success on a characteristic enabling Notify.
867 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { 876 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession) {
868 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 877 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
869 /* properties: NOTIFY */ 0x10, 878 /* properties: NOTIFY */ 0x10,
870 /* expected_config_descriptor_value: NOTIFY */ 1)); 879 /* expected_config_descriptor_value: NOTIFY */ 1));
871 } 880 }
872 #endif // defined(OS_ANDROID) || defined(OS_WIN) 881 #endif // defined(OS_ANDROID) || defined(OS_WIN)
873 882
874 #if defined(OS_ANDROID) || defined(OS_WIN) 883 #if defined(OS_ANDROID) || defined(OS_WIN)
875 // Tests StartNotifySession success on a characteristic enabling Indicate. 884 // Tests StartNotifySession success on a characteristic enabling Indicate.
876 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_OnIndicate) { 885 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_OnIndicate) {
877 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 886 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
878 /* properties: INDICATE */ 0x20, 887 /* properties: INDICATE */ 0x20,
879 /* expected_config_descriptor_value: INDICATE */ 2)); 888 /* expected_config_descriptor_value: INDICATE */ 2));
880 } 889 }
881 #endif // defined(OS_ANDROID) || defined(OS_WIN) 890 #endif // defined(OS_ANDROID) || defined(OS_WIN)
882 891
883 #if defined(OS_ANDROID) || defined(OS_WIN) 892 #if defined(OS_ANDROID) || defined(OS_WIN)
884 // Tests StartNotifySession success on a characteristic enabling Notify & 893 // Tests StartNotifySession success on a characteristic enabling Notify &
885 // Indicate. 894 // Indicate.
886 TEST_F(BluetoothGattCharacteristicTest, 895 TEST_F(BluetoothRemoteGattCharacteristicTest,
887 StartNotifySession_OnNotifyAndIndicate) { 896 StartNotifySession_OnNotifyAndIndicate) {
888 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 897 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
889 /* properties: NOTIFY and INDICATE bits set */ 0x30, 898 /* properties: NOTIFY and INDICATE bits set */ 0x30,
890 /* expected_config_descriptor_value: NOTIFY */ 1)); 899 /* expected_config_descriptor_value: NOTIFY */ 1));
891 } 900 }
892 #endif // defined(OS_ANDROID) || defined(OS_WIN) 901 #endif // defined(OS_ANDROID) || defined(OS_WIN)
893 902
894 #if defined(OS_ANDROID) || defined(OS_WIN) 903 #if defined(OS_ANDROID) || defined(OS_WIN)
895 // Tests multiple StartNotifySession success. 904 // Tests multiple StartNotifySession success.
896 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { 905 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_Multiple) {
897 ASSERT_NO_FATAL_FAILURE( 906 ASSERT_NO_FATAL_FAILURE(
898 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 907 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
899 SimulateGattDescriptor( 908 SimulateGattDescriptor(
900 characteristic1_, 909 characteristic1_,
901 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() 910 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
902 .canonical_value()); 911 .canonical_value());
903 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 912 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
904 913
905 characteristic1_->StartNotifySession( 914 characteristic1_->StartNotifySession(
906 GetNotifyCallback(Call::EXPECTED), 915 GetNotifyCallback(Call::EXPECTED),
907 GetGattErrorCallback(Call::NOT_EXPECTED)); 916 GetGattErrorCallback(Call::NOT_EXPECTED));
908 characteristic1_->StartNotifySession( 917 characteristic1_->StartNotifySession(
909 GetNotifyCallback(Call::EXPECTED), 918 GetNotifyCallback(Call::EXPECTED),
910 GetGattErrorCallback(Call::NOT_EXPECTED)); 919 GetGattErrorCallback(Call::NOT_EXPECTED));
911 EXPECT_EQ(0, callback_count_); 920 EXPECT_EQ(0, callback_count_);
912 SimulateGattNotifySessionStarted(characteristic1_); 921 SimulateGattNotifySessionStarted(characteristic1_);
913 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 922 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
914 EXPECT_EQ(2, callback_count_); 923 EXPECT_EQ(2, callback_count_);
915 EXPECT_EQ(0, error_callback_count_); 924 EXPECT_EQ(0, error_callback_count_);
916 ASSERT_EQ(2u, notify_sessions_.size()); 925 ASSERT_EQ(2u, notify_sessions_.size());
917 ASSERT_TRUE(notify_sessions_[0]); 926 ASSERT_TRUE(notify_sessions_[0]);
918 ASSERT_TRUE(notify_sessions_[1]); 927 ASSERT_TRUE(notify_sessions_[1]);
919 EXPECT_EQ(characteristic1_->GetIdentifier(), 928 EXPECT_EQ(characteristic1_->GetIdentifier(),
920 notify_sessions_[0]->GetCharacteristicIdentifier()); 929 notify_sessions_[0]->GetCharacteristicIdentifier());
921 EXPECT_EQ(characteristic1_->GetIdentifier(), 930 EXPECT_EQ(characteristic1_->GetIdentifier(),
922 notify_sessions_[1]->GetCharacteristicIdentifier()); 931 notify_sessions_[1]->GetCharacteristicIdentifier());
923 EXPECT_TRUE(notify_sessions_[0]->IsActive()); 932 EXPECT_TRUE(notify_sessions_[0]->IsActive());
924 EXPECT_TRUE(notify_sessions_[1]->IsActive()); 933 EXPECT_TRUE(notify_sessions_[1]->IsActive());
925 } 934 }
926 #endif // defined(OS_ANDROID) || defined(OS_WIN) 935 #endif // defined(OS_ANDROID) || defined(OS_WIN)
927 936
928 #if defined(OS_ANDROID) 937 #if defined(OS_ANDROID)
929 // Tests multiple StartNotifySessions pending and then an error. 938 // Tests multiple StartNotifySessions pending and then an error.
930 TEST_F(BluetoothGattCharacteristicTest, StartNotifySessionError_Multiple) { 939 TEST_F(BluetoothRemoteGattCharacteristicTest,
940 StartNotifySessionError_Multiple) {
931 ASSERT_NO_FATAL_FAILURE( 941 ASSERT_NO_FATAL_FAILURE(
932 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 942 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
933 SimulateGattDescriptor( 943 SimulateGattDescriptor(
934 characteristic1_, 944 characteristic1_,
935 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() 945 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
936 .canonical_value()); 946 .canonical_value());
937 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 947 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
938 948
939 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 949 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
940 GetGattErrorCallback(Call::EXPECTED)); 950 GetGattErrorCallback(Call::EXPECTED));
941 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 951 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
942 GetGattErrorCallback(Call::EXPECTED)); 952 GetGattErrorCallback(Call::EXPECTED));
943 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 953 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
944 EXPECT_EQ(0, callback_count_); 954 EXPECT_EQ(0, callback_count_);
945 SimulateGattNotifySessionStartError(characteristic1_, 955 SimulateGattNotifySessionStartError(
946 BluetoothGattService::GATT_ERROR_FAILED); 956 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
947 EXPECT_EQ(0, callback_count_); 957 EXPECT_EQ(0, callback_count_);
948 EXPECT_EQ(2, error_callback_count_); 958 EXPECT_EQ(2, error_callback_count_);
949 ASSERT_EQ(0u, notify_sessions_.size()); 959 ASSERT_EQ(0u, notify_sessions_.size());
950 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); 960 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
961 last_gatt_error_code_);
951 } 962 }
952 #endif // defined(OS_ANDROID) 963 #endif // defined(OS_ANDROID)
953 964
954 #if defined(OS_ANDROID) 965 #if defined(OS_ANDROID)
955 // Tests StartNotifySession completing after chrome objects are deleted. 966 // Tests StartNotifySession completing after chrome objects are deleted.
956 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_AfterDeleted) { 967 TEST_F(BluetoothRemoteGattCharacteristicTest, StartNotifySession_AfterDeleted) {
957 ASSERT_NO_FATAL_FAILURE( 968 ASSERT_NO_FATAL_FAILURE(
958 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); 969 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
959 SimulateGattDescriptor( 970 SimulateGattDescriptor(
960 characteristic1_, 971 characteristic1_,
961 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() 972 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
962 .canonical_value()); 973 .canonical_value());
963 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); 974 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
964 975
965 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), 976 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
966 GetGattErrorCallback(Call::EXPECTED)); 977 GetGattErrorCallback(Call::EXPECTED));
967 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); 978 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
968 EXPECT_EQ(0, callback_count_); 979 EXPECT_EQ(0, callback_count_);
969 980
970 RememberCharacteristicForSubsequentAction(characteristic1_); 981 RememberCharacteristicForSubsequentAction(characteristic1_);
971 RememberCCCDescriptorForSubsequentAction(characteristic1_); 982 RememberCCCDescriptorForSubsequentAction(characteristic1_);
972 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 983 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
973 984
974 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); 985 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr);
975 EXPECT_EQ(0, callback_count_); 986 EXPECT_EQ(0, callback_count_);
976 EXPECT_EQ(1, error_callback_count_); 987 EXPECT_EQ(1, error_callback_count_);
977 ASSERT_EQ(0u, notify_sessions_.size()); 988 ASSERT_EQ(0u, notify_sessions_.size());
978 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); 989 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
990 last_gatt_error_code_);
979 } 991 }
980 #endif // defined(OS_ANDROID) 992 #endif // defined(OS_ANDROID)
981 993
982 #if defined(OS_ANDROID) || defined(OS_WIN) 994 #if defined(OS_ANDROID) || defined(OS_WIN)
983 // Tests Characteristic Value changes during a Notify Session. 995 // Tests Characteristic Value changes during a Notify Session.
984 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { 996 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) {
985 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 997 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
986 /* properties: NOTIFY */ 0x10, 998 /* properties: NOTIFY */ 0x10,
987 /* expected_config_descriptor_value: NOTIFY */ 1)); 999 /* expected_config_descriptor_value: NOTIFY */ 1));
988 1000
989 TestBluetoothAdapterObserver observer(adapter_); 1001 TestBluetoothAdapterObserver observer(adapter_);
990 1002
991 std::vector<uint8_t> test_vector1, test_vector2; 1003 std::vector<uint8_t> test_vector1, test_vector2;
992 test_vector1.push_back(111); 1004 test_vector1.push_back(111);
993 test_vector2.push_back(222); 1005 test_vector2.push_back(222);
994 1006
995 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); 1007 SimulateGattCharacteristicChanged(characteristic1_, test_vector1);
996 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1008 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
997 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); 1009 EXPECT_EQ(test_vector1, characteristic1_->GetValue());
998 1010
999 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); 1011 SimulateGattCharacteristicChanged(characteristic1_, test_vector2);
1000 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 1012 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count());
1001 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); 1013 EXPECT_EQ(test_vector2, characteristic1_->GetValue());
1002 } 1014 }
1003 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1015 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1004 1016
1005 #if defined(OS_ANDROID) || defined(OS_WIN) 1017 #if defined(OS_ANDROID) || defined(OS_WIN)
1006 // Tests Characteristic Value changing after a Notify Session and objects being 1018 // Tests Characteristic Value changing after a Notify Session and objects being
1007 // destroyed. 1019 // destroyed.
1008 TEST_F(BluetoothGattCharacteristicTest, 1020 TEST_F(BluetoothRemoteGattCharacteristicTest,
1009 GattCharacteristicValueChanged_AfterDeleted) { 1021 GattCharacteristicValueChanged_AfterDeleted) {
1010 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1022 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
1011 /* properties: NOTIFY */ 0x10, 1023 /* properties: NOTIFY */ 0x10,
1012 /* expected_config_descriptor_value: NOTIFY */ 1)); 1024 /* expected_config_descriptor_value: NOTIFY */ 1));
1013 TestBluetoothAdapterObserver observer(adapter_); 1025 TestBluetoothAdapterObserver observer(adapter_);
1014 1026
1015 RememberCharacteristicForSubsequentAction(characteristic1_); 1027 RememberCharacteristicForSubsequentAction(characteristic1_);
1016 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 1028 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
1017 1029
1018 std::vector<uint8_t> empty_vector; 1030 std::vector<uint8_t> empty_vector;
1019 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, 1031 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr,
1020 empty_vector); 1032 empty_vector);
1021 EXPECT_TRUE("Did not crash!"); 1033 EXPECT_TRUE("Did not crash!");
1022 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 1034 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
1023 } 1035 }
1024 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1036 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1025 1037
1026 #if defined(OS_ANDROID) || defined(OS_WIN) 1038 #if defined(OS_ANDROID) || defined(OS_WIN)
1027 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { 1039 TEST_F(BluetoothRemoteGattCharacteristicTest, GetDescriptors_FindNone) {
1028 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 1040 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
1029 1041
1030 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); 1042 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size());
1031 } 1043 }
1032 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1044 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1033 1045
1034 #if defined(OS_ANDROID) || defined(OS_WIN) 1046 #if defined(OS_ANDROID) || defined(OS_WIN)
1035 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_and_GetDescriptor) { 1047 TEST_F(BluetoothRemoteGattCharacteristicTest,
1048 GetDescriptors_and_GetDescriptor) {
1036 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 1049 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
1037 1050
1038 // Add several Descriptors: 1051 // Add several Descriptors:
1039 BluetoothUUID uuid1("11111111-0000-1000-8000-00805f9b34fb"); 1052 BluetoothUUID uuid1("11111111-0000-1000-8000-00805f9b34fb");
1040 BluetoothUUID uuid2("22222222-0000-1000-8000-00805f9b34fb"); 1053 BluetoothUUID uuid2("22222222-0000-1000-8000-00805f9b34fb");
1041 BluetoothUUID uuid3("33333333-0000-1000-8000-00805f9b34fb"); 1054 BluetoothUUID uuid3("33333333-0000-1000-8000-00805f9b34fb");
1042 BluetoothUUID uuid4("44444444-0000-1000-8000-00805f9b34fb"); 1055 BluetoothUUID uuid4("44444444-0000-1000-8000-00805f9b34fb");
1043 SimulateGattDescriptor(characteristic1_, uuid1.canonical_value()); 1056 SimulateGattDescriptor(characteristic1_, uuid1.canonical_value());
1044 SimulateGattDescriptor(characteristic1_, uuid2.canonical_value()); 1057 SimulateGattDescriptor(characteristic1_, uuid2.canonical_value());
1045 SimulateGattDescriptor(characteristic2_, uuid3.canonical_value()); 1058 SimulateGattDescriptor(characteristic2_, uuid3.canonical_value());
(...skipping 24 matching lines...) Expand all
1070 1083
1071 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). 1084 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order).
1072 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); 1085 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1);
1073 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); 1086 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2);
1074 // ... but not uuid 3 1087 // ... but not uuid 3
1075 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); 1088 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3);
1076 } 1089 }
1077 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1090 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1078 1091
1079 #if defined(OS_ANDROID) || defined(OS_WIN) 1092 #if defined(OS_ANDROID) || defined(OS_WIN)
1080 TEST_F(BluetoothGattCharacteristicTest, GetDescriptorsByUUID) { 1093 TEST_F(BluetoothRemoteGattCharacteristicTest, GetDescriptorsByUUID) {
1081 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 1094 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
1082 1095
1083 // Add several Descriptors: 1096 // Add several Descriptors:
1084 BluetoothUUID id1("11111111-0000-1000-8000-00805f9b34fb"); 1097 BluetoothUUID id1("11111111-0000-1000-8000-00805f9b34fb");
1085 BluetoothUUID id2("22222222-0000-1000-8000-00805f9b34fb"); 1098 BluetoothUUID id2("22222222-0000-1000-8000-00805f9b34fb");
1086 BluetoothUUID id3("33333333-0000-1000-8000-00805f9b34fb"); 1099 BluetoothUUID id3("33333333-0000-1000-8000-00805f9b34fb");
1087 SimulateGattDescriptor(characteristic1_, id1.canonical_value()); 1100 SimulateGattDescriptor(characteristic1_, id1.canonical_value());
1088 SimulateGattDescriptor(characteristic1_, id2.canonical_value()); 1101 SimulateGattDescriptor(characteristic1_, id2.canonical_value());
1089 SimulateGattDescriptor(characteristic2_, id3.canonical_value()); 1102 SimulateGattDescriptor(characteristic2_, id3.canonical_value());
1090 SimulateGattDescriptor(characteristic2_, id3.canonical_value()); 1103 SimulateGattDescriptor(characteristic2_, id3.canonical_value());
1091 1104
1092 EXPECT_NE(characteristic2_->GetDescriptorsByUUID(id3).at(0)->GetIdentifier(), 1105 EXPECT_NE(characteristic2_->GetDescriptorsByUUID(id3).at(0)->GetIdentifier(),
1093 characteristic2_->GetDescriptorsByUUID(id3).at(1)->GetIdentifier()); 1106 characteristic2_->GetDescriptorsByUUID(id3).at(1)->GetIdentifier());
1094 1107
1095 EXPECT_EQ(id1, characteristic1_->GetDescriptorsByUUID(id1).at(0)->GetUUID()); 1108 EXPECT_EQ(id1, characteristic1_->GetDescriptorsByUUID(id1).at(0)->GetUUID());
1096 EXPECT_EQ(id2, characteristic1_->GetDescriptorsByUUID(id2).at(0)->GetUUID()); 1109 EXPECT_EQ(id2, characteristic1_->GetDescriptorsByUUID(id2).at(0)->GetUUID());
1097 EXPECT_EQ(id3, characteristic2_->GetDescriptorsByUUID(id3).at(0)->GetUUID()); 1110 EXPECT_EQ(id3, characteristic2_->GetDescriptorsByUUID(id3).at(0)->GetUUID());
1098 EXPECT_EQ(id3, characteristic2_->GetDescriptorsByUUID(id3).at(1)->GetUUID()); 1111 EXPECT_EQ(id3, characteristic2_->GetDescriptorsByUUID(id3).at(1)->GetUUID());
1099 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id1).size()); 1112 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id1).size());
1100 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 1113 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
1101 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 1114 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
1102 1115
1103 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 1116 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
1104 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 1117 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
1105 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 1118 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
1106 } 1119 }
1107 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1120 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1108 1121
1109 } // namespace device 1122 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698