Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "device/bluetooth/test/bluetooth_test_bluez.h" | |
| 6 | |
| 7 #include <iterator> | |
| 8 #include <sstream> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "base/run_loop.h" | |
| 12 #include "device/bluetooth/bluetooth_adapter_bluez.h" | |
| 13 #include "device/bluetooth/bluetooth_device_bluez.h" | |
| 14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" | |
| 15 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h" | |
| 16 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" | |
| 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | |
| 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" | |
| 19 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | |
| 20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | |
| 21 | |
| 22 namespace device { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 void AdapterCallback(base::Closure quit_closure) { | |
| 27 quit_closure.Run(); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 BluetoothTestBlueZ::BluetoothTestBlueZ() | |
| 32 : fake_bluetooth_device_client_(nullptr) {} | |
| 33 | |
| 34 BluetoothTestBlueZ::~BluetoothTestBlueZ() {} | |
| 35 | |
| 36 void BluetoothTestBlueZ::SetUp() { | |
| 37 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = | |
| 38 bluez::BluezDBusManager::GetSetterForTesting(); | |
| 39 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; | |
| 40 // TODO(rkc): This is a big hacky. Creating a device client creates three | |
| 41 // devices by default. For now, the easiest path is to just clear them, but | |
| 42 // a better way will be to only create them as needed. This will require | |
| 43 // looking at a lot of tests but should be done eventually. | |
| 44 fake_bluetooth_device_client_->RemoveAllDevices(); | |
| 45 dbus_setter->SetBluetoothDeviceClient( | |
| 46 std::unique_ptr<bluez::BluetoothDeviceClient>( | |
| 47 fake_bluetooth_device_client_)); | |
| 48 } | |
| 49 | |
| 50 void BluetoothTestBlueZ::TearDown() { | |
| 51 adapter_ = nullptr; | |
| 52 bluez::BluezDBusManager::Shutdown(); | |
| 53 } | |
| 54 | |
| 55 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() { | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 void BluetoothTestBlueZ::InitWithDefaultAdapter() { | |
|
scheib
2016/04/15 19:44:45
This doesn't bring up the hardware adapter, which
rkc
2016/04/15 20:26:06
Done.
| |
| 60 base::RunLoop run_loop; | |
| 61 adapter_ = new bluez::BluetoothAdapterBlueZ( | |
| 62 base::Bind(&AdapterCallback, run_loop.QuitClosure())); | |
| 63 run_loop.Run(); | |
| 64 } | |
| 65 | |
| 66 void BluetoothTestBlueZ::InitWithFakeAdapter() { | |
| 67 base::RunLoop run_loop; | |
| 68 adapter_ = new bluez::BluetoothAdapterBlueZ( | |
| 69 base::Bind(&AdapterCallback, run_loop.QuitClosure())); | |
| 70 run_loop.Run(); | |
| 71 } | |
| 72 | |
| 73 BluetoothDevice* BluetoothTestBlueZ::DiscoverLowEnergyDevice( | |
| 74 int device_ordinal) { | |
| 75 if (device_ordinal > 4 || device_ordinal < 1) | |
| 76 return nullptr; | |
| 77 | |
| 78 std::string device_name = kTestDeviceName; | |
| 79 std::string device_address = kTestDeviceAddress1; | |
| 80 std::vector<std::string> service_uuids; | |
| 81 | |
| 82 switch (device_ordinal) { | |
| 83 case 1: { | |
| 84 service_uuids.push_back(kTestUUIDGenericAccess); | |
| 85 service_uuids.push_back(kTestUUIDGenericAttribute); | |
| 86 } break; | |
|
scheib
2016/04/15 19:44:45
optional:
"} break;" looks odd to me, though I se
rkc
2016/04/15 20:26:06
I copy/pasted this without looking too hard. This
| |
| 87 case 2: { | |
| 88 service_uuids.push_back(kTestUUIDImmediateAlert); | |
| 89 service_uuids.push_back(kTestUUIDLinkLoss); | |
| 90 } break; | |
| 91 case 3: { | |
| 92 device_name = kTestDeviceNameEmpty; | |
| 93 } break; | |
| 94 case 4: { | |
| 95 device_name = kTestDeviceNameEmpty; | |
| 96 device_address = kTestDeviceAddress2; | |
| 97 } break; | |
| 98 } | |
| 99 | |
| 100 if (!adapter_->GetDevice(device_address)) { | |
| 101 fake_bluetooth_device_client_->CreateTestDevice( | |
| 102 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | |
| 103 device_name /* name */, device_name /* alias */, device_address, | |
| 104 service_uuids); | |
| 105 } | |
| 106 BluetoothDevice* device = adapter_->GetDevice(device_address); | |
| 107 | |
| 108 return device; | |
| 109 } | |
| 110 } | |
| OLD | NEW |