Add ICU message format support
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_bluetooth_adapter_provider.h
blobe1340c86a1116242a8c048529da7036abc621d71
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 // |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.
50 // Devices added:
51 // - |BatteryDevice|
52 // Mock Functions:
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|
62 // Devices added:
63 // None.
64 // Mock Functions:
65 // - StartDiscoverySessionWithFilter:
66 // Run error callback.
67 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
68 GetFailStartDiscoveryAdapter();
70 // |EmptyAdapter|
71 // Inherits from |BaseAdapter|
72 // Devices Added:
73 // None.
74 // Mock Functions:
75 // - StartDiscoverySessionWithFilter:
76 // Run success callback with |DiscoverySession|.
77 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
78 GetEmptyAdapter();
80 // |GlucoseHeartRateAdapter|
81 // Inherits from |EmptyAdapter|
82 // Devices added:
83 // - |GlucoseDevice|
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:
112 // - Mock Functions:
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)
134 // errorUUID(0x7)
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:
145 // - ErrorsDevice
146 // - ErrorsService errorUUID(0xA0)
147 // - ErrorCharacteristic(
148 // BluetoothGattService::GATT_ERROR_UNKNOWN)
149 // errorUUID(0xA1)
150 // - ErrorCharacteristic(
151 // BluetoothGattService::GATT_ERROR_FAILED)
152 // errorUUID(0xA2)
153 // - ErrorCharacteristic(
154 // BluetoothGattService::GATT_ERROR_IN_PROGRESS)
155 // errorUUID(0xA3)
156 // - ErrorCharacteristic(
157 // BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
158 // errorUUID(0xA4)
159 // - ErrorCharacteristic(
160 // BluetoothGattService::GATT_ERROR_NOT_PERMITTED)
161 // errorUUID(0xA5)
162 // - ErrorCharacteristic(
163 // BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED)
164 // errorUUID(0xA6)
165 // - ErrorCharacteristic(
166 // BluetoothGattService::GATT_ERROR_NOT_PAIRED)
167 // errorUUID(0xA7)
168 // - ErrorCharacteristic(
169 // BluetoothGattService::GATT_ERROR_NOT_SUPPORTED)
170 // errorUUID(0xA8)
171 static scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>>
172 GetFailingGATTOperationsAdapter();
174 // Discovery Sessions
176 // |DiscoverySession|
177 // Mock Functions:
178 // - Stop:
179 // Run success callback.
180 static scoped_ptr<testing::NiceMock<device::MockBluetoothDiscoverySession>>
181 GetDiscoverySession();
183 // Devices
185 // |BaseDevice|
186 // Adv UUIDs added:
187 // None.
188 // Services added:
189 // None.
190 // MockFunctions:
191 // - GetUUIDs:
192 // Returns uuids
193 // - GetGattServices:
194 // Returns a list of all services added to the device.
195 // - GetGattService:
196 // Return a service matching the identifier provided if the service was
197 // added to the mock.
198 // - GetAddress:
199 // Returns: address
200 // - GetName:
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.
207 // - GetVendorID:
208 // Returns: 0xFFFF.
209 // - GetProductID:
210 // Returns: 1.
211 // - GetDeviceID:
212 // Returns: 2.
213 // - IsPaired:
214 // Returns true.
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");
222 // |BatteryDevice|
223 // Inherits from |BaseDevice|(adapter, "Battery Device", uuids,
224 // "00:00:00:00:00:01")
225 // Adv UUIDs added:
226 // - Generic Access (0x1800)
227 // - Battery Service UUID (0x180F)
228 // Services added:
229 // None.
230 static scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
231 GetBatteryDevice(device::MockBluetoothAdapter* adapter);
233 // |GlucoseDevice|
234 // Inherits from |BaseDevice|(adapter, "Glucose Device", uuids,
235 // "00:00:00:00:00:02")
236 // Adv UUIDs added:
237 // - Generic Access (0x1800)
238 // - Glucose UUID (0x1808)
239 // Services added:
240 // None.
241 static scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
242 GetGlucoseDevice(device::MockBluetoothAdapter* adapter);
244 // |HeartRateDevice|
245 // Inherits from |BaseDevice|(adapter, "Heart Rate Device", uuids,
246 // "00:00:00:00:00:03")
247 // Adv UUIDs added:
248 // - Generic Access (0x1800)
249 // - Heart Rate UUID (0x180D)
250 // Services added:
251 // None.
252 static scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
253 GetHeartRateDevice(device::MockBluetoothAdapter* adapter);
255 // |ConnectableDevice|
256 // Inherits from |BaseDevice|(adapter, device_name)
257 // Adv UUIDs added:
258 // None.
259 // Services added:
260 // None.
261 // Mock Functions:
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)
272 // Adv UUIDs added:
273 // - errorUUID(error_code)
274 // Services added:
275 // None.
276 // Mock Functions:
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)
287 // Adv UUIDs added:
288 // - Generic Access UUID (0x1800)
289 // Services added:
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");
297 // Services
299 // |BaseGATTService|
300 // Characteristics added:
301 // None.
302 // Mock Functions:
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.
308 // - GetIdentifier:
309 // Returns: uuid + “ Identifier”
310 // - GetUUID:
311 // Returns: uuid
312 // - IsLocal:
313 // Returns: false
314 // - IsPrimary:
315 // Returns: true
316 // - GetDevice:
317 // Returns: device
318 static scoped_ptr<testing::NiceMock<device::MockBluetoothGattService>>
319 GetBaseGATTService(device::MockBluetoothDevice* device,
320 const std::string& uuid);
322 // Characteristics
324 // |BaseCharacteristic|(service, uuid)
325 // Descriptors added:
326 // None.
327 // Mock Functions:
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.
333 // - GetIdentifier:
334 // Returns: uuid + “ Identifier”
335 // - GetUUID:
336 // Returns: uuid
337 // - IsLocal:
338 // Returns: false
339 // - GetService:
340 // Returns: service
341 // - GetProperties:
342 // Returns: NULL
343 // - GetPermissions:
344 // Returns: NULL
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:
352 // None.
353 // Mock Functions:
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);
363 // Helper functions:
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_