| 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_remote_gatt_characteristic.h" | 6 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 7 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | 7 #include "device/bluetooth/bluetooth_remote_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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 | 633 |
| 634 // Initial read should still succeed: | 634 // Initial read should still succeed: |
| 635 ResetEventCounts(); | 635 ResetEventCounts(); |
| 636 SimulateGattDescriptorRead(descriptor1_, empty_vector); | 636 SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| 637 base::RunLoop().RunUntilIdle(); | 637 base::RunLoop().RunUntilIdle(); |
| 638 EXPECT_EQ(1, callback_count_); | 638 EXPECT_EQ(1, callback_count_); |
| 639 EXPECT_EQ(0, error_callback_count_); | 639 EXPECT_EQ(0, error_callback_count_); |
| 640 } | 640 } |
| 641 #endif // defined(OS_ANDROID) | 641 #endif // defined(OS_ANDROID) |
| 642 | 642 |
| 643 #if defined(OS_ANDROID) |
| 644 // Tests that read requests after a device disconnects but before the |
| 645 // disconnect task runs do not result in a crash. |
| 646 // macOS: Does not apply. All events arrive on the UI Thread. |
| 647 // TODO(crbug.com/694102): Enable this test on Windows. |
| 648 TEST_F(BluetoothRemoteGattDescriptorTest, ReadDuringDisconnect) { |
| 649 if (!PlatformSupportsLowEnergy()) { |
| 650 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 651 return; |
| 652 } |
| 653 |
| 654 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| 655 |
| 656 SimulateGattDisconnection(device_); |
| 657 // Don't run the disconnect task. |
| 658 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::NOT_EXPECTED), |
| 659 // TODO(crbug.com/621901): Expect an error. |
| 660 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 661 |
| 662 base::RunLoop().RunUntilIdle(); |
| 663 // TODO(crbug.com/621901): Test error callback was called. |
| 664 } |
| 665 #endif // defined(OS_ANDROID) |
| 666 |
| 667 #if defined(OS_ANDROID) |
| 668 // Tests that write requests after a device disconnects but before the |
| 669 // disconnect task runs do not result in a crash. |
| 670 // macOS: Does not apply. All events arrive on the UI Thread. |
| 671 // TODO(crbug.com/694102): Enable this test on Windows. |
| 672 TEST_F(BluetoothRemoteGattDescriptorTest, WriteDuringDisconnect) { |
| 673 if (!PlatformSupportsLowEnergy()) { |
| 674 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 675 return; |
| 676 } |
| 677 |
| 678 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| 679 |
| 680 SimulateGattDisconnection(device_); |
| 681 // Don't run the disconnect task. |
| 682 descriptor1_->WriteRemoteDescriptor( |
| 683 std::vector<uint8_t>(), GetCallback(Call::NOT_EXPECTED), |
| 684 // TODO(crbug.com/621901): Expect an error. |
| 685 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 686 |
| 687 base::RunLoop().RunUntilIdle(); |
| 688 // TODO(crbug.com/621901): Test that an error was returned. |
| 689 } |
| 690 #endif // defined(OS_ANDROID) |
| 691 |
| 643 } // namespace device | 692 } // namespace device |
| OLD | NEW |