OLD | NEW |
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 "device/bluetooth/test/bluetooth_test_win.h" | 5 #include "device/bluetooth/test/bluetooth_test_win.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "device/bluetooth/bluetooth_adapter_win.h" | 9 #include "device/bluetooth/bluetooth_adapter_win.h" |
10 #include "device/bluetooth/bluetooth_low_energy_win.h" | 10 #include "device/bluetooth/bluetooth_low_energy_win.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 &BluetoothTestWin::AdapterInitCallback, base::Unretained(this))); | 66 &BluetoothTestWin::AdapterInitCallback, base::Unretained(this))); |
67 adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get()); | 67 adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get()); |
68 adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_); | 68 adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_); |
69 bluetooth_task_runner_->RunPendingTasks(); | 69 bluetooth_task_runner_->RunPendingTasks(); |
70 ui_task_runner_->RunPendingTasks(); | 70 ui_task_runner_->RunPendingTasks(); |
71 } | 71 } |
72 | 72 |
73 bool BluetoothTestWin::DenyPermission() { | 73 bool BluetoothTestWin::DenyPermission() { |
74 return false; | 74 return false; |
75 } | 75 } |
| 76 |
| 77 void BluetoothTestWin::StartLowEnergyDiscoverySession() { |
| 78 __super ::StartLowEnergyDiscoverySession(); |
| 79 bluetooth_task_runner_->RunPendingTasks(); |
| 80 ui_task_runner_->RunPendingTasks(); |
76 } | 81 } |
| 82 |
| 83 BluetoothDevice* BluetoothTestWin::DiscoverLowEnergyDevice(int device_ordinal) { |
| 84 if (device_ordinal > 4 || device_ordinal < 1) |
| 85 return nullptr; |
| 86 |
| 87 std::string device_name = kTestDeviceName; |
| 88 std::string device_address = kTestDeviceAddress1; |
| 89 std::string service_uuid_1; |
| 90 std::string service_uuid_2; |
| 91 |
| 92 switch (device_ordinal) { |
| 93 case 1: { |
| 94 service_uuid_1 = kTestUUIDGenericAccess; |
| 95 service_uuid_2 = kTestUUIDGenericAttribute; |
| 96 } break; |
| 97 case 2: { |
| 98 service_uuid_1 = kTestUUIDImmediateAlert; |
| 99 service_uuid_2 = kTestUUIDLinkLoss; |
| 100 } break; |
| 101 case 3: { |
| 102 device_name = kTestDeviceNameEmpty; |
| 103 } break; |
| 104 case 4: { |
| 105 device_name = kTestDeviceNameEmpty; |
| 106 device_address = kTestDeviceAddress2; |
| 107 } break; |
| 108 } |
| 109 |
| 110 win::BLEDevice* simulated_device = fake_bt_le_wrapper_->SimulateBLEDevice( |
| 111 device_name, CanonicalStringToBLUETOOTH_ADDRESS(device_address)); |
| 112 if (simulated_device != nullptr) { |
| 113 if (!service_uuid_1.empty()) |
| 114 fake_bt_le_wrapper_->SimulateBLEGattService(simulated_device, |
| 115 service_uuid_1); |
| 116 if (!service_uuid_2.empty()) |
| 117 fake_bt_le_wrapper_->SimulateBLEGattService(simulated_device, |
| 118 service_uuid_2); |
| 119 } |
| 120 bluetooth_task_runner_->RunPendingTasks(); |
| 121 ui_task_runner_->RunPendingTasks(); |
| 122 |
| 123 std::vector<BluetoothDevice*> devices = adapter_win_->GetDevices(); |
| 124 for (auto device : devices) { |
| 125 if (device->GetAddress() == device_address) |
| 126 return device; |
| 127 } |
| 128 |
| 129 return nullptr; |
| 130 } |
| 131 } |
OLD | NEW |