Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: device/bluetooth/bluetooth_gatt_chromeos_unittest.cc

Issue 309623002: device/bluetooth: Update GATT descriptor value D-Bus bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 GetHeartRateMeasurementPath().value()); 894 GetHeartRateMeasurementPath().value());
895 ASSERT_TRUE(characteristic); 895 ASSERT_TRUE(characteristic);
896 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); 896 EXPECT_EQ(1U, characteristic->GetDescriptors().size());
897 897
898 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; 898 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0];
899 EXPECT_FALSE(descriptor->IsLocal()); 899 EXPECT_FALSE(descriptor->IsLocal());
900 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), 900 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
901 descriptor->GetUUID()); 901 descriptor->GetUUID());
902 902
903 std::vector<uint8> desc_value; 903 std::vector<uint8> desc_value;
904 desc_value.push_back(1);
904 desc_value.push_back(0); 905 desc_value.push_back(0);
905 desc_value.push_back(0); 906
906 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); 907 /* The cached value will be empty until the first read request */
908 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
909 EXPECT_TRUE(descriptor->GetValue().empty());
907 910
908 EXPECT_EQ(0, success_callback_count_); 911 EXPECT_EQ(0, success_callback_count_);
909 EXPECT_EQ(0, error_callback_count_); 912 EXPECT_EQ(0, error_callback_count_);
910 EXPECT_TRUE(last_read_value_.empty()); 913 EXPECT_TRUE(last_read_value_.empty());
911 914
912 // Read value. 915 // Read value. GattDescriptorValueChanged event will be sent after a
916 // successful read.
913 descriptor->ReadRemoteDescriptor( 917 descriptor->ReadRemoteDescriptor(
914 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 918 base::Bind(&BluetoothGattChromeOSTest::ValueCallback,
915 base::Unretained(this)), 919 base::Unretained(this)),
916 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, 920 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback,
917 base::Unretained(this))); 921 base::Unretained(this)));
918 EXPECT_EQ(1, success_callback_count_); 922 EXPECT_EQ(1, success_callback_count_);
919 EXPECT_EQ(0, error_callback_count_); 923 EXPECT_EQ(0, error_callback_count_);
920 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 924 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
925 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue()));
921 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); 926 EXPECT_EQ(4, service_observer.gatt_service_changed_count_);
922 EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); 927 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_);
923 928
924 // Write value. 929 // Write value. Writes to this descriptor will fail.
925 desc_value[0] = 0x03; 930 desc_value[0] = 0x03;
926 descriptor->WriteRemoteDescriptor( 931 descriptor->WriteRemoteDescriptor(
927 desc_value, 932 desc_value,
928 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 933 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback,
929 base::Unretained(this)), 934 base::Unretained(this)),
930 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, 935 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback,
931 base::Unretained(this))); 936 base::Unretained(this)));
932 EXPECT_EQ(2, success_callback_count_); 937 EXPECT_EQ(1, success_callback_count_);
933 EXPECT_EQ(0, error_callback_count_); 938 EXPECT_EQ(1, error_callback_count_);
934 EXPECT_FALSE(ValuesEqual(last_read_value_, descriptor->GetValue())); 939 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
935 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); 940 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
936 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); 941 EXPECT_EQ(4, service_observer.gatt_service_changed_count_);
937 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); 942 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_);
938 943
939 // Read new value. 944 // Read new value.
940 descriptor->ReadRemoteDescriptor( 945 descriptor->ReadRemoteDescriptor(
941 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 946 base::Bind(&BluetoothGattChromeOSTest::ValueCallback,
942 base::Unretained(this)), 947 base::Unretained(this)),
943 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, 948 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback,
944 base::Unretained(this))); 949 base::Unretained(this)));
945 EXPECT_EQ(3, success_callback_count_); 950 EXPECT_EQ(2, success_callback_count_);
946 EXPECT_EQ(0, error_callback_count_); 951 EXPECT_EQ(1, error_callback_count_);
947 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 952 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
948 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); 953 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
949 EXPECT_EQ(4, service_observer.gatt_service_changed_count_); 954 EXPECT_EQ(4, service_observer.gatt_service_changed_count_);
950 EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); 955 EXPECT_EQ(2, service_observer.gatt_descriptor_value_changed_count_);
951 } 956 }
952 957
953 } // namespace chromeos 958 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698