| 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" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "device/bluetooth/bluetooth_gatt_service.h" | 12 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 13 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
| 16 #include "device/bluetooth/test/bluetooth_test_android.h" | 17 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 17 #elif defined(OS_MACOSX) | 18 #elif defined(OS_MACOSX) |
| 18 #include "device/bluetooth/test/bluetooth_test_mac.h" | 19 #include "device/bluetooth/test/bluetooth_test_mac.h" |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 namespace device { | 22 namespace device { |
| 22 | 23 |
| 23 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 24 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 24 class BluetoothGattCharacteristicTest : public BluetoothTest { | 25 class BluetoothGattCharacteristicTest : public BluetoothTest { |
| 25 public: | 26 public: |
| 26 // Creates adapter_, device_, service_, characteristic1_, & characteristic2_. | 27 // Creates adapter_, device_, service_, characteristic1_, & characteristic2_. |
| 27 void FakeCharacteristicBoilerplate() { | 28 // |properties| will be used for each characteristic. |
| 29 void FakeCharacteristicBoilerplate(int properties = 0) { |
| 28 InitWithFakeAdapter(); | 30 InitWithFakeAdapter(); |
| 29 StartLowEnergyDiscoverySession(); | 31 StartLowEnergyDiscoverySession(); |
| 30 device_ = DiscoverLowEnergyDevice(3); | 32 device_ = DiscoverLowEnergyDevice(3); |
| 31 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 33 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 32 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 34 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 33 SimulateGattConnection(device_); | 35 SimulateGattConnection(device_); |
| 34 std::vector<std::string> services; | 36 std::vector<std::string> services; |
| 35 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); | 37 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); |
| 36 services.push_back(uuid); | 38 services.push_back(uuid); |
| 37 SimulateGattServicesDiscovered(device_, services); | 39 SimulateGattServicesDiscovered(device_, services); |
| 38 ASSERT_EQ(1u, device_->GetGattServices().size()); | 40 ASSERT_EQ(1u, device_->GetGattServices().size()); |
| 39 service_ = device_->GetGattServices()[0]; | 41 service_ = device_->GetGattServices()[0]; |
| 40 SimulateGattCharacteristic(service_, uuid, /* properties */ 0); | 42 SimulateGattCharacteristic(service_, uuid, properties); |
| 41 SimulateGattCharacteristic(service_, uuid, /* properties */ 0); | 43 SimulateGattCharacteristic(service_, uuid, properties); |
| 42 ASSERT_EQ(2u, service_->GetCharacteristics().size()); | 44 ASSERT_EQ(2u, service_->GetCharacteristics().size()); |
| 43 characteristic1_ = service_->GetCharacteristics()[0]; | 45 characteristic1_ = service_->GetCharacteristics()[0]; |
| 44 characteristic2_ = service_->GetCharacteristics()[1]; | 46 characteristic2_ = service_->GetCharacteristics()[1]; |
| 45 ResetEventCounts(); | 47 ResetEventCounts(); |
| 46 } | 48 } |
| 47 | 49 |
| 50 // Constructs characteristics with |properties|, calls StartNotifySession, |
| 51 // and verifies the appropriate |expected_config_descriptor_value| is written. |
| 52 void StartNotifyBoilerplate(int properties, |
| 53 uint16_t expected_config_descriptor_value) { |
| 54 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(properties)); |
| 55 SimulateGattDescriptor( |
| 56 characteristic1_, |
| 57 /* Client Characteristic Configuration descriptor's standard UUID: */ |
| 58 "00002902-0000-1000-8000-00805F9B34FB"); |
| 59 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 60 |
| 61 characteristic1_->StartNotifySession( |
| 62 GetNotifyCallback(Call::EXPECTED), |
| 63 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 64 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 65 EXPECT_EQ(0, callback_count_); |
| 66 SimulateGattNotifySessionStarted(characteristic1_); |
| 67 EXPECT_EQ(1, callback_count_); |
| 68 EXPECT_EQ(0, error_callback_count_); |
| 69 ASSERT_EQ(1u, notify_sessions_.size()); |
| 70 ASSERT_TRUE(notify_sessions_[0]); |
| 71 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 72 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 73 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 74 |
| 75 // Verify the Client Characteristic Configuration descriptor was written to. |
| 76 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| 77 EXPECT_EQ(2u, last_write_value_.size()); |
| 78 uint8_t expected_byte0 = expected_config_descriptor_value & 0xFF; |
| 79 uint8_t expected_byte1 = (expected_config_descriptor_value >> 8) & 0xFF; |
| 80 EXPECT_EQ(expected_byte0, last_write_value_[0]); |
| 81 EXPECT_EQ(expected_byte1, last_write_value_[1]); |
| 82 } |
| 83 |
| 48 BluetoothDevice* device_ = nullptr; | 84 BluetoothDevice* device_ = nullptr; |
| 49 BluetoothGattService* service_ = nullptr; | 85 BluetoothGattService* service_ = nullptr; |
| 50 BluetoothGattCharacteristic* characteristic1_ = nullptr; | 86 BluetoothGattCharacteristic* characteristic1_ = nullptr; |
| 51 BluetoothGattCharacteristic* characteristic2_ = nullptr; | 87 BluetoothGattCharacteristic* characteristic2_ = nullptr; |
| 52 }; | 88 }; |
| 53 #endif | 89 #endif |
| 54 | 90 |
| 55 #if defined(OS_ANDROID) | 91 #if defined(OS_ANDROID) |
| 56 TEST_F(BluetoothGattCharacteristicTest, GetIdentifier) { | 92 TEST_F(BluetoothGattCharacteristicTest, GetIdentifier) { |
| 57 InitWithFakeAdapter(); | 93 InitWithFakeAdapter(); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 characteristic1_->ReadRemoteCharacteristic( | 271 characteristic1_->ReadRemoteCharacteristic( |
| 236 GetReadValueCallback(Call::NOT_EXPECTED), | 272 GetReadValueCallback(Call::NOT_EXPECTED), |
| 237 GetGattErrorCallback(Call::NOT_EXPECTED)); | 273 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 238 | 274 |
| 239 RememberCharacteristicForSubsequentAction(characteristic1_); | 275 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 240 DeleteDevice(device_); | 276 DeleteDevice(device_); |
| 241 | 277 |
| 242 std::vector<uint8_t> empty_vector; | 278 std::vector<uint8_t> empty_vector; |
| 243 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, | 279 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, |
| 244 empty_vector); | 280 empty_vector); |
| 281 EXPECT_TRUE("Did not crash!"); |
| 245 } | 282 } |
| 246 #endif // defined(OS_ANDROID) | 283 #endif // defined(OS_ANDROID) |
| 247 | 284 |
| 248 #if defined(OS_ANDROID) | 285 #if defined(OS_ANDROID) |
| 249 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. | 286 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. |
| 250 TEST_F(BluetoothGattCharacteristicTest, | 287 TEST_F(BluetoothGattCharacteristicTest, |
| 251 WriteRemoteCharacteristic_AfterDeleted) { | 288 WriteRemoteCharacteristic_AfterDeleted) { |
| 252 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 289 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 253 | 290 |
| 254 std::vector<uint8_t> empty_vector; | 291 std::vector<uint8_t> empty_vector; |
| 255 characteristic1_->WriteRemoteCharacteristic( | 292 characteristic1_->WriteRemoteCharacteristic( |
| 256 empty_vector, GetCallback(Call::NOT_EXPECTED), | 293 empty_vector, GetCallback(Call::NOT_EXPECTED), |
| 257 GetGattErrorCallback(Call::NOT_EXPECTED)); | 294 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 258 | 295 |
| 259 RememberCharacteristicForSubsequentAction(characteristic1_); | 296 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 260 DeleteDevice(device_); | 297 DeleteDevice(device_); |
| 261 | 298 |
| 262 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); | 299 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); |
| 300 EXPECT_TRUE("Did not crash!"); |
| 263 } | 301 } |
| 264 #endif // defined(OS_ANDROID) | 302 #endif // defined(OS_ANDROID) |
| 265 | 303 |
| 266 #if defined(OS_ANDROID) | 304 #if defined(OS_ANDROID) |
| 267 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. | 305 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. |
| 268 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { | 306 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { |
| 269 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 307 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 270 | 308 |
| 271 characteristic1_->ReadRemoteCharacteristic( | 309 characteristic1_->ReadRemoteCharacteristic( |
| 272 GetReadValueCallback(Call::EXPECTED), | 310 GetReadValueCallback(Call::EXPECTED), |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 669 |
| 632 // Initial read should still succeed: | 670 // Initial read should still succeed: |
| 633 ResetEventCounts(); | 671 ResetEventCounts(); |
| 634 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 672 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 635 EXPECT_EQ(1, callback_count_); | 673 EXPECT_EQ(1, callback_count_); |
| 636 EXPECT_EQ(0, error_callback_count_); | 674 EXPECT_EQ(0, error_callback_count_); |
| 637 } | 675 } |
| 638 #endif // defined(OS_ANDROID) | 676 #endif // defined(OS_ANDROID) |
| 639 | 677 |
| 640 #if defined(OS_ANDROID) | 678 #if defined(OS_ANDROID) |
| 641 // Tests StartNotifySession success. | 679 // StartNotifySession fails if characteristic doesn't have Notify or Indicate |
| 642 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { | 680 // property. |
| 681 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { |
| 643 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 682 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 644 | 683 |
| 645 characteristic1_->StartNotifySession( | 684 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 646 GetNotifyCallback(Call::EXPECTED), | 685 GetGattErrorCallback(Call::EXPECTED)); |
| 647 GetGattErrorCallback(Call::NOT_EXPECTED)); | 686 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 648 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 687 |
| 649 EXPECT_EQ(0, callback_count_); | 688 // The expected error callback is asynchronous: |
| 650 SimulateGattNotifySessionStarted(characteristic1_); | |
| 651 EXPECT_EQ(1, callback_count_); | |
| 652 EXPECT_EQ(0, error_callback_count_); | 689 EXPECT_EQ(0, error_callback_count_); |
| 653 ASSERT_EQ(1u, notify_sessions_.size()); | 690 base::RunLoop().RunUntilIdle(); |
| 654 ASSERT_TRUE(notify_sessions_[0]); | 691 EXPECT_EQ(1, error_callback_count_); |
| 655 EXPECT_EQ(characteristic1_->GetIdentifier(), | |
| 656 notify_sessions_[0]->GetCharacteristicIdentifier()); | |
| 657 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | |
| 658 } | 692 } |
| 659 #endif // defined(OS_ANDROID) | 693 #endif // defined(OS_ANDROID) |
| 660 | 694 |
| 661 #if defined(OS_ANDROID) | 695 #if defined(OS_ANDROID) |
| 662 // Tests StartNotifySession synchronous failure. | 696 // StartNotifySession fails if the characteristic is missing the Client |
| 663 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_SynchronousError) { | 697 // Characteristic Configuration descriptor. |
| 664 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 698 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { |
| 699 ASSERT_NO_FATAL_FAILURE( |
| 700 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 701 |
| 702 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 703 GetGattErrorCallback(Call::EXPECTED)); |
| 704 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 705 |
| 706 // The expected error callback is asynchronous: |
| 707 EXPECT_EQ(0, error_callback_count_); |
| 708 base::RunLoop().RunUntilIdle(); |
| 709 EXPECT_EQ(1, error_callback_count_); |
| 710 } |
| 711 #endif // defined(OS_ANDROID) |
| 712 |
| 713 #if defined(OS_ANDROID) |
| 714 // StartNotifySession fails synchronously when failing to set a characteristic |
| 715 // to enable notifications. |
| 716 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. |
| 717 TEST_F(BluetoothGattCharacteristicTest, |
| 718 StartNotifySession_FailToSetCharacteristicNotification) { |
| 719 ASSERT_NO_FATAL_FAILURE( |
| 720 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 721 SimulateGattDescriptor( |
| 722 characteristic1_, |
| 723 /* Client Characteristic Configuration descriptor's standard UUID: */ |
| 724 "00002902-0000-1000-8000-00805F9B34FB"); |
| 725 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 665 | 726 |
| 666 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( | 727 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( |
| 667 characteristic1_); | 728 characteristic1_); |
| 668 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | 729 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 669 GetGattErrorCallback(Call::EXPECTED)); | 730 GetGattErrorCallback(Call::EXPECTED)); |
| 670 EXPECT_EQ(0, error_callback_count_); | 731 EXPECT_EQ(0, error_callback_count_); |
| 671 base::RunLoop().RunUntilIdle(); | 732 base::RunLoop().RunUntilIdle(); |
| 733 EXPECT_EQ(1, error_callback_count_); |
| 672 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 734 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 673 EXPECT_EQ(0, callback_count_); | 735 ASSERT_EQ(0u, notify_sessions_.size()); |
| 736 } |
| 737 #endif // defined(OS_ANDROID) |
| 738 |
| 739 #if defined(OS_ANDROID) |
| 740 // Tests StartNotifySession descriptor write synchronous failure. |
| 741 TEST_F(BluetoothGattCharacteristicTest, |
| 742 StartNotifySession_WriteDescriptorSynchronousError) { |
| 743 ASSERT_NO_FATAL_FAILURE( |
| 744 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 745 SimulateGattDescriptor( |
| 746 characteristic1_, |
| 747 /* Client Characteristic Configuration descriptor's standard UUID: */ |
| 748 "00002902-0000-1000-8000-00805F9B34FB"); |
| 749 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 750 |
| 751 // Fail to write to config descriptor synchronously. |
| 752 SimulateGattDescriptorWriteWillFailSynchronouslyOnce( |
| 753 characteristic1_->GetDescriptors()[0]); |
| 754 |
| 755 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), |
| 756 GetGattErrorCallback(Call::EXPECTED)); |
| 757 EXPECT_EQ(0, error_callback_count_); |
| 758 base::RunLoop().RunUntilIdle(); |
| 674 EXPECT_EQ(1, error_callback_count_); | 759 EXPECT_EQ(1, error_callback_count_); |
| 760 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 675 ASSERT_EQ(0u, notify_sessions_.size()); | 761 ASSERT_EQ(0u, notify_sessions_.size()); |
| 676 } | 762 } |
| 677 #endif // defined(OS_ANDROID) | 763 #endif // defined(OS_ANDROID) |
| 678 | 764 |
| 679 #if defined(OS_ANDROID) | 765 #if defined(OS_ANDROID) |
| 766 // Tests StartNotifySession success on a characteristic enabling Notify. |
| 767 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { |
| 768 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 769 /* properties: NOTIFY */ 0x10, |
| 770 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 771 } |
| 772 #endif // defined(OS_ANDROID) |
| 773 |
| 774 #if defined(OS_ANDROID) |
| 775 // Tests StartNotifySession success on a characteristic enabling Indicate. |
| 776 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_OnIndicate) { |
| 777 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 778 /* properties: INDICATE */ 0x20, |
| 779 /* expected_config_descriptor_value: INDICATE */ 2)); |
| 780 } |
| 781 #endif // defined(OS_ANDROID) |
| 782 |
| 783 #if defined(OS_ANDROID) |
| 784 // Tests StartNotifySession success on a characteristic enabling Notify & |
| 785 // Indicate. |
| 786 TEST_F(BluetoothGattCharacteristicTest, |
| 787 StartNotifySession_OnNotifyAndIndicate) { |
| 788 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 789 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 790 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 791 } |
| 792 #endif // defined(OS_ANDROID) |
| 793 |
| 794 #if defined(OS_ANDROID) |
| 795 // Tests Characteristic Value changes during a Notify Session. |
| 796 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { |
| 797 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 798 /* properties: NOTIFY */ 0x10, |
| 799 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 800 |
| 801 TestBluetoothAdapterObserver observer(adapter_); |
| 802 |
| 803 std::vector<uint8_t> test_vector1, test_vector2; |
| 804 test_vector1.push_back(111); |
| 805 test_vector2.push_back(222); |
| 806 |
| 807 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); |
| 808 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 809 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 810 |
| 811 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); |
| 812 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| 813 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| 814 } |
| 815 #endif // defined(OS_ANDROID) |
| 816 |
| 817 #if defined(OS_ANDROID) |
| 818 // Tests Characteristic Value changing after a Notify Session and objects being |
| 819 // destroyed. |
| 820 TEST_F(BluetoothGattCharacteristicTest, |
| 821 GattCharacteristicValueChanged_AfterDeleted) { |
| 822 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 823 /* properties: NOTIFY */ 0x10, |
| 824 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 825 |
| 826 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 827 DeleteDevice(device_); |
| 828 |
| 829 std::vector<uint8_t> empty_vector; |
| 830 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, |
| 831 empty_vector); |
| 832 EXPECT_TRUE("Did not crash!"); |
| 833 } |
| 834 #endif // defined(OS_ANDROID) |
| 835 |
| 836 #if defined(OS_ANDROID) |
| 680 // Tests multiple StartNotifySession success. | 837 // Tests multiple StartNotifySession success. |
| 681 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { | 838 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| 682 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 839 ASSERT_NO_FATAL_FAILURE( |
| 840 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 841 SimulateGattDescriptor( |
| 842 characteristic1_, |
| 843 /* Client Characteristic Configuration descriptor's standard UUID: */ |
| 844 "00002902-0000-1000-8000-00805F9B34FB"); |
| 845 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 683 | 846 |
| 684 characteristic1_->StartNotifySession( | 847 characteristic1_->StartNotifySession( |
| 685 GetNotifyCallback(Call::EXPECTED), | 848 GetNotifyCallback(Call::EXPECTED), |
| 686 GetGattErrorCallback(Call::NOT_EXPECTED)); | 849 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 687 characteristic1_->StartNotifySession( | 850 characteristic1_->StartNotifySession( |
| 688 GetNotifyCallback(Call::EXPECTED), | 851 GetNotifyCallback(Call::EXPECTED), |
| 689 GetGattErrorCallback(Call::NOT_EXPECTED)); | 852 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 690 #if defined(OS_ANDROID) | 853 #if defined(OS_ANDROID) |
| 691 // TODO(crbug.com/551634): Decide when implementing IsNotifying if Android | 854 // TODO(crbug.com/551634): Decide when implementing IsNotifying if Android |
| 692 // should trust the notification request always worked, or if we should always | 855 // should trust the notification request always worked, or if we should always |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 | 921 |
| 759 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). | 922 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). |
| 760 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); | 923 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); |
| 761 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); | 924 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); |
| 762 // ... but not uuid 3 | 925 // ... but not uuid 3 |
| 763 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); | 926 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); |
| 764 } | 927 } |
| 765 #endif // defined(OS_ANDROID) | 928 #endif // defined(OS_ANDROID) |
| 766 | 929 |
| 767 } // namespace device | 930 } // namespace device |
| OLD | NEW |