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
3 // found in the LICENSE file.
5 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_BLUETOOTH_ADAPTER_PROVIDER_H_
6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_BLUETOOTH_ADAPTER_PROVIDER_H_
8 #include "base/callback.h"
9 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
10 #include "device/bluetooth/test/mock_bluetooth_device.h"
11 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
12 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
13 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h"
17 // Implements fake adapters with named mock data set for use in tests as a
18 // result of layout tests calling testRunner.setBluetoothMockDataSet.
20 // We have a complete “GenericAccessAdapter”, meaning it has a device which has
21 // a Generic Access service with a Device Name characteristic with a descriptor.
22 // The other adapters are named based on their particular non-expected behavior.
24 class LayoutTestBluetoothAdapterProvider
{
26 // Returns a BluetoothAdapter. Its behavior depends on |fake_adapter_name|.
27 static scoped_refptr
<device::BluetoothAdapter
> GetBluetoothAdapter(
28 const std::string
& fake_adapter_name
);
38 // Returns a list of devices added to the adapter.
40 // Returns a device matching the address provided if the device was
41 // added to the adapter.
42 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
46 // Inherits from |BaseAdapter|
50 // - IsPresent: Returns true
51 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
54 // |NotPresentAdapter|
55 // Inherits from |BaseAdapter|
59 // - IsPresent: Returns false
60 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
61 GetNotPresentAdapter();
64 // Inherits from |PresentAdapter|
68 // - IsPowered: Returns true
69 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
72 // |NotPoweredAdapter|
73 // Inherits from |PresentAdapter|
77 // - IsPowered: Returns false
78 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
79 GetNotPoweredAdapter();
81 // |ScanFilterCheckingAdapter|
82 // Inherits from |PoweredAdapter|
83 // BluetoothAdapter that asserts that its StartDiscoverySessionWithFilter()
84 // method is called with a filter consisting of the standard battery, heart
85 // rate, and glucose services.
89 // - StartDiscoverySessionWithFilter:
90 // - With correct arguments: Run success callback.
91 // - With incorrect arguments: Mock complains that function with
92 // correct arguments was never called and error callback is called.
93 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
94 GetScanFilterCheckingAdapter();
96 // |FailStartDiscoveryAdapter|
97 // Inherits from |PoweredAdapter|
101 // - StartDiscoverySessionWithFilter:
102 // Run error callback.
103 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
104 GetFailStartDiscoveryAdapter();
107 // Inherits from |PoweredAdapter|
111 // - StartDiscoverySessionWithFilter:
112 // Run success callback with |DiscoverySession|.
113 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
116 // |GlucoseHeartRateAdapter|
117 // Inherits from |EmptyAdapter|
120 // - |HeartRateDevice|
121 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
122 GetGlucoseHeartRateAdapter();
124 // |MissingServiceGenericAccessAdapter|
125 // Inherits from |EmptyAdapter|
126 // Internal Structure:
127 // - Generic Access Device
128 // - Generic Access UUID (0x1800)
129 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
130 GetMissingServiceGenericAccessAdapter();
132 // |MissingCharacteristicGenericAccessAdapter|
133 // Inherits from |EmptyAdapter|
134 // Internal Structure:
135 // - Generic Access Device
136 // - Generic Access UUID (0x1800)
137 // - Generic Access Service
138 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
139 GetMissingCharacteristicGenericAccessAdapter();
141 // |GenericAccessAdapter|
142 // Inherits from |EmptyAdapter|
143 // Internal Structure:
144 // - Generic Access Device
145 // - Generic Access UUID (0x1800)
146 // - Generic Access Service
147 // - Device Name Characteristic:
149 // - Read: Calls success callback with device's name.
150 // - Write: Calls success callback.
151 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
152 GetGenericAccessAdapter();
154 // |FailingConnectionsAdapter|
155 // Inherits from |EmptyAdapter|
156 // FailingConnectionsAdapter holds a device for each type of connection error
157 // that can occur. This way we don’t need to create an adapter for each type
158 // of error. Each of the devices has a service with a different UUID so that
159 // they can be accessed by using different filters.
160 // See errorUUID() declaration below.
161 // Internal Structure:
162 // - UnconnectableDevice(BluetoothDevice::ERROR_UNKNOWN) errorUUID(0x0)
163 // - UnconnectableDevice(BluetoothDevice::ERROR_INPROGRESS) errorUUID(0x1)
164 // - UnconnectableDevice(BluetoothDevice::ERROR_FAILED) errorUUID(0x2)
165 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_FAILED) errorUUID(0x3)
166 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_CANCELED) errorUUID(0x4)
167 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_REJECTED) errorUUID(0x5)
168 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_TIMEOUT) errorUUID(0x6)
169 // - UnconnectableDevice(BluetoothDevice::ERROR_UNSUPPORTED_DEVICE)
171 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
172 GetFailingConnectionsAdapter();
174 // |FailingGATTOperationsAdapter|
175 // Inherits from |EmptyAdapter|
176 // FailingGATTOperationsAdapter holds a device with one
177 // service: ErrorsService. This service contains a characteristic for each
178 // type of GATT Error that can be thrown. Trying to write or read from these
179 // characteristics results in the corresponding error being returned.
180 // Internal Structure:
182 // - ErrorsService errorUUID(0xA0)
183 // - ErrorCharacteristic(
184 // BluetoothGattService::GATT_ERROR_UNKNOWN)
186 // - ErrorCharacteristic(
187 // BluetoothGattService::GATT_ERROR_FAILED)
189 // - ErrorCharacteristic(
190 // BluetoothGattService::GATT_ERROR_IN_PROGRESS)
192 // - ErrorCharacteristic(
193 // BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
195 // - ErrorCharacteristic(
196 // BluetoothGattService::GATT_ERROR_NOT_PERMITTED)
198 // - ErrorCharacteristic(
199 // BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED)
201 // - ErrorCharacteristic(
202 // BluetoothGattService::GATT_ERROR_NOT_PAIRED)
204 // - ErrorCharacteristic(
205 // BluetoothGattService::GATT_ERROR_NOT_SUPPORTED)
207 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
208 GetFailingGATTOperationsAdapter();
210 // Discovery Sessions
212 // |DiscoverySession|
215 // Run success callback.
216 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDiscoverySession
>>
217 GetDiscoverySession();
229 // - GetGattServices:
230 // Returns a list of all services added to the device.
232 // Return a service matching the identifier provided if the service was
233 // added to the mock.
237 // Returns: device_name.
238 // - GetBluetoothClass:
239 // Returns: 0x1F00. “Unspecified Device Class” see
240 // bluetooth.org/en-us/specification/assigned-numbers/baseband
241 // - GetVendorIDSource:
242 // Returns: BluetoothDevice::VENDOR_ID_BLUETOOTH.
251 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
252 GetBaseDevice(device::MockBluetoothAdapter
* adapter
,
253 const std::string
& device_name
= "Base Device",
254 device::BluetoothDevice::UUIDList uuids
=
255 device::BluetoothDevice::UUIDList(),
256 const std::string
& address
= "00:00:00:00:00:00");
259 // Inherits from |BaseDevice|(adapter, "Battery Device", uuids,
260 // "00:00:00:00:00:01")
262 // - Generic Access (0x1800)
263 // - Battery Service UUID (0x180F)
266 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
267 GetBatteryDevice(device::MockBluetoothAdapter
* adapter
);
270 // Inherits from |BaseDevice|(adapter, "Glucose Device", uuids,
271 // "00:00:00:00:00:02")
273 // - Generic Access (0x1800)
274 // - Glucose UUID (0x1808)
277 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
278 GetGlucoseDevice(device::MockBluetoothAdapter
* adapter
);
281 // Inherits from |BaseDevice|(adapter, "Heart Rate Device", uuids,
282 // "00:00:00:00:00:03")
284 // - Generic Access (0x1800)
285 // - Heart Rate UUID (0x180D)
288 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
289 GetHeartRateDevice(device::MockBluetoothAdapter
* adapter
);
291 // |ConnectableDevice|
292 // Inherits from |BaseDevice|(adapter, device_name)
298 // - CreateGattConnection:
299 // - Run success callback with BaseGATTConnection
300 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
301 GetConnectableDevice(
302 device::MockBluetoothAdapter
* adapter
,
303 const std::string
& device_name
= "Connectable Device",
304 device::BluetoothDevice::UUIDList
= device::BluetoothDevice::UUIDList());
306 // |UnconnectableDevice|
307 // Inherits from |BaseDevice|(adapter, device_name)
309 // - errorUUID(error_code)
313 // - CreateGATTConnection:
314 // - Run error callback with error_type
315 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
316 GetUnconnectableDevice(
317 device::MockBluetoothAdapter
* adapter
,
318 device::BluetoothDevice::ConnectErrorCode error_code
,
319 const std::string
& device_name
= "Unconnectable Device");
321 // |GenericAccessDevice|
322 // Inherits from |ConnectableDevice|(adapter, device_name)
324 // - Generic Access UUID (0x1800)
326 // None. Each user of the GenericAccessDevice is in charge of adding the
327 // relevant services, characteristics, and descriptors.
328 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
329 GetGenericAccessDevice(
330 device::MockBluetoothAdapter
* adapter
,
331 const std::string
& device_name
= "Generic Access Device");
336 // Characteristics added:
339 // - GetCharacteristics:
340 // Returns a list with all the characteristics added to the service
341 // - GetCharacteristic:
342 // Returns a characteristic matching the identifier provided if the
343 // characteristic was added to the mock.
345 // Returns: uuid + “ Identifier”
354 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothGattService
>>
355 GetBaseGATTService(device::MockBluetoothDevice
* device
,
356 const std::string
& uuid
);
360 // |BaseCharacteristic|(service, uuid)
361 // Descriptors added:
364 // - TODO(ortuno): http://crbug.com/483347 GetDescriptors:
365 // Returns: all descriptors added to the characteristic
366 // - TODO(ortuno): http://crbug.com/483347 GetDescriptor:
367 // Returns the descriptor matching the identifier provided if the
368 // descriptor was added to the characteristic.
370 // Returns: uuid + “ Identifier”
381 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothGattCharacteristic
>>
382 GetBaseGATTCharacteristic(device::MockBluetoothGattService
* service
,
383 const std::string
& uuid
);
385 // |ErrorCharacteristic|(service, error_type)
386 // Inherits from BaseCharacteristic(service, errorUUID(error_type + 0xA1))
387 // Descriptors added:
390 // - ReadRemoteCharacteristic:
391 // Run error callback with error_type
392 // - WriteRemoteCharacteristic:
393 // Run error callback with error_type
394 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothGattCharacteristic
>>
395 GetErrorCharacteristic(
396 device::MockBluetoothGattService
* service
,
397 device::BluetoothGattService::GattErrorCode error_code
);
401 // errorUUID(alias) returns a UUID with the top 32 bits of
402 // "00000000-97e5-4cd7-b9f1-f5a427670c59" replaced with the bits of |alias|.
403 // For example, errorUUID(0xDEADBEEF) returns
404 // "deadbeef-97e5-4cd7-b9f1-f5a427670c59". The bottom 96 bits of error UUIDs
405 // were generated as a type 4 (random) UUID.
406 static std::string
errorUUID(uint32_t alias
);
408 // Function to turn an integer into an MAC address of the form
409 // XX:XX:XX:XX:XX:XX. For example makeMACAddress(0xdeadbeef)
410 // returns "00:00:DE:AD:BE:EF".
411 static std::string
makeMACAddress(uint64_t addr
);
414 } // namespace content
416 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_BLUETOOTH_ADAPTER_PROVIDER_H_