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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(6, 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, GattCharacteristicProperties) { |
| 864 fake_bluetooth_device_client_->CreateDevice( |
| 865 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 866 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); |
| 867 BluetoothDevice* device = adapter_->GetDevice( |
| 868 FakeBluetoothDeviceClient::kLowEnergyAddress); |
| 869 ASSERT_TRUE(device); |
| 870 |
| 871 TestDeviceObserver observer(adapter_, device); |
| 872 |
| 873 // Expose the fake Heart Rate service. This will asynchronously expose |
| 874 // characteristics. |
| 875 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
| 876 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); |
| 877 |
| 878 BluetoothGattService* service = |
| 879 device->GetGattService(observer.last_gatt_service_id_); |
| 880 |
| 881 TestGattServiceObserver service_observer(adapter_, device, service); |
| 882 EXPECT_TRUE(service->GetCharacteristics().empty()); |
| 883 |
| 884 // Run the message loop so that the characteristics appear. |
| 885 base::MessageLoop::current()->Run(); |
| 886 |
| 887 BluetoothGattCharacteristic *characteristic = service->GetCharacteristic( |
| 888 fake_bluetooth_gatt_characteristic_client_-> |
| 889 GetBodySensorLocationPath().value()); |
| 890 EXPECT_EQ(BluetoothGattCharacteristic::kPropertyRead, |
| 891 characteristic->GetProperties()); |
| 892 |
| 893 characteristic = service->GetCharacteristic( |
| 894 fake_bluetooth_gatt_characteristic_client_-> |
| 895 GetHeartRateControlPointPath().value()); |
| 896 EXPECT_EQ(BluetoothGattCharacteristic::kPropertyWrite, |
| 897 characteristic->GetProperties()); |
| 898 |
| 899 characteristic = service->GetCharacteristic( |
| 900 fake_bluetooth_gatt_characteristic_client_-> |
| 901 GetHeartRateMeasurementPath().value()); |
| 902 EXPECT_EQ(BluetoothGattCharacteristic::kPropertyNotify, |
| 903 characteristic->GetProperties()); |
| 904 } |
| 905 |
863 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { | 906 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { |
864 fake_bluetooth_device_client_->CreateDevice( | 907 fake_bluetooth_device_client_->CreateDevice( |
865 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 908 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
866 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 909 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); |
867 BluetoothDevice* device = adapter_->GetDevice( | 910 BluetoothDevice* device = adapter_->GetDevice( |
868 FakeBluetoothDeviceClient::kLowEnergyAddress); | 911 FakeBluetoothDeviceClient::kLowEnergyAddress); |
869 ASSERT_TRUE(device); | 912 ASSERT_TRUE(device); |
870 | 913 |
871 TestDeviceObserver observer(adapter_, device); | 914 TestDeviceObserver observer(adapter_, device); |
872 | 915 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 base::Unretained(this))); | 987 base::Unretained(this))); |
945 EXPECT_EQ(3, success_callback_count_); | 988 EXPECT_EQ(3, success_callback_count_); |
946 EXPECT_EQ(0, error_callback_count_); | 989 EXPECT_EQ(0, error_callback_count_); |
947 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 990 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
948 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); | 991 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); |
949 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); | 992 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); |
950 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); | 993 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); |
951 } | 994 } |
952 | 995 |
953 } // namespace chromeos | 996 } // namespace chromeos |
OLD | NEW |