| OLD | NEW |
| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |