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

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: 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) {
370 // This tests if the notifications on service discovered complete are invoked
371 // with the cached services and added to the GATT service map of |device|.
372 TestBluetoothAdapterObserver observer(adapter_);
373
374 // Create the device and pre-expose the fake Heart Rate service. This will
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(
397 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
398 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
399 BluetoothDevice* device =
400 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
401 ASSERT_TRUE(device);
402
403 EXPECT_EQ(0u, device->GetGattServices().size());
404 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
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 }
424
425 TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) { 437 TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) {
426 // Create a fake LE device. We store the device pointer here because this is a 438 // 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. 439 // test. It's unsafe to do this in production as the device might get deleted.
428 fake_bluetooth_device_client_->CreateDevice( 440 fake_bluetooth_device_client_->CreateDevice(
429 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 441 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
430 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 442 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
431 BluetoothDevice* device = 443 BluetoothDevice* device =
432 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 444 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
433 bluez::FakeBluetoothDeviceClient::Properties* properties = 445 bluez::FakeBluetoothDeviceClient::Properties* properties =
434 fake_bluetooth_device_client_->GetProperties( 446 fake_bluetooth_device_client_->GetProperties(
435 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 447 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
436 448
437 ASSERT_TRUE(device); 449 ASSERT_TRUE(device);
438 450
439 TestBluetoothAdapterObserver observer(adapter_); 451 TestBluetoothAdapterObserver observer(adapter_);
440 452
441 // Expose the fake Heart Rate Service. 453 // Expose the fake Heart Rate Service.
442 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 454 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
443 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 455 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
444 // Run the message loop so that the characteristics/descriptors appear. 456 // Run the message loop so that the characteristics/descriptors appear.
445 base::MessageLoop::current()->Run(); 457 base::MessageLoop::current()->Run();
458 properties->services_resolved.ReplaceValue(true);
459
446 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 460 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
447 EXPECT_EQ(1u, device->GetGattServices().size()); 461 EXPECT_EQ(1u, device->GetGattServices().size());
448 EXPECT_EQ(device, observer.last_device()); 462 EXPECT_EQ(device, observer.last_device());
449 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, 463 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
450 observer.last_device_address()); 464 observer.last_device_address());
451 465
452 // Disconnect from the device: 466 // Disconnect from the device:
453 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, 467 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
454 base::Unretained(this)), 468 base::Unretained(this)),
455 base::Bind(&BluetoothGattBlueZTest::ErrorCallback, 469 base::Bind(&BluetoothGattBlueZTest::ErrorCallback,
(...skipping 13 matching lines...) Expand all
469 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, 483 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
470 base::Unretained(this))); 484 base::Unretained(this)));
471 properties->connected.ReplaceValue(true); 485 properties->connected.ReplaceValue(true);
472 EXPECT_TRUE(device->IsConnected()); 486 EXPECT_TRUE(device->IsConnected());
473 487
474 // Verify that service discovery can be done again: 488 // Verify that service discovery can be done again:
475 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 489 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
476 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 490 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
477 // Run the message loop so that the characteristics/descriptors appear. 491 // Run the message loop so that the characteristics/descriptors appear.
478 base::MessageLoop::current()->Run(); 492 base::MessageLoop::current()->Run();
493 properties->services_resolved.ReplaceValue(true);
494
479 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 495 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
480 EXPECT_EQ(1u, device->GetGattServices().size()); 496 EXPECT_EQ(1u, device->GetGattServices().size());
481 } 497 }
482 498
483 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) { 499 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
484 fake_bluetooth_device_client_->CreateDevice( 500 fake_bluetooth_device_client_->CreateDevice(
485 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 501 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
486 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 502 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
487 BluetoothDevice* device = 503 BluetoothDevice* device =
488 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 504 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); 647 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count());
632 648
633 descriptor = characteristic->GetDescriptors()[0]; 649 descriptor = characteristic->GetDescriptors()[0];
634 EXPECT_EQ( 650 EXPECT_EQ(
635 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid(), 651 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid(),
636 descriptor->GetUUID()); 652 descriptor->GetUUID());
637 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); 653 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid());
638 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); 654 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id());
639 } 655 }
640 656
641 TEST_F(BluetoothGattBlueZTest, AdapterAddedAfterGattService) { 657 TEST_F(BluetoothGattBlueZTest, CachedServices) {
scheib 2016/07/01 00:40:53 I like this test coverage, but after this change i
ortuno 2016/07/01 15:51:48 I moved them after services discovered and changed
642 // This unit test tests that all remote GATT objects are created for D-Bus 658 // This unit test tests that all remote GATT objects are created for D-Bus
643 // objects that were already exposed. 659 // objects that were already exposed and all relevant events have been
660 // dispatched.
644 adapter_ = NULL; 661 adapter_ = NULL;
645 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting()); 662 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting());
646 663
647 // Create the fake D-Bus objects. 664 // Create the fake D-Bus objects.
648 fake_bluetooth_device_client_->CreateDevice( 665 fake_bluetooth_device_client_->CreateDevice(
649 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 666 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
650 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 667 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
668 bluez::FakeBluetoothDeviceClient::Properties* properties =
669 fake_bluetooth_device_client_->GetProperties(
670 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
671 properties->services_resolved.ReplaceValue(false);
672
651 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 673 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
652 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 674 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
653 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible()) 675 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
654 base::RunLoop().RunUntilIdle(); 676 base::RunLoop().RunUntilIdle();
655 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible()); 677 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
656 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible()); 678 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
657 679
658 // Create the adapter. This should create all the GATT objects. 680 // Create the adapter. This should create all the GATT objects.
659 GetAdapter(); 681 GetAdapter();
682 TestBluetoothAdapterObserver observer(adapter_);
683
684 // The device should exist but contain no cached services while the services
vudentz 2016/07/01 11:25:15 Should this be the other way around, we are suppos
ortuno 2016/07/01 15:51:48 We have no guarantee that the cached services are
685 // haven't been resolved.
660 BluetoothDevice* device = 686 BluetoothDevice* device =
661 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 687 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
662 ASSERT_TRUE(device);
663 EXPECT_EQ(1U, device->GetGattServices().size());
664 688
665 BluetoothRemoteGattService* service = device->GetGattServices()[0]; 689 EXPECT_TRUE(device->GetGattServices().empty());
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 690
675 BluetoothRemoteGattCharacteristic* characteristic = 691 EXPECT_EQ(0, observer.gatt_services_discovered_count());
676 service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ 692 EXPECT_EQ(0, observer.gatt_service_added_count());
677 ->GetBodySensorLocationPath() 693 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
678 .value()); 694 EXPECT_EQ(0, observer.gatt_characteristic_added_count());
679 ASSERT_TRUE(characteristic); 695 EXPECT_EQ(0, observer.gatt_descriptor_added_count());
680 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient::
681 kBodySensorLocationUUID),
682 characteristic->GetUUID());
683 EXPECT_TRUE(characteristic->GetDescriptors().empty());
684 696
685 characteristic = service->GetCharacteristic( 697 properties->services_resolved.ReplaceValue(true);
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 698
694 characteristic = service->GetCharacteristic( 699 EXPECT_EQ(1, observer.gatt_services_discovered_count());
695 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() 700 EXPECT_EQ(1, observer.gatt_service_added_count());
696 .value()); 701 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
697 ASSERT_TRUE(characteristic); 702 EXPECT_EQ(3, observer.gatt_characteristic_added_count());
698 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: 703 EXPECT_EQ(1, observer.gatt_descriptor_added_count());
699 kHeartRateMeasurementUUID),
700 characteristic->GetUUID());
701 EXPECT_EQ(1U, characteristic->GetDescriptors().size());
702 704
703 BluetoothRemoteGattDescriptor* descriptor = 705 HeartRateServiceShouldBeComplete(device);
704 characteristic->GetDescriptors()[0]; 706 }
705 ASSERT_TRUE(descriptor); 707
706 EXPECT_EQ( 708 TEST_F(BluetoothGattBlueZTest, NewServices) {
707 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid(), 709 // This unit test tests that all remote GATT Objects are created for D-Bus
708 descriptor->GetUUID()); 710 // objects that are newly exposed.
711 TestBluetoothAdapterObserver observer(adapter_);
712
713 // Create the fake D-Bus objects.
714 fake_bluetooth_device_client_->CreateDevice(
715 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
716 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
717 bluez::FakeBluetoothDeviceClient::Properties* properties =
718 fake_bluetooth_device_client_->GetProperties(
719 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
720
721 properties->services_resolved.ReplaceValue(false);
722 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
723 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
724 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
725 base::RunLoop().RunUntilIdle();
726 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
727 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
728
729 // The device should exist and contain new services even though the services
730 // haven't been resolved.
731 BluetoothDevice* device =
732 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
733 EXPECT_EQ(1u, device->GetGattServices().size());
734 HeartRateServiceShouldBeComplete(device);
735
736 EXPECT_EQ(0, observer.gatt_services_discovered_count());
737 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
738 // The rest of the events are tested in the corresponding
739 // {GATTObject}AddedAndRemoved tests.
740
741 properties->services_resolved.ReplaceValue(true);
742
743 EXPECT_EQ(1, observer.gatt_services_discovered_count());
744 EXPECT_EQ(1, observer.gatt_discovery_complete_count());
745 }
746
747 TEST_F(BluetoothGattBlueZTest, CachedAndNewServices) {
748 // This unit test tests that all remote GATT objects are created for D-Bus
749 // objects that were already exposed and for new GATT Objects.
750 adapter_ = NULL;
751 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting());
752
753 // Create the fake D-Bus objects.
754 fake_bluetooth_device_client_->CreateDevice(
755 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
756 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
757 bluez::FakeBluetoothDeviceClient::Properties* properties =
758 fake_bluetooth_device_client_->GetProperties(
759 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
760 properties->services_resolved.ReplaceValue(false);
761
762 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
763 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
764 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
765 base::RunLoop().RunUntilIdle();
766 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());
767 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible());
768
769 // Create the adapter. This should create all the GATT objects.
770 GetAdapter();
771 TestBluetoothAdapterObserver observer(adapter_);
772
773 // The device should exist but contain no cached services while the services
774 // haven't been resolved.
775 BluetoothDevice* device =
776 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
777
778 EXPECT_EQ(0, observer.gatt_services_discovered_count());
779 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
780 EXPECT_TRUE(device->GetGattServices().empty());
781
782 fake_bluetooth_gatt_service_client_->ExposeBatteryService(
783 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
784 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsBatteryServiceVisible());
785
786 EXPECT_EQ(0, observer.gatt_services_discovered_count());
787 EXPECT_EQ(0, observer.gatt_discovery_complete_count());
788 EXPECT_EQ(1u, device->GetGattServices().size());
789
790 // A newly added service should be complete even if services haven't been
791 // resolved.
792 BatteryServiceShouldBeComplete(device);
793
794 properties->services_resolved.ReplaceValue(true);
795
796 EXPECT_EQ(1, observer.gatt_services_discovered_count());
797 EXPECT_EQ(2, observer.gatt_discovery_complete_count());
798 EXPECT_EQ(2u, device->GetGattServices().size());
799
800 // Now that services have been resolved both services should be present.
801 HeartRateServiceShouldBeComplete(device);
802 BatteryServiceShouldBeComplete(device);
709 } 803 }
710 804
711 TEST_F(BluetoothGattBlueZTest, GattCharacteristicValue) { 805 TEST_F(BluetoothGattBlueZTest, GattCharacteristicValue) {
712 fake_bluetooth_device_client_->CreateDevice( 806 fake_bluetooth_device_client_->CreateDevice(
713 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 807 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
714 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 808 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
715 BluetoothDevice* device = 809 BluetoothDevice* device =
716 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 810 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
717 ASSERT_TRUE(device); 811 ASSERT_TRUE(device);
718 812
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 1446
1353 EXPECT_EQ(1, success_callback_count_); 1447 EXPECT_EQ(1, success_callback_count_);
1354 EXPECT_EQ(0, error_callback_count_); 1448 EXPECT_EQ(0, error_callback_count_);
1355 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1449 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1356 EXPECT_TRUE(characteristic->IsNotifying()); 1450 EXPECT_TRUE(characteristic->IsNotifying());
1357 EXPECT_EQ(1U, update_sessions_.size()); 1451 EXPECT_EQ(1U, update_sessions_.size());
1358 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1452 EXPECT_TRUE(update_sessions_[0]->IsActive());
1359 } 1453 }
1360 1454
1361 } // namespace bluez 1455 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698