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

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

Issue 788193004: chromeos/dbus: Update Bluetooth GATT API clients to upstream definition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
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/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chromeos/dbus/dbus_thread_manager.h" 8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 fake_bluetooth_gatt_characteristic_client_-> 1095 fake_bluetooth_gatt_characteristic_client_->
1096 GetHeartRateMeasurementPath().value()); 1096 GetHeartRateMeasurementPath().value());
1097 ASSERT_TRUE(characteristic); 1097 ASSERT_TRUE(characteristic);
1098 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); 1098 EXPECT_EQ(1U, characteristic->GetDescriptors().size());
1099 1099
1100 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; 1100 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0];
1101 EXPECT_FALSE(descriptor->IsLocal()); 1101 EXPECT_FALSE(descriptor->IsLocal());
1102 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), 1102 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
1103 descriptor->GetUUID()); 1103 descriptor->GetUUID());
1104 1104
1105 std::vector<uint8> desc_value; 1105 std::vector<uint8_t> desc_value = {0x00, 0x00};
1106 desc_value.push_back(1);
1107 desc_value.push_back(0);
1108 1106
1109 /* The cached value will be empty until the first read request */ 1107 /* The cached value will be empty until the first read request */
1110 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); 1108 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
1111 EXPECT_TRUE(descriptor->GetValue().empty()); 1109 EXPECT_TRUE(descriptor->GetValue().empty());
1112 1110
1113 EXPECT_EQ(0, success_callback_count_); 1111 EXPECT_EQ(0, success_callback_count_);
1114 EXPECT_EQ(0, error_callback_count_); 1112 EXPECT_EQ(0, error_callback_count_);
1115 EXPECT_TRUE(last_read_value_.empty()); 1113 EXPECT_TRUE(last_read_value_.empty());
1116 1114
1117 // Read value. GattDescriptorValueChanged event will be sent after a 1115 // Read value. GattDescriptorValueChanged event will be sent after a
(...skipping 20 matching lines...) Expand all
1138 base::Unretained(this))); 1136 base::Unretained(this)));
1139 EXPECT_EQ(1, success_callback_count_); 1137 EXPECT_EQ(1, success_callback_count_);
1140 EXPECT_EQ(1, error_callback_count_); 1138 EXPECT_EQ(1, error_callback_count_);
1141 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, 1139 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED,
1142 last_service_error_); 1140 last_service_error_);
1143 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 1141 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
1144 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); 1142 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
1145 EXPECT_EQ(0, observer.gatt_service_changed_count_); 1143 EXPECT_EQ(0, observer.gatt_service_changed_count_);
1146 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_); 1144 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_);
1147 1145
1148 // Read new value. 1146 // Read value. The value should remain unchanged.
1149 descriptor->ReadRemoteDescriptor( 1147 descriptor->ReadRemoteDescriptor(
1150 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 1148 base::Bind(&BluetoothGattChromeOSTest::ValueCallback,
1151 base::Unretained(this)), 1149 base::Unretained(this)),
1152 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1150 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
1153 base::Unretained(this))); 1151 base::Unretained(this)));
1154 EXPECT_EQ(2, success_callback_count_); 1152 EXPECT_EQ(2, success_callback_count_);
1155 EXPECT_EQ(1, error_callback_count_); 1153 EXPECT_EQ(1, error_callback_count_);
1156 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 1154 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
1157 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); 1155 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
1158 EXPECT_EQ(0, observer.gatt_service_changed_count_); 1156 EXPECT_EQ(0, observer.gatt_service_changed_count_);
1157 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_);
1158
1159 // Start notifications on the descriptor's characteristic. The descriptor
1160 // value should change.
1161 characteristic->StartNotifySession(
Marie Janssen 2014/12/11 23:18:52 You should EXPECT_FALSE(characteristic->IsNotifyin
armansito 2015/02/03 01:54:38 Done.
1162 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback,
1163 base::Unretained(this)),
1164 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
1165 base::Unretained(this)));
1166 base::MessageLoop::current()->Run();
1167 EXPECT_EQ(3, success_callback_count_);
1168 EXPECT_EQ(1, error_callback_count_);
1169 EXPECT_EQ(1U, update_sessions_.size());
1170 EXPECT_TRUE(characteristic->IsNotifying());
1171
1172 // Read the new descriptor value. We should receive a value updated event.
1173 descriptor->ReadRemoteDescriptor(
1174 base::Bind(&BluetoothGattChromeOSTest::ValueCallback,
1175 base::Unretained(this)),
1176 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
1177 base::Unretained(this)));
1178 EXPECT_EQ(4, success_callback_count_);
1179 EXPECT_EQ(1, error_callback_count_);
1180 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
1181 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
1182 EXPECT_EQ(0, observer.gatt_service_changed_count_);
1159 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count_); 1183 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count_);
1160 } 1184 }
1161 1185
1162 TEST_F(BluetoothGattChromeOSTest, NotifySessions) { 1186 TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
1163 fake_bluetooth_device_client_->CreateDevice( 1187 fake_bluetooth_device_client_->CreateDevice(
1164 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 1188 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
1165 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); 1189 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath));
1166 BluetoothDevice* device = 1190 BluetoothDevice* device =
1167 adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress); 1191 adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress);
1168 ASSERT_TRUE(device); 1192 ASSERT_TRUE(device);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 1443
1420 EXPECT_EQ(1, success_callback_count_); 1444 EXPECT_EQ(1, success_callback_count_);
1421 EXPECT_EQ(0, error_callback_count_); 1445 EXPECT_EQ(0, error_callback_count_);
1422 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); 1446 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
1423 EXPECT_TRUE(characteristic->IsNotifying()); 1447 EXPECT_TRUE(characteristic->IsNotifying());
1424 EXPECT_EQ(1U, update_sessions_.size()); 1448 EXPECT_EQ(1U, update_sessions_.size());
1425 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1449 EXPECT_TRUE(update_sessions_[0]->IsActive());
1426 } 1450 }
1427 1451
1428 } // namespace chromeos 1452 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698