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

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

Issue 1779083002: bluetooth: Test & make StartNotifySession reentrant. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-notify-followup-descriptors-
Patch Set: addressed ortuno comments 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 6 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
7 #include "device/bluetooth/bluetooth_gatt_service.h" 7 #include "device/bluetooth/bluetooth_gatt_service.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #if defined(OS_ANDROID) 10 #if defined(OS_ANDROID)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); 87 SimulateGattCharacteristic(service2, uuid, /* properties */ 0);
88 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 88 SimulateGattCharacteristic(service3, uuid, /* properties */ 0);
89 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 89 SimulateGattCharacteristic(service3, uuid, /* properties */ 0);
90 BluetoothGattCharacteristic* char1 = service1->GetCharacteristics()[0]; 90 BluetoothGattCharacteristic* char1 = service1->GetCharacteristics()[0];
91 BluetoothGattCharacteristic* char2 = service1->GetCharacteristics()[1]; 91 BluetoothGattCharacteristic* char2 = service1->GetCharacteristics()[1];
92 BluetoothGattCharacteristic* char3 = service2->GetCharacteristics()[0]; 92 BluetoothGattCharacteristic* char3 = service2->GetCharacteristics()[0];
93 BluetoothGattCharacteristic* char4 = service2->GetCharacteristics()[1]; 93 BluetoothGattCharacteristic* char4 = service2->GetCharacteristics()[1];
94 BluetoothGattCharacteristic* char5 = service3->GetCharacteristics()[0]; 94 BluetoothGattCharacteristic* char5 = service3->GetCharacteristics()[0];
95 BluetoothGattCharacteristic* char6 = service3->GetCharacteristics()[1]; 95 BluetoothGattCharacteristic* char6 = service3->GetCharacteristics()[1];
96 // 6 descriptors (same UUID), 1 on each characteristic 96 // 6 descriptors (same UUID), 1 on each characteristic
97 // TODO(crbug.com/576900) Test multiple descriptors with same UUID on one 97 // TODO(576900) Test multiple descriptors with same UUID on one
98 // characteristic. 98 // characteristic.
99 SimulateGattDescriptor(char1, uuid); 99 SimulateGattDescriptor(char1, uuid);
100 SimulateGattDescriptor(char2, uuid); 100 SimulateGattDescriptor(char2, uuid);
101 SimulateGattDescriptor(char3, uuid); 101 SimulateGattDescriptor(char3, uuid);
102 SimulateGattDescriptor(char4, uuid); 102 SimulateGattDescriptor(char4, uuid);
103 SimulateGattDescriptor(char5, uuid); 103 SimulateGattDescriptor(char5, uuid);
104 SimulateGattDescriptor(char6, uuid); 104 SimulateGattDescriptor(char6, uuid);
105 BluetoothGattDescriptor* desc1 = char1->GetDescriptors()[0]; 105 BluetoothGattDescriptor* desc1 = char1->GetDescriptors()[0];
106 BluetoothGattDescriptor* desc2 = char2->GetDescriptors()[0]; 106 BluetoothGattDescriptor* desc2 = char2->GetDescriptors()[0];
107 BluetoothGattDescriptor* desc3 = char3->GetDescriptors()[0]; 107 BluetoothGattDescriptor* desc3 = char3->GetDescriptors()[0];
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Tests WriteRemoteDescriptor with empty value buffer. 195 // Tests WriteRemoteDescriptor with empty value buffer.
196 TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_Empty) { 196 TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_Empty) {
197 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); 197 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate());
198 198
199 std::vector<uint8_t> empty_vector; 199 std::vector<uint8_t> empty_vector;
200 descriptor1_->WriteRemoteDescriptor(empty_vector, GetCallback(Call::EXPECTED), 200 descriptor1_->WriteRemoteDescriptor(empty_vector, GetCallback(Call::EXPECTED),
201 GetGattErrorCallback(Call::NOT_EXPECTED)); 201 GetGattErrorCallback(Call::NOT_EXPECTED));
202 EXPECT_EQ(1, gatt_write_descriptor_attempts_); 202 EXPECT_EQ(1, gatt_write_descriptor_attempts_);
203 SimulateGattDescriptorWrite(descriptor1_); 203 SimulateGattDescriptorWrite(descriptor1_);
204 204
205 // Duplicate write reported from OS shouldn't cause a problem:
206 SimulateGattDescriptorWrite(descriptor1_);
207
205 EXPECT_EQ(empty_vector, last_write_value_); 208 EXPECT_EQ(empty_vector, last_write_value_);
206 } 209 }
207 #endif // defined(OS_ANDROID) 210 #endif // defined(OS_ANDROID)
208 211
209 #if defined(OS_ANDROID) 212 #if defined(OS_ANDROID)
210 // Tests ReadRemoteDescriptor completing after Chrome objects are deleted. 213 // Tests ReadRemoteDescriptor completing after Chrome objects are deleted.
211 TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_AfterDeleted) { 214 TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor_AfterDeleted) {
212 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); 215 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate());
213 216
214 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED), 217 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED),
215 GetGattErrorCallback(Call::NOT_EXPECTED)); 218 GetGattErrorCallback(Call::NOT_EXPECTED));
216 219
217 RememberDescriptorForSubsequentAction(descriptor1_); 220 RememberDescriptorForSubsequentAction(descriptor1_);
218 DeleteDevice(device_); 221 DeleteDevice(device_); // TODO(576906) delete only the descriptor.
219 222
220 std::vector<uint8_t> empty_vector; 223 std::vector<uint8_t> empty_vector;
221 SimulateGattDescriptorRead(/* use remembered descriptor */ nullptr, 224 SimulateGattDescriptorRead(/* use remembered descriptor */ nullptr,
222 empty_vector); 225 empty_vector);
223 EXPECT_TRUE("Did not crash!"); 226 EXPECT_TRUE("Did not crash!");
224 } 227 }
225 #endif // defined(OS_ANDROID) 228 #endif // defined(OS_ANDROID)
226 229
227 #if defined(OS_ANDROID) 230 #if defined(OS_ANDROID)
228 // Tests WriteRemoteDescriptor completing after Chrome objects are deleted. 231 // Tests WriteRemoteDescriptor completing after Chrome objects are deleted.
229 TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_AfterDeleted) { 232 TEST_F(BluetoothGattDescriptorTest, WriteRemoteDescriptor_AfterDeleted) {
230 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); 233 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate());
231 234
232 std::vector<uint8_t> empty_vector; 235 std::vector<uint8_t> empty_vector;
233 descriptor1_->WriteRemoteDescriptor(empty_vector, 236 descriptor1_->WriteRemoteDescriptor(empty_vector,
234 GetCallback(Call::NOT_EXPECTED), 237 GetCallback(Call::NOT_EXPECTED),
235 GetGattErrorCallback(Call::NOT_EXPECTED)); 238 GetGattErrorCallback(Call::NOT_EXPECTED));
236 239
237 RememberDescriptorForSubsequentAction(descriptor1_); 240 RememberDescriptorForSubsequentAction(descriptor1_);
238 DeleteDevice(device_); 241 DeleteDevice(device_); // TODO(576906) delete only the descriptor.
239 242
240 SimulateGattDescriptorWrite(/* use remembered descriptor */ nullptr); 243 SimulateGattDescriptorWrite(/* use remembered descriptor */ nullptr);
241 EXPECT_TRUE("Did not crash!"); 244 EXPECT_TRUE("Did not crash!");
242 } 245 }
243 #endif // defined(OS_ANDROID) 246 #endif // defined(OS_ANDROID)
244 247
245 #if defined(OS_ANDROID) 248 #if defined(OS_ANDROID)
246 // Tests ReadRemoteDescriptor and GetValue with non-empty value buffer. 249 // Tests ReadRemoteDescriptor and GetValue with non-empty value buffer.
247 TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor) { 250 TEST_F(BluetoothGattDescriptorTest, ReadRemoteDescriptor) {
248 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); 251 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate());
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 590
588 // Initial read should still succeed: 591 // Initial read should still succeed:
589 ResetEventCounts(); 592 ResetEventCounts();
590 SimulateGattDescriptorRead(descriptor1_, empty_vector); 593 SimulateGattDescriptorRead(descriptor1_, empty_vector);
591 EXPECT_EQ(1, callback_count_); 594 EXPECT_EQ(1, callback_count_);
592 EXPECT_EQ(0, error_callback_count_); 595 EXPECT_EQ(0, error_callback_count_);
593 } 596 }
594 #endif // defined(OS_ANDROID) 597 #endif // defined(OS_ANDROID)
595 598
596 } // namespace device 599 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698