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 adapter_->StartDiscoverySessionWithFilter( | |
scheib
2016/02/07 02:24:08
Is it possible to avoid duplicate code, and not be
gogerald1
2016/02/08 19:23:51
Done.
| |
79 make_scoped_ptr(new BluetoothDiscoveryFilter( | |
80 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE)), | |
81 GetDiscoverySessionCallback(Call::EXPECTED), | |
82 GetErrorCallback(Call::NOT_EXPECTED)); | |
83 bluetooth_task_runner_->RunPendingTasks(); | |
84 ui_task_runner_->RunPendingTasks(); | |
76 } | 85 } |
86 | |
87 BluetoothDevice* BluetoothTestWin::DiscoverLowEnergyDevice(int device_ordinal) { | |
88 if (device_ordinal > 4 || device_ordinal < 1) | |
89 return nullptr; | |
90 | |
91 std::string device_name = kTestDeviceName; | |
92 std::string device_address = kTestDeviceAddress1; | |
93 std::string service_uuid_1; | |
94 std::string service_uuid_2; | |
95 | |
96 switch (device_ordinal) { | |
97 case 1: { | |
98 service_uuid_1 = kTestUUIDGenericAccess; | |
99 service_uuid_2 = kTestUUIDGenericAttribute; | |
100 } break; | |
101 case 2: { | |
102 service_uuid_1 = kTestUUIDImmediateAlert; | |
103 service_uuid_2 = kTestUUIDLinkLoss; | |
104 } break; | |
105 case 3: { | |
106 device_name = kTestDeviceNameEmpty; | |
107 } break; | |
108 case 4: { | |
109 device_name = kTestDeviceNameEmpty; | |
110 device_address = kTestDeviceAddress2; | |
111 } break; | |
112 } | |
113 | |
114 win::BLEDevice* simulated_device = fake_bt_le_wrapper_->SimulateBLEDevice( | |
115 device_name, CanonicalStringToBLUETOOTH_ADDRESS(device_address)); | |
116 if (simulated_device != nullptr) { | |
117 if (!service_uuid_1.empty()) | |
118 fake_bt_le_wrapper_->SimulateBLEGattService(simulated_device, | |
119 service_uuid_1); | |
120 if (!service_uuid_2.empty()) | |
121 fake_bt_le_wrapper_->SimulateBLEGattService(simulated_device, | |
122 service_uuid_2); | |
123 } | |
124 bluetooth_task_runner_->RunPendingTasks(); | |
125 ui_task_runner_->RunPendingTasks(); | |
126 | |
127 std::vector<BluetoothDevice*> devices = adapter_win_->GetDevices(); | |
128 for (auto device : devices) { | |
129 if (device->GetAddress() == device_address) | |
130 return device; | |
131 } | |
132 | |
133 return nullptr; | |
134 } | |
135 } | |
OLD | NEW |