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

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

Issue 1606523002: Tidy up service discovery state for bluez on disconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address issues highlighted in code review Created 4 years, 11 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
« no previous file with comments | « device/bluetooth/bluetooth_adapter_bluez.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 EXPECT_EQ(0, observer.gatt_services_discovered_count()); 371 EXPECT_EQ(0, observer.gatt_services_discovered_count());
372 372
373 // Expose the fake Heart Rate Service. 373 // Expose the fake Heart Rate Service.
374 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( 374 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
375 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 375 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
376 // Notify that all services have been discovered. 376 // Notify that all services have been discovered.
377 properties->gatt_services.ReplaceValue( 377 properties->gatt_services.ReplaceValue(
378 fake_bluetooth_gatt_service_client_->GetServices()); 378 fake_bluetooth_gatt_service_client_->GetServices());
379 379
380 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
381 EXPECT_EQ(1u, device->GetGattServices().size());
380 EXPECT_EQ(1, observer.gatt_services_discovered_count()); 382 EXPECT_EQ(1, observer.gatt_services_discovered_count());
381 EXPECT_EQ(device, observer.last_device()); 383 EXPECT_EQ(device, observer.last_device());
382 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, 384 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
383 observer.last_device_address()); 385 observer.last_device_address());
386
387 // Disconnect from the device:
388 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
389 base::Unretained(this)),
390 base::Bind(&BluetoothGattBlueZTest::ErrorCallback,
391 base::Unretained(this)));
392 fake_bluetooth_gatt_service_client_->HideHeartRateService();
393 properties->connected.ReplaceValue(false);
394
395 EXPECT_FALSE(device->IsConnected());
396 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete());
397 EXPECT_EQ(0u, device->GetGattServices().size());
398
399 // Verify that the device can be connected to again:
400 device->CreateGattConnection(
401 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback,
402 base::Unretained(this)),
403 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback,
404 base::Unretained(this)));
405 properties->connected.ReplaceValue(true);
406 EXPECT_TRUE(device->IsConnected());
407
408 // Verify that service discovery can be done again:
409 fake_bluetooth_gatt_service_client_->ExposeHeartRateService(
410 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
411 properties->gatt_services.ReplaceValue(
412 fake_bluetooth_gatt_service_client_->GetServices());
413 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
414 EXPECT_EQ(1u, device->GetGattServices().size());
384 } 415 }
385 416
386 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) { 417 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) {
387 fake_bluetooth_device_client_->CreateDevice( 418 fake_bluetooth_device_client_->CreateDevice(
388 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 419 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
389 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 420 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
390 BluetoothDevice* device = 421 BluetoothDevice* device =
391 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 422 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
392 ASSERT_TRUE(device); 423 ASSERT_TRUE(device);
393 424
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 1283
1253 EXPECT_EQ(1, success_callback_count_); 1284 EXPECT_EQ(1, success_callback_count_);
1254 EXPECT_EQ(0, error_callback_count_); 1285 EXPECT_EQ(0, error_callback_count_);
1255 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1286 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1256 EXPECT_TRUE(characteristic->IsNotifying()); 1287 EXPECT_TRUE(characteristic->IsNotifying());
1257 EXPECT_EQ(1U, update_sessions_.size()); 1288 EXPECT_EQ(1U, update_sessions_.size());
1258 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1289 EXPECT_TRUE(update_sessions_[0]->IsActive());
1259 } 1290 }
1260 1291
1261 } // namespace bluez 1292 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_bluez.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698