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 "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" | 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/strings/string_number_conversions.h" | |
12 #include "base/strings/string_split.h" | |
13 #include "base/strings/string_util.h" | |
11 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
12 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
13 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
14 #include "device/bluetooth/bluetooth_device.h" | 17 #include "device/bluetooth/bluetooth_device.h" |
15 #include "device/bluetooth/bluetooth_discovery_session.h" | 18 #include "device/bluetooth/bluetooth_discovery_session.h" |
16 #include "device/bluetooth/bluetooth_uuid.h" | 19 #include "device/bluetooth/bluetooth_uuid.h" |
17 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 20 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
18 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 21 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
19 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 22 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
20 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" | 23 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
22 | 25 |
26 using base::StringPiece; | |
23 using device::BluetoothAdapter; | 27 using device::BluetoothAdapter; |
24 using device::BluetoothDevice; | 28 using device::BluetoothDevice; |
25 using device::BluetoothGattCharacteristic; | 29 using device::BluetoothGattCharacteristic; |
26 using device::BluetoothGattService; | 30 using device::BluetoothGattService; |
27 using device::BluetoothUUID; | 31 using device::BluetoothUUID; |
28 using device::MockBluetoothAdapter; | 32 using device::MockBluetoothAdapter; |
29 using device::MockBluetoothDevice; | 33 using device::MockBluetoothDevice; |
30 using device::MockBluetoothDiscoverySession; | 34 using device::MockBluetoothDiscoverySession; |
31 using device::MockBluetoothGattCharacteristic; | 35 using device::MockBluetoothGattCharacteristic; |
32 using device::MockBluetoothGattConnection; | 36 using device::MockBluetoothGattConnection; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 return GetHeartRateAdapter(); | 138 return GetHeartRateAdapter(); |
135 else if (fake_adapter_name == "FailingConnectionsAdapter") | 139 else if (fake_adapter_name == "FailingConnectionsAdapter") |
136 return GetFailingConnectionsAdapter(); | 140 return GetFailingConnectionsAdapter(); |
137 else if (fake_adapter_name == "FailingGATTOperationsAdapter") | 141 else if (fake_adapter_name == "FailingGATTOperationsAdapter") |
138 return GetFailingGATTOperationsAdapter(); | 142 return GetFailingGATTOperationsAdapter(); |
139 else if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") | 143 else if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") |
140 return GetSecondDiscoveryFindsHeartRateAdapter(); | 144 return GetSecondDiscoveryFindsHeartRateAdapter(); |
141 else if (fake_adapter_name == "") | 145 else if (fake_adapter_name == "") |
142 return NULL; | 146 return NULL; |
143 | 147 |
148 if (base::StartsWith(fake_adapter_name, "PowerAdapter", | |
149 base::CompareCase::SENSITIVE)) { | |
150 std::vector<StringPiece> args = | |
151 base::SplitStringPiece(fake_adapter_name, ":", base::KEEP_WHITESPACE, | |
152 base::SPLIT_WANT_NONEMPTY); | |
153 DCHECK(args.size() == 2); | |
154 | |
155 int power; | |
156 base::StringToInt(args[1], &power); | |
157 | |
158 return GetPowerDeviceAdapter(power); | |
159 } | |
160 | |
144 NOTREACHED() << fake_adapter_name; | 161 NOTREACHED() << fake_adapter_name; |
145 return NULL; | 162 return NULL; |
146 } | 163 } |
147 | 164 |
148 // Adapters | 165 // Adapters |
149 | 166 |
150 // static | 167 // static |
151 scoped_refptr<NiceMockBluetoothAdapter> | 168 scoped_refptr<NiceMockBluetoothAdapter> |
152 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { | 169 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { |
153 scoped_refptr<NiceMockBluetoothAdapter> adapter( | 170 scoped_refptr<NiceMockBluetoothAdapter> adapter( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 | 265 |
249 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) | 266 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
250 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( | 267 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( |
251 []() { return GetDiscoverySession(); })); | 268 []() { return GetDiscoverySession(); })); |
252 | 269 |
253 return adapter.Pass(); | 270 return adapter.Pass(); |
254 } | 271 } |
255 | 272 |
256 // static | 273 // static |
257 scoped_refptr<NiceMockBluetoothAdapter> | 274 scoped_refptr<NiceMockBluetoothAdapter> |
275 LayoutTestBluetoothAdapterProvider::GetPowerDeviceAdapter(int power) { | |
276 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | |
277 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | |
278 | |
279 ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(power)); | |
280 ON_CALL(*device, GetInquiryRSSI()).WillByDefault(Return(power)); | |
scheib
2015/10/29 17:37:25
We should return different numbers, validating the
ortuno
2015/10/29 20:21:42
Done.
| |
281 | |
282 adapter->AddMockDevice(device.Pass()); | |
283 | |
284 return adapter; | |
285 } | |
286 | |
287 // static | |
288 scoped_refptr<NiceMockBluetoothAdapter> | |
258 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { | 289 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { |
259 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 290 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
260 | 291 |
261 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); | 292 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); |
262 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); | 293 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); |
263 | 294 |
264 return adapter.Pass(); | 295 return adapter.Pass(); |
265 } | 296 } |
266 | 297 |
267 // Adds a device to |adapter| and notifies all observers about that new device. | 298 // Adds a device to |adapter| and notifies all observers about that new device. |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); | 737 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); |
707 } | 738 } |
708 | 739 |
709 // static | 740 // static |
710 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 741 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
711 return BluetoothDevice::CanonicalizeAddress( | 742 return BluetoothDevice::CanonicalizeAddress( |
712 base::StringPrintf("%012" PRIx64, addr)); | 743 base::StringPrintf("%012" PRIx64, addr)); |
713 } | 744 } |
714 | 745 |
715 } // namespace content | 746 } // namespace content |
OLD | NEW |