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
>>
45 // |ScanFilterCheckingAdapter|
46 // Inherits from |BaseAdapter|
47 // BluetoothAdapter that asserts that its StartDiscoverySessionWithFilter()
48 // method is called with a filter consisting of the standard battery, heart
49 // rate, and glucose services.
53 // - StartDiscoverySessionWithFilter:
54 // - With correct arguments: Run success callback.
55 // - With incorrect arguments: Mock complains that function with
56 // correct arguments was never called and error callback is called.
57 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
58 GetScanFilterCheckingAdapter();
60 // |FailStartDiscoveryAdapter|
61 // Inherits from |BaseAdapter|
65 // - StartDiscoverySessionWithFilter:
66 // Run error callback.
67 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
68 GetFailStartDiscoveryAdapter();
71 // Inherits from |BaseAdapter|
75 // - StartDiscoverySessionWithFilter:
76 // Run success callback with |DiscoverySession|.
77 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
80 // |GlucoseHeartRateAdapter|
81 // Inherits from |EmptyAdapter|
84 // - |HeartRateDevice|
85 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
86 GetGlucoseHeartRateAdapter();
88 // |MissingServiceGenericAccessAdapter|
89 // Inherits from |EmptyAdapter|
90 // Internal Structure:
91 // - Generic Access Device
92 // - Generic Access UUID (0x1800)
93 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
94 GetMissingServiceGenericAccessAdapter();
96 // |MissingCharacteristicGenericAccessAdapter|
97 // Inherits from |EmptyAdapter|
98 // Internal Structure:
99 // - Generic Access Device
100 // - Generic Access UUID (0x1800)
101 // - Generic Access Service
102 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
103 GetMissingCharacteristicGenericAccessAdapter();
105 // |GenericAccessAdapter|
106 // Inherits from |EmptyAdapter|
107 // Internal Structure:
108 // - Generic Access Device
109 // - Generic Access UUID (0x1800)
110 // - Generic Access Service
111 // - Device Name Characteristic:
113 // - Read: Calls success callback with device's name.
114 // - Write: Calls success callback.
115 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
116 GetGenericAccessAdapter();
118 // |FailingConnectionsAdapter|
119 // Inherits from |BaseAdapter|
120 // FailingConnectionsAdapter holds a device for each type of connection error
121 // that can occur. This way we don’t need to create an adapter for each type
122 // of error. Each of the devices has a service with a different UUID so that
123 // they can be accessed by using different filters.
124 // See errorUUID() declaration below.
125 // Internal Structure:
126 // - UnconnectableDevice(BluetoothDevice::ERROR_UNKNOWN) errorUUID(0x0)
127 // - UnconnectableDevice(BluetoothDevice::ERROR_INPROGRESS) errorUUID(0x1)
128 // - UnconnectableDevice(BluetoothDevice::ERROR_FAILED) errorUUID(0x2)
129 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_FAILED) errorUUID(0x3)
130 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_CANCELED) errorUUID(0x4)
131 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_REJECTED) errorUUID(0x5)
132 // - UnconnectableDevice(BluetoothDevice::ERROR_AUTH_TIMEOUT) errorUUID(0x6)
133 // - UnconnectableDevice(BluetoothDevice::ERROR_UNSUPPORTED_DEVICE)
135 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
136 GetFailingConnectionsAdapter();
138 // |FailingGATTOperationsAdapter|
139 // Inherits from |EmptyAdapter|
140 // FailingGATTOperationsAdapter holds a device with one
141 // service: ErrorsService. This service contains a characteristic for each
142 // type of GATT Error that can be thrown. Trying to write or read from these
143 // characteristics results in the corresponding error being returned.
144 // Internal Structure:
146 // - ErrorsService errorUUID(0xA0)
147 // - ErrorCharacteristic(
148 // BluetoothGattService::GATT_ERROR_UNKNOWN)
150 // - ErrorCharacteristic(
151 // BluetoothGattService::GATT_ERROR_FAILED)
153 // - ErrorCharacteristic(
154 // BluetoothGattService::GATT_ERROR_IN_PROGRESS)
156 // - ErrorCharacteristic(
157 // BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
159 // - ErrorCharacteristic(
160 // BluetoothGattService::GATT_ERROR_NOT_PERMITTED)
162 // - ErrorCharacteristic(
163 // BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED)
165 // - ErrorCharacteristic(
166 // BluetoothGattService::GATT_ERROR_NOT_PAIRED)
168 // - ErrorCharacteristic(
169 // BluetoothGattService::GATT_ERROR_NOT_SUPPORTED)
171 static scoped_refptr
<testing::NiceMock
<device::MockBluetoothAdapter
>>
172 GetFailingGATTOperationsAdapter();
174 // Discovery Sessions
176 // |DiscoverySession|
179 // Run success callback.
180 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDiscoverySession
>>
181 GetDiscoverySession();
193 // - GetGattServices:
194 // Returns a list of all services added to the device.
196 // Return a service matching the identifier provided if the service was
197 // added to the mock.
201 // Returns: device_name.
202 // - GetBluetoothClass:
203 // Returns: 0x1F00. “Unspecified Device Class” see
204 // bluetooth.org/en-us/specification/assigned-numbers/baseband
205 // - GetVendorIDSource:
206 // Returns: BluetoothDevice::VENDOR_ID_BLUETOOTH.
215 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
216 GetBaseDevice(device::MockBluetoothAdapter
* adapter
,
217 const std::string
& device_name
= "Base Device",
218 device::BluetoothDevice::UUIDList uuids
=
219 device::BluetoothDevice::UUIDList(),
220 const std::string
& address
= "00:00:00:00:00:00");
223 // Inherits from |BaseDevice|(adapter, "Battery Device", uuids,
224 // "00:00:00:00:00:01")
226 // - Generic Access (0x1800)
227 // - Battery Service UUID (0x180F)
230 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
231 GetBatteryDevice(device::MockBluetoothAdapter
* adapter
);
234 // Inherits from |BaseDevice|(adapter, "Glucose Device", uuids,
235 // "00:00:00:00:00:02")
237 // - Generic Access (0x1800)
238 // - Glucose UUID (0x1808)
241 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
242 GetGlucoseDevice(device::MockBluetoothAdapter
* adapter
);
245 // Inherits from |BaseDevice|(adapter, "Heart Rate Device", uuids,
246 // "00:00:00:00:00:03")
248 // - Generic Access (0x1800)
249 // - Heart Rate UUID (0x180D)
252 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
253 GetHeartRateDevice(device::MockBluetoothAdapter
* adapter
);
255 // |ConnectableDevice|
256 // Inherits from |BaseDevice|(adapter, device_name)
262 // - CreateGattConnection:
263 // - Run success callback with BaseGATTConnection
264 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
265 GetConnectableDevice(
266 device::MockBluetoothAdapter
* adapter
,
267 const std::string
& device_name
= "Connectable Device",
268 device::BluetoothDevice::UUIDList
= device::BluetoothDevice::UUIDList());
270 // |UnconnectableDevice|
271 // Inherits from |BaseDevice|(adapter, device_name)
273 // - errorUUID(error_code)
277 // - CreateGATTConnection:
278 // - Run error callback with error_type
279 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
280 GetUnconnectableDevice(
281 device::MockBluetoothAdapter
* adapter
,
282 device::BluetoothDevice::ConnectErrorCode error_code
,
283 const std::string
& device_name
= "Unconnectable Device");
285 // |GenericAccessDevice|
286 // Inherits from |ConnectableDevice|(adapter, device_name)
288 // - Generic Access UUID (0x1800)
290 // None. Each user of the GenericAccessDevice is in charge of adding the
291 // relevant services, characteristics, and descriptors.
292 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothDevice
>>
293 GetGenericAccessDevice(
294 device::MockBluetoothAdapter
* adapter
,
295 const std::string
& device_name
= "Generic Access Device");
300 // Characteristics added:
303 // - GetCharacteristics:
304 // Returns a list with all the characteristics added to the service
305 // - GetCharacteristic:
306 // Returns a characteristic matching the identifier provided if the
307 // characteristic was added to the mock.
309 // Returns: uuid + “ Identifier”
318 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothGattService
>>
319 GetBaseGATTService(device::MockBluetoothDevice
* device
,
320 const std::string
& uuid
);
324 // |BaseCharacteristic|(service, uuid)
325 // Descriptors added:
328 // - TODO(ortuno): http://crbug.com/483347 GetDescriptors:
329 // Returns: all descriptors added to the characteristic
330 // - TODO(ortuno): http://crbug.com/483347 GetDescriptor:
331 // Returns the descriptor matching the identifier provided if the
332 // descriptor was added to the characteristic.
334 // Returns: uuid + “ Identifier”
345 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothGattCharacteristic
>>
346 GetBaseGATTCharacteristic(device::MockBluetoothGattService
* service
,
347 const std::string
& uuid
);
349 // |ErrorCharacteristic|(service, error_type)
350 // Inherits from BaseCharacteristic(service, errorUUID(error_type + 0xA1))
351 // Descriptors added:
354 // - ReadRemoteCharacteristic:
355 // Run error callback with error_type
356 // - WriteRemoteCharacteristic:
357 // Run error callback with error_type
358 static scoped_ptr
<testing::NiceMock
<device::MockBluetoothGattCharacteristic
>>
359 GetErrorCharacteristic(
360 device::MockBluetoothGattService
* service
,
361 device::BluetoothGattService::GattErrorCode error_code
);
365 // errorUUID(alias) returns a UUID with the top 32 bits of
366 // "00000000-97e5-4cd7-b9f1-f5a427670c59" replaced with the bits of |alias|.
367 // For example, errorUUID(0xDEADBEEF) returns
368 // "deadbeef-97e5-4cd7-b9f1-f5a427670c59". The bottom 96 bits of error UUIDs
369 // were generated as a type 4 (random) UUID.
370 static std::string
errorUUID(uint32_t alias
);
372 // Function to turn an integer into an MAC address of the form
373 // XX:XX:XX:XX:XX:XX. For example makeMACAddress(0xdeadbeef)
374 // returns "00:00:DE:AD:BE:EF".
375 static std::string
makeMACAddress(uint64_t addr
);
378 } // namespace content
380 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_BLUETOOTH_ADAPTER_PROVIDER_H_