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 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 GetHeartRateMeasurementPath().value()); | 937 GetHeartRateMeasurementPath().value()); |
938 ASSERT_TRUE(characteristic); | 938 ASSERT_TRUE(characteristic); |
939 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 939 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |
940 | 940 |
941 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; | 941 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; |
942 EXPECT_FALSE(descriptor->IsLocal()); | 942 EXPECT_FALSE(descriptor->IsLocal()); |
943 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 943 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
944 descriptor->GetUUID()); | 944 descriptor->GetUUID()); |
945 | 945 |
946 std::vector<uint8> desc_value; | 946 std::vector<uint8> desc_value; |
| 947 desc_value.push_back(1); |
947 desc_value.push_back(0); | 948 desc_value.push_back(0); |
948 desc_value.push_back(0); | 949 |
949 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); | 950 /* The cached value will be empty until the first read request */ |
| 951 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
| 952 EXPECT_TRUE(descriptor->GetValue().empty()); |
950 | 953 |
951 EXPECT_EQ(0, success_callback_count_); | 954 EXPECT_EQ(0, success_callback_count_); |
952 EXPECT_EQ(0, error_callback_count_); | 955 EXPECT_EQ(0, error_callback_count_); |
953 EXPECT_TRUE(last_read_value_.empty()); | 956 EXPECT_TRUE(last_read_value_.empty()); |
954 | 957 |
955 // Read value. | 958 // Read value. GattDescriptorValueChanged event will be sent after a |
| 959 // successful read. |
956 descriptor->ReadRemoteDescriptor( | 960 descriptor->ReadRemoteDescriptor( |
957 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 961 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, |
958 base::Unretained(this)), | 962 base::Unretained(this)), |
959 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, | 963 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, |
960 base::Unretained(this))); | 964 base::Unretained(this))); |
961 EXPECT_EQ(1, success_callback_count_); | 965 EXPECT_EQ(1, success_callback_count_); |
962 EXPECT_EQ(0, error_callback_count_); | 966 EXPECT_EQ(0, error_callback_count_); |
963 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 967 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
| 968 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); |
964 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); | 969 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); |
965 EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); | 970 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); |
966 | 971 |
967 // Write value. | 972 // Write value. Writes to this descriptor will fail. |
968 desc_value[0] = 0x03; | 973 desc_value[0] = 0x03; |
969 descriptor->WriteRemoteDescriptor( | 974 descriptor->WriteRemoteDescriptor( |
970 desc_value, | 975 desc_value, |
971 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 976 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, |
972 base::Unretained(this)), | 977 base::Unretained(this)), |
973 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, | 978 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, |
974 base::Unretained(this))); | 979 base::Unretained(this))); |
975 EXPECT_EQ(2, success_callback_count_); | 980 EXPECT_EQ(1, success_callback_count_); |
976 EXPECT_EQ(0, error_callback_count_); | 981 EXPECT_EQ(1, error_callback_count_); |
977 EXPECT_FALSE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 982 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
978 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); | 983 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
979 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); | 984 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); |
980 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); | 985 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); |
981 | 986 |
982 // Read new value. | 987 // Read new value. |
983 descriptor->ReadRemoteDescriptor( | 988 descriptor->ReadRemoteDescriptor( |
984 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 989 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, |
985 base::Unretained(this)), | 990 base::Unretained(this)), |
986 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, | 991 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, |
987 base::Unretained(this))); | 992 base::Unretained(this))); |
988 EXPECT_EQ(3, success_callback_count_); | 993 EXPECT_EQ(2, success_callback_count_); |
989 EXPECT_EQ(0, error_callback_count_); | 994 EXPECT_EQ(1, error_callback_count_); |
990 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 995 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
991 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); | 996 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
992 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); | 997 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); |
993 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); | 998 EXPECT_EQ(2, service_observer.gatt_descriptor_value_changed_count_); |
994 } | 999 } |
995 | 1000 |
996 } // namespace chromeos | 1001 } // namespace chromeos |
OLD | NEW |