Index: device/bluetooth/test/bluetooth_test_bluez.cc |
diff --git a/device/bluetooth/test/bluetooth_test_bluez.cc b/device/bluetooth/test/bluetooth_test_bluez.cc |
index d492f4a196461e96ca0c20e39658d7c0bc052637..19ac65aea94f29faa49667915d13140cf0f8d967 100644 |
--- a/device/bluetooth/test/bluetooth_test_bluez.cc |
+++ b/device/bluetooth/test/bluetooth_test_bluez.cc |
@@ -66,13 +66,38 @@ void BluetoothTestBlueZ::SetUp() { |
BluetoothTestBase::SetUp(); |
std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
bluez::BluezDBusManager::GetSetterForTesting(); |
+ |
+ fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient; |
+ dbus_setter->SetBluetoothAdapterClient( |
+ std::unique_ptr<bluez::BluetoothAdapterClient>( |
+ fake_bluetooth_adapter_client_)); |
+ |
fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; |
dbus_setter->SetBluetoothDeviceClient( |
std::unique_ptr<bluez::BluetoothDeviceClient>( |
fake_bluetooth_device_client_)); |
+ |
+ // Make the fake adapter post tasks without delay in order to avoid timing |
+ // issues. |
+ fake_bluetooth_adapter_client_->SetSimulationIntervalMs(0); |
} |
void BluetoothTestBlueZ::TearDown() { |
+ // Connections and sessions will normally be closed by destructors, |
+ // but for BlueZ we need to close them before shutting down the |
+ // BluezDBusManager. |
+ for (const auto& connection : gatt_connections_) { |
+ if (connection->IsConnected()) |
+ connection->Disconnect(); |
+ } |
+ gatt_connections_.clear(); |
+ |
+ for (const auto& session : discovery_sessions_) { |
+ if (session->IsActive()) |
+ session->Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
+ } |
+ discovery_sessions_.clear(); |
+ |
adapter_ = nullptr; |
bluez::BluezDBusManager::Shutdown(); |
BluetoothTestBase::TearDown(); |
@@ -87,6 +112,8 @@ void BluetoothTestBlueZ::InitWithFakeAdapter() { |
adapter_ = new bluez::BluetoothAdapterBlueZ( |
base::Bind(&AdapterCallback, run_loop.QuitClosure())); |
run_loop.Run(); |
+ adapter_->SetPowered(true, base::Bind(&base::DoNothing), |
+ base::Bind(&base::DoNothing)); |
} |
BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( |