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

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

Issue 1367663002: Add Linux support for the Bluetooth API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_dbus
Patch Set: rebase Created 5 years, 2 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
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 "dbus/object_path.h" 8 #include "dbus/object_path.h"
9 #include "device/bluetooth/bluetooth_adapter.h" 9 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_adapter_factory.h" 10 #include "device/bluetooth/bluetooth_adapter_factory.h"
(...skipping 18 matching lines...) Expand all
29 using device::BluetoothAdapter; 29 using device::BluetoothAdapter;
30 using device::BluetoothDevice; 30 using device::BluetoothDevice;
31 using device::BluetoothGattCharacteristic; 31 using device::BluetoothGattCharacteristic;
32 using device::BluetoothGattConnection; 32 using device::BluetoothGattConnection;
33 using device::BluetoothGattDescriptor; 33 using device::BluetoothGattDescriptor;
34 using device::BluetoothGattService; 34 using device::BluetoothGattService;
35 using device::BluetoothGattNotifySession; 35 using device::BluetoothGattNotifySession;
36 using device::BluetoothUUID; 36 using device::BluetoothUUID;
37 using device::TestBluetoothAdapterObserver; 37 using device::TestBluetoothAdapterObserver;
38 38
39 namespace chromeos { 39 namespace bluez {
40 40
41 namespace { 41 namespace {
42 42
43 const BluetoothUUID kHeartRateMeasurementUUID( 43 const BluetoothUUID kHeartRateMeasurementUUID(
44 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID); 44 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID);
45 const BluetoothUUID kBodySensorLocationUUID( 45 const BluetoothUUID kBodySensorLocationUUID(
46 bluez::FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID); 46 bluez::FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID);
47 const BluetoothUUID kHeartRateControlPointUUID( 47 const BluetoothUUID kHeartRateControlPointUUID(
48 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID); 48 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID);
49 49
50 // Compares GATT characteristic/descriptor values. Returns true, if the values 50 // Compares GATT characteristic/descriptor values. Returns true, if the values
51 // are equal. 51 // are equal.
52 bool ValuesEqual(const std::vector<uint8>& value0, 52 bool ValuesEqual(const std::vector<uint8>& value0,
53 const std::vector<uint8>& value1) { 53 const std::vector<uint8>& value1) {
54 if (value0.size() != value1.size()) 54 if (value0.size() != value1.size())
55 return false; 55 return false;
56 for (size_t i = 0; i < value0.size(); ++i) 56 for (size_t i = 0; i < value0.size(); ++i)
57 if (value0[i] != value1[i]) 57 if (value0[i] != value1[i])
58 return false; 58 return false;
59 return true; 59 return true;
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 class BluetoothGattChromeOSTest : public testing::Test { 64 class BluetoothGattBlueZTest : public testing::Test {
65 public: 65 public:
66 BluetoothGattChromeOSTest() 66 BluetoothGattBlueZTest()
67 : fake_bluetooth_gatt_service_client_(NULL), 67 : fake_bluetooth_gatt_service_client_(NULL),
68 success_callback_count_(0), 68 success_callback_count_(0),
69 error_callback_count_(0) { 69 error_callback_count_(0) {}
70 }
71 70
72 void SetUp() override { 71 void SetUp() override {
73 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = 72 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
74 bluez::BluezDBusManager::GetSetterForTesting(); 73 bluez::BluezDBusManager::GetSetterForTesting();
75 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; 74 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient;
76 fake_bluetooth_gatt_service_client_ = 75 fake_bluetooth_gatt_service_client_ =
77 new bluez::FakeBluetoothGattServiceClient; 76 new bluez::FakeBluetoothGattServiceClient;
78 fake_bluetooth_gatt_characteristic_client_ = 77 fake_bluetooth_gatt_characteristic_client_ =
79 new bluez::FakeBluetoothGattCharacteristicClient; 78 new bluez::FakeBluetoothGattCharacteristicClient;
80 fake_bluetooth_gatt_descriptor_client_ = 79 fake_bluetooth_gatt_descriptor_client_ =
(...skipping 15 matching lines...) Expand all
96 new bluez::FakeBluetoothAdapterClient)); 95 new bluez::FakeBluetoothAdapterClient));
97 dbus_setter->SetBluetoothInputClient( 96 dbus_setter->SetBluetoothInputClient(
98 scoped_ptr<bluez::BluetoothInputClient>( 97 scoped_ptr<bluez::BluetoothInputClient>(
99 new bluez::FakeBluetoothInputClient)); 98 new bluez::FakeBluetoothInputClient));
100 dbus_setter->SetBluetoothAgentManagerClient( 99 dbus_setter->SetBluetoothAgentManagerClient(
101 scoped_ptr<bluez::BluetoothAgentManagerClient>( 100 scoped_ptr<bluez::BluetoothAgentManagerClient>(
102 new bluez::FakeBluetoothAgentManagerClient)); 101 new bluez::FakeBluetoothAgentManagerClient));
103 102
104 GetAdapter(); 103 GetAdapter();
105 104
106 adapter_->SetPowered( 105 adapter_->SetPowered(true, base::Bind(&base::DoNothing),
107 true, 106 base::Bind(&base::DoNothing));
108 base::Bind(&base::DoNothing),
109 base::Bind(&base::DoNothing));
110 ASSERT_TRUE(adapter_->IsPowered()); 107 ASSERT_TRUE(adapter_->IsPowered());
111 } 108 }
112 109
113 void TearDown() override { 110 void TearDown() override {
114 adapter_ = NULL; 111 adapter_ = NULL;
115 update_sessions_.clear(); 112 update_sessions_.clear();
116 gatt_conn_.reset(); 113 gatt_conn_.reset();
117 bluez::BluezDBusManager::Shutdown(); 114 bluez::BluezDBusManager::Shutdown();
118 } 115 }
119 116
120 void GetAdapter() { 117 void GetAdapter() {
121 device::BluetoothAdapterFactory::GetAdapter( 118 device::BluetoothAdapterFactory::GetAdapter(base::Bind(
122 base::Bind(&BluetoothGattChromeOSTest::AdapterCallback, 119 &BluetoothGattBlueZTest::AdapterCallback, base::Unretained(this)));
123 base::Unretained(this)));
124 ASSERT_TRUE(adapter_.get() != NULL); 120 ASSERT_TRUE(adapter_.get() != NULL);
125 ASSERT_TRUE(adapter_->IsInitialized()); 121 ASSERT_TRUE(adapter_->IsInitialized());
126 ASSERT_TRUE(adapter_->IsPresent()); 122 ASSERT_TRUE(adapter_->IsPresent());
127 } 123 }
128 124
129 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { 125 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) {
130 adapter_ = adapter; 126 adapter_ = adapter;
131 } 127 }
132 128
133 void SuccessCallback() { 129 void SuccessCallback() { ++success_callback_count_; }
134 ++success_callback_count_;
135 }
136 130
137 void ValueCallback(const std::vector<uint8>& value) { 131 void ValueCallback(const std::vector<uint8>& value) {
138 ++success_callback_count_; 132 ++success_callback_count_;
139 last_read_value_ = value; 133 last_read_value_ = value;
140 } 134 }
141 135
142 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) { 136 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) {
143 ++success_callback_count_; 137 ++success_callback_count_;
144 gatt_conn_ = conn.Pass(); 138 gatt_conn_ = conn.Pass();
145 } 139 }
146 140
147 void NotifySessionCallback(scoped_ptr<BluetoothGattNotifySession> session) { 141 void NotifySessionCallback(scoped_ptr<BluetoothGattNotifySession> session) {
148 ++success_callback_count_; 142 ++success_callback_count_;
149 update_sessions_.push_back(session.release()); 143 update_sessions_.push_back(session.release());
150 QuitMessageLoop(); 144 QuitMessageLoop();
151 } 145 }
152 146
153 void ServiceErrorCallback(BluetoothGattService::GattErrorCode err) { 147 void ServiceErrorCallback(BluetoothGattService::GattErrorCode err) {
154 ++error_callback_count_; 148 ++error_callback_count_;
155 last_service_error_ = err; 149 last_service_error_ = err;
156 } 150 }
157 151
158 void ErrorCallback() { 152 void ErrorCallback() { ++error_callback_count_; }
159 ++error_callback_count_;
160 }
161 153
162 void DBusErrorCallback(const std::string& error_name, 154 void DBusErrorCallback(const std::string& error_name,
163 const std::string& error_message) { 155 const std::string& error_message) {
164 ++error_callback_count_; 156 ++error_callback_count_;
165 } 157 }
166 158
167 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { 159 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) {
168 ++error_callback_count_; 160 ++error_callback_count_;
169 } 161 }
170 162
(...skipping 15 matching lines...) Expand all
186 scoped_ptr<device::BluetoothGattConnection> gatt_conn_; 178 scoped_ptr<device::BluetoothGattConnection> gatt_conn_;
187 ScopedVector<BluetoothGattNotifySession> update_sessions_; 179 ScopedVector<BluetoothGattNotifySession> update_sessions_;
188 scoped_refptr<BluetoothAdapter> adapter_; 180 scoped_refptr<BluetoothAdapter> adapter_;
189 181
190 int success_callback_count_; 182 int success_callback_count_;
191 int error_callback_count_; 183 int error_callback_count_;
192 std::vector<uint8> last_read_value_; 184 std::vector<uint8> last_read_value_;
193 BluetoothGattService::GattErrorCode last_service_error_; 185 BluetoothGattService::GattErrorCode last_service_error_;
194 }; 186 };
195 187
196 TEST_F(BluetoothGattChromeOSTest, GattConnection) { 188 TEST_F(BluetoothGattBlueZTest, GattConnection) {
197 fake_bluetooth_device_client_->CreateDevice( 189 fake_bluetooth_device_client_->CreateDevice(
198 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 190 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
199 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 191 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
200 BluetoothDevice* device = 192 BluetoothDevice* device =
201 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 193 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
202 ASSERT_TRUE(device); 194 ASSERT_TRUE(device);
203 ASSERT_FALSE(device->IsConnected()); 195 ASSERT_FALSE(device->IsConnected());
204 ASSERT_FALSE(gatt_conn_.get()); 196 ASSERT_FALSE(gatt_conn_.get());
205 ASSERT_EQ(0, success_callback_count_); 197 ASSERT_EQ(0, success_callback_count_);
206 ASSERT_EQ(0, error_callback_count_); 198 ASSERT_EQ(0, error_callback_count_);
207 199
208 device->CreateGattConnection( 200 device->CreateGattConnection(
209 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, 201 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback,
210 base::Unretained(this)), 202 base::Unretained(this)),
211 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, 203 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
212 base::Unretained(this))); 204 base::Unretained(this)));
213 205
214 EXPECT_EQ(1, success_callback_count_); 206 EXPECT_EQ(1, success_callback_count_);
215 EXPECT_EQ(0, error_callback_count_); 207 EXPECT_EQ(0, error_callback_count_);
216 EXPECT_TRUE(device->IsConnected()); 208 EXPECT_TRUE(device->IsConnected());
217 ASSERT_TRUE(gatt_conn_.get()); 209 ASSERT_TRUE(gatt_conn_.get());
218 EXPECT_TRUE(gatt_conn_->IsConnected()); 210 EXPECT_TRUE(gatt_conn_->IsConnected());
219 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, 211 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
220 gatt_conn_->GetDeviceAddress()); 212 gatt_conn_->GetDeviceAddress());
221 213
222 gatt_conn_->Disconnect(); 214 gatt_conn_->Disconnect();
223 EXPECT_TRUE(device->IsConnected()); 215 EXPECT_TRUE(device->IsConnected());
224 EXPECT_FALSE(gatt_conn_->IsConnected()); 216 EXPECT_FALSE(gatt_conn_->IsConnected());
225 217
226 device->CreateGattConnection( 218 device->CreateGattConnection(
227 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, 219 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback,
228 base::Unretained(this)), 220 base::Unretained(this)),
229 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, 221 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
230 base::Unretained(this))); 222 base::Unretained(this)));
231 223
232 EXPECT_EQ(2, success_callback_count_); 224 EXPECT_EQ(2, success_callback_count_);
233 EXPECT_EQ(0, error_callback_count_); 225 EXPECT_EQ(0, error_callback_count_);
234 EXPECT_TRUE(device->IsConnected()); 226 EXPECT_TRUE(device->IsConnected());
235 ASSERT_TRUE(gatt_conn_.get()); 227 ASSERT_TRUE(gatt_conn_.get());
236 EXPECT_TRUE(gatt_conn_->IsConnected()); 228 EXPECT_TRUE(gatt_conn_->IsConnected());
237 229
238 device->Disconnect( 230 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
239 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 231 base::Unretained(this)),
240 base::Unretained(this)), 232 base::Bind(&BluetoothGattBlueZTest::ErrorCallback,
241 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, 233 base::Unretained(this)));
242 base::Unretained(this)));
243 234
244 EXPECT_EQ(3, success_callback_count_); 235 EXPECT_EQ(3, success_callback_count_);
245 EXPECT_EQ(0, error_callback_count_); 236 EXPECT_EQ(0, error_callback_count_);
246 ASSERT_TRUE(gatt_conn_.get()); 237 ASSERT_TRUE(gatt_conn_.get());
247 EXPECT_FALSE(gatt_conn_->IsConnected()); 238 EXPECT_FALSE(gatt_conn_->IsConnected());
248 239
249 device->CreateGattConnection( 240 device->CreateGattConnection(
250 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, 241 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback,
251 base::Unretained(this)), 242 base::Unretained(this)),
252 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, 243 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
253 base::Unretained(this))); 244 base::Unretained(this)));
254 245
255 EXPECT_EQ(4, success_callback_count_); 246 EXPECT_EQ(4, success_callback_count_);
256 EXPECT_EQ(0, error_callback_count_); 247 EXPECT_EQ(0, error_callback_count_);
257 EXPECT_TRUE(device->IsConnected()); 248 EXPECT_TRUE(device->IsConnected());
258 EXPECT_TRUE(gatt_conn_->IsConnected()); 249 EXPECT_TRUE(gatt_conn_->IsConnected());
259 250
260 fake_bluetooth_device_client_->RemoveDevice( 251 fake_bluetooth_device_client_->RemoveDevice(
261 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 252 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
262 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 253 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
263 ASSERT_TRUE(gatt_conn_.get()); 254 ASSERT_TRUE(gatt_conn_.get());
264 EXPECT_FALSE(gatt_conn_->IsConnected()); 255 EXPECT_FALSE(gatt_conn_->IsConnected());
265 } 256 }
266 257
267 TEST_F(BluetoothGattChromeOSTest, GattServiceAddedAndRemoved) { 258 TEST_F(BluetoothGattBlueZTest, GattServiceAddedAndRemoved) {
268 // Create a fake LE device. We store the device pointer here because this is a 259 // Create a fake LE device. We store the device pointer here because this is a
269 // test. It's unsafe to do this in production as the device might get deleted. 260 // test. It's unsafe to do this in production as the device might get deleted.
270 fake_bluetooth_device_client_->CreateDevice( 261 fake_bluetooth_device_client_->CreateDevice(
271 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 262 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
272 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 263 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
273 BluetoothDevice* device = 264 BluetoothDevice* device =
274 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 265 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
275 ASSERT_TRUE(device); 266 ASSERT_TRUE(device);
276 267
277 TestBluetoothAdapterObserver observer(adapter_); 268 TestBluetoothAdapterObserver observer(adapter_);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 EXPECT_EQ(2, observer.gatt_service_added_count()); 341 EXPECT_EQ(2, observer.gatt_service_added_count());
351 EXPECT_EQ(2, observer.gatt_service_removed_count()); 342 EXPECT_EQ(2, observer.gatt_service_removed_count());
352 EXPECT_FALSE(observer.last_gatt_service_id().empty()); 343 EXPECT_FALSE(observer.last_gatt_service_id().empty());
353 EXPECT_EQ(BluetoothUUID( 344 EXPECT_EQ(BluetoothUUID(
354 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), 345 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
355 observer.last_gatt_service_uuid()); 346 observer.last_gatt_service_uuid());
356 EXPECT_EQ(NULL, adapter_->GetDevice( 347 EXPECT_EQ(NULL, adapter_->GetDevice(
357 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress)); 348 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress));
358 } 349 }
359 350
360 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { 351 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
361 fake_bluetooth_device_client_->CreateDevice( 352 fake_bluetooth_device_client_->CreateDevice(
362 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 353 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
363 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 354 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
364 BluetoothDevice* device = 355 BluetoothDevice* device =
365 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 356 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
366 ASSERT_TRUE(device); 357 ASSERT_TRUE(device);
367 358
368 TestBluetoothAdapterObserver observer(adapter_); 359 TestBluetoothAdapterObserver observer(adapter_);
369 360
370 // Expose the fake Heart Rate service. This will asynchronously expose 361 // Expose the fake Heart Rate service. This will asynchronously expose
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 EXPECT_EQ(3U, service->GetCharacteristics().size()); 409 EXPECT_EQ(3U, service->GetCharacteristics().size());
419 410
420 // Hide the service. All characteristics should disappear. 411 // Hide the service. All characteristics should disappear.
421 fake_bluetooth_gatt_service_client_->HideHeartRateService(); 412 fake_bluetooth_gatt_service_client_->HideHeartRateService();
422 EXPECT_EQ(0, observer.gatt_service_changed_count()); 413 EXPECT_EQ(0, observer.gatt_service_changed_count());
423 EXPECT_EQ(6, observer.gatt_characteristic_added_count()); 414 EXPECT_EQ(6, observer.gatt_characteristic_added_count());
424 EXPECT_EQ(6, observer.gatt_characteristic_removed_count()); 415 EXPECT_EQ(6, observer.gatt_characteristic_removed_count());
425 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 416 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
426 } 417 }
427 418
428 TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { 419 TEST_F(BluetoothGattBlueZTest, GattDescriptorAddedAndRemoved) {
429 fake_bluetooth_device_client_->CreateDevice( 420 fake_bluetooth_device_client_->CreateDevice(
430 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 421 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
431 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 422 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
432 BluetoothDevice* device = 423 BluetoothDevice* device =
433 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 424 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
434 ASSERT_TRUE(device); 425 ASSERT_TRUE(device);
435 426
436 TestBluetoothAdapterObserver observer(adapter_); 427 TestBluetoothAdapterObserver observer(adapter_);
437 428
438 // Expose the fake Heart Rate service. This will asynchronously expose 429 // Expose the fake Heart Rate service. This will asynchronously expose
(...skipping 15 matching lines...) Expand all
454 // Run the message loop so that the characteristics appear. 445 // Run the message loop so that the characteristics appear.
455 base::MessageLoop::current()->Run(); 446 base::MessageLoop::current()->Run();
456 EXPECT_EQ(0, observer.gatt_service_changed_count()); 447 EXPECT_EQ(0, observer.gatt_service_changed_count());
457 448
458 // Only the Heart Rate Measurement characteristic has a descriptor. 449 // Only the Heart Rate Measurement characteristic has a descriptor.
459 EXPECT_EQ(1, observer.gatt_descriptor_added_count()); 450 EXPECT_EQ(1, observer.gatt_descriptor_added_count());
460 EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); 451 EXPECT_EQ(0, observer.gatt_descriptor_removed_count());
461 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); 452 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count());
462 453
463 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( 454 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
464 fake_bluetooth_gatt_characteristic_client_-> 455 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
465 GetBodySensorLocationPath().value()); 456 .value());
466 ASSERT_TRUE(characteristic); 457 ASSERT_TRUE(characteristic);
467 EXPECT_TRUE(characteristic->GetDescriptors().empty()); 458 EXPECT_TRUE(characteristic->GetDescriptors().empty());
468 459
469 characteristic = service->GetCharacteristic( 460 characteristic = service->GetCharacteristic(
470 fake_bluetooth_gatt_characteristic_client_-> 461 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath()
471 GetHeartRateControlPointPath().value()); 462 .value());
472 ASSERT_TRUE(characteristic); 463 ASSERT_TRUE(characteristic);
473 EXPECT_TRUE(characteristic->GetDescriptors().empty()); 464 EXPECT_TRUE(characteristic->GetDescriptors().empty());
474 465
475 characteristic = service->GetCharacteristic( 466 characteristic = service->GetCharacteristic(
476 fake_bluetooth_gatt_characteristic_client_-> 467 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
477 GetHeartRateMeasurementPath().value()); 468 .value());
478 ASSERT_TRUE(characteristic); 469 ASSERT_TRUE(characteristic);
479 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); 470 EXPECT_EQ(1U, characteristic->GetDescriptors().size());
480 471
481 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; 472 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0];
482 EXPECT_FALSE(descriptor->IsLocal()); 473 EXPECT_FALSE(descriptor->IsLocal());
483 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), 474 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
484 descriptor->GetUUID()); 475 descriptor->GetUUID());
485 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); 476 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid());
486 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); 477 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id());
487 478
(...skipping 20 matching lines...) Expand all
508 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); 499 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count());
509 500
510 descriptor = characteristic->GetDescriptors()[0]; 501 descriptor = characteristic->GetDescriptors()[0];
511 EXPECT_FALSE(descriptor->IsLocal()); 502 EXPECT_FALSE(descriptor->IsLocal());
512 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), 503 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
513 descriptor->GetUUID()); 504 descriptor->GetUUID());
514 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); 505 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid());
515 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); 506 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id());
516 } 507 }
517 508
518 TEST_F(BluetoothGattChromeOSTest, AdapterAddedAfterGattService) { 509 TEST_F(BluetoothGattBlueZTest, AdapterAddedAfterGattService) {
519 // This unit test tests that all remote GATT objects are created for D-Bus 510 // This unit test tests that all remote GATT objects are created for D-Bus
520 // objects that were already exposed. 511 // objects that were already exposed.
521 adapter_ = NULL; 512 adapter_ = NULL;
522 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting()); 513 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting());
523 514
524 // Create the fake D-Bus objects. 515 // Create the fake D-Bus objects.
525 fake_bluetooth_device_client_->CreateDevice( 516 fake_bluetooth_device_client_->CreateDevice(
526 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 517 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
527 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 518 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
528 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 519 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
(...skipping 16 matching lines...) Expand all
545 EXPECT_TRUE(service->IsPrimary()); 536 EXPECT_TRUE(service->IsPrimary());
546 EXPECT_EQ(BluetoothUUID( 537 EXPECT_EQ(BluetoothUUID(
547 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), 538 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
548 service->GetUUID()); 539 service->GetUUID());
549 EXPECT_EQ(service, device->GetGattServices()[0]); 540 EXPECT_EQ(service, device->GetGattServices()[0]);
550 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier())); 541 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
551 EXPECT_FALSE(service->IsLocal()); 542 EXPECT_FALSE(service->IsLocal());
552 EXPECT_EQ(3U, service->GetCharacteristics().size()); 543 EXPECT_EQ(3U, service->GetCharacteristics().size());
553 544
554 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( 545 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
555 fake_bluetooth_gatt_characteristic_client_-> 546 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
556 GetBodySensorLocationPath().value()); 547 .value());
557 ASSERT_TRUE(characteristic); 548 ASSERT_TRUE(characteristic);
558 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: 549 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
559 kBodySensorLocationUUID), 550 kBodySensorLocationUUID),
560 characteristic->GetUUID()); 551 characteristic->GetUUID());
561 EXPECT_FALSE(characteristic->IsLocal()); 552 EXPECT_FALSE(characteristic->IsLocal());
562 EXPECT_TRUE(characteristic->GetDescriptors().empty()); 553 EXPECT_TRUE(characteristic->GetDescriptors().empty());
563 554
564 characteristic = service->GetCharacteristic( 555 characteristic = service->GetCharacteristic(
565 fake_bluetooth_gatt_characteristic_client_-> 556 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath()
566 GetHeartRateControlPointPath().value()); 557 .value());
567 ASSERT_TRUE(characteristic); 558 ASSERT_TRUE(characteristic);
568 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: 559 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
569 kHeartRateControlPointUUID), 560 kHeartRateControlPointUUID),
570 characteristic->GetUUID()); 561 characteristic->GetUUID());
571 EXPECT_FALSE(characteristic->IsLocal()); 562 EXPECT_FALSE(characteristic->IsLocal());
572 EXPECT_TRUE(characteristic->GetDescriptors().empty()); 563 EXPECT_TRUE(characteristic->GetDescriptors().empty());
573 564
574 characteristic = service->GetCharacteristic( 565 characteristic = service->GetCharacteristic(
575 fake_bluetooth_gatt_characteristic_client_-> 566 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
576 GetHeartRateMeasurementPath().value()); 567 .value());
577 ASSERT_TRUE(characteristic); 568 ASSERT_TRUE(characteristic);
578 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: 569 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
579 kHeartRateMeasurementUUID), 570 kHeartRateMeasurementUUID),
580 characteristic->GetUUID()); 571 characteristic->GetUUID());
581 EXPECT_FALSE(characteristic->IsLocal()); 572 EXPECT_FALSE(characteristic->IsLocal());
582 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); 573 EXPECT_EQ(1U, characteristic->GetDescriptors().size());
583 574
584 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; 575 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0];
585 ASSERT_TRUE(descriptor); 576 ASSERT_TRUE(descriptor);
586 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), 577 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
587 descriptor->GetUUID()); 578 descriptor->GetUUID());
588 EXPECT_FALSE(descriptor->IsLocal()); 579 EXPECT_FALSE(descriptor->IsLocal());
589 } 580 }
590 581
591 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { 582 TEST_F(BluetoothGattBlueZTest, GattCharacteristicValue) {
592 fake_bluetooth_device_client_->CreateDevice( 583 fake_bluetooth_device_client_->CreateDevice(
593 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 584 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
594 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 585 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
595 BluetoothDevice* device = 586 BluetoothDevice* device =
596 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 587 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
597 ASSERT_TRUE(device); 588 ASSERT_TRUE(device);
598 589
599 TestBluetoothAdapterObserver observer(adapter_); 590 TestBluetoothAdapterObserver observer(adapter_);
600 591
601 // Expose the fake Heart Rate service. This will asynchronously expose 592 // Expose the fake Heart Rate service. This will asynchronously expose
602 // characteristics. 593 // characteristics.
603 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 594 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
604 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 595 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
605 ASSERT_EQ(1, observer.gatt_service_added_count()); 596 ASSERT_EQ(1, observer.gatt_service_added_count());
606 597
607 BluetoothGattService* service = 598 BluetoothGattService* service =
608 device->GetGattService(observer.last_gatt_service_id()); 599 device->GetGattService(observer.last_gatt_service_id());
609 600
610 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 601 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
611 602
612 // Run the message loop so that the characteristics appear. 603 // Run the message loop so that the characteristics appear.
613 base::MessageLoop::current()->Run(); 604 base::MessageLoop::current()->Run();
614 605
615 // Issue write request to non-writable characteristics. 606 // Issue write request to non-writable characteristics.
616 observer.Reset(); 607 observer.Reset();
617 608
618 std::vector<uint8> write_value; 609 std::vector<uint8> write_value;
619 write_value.push_back(0x01); 610 write_value.push_back(0x01);
620 BluetoothGattCharacteristic* characteristic = 611 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
621 service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_-> 612 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
622 GetHeartRateMeasurementPath().value()); 613 .value());
623 ASSERT_TRUE(characteristic); 614 ASSERT_TRUE(characteristic);
624 EXPECT_FALSE(characteristic->IsNotifying()); 615 EXPECT_FALSE(characteristic->IsNotifying());
625 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> 616 EXPECT_EQ(
626 GetHeartRateMeasurementPath().value(), 617 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
627 characteristic->GetIdentifier()); 618 .value(),
619 characteristic->GetIdentifier());
628 EXPECT_EQ(kHeartRateMeasurementUUID, characteristic->GetUUID()); 620 EXPECT_EQ(kHeartRateMeasurementUUID, characteristic->GetUUID());
629 characteristic->WriteRemoteCharacteristic( 621 characteristic->WriteRemoteCharacteristic(
630 write_value, 622 write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
631 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 623 base::Unretained(this)),
632 base::Unretained(this)), 624 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
633 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
634 base::Unretained(this))); 625 base::Unretained(this)));
635 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); 626 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty());
636 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); 627 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid());
637 EXPECT_EQ(0, success_callback_count_); 628 EXPECT_EQ(0, success_callback_count_);
638 EXPECT_EQ(1, error_callback_count_); 629 EXPECT_EQ(1, error_callback_count_);
639 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, 630 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED,
640 last_service_error_); 631 last_service_error_);
641 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 632 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
642 633
643 characteristic = service->GetCharacteristic( 634 characteristic = service->GetCharacteristic(
644 fake_bluetooth_gatt_characteristic_client_-> 635 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
645 GetBodySensorLocationPath().value()); 636 .value());
646 ASSERT_TRUE(characteristic); 637 ASSERT_TRUE(characteristic);
647 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> 638 EXPECT_EQ(
648 GetBodySensorLocationPath().value(), 639 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
649 characteristic->GetIdentifier()); 640 .value(),
641 characteristic->GetIdentifier());
650 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); 642 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID());
651 characteristic->WriteRemoteCharacteristic( 643 characteristic->WriteRemoteCharacteristic(
652 write_value, 644 write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
653 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 645 base::Unretained(this)),
654 base::Unretained(this)), 646 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
655 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
656 base::Unretained(this))); 647 base::Unretained(this)));
657 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); 648 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty());
658 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); 649 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid());
659 EXPECT_EQ(0, success_callback_count_); 650 EXPECT_EQ(0, success_callback_count_);
660 EXPECT_EQ(2, error_callback_count_); 651 EXPECT_EQ(2, error_callback_count_);
661 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, 652 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED,
662 last_service_error_); 653 last_service_error_);
663 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 654 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
664 655
665 // Issue write request to writable characteristic. The "Body Sensor Location" 656 // Issue write request to writable characteristic. The "Body Sensor Location"
666 // characteristic does not send notifications and WriteValue does not result 657 // characteristic does not send notifications and WriteValue does not result
667 // in a CharacteristicValueChanged event, thus no such event should be 658 // in a CharacteristicValueChanged event, thus no such event should be
668 // received. 659 // received.
669 characteristic = service->GetCharacteristic( 660 characteristic = service->GetCharacteristic(
670 fake_bluetooth_gatt_characteristic_client_-> 661 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath()
671 GetHeartRateControlPointPath().value()); 662 .value());
672 ASSERT_TRUE(characteristic); 663 ASSERT_TRUE(characteristic);
673 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> 664 EXPECT_EQ(
674 GetHeartRateControlPointPath().value(), 665 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath()
675 characteristic->GetIdentifier()); 666 .value(),
667 characteristic->GetIdentifier());
676 EXPECT_EQ(kHeartRateControlPointUUID, characteristic->GetUUID()); 668 EXPECT_EQ(kHeartRateControlPointUUID, characteristic->GetUUID());
677 characteristic->WriteRemoteCharacteristic( 669 characteristic->WriteRemoteCharacteristic(
678 write_value, 670 write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
679 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 671 base::Unretained(this)),
680 base::Unretained(this)), 672 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
681 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
682 base::Unretained(this))); 673 base::Unretained(this)));
683 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); 674 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty());
684 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); 675 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid());
685 EXPECT_EQ(1, success_callback_count_); 676 EXPECT_EQ(1, success_callback_count_);
686 EXPECT_EQ(2, error_callback_count_); 677 EXPECT_EQ(2, error_callback_count_);
687 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 678 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
688 679
689 // Issue some invalid write requests to the characteristic. 680 // Issue some invalid write requests to the characteristic.
690 // The value should still not change. 681 // The value should still not change.
691 682
692 std::vector<uint8> invalid_write_length; 683 std::vector<uint8> invalid_write_length;
693 invalid_write_length.push_back(0x01); 684 invalid_write_length.push_back(0x01);
694 invalid_write_length.push_back(0x00); 685 invalid_write_length.push_back(0x00);
695 characteristic->WriteRemoteCharacteristic( 686 characteristic->WriteRemoteCharacteristic(
696 invalid_write_length, 687 invalid_write_length, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
697 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 688 base::Unretained(this)),
698 base::Unretained(this)), 689 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
699 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
700 base::Unretained(this))); 690 base::Unretained(this)));
701 EXPECT_EQ(1, success_callback_count_); 691 EXPECT_EQ(1, success_callback_count_);
702 EXPECT_EQ(3, error_callback_count_); 692 EXPECT_EQ(3, error_callback_count_);
703 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, 693 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH,
704 last_service_error_); 694 last_service_error_);
705 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 695 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
706 696
707 std::vector<uint8> invalid_write_value; 697 std::vector<uint8> invalid_write_value;
708 invalid_write_value.push_back(0x02); 698 invalid_write_value.push_back(0x02);
709 characteristic->WriteRemoteCharacteristic( 699 characteristic->WriteRemoteCharacteristic(
710 invalid_write_value, 700 invalid_write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
711 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 701 base::Unretained(this)),
712 base::Unretained(this)), 702 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
713 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
714 base::Unretained(this))); 703 base::Unretained(this)));
715 EXPECT_EQ(1, success_callback_count_); 704 EXPECT_EQ(1, success_callback_count_);
716 EXPECT_EQ(4, error_callback_count_); 705 EXPECT_EQ(4, error_callback_count_);
717 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_service_error_); 706 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_service_error_);
718 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 707 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
719 708
720 // Issue a read request. A successful read results in a 709 // Issue a read request. A successful read results in a
721 // CharacteristicValueChanged notification. 710 // CharacteristicValueChanged notification.
722 characteristic = service->GetCharacteristic( 711 characteristic = service->GetCharacteristic(
723 fake_bluetooth_gatt_characteristic_client_-> 712 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
724 GetBodySensorLocationPath().value()); 713 .value());
725 ASSERT_TRUE(characteristic); 714 ASSERT_TRUE(characteristic);
726 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> 715 EXPECT_EQ(
727 GetBodySensorLocationPath().value(), 716 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
728 characteristic->GetIdentifier()); 717 .value(),
718 characteristic->GetIdentifier());
729 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); 719 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID());
730 characteristic->ReadRemoteCharacteristic( 720 characteristic->ReadRemoteCharacteristic(
731 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 721 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
732 base::Unretained(this)), 722 base::Unretained(this)),
733 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 723 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
734 base::Unretained(this))); 724 base::Unretained(this)));
735 EXPECT_EQ(2, success_callback_count_); 725 EXPECT_EQ(2, success_callback_count_);
736 EXPECT_EQ(4, error_callback_count_); 726 EXPECT_EQ(4, error_callback_count_);
737 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 727 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
738 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); 728 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_));
739 729
740 // Test long-running actions. 730 // Test long-running actions.
741 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(1); 731 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(1);
742 characteristic = service->GetCharacteristic( 732 characteristic = service->GetCharacteristic(
743 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() 733 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
744 .value()); 734 .value());
745 ASSERT_TRUE(characteristic); 735 ASSERT_TRUE(characteristic);
746 EXPECT_EQ( 736 EXPECT_EQ(
747 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() 737 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
748 .value(), 738 .value(),
749 characteristic->GetIdentifier()); 739 characteristic->GetIdentifier());
750 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); 740 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID());
751 characteristic->ReadRemoteCharacteristic( 741 characteristic->ReadRemoteCharacteristic(
752 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 742 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
753 base::Unretained(this)), 743 base::Unretained(this)),
754 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 744 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
755 base::Unretained(this))); 745 base::Unretained(this)));
756 746
757 // Callback counts shouldn't change, this one will be delayed until after 747 // Callback counts shouldn't change, this one will be delayed until after
758 // tne next one. 748 // tne next one.
759 EXPECT_EQ(2, success_callback_count_); 749 EXPECT_EQ(2, success_callback_count_);
760 EXPECT_EQ(4, error_callback_count_); 750 EXPECT_EQ(4, error_callback_count_);
761 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 751 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
762 752
763 // Next read should error because IN_PROGRESS 753 // Next read should error because IN_PROGRESS
764 characteristic->ReadRemoteCharacteristic( 754 characteristic->ReadRemoteCharacteristic(
765 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 755 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
766 base::Unretained(this)), 756 base::Unretained(this)),
767 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 757 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
768 base::Unretained(this))); 758 base::Unretained(this)));
769 EXPECT_EQ(5, error_callback_count_); 759 EXPECT_EQ(5, error_callback_count_);
770 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, last_service_error_); 760 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, last_service_error_);
771 761
772 // But previous call finished. 762 // But previous call finished.
773 EXPECT_EQ(3, success_callback_count_); 763 EXPECT_EQ(3, success_callback_count_);
774 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 764 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count());
775 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); 765 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_));
776 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(0); 766 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(0);
777 767
778 // Test unauthorized actions. 768 // Test unauthorized actions.
779 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(false); 769 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(false);
780 characteristic->ReadRemoteCharacteristic( 770 characteristic->ReadRemoteCharacteristic(
781 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 771 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
782 base::Unretained(this)), 772 base::Unretained(this)),
783 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 773 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
784 base::Unretained(this))); 774 base::Unretained(this)));
785 EXPECT_EQ(3, success_callback_count_); 775 EXPECT_EQ(3, success_callback_count_);
786 EXPECT_EQ(6, error_callback_count_); 776 EXPECT_EQ(6, error_callback_count_);
787 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED, 777 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED,
788 last_service_error_); 778 last_service_error_);
789 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 779 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count());
790 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(true); 780 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(true);
791 781
792 // Test unauthenticated / needs login. 782 // Test unauthenticated / needs login.
793 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(false); 783 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(false);
794 characteristic->ReadRemoteCharacteristic( 784 characteristic->ReadRemoteCharacteristic(
795 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 785 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
796 base::Unretained(this)), 786 base::Unretained(this)),
797 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 787 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
798 base::Unretained(this))); 788 base::Unretained(this)));
799 EXPECT_EQ(3, success_callback_count_); 789 EXPECT_EQ(3, success_callback_count_);
800 EXPECT_EQ(7, error_callback_count_); 790 EXPECT_EQ(7, error_callback_count_);
801 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PAIRED, last_service_error_); 791 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PAIRED, last_service_error_);
802 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 792 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count());
803 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true); 793 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true);
804 } 794 }
805 795
806 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { 796 TEST_F(BluetoothGattBlueZTest, GattCharacteristicProperties) {
807 fake_bluetooth_device_client_->CreateDevice( 797 fake_bluetooth_device_client_->CreateDevice(
808 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 798 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
809 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 799 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
810 BluetoothDevice* device = 800 BluetoothDevice* device =
811 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 801 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
812 ASSERT_TRUE(device); 802 ASSERT_TRUE(device);
813 803
814 TestBluetoothAdapterObserver observer(adapter_); 804 TestBluetoothAdapterObserver observer(adapter_);
815 805
816 // Expose the fake Heart Rate service. This will asynchronously expose 806 // Expose the fake Heart Rate service. This will asynchronously expose
817 // characteristics. 807 // characteristics.
818 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 808 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
819 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 809 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
820 810
821 BluetoothGattService* service = 811 BluetoothGattService* service =
822 device->GetGattService(observer.last_gatt_service_id()); 812 device->GetGattService(observer.last_gatt_service_id());
823 813
824 EXPECT_TRUE(service->GetCharacteristics().empty()); 814 EXPECT_TRUE(service->GetCharacteristics().empty());
825 815
826 // Run the message loop so that the characteristics appear. 816 // Run the message loop so that the characteristics appear.
827 base::MessageLoop::current()->Run(); 817 base::MessageLoop::current()->Run();
828 818
829 BluetoothGattCharacteristic *characteristic = service->GetCharacteristic( 819 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
830 fake_bluetooth_gatt_characteristic_client_-> 820 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
831 GetBodySensorLocationPath().value()); 821 .value());
832 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_READ, 822 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_READ,
833 characteristic->GetProperties()); 823 characteristic->GetProperties());
834 824
835 characteristic = service->GetCharacteristic( 825 characteristic = service->GetCharacteristic(
836 fake_bluetooth_gatt_characteristic_client_-> 826 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath()
837 GetHeartRateControlPointPath().value()); 827 .value());
838 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_WRITE, 828 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_WRITE,
839 characteristic->GetProperties()); 829 characteristic->GetProperties());
840 830
841 characteristic = service->GetCharacteristic( 831 characteristic = service->GetCharacteristic(
842 fake_bluetooth_gatt_characteristic_client_-> 832 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
843 GetHeartRateMeasurementPath().value()); 833 .value());
844 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_NOTIFY, 834 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_NOTIFY,
845 characteristic->GetProperties()); 835 characteristic->GetProperties());
846 } 836 }
847 837
848 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { 838 TEST_F(BluetoothGattBlueZTest, GattDescriptorValue) {
849 fake_bluetooth_device_client_->CreateDevice( 839 fake_bluetooth_device_client_->CreateDevice(
850 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 840 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
851 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 841 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
852 BluetoothDevice* device = 842 BluetoothDevice* device =
853 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 843 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
854 ASSERT_TRUE(device); 844 ASSERT_TRUE(device);
855 845
856 TestBluetoothAdapterObserver observer(adapter_); 846 TestBluetoothAdapterObserver observer(adapter_);
857 847
858 // Expose the fake Heart Rate service. This will asynchronously expose 848 // Expose the fake Heart Rate service. This will asynchronously expose
(...skipping 10 matching lines...) Expand all
869 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); 859 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count());
870 EXPECT_TRUE(service->GetCharacteristics().empty()); 860 EXPECT_TRUE(service->GetCharacteristics().empty());
871 861
872 // Run the message loop so that the characteristics appear. 862 // Run the message loop so that the characteristics appear.
873 base::MessageLoop::current()->Run(); 863 base::MessageLoop::current()->Run();
874 EXPECT_EQ(0, observer.gatt_service_changed_count()); 864 EXPECT_EQ(0, observer.gatt_service_changed_count());
875 EXPECT_EQ(1, observer.gatt_discovery_complete_count()); 865 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
876 866
877 // Only the Heart Rate Measurement characteristic has a descriptor. 867 // Only the Heart Rate Measurement characteristic has a descriptor.
878 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( 868 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
879 fake_bluetooth_gatt_characteristic_client_-> 869 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
880 GetHeartRateMeasurementPath().value()); 870 .value());
881 ASSERT_TRUE(characteristic); 871 ASSERT_TRUE(characteristic);
882 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); 872 EXPECT_EQ(1U, characteristic->GetDescriptors().size());
883 EXPECT_FALSE(characteristic->IsNotifying()); 873 EXPECT_FALSE(characteristic->IsNotifying());
884 874
885 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; 875 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0];
886 EXPECT_FALSE(descriptor->IsLocal()); 876 EXPECT_FALSE(descriptor->IsLocal());
887 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), 877 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
888 descriptor->GetUUID()); 878 descriptor->GetUUID());
889 879
890 std::vector<uint8_t> desc_value = {0x00, 0x00}; 880 std::vector<uint8_t> desc_value = {0x00, 0x00};
891 881
892 /* The cached value will be empty until the first read request */ 882 /* The cached value will be empty until the first read request */
893 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); 883 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
894 EXPECT_TRUE(descriptor->GetValue().empty()); 884 EXPECT_TRUE(descriptor->GetValue().empty());
895 885
896 EXPECT_EQ(0, success_callback_count_); 886 EXPECT_EQ(0, success_callback_count_);
897 EXPECT_EQ(0, error_callback_count_); 887 EXPECT_EQ(0, error_callback_count_);
898 EXPECT_TRUE(last_read_value_.empty()); 888 EXPECT_TRUE(last_read_value_.empty());
899 889
900 // Read value. GattDescriptorValueChanged event will be sent after a 890 // Read value. GattDescriptorValueChanged event will be sent after a
901 // successful read. 891 // successful read.
902 descriptor->ReadRemoteDescriptor( 892 descriptor->ReadRemoteDescriptor(
903 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 893 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
904 base::Unretained(this)), 894 base::Unretained(this)),
905 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 895 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
906 base::Unretained(this))); 896 base::Unretained(this)));
907 EXPECT_EQ(1, success_callback_count_); 897 EXPECT_EQ(1, success_callback_count_);
908 EXPECT_EQ(0, error_callback_count_); 898 EXPECT_EQ(0, error_callback_count_);
909 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 899 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
910 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); 900 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue()));
911 EXPECT_EQ(0, observer.gatt_service_changed_count()); 901 EXPECT_EQ(0, observer.gatt_service_changed_count());
912 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); 902 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count());
913 903
914 // Write value. Writes to this descriptor will fail. 904 // Write value. Writes to this descriptor will fail.
915 desc_value[0] = 0x03; 905 desc_value[0] = 0x03;
916 descriptor->WriteRemoteDescriptor( 906 descriptor->WriteRemoteDescriptor(
917 desc_value, 907 desc_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
918 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 908 base::Unretained(this)),
919 base::Unretained(this)), 909 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
920 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback,
921 base::Unretained(this))); 910 base::Unretained(this)));
922 EXPECT_EQ(1, success_callback_count_); 911 EXPECT_EQ(1, success_callback_count_);
923 EXPECT_EQ(1, error_callback_count_); 912 EXPECT_EQ(1, error_callback_count_);
924 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, 913 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED,
925 last_service_error_); 914 last_service_error_);
926 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 915 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
927 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); 916 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
928 EXPECT_EQ(0, observer.gatt_service_changed_count()); 917 EXPECT_EQ(0, observer.gatt_service_changed_count());
929 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); 918 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count());
930 919
931 // Read value. The value should remain unchanged. 920 // Read value. The value should remain unchanged.
932 descriptor->ReadRemoteDescriptor( 921 descriptor->ReadRemoteDescriptor(
933 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 922 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
934 base::Unretained(this)), 923 base::Unretained(this)),
935 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 924 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
936 base::Unretained(this))); 925 base::Unretained(this)));
937 EXPECT_EQ(2, success_callback_count_); 926 EXPECT_EQ(2, success_callback_count_);
938 EXPECT_EQ(1, error_callback_count_); 927 EXPECT_EQ(1, error_callback_count_);
939 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 928 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
940 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); 929 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
941 EXPECT_EQ(0, observer.gatt_service_changed_count()); 930 EXPECT_EQ(0, observer.gatt_service_changed_count());
942 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); 931 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count());
943 932
944 // Start notifications on the descriptor's characteristic. The descriptor 933 // Start notifications on the descriptor's characteristic. The descriptor
945 // value should change. 934 // value should change.
946 characteristic->StartNotifySession( 935 characteristic->StartNotifySession(
947 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 936 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
948 base::Unretained(this)), 937 base::Unretained(this)),
949 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 938 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
950 base::Unretained(this))); 939 base::Unretained(this)));
951 base::MessageLoop::current()->Run(); 940 base::MessageLoop::current()->Run();
952 EXPECT_EQ(3, success_callback_count_); 941 EXPECT_EQ(3, success_callback_count_);
953 EXPECT_EQ(1, error_callback_count_); 942 EXPECT_EQ(1, error_callback_count_);
954 EXPECT_EQ(1U, update_sessions_.size()); 943 EXPECT_EQ(1U, update_sessions_.size());
955 EXPECT_TRUE(characteristic->IsNotifying()); 944 EXPECT_TRUE(characteristic->IsNotifying());
956 945
957 // Read the new descriptor value. We should receive a value updated event. 946 // Read the new descriptor value. We should receive a value updated event.
958 descriptor->ReadRemoteDescriptor( 947 descriptor->ReadRemoteDescriptor(
959 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, 948 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
960 base::Unretained(this)), 949 base::Unretained(this)),
961 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 950 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
962 base::Unretained(this))); 951 base::Unretained(this)));
963 EXPECT_EQ(4, success_callback_count_); 952 EXPECT_EQ(4, success_callback_count_);
964 EXPECT_EQ(1, error_callback_count_); 953 EXPECT_EQ(1, error_callback_count_);
965 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); 954 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
966 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); 955 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
967 EXPECT_EQ(0, observer.gatt_service_changed_count()); 956 EXPECT_EQ(0, observer.gatt_service_changed_count());
968 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count()); 957 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count());
969 } 958 }
970 959
971 TEST_F(BluetoothGattChromeOSTest, NotifySessions) { 960 TEST_F(BluetoothGattBlueZTest, NotifySessions) {
972 fake_bluetooth_device_client_->CreateDevice( 961 fake_bluetooth_device_client_->CreateDevice(
973 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 962 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
974 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 963 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
975 BluetoothDevice* device = 964 BluetoothDevice* device =
976 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 965 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
977 ASSERT_TRUE(device); 966 ASSERT_TRUE(device);
978 967
979 TestBluetoothAdapterObserver observer(adapter_); 968 TestBluetoothAdapterObserver observer(adapter_);
980 969
981 // Expose the fake Heart Rate service. This will asynchronously expose 970 // Expose the fake Heart Rate service. This will asynchronously expose
(...skipping 12 matching lines...) Expand all
994 983
995 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( 984 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
996 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() 985 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
997 .value()); 986 .value());
998 ASSERT_TRUE(characteristic); 987 ASSERT_TRUE(characteristic);
999 EXPECT_FALSE(characteristic->IsNotifying()); 988 EXPECT_FALSE(characteristic->IsNotifying());
1000 EXPECT_TRUE(update_sessions_.empty()); 989 EXPECT_TRUE(update_sessions_.empty());
1001 990
1002 // Request to start notifications. 991 // Request to start notifications.
1003 characteristic->StartNotifySession( 992 characteristic->StartNotifySession(
1004 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 993 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1005 base::Unretained(this)), 994 base::Unretained(this)),
1006 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 995 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1007 base::Unretained(this))); 996 base::Unretained(this)));
1008 997
1009 // The operation still hasn't completed but we should have received the first 998 // The operation still hasn't completed but we should have received the first
1010 // notification. 999 // notification.
1011 EXPECT_EQ(0, success_callback_count_); 1000 EXPECT_EQ(0, success_callback_count_);
1012 EXPECT_EQ(0, error_callback_count_); 1001 EXPECT_EQ(0, error_callback_count_);
1013 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1002 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1014 EXPECT_TRUE(update_sessions_.empty()); 1003 EXPECT_TRUE(update_sessions_.empty());
1015 1004
1016 // Send a two more requests, which should get queued. 1005 // Send a two more requests, which should get queued.
1017 characteristic->StartNotifySession( 1006 characteristic->StartNotifySession(
1018 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1007 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1019 base::Unretained(this)), 1008 base::Unretained(this)),
1020 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1009 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1021 base::Unretained(this))); 1010 base::Unretained(this)));
1022 characteristic->StartNotifySession( 1011 characteristic->StartNotifySession(
1023 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1012 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1024 base::Unretained(this)), 1013 base::Unretained(this)),
1025 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1014 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1026 base::Unretained(this))); 1015 base::Unretained(this)));
1027 EXPECT_EQ(0, success_callback_count_); 1016 EXPECT_EQ(0, success_callback_count_);
1028 EXPECT_EQ(0, error_callback_count_); 1017 EXPECT_EQ(0, error_callback_count_);
1029 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1018 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1030 EXPECT_TRUE(update_sessions_.empty()); 1019 EXPECT_TRUE(update_sessions_.empty());
1031 EXPECT_TRUE(characteristic->IsNotifying()); 1020 EXPECT_TRUE(characteristic->IsNotifying());
1032 1021
1033 // Run the main loop. The initial call should complete. The queued call should 1022 // Run the main loop. The initial call should complete. The queued call should
1034 // succeed immediately. 1023 // succeed immediately.
1035 base::MessageLoop::current()->Run(); 1024 base::MessageLoop::current()->Run();
1036 1025
1037 EXPECT_EQ(3, success_callback_count_); 1026 EXPECT_EQ(3, success_callback_count_);
1038 EXPECT_EQ(0, error_callback_count_); 1027 EXPECT_EQ(0, error_callback_count_);
1039 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1028 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1040 EXPECT_EQ(3U, update_sessions_.size()); 1029 EXPECT_EQ(3U, update_sessions_.size());
1041 1030
1042 // Notifications should be getting sent regularly now. 1031 // Notifications should be getting sent regularly now.
1043 base::MessageLoop::current()->Run(); 1032 base::MessageLoop::current()->Run();
1044 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); 1033 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1);
1045 1034
1046 // Stop one of the sessions. The session should become inactive but the 1035 // Stop one of the sessions. The session should become inactive but the
1047 // characteristic should still be notifying. 1036 // characteristic should still be notifying.
1048 BluetoothGattNotifySession* session = update_sessions_[0]; 1037 BluetoothGattNotifySession* session = update_sessions_[0];
1049 EXPECT_TRUE(session->IsActive()); 1038 EXPECT_TRUE(session->IsActive());
1050 session->Stop(base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 1039 session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
1051 base::Unretained(this))); 1040 base::Unretained(this)));
1052 EXPECT_EQ(4, success_callback_count_); 1041 EXPECT_EQ(4, success_callback_count_);
1053 EXPECT_EQ(0, error_callback_count_); 1042 EXPECT_EQ(0, error_callback_count_);
1054 EXPECT_FALSE(session->IsActive()); 1043 EXPECT_FALSE(session->IsActive());
1055 EXPECT_EQ(characteristic->GetIdentifier(), 1044 EXPECT_EQ(characteristic->GetIdentifier(),
1056 session->GetCharacteristicIdentifier()); 1045 session->GetCharacteristicIdentifier());
1057 EXPECT_TRUE(characteristic->IsNotifying()); 1046 EXPECT_TRUE(characteristic->IsNotifying());
1058 1047
1059 // Delete another session. Characteristic should still be notifying. 1048 // Delete another session. Characteristic should still be notifying.
1060 update_sessions_.pop_back(); 1049 update_sessions_.pop_back();
1061 EXPECT_EQ(2U, update_sessions_.size()); 1050 EXPECT_EQ(2U, update_sessions_.size());
1062 EXPECT_TRUE(characteristic->IsNotifying()); 1051 EXPECT_TRUE(characteristic->IsNotifying());
1063 EXPECT_FALSE(update_sessions_[0]->IsActive()); 1052 EXPECT_FALSE(update_sessions_[0]->IsActive());
1064 EXPECT_TRUE(update_sessions_[1]->IsActive()); 1053 EXPECT_TRUE(update_sessions_[1]->IsActive());
1065 1054
1066 // Clear the last session. 1055 // Clear the last session.
1067 update_sessions_.clear(); 1056 update_sessions_.clear();
1068 EXPECT_TRUE(update_sessions_.empty()); 1057 EXPECT_TRUE(update_sessions_.empty());
1069 EXPECT_FALSE(characteristic->IsNotifying()); 1058 EXPECT_FALSE(characteristic->IsNotifying());
1070 1059
1071 success_callback_count_ = 0; 1060 success_callback_count_ = 0;
1072 observer.Reset(); 1061 observer.Reset();
1073 1062
1074 // Enable notifications again. 1063 // Enable notifications again.
1075 characteristic->StartNotifySession( 1064 characteristic->StartNotifySession(
1076 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1065 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1077 base::Unretained(this)), 1066 base::Unretained(this)),
1078 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1067 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1079 base::Unretained(this))); 1068 base::Unretained(this)));
1080 EXPECT_EQ(0, success_callback_count_); 1069 EXPECT_EQ(0, success_callback_count_);
1081 EXPECT_EQ(0, error_callback_count_); 1070 EXPECT_EQ(0, error_callback_count_);
1082 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1071 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1083 EXPECT_TRUE(update_sessions_.empty()); 1072 EXPECT_TRUE(update_sessions_.empty());
1084 EXPECT_TRUE(characteristic->IsNotifying()); 1073 EXPECT_TRUE(characteristic->IsNotifying());
1085 1074
1086 // Run the message loop. Notifications should begin. 1075 // Run the message loop. Notifications should begin.
1087 base::MessageLoop::current()->Run(); 1076 base::MessageLoop::current()->Run();
1088 1077
1089 EXPECT_EQ(1, success_callback_count_); 1078 EXPECT_EQ(1, success_callback_count_);
1090 EXPECT_EQ(0, error_callback_count_); 1079 EXPECT_EQ(0, error_callback_count_);
1091 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1080 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1092 EXPECT_EQ(1U, update_sessions_.size()); 1081 EXPECT_EQ(1U, update_sessions_.size());
1093 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1082 EXPECT_TRUE(update_sessions_[0]->IsActive());
1094 EXPECT_TRUE(characteristic->IsNotifying()); 1083 EXPECT_TRUE(characteristic->IsNotifying());
1095 1084
1096 // Check that notifications are happening. 1085 // Check that notifications are happening.
1097 base::MessageLoop::current()->Run(); 1086 base::MessageLoop::current()->Run();
1098 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); 1087 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1);
1099 1088
1100 // Request another session. This should return immediately. 1089 // Request another session. This should return immediately.
1101 characteristic->StartNotifySession( 1090 characteristic->StartNotifySession(
1102 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1091 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1103 base::Unretained(this)), 1092 base::Unretained(this)),
1104 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1093 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1105 base::Unretained(this))); 1094 base::Unretained(this)));
1106 EXPECT_EQ(2, success_callback_count_); 1095 EXPECT_EQ(2, success_callback_count_);
1107 EXPECT_EQ(0, error_callback_count_); 1096 EXPECT_EQ(0, error_callback_count_);
1108 EXPECT_EQ(2U, update_sessions_.size()); 1097 EXPECT_EQ(2U, update_sessions_.size());
1109 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1098 EXPECT_TRUE(update_sessions_[0]->IsActive());
1110 EXPECT_TRUE(update_sessions_[1]->IsActive()); 1099 EXPECT_TRUE(update_sessions_[1]->IsActive());
1111 EXPECT_TRUE(characteristic->IsNotifying()); 1100 EXPECT_TRUE(characteristic->IsNotifying());
1112 1101
1113 // Hide the characteristic. The sessions should become inactive. 1102 // Hide the characteristic. The sessions should become inactive.
1114 fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics(); 1103 fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics();
1115 EXPECT_EQ(2U, update_sessions_.size()); 1104 EXPECT_EQ(2U, update_sessions_.size());
1116 EXPECT_FALSE(update_sessions_[0]->IsActive()); 1105 EXPECT_FALSE(update_sessions_[0]->IsActive());
1117 EXPECT_FALSE(update_sessions_[1]->IsActive()); 1106 EXPECT_FALSE(update_sessions_[1]->IsActive());
1118 } 1107 }
1119 1108
1120 TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { 1109 TEST_F(BluetoothGattBlueZTest, NotifySessionsMadeInactive) {
1121 fake_bluetooth_device_client_->CreateDevice( 1110 fake_bluetooth_device_client_->CreateDevice(
1122 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1111 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1123 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 1112 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
1124 BluetoothDevice* device = 1113 BluetoothDevice* device =
1125 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 1114 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
1126 ASSERT_TRUE(device); 1115 ASSERT_TRUE(device);
1127 1116
1128 TestBluetoothAdapterObserver observer(adapter_); 1117 TestBluetoothAdapterObserver observer(adapter_);
1129 1118
1130 // Expose the fake Heart Rate service. This will asynchronously expose 1119 // Expose the fake Heart Rate service. This will asynchronously expose
(...skipping 12 matching lines...) Expand all
1143 1132
1144 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( 1133 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
1145 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() 1134 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
1146 .value()); 1135 .value());
1147 ASSERT_TRUE(characteristic); 1136 ASSERT_TRUE(characteristic);
1148 EXPECT_FALSE(characteristic->IsNotifying()); 1137 EXPECT_FALSE(characteristic->IsNotifying());
1149 EXPECT_TRUE(update_sessions_.empty()); 1138 EXPECT_TRUE(update_sessions_.empty());
1150 1139
1151 // Send several requests to start notifications. 1140 // Send several requests to start notifications.
1152 characteristic->StartNotifySession( 1141 characteristic->StartNotifySession(
1153 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1142 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1154 base::Unretained(this)), 1143 base::Unretained(this)),
1155 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1144 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1156 base::Unretained(this))); 1145 base::Unretained(this)));
1157 characteristic->StartNotifySession( 1146 characteristic->StartNotifySession(
1158 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1147 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1159 base::Unretained(this)), 1148 base::Unretained(this)),
1160 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1149 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1161 base::Unretained(this))); 1150 base::Unretained(this)));
1162 characteristic->StartNotifySession( 1151 characteristic->StartNotifySession(
1163 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1152 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1164 base::Unretained(this)), 1153 base::Unretained(this)),
1165 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1154 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1166 base::Unretained(this))); 1155 base::Unretained(this)));
1167 characteristic->StartNotifySession( 1156 characteristic->StartNotifySession(
1168 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1157 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1169 base::Unretained(this)), 1158 base::Unretained(this)),
1170 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1159 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1171 base::Unretained(this))); 1160 base::Unretained(this)));
1172 1161
1173 // The operation still hasn't completed but we should have received the first 1162 // The operation still hasn't completed but we should have received the first
1174 // notification. 1163 // notification.
1175 EXPECT_EQ(0, success_callback_count_); 1164 EXPECT_EQ(0, success_callback_count_);
1176 EXPECT_EQ(0, error_callback_count_); 1165 EXPECT_EQ(0, error_callback_count_);
1177 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1166 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1178 EXPECT_TRUE(characteristic->IsNotifying()); 1167 EXPECT_TRUE(characteristic->IsNotifying());
1179 EXPECT_TRUE(update_sessions_.empty()); 1168 EXPECT_TRUE(update_sessions_.empty());
1180 1169
1181 // Run the main loop. The initial call should complete. The queued calls 1170 // Run the main loop. The initial call should complete. The queued calls
1182 // should succeed immediately. 1171 // should succeed immediately.
1183 base::MessageLoop::current()->Run(); 1172 base::MessageLoop::current()->Run();
1184 1173
1185 EXPECT_EQ(4, success_callback_count_); 1174 EXPECT_EQ(4, success_callback_count_);
1186 EXPECT_EQ(0, error_callback_count_); 1175 EXPECT_EQ(0, error_callback_count_);
1187 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1176 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1188 EXPECT_TRUE(characteristic->IsNotifying()); 1177 EXPECT_TRUE(characteristic->IsNotifying());
1189 EXPECT_EQ(4U, update_sessions_.size()); 1178 EXPECT_EQ(4U, update_sessions_.size());
1190 1179
1191 for (int i = 0; i < 4; i++) 1180 for (int i = 0; i < 4; i++)
1192 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1181 EXPECT_TRUE(update_sessions_[0]->IsActive());
1193 1182
1194 // Stop notifications directly through the client. The sessions should get 1183 // Stop notifications directly through the client. The sessions should get
1195 // marked as inactive. 1184 // marked as inactive.
1196 fake_bluetooth_gatt_characteristic_client_->StopNotify( 1185 fake_bluetooth_gatt_characteristic_client_->StopNotify(
1197 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath(), 1186 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath(),
1198 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, 1187 base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
1199 base::Unretained(this)), 1188 base::Unretained(this)),
1200 base::Bind(&BluetoothGattChromeOSTest::DBusErrorCallback, 1189 base::Bind(&BluetoothGattBlueZTest::DBusErrorCallback,
1201 base::Unretained(this))); 1190 base::Unretained(this)));
1202 EXPECT_EQ(5, success_callback_count_); 1191 EXPECT_EQ(5, success_callback_count_);
1203 EXPECT_EQ(0, error_callback_count_); 1192 EXPECT_EQ(0, error_callback_count_);
1204 EXPECT_FALSE(characteristic->IsNotifying()); 1193 EXPECT_FALSE(characteristic->IsNotifying());
1205 EXPECT_EQ(4U, update_sessions_.size()); 1194 EXPECT_EQ(4U, update_sessions_.size());
1206 1195
1207 for (int i = 0; i < 4; i++) 1196 for (int i = 0; i < 4; i++)
1208 EXPECT_FALSE(update_sessions_[0]->IsActive()); 1197 EXPECT_FALSE(update_sessions_[0]->IsActive());
1209 1198
1210 // It should be possible to restart notifications and the call should reset 1199 // It should be possible to restart notifications and the call should reset
1211 // the session count and make a request through the client. 1200 // the session count and make a request through the client.
1212 update_sessions_.clear(); 1201 update_sessions_.clear();
1213 success_callback_count_ = 0; 1202 success_callback_count_ = 0;
1214 observer.Reset(); 1203 observer.Reset();
1215 characteristic->StartNotifySession( 1204 characteristic->StartNotifySession(
1216 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, 1205 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback,
1217 base::Unretained(this)), 1206 base::Unretained(this)),
1218 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, 1207 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1219 base::Unretained(this))); 1208 base::Unretained(this)));
1220 1209
1221 EXPECT_EQ(0, success_callback_count_); 1210 EXPECT_EQ(0, success_callback_count_);
1222 EXPECT_EQ(0, error_callback_count_); 1211 EXPECT_EQ(0, error_callback_count_);
1223 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1212 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1224 EXPECT_TRUE(characteristic->IsNotifying()); 1213 EXPECT_TRUE(characteristic->IsNotifying());
1225 EXPECT_TRUE(update_sessions_.empty()); 1214 EXPECT_TRUE(update_sessions_.empty());
1226 1215
1227 base::MessageLoop::current()->Run(); 1216 base::MessageLoop::current()->Run();
1228 1217
1229 EXPECT_EQ(1, success_callback_count_); 1218 EXPECT_EQ(1, success_callback_count_);
1230 EXPECT_EQ(0, error_callback_count_); 1219 EXPECT_EQ(0, error_callback_count_);
1231 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1220 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1232 EXPECT_TRUE(characteristic->IsNotifying()); 1221 EXPECT_TRUE(characteristic->IsNotifying());
1233 EXPECT_EQ(1U, update_sessions_.size()); 1222 EXPECT_EQ(1U, update_sessions_.size());
1234 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1223 EXPECT_TRUE(update_sessions_[0]->IsActive());
1235 } 1224 }
1236 1225
1237 } // namespace chromeos 1226 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_discovery_session_outcome.h ('k') | device/bluetooth/bluetooth_gatt_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698