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 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
| 11 #include <string> |
| 12 #include <vector> |
11 | 13 |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
15 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
16 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
17 #include "device/bluetooth/bluetooth_discovery_session.h" | 19 #include "device/bluetooth/bluetooth_discovery_session.h" |
18 #include "device/bluetooth/bluetooth_gatt_connection.h" | 20 #include "device/bluetooth/bluetooth_gatt_connection.h" |
19 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 21 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
20 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 22 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 66 |
65 // Calls adapter_->StartDiscoverySessionWithFilter with Low Energy transport, | 67 // Calls adapter_->StartDiscoverySessionWithFilter with Low Energy transport, |
66 // and this fixture's callbacks expecting error. | 68 // and this fixture's callbacks expecting error. |
67 // Then RunLoop().RunUntilIdle(). | 69 // Then RunLoop().RunUntilIdle(). |
68 void StartLowEnergyDiscoverySessionExpectedToFail(); | 70 void StartLowEnergyDiscoverySessionExpectedToFail(); |
69 | 71 |
70 // Check if Low Energy is available. On Mac, we require OS X >= 10.10. | 72 // Check if Low Energy is available. On Mac, we require OS X >= 10.10. |
71 virtual bool PlatformSupportsLowEnergy() = 0; | 73 virtual bool PlatformSupportsLowEnergy() = 0; |
72 | 74 |
73 // Initializes the BluetoothAdapter |adapter_| with the system adapter. | 75 // Initializes the BluetoothAdapter |adapter_| with the system adapter. |
74 virtual void InitWithDefaultAdapter(){}; | 76 virtual void InitWithDefaultAdapter() {} |
75 | 77 |
76 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced | 78 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced |
77 // to be ignored as if it did not exist. This enables tests for when an | 79 // to be ignored as if it did not exist. This enables tests for when an |
78 // adapter is not present on the system. | 80 // adapter is not present on the system. |
79 virtual void InitWithoutDefaultAdapter(){}; | 81 virtual void InitWithoutDefaultAdapter() {} |
80 | 82 |
81 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be | 83 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be |
82 // controlled by this test fixture. | 84 // controlled by this test fixture. |
83 virtual void InitWithFakeAdapter(){}; | 85 virtual void InitWithFakeAdapter() {} |
84 | 86 |
85 // Configures the fake adapter to lack the necessary permissions to scan for | 87 // Configures the fake adapter to lack the necessary permissions to scan for |
86 // devices. Returns false if the current platform always has permission. | 88 // devices. Returns false if the current platform always has permission. |
87 virtual bool DenyPermission(); | 89 virtual bool DenyPermission(); |
88 | 90 |
89 // Create a fake Low Energy device and discover it. | 91 // Create a fake Low Energy device and discover it. |
90 // |device_ordinal| selects between multiple fake device data sets to produce: | 92 // |device_ordinal| selects between multiple fake device data sets to produce: |
91 // 1: kTestDeviceName with advertised UUIDs kTestUUIDGenericAccess, | 93 // 1: kTestDeviceName with advertised UUIDs kTestUUIDGenericAccess, |
92 // kTestUUIDGenericAttribute and address kTestDeviceAddress1. | 94 // kTestUUIDGenericAttribute and address kTestDeviceAddress1. |
93 // 2: kTestDeviceName with advertised UUIDs kTestUUIDImmediateAlert, | 95 // 2: kTestDeviceName with advertised UUIDs kTestUUIDImmediateAlert, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // Simulates a Characteristic Write operation failing synchronously once for | 208 // Simulates a Characteristic Write operation failing synchronously once for |
207 // an unknown reason. | 209 // an unknown reason. |
208 virtual void SimulateGattCharacteristicWriteWillFailSynchronouslyOnce( | 210 virtual void SimulateGattCharacteristicWriteWillFailSynchronouslyOnce( |
209 BluetoothRemoteGattCharacteristic* characteristic) {} | 211 BluetoothRemoteGattCharacteristic* characteristic) {} |
210 | 212 |
211 // Simulates a Descriptor on a service. | 213 // Simulates a Descriptor on a service. |
212 virtual void SimulateGattDescriptor( | 214 virtual void SimulateGattDescriptor( |
213 BluetoothRemoteGattCharacteristic* characteristic, | 215 BluetoothRemoteGattCharacteristic* characteristic, |
214 const std::string& uuid) {} | 216 const std::string& uuid) {} |
215 | 217 |
| 218 // Simulates reading a value from a locally hosted GATT characteristic by a |
| 219 // remote central device. Returns the value that was read from the local |
| 220 // GATT characteristic in the value callback. |
| 221 virtual void SimulateLocalGattCharacteristicValueReadRequest( |
| 222 BluetoothLocalGattService* service, |
| 223 BluetoothLocalGattCharacteristic* characteristic, |
| 224 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, |
| 225 const base::Closure& error_callback) {} |
| 226 |
| 227 // Simulates write a value to a locally hosted GATT characteristic by a |
| 228 // remote central device. |
| 229 virtual void SimulateLocalGattCharacteristicValueWriteRequest( |
| 230 BluetoothLocalGattService* service, |
| 231 BluetoothLocalGattCharacteristic* characteristic, |
| 232 const std::vector<uint8_t>& value_to_write, |
| 233 const base::Closure& success_callback, |
| 234 const base::Closure& error_callback) {} |
| 235 |
| 236 // Simulates reading a value from a locally hosted GATT descriptor by a |
| 237 // remote central device. Returns the value that was read from the local |
| 238 // GATT descriptor in the value callback. |
| 239 virtual void SimulateLocalGattDescriptorValueReadRequest( |
| 240 BluetoothLocalGattService* service, |
| 241 BluetoothLocalGattDescriptor* descriptor, |
| 242 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, |
| 243 const base::Closure& error_callback) {} |
| 244 |
| 245 // Simulates write a value to a locally hosted GATT descriptor by a |
| 246 // remote central device. |
| 247 virtual void SimulateLocalGattDescriptorValueWriteRequest( |
| 248 BluetoothLocalGattService* service, |
| 249 BluetoothLocalGattDescriptor* descriptor, |
| 250 const std::vector<uint8_t>& value_to_write, |
| 251 const base::Closure& success_callback, |
| 252 const base::Closure& error_callback) {} |
| 253 |
216 // Remembers |descriptor|'s platform specific object to be used in a | 254 // Remembers |descriptor|'s platform specific object to be used in a |
217 // subsequent call to methods such as SimulateGattDescriptorRead that | 255 // subsequent call to methods such as SimulateGattDescriptorRead that |
218 // accept a nullptr value to select this remembered descriptor. This | 256 // accept a nullptr value to select this remembered descriptor. This |
219 // enables tests where the platform attempts to reference descriptor | 257 // enables tests where the platform attempts to reference descriptor |
220 // objects after the Chrome objects have been deleted, e.g. with DeleteDevice. | 258 // objects after the Chrome objects have been deleted, e.g. with DeleteDevice. |
221 virtual void RememberDescriptorForSubsequentAction( | 259 virtual void RememberDescriptorForSubsequentAction( |
222 BluetoothRemoteGattDescriptor* descriptor) {} | 260 BluetoothRemoteGattDescriptor* descriptor) {} |
223 | 261 |
224 // Simulates a Descriptor Read operation succeeding, returning |value|. | 262 // Simulates a Descriptor Read operation succeeding, returning |value|. |
225 // If |descriptor| is null, acts upon the descriptor provided to | 263 // If |descriptor| is null, acts upon the descriptor provided to |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 int actual_error_callback_calls_ = 0; | 361 int actual_error_callback_calls_ = 0; |
324 bool unexpected_success_callback_ = false; | 362 bool unexpected_success_callback_ = false; |
325 bool unexpected_error_callback_ = false; | 363 bool unexpected_error_callback_ = false; |
326 | 364 |
327 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; | 365 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; |
328 }; | 366 }; |
329 | 367 |
330 } // namespace device | 368 } // namespace device |
331 | 369 |
332 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 370 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
OLD | NEW |