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

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

Issue 2105423003: bluetooth: Update the map of GATT services when services resolve (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address luiz's comments Created 4 years, 5 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 void GetAdapter() { 123 void GetAdapter() {
124 device::BluetoothAdapterFactory::GetAdapter(base::Bind( 124 device::BluetoothAdapterFactory::GetAdapter(base::Bind(
125 &BluetoothGattBlueZTest::AdapterCallback, base::Unretained(this))); 125 &BluetoothGattBlueZTest::AdapterCallback, base::Unretained(this)));
126 base::MessageLoop::current()->Run(); 126 base::MessageLoop::current()->Run();
127 ASSERT_TRUE(adapter_.get() != NULL); 127 ASSERT_TRUE(adapter_.get() != NULL);
128 ASSERT_TRUE(adapter_->IsInitialized()); 128 ASSERT_TRUE(adapter_->IsInitialized());
129 ASSERT_TRUE(adapter_->IsPresent()); 129 ASSERT_TRUE(adapter_->IsPresent());
130 } 130 }
131 131
132 void BatteryServiceShouldBeComplete(BluetoothDevice* device) {
133 ASSERT_TRUE(device);
134 ASSERT_GE(device->GetGattServices().size(), 1u);
135
136 BluetoothRemoteGattService* service = device->GetGattService(
137 fake_bluetooth_gatt_service_client_->GetBatteryServicePath().value());
138
139 ASSERT_TRUE(service);
140 EXPECT_TRUE(service->IsPrimary());
141 EXPECT_EQ(BluetoothUUID(
142 bluez::FakeBluetoothGattServiceClient::kBatteryServiceUUID),
143 service->GetUUID());
144 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
145 }
146
147 void HeartRateServiceShouldBeComplete(BluetoothDevice* device) {
148 ASSERT_TRUE(device);
149 ASSERT_GE(device->GetGattServices().size(), 1u);
150
151 BluetoothRemoteGattService* service = device->GetGattService(
152 fake_bluetooth_gatt_service_client_->GetHeartRateServicePath().value());
153
154 ASSERT_TRUE(service);
155 EXPECT_TRUE(service->IsPrimary());
156 EXPECT_EQ(BluetoothUUID(
157 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
158 service->GetUUID());
159 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
160 EXPECT_EQ(3U, service->GetCharacteristics().size());
161
162 BluetoothRemoteGattCharacteristic* characteristic =
163 service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_
164 ->GetBodySensorLocationPath()
165 .value());
166 ASSERT_TRUE(characteristic);
167 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
168 kBodySensorLocationUUID),
169 characteristic->GetUUID());
170 EXPECT_TRUE(characteristic->GetDescriptors().empty());
171
172 characteristic =
173 service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_
174 ->GetHeartRateControlPointPath()
175 .value());
176 ASSERT_TRUE(characteristic);
177 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
178 kHeartRateControlPointUUID),
179 characteristic->GetUUID());
180 EXPECT_TRUE(characteristic->GetDescriptors().empty());
181
182 characteristic =
183 service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_
184 ->GetHeartRateMeasurementPath()
185 .value());
186 ASSERT_TRUE(characteristic);
187 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
188 kHeartRateMeasurementUUID),
189 characteristic->GetUUID());
190
191 ASSERT_EQ(1u, characteristic->GetDescriptors().size());
192
193 BluetoothRemoteGattDescriptor* descriptor =
194 characteristic->GetDescriptors()[0];
195 EXPECT_EQ(
196 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid(),
197 descriptor->GetUUID());
198 }
199
132 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { 200 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) {
133 adapter_ = adapter; 201 adapter_ = adapter;
134 if (base::MessageLoop::current() && 202 if (base::MessageLoop::current() &&
135 base::MessageLoop::current()->is_running()) { 203 base::MessageLoop::current()->is_running()) {
136 base::MessageLoop::current()->QuitWhenIdle(); 204 base::MessageLoop::current()->QuitWhenIdle();
137 } 205 }
138 } 206 }
139 207
140 void SuccessCallback() { ++success_callback_count_; } 208 void SuccessCallback() { ++success_callback_count_; }
141 209
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 EXPECT_EQ(2, observer.gatt_service_added_count()); 427 EXPECT_EQ(2, observer.gatt_service_added_count());
360 EXPECT_EQ(2, observer.gatt_service_removed_count()); 428 EXPECT_EQ(2, observer.gatt_service_removed_count());
361 EXPECT_FALSE(observer.last_gatt_service_id().empty()); 429 EXPECT_FALSE(observer.last_gatt_service_id().empty());
362 EXPECT_EQ(BluetoothUUID( 430 EXPECT_EQ(BluetoothUUID(
363 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), 431 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
364 observer.last_gatt_service_uuid()); 432 observer.last_gatt_service_uuid());
365 EXPECT_EQ(NULL, adapter_->GetDevice( 433 EXPECT_EQ(NULL, adapter_->GetDevice(
366 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress)); 434 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress));
367 } 435 }
368 436
369 TEST_F(BluetoothGattBlueZTest, DiscoveryCompleteForCachedGattService) { 437 TEST_F(BluetoothGattBlueZTest, ServicesDiscoveredBeforeAdapterIsCreated) {
370 // This tests if the notifications on service discovered complete are invoked 438 // Tests that all GATT objects are created for a device whose D-Bus objects
371 // with the cached services and added to the GATT service map of |device|. 439 // were already exposed and for which services have been resolved.
372 TestBluetoothAdapterObserver observer(adapter_); 440 adapter_ = NULL;
441 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting());
373 442
374 // Create the device and pre-expose the fake Heart Rate service. This will 443 // Create the fake D-Bus objects.
375 // synchronously expose characteristics.
376 fake_bluetooth_device_client_->CreateDevice(
377 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
378 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kCachedLowEnergyPath));
379 BluetoothDevice* device =
380 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
381 ASSERT_TRUE(device);
382
383 device::BluetoothRemoteGattService* service = device->GetGattServices()[0];
384 EXPECT_EQ(1u, device->GetGattServices().size());
385 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
386 EXPECT_EQ(device, service->GetDevice());
387 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
388 EXPECT_EQ(3U, service->GetCharacteristics().size());
389 }
390
391 TEST_F(BluetoothGattBlueZTest, DiscoveryCompleteForNewGattService) {
392 TestBluetoothAdapterObserver observer(adapter_);
393
394 // This tests the discovery complete notification on a newly-added GATT
395 // service.
396 fake_bluetooth_device_client_->CreateDevice( 444 fake_bluetooth_device_client_->CreateDevice(
397 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 445 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
398 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 446 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
447 bluez::FakeBluetoothDeviceClient::Properties* properties =
448 fake_bluetooth_device_client_->GetProperties(
449 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
450
451 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
452 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
453 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
454 base::RunLoop().RunUntilIdle();
455 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
456 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
457
458 properties->services_resolved.ReplaceValue(true);
459
460 // Create the adapter. This should create all the GATT objects.
461 GetAdapter();
462
399 BluetoothDevice* device = 463 BluetoothDevice* device =
400 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 464 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
401 ASSERT_TRUE(device);
402 465
403 EXPECT_EQ(0u, device->GetGattServices().size()); 466 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
404 EXPECT_EQ(0, observer.gatt_discovery_complete_count()); 467 HeartRateServiceShouldBeComplete(device);
405
406 // Expose the fake Heart Rate service. This will asynchronously expose
407 // characteristics.
408 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
409 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
410
411 // Run the message loop so that the characteristics/descriptors appear.
412 base::MessageLoop::current()->Run();
413
414 // The discovery completed event of a newly-added GATT service should not be
415 // fired until ServicesResolved property becomes true. And the new service
416 // will be added immediately to the GATT service map of |device|.
417 BluetoothRemoteGattService* service = device->GetGattServices()[0];
418 EXPECT_EQ(1u, device->GetGattServices().size());
419 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
420 EXPECT_EQ(device, service->GetDevice());
421 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
422 EXPECT_EQ(3U, service->GetCharacteristics().size());
423 } 468 }
424 469
425 TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) { 470 TEST_F(BluetoothGattBlueZTest, ServicesDiscoveredAfterAdapterIsCreated) {
426 // Create a fake LE device. We store the device pointer here because this is a 471 // Create a fake LE device. We store the device pointer here because this is a
427 // test. It's unsafe to do this in production as the device might get deleted. 472 // test. It's unsafe to do this in production as the device might get deleted.
428 fake_bluetooth_device_client_->CreateDevice( 473 fake_bluetooth_device_client_->CreateDevice(
429 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 474 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
430 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 475 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
431 BluetoothDevice* device = 476 BluetoothDevice* device =
432 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 477 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
433 bluez::FakeBluetoothDeviceClient::Properties* properties = 478 bluez::FakeBluetoothDeviceClient::Properties* properties =
434 fake_bluetooth_device_client_->GetProperties( 479 fake_bluetooth_device_client_->GetProperties(
435 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 480 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
436 481
437 ASSERT_TRUE(device); 482 ASSERT_TRUE(device);
438 483
439 TestBluetoothAdapterObserver observer(adapter_); 484 TestBluetoothAdapterObserver observer(adapter_);
440 485
441 // Expose the fake Heart Rate Service. 486 // Expose the fake Heart Rate Service.
442 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 487 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
443 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 488 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
444 // Run the message loop so that the characteristics/descriptors appear. 489 // Run the message loop so that the characteristics/descriptors appear.
445 base::MessageLoop::current()->Run(); 490 base::MessageLoop::current()->Run();
491 properties->services_resolved.ReplaceValue(true);
492
446 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 493 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
447 EXPECT_EQ(1u, device->GetGattServices().size()); 494 EXPECT_EQ(1u, device->GetGattServices().size());
448 EXPECT_EQ(device, observer.last_device()); 495 EXPECT_EQ(device, observer.last_device());
449 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, 496 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
450 observer.last_device_address()); 497 observer.last_device_address());
451 498
452 // Disconnect from the device: 499 // Disconnect from the device:
453 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, 500 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
454 base::Unretained(this)), 501 base::Unretained(this)),
455 base::Bind(&BluetoothGattBlueZTest::ErrorCallback, 502 base::Bind(&BluetoothGattBlueZTest::ErrorCallback,
(...skipping 13 matching lines...) Expand all
469 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, 516 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
470 base::Unretained(this))); 517 base::Unretained(this)));
471 properties->connected.ReplaceValue(true); 518 properties->connected.ReplaceValue(true);
472 EXPECT_TRUE(device->IsConnected()); 519 EXPECT_TRUE(device->IsConnected());
473 520
474 // Verify that service discovery can be done again: 521 // Verify that service discovery can be done again:
475 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 522 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
476 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 523 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
477 // Run the message loop so that the characteristics/descriptors appear. 524 // Run the message loop so that the characteristics/descriptors appear.
478 base::MessageLoop::current()->Run(); 525 base::MessageLoop::current()->Run();
526 properties->services_resolved.ReplaceValue(true);
527
479 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 528 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
480 EXPECT_EQ(1u, device->GetGattServices().size()); 529 EXPECT_EQ(1u, device->GetGattServices().size());
481 } 530 }
482 531
532 TEST_F(BluetoothGattBlueZTest, DiscoverCachedServices) {
533 // This unit test tests that all remote GATT objects are created for D-Bus
534 // objects that were already exposed and all relevant events have been
535 // dispatched.
536 adapter_ = NULL;
537 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting());
538
539 // Create the fake D-Bus objects.
540 fake_bluetooth_device_client_->CreateDevice(
541 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
542 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
543 bluez::FakeBluetoothDeviceClient::Properties* properties =
544 fake_bluetooth_device_client_->GetProperties(
545 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
546 properties->services_resolved.ReplaceValue(false);
547
548 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
549 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
550 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
551 base::RunLoop().RunUntilIdle();
552 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
553 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
554
555 // Create the adapter. This should create all the GATT objects.
556 GetAdapter();
557 TestBluetoothAdapterObserver observer(adapter_);
558
559 // The device should exist but contain no cached services while the services
560 // haven't been resolved.
561 BluetoothDevice* device =
562 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
563
564 EXPECT_TRUE(device->GetGattServices().empty());
565
566 EXPECT_EQ(0, observer.gatt_services_discovered_count());
567 EXPECT_EQ(0, observer.gatt_service_added_count());
568 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
569 EXPECT_EQ(0, observer.gatt_characteristic_added_count());
570 EXPECT_EQ(0, observer.gatt_descriptor_added_count());
571
572 properties->services_resolved.ReplaceValue(true);
573
574 EXPECT_EQ(1, observer.gatt_services_discovered_count());
575 EXPECT_EQ(1, observer.gatt_service_added_count());
576 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
577 EXPECT_EQ(3, observer.gatt_characteristic_added_count());
578 EXPECT_EQ(1, observer.gatt_descriptor_added_count());
579
580 HeartRateServiceShouldBeComplete(device);
581 }
582
583 TEST_F(BluetoothGattBlueZTest, DiscoverNewServices) {
584 // This unit test tests that all remote GATT Objects are created for D-Bus
585 // objects that are newly exposed.
586 TestBluetoothAdapterObserver observer(adapter_);
587
588 // Create the fake D-Bus objects.
589 fake_bluetooth_device_client_->CreateDevice(
590 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
591 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
592 bluez::FakeBluetoothDeviceClient::Properties* properties =
593 fake_bluetooth_device_client_->GetProperties(
594 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
595
596 properties->services_resolved.ReplaceValue(false);
597 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
598 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
599 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
600 base::RunLoop().RunUntilIdle();
601 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
602 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
603
604 // The device should exist and contain new services even though the services
605 // haven't been resolved.
606 BluetoothDevice* device =
607 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
608 EXPECT_EQ(1u, device->GetGattServices().size());
609 HeartRateServiceShouldBeComplete(device);
610
611 EXPECT_EQ(0, observer.gatt_services_discovered_count());
612 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
613 // The rest of the events are tested in the corresponding
614 // {GATTObject}AddedAndRemoved tests.
615
616 properties->services_resolved.ReplaceValue(true);
617
618 EXPECT_EQ(1, observer.gatt_services_discovered_count());
619 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
620 }
621
622 TEST_F(BluetoothGattBlueZTest, DiscoverCachedAndNewServices) {
623 // This unit test tests that all remote GATT objects are created for D-Bus
624 // objects that were already exposed and for new GATT Objects.
625 adapter_ = NULL;
626 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting());
627
628 // Create the fake D-Bus objects.
629 fake_bluetooth_device_client_->CreateDevice(
630 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
631 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
632 bluez::FakeBluetoothDeviceClient::Properties* properties =
633 fake_bluetooth_device_client_->GetProperties(
634 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
635 properties->services_resolved.ReplaceValue(false);
636
637 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
638 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
639 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
640 base::RunLoop().RunUntilIdle();
641 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
642 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
643
644 // Create the adapter. This should create all the GATT objects.
645 GetAdapter();
646 TestBluetoothAdapterObserver observer(adapter_);
647
648 // The device should exist but contain no cached services while the services
649 // haven't been resolved.
650 BluetoothDevice* device =
651 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
652
653 EXPECT_EQ(0, observer.gatt_services_discovered_count());
654 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
655 EXPECT_TRUE(device->GetGattServices().empty());
656
657 fake_bluetooth_gatt_service_client_->ExposeBatteryService(
658 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
659 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsBatteryServiceVisible());
660
661 EXPECT_EQ(0, observer.gatt_services_discovered_count());
662 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
663 EXPECT_EQ(1u, device->GetGattServices().size());
664
665 // A newly added service should be complete even if services haven't been
666 // resolved.
667 BatteryServiceShouldBeComplete(device);
668
669 properties->services_resolved.ReplaceValue(true);
670
671 EXPECT_EQ(1, observer.gatt_services_discovered_count());
672 EXPECT_EQ(2, observer.gatt_discovery_complete_count());
673 EXPECT_EQ(2u, device->GetGattServices().size());
674
675 // Now that services have been resolved both services should be present.
676 HeartRateServiceShouldBeComplete(device);
677 BatteryServiceShouldBeComplete(device);
678 }
679
483 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) { 680 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
484 fake_bluetooth_device_client_->CreateDevice( 681 fake_bluetooth_device_client_->CreateDevice(
485 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 682 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
486 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 683 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
487 BluetoothDevice* device = 684 BluetoothDevice* device =
488 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 685 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
489 ASSERT_TRUE(device); 686 ASSERT_TRUE(device);
490 687
491 TestBluetoothAdapterObserver observer(adapter_); 688 TestBluetoothAdapterObserver observer(adapter_);
492 689
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); 828 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count());
632 829
633 descriptor = characteristic->GetDescriptors()[0]; 830 descriptor = characteristic->GetDescriptors()[0];
634 EXPECT_EQ( 831 EXPECT_EQ(
635 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid(), 832 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid(),
636 descriptor->GetUUID()); 833 descriptor->GetUUID());
637 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); 834 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid());
638 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); 835 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id());
639 } 836 }
640 837
641 TEST_F(BluetoothGattBlueZTest, AdapterAddedAfterGattService) {
642 // This unit test tests that all remote GATT objects are created for D-Bus
643 // objects that were already exposed.
644 adapter_ = NULL;
645 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting());
646
647 // Create the fake D-Bus objects.
648 fake_bluetooth_device_client_->CreateDevice(
649 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
650 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
651 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
652 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
653 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
654 base::RunLoop().RunUntilIdle();
655 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
656 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
657
658 // Create the adapter. This should create all the GATT objects.
659 GetAdapter();
660 BluetoothDevice* device =
661 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
662 ASSERT_TRUE(device);
663 EXPECT_EQ(1U, device->GetGattServices().size());
664
665 BluetoothRemoteGattService* service = device->GetGattServices()[0];
666 ASSERT_TRUE(service);
667 EXPECT_TRUE(service->IsPrimary());
668 EXPECT_EQ(BluetoothUUID(
669 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
670 service->GetUUID());
671 EXPECT_EQ(service, device->GetGattServices()[0]);
672 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier()));
673 EXPECT_EQ(3U, service->GetCharacteristics().size());
674
675 BluetoothRemoteGattCharacteristic* characteristic =
676 service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_
677 ->GetBodySensorLocationPath()
678 .value());
679 ASSERT_TRUE(characteristic);
680 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
681 kBodySensorLocationUUID),
682 characteristic->GetUUID());
683 EXPECT_TRUE(characteristic->GetDescriptors().empty());
684
685 characteristic = service->GetCharacteristic(
686 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath()
687 .value());
688 ASSERT_TRUE(characteristic);
689 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
690 kHeartRateControlPointUUID),
691 characteristic->GetUUID());
692 EXPECT_TRUE(characteristic->GetDescriptors().empty());
693
694 characteristic = service->GetCharacteristic(
695 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
696 .value());
697 ASSERT_TRUE(characteristic);
698 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
699 kHeartRateMeasurementUUID),
700 characteristic->GetUUID());
701 EXPECT_EQ(1U, characteristic->GetDescriptors().size());
702
703 BluetoothRemoteGattDescriptor* descriptor =
704 characteristic->GetDescriptors()[0];
705 ASSERT_TRUE(descriptor);
706 EXPECT_EQ(
707 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid(),
708 descriptor->GetUUID());
709 }
710
711 TEST_F(BluetoothGattBlueZTest, GattCharacteristicValue) { 838 TEST_F(BluetoothGattBlueZTest, GattCharacteristicValue) {
712 fake_bluetooth_device_client_->CreateDevice( 839 fake_bluetooth_device_client_->CreateDevice(
713 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 840 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
714 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 841 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
715 BluetoothDevice* device = 842 BluetoothDevice* device =
716 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 843 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
717 ASSERT_TRUE(device); 844 ASSERT_TRUE(device);
718 845
719 TestBluetoothAdapterObserver observer(adapter_); 846 TestBluetoothAdapterObserver observer(adapter_);
720 847
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 1479
1353 EXPECT_EQ(1, success_callback_count_); 1480 EXPECT_EQ(1, success_callback_count_);
1354 EXPECT_EQ(0, error_callback_count_); 1481 EXPECT_EQ(0, error_callback_count_);
1355 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1482 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1356 EXPECT_TRUE(characteristic->IsNotifying()); 1483 EXPECT_TRUE(characteristic->IsNotifying());
1357 EXPECT_EQ(1U, update_sessions_.size()); 1484 EXPECT_EQ(1U, update_sessions_.size());
1358 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1485 EXPECT_TRUE(update_sessions_[0]->IsActive());
1359 } 1486 }
1360 1487
1361 } // namespace bluez 1488 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698