| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 true /* disconnect */, false /* succeeds */); | 212 true /* disconnect */, false /* succeeds */); |
| 213 } | 213 } |
| 214 if (fake_adapter_name == "GATTOperationSucceedsAfterReconnectionAdapter") { | 214 if (fake_adapter_name == "GATTOperationSucceedsAfterReconnectionAdapter") { |
| 215 return GetGATTOperationFinishesAfterReconnectionAdapter( | 215 return GetGATTOperationFinishesAfterReconnectionAdapter( |
| 216 false /* disconnect */, true /* succeeds */); | 216 false /* disconnect */, true /* succeeds */); |
| 217 } | 217 } |
| 218 if (fake_adapter_name == "GATTOperationFailsAfterReconnectionAdapter") { | 218 if (fake_adapter_name == "GATTOperationFailsAfterReconnectionAdapter") { |
| 219 return GetGATTOperationFinishesAfterReconnectionAdapter( | 219 return GetGATTOperationFinishesAfterReconnectionAdapter( |
| 220 false /* disconnect */, false /* succeeds */); | 220 false /* disconnect */, false /* succeeds */); |
| 221 } | 221 } |
| 222 if (fake_adapter_name == "DisconnectingDuringStopNotifySessionAdapter") { |
| 223 return GetStopNotifySessionFinishesAfterReconnectionAdapter( |
| 224 true /* disconnect */); |
| 225 } |
| 226 if (fake_adapter_name == |
| 227 "StopNotifySessionFinishesAfterReconnectionAdapter") { |
| 228 return GetStopNotifySessionFinishesAfterReconnectionAdapter( |
| 229 false /* disconnect */); |
| 230 } |
| 222 if (fake_adapter_name == "BlacklistTestAdapter") | 231 if (fake_adapter_name == "BlacklistTestAdapter") |
| 223 return GetBlacklistTestAdapter(); | 232 return GetBlacklistTestAdapter(); |
| 224 if (fake_adapter_name == "FailingConnectionsAdapter") | 233 if (fake_adapter_name == "FailingConnectionsAdapter") |
| 225 return GetFailingConnectionsAdapter(); | 234 return GetFailingConnectionsAdapter(); |
| 226 if (fake_adapter_name == "FailingGATTOperationsAdapter") | 235 if (fake_adapter_name == "FailingGATTOperationsAdapter") |
| 227 return GetFailingGATTOperationsAdapter(); | 236 return GetFailingGATTOperationsAdapter(); |
| 228 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") | 237 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") |
| 229 return GetSecondDiscoveryFindsHeartRateAdapter(); | 238 return GetSecondDiscoveryFindsHeartRateAdapter(); |
| 230 if (fake_adapter_name == "DeviceEventAdapter") | 239 if (fake_adapter_name == "DeviceEventAdapter") |
| 231 return GetDeviceEventAdapter(); | 240 return GetDeviceEventAdapter(); |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 base::ThreadTaskRunnerHandle::Get()->PostTask( | 995 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 987 FROM_HERE, | 996 FROM_HERE, |
| 988 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), | 997 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), |
| 989 device_ptr)); | 998 device_ptr)); |
| 990 } | 999 } |
| 991 })); | 1000 })); |
| 992 | 1001 |
| 993 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); | 1002 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); |
| 994 device->AddMockService(std::move(health_thermometer)); | 1003 device->AddMockService(std::move(health_thermometer)); |
| 995 adapter->AddMockDevice(std::move(device)); | 1004 adapter->AddMockDevice(std::move(device)); |
| 1005 return adapter; |
| 1006 } |
| 1007 |
| 1008 // static |
| 1009 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider:: |
| 1010 GetStopNotifySessionFinishesAfterReconnectionAdapter(bool disconnect) { |
| 1011 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 1012 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); |
| 1013 |
| 1014 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice( |
| 1015 adapter_ptr, "GATT Operation finishes after reconnection Device", |
| 1016 BluetoothDevice::UUIDList({BluetoothUUID(kGenericAccessServiceUUID), |
| 1017 BluetoothUUID(kHealthThermometerUUID)}))); |
| 1018 NiceMockBluetoothDevice* device_ptr = device.get(); |
| 1019 |
| 1020 ON_CALL(*device, CreateGattConnection(_, _)) |
| 1021 .WillByDefault(Invoke([adapter_ptr, device_ptr]( |
| 1022 const BluetoothDevice::GattConnectionCallback& callback, |
| 1023 const BluetoothDevice::ConnectErrorCallback& error_callback) { |
| 1024 callback.Run(base::MakeUnique<NiceMockBluetoothGattConnection>( |
| 1025 adapter_ptr, device_ptr->GetAddress())); |
| 1026 device_ptr->RunPendingCallbacks(); |
| 1027 })); |
| 1028 |
| 1029 device->AddMockService(GetGenericAccessService(device.get())); |
| 1030 |
| 1031 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer( |
| 1032 GetBaseGATTService("Health Thermometer", device.get(), |
| 1033 kHealthThermometerUUID)); |
| 1034 |
| 1035 // Measurement Interval |
| 1036 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval( |
| 1037 GetBaseGATTCharacteristic( |
| 1038 "Measurement Interval", health_thermometer.get(), |
| 1039 kMeasurementIntervalUUID, |
| 1040 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY)); |
| 1041 NiceMockBluetoothGattCharacteristic* measurement_ptr = |
| 1042 measurement_interval.get(); |
| 1043 |
| 1044 ON_CALL(*measurement_interval, StartNotifySession(_, _)) |
| 1045 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
| 1046 [adapter_ptr, device_ptr, measurement_ptr, disconnect]() { |
| 1047 std::unique_ptr<NiceMockBluetoothGattNotifySession> notify_session = |
| 1048 base::MakeUnique<NiceMockBluetoothGattNotifySession>( |
| 1049 measurement_ptr->GetWeakPtr()); |
| 1050 |
| 1051 ON_CALL(*notify_session, Stop(_)) |
| 1052 .WillByDefault(Invoke([adapter_ptr, device_ptr, disconnect]( |
| 1053 const base::Closure& callback) { |
| 1054 |
| 1055 device_ptr->PushPendingCallback(callback); |
| 1056 |
| 1057 if (disconnect) { |
| 1058 device_ptr->SetConnected(false); |
| 1059 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1060 FROM_HERE, |
| 1061 base::Bind(&NotifyDeviceChanged, |
| 1062 base::RetainedRef(adapter_ptr), device_ptr)); |
| 1063 } |
| 1064 })); |
| 1065 return notify_session; |
| 1066 })); |
| 1067 |
| 1068 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); |
| 1069 device->AddMockService(std::move(health_thermometer)); |
| 1070 adapter->AddMockDevice(std::move(device)); |
| 996 | 1071 |
| 997 return adapter; | 1072 return adapter; |
| 998 } | 1073 } |
| 999 | 1074 |
| 1000 // static | 1075 // static |
| 1001 scoped_refptr<NiceMockBluetoothAdapter> | 1076 scoped_refptr<NiceMockBluetoothAdapter> |
| 1002 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { | 1077 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { |
| 1003 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 1078 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 1004 | 1079 |
| 1005 BluetoothDevice::UUIDList uuids; | 1080 BluetoothDevice::UUIDList uuids; |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 return BluetoothUUID(); | 1666 return BluetoothUUID(); |
| 1592 } | 1667 } |
| 1593 | 1668 |
| 1594 // static | 1669 // static |
| 1595 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1670 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
| 1596 return BluetoothDevice::CanonicalizeAddress( | 1671 return BluetoothDevice::CanonicalizeAddress( |
| 1597 base::StringPrintf("%012" PRIx64, addr)); | 1672 base::StringPrintf("%012" PRIx64, addr)); |
| 1598 } | 1673 } |
| 1599 | 1674 |
| 1600 } // namespace content | 1675 } // namespace content |
| OLD | NEW |