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 "device/bluetooth/bluetooth_gatt_characteristic.h" | 5 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 // Indicate. | 842 // Indicate. |
843 TEST_F(BluetoothGattCharacteristicTest, | 843 TEST_F(BluetoothGattCharacteristicTest, |
844 StartNotifySession_OnNotifyAndIndicate) { | 844 StartNotifySession_OnNotifyAndIndicate) { |
845 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 845 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
846 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 846 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
847 /* expected_config_descriptor_value: NOTIFY */ 1)); | 847 /* expected_config_descriptor_value: NOTIFY */ 1)); |
848 } | 848 } |
849 #endif // defined(OS_ANDROID) | 849 #endif // defined(OS_ANDROID) |
850 | 850 |
851 #if defined(OS_ANDROID) | 851 #if defined(OS_ANDROID) |
| 852 // Tests multiple StartNotifySession success. |
| 853 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| 854 ASSERT_NO_FATAL_FAILURE( |
| 855 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 856 SimulateGattDescriptor( |
| 857 characteristic1_, |
| 858 /* Client Characteristic Configuration descriptor's standard UUID: */ |
| 859 "00002902-0000-1000-8000-00805F9B34FB"); |
| 860 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 861 |
| 862 characteristic1_->StartNotifySession( |
| 863 GetNotifyCallback(Call::EXPECTED), |
| 864 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 865 characteristic1_->StartNotifySession( |
| 866 GetNotifyCallback(Call::EXPECTED), |
| 867 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 868 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 869 EXPECT_EQ(0, callback_count_); |
| 870 SimulateGattNotifySessionStarted(characteristic1_); |
| 871 EXPECT_EQ(2, callback_count_); |
| 872 EXPECT_EQ(0, error_callback_count_); |
| 873 ASSERT_EQ(2u, notify_sessions_.size()); |
| 874 ASSERT_TRUE(notify_sessions_[0]); |
| 875 ASSERT_TRUE(notify_sessions_[1]); |
| 876 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 877 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 878 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 879 notify_sessions_[1]->GetCharacteristicIdentifier()); |
| 880 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 881 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 882 } |
| 883 #endif // defined(OS_ANDROID) |
| 884 |
| 885 #if defined(OS_ANDROID) |
852 // Tests Characteristic Value changes during a Notify Session. | 886 // Tests Characteristic Value changes during a Notify Session. |
853 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { | 887 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { |
854 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 888 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
855 /* properties: NOTIFY */ 0x10, | 889 /* properties: NOTIFY */ 0x10, |
856 /* expected_config_descriptor_value: NOTIFY */ 1)); | 890 /* expected_config_descriptor_value: NOTIFY */ 1)); |
857 | 891 |
858 TestBluetoothAdapterObserver observer(adapter_); | 892 TestBluetoothAdapterObserver observer(adapter_); |
859 | 893 |
860 std::vector<uint8_t> test_vector1, test_vector2; | 894 std::vector<uint8_t> test_vector1, test_vector2; |
861 test_vector1.push_back(111); | 895 test_vector1.push_back(111); |
(...skipping 21 matching lines...) Expand all Loading... |
883 RememberCharacteristicForSubsequentAction(characteristic1_); | 917 RememberCharacteristicForSubsequentAction(characteristic1_); |
884 DeleteDevice(device_); | 918 DeleteDevice(device_); |
885 | 919 |
886 std::vector<uint8_t> empty_vector; | 920 std::vector<uint8_t> empty_vector; |
887 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, | 921 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, |
888 empty_vector); | 922 empty_vector); |
889 EXPECT_TRUE("Did not crash!"); | 923 EXPECT_TRUE("Did not crash!"); |
890 } | 924 } |
891 #endif // defined(OS_ANDROID) | 925 #endif // defined(OS_ANDROID) |
892 | 926 |
893 #if defined(OS_ANDROID) | |
894 // Tests multiple StartNotifySession success. | |
895 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { | |
896 ASSERT_NO_FATAL_FAILURE( | |
897 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | |
898 SimulateGattDescriptor( | |
899 characteristic1_, | |
900 /* Client Characteristic Configuration descriptor's standard UUID: */ | |
901 "00002902-0000-1000-8000-00805F9B34FB"); | |
902 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | |
903 | |
904 characteristic1_->StartNotifySession( | |
905 GetNotifyCallback(Call::EXPECTED), | |
906 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
907 characteristic1_->StartNotifySession( | |
908 GetNotifyCallback(Call::EXPECTED), | |
909 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
910 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
911 EXPECT_EQ(0, callback_count_); | |
912 SimulateGattNotifySessionStarted(characteristic1_); | |
913 EXPECT_EQ(2, callback_count_); | |
914 EXPECT_EQ(0, error_callback_count_); | |
915 ASSERT_EQ(2u, notify_sessions_.size()); | |
916 ASSERT_TRUE(notify_sessions_[0]); | |
917 ASSERT_TRUE(notify_sessions_[1]); | |
918 EXPECT_EQ(characteristic1_->GetIdentifier(), | |
919 notify_sessions_[0]->GetCharacteristicIdentifier()); | |
920 EXPECT_EQ(characteristic1_->GetIdentifier(), | |
921 notify_sessions_[1]->GetCharacteristicIdentifier()); | |
922 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | |
923 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | |
924 } | |
925 #endif // defined(OS_ANDROID) | |
926 | |
927 #if defined(OS_ANDROID) || defined(OS_WIN) | 927 #if defined(OS_ANDROID) || defined(OS_WIN) |
928 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { | 928 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { |
929 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 929 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
930 | 930 |
931 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); | 931 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); |
932 } | 932 } |
933 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 933 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
934 | 934 |
935 #if defined(OS_ANDROID) || defined(OS_WIN) | 935 #if defined(OS_ANDROID) || defined(OS_WIN) |
936 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_and_GetDescriptor) { | 936 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_and_GetDescriptor) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 | 971 |
972 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). | 972 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). |
973 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); | 973 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); |
974 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); | 974 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); |
975 // ... but not uuid 3 | 975 // ... but not uuid 3 |
976 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); | 976 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); |
977 } | 977 } |
978 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 978 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
979 | 979 |
980 } // namespace device | 980 } // namespace device |
OLD | NEW |