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

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

Issue 1979633004: Invoke GattDiscoveryCompleteForService by observing ServicesResolved property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_attr
Patch Set: Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), 318 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
319 observer.last_gatt_service_uuid()); 319 observer.last_gatt_service_uuid());
320 320
321 EXPECT_EQ(NULL, device->GetGattService(observer.last_gatt_service_id())); 321 EXPECT_EQ(NULL, device->GetGattService(observer.last_gatt_service_id()));
322 322
323 // Expose the service again. 323 // Expose the service again.
324 observer.last_gatt_service_uuid() = BluetoothUUID(); 324 observer.last_gatt_service_uuid() = BluetoothUUID();
325 observer.last_gatt_service_id().clear(); 325 observer.last_gatt_service_id().clear();
326 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 326 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
327 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 327 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
328
328 EXPECT_EQ(2, observer.gatt_service_added_count()); 329 EXPECT_EQ(2, observer.gatt_service_added_count());
329 EXPECT_EQ(1, observer.gatt_service_removed_count()); 330 EXPECT_EQ(1, observer.gatt_service_removed_count());
330 EXPECT_FALSE(observer.last_gatt_service_id().empty()); 331 EXPECT_FALSE(observer.last_gatt_service_id().empty());
331 EXPECT_EQ(1U, device->GetGattServices().size()); 332 EXPECT_EQ(1U, device->GetGattServices().size());
332 EXPECT_EQ(BluetoothUUID( 333 EXPECT_EQ(BluetoothUUID(
333 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), 334 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
334 observer.last_gatt_service_uuid()); 335 observer.last_gatt_service_uuid());
335 336
336 // The object |service| points to should have been deallocated. |device| 337 // The object |service| points to should have been deallocated. |device|
337 // should contain a brand new instance. 338 // should contain a brand new instance.
(...skipping 14 matching lines...) Expand all
352 EXPECT_EQ(2, observer.gatt_service_added_count()); 353 EXPECT_EQ(2, observer.gatt_service_added_count());
353 EXPECT_EQ(2, observer.gatt_service_removed_count()); 354 EXPECT_EQ(2, observer.gatt_service_removed_count());
354 EXPECT_FALSE(observer.last_gatt_service_id().empty()); 355 EXPECT_FALSE(observer.last_gatt_service_id().empty());
355 EXPECT_EQ(BluetoothUUID( 356 EXPECT_EQ(BluetoothUUID(
356 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), 357 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
357 observer.last_gatt_service_uuid()); 358 observer.last_gatt_service_uuid());
358 EXPECT_EQ(NULL, adapter_->GetDevice( 359 EXPECT_EQ(NULL, adapter_->GetDevice(
359 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress)); 360 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress));
360 } 361 }
361 362
363 TEST_F(BluetoothGattBlueZTest, DiscoveryCompleteForCachedGattService) {
364 // This tests if the notifications on service discovered complete are invoked
365 // with the cached services and added to the GATT service map of |device|.
366 TestBluetoothAdapterObserver observer(adapter_);
367
368 // Create the device and pre-expose the fake Heart Rate service. This will
369 // synchronously expose characteristics.
370 fake_bluetooth_device_client_->CreateDevice(
371 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
372 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kCachedLowEnergyPath));
373 BluetoothDevice* device =
374 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
375 ASSERT_TRUE(device);
376
377 device::BluetoothRemoteGattService* service = device->GetGattServices()[0];
378 EXPECT_EQ(1u, device->GetGattServices().size());
379 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
380 EXPECT_EQ(device, service->GetDevice());
381 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
382 EXPECT_EQ(3U, service->GetCharacteristics().size());
383 }
384
385 TEST_F(BluetoothGattBlueZTest, DiscoveryCompleteForNewGattService) {
386 TestBluetoothAdapterObserver observer(adapter_);
387
388 // This tests the discovery complete notification on a newly-added GATT
389 // service.
390 fake_bluetooth_device_client_->CreateDevice(
391 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
392 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
393 BluetoothDevice* device =
394 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
395 ASSERT_TRUE(device);
396
397 EXPECT_EQ(0u, device->GetGattServices().size());
398 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
399
400 // Expose the fake Heart Rate service. This will asynchronously expose
401 // characteristics.
402 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
403 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
404
405 // Run the message loop so that the characteristics/descriptors appear.
406 base::MessageLoop::current()->Run();
407
408 // The discovery completed event of a newly-added GATT service should not be
409 // fired until ServicesResolved property becomes true. And the new service
410 // will be added immediately to the GATT service map of |device|.
411 BluetoothRemoteGattService* service = device->GetGattServices()[0];
412 EXPECT_EQ(1u, device->GetGattServices().size());
413 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
414 EXPECT_EQ(device, service->GetDevice());
415 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
416 EXPECT_EQ(3U, service->GetCharacteristics().size());
417 }
418
362 TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) { 419 TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) {
363 // Create a fake LE device. We store the device pointer here because this is a 420 // Create a fake LE device. We store the device pointer here because this is a
364 // test. It's unsafe to do this in production as the device might get deleted. 421 // test. It's unsafe to do this in production as the device might get deleted.
365 fake_bluetooth_device_client_->CreateDevice( 422 fake_bluetooth_device_client_->CreateDevice(
366 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 423 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
367 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 424 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
368 BluetoothDevice* device = 425 BluetoothDevice* device =
369 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 426 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
370 bluez::FakeBluetoothDeviceClient::Properties* properties = 427 bluez::FakeBluetoothDeviceClient::Properties* properties =
371 fake_bluetooth_device_client_->GetProperties( 428 fake_bluetooth_device_client_->GetProperties(
372 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 429 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
373 430
374 ASSERT_TRUE(device); 431 ASSERT_TRUE(device);
375 432
376 TestBluetoothAdapterObserver observer(adapter_); 433 TestBluetoothAdapterObserver observer(adapter_);
377 434
378 // Expose the fake Heart Rate Service. 435 // Expose the fake Heart Rate Service.
379 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 436 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
380 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 437 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
381 // Notify that all services have been discovered. 438 // Run the message loop so that the characteristics/descriptors appear.
382 properties->services_resolved.ReplaceValue(true); 439 base::MessageLoop::current()->Run();
383
384 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 440 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
385 EXPECT_EQ(1u, device->GetGattServices().size()); 441 EXPECT_EQ(1u, device->GetGattServices().size());
386 EXPECT_EQ(device, observer.last_device()); 442 EXPECT_EQ(device, observer.last_device());
387 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, 443 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
388 observer.last_device_address()); 444 observer.last_device_address());
389 445
390 // Disconnect from the device: 446 // Disconnect from the device:
391 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, 447 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
392 base::Unretained(this)), 448 base::Unretained(this)),
393 base::Bind(&BluetoothGattBlueZTest::ErrorCallback, 449 base::Bind(&BluetoothGattBlueZTest::ErrorCallback,
(...skipping 11 matching lines...) Expand all
405 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback, 461 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback,
406 base::Unretained(this)), 462 base::Unretained(this)),
407 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, 463 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
408 base::Unretained(this))); 464 base::Unretained(this)));
409 properties->connected.ReplaceValue(true); 465 properties->connected.ReplaceValue(true);
410 EXPECT_TRUE(device->IsConnected()); 466 EXPECT_TRUE(device->IsConnected());
411 467
412 // Verify that service discovery can be done again: 468 // Verify that service discovery can be done again:
413 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 469 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
414 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 470 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
415 properties->services_resolved.ReplaceValue(true); 471 // Run the message loop so that the characteristics/descriptors appear.
472 base::MessageLoop::current()->Run();
416 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 473 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
417 EXPECT_EQ(1u, device->GetGattServices().size()); 474 EXPECT_EQ(1u, device->GetGattServices().size());
418 } 475 }
419 476
420 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) { 477 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
421 fake_bluetooth_device_client_->CreateDevice( 478 fake_bluetooth_device_client_->CreateDevice(
422 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 479 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
423 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 480 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
424 BluetoothDevice* device = 481 BluetoothDevice* device =
425 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 482 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1346
1290 EXPECT_EQ(1, success_callback_count_); 1347 EXPECT_EQ(1, success_callback_count_);
1291 EXPECT_EQ(0, error_callback_count_); 1348 EXPECT_EQ(0, error_callback_count_);
1292 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1349 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1293 EXPECT_TRUE(characteristic->IsNotifying()); 1350 EXPECT_TRUE(characteristic->IsNotifying());
1294 EXPECT_EQ(1U, update_sessions_.size()); 1351 EXPECT_EQ(1U, update_sessions_.size());
1295 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1352 EXPECT_TRUE(update_sessions_[0]->IsActive());
1296 } 1353 }
1297 1354
1298 } // namespace bluez 1355 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluez/bluetooth_device_bluez.cc ('k') | device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698