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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 namespace { | 62 namespace { |
63 // Bluetooth UUIDs suitable to pass to BluetoothUUID(): | 63 // Bluetooth UUIDs suitable to pass to BluetoothUUID(): |
64 // Services: | 64 // Services: |
65 const char kBatteryServiceUUID[] = "180f"; | 65 const char kBatteryServiceUUID[] = "180f"; |
66 const char kBlacklistTestServiceUUID[] = "611c954a-263b-4f4a-aab6-01ddb953f985"; | 66 const char kBlacklistTestServiceUUID[] = "611c954a-263b-4f4a-aab6-01ddb953f985"; |
67 const char kDeviceInformationServiceUUID[] = "180a"; | 67 const char kDeviceInformationServiceUUID[] = "180a"; |
68 const char kGenericAccessServiceUUID[] = "1800"; | 68 const char kGenericAccessServiceUUID[] = "1800"; |
69 const char kGlucoseServiceUUID[] = "1808"; | 69 const char kGlucoseServiceUUID[] = "1808"; |
70 const char kHeartRateServiceUUID[] = "180d"; | 70 const char kHeartRateServiceUUID[] = "180d"; |
71 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; | 71 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; |
| 72 const char kRequestDisconnectionServiceUUID[] = |
| 73 "01d7d889-7451-419f-aeb8-d65e7b9277af"; |
72 const char kTxPowerServiceUUID[] = "1804"; | 74 const char kTxPowerServiceUUID[] = "1804"; |
73 // Characteristics: | 75 // Characteristics: |
74 const char kBlacklistExcludeReadsCharacteristicUUID[] = | 76 const char kBlacklistExcludeReadsCharacteristicUUID[] = |
75 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135"; | 77 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135"; |
76 const char kBodySensorLocation[] = "2a38"; | 78 const char kBodySensorLocation[] = "2a38"; |
77 const char kDeviceNameUUID[] = "2a00"; | 79 const char kDeviceNameUUID[] = "2a00"; |
78 const char kHeartRateMeasurementUUID[] = "2a37"; | 80 const char kHeartRateMeasurementUUID[] = "2a37"; |
79 const char kSerialNumberStringUUID[] = "2a25"; | 81 const char kSerialNumberStringUUID[] = "2a25"; |
80 const char kPeripheralPrivacyFlagUUID[] = "2a02"; | 82 const char kPeripheralPrivacyFlagUUID[] = "2a02"; |
81 | 83 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 if (fake_adapter_name == "GlucoseHeartRateAdapter") | 151 if (fake_adapter_name == "GlucoseHeartRateAdapter") |
150 return GetGlucoseHeartRateAdapter(); | 152 return GetGlucoseHeartRateAdapter(); |
151 if (fake_adapter_name == "UnicodeDeviceAdapter") | 153 if (fake_adapter_name == "UnicodeDeviceAdapter") |
152 return GetUnicodeDeviceAdapter(); | 154 return GetUnicodeDeviceAdapter(); |
153 if (fake_adapter_name == "MissingServiceHeartRateAdapter") | 155 if (fake_adapter_name == "MissingServiceHeartRateAdapter") |
154 return GetMissingServiceHeartRateAdapter(); | 156 return GetMissingServiceHeartRateAdapter(); |
155 if (fake_adapter_name == "MissingCharacteristicHeartRateAdapter") | 157 if (fake_adapter_name == "MissingCharacteristicHeartRateAdapter") |
156 return GetMissingCharacteristicHeartRateAdapter(); | 158 return GetMissingCharacteristicHeartRateAdapter(); |
157 if (fake_adapter_name == "HeartRateAdapter") | 159 if (fake_adapter_name == "HeartRateAdapter") |
158 return GetHeartRateAdapter(); | 160 return GetHeartRateAdapter(); |
| 161 if (fake_adapter_name == "DisconnectingHeartRateAdapter") |
| 162 return GetDisconnectingHeartRateAdapter(); |
159 if (fake_adapter_name == "BlacklistTestAdapter") | 163 if (fake_adapter_name == "BlacklistTestAdapter") |
160 return GetBlacklistTestAdapter(); | 164 return GetBlacklistTestAdapter(); |
161 if (fake_adapter_name == "FailingConnectionsAdapter") | 165 if (fake_adapter_name == "FailingConnectionsAdapter") |
162 return GetFailingConnectionsAdapter(); | 166 return GetFailingConnectionsAdapter(); |
163 if (fake_adapter_name == "FailingGATTOperationsAdapter") | 167 if (fake_adapter_name == "FailingGATTOperationsAdapter") |
164 return GetFailingGATTOperationsAdapter(); | 168 return GetFailingGATTOperationsAdapter(); |
165 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") | 169 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") |
166 return GetSecondDiscoveryFindsHeartRateAdapter(); | 170 return GetSecondDiscoveryFindsHeartRateAdapter(); |
167 if (fake_adapter_name == "DelayedServicesDiscoveryAdapter") | 171 if (fake_adapter_name == "DelayedServicesDiscoveryAdapter") |
168 return GetDelayedServicesDiscoveryAdapter(); | 172 return GetDelayedServicesDiscoveryAdapter(); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { | 419 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
416 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 420 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
417 std::unique_ptr<NiceMockBluetoothDevice> device( | 421 std::unique_ptr<NiceMockBluetoothDevice> device( |
418 GetHeartRateDevice(adapter.get())); | 422 GetHeartRateDevice(adapter.get())); |
419 | 423 |
420 // TODO(ortuno): Implement the rest of the service's characteristics | 424 // TODO(ortuno): Implement the rest of the service's characteristics |
421 // See: http://crbug.com/529975 | 425 // See: http://crbug.com/529975 |
422 | 426 |
423 device->AddMockService(GetGenericAccessService(device.get())); | 427 device->AddMockService(GetGenericAccessService(device.get())); |
424 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 428 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| 429 |
425 adapter->AddMockDevice(std::move(device)); | 430 adapter->AddMockDevice(std::move(device)); |
426 | 431 |
427 return adapter; | 432 return adapter; |
| 433 } |
| 434 |
| 435 // static |
| 436 scoped_refptr<NiceMockBluetoothAdapter> |
| 437 LayoutTestBluetoothAdapterProvider::GetDisconnectingHeartRateAdapter() { |
| 438 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 439 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); |
| 440 std::unique_ptr<NiceMockBluetoothDevice> device( |
| 441 GetHeartRateDevice(adapter.get())); |
| 442 NiceMockBluetoothDevice* device_ptr = device.get(); |
| 443 |
| 444 // TODO(ortuno): Implement the rest of the service's characteristics |
| 445 // See: http://crbug.com/529975 |
| 446 |
| 447 device->AddMockService(GetGenericAccessService(device.get())); |
| 448 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| 449 |
| 450 // Set up a service to disconnect the device when its characteristics are |
| 451 // discovered. |
| 452 std::unique_ptr<NiceMockBluetoothGattService> disconnection_service = |
| 453 GetBaseGATTService(device_ptr, kRequestDisconnectionServiceUUID); |
| 454 ON_CALL(*disconnection_service, GetCharacteristics()) |
| 455 .WillByDefault(Invoke([adapter_ptr, device_ptr]() { |
| 456 LOG(ERROR) << "Got characteristics"; |
| 457 device_ptr->SetConnected(false); |
| 458 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
| 459 adapter_ptr->GetObservers(), |
| 460 DeviceChanged(adapter_ptr, device_ptr)); |
| 461 return std::vector<device::BluetoothRemoteGattCharacteristic*>(); |
| 462 })); |
| 463 device->AddMockService(std::move(disconnection_service)); |
| 464 |
| 465 adapter->AddMockDevice(std::move(device)); |
| 466 |
| 467 return adapter; |
428 } | 468 } |
429 | 469 |
430 // static | 470 // static |
431 scoped_refptr<NiceMockBluetoothAdapter> | 471 scoped_refptr<NiceMockBluetoothAdapter> |
432 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { | 472 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { |
433 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 473 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
434 | 474 |
435 BluetoothDevice::UUIDList uuids; | 475 BluetoothDevice::UUIDList uuids; |
436 uuids.push_back(BluetoothUUID(kBlacklistTestServiceUUID)); | 476 uuids.push_back(BluetoothUUID(kBlacklistTestServiceUUID)); |
437 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); | 477 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 return BluetoothUUID(); | 1002 return BluetoothUUID(); |
963 } | 1003 } |
964 | 1004 |
965 // static | 1005 // static |
966 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1006 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
967 return BluetoothDevice::CanonicalizeAddress( | 1007 return BluetoothDevice::CanonicalizeAddress( |
968 base::StringPrintf("%012" PRIx64, addr)); | 1008 base::StringPrintf("%012" PRIx64, addr)); |
969 } | 1009 } |
970 | 1010 |
971 } // namespace content | 1011 } // namespace content |
OLD | NEW |