Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "device/bluetooth/test/bluetooth_test_bluez.h" | 5 #include "device/bluetooth/test/bluetooth_test_bluez.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 59 |
| 60 BluetoothTestBlueZ::BluetoothTestBlueZ() | 60 BluetoothTestBlueZ::BluetoothTestBlueZ() |
| 61 : fake_bluetooth_device_client_(nullptr) {} | 61 : fake_bluetooth_device_client_(nullptr) {} |
| 62 | 62 |
| 63 BluetoothTestBlueZ::~BluetoothTestBlueZ() {} | 63 BluetoothTestBlueZ::~BluetoothTestBlueZ() {} |
| 64 | 64 |
| 65 void BluetoothTestBlueZ::SetUp() { | 65 void BluetoothTestBlueZ::SetUp() { |
| 66 BluetoothTestBase::SetUp(); | 66 BluetoothTestBase::SetUp(); |
| 67 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = | 67 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
| 68 bluez::BluezDBusManager::GetSetterForTesting(); | 68 bluez::BluezDBusManager::GetSetterForTesting(); |
| 69 | |
| 70 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient; | |
| 71 dbus_setter->SetBluetoothAdapterClient( | |
| 72 std::unique_ptr<bluez::BluetoothAdapterClient>( | |
| 73 fake_bluetooth_adapter_client_)); | |
| 74 | |
| 69 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; | 75 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; |
| 70 dbus_setter->SetBluetoothDeviceClient( | 76 dbus_setter->SetBluetoothDeviceClient( |
| 71 std::unique_ptr<bluez::BluetoothDeviceClient>( | 77 std::unique_ptr<bluez::BluetoothDeviceClient>( |
| 72 fake_bluetooth_device_client_)); | 78 fake_bluetooth_device_client_)); |
| 79 | |
| 80 // Make the fake adapter post tasks without delay in order to avoid timing | |
| 81 // issues. | |
| 82 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(0); | |
| 73 } | 83 } |
| 74 | 84 |
| 75 void BluetoothTestBlueZ::TearDown() { | 85 void BluetoothTestBlueZ::TearDown() { |
| 86 for (const auto& connection : gatt_connections_) { | |
|
ortuno
2017/01/22 20:51:55
A comment explaining why we need to close all conn
perja
2017/01/23 09:05:34
Done.
| |
| 87 if (connection->IsConnected()) | |
| 88 connection->Disconnect(); | |
| 89 } | |
| 90 gatt_connections_.clear(); | |
| 91 | |
| 92 for (const auto& session : discovery_sessions_) { | |
| 93 if (session->IsActive()) | |
| 94 session->Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | |
| 95 } | |
| 96 discovery_sessions_.clear(); | |
| 97 | |
| 76 adapter_ = nullptr; | 98 adapter_ = nullptr; |
| 77 bluez::BluezDBusManager::Shutdown(); | 99 bluez::BluezDBusManager::Shutdown(); |
| 78 BluetoothTestBase::TearDown(); | 100 BluetoothTestBase::TearDown(); |
| 79 } | 101 } |
| 80 | 102 |
| 81 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() { | 103 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() { |
| 82 return true; | 104 return true; |
| 83 } | 105 } |
| 84 | 106 |
| 85 void BluetoothTestBlueZ::InitWithFakeAdapter() { | 107 void BluetoothTestBlueZ::InitWithFakeAdapter() { |
| 86 base::RunLoop run_loop; | 108 base::RunLoop run_loop; |
| 87 adapter_ = new bluez::BluetoothAdapterBlueZ( | 109 adapter_ = new bluez::BluetoothAdapterBlueZ( |
| 88 base::Bind(&AdapterCallback, run_loop.QuitClosure())); | 110 base::Bind(&AdapterCallback, run_loop.QuitClosure())); |
| 89 run_loop.Run(); | 111 run_loop.Run(); |
| 112 adapter_->SetPowered(true, base::Bind(&base::DoNothing), | |
| 113 base::Bind(&base::DoNothing)); | |
| 90 } | 114 } |
| 91 | 115 |
| 92 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( | 116 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( |
| 93 int device_ordinal) { | 117 int device_ordinal) { |
| 94 if (device_ordinal > 6 || device_ordinal < 1) | 118 if (device_ordinal > 6 || device_ordinal < 1) |
| 95 return nullptr; | 119 return nullptr; |
| 96 | 120 |
| 97 base::Optional<std::string> device_name = kTestDeviceName; | 121 base::Optional<std::string> device_name = kTestDeviceName; |
| 98 std::string device_address = kTestDeviceAddress1; | 122 std::string device_address = kTestDeviceAddress1; |
| 99 std::vector<std::string> service_uuids; | 123 std::vector<std::string> service_uuids; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 std::vector<BluetoothLocalGattService*> services; | 341 std::vector<BluetoothLocalGattService*> services; |
| 318 bluez::BluetoothAdapterBlueZ* adapter_bluez = | 342 bluez::BluetoothAdapterBlueZ* adapter_bluez = |
| 319 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); | 343 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); |
| 320 | 344 |
| 321 for (const auto& iter : adapter_bluez->registered_gatt_services_) | 345 for (const auto& iter : adapter_bluez->registered_gatt_services_) |
| 322 services.push_back(iter.second); | 346 services.push_back(iter.second); |
| 323 return services; | 347 return services; |
| 324 } | 348 } |
| 325 | 349 |
| 326 } // namespace device | 350 } // namespace device |
| OLD | NEW |