Roll src/third_party/skia 2440fcd:4de8c3a
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_bluetooth_adapter_provider.h
blob9d52de934c1d4b9ee2631142262174339c5b0ee4
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"
15 namespace content {
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 {
25 public:
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);
30 private:
31 // Adapters
33 // |BaseAdapter|
34 // Devices added:
35 // None.
36 // Mock Functions:
37 // - GetDevices:
38 // Returns a list of devices added to the adapter.
39 // - GetDevice:
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>>
43 GetBaseAdapter();
45 // |PresentAdapter|
46 // Inherits from |BaseAdapter|
47 // Devices added:
48 // None.
49 // Mock Functions:
50 // - IsPresent: Returns true
51 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
52 GetPresentAdapter();
54 // |NotPresentAdapter|
55 // Inherits from |BaseAdapter|
56 // Devices added:
57 // None.
58 // Mock Functions:
59 // - IsPresent: Returns false
60 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
61 GetNotPresentAdapter();
63 // |PoweredAdapter|
64 // Inherits from |PresentAdapter|
65 // Devices added:
66 // None.
67 // Mock Functions:
68 // - IsPowered: Returns true
69 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
70 GetPoweredAdapter();
72 // |NotPoweredAdapter|
73 // Inherits from |PresentAdapter|
74 // Devices added:
75 // None.
76 // Mock Functions:
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.
86 // Devices added:
87 // - |BatteryDevice|
88 // Mock Functions:
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|
98 // Devices added:
99 // None.
100 // Mock Functions:
101 // - StartDiscoverySessionWithFilter:
102 // Run error callback.
103 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
104 GetFailStartDiscoveryAdapter();
106 // |EmptyAdapter|
107 // Inherits from |PoweredAdapter|
108 // Devices Added:
109 // None.
110 // Mock Functions:
111 // - StartDiscoverySessionWithFilter:
112 // Run success callback with |DiscoverySession|.
113 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
114 GetEmptyAdapter();
116 // |GlucoseHeartRateAdapter|
117 // Inherits from |EmptyAdapter|
118 // Devices added:
119 // - |GlucoseDevice|
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:
148 // - Mock Functions:
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)
170 // errorUUID(0x7)
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:
181 // - ErrorsDevice
182 // - ErrorsService errorUUID(0xA0)
183 // - ErrorCharacteristic(
184 // BluetoothGattService::GATT_ERROR_UNKNOWN)
185 // errorUUID(0xA1)
186 // - ErrorCharacteristic(
187 // BluetoothGattService::GATT_ERROR_FAILED)
188 // errorUUID(0xA2)
189 // - ErrorCharacteristic(
190 // BluetoothGattService::GATT_ERROR_IN_PROGRESS)
191 // errorUUID(0xA3)
192 // - ErrorCharacteristic(
193 // BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
194 // errorUUID(0xA4)
195 // - ErrorCharacteristic(
196 // BluetoothGattService::GATT_ERROR_NOT_PERMITTED)
197 // errorUUID(0xA5)
198 // - ErrorCharacteristic(
199 // BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED)
200 // errorUUID(0xA6)
201 // - ErrorCharacteristic(
202 // BluetoothGattService::GATT_ERROR_NOT_PAIRED)
203 // errorUUID(0xA7)
204 // - ErrorCharacteristic(
205 // BluetoothGattService::GATT_ERROR_NOT_SUPPORTED)
206 // errorUUID(0xA8)
207 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
208 GetFailingGATTOperationsAdapter();
210 // Discovery Sessions
212 // |DiscoverySession|
213 // Mock Functions:
214 // - Stop:
215 // Run success callback.
216 static scoped_ptr<testing::NiceMock<device::MockBluetoothDiscoverySession>>
217 GetDiscoverySession();
219 // Devices
221 // |BaseDevice|
222 // Adv UUIDs added:
223 // None.
224 // Services added:
225 // None.
226 // MockFunctions:
227 // - GetUUIDs:
228 // Returns uuids
229 // - GetGattServices:
230 // Returns a list of all services added to the device.
231 // - GetGattService:
232 // Return a service matching the identifier provided if the service was
233 // added to the mock.
234 // - GetAddress:
235 // Returns: address
236 // - GetName:
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.
243 // - GetVendorID:
244 // Returns: 0xFFFF.
245 // - GetProductID:
246 // Returns: 1.
247 // - GetDeviceID:
248 // Returns: 2.
249 // - IsPaired:
250 // Returns true.
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");
258 // |BatteryDevice|
259 // Inherits from |BaseDevice|(adapter, "Battery Device", uuids,
260 // "00:00:00:00:00:01")
261 // Adv UUIDs added:
262 // - Generic Access (0x1800)
263 // - Battery Service UUID (0x180F)
264 // Services added:
265 // None.
266 static scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
267 GetBatteryDevice(device::MockBluetoothAdapter* adapter);
269 // |GlucoseDevice|
270 // Inherits from |BaseDevice|(adapter, "Glucose Device", uuids,
271 // "00:00:00:00:00:02")
272 // Adv UUIDs added:
273 // - Generic Access (0x1800)
274 // - Glucose UUID (0x1808)
275 // Services added:
276 // None.
277 static scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
278 GetGlucoseDevice(device::MockBluetoothAdapter* adapter);
280 // |HeartRateDevice|
281 // Inherits from |BaseDevice|(adapter, "Heart Rate Device", uuids,
282 // "00:00:00:00:00:03")
283 // Adv UUIDs added:
284 // - Generic Access (0x1800)
285 // - Heart Rate UUID (0x180D)
286 // Services added:
287 // None.
288 static scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
289 GetHeartRateDevice(device::MockBluetoothAdapter* adapter);
291 // |ConnectableDevice|
292 // Inherits from |BaseDevice|(adapter, device_name)
293 // Adv UUIDs added:
294 // None.
295 // Services added:
296 // None.
297 // Mock Functions:
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)
308 // Adv UUIDs added:
309 // - errorUUID(error_code)
310 // Services added:
311 // None.
312 // Mock Functions:
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)
323 // Adv UUIDs added:
324 // - Generic Access UUID (0x1800)
325 // Services added:
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");
333 // Services
335 // |BaseGATTService|
336 // Characteristics added:
337 // None.
338 // Mock Functions:
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.
344 // - GetIdentifier:
345 // Returns: uuid + “ Identifier”
346 // - GetUUID:
347 // Returns: uuid
348 // - IsLocal:
349 // Returns: false
350 // - IsPrimary:
351 // Returns: true
352 // - GetDevice:
353 // Returns: device
354 static scoped_ptr<testing::NiceMock<device::MockBluetoothGattService>>
355 GetBaseGATTService(device::MockBluetoothDevice* device,
356 const std::string& uuid);
358 // Characteristics
360 // |BaseCharacteristic|(service, uuid)
361 // Descriptors added:
362 // None.
363 // Mock Functions:
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.
369 // - GetIdentifier:
370 // Returns: uuid + “ Identifier”
371 // - GetUUID:
372 // Returns: uuid
373 // - IsLocal:
374 // Returns: false
375 // - GetService:
376 // Returns: service
377 // - GetProperties:
378 // Returns: NULL
379 // - GetPermissions:
380 // Returns: NULL
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:
388 // None.
389 // Mock Functions:
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);
399 // Helper functions:
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_