OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 7 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
8 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 8 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
9 #include "chromeos/dbus/fake_bluetooth_device_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
10 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 799 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, |
800 base::Unretained(this)), | 800 base::Unretained(this)), |
801 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, | 801 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, |
802 base::Unretained(this))); | 802 base::Unretained(this))); |
803 EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty()); | 803 EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty()); |
804 EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid()); | 804 EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid()); |
805 EXPECT_EQ(0, success_callback_count_); | 805 EXPECT_EQ(0, success_callback_count_); |
806 EXPECT_EQ(2, error_callback_count_); | 806 EXPECT_EQ(2, error_callback_count_); |
807 EXPECT_EQ(3, service_observer.gatt_characteristic_value_changed_count_); | 807 EXPECT_EQ(3, service_observer.gatt_characteristic_value_changed_count_); |
808 | 808 |
809 // Issue write request to writeable characteristic. Writing "1" to the control | 809 // Issue write request to writeable characteristic. The "Body Sensor Location" |
810 // point characteristic will immediately change its value back to "0", hence | 810 // characteristic does not send notifications and WriteValue does not result |
811 // sending "ValueChanged" events twice. | 811 // in a CharacteristicValueChanged event, thus no such event should be |
| 812 // received. |
812 characteristic = service->GetCharacteristic( | 813 characteristic = service->GetCharacteristic( |
813 fake_bluetooth_gatt_characteristic_client_-> | 814 fake_bluetooth_gatt_characteristic_client_-> |
814 GetHeartRateControlPointPath().value()); | 815 GetHeartRateControlPointPath().value()); |
815 ASSERT_TRUE(characteristic); | 816 ASSERT_TRUE(characteristic); |
816 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> | 817 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> |
817 GetHeartRateControlPointPath().value(), | 818 GetHeartRateControlPointPath().value(), |
818 characteristic->GetIdentifier()); | 819 characteristic->GetIdentifier()); |
819 EXPECT_EQ(kHeartRateControlPointUUID, characteristic->GetUUID()); | 820 EXPECT_EQ(kHeartRateControlPointUUID, characteristic->GetUUID()); |
820 characteristic->WriteRemoteCharacteristic( | 821 characteristic->WriteRemoteCharacteristic( |
821 write_value, | 822 write_value, |
822 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 823 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, |
823 base::Unretained(this)), | 824 base::Unretained(this)), |
824 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, | 825 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, |
825 base::Unretained(this))); | 826 base::Unretained(this))); |
826 EXPECT_EQ(characteristic->GetIdentifier(), | 827 EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty()); |
827 service_observer.last_gatt_characteristic_id_); | 828 EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid()); |
828 EXPECT_EQ(characteristic->GetUUID(), | |
829 service_observer.last_gatt_characteristic_uuid_); | |
830 EXPECT_EQ(1, success_callback_count_); | 829 EXPECT_EQ(1, success_callback_count_); |
831 EXPECT_EQ(2, error_callback_count_); | 830 EXPECT_EQ(2, error_callback_count_); |
832 EXPECT_EQ(5, service_observer.gatt_characteristic_value_changed_count_); | 831 EXPECT_EQ(3, service_observer.gatt_characteristic_value_changed_count_); |
833 | 832 |
834 // Issue a read request. | 833 // Issue a read request. A successful read results in a |
| 834 // CharacteristicValueChanged notification. |
835 characteristic = service->GetCharacteristic( | 835 characteristic = service->GetCharacteristic( |
836 fake_bluetooth_gatt_characteristic_client_-> | 836 fake_bluetooth_gatt_characteristic_client_-> |
837 GetBodySensorLocationPath().value()); | 837 GetBodySensorLocationPath().value()); |
838 ASSERT_TRUE(characteristic); | 838 ASSERT_TRUE(characteristic); |
839 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> | 839 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> |
840 GetBodySensorLocationPath().value(), | 840 GetBodySensorLocationPath().value(), |
841 characteristic->GetIdentifier()); | 841 characteristic->GetIdentifier()); |
842 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); | 842 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); |
843 characteristic->ReadRemoteCharacteristic( | 843 characteristic->ReadRemoteCharacteristic( |
844 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 844 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, |
845 base::Unretained(this)), | 845 base::Unretained(this)), |
846 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, | 846 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, |
847 base::Unretained(this))); | 847 base::Unretained(this))); |
848 EXPECT_EQ(2, success_callback_count_); | 848 EXPECT_EQ(2, success_callback_count_); |
849 EXPECT_EQ(2, error_callback_count_); | 849 EXPECT_EQ(2, error_callback_count_); |
850 EXPECT_EQ(5, service_observer.gatt_characteristic_value_changed_count_); | 850 EXPECT_EQ(4, service_observer.gatt_characteristic_value_changed_count_); |
851 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); | 851 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); |
852 | 852 |
853 // One last value changed notification. | 853 // One last value changed notification. |
854 base::MessageLoop::current()->Run(); | 854 base::MessageLoop::current()->Run(); |
855 EXPECT_EQ(6, service_observer.gatt_characteristic_value_changed_count_); | 855 EXPECT_EQ(5, service_observer.gatt_characteristic_value_changed_count_); |
856 EXPECT_EQ(kHeartRateMeasurementUUID, | 856 EXPECT_EQ(kHeartRateMeasurementUUID, |
857 service_observer.last_gatt_characteristic_uuid_); | 857 service_observer.last_gatt_characteristic_uuid_); |
858 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> | 858 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> |
859 GetHeartRateMeasurementPath().value(), | 859 GetHeartRateMeasurementPath().value(), |
860 service_observer.last_gatt_characteristic_id_); | 860 service_observer.last_gatt_characteristic_id_); |
861 } | 861 } |
862 | 862 |
863 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { | 863 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { |
864 fake_bluetooth_device_client_->CreateDevice( | 864 fake_bluetooth_device_client_->CreateDevice( |
865 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 865 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 base::Unretained(this))); | 944 base::Unretained(this))); |
945 EXPECT_EQ(3, success_callback_count_); | 945 EXPECT_EQ(3, success_callback_count_); |
946 EXPECT_EQ(0, error_callback_count_); | 946 EXPECT_EQ(0, error_callback_count_); |
947 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 947 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
948 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); | 948 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); |
949 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); | 949 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); |
950 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); | 950 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); |
951 } | 951 } |
952 | 952 |
953 } // namespace chromeos | 953 } // namespace chromeos |
OLD | NEW |