Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 12 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 13 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | 13 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
| 14 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 14 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
| 18 #include "device/bluetooth/test/bluetooth_test_android.h" | 18 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 19 #elif defined(OS_MACOSX) | 19 #elif defined(OS_MACOSX) |
| 20 #include "device/bluetooth/test/bluetooth_test_mac.h" | 20 #include "device/bluetooth/test/bluetooth_test_mac.h" |
| 21 #elif defined(OS_WIN) | 21 #elif defined(OS_WIN) |
| 22 #include "device/bluetooth/test/bluetooth_test_win.h" | 22 #include "device/bluetooth/test/bluetooth_test_win.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace device { | 25 namespace device { |
| 26 | 26 |
| 27 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 27 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 28 class BluetoothRemoteGattCharacteristicTest : public BluetoothTest { | 28 class BluetoothRemoteGattCharacteristicTest : public BluetoothTest { |
| 29 public: | 29 public: |
| 30 BluetoothDevice* GetDeviceWithGattAttributes(int device_ordinal, | |
| 31 size_t num_services, | |
| 32 size_t num_characteristics, | |
| 33 int properties) { | |
| 34 BluetoothDevice* device = SimulateLowEnergyDevice(device_ordinal); | |
| 35 | |
| 36 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
| 37 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
| 38 SimulateGattConnection(device); | |
| 39 base::RunLoop().RunUntilIdle(); | |
|
scheib
2017/04/21 23:33:11
Heads up: This pattern is changing:
https://codere
ortuno
2017/04/28 03:47:12
Those tests used a slightly different pattern in w
| |
| 40 | |
| 41 std::vector<std::string> service_uuids; | |
| 42 for (size_t s = 0; s < num_services; s++) { | |
| 43 service_uuids.push_back(kTestUUIDHeartRate); | |
| 44 } | |
| 45 SimulateGattServicesDiscovered(device, service_uuids); | |
| 46 | |
| 47 base::RunLoop().RunUntilIdle(); | |
| 48 DCHECK(num_services == device->GetGattServices().size()); | |
| 49 | |
| 50 for (BluetoothRemoteGattService* service : device->GetGattServices()) { | |
| 51 for (size_t c = 0; c < num_characteristics; c++) { | |
| 52 SimulateGattCharacteristic(service, kTestUUIDHeartRateMeasurement, | |
| 53 properties); | |
| 54 } | |
| 55 DCHECK(num_characteristics == service->GetCharacteristics().size()); | |
| 56 } | |
| 57 | |
| 58 ResetEventCounts(); | |
| 59 return device; | |
| 60 } | |
| 61 | |
| 30 // Creates adapter_, device_, service_, characteristic1_, & characteristic2_. | 62 // Creates adapter_, device_, service_, characteristic1_, & characteristic2_. |
| 31 // |properties| will be used for each characteristic. | 63 // |properties| will be used for each characteristic. |
| 32 void FakeCharacteristicBoilerplate(int properties = 0) { | 64 void FakeCharacteristicBoilerplate(int properties = 0) { |
| 33 InitWithFakeAdapter(); | 65 InitWithFakeAdapter(); |
| 34 StartLowEnergyDiscoverySession(); | 66 StartLowEnergyDiscoverySession(); |
| 35 device_ = SimulateLowEnergyDevice(3); | 67 device_ = GetDeviceWithGattAttributes( |
| 36 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 68 3 /* device_ordinal */, 1 /* num_services */, |
| 37 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 69 2 /* num_characteristics */, properties); |
| 38 SimulateGattConnection(device_); | 70 service_ = device_->GetGattServices()[0]; |
| 39 base::RunLoop().RunUntilIdle(); | 71 std::vector<BluetoothRemoteGattCharacteristic*> characteristics = |
| 72 service_->GetCharacteristics(); | |
| 73 characteristic1_ = characteristics[0]; | |
| 74 characteristic2_ = characteristics[1]; | |
| 75 } | |
| 40 | 76 |
| 41 SimulateGattServicesDiscovered( | 77 std::pair<BluetoothRemoteGattCharacteristic*, |
| 42 device_, std::vector<std::string>({kTestUUIDGenericAccess})); | 78 BluetoothRemoteGattCharacteristic*> |
| 43 base::RunLoop().RunUntilIdle(); | 79 GetCharacteristicsInDifferentServices(int properties) { |
|
scheib
2017/04/21 23:33:11
Consider naming: I named a few fixture methods suc
| |
| 44 ASSERT_EQ(1u, device_->GetGattServices().size()); | 80 InitWithFakeAdapter(); |
| 45 service_ = device_->GetGattServices()[0]; | 81 StartLowEnergyDiscoverySession(); |
| 46 SimulateGattCharacteristic(service_, kTestUUIDDeviceName, properties); | 82 BluetoothDevice* device = GetDeviceWithGattAttributes( |
| 47 SimulateGattCharacteristic(service_, kTestUUIDDeviceName, properties); | 83 3 /* device_ordinal */, 2 /* num_services */, |
| 48 ASSERT_EQ(2u, service_->GetCharacteristics().size()); | 84 1 /* num_characteristics */, properties); |
| 49 characteristic1_ = service_->GetCharacteristics()[0]; | 85 std::vector<BluetoothRemoteGattService*> services = |
| 50 characteristic2_ = service_->GetCharacteristics()[1]; | 86 device->GetGattServices(); |
| 51 ResetEventCounts(); | 87 BluetoothRemoteGattCharacteristic* char_in_service1 = |
| 88 services[0]->GetCharacteristics()[0]; | |
| 89 BluetoothRemoteGattCharacteristic* char_in_service2 = | |
| 90 services[1]->GetCharacteristics()[0]; | |
| 91 return std::make_pair(char_in_service1, char_in_service2); | |
| 92 } | |
| 93 | |
| 94 std::pair<BluetoothRemoteGattCharacteristic*, | |
| 95 BluetoothRemoteGattCharacteristic*> | |
| 96 GetCharacteristicsInDifferentDevices(int properties) { | |
| 97 InitWithFakeAdapter(); | |
| 98 StartLowEnergyDiscoverySession(); | |
| 99 BluetoothDevice* device1 = GetDeviceWithGattAttributes( | |
| 100 3 /* device_ordinal */, 2 /* num_services */, | |
|
scheib
2017/04/21 23:33:11
1 service only needed
| |
| 101 1 /* num_characteristics */, properties); | |
| 102 BluetoothRemoteGattCharacteristic* char_in_device1 = | |
| 103 device1->GetGattServices()[0]->GetCharacteristics()[0]; | |
| 104 | |
| 105 BluetoothDevice* device2 = GetDeviceWithGattAttributes( | |
| 106 4 /* device_ordinal */, 1 /* num_services */, | |
| 107 1 /* num_characteristics */, properties); | |
| 108 BluetoothRemoteGattCharacteristic* char_in_device2 = | |
| 109 device2->GetGattServices()[0]->GetCharacteristics()[0]; | |
| 110 | |
| 111 return std::make_pair(char_in_device1, char_in_device2); | |
| 52 } | 112 } |
| 53 | 113 |
| 54 enum class StartNotifySetupError { | 114 enum class StartNotifySetupError { |
| 55 CHARACTERISTIC_PROPERTIES, | 115 CHARACTERISTIC_PROPERTIES, |
| 56 CONFIG_DESCRIPTOR_MISSING, | 116 CONFIG_DESCRIPTOR_MISSING, |
| 57 CONFIG_DESCRIPTOR_DUPLICATE, | 117 CONFIG_DESCRIPTOR_DUPLICATE, |
| 58 SET_NOTIFY, | 118 SET_NOTIFY, |
| 59 WRITE_DESCRIPTOR, | 119 WRITE_DESCRIPTOR, |
| 60 NONE | 120 NONE |
| 61 }; | 121 }; |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 | 720 |
| 661 SimulateGattCharacteristicWrite(characteristic1_); | 721 SimulateGattCharacteristicWrite(characteristic1_); |
| 662 base::RunLoop().RunUntilIdle(); | 722 base::RunLoop().RunUntilIdle(); |
| 663 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 723 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 664 EXPECT_EQ(1, callback_count_); | 724 EXPECT_EQ(1, callback_count_); |
| 665 EXPECT_EQ(0, error_callback_count_); | 725 EXPECT_EQ(0, error_callback_count_); |
| 666 EXPECT_EQ(empty_vector, last_write_value_); | 726 EXPECT_EQ(empty_vector, last_write_value_); |
| 667 } | 727 } |
| 668 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 728 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 669 | 729 |
| 670 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 730 #if defined(OS_ANDROID) |
| 671 // Tests ReadRemoteCharacteristic on two characteristics. | 731 // Tests parallel ReadRemoteCharacteristic on two characteristic in the same |
| 732 // service. | |
| 733 // TODO(crbug.com/657921): Enable on macOS and Windows. | |
| 672 TEST_F(BluetoothRemoteGattCharacteristicTest, | 734 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 673 ReadRemoteCharacteristic_MultipleCharacteristics) { | 735 ReadRemoteCharacteristic_MultipleCharacteristicsInService) { |
| 674 if (!PlatformSupportsLowEnergy()) { | 736 if (!PlatformSupportsLowEnergy()) { |
| 675 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 737 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 676 return; | 738 return; |
| 677 } | 739 } |
| 678 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 740 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 679 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); | 741 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
| 680 | 742 |
| 681 characteristic1_->ReadRemoteCharacteristic( | 743 characteristic1_->ReadRemoteCharacteristic( |
| 682 GetReadValueCallback(Call::EXPECTED), | 744 GetReadValueCallback(Call::EXPECTED), |
| 683 GetGattErrorCallback(Call::NOT_EXPECTED)); | 745 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 684 characteristic2_->ReadRemoteCharacteristic( | 746 characteristic2_->ReadRemoteCharacteristic( |
| 685 GetReadValueCallback(Call::EXPECTED), | 747 GetReadValueCallback(Call::NOT_EXPECTED), |
| 686 GetGattErrorCallback(Call::NOT_EXPECTED)); | 748 GetGattErrorCallback(Call::EXPECTED)); |
| 687 EXPECT_EQ(0, callback_count_); | 749 |
| 688 EXPECT_EQ(0, error_callback_count_); | 750 EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| 689 | 751 EXPECT_EQ(0, callback_count_); |
| 690 std::vector<uint8_t> test_vector1; | 752 EXPECT_EQ(0, error_callback_count_); |
| 691 test_vector1.push_back(111); | 753 |
| 754 base::RunLoop().RunUntilIdle(); | |
| 755 | |
| 756 EXPECT_EQ(0, callback_count_); | |
| 757 EXPECT_EQ(1, error_callback_count_); | |
| 758 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, | |
| 759 last_gatt_error_code_); | |
| 760 | |
| 761 ResetEventCounts(); | |
| 762 | |
| 763 std::vector<uint8_t> test_vector1({111}); | |
| 692 SimulateGattCharacteristicRead(characteristic1_, test_vector1); | 764 SimulateGattCharacteristicRead(characteristic1_, test_vector1); |
| 693 base::RunLoop().RunUntilIdle(); | 765 base::RunLoop().RunUntilIdle(); |
| 694 EXPECT_EQ(test_vector1, last_read_value_); | 766 EXPECT_EQ(test_vector1, last_read_value_); |
| 695 | |
| 696 std::vector<uint8_t> test_vector2; | |
| 697 test_vector2.push_back(222); | |
| 698 SimulateGattCharacteristicRead(characteristic2_, test_vector2); | |
| 699 base::RunLoop().RunUntilIdle(); | |
| 700 EXPECT_EQ(test_vector2, last_read_value_); | |
| 701 | |
| 702 EXPECT_EQ(2, gatt_read_characteristic_attempts_); | |
| 703 EXPECT_EQ(2, callback_count_); | |
| 704 EXPECT_EQ(0, error_callback_count_); | |
| 705 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 767 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 706 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); | 768 EXPECT_EQ(1, callback_count_); |
|
scheib
2017/04/21 23:33:11
The meaning of the test is changing. Before, it wa
| |
| 707 } | 769 EXPECT_EQ(0, error_callback_count_); |
| 708 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 770 } |
| 709 | 771 #endif // defined(OS_ANDROID) |
| 710 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 772 |
| 711 // Tests WriteRemoteCharacteristic on two characteristics. | 773 #if defined(OS_ANDROID) |
| 712 TEST_F(BluetoothRemoteGattCharacteristicTest, | 774 // Tests parallel ReadRemoteCharacteristic on two characteristic in the same |
| 713 WriteRemoteCharacteristic_MultipleCharacteristics) { | 775 // service. |
| 776 // TODO(crbug.com/657921): Enable on macOS and Windows. | |
| 777 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 778 WriteRemoteCharacteristic_MultipleCharacteristicsInService) { | |
| 714 if (!PlatformSupportsLowEnergy()) { | 779 if (!PlatformSupportsLowEnergy()) { |
| 715 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 780 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 716 return; | 781 return; |
| 717 } | 782 } |
| 718 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 783 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 719 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); | 784 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
| 720 | 785 |
| 721 std::vector<uint8_t> test_vector1; | 786 std::vector<uint8_t> test_vector1({111}); |
| 722 test_vector1.push_back(111); | |
| 723 characteristic1_->WriteRemoteCharacteristic( | 787 characteristic1_->WriteRemoteCharacteristic( |
| 724 test_vector1, GetCallback(Call::EXPECTED), | 788 test_vector1, GetCallback(Call::EXPECTED), |
| 725 GetGattErrorCallback(Call::NOT_EXPECTED)); | 789 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 726 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 790 EXPECT_EQ(test_vector1, last_write_value_); |
| 727 EXPECT_EQ(test_vector1, last_write_value_); | 791 |
| 792 std::vector<uint8_t> test_vector2({222}); | |
| 793 characteristic2_->WriteRemoteCharacteristic( | |
| 794 test_vector2, GetCallback(Call::NOT_EXPECTED), | |
| 795 GetGattErrorCallback(Call::EXPECTED)); | |
| 796 EXPECT_EQ(test_vector1, last_write_value_); | |
| 797 | |
| 798 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | |
| 799 EXPECT_EQ(0, callback_count_); | |
| 800 EXPECT_EQ(0, error_callback_count_); | |
| 801 | |
| 802 base::RunLoop().RunUntilIdle(); | |
| 803 | |
| 804 EXPECT_EQ(0, callback_count_); | |
| 805 EXPECT_EQ(1, error_callback_count_); | |
| 806 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, | |
| 807 last_gatt_error_code_); | |
| 808 | |
| 809 ResetEventCounts(); | |
| 810 | |
| 811 SimulateGattCharacteristicWrite(characteristic1_); | |
| 812 base::RunLoop().RunUntilIdle(); | |
| 813 EXPECT_EQ(1, callback_count_); | |
| 814 EXPECT_EQ(0, error_callback_count_); | |
| 815 } | |
| 816 #endif // defined(OS_ANDROID) | |
| 817 | |
| 818 #if defined(OS_ANDROID) | |
| 819 // Tests parallel ReadRemoteCharacteristic on two characteristics on different | |
| 820 // services but on the same device. | |
|
scheib
2017/04/21 23:33:11
I pause thinking about the number of test permutat
| |
| 821 // TODO(crbug.com/657921): Enable on macOS and Windows. | |
| 822 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 823 ReadRemoteCharacteristic_MultipleCharacteristicsInDevice) { | |
| 824 if (!PlatformSupportsLowEnergy()) { | |
| 825 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 826 return; | |
| 827 } | |
| 828 | |
| 829 BluetoothRemoteGattCharacteristic* characteristic_in_service1; | |
| 830 BluetoothRemoteGattCharacteristic* characteristic_in_service2; | |
| 831 std::tie(characteristic_in_service1, characteristic_in_service2) = | |
| 832 GetCharacteristicsInDifferentServices( | |
| 833 BluetoothRemoteGattCharacteristic::PROPERTY_READ); | |
| 834 | |
| 835 characteristic_in_service1->ReadRemoteCharacteristic( | |
| 836 GetReadValueCallback(Call::EXPECTED), | |
| 837 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 838 characteristic_in_service2->ReadRemoteCharacteristic( | |
| 839 GetReadValueCallback(Call::NOT_EXPECTED), | |
| 840 GetGattErrorCallback(Call::EXPECTED)); | |
| 841 | |
| 842 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 843 EXPECT_EQ(0, callback_count_); | |
| 844 EXPECT_EQ(0, error_callback_count_); | |
| 845 | |
| 846 base::RunLoop().RunUntilIdle(); | |
| 847 | |
| 848 EXPECT_EQ(0, callback_count_); | |
| 849 EXPECT_EQ(1, error_callback_count_); | |
| 850 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, | |
| 851 last_gatt_error_code_); | |
| 852 | |
| 853 ResetEventCounts(); | |
| 854 | |
| 855 std::vector<uint8_t> test_vector1({111}); | |
| 856 SimulateGattCharacteristicRead(characteristic_in_service1, test_vector1); | |
| 857 base::RunLoop().RunUntilIdle(); | |
| 858 EXPECT_EQ(test_vector1, last_read_value_); | |
| 859 EXPECT_EQ(test_vector1, characteristic_in_service1->GetValue()); | |
| 860 EXPECT_EQ(1, callback_count_); | |
| 861 EXPECT_EQ(0, error_callback_count_); | |
| 862 } | |
| 863 #endif // defined(OS_ANDROID) | |
| 864 | |
| 865 #if defined(OS_ANDROID) | |
| 866 // Tests parallel WriteRemoteCharacteristic on two characteristics on different | |
| 867 // services but on the same device. | |
| 868 // TODO(crbug.com/657921): Enable on macOS and Windows. | |
| 869 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 870 WriteRemoteCharacteristic_MultipleCharacteristicsInDevice) { | |
| 871 if (!PlatformSupportsLowEnergy()) { | |
| 872 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 873 return; | |
| 874 } | |
| 875 BluetoothRemoteGattCharacteristic* characteristic_in_service1; | |
| 876 BluetoothRemoteGattCharacteristic* characteristic_in_service2; | |
| 877 std::tie(characteristic_in_service1, characteristic_in_service2) = | |
| 878 GetCharacteristicsInDifferentServices( | |
| 879 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE); | |
| 880 | |
| 881 std::vector<uint8_t> test_vector1({111}); | |
| 882 characteristic_in_service1->WriteRemoteCharacteristic( | |
| 883 test_vector1, GetCallback(Call::EXPECTED), | |
| 884 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 885 EXPECT_EQ(test_vector1, last_write_value_); | |
| 886 | |
| 887 std::vector<uint8_t> test_vector2({222}); | |
| 888 characteristic_in_service2->WriteRemoteCharacteristic( | |
| 889 test_vector2, GetCallback(Call::NOT_EXPECTED), | |
| 890 GetGattErrorCallback(Call::EXPECTED)); | |
| 891 EXPECT_EQ(test_vector1, last_write_value_); | |
| 892 | |
| 893 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | |
| 894 EXPECT_EQ(0, callback_count_); | |
| 895 EXPECT_EQ(0, error_callback_count_); | |
| 896 | |
| 897 base::RunLoop().RunUntilIdle(); | |
| 898 | |
| 899 EXPECT_EQ(0, callback_count_); | |
| 900 EXPECT_EQ(1, error_callback_count_); | |
| 901 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, | |
| 902 last_gatt_error_code_); | |
| 903 | |
| 904 ResetEventCounts(); | |
| 905 | |
| 906 SimulateGattCharacteristicWrite(characteristic_in_service1); | |
| 907 base::RunLoop().RunUntilIdle(); | |
| 908 EXPECT_EQ(1, callback_count_); | |
| 909 EXPECT_EQ(0, error_callback_count_); | |
| 910 } | |
| 911 #endif // defined(OS_ANDROID) | |
| 912 | |
| 913 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | |
| 914 // Tests parallel ReadRemoteCharacteristic on two characteristics on different | |
| 915 // devices. | |
| 916 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 917 ReadRemoteCharacteristic_MultipleCharacteristicsInAdapter) { | |
| 918 if (!PlatformSupportsLowEnergy()) { | |
| 919 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 920 return; | |
| 921 } | |
| 922 | |
| 923 BluetoothRemoteGattCharacteristic* characteristic_in_device1; | |
| 924 BluetoothRemoteGattCharacteristic* characteristic_in_device2; | |
| 925 std::tie(characteristic_in_device1, characteristic_in_device2) = | |
| 926 GetCharacteristicsInDifferentDevices( | |
| 927 BluetoothRemoteGattCharacteristic::PROPERTY_READ); | |
| 928 | |
| 929 characteristic_in_device1->ReadRemoteCharacteristic( | |
| 930 GetReadValueCallback(Call::EXPECTED), | |
| 931 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 932 characteristic_in_device2->ReadRemoteCharacteristic( | |
| 933 GetReadValueCallback(Call::EXPECTED), | |
| 934 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 935 | |
| 936 #if !defined(OS_WIN) | |
| 937 // TODO(crbug.com/713991): Remove #if once all platforms increate the counters | |
| 938 // at the same time. | |
| 939 EXPECT_EQ(2, gatt_read_characteristic_attempts_); | |
| 728 #endif | 940 #endif |
| 729 | 941 EXPECT_EQ(0, callback_count_); |
| 730 std::vector<uint8_t> test_vector2; | 942 EXPECT_EQ(0, error_callback_count_); |
| 731 test_vector2.push_back(222); | 943 |
| 732 characteristic2_->WriteRemoteCharacteristic( | 944 base::RunLoop().RunUntilIdle(); |
| 945 | |
| 946 EXPECT_EQ(0, callback_count_); | |
| 947 EXPECT_EQ(0, error_callback_count_); | |
| 948 | |
| 949 std::vector<uint8_t> test_vector1({111}); | |
| 950 SimulateGattCharacteristicRead(characteristic_in_device1, test_vector1); | |
| 951 std::vector<uint8_t> test_vector2({222}); | |
| 952 SimulateGattCharacteristicRead(characteristic_in_device2, test_vector2); | |
| 953 | |
| 954 base::RunLoop().RunUntilIdle(); | |
| 955 EXPECT_EQ(test_vector1, characteristic_in_device1->GetValue()); | |
| 956 EXPECT_EQ(test_vector2, characteristic_in_device2->GetValue()); | |
| 957 EXPECT_EQ(test_vector2, last_read_value_); | |
| 958 EXPECT_EQ(2, callback_count_); | |
| 959 EXPECT_EQ(0, error_callback_count_); | |
| 960 } | |
| 961 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | |
| 962 | |
| 963 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | |
| 964 // Tests parallel WriteRemoteCharacteristic on two characteristics on different | |
| 965 // devices. | |
| 966 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 967 WriteRemoteCharacteristic_MultipleCharacteristicsInAdapter) { | |
| 968 if (!PlatformSupportsLowEnergy()) { | |
| 969 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 970 return; | |
| 971 } | |
| 972 BluetoothRemoteGattCharacteristic* characteristic_in_device1; | |
| 973 BluetoothRemoteGattCharacteristic* characteristic_in_device2; | |
| 974 std::tie(characteristic_in_device1, characteristic_in_device2) = | |
| 975 GetCharacteristicsInDifferentDevices( | |
| 976 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE); | |
| 977 | |
| 978 std::vector<uint8_t> test_vector1({111}); | |
| 979 characteristic_in_device1->WriteRemoteCharacteristic( | |
| 980 test_vector1, GetCallback(Call::EXPECTED), | |
| 981 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 982 #if !defined(OS_WIN) | |
| 983 // TODO(crbug.com/713991): Remove #if once all platforms increate the counters | |
| 984 // at the same time. | |
| 985 EXPECT_EQ(test_vector1, last_write_value_); | |
| 986 #endif | |
| 987 | |
| 988 std::vector<uint8_t> test_vector2({222}); | |
| 989 characteristic_in_device2->WriteRemoteCharacteristic( | |
| 733 test_vector2, GetCallback(Call::EXPECTED), | 990 test_vector2, GetCallback(Call::EXPECTED), |
| 734 GetGattErrorCallback(Call::NOT_EXPECTED)); | 991 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 735 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 992 #if !defined(OS_WIN) |
| 993 // TODO(crbug.com/713991): Remove #if once all platforms increate the counters | |
| 994 // at the same time. | |
| 736 EXPECT_EQ(test_vector2, last_write_value_); | 995 EXPECT_EQ(test_vector2, last_write_value_); |
| 996 | |
| 997 EXPECT_EQ(2, gatt_write_characteristic_attempts_); | |
| 737 #endif | 998 #endif |
| 738 | 999 EXPECT_EQ(0, callback_count_); |
| 739 EXPECT_EQ(0, callback_count_); | 1000 EXPECT_EQ(0, error_callback_count_); |
| 740 EXPECT_EQ(0, error_callback_count_); | 1001 |
| 741 | 1002 base::RunLoop().RunUntilIdle(); |
| 742 SimulateGattCharacteristicWrite(characteristic1_); | 1003 |
| 743 base::RunLoop().RunUntilIdle(); | 1004 EXPECT_EQ(0, callback_count_); |
| 744 #if !(defined(OS_ANDROID) || defined(OS_MACOSX)) | 1005 EXPECT_EQ(0, error_callback_count_); |
| 745 EXPECT_EQ(test_vector1, last_write_value_); | 1006 |
| 746 #endif | 1007 SimulateGattCharacteristicWrite(characteristic_in_device1); |
| 747 | 1008 SimulateGattCharacteristicWrite(characteristic_in_device2); |
| 748 SimulateGattCharacteristicWrite(characteristic2_); | 1009 base::RunLoop().RunUntilIdle(); |
| 749 base::RunLoop().RunUntilIdle(); | |
| 750 #if !(defined(OS_ANDROID) || defined(OS_MACOSX)) | |
| 751 EXPECT_EQ(test_vector2, last_write_value_); | |
| 752 #endif | |
| 753 | |
| 754 EXPECT_EQ(2, gatt_write_characteristic_attempts_); | |
| 755 EXPECT_EQ(2, callback_count_); | 1010 EXPECT_EQ(2, callback_count_); |
| 756 EXPECT_EQ(0, error_callback_count_); | 1011 EXPECT_EQ(0, error_callback_count_); |
| 757 | |
| 758 // TODO(591740): Remove if define for OS_ANDROID in this test. | |
| 759 } | 1012 } |
| 760 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1013 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 761 | 1014 |
| 762 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1015 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 763 // Tests ReadRemoteCharacteristic asynchronous error. | 1016 // Tests ReadRemoteCharacteristic asynchronous error. |
| 764 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadError) { | 1017 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadError) { |
| 765 if (!PlatformSupportsLowEnergy()) { | 1018 if (!PlatformSupportsLowEnergy()) { |
| 766 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1019 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 767 return; | 1020 return; |
| 768 } | 1021 } |
| (...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2384 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2637 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2385 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); | 2638 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2386 | 2639 |
| 2387 SimulateGattDisconnection(device_); | 2640 SimulateGattDisconnection(device_); |
| 2388 // Don't run the disconnect task. | 2641 // Don't run the disconnect task. |
| 2389 notify_sessions_.clear(); | 2642 notify_sessions_.clear(); |
| 2390 base::RunLoop().RunUntilIdle(); | 2643 base::RunLoop().RunUntilIdle(); |
| 2391 } | 2644 } |
| 2392 #endif | 2645 #endif |
| 2393 } // namespace device | 2646 } // namespace device |
| OLD | NEW |