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() == 3) << "Should contain AdapterName:txPower:RSSI"; |
| 154 |
| 155 int tx_power; |
| 156 base::StringToInt(args[1], &tx_power); |
| 157 int rssi; |
| 158 base::StringToInt(args[2], &rssi); |
| 159 return GetPowerDeviceAdapter(tx_power, rssi); |
| 160 } |
| 161 |
144 NOTREACHED() << fake_adapter_name; | 162 NOTREACHED() << fake_adapter_name; |
145 return NULL; | 163 return NULL; |
146 } | 164 } |
147 | 165 |
148 // Adapters | 166 // Adapters |
149 | 167 |
150 // static | 168 // static |
151 scoped_refptr<NiceMockBluetoothAdapter> | 169 scoped_refptr<NiceMockBluetoothAdapter> |
152 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { | 170 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { |
153 scoped_refptr<NiceMockBluetoothAdapter> adapter( | 171 scoped_refptr<NiceMockBluetoothAdapter> adapter( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 266 |
249 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) | 267 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
250 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( | 268 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( |
251 []() { return GetDiscoverySession(); })); | 269 []() { return GetDiscoverySession(); })); |
252 | 270 |
253 return adapter.Pass(); | 271 return adapter.Pass(); |
254 } | 272 } |
255 | 273 |
256 // static | 274 // static |
257 scoped_refptr<NiceMockBluetoothAdapter> | 275 scoped_refptr<NiceMockBluetoothAdapter> |
| 276 LayoutTestBluetoothAdapterProvider::GetPowerDeviceAdapter(int tx_power, |
| 277 int rssi) { |
| 278 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 279 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
| 280 |
| 281 ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(tx_power)); |
| 282 ON_CALL(*device, GetInquiryRSSI()).WillByDefault(Return(rssi)); |
| 283 |
| 284 adapter->AddMockDevice(device.Pass()); |
| 285 |
| 286 return adapter; |
| 287 } |
| 288 |
| 289 // static |
| 290 scoped_refptr<NiceMockBluetoothAdapter> |
258 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { | 291 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { |
259 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 292 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
260 | 293 |
261 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); | 294 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); |
262 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); | 295 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); |
263 | 296 |
264 return adapter.Pass(); | 297 return adapter.Pass(); |
265 } | 298 } |
266 | 299 |
267 // Adds a device to |adapter| and notifies all observers about that new device. | 300 // 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); | 739 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); |
707 } | 740 } |
708 | 741 |
709 // static | 742 // static |
710 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 743 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
711 return BluetoothDevice::CanonicalizeAddress( | 744 return BluetoothDevice::CanonicalizeAddress( |
712 base::StringPrintf("%012" PRIx64, addr)); | 745 base::StringPrintf("%012" PRIx64, addr)); |
713 } | 746 } |
714 | 747 |
715 } // namespace content | 748 } // namespace content |
OLD | NEW |