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" |
| 8 #include "base/bind_helpers.h" |
7 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/location.h" |
8 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/thread_task_runner_handle.h" |
9 #include "device/bluetooth/bluetooth_adapter.h" | 13 #include "device/bluetooth/bluetooth_adapter.h" |
10 #include "device/bluetooth/bluetooth_device.h" | 14 #include "device/bluetooth/bluetooth_device.h" |
11 #include "device/bluetooth/bluetooth_discovery_session.h" | 15 #include "device/bluetooth/bluetooth_discovery_session.h" |
12 #include "device/bluetooth/bluetooth_uuid.h" | 16 #include "device/bluetooth/bluetooth_uuid.h" |
13 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 17 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
14 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 18 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
15 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 19 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
17 | 21 |
18 using device::BluetoothAdapter; | 22 using device::BluetoothAdapter; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter") | 119 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter") |
116 return GetMissingServiceGenericAccessAdapter(); | 120 return GetMissingServiceGenericAccessAdapter(); |
117 else if (fake_adapter_name == "MissingCharacteristicGenericAccessAdapter") | 121 else if (fake_adapter_name == "MissingCharacteristicGenericAccessAdapter") |
118 return GetMissingCharacteristicGenericAccessAdapter(); | 122 return GetMissingCharacteristicGenericAccessAdapter(); |
119 else if (fake_adapter_name == "GenericAccessAdapter") | 123 else if (fake_adapter_name == "GenericAccessAdapter") |
120 return GetGenericAccessAdapter(); | 124 return GetGenericAccessAdapter(); |
121 else if (fake_adapter_name == "FailingConnectionsAdapter") | 125 else if (fake_adapter_name == "FailingConnectionsAdapter") |
122 return GetFailingConnectionsAdapter(); | 126 return GetFailingConnectionsAdapter(); |
123 else if (fake_adapter_name == "FailingGATTOperationsAdapter") | 127 else if (fake_adapter_name == "FailingGATTOperationsAdapter") |
124 return GetFailingGATTOperationsAdapter(); | 128 return GetFailingGATTOperationsAdapter(); |
| 129 else if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") |
| 130 return GetSecondDiscoveryFindsHeartRateAdapter(); |
125 else if (fake_adapter_name == "") | 131 else if (fake_adapter_name == "") |
126 return NULL; | 132 return NULL; |
127 | 133 |
128 NOTREACHED() << fake_adapter_name; | 134 NOTREACHED() << fake_adapter_name; |
129 return NULL; | 135 return NULL; |
130 } | 136 } |
131 | 137 |
132 // Adapters | 138 // Adapters |
133 | 139 |
134 // static | 140 // static |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 scoped_refptr<NiceMockBluetoothAdapter> | 247 scoped_refptr<NiceMockBluetoothAdapter> |
242 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { | 248 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { |
243 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 249 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
244 | 250 |
245 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); | 251 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); |
246 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); | 252 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); |
247 | 253 |
248 return adapter.Pass(); | 254 return adapter.Pass(); |
249 } | 255 } |
250 | 256 |
| 257 // Adds a device to |adapter| and notifies all observers about that new device. |
| 258 // Mocks can call this asynchronously to cause changes in the middle of a test. |
| 259 static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, |
| 260 scoped_ptr<NiceMockBluetoothDevice> new_device) { |
| 261 NiceMockBluetoothDevice* new_device_ptr = new_device.get(); |
| 262 adapter->AddMockDevice(new_device.Pass()); |
| 263 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), |
| 264 DeviceAdded(adapter.get(), new_device_ptr)); |
| 265 } |
| 266 |
| 267 // static |
| 268 scoped_refptr<NiceMockBluetoothAdapter> |
| 269 LayoutTestBluetoothAdapterProvider::GetSecondDiscoveryFindsHeartRateAdapter() { |
| 270 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); |
| 271 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); |
| 272 |
| 273 EXPECT_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
| 274 .WillOnce(RunCallbackWithResult<1 /* success_callback */>( |
| 275 []() { return GetDiscoverySession(); })) |
| 276 .WillOnce( |
| 277 RunCallbackWithResult<1 /* success_callback */>([adapter_ptr]() { |
| 278 // In the second discovery session, have the adapter discover a new |
| 279 // device, shortly after the session starts. |
| 280 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 281 FROM_HERE, |
| 282 base::Bind(&AddDevice, make_scoped_refptr(adapter_ptr), |
| 283 |
| 284 base::Passed(GetHeartRateDevice(adapter_ptr)))); |
| 285 return GetDiscoverySession(); |
| 286 })); |
| 287 |
| 288 return adapter; |
| 289 } |
| 290 |
251 // static | 291 // static |
252 scoped_refptr<NiceMockBluetoothAdapter> | 292 scoped_refptr<NiceMockBluetoothAdapter> |
253 LayoutTestBluetoothAdapterProvider::GetMissingServiceGenericAccessAdapter() { | 293 LayoutTestBluetoothAdapterProvider::GetMissingServiceGenericAccessAdapter() { |
254 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 294 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
255 | 295 |
256 adapter->AddMockDevice(GetGenericAccessDevice(adapter.get())); | 296 adapter->AddMockDevice(GetGenericAccessDevice(adapter.get())); |
257 | 297 |
258 return adapter.Pass(); | 298 return adapter.Pass(); |
259 } | 299 } |
260 | 300 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); | 591 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); |
552 } | 592 } |
553 | 593 |
554 // static | 594 // static |
555 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 595 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
556 return BluetoothDevice::CanonicalizeAddress( | 596 return BluetoothDevice::CanonicalizeAddress( |
557 base::StringPrintf("%012" PRIx64, addr)); | 597 base::StringPrintf("%012" PRIx64, addr)); |
558 } | 598 } |
559 | 599 |
560 } // namespace content | 600 } // namespace content |
OLD | NEW |