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

Unified 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: Invoke GattDiscoveryCompleteForService for each GATT service once 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
diff --git a/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc b/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
index ce7087eac54dbcbd2531be33b5e3c23f228bd4ac..05c9213bda28f90c96b2402812d3c76d6ab00f1b 100644
--- a/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
+++ b/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
@@ -276,12 +276,17 @@ TEST_F(BluetoothGattBlueZTest, GattServiceAddedAndRemoved) {
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
BluetoothDevice* device =
adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
+ bluez::FakeBluetoothDeviceClient::Properties* properties =
+ fake_bluetooth_device_client_->GetProperties(
+ dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
ASSERT_TRUE(device);
TestBluetoothAdapterObserver observer(adapter_);
EXPECT_EQ(0, observer.gatt_service_added_count());
EXPECT_EQ(0, observer.gatt_service_removed_count());
+ EXPECT_EQ(0, observer.gatt_discovery_complete_count());
+ EXPECT_TRUE(device->GetGattServices().empty());
EXPECT_TRUE(observer.last_gatt_service_id().empty());
EXPECT_FALSE(observer.last_gatt_service_uuid().IsValid());
EXPECT_TRUE(device->GetGattServices().empty());
@@ -289,8 +294,11 @@ TEST_F(BluetoothGattBlueZTest, GattServiceAddedAndRemoved) {
// Expose the fake Heart Rate Service.
fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
+ // Notify that all services have been discovered.
+ properties->services_resolved.ReplaceValue(true);
EXPECT_EQ(1, observer.gatt_service_added_count());
EXPECT_EQ(0, observer.gatt_service_removed_count());
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count());
EXPECT_FALSE(observer.last_gatt_service_id().empty());
EXPECT_EQ(1U, device->GetGattServices().size());
EXPECT_EQ(BluetoothUUID(
@@ -312,6 +320,7 @@ TEST_F(BluetoothGattBlueZTest, GattServiceAddedAndRemoved) {
EXPECT_EQ(1, observer.gatt_service_added_count());
EXPECT_EQ(1, observer.gatt_service_removed_count());
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count());
EXPECT_FALSE(observer.last_gatt_service_id().empty());
EXPECT_TRUE(device->GetGattServices().empty());
EXPECT_EQ(BluetoothUUID(
@@ -325,8 +334,12 @@ TEST_F(BluetoothGattBlueZTest, GattServiceAddedAndRemoved) {
observer.last_gatt_service_id().clear();
fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
+ // Notify that all services have been discovered.
+ properties->services_resolved.ReplaceValue(true);
+
EXPECT_EQ(2, observer.gatt_service_added_count());
EXPECT_EQ(1, observer.gatt_service_removed_count());
+ EXPECT_EQ(2, observer.gatt_discovery_complete_count());
EXPECT_FALSE(observer.last_gatt_service_id().empty());
EXPECT_EQ(1U, device->GetGattServices().size());
EXPECT_EQ(BluetoothUUID(
@@ -351,6 +364,7 @@ TEST_F(BluetoothGattBlueZTest, GattServiceAddedAndRemoved) {
EXPECT_EQ(2, observer.gatt_service_added_count());
EXPECT_EQ(2, observer.gatt_service_removed_count());
+ EXPECT_EQ(2, observer.gatt_discovery_complete_count());
EXPECT_FALSE(observer.last_gatt_service_id().empty());
EXPECT_EQ(BluetoothUUID(
bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID),
@@ -373,17 +387,34 @@ TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) {
ASSERT_TRUE(device);
+ device->CreateGattConnection(
+ base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
+ base::Unretained(this)));
+
+ EXPECT_EQ(1, success_callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ EXPECT_TRUE(device->IsConnected());
+ ASSERT_TRUE(gatt_conn_.get());
+ EXPECT_TRUE(gatt_conn_->IsConnected());
+ EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
+ gatt_conn_->GetDeviceAddress());
+
TestBluetoothAdapterObserver observer(adapter_);
+ EXPECT_EQ(0, observer.gatt_discovery_complete_count());
+ EXPECT_TRUE(device->GetGattServices().empty());
+
// Expose the fake Heart Rate Service.
fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
// Notify that all services have been discovered.
properties->services_resolved.ReplaceValue(true);
-
EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
EXPECT_EQ(1u, device->GetGattServices().size());
EXPECT_EQ(device, observer.last_device());
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count());
EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
observer.last_device_address());
@@ -398,6 +429,7 @@ TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) {
EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsGattServicesDiscoveryComplete());
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count());
EXPECT_EQ(0u, device->GetGattServices().size());
// Verify that the device can be connected to again:
@@ -412,9 +444,13 @@ TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) {
// Verify that service discovery can be done again:
fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
+ // Notify that all services have been discovered.
properties->services_resolved.ReplaceValue(true);
EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
EXPECT_EQ(1u, device->GetGattServices().size());
+ EXPECT_EQ(2, observer.gatt_discovery_complete_count());
+ EXPECT_FALSE(device->GetGattServices().empty());
+ EXPECT_EQ(1u, device->GetGattServices().size());
}
TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
@@ -423,6 +459,10 @@ TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
BluetoothDevice* device =
adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
+ bluez::FakeBluetoothDeviceClient::Properties* properties =
+ fake_bluetooth_device_client_->GetProperties(
+ dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
+
ASSERT_TRUE(device);
TestBluetoothAdapterObserver observer(adapter_);
@@ -431,13 +471,15 @@ TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
// characteristics.
fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
+ // Notify that all services have been discovered.
+ properties->services_resolved.ReplaceValue(true);
ASSERT_EQ(1, observer.gatt_service_added_count());
BluetoothRemoteGattService* service =
device->GetGattService(observer.last_gatt_service_id());
EXPECT_EQ(0, observer.gatt_service_changed_count());
- EXPECT_EQ(0, observer.gatt_discovery_complete_count());
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count());
EXPECT_EQ(0, observer.gatt_characteristic_added_count());
EXPECT_EQ(0, observer.gatt_characteristic_removed_count());
EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
@@ -587,6 +629,11 @@ TEST_F(BluetoothGattBlueZTest, AdapterAddedAfterGattService) {
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
+ bluez::FakeBluetoothDeviceClient::Properties* properties =
+ fake_bluetooth_device_client_->GetProperties(
+ dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
+ // Notify that all services have been discovered.
+ properties->services_resolved.ReplaceValue(true);
while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible())
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible());

Powered by Google App Engine
This is Rietveld 408576698