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

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

Issue 1862093002: bluetooth: replace GattServices D-Bus property with ServicesResolved (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 BluetoothDevice* device = 368 BluetoothDevice* device =
369 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 369 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
370 bluez::FakeBluetoothDeviceClient::Properties* properties = 370 bluez::FakeBluetoothDeviceClient::Properties* properties =
371 fake_bluetooth_device_client_->GetProperties( 371 fake_bluetooth_device_client_->GetProperties(
372 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 372 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
373 373
374 ASSERT_TRUE(device); 374 ASSERT_TRUE(device);
375 375
376 TestBluetoothAdapterObserver observer(adapter_); 376 TestBluetoothAdapterObserver observer(adapter_);
377 377
378 EXPECT_EQ(0, observer.gatt_services_discovered_count());
379
380 // Expose the fake Heart Rate Service. 378 // Expose the fake Heart Rate Service.
381 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 379 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
382 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 380 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
383 // Notify that all services have been discovered. 381 // Notify that all services have been discovered.
384 properties->gatt_services.ReplaceValue( 382 properties->services_resolved.ReplaceValue(true);
385 fake_bluetooth_gatt_service_client_->GetServices());
386 383
387 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 384 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
388 EXPECT_EQ(1u, device->GetGattServices().size()); 385 EXPECT_EQ(1u, device->GetGattServices().size());
389 EXPECT_EQ(1, observer.gatt_services_discovered_count());
390 EXPECT_EQ(device, observer.last_device()); 386 EXPECT_EQ(device, observer.last_device());
391 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, 387 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
392 observer.last_device_address()); 388 observer.last_device_address());
393 389
394 // Disconnect from the device: 390 // Disconnect from the device:
395 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, 391 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
396 base::Unretained(this)), 392 base::Unretained(this)),
397 base::Bind(&BluetoothGattBlueZTest::ErrorCallback, 393 base::Bind(&BluetoothGattBlueZTest::ErrorCallback,
398 base::Unretained(this))); 394 base::Unretained(this)));
399 fake_bluetooth_gatt_service_client_->HideHeartRateService(); 395 fake_bluetooth_gatt_service_client_->HideHeartRateService();
400 properties->connected.ReplaceValue(false); 396 properties->connected.ReplaceValue(false);
397 properties->services_resolved.ReplaceValue(false);
401 398
402 EXPECT_FALSE(device->IsConnected()); 399 EXPECT_FALSE(device->IsConnected());
403 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); 400 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete());
404 EXPECT_EQ(0u, device->GetGattServices().size()); 401 EXPECT_EQ(0u, device->GetGattServices().size());
405 402
406 // Verify that the device can be connected to again: 403 // Verify that the device can be connected to again:
407 device->CreateGattConnection( 404 device->CreateGattConnection(
408 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback, 405 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback,
409 base::Unretained(this)), 406 base::Unretained(this)),
410 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, 407 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
411 base::Unretained(this))); 408 base::Unretained(this)));
412 properties->connected.ReplaceValue(true); 409 properties->connected.ReplaceValue(true);
413 EXPECT_TRUE(device->IsConnected()); 410 EXPECT_TRUE(device->IsConnected());
414 411
415 // Verify that service discovery can be done again: 412 // Verify that service discovery can be done again:
416 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 413 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
417 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 414 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
418 properties->gatt_services.ReplaceValue( 415 properties->services_resolved.ReplaceValue(true);
419 fake_bluetooth_gatt_service_client_->GetServices());
420 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 416 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
421 EXPECT_EQ(1u, device->GetGattServices().size()); 417 EXPECT_EQ(1u, device->GetGattServices().size());
422 } 418 }
423 419
424 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) { 420 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
425 fake_bluetooth_device_client_->CreateDevice( 421 fake_bluetooth_device_client_->CreateDevice(
426 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 422 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
427 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 423 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
428 BluetoothDevice* device = 424 BluetoothDevice* device =
429 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 425 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 1293
1298 EXPECT_EQ(1, success_callback_count_); 1294 EXPECT_EQ(1, success_callback_count_);
1299 EXPECT_EQ(0, error_callback_count_); 1295 EXPECT_EQ(0, error_callback_count_);
1300 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1296 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1301 EXPECT_TRUE(characteristic->IsNotifying()); 1297 EXPECT_TRUE(characteristic->IsNotifying());
1302 EXPECT_EQ(1U, update_sessions_.size()); 1298 EXPECT_EQ(1U, update_sessions_.size());
1303 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1299 EXPECT_TRUE(update_sessions_[0]->IsActive());
1304 } 1300 }
1305 1301
1306 } // namespace bluez 1302 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluez/bluetooth_device_bluez.cc ('k') | device/bluetooth/dbus/bluetooth_device_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698