forked from WebBluetoothCG/web-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.bs
291 lines (240 loc) · 12.2 KB
/
tests.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<pre class='metadata'>
Title: Testing Web Bluetooth
Group: web-bluetooth-cg
Status: CG-DRAFT
ED: https://webbluetoothcg.github.io/web-bluetooth/tests
Shortname: testing-web-bluetooth
Level: 1
Editor: See contributors on GitHub, , https://github.com/WebBluetoothCG/web-bluetooth/graphs/contributors
Abstract: This document describes functions used in testing the Web Bluetooth API.
Status Text:
<strong class="advisement">
This specification does not yet reflect the consensus of the Web Bluetooth
CG. It is presented by the Chromium developers in the hope that other
implementers will find it useful. It may be withdrawn if they don't.
</strong>
<div class="issue">
This document is out of date. It is a snapshot of the testing API as of
late 2015. A
<a href="https://docs.google.com/document/d/1Nhv_oVDCodd1pEH_jj9k8gF4rPGb_84VYaZ9IG8M_WY">
test API redesign</a>
is under active design and development as of August 2017.
Chromium developers are interested
in updating and collaborating on this document when the next tested
implementation begins development.
</div>
Markup Shorthands: css no, markdown yes
Link Defaults: html (dfn) trusted event/the body element
Link Defaults: web-bluetooth (dfn) valid uuid
</pre>
<pre class="biblio">
{
"BLUETOOTH42": {
"href": "https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=286439",
"title": "BLUETOOTH SPECIFICATION Version 4.2",
"publisher": "Bluetooth SIG",
"date": "2 December 2014"
}
}
</pre>
<pre class="anchors">
spec: BLUETOOTH-ASSIGNED
type: enum; urlPrefix: https://developer.bluetooth.org/gatt/
urlPrefix: characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.
text: org.bluetooth.characteristic.gap.device_name; url: gap.device_name.xml#
urlPrefix: descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.
text: org.bluetooth.descriptor.gatt.characteristic_user_description; url: gatt.characteristic_user_description.xml#
text: org.bluetooth.descriptor.gatt.characteristic_extended_properties; url: gatt.characteristic_extended_properties.xml#
urlPrefix: services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.
text: org.bluetooth.service.battery_service; url: battery_service.xml#
text: org.bluetooth.service.glucose; url: glucose.xml#
text: org.bluetooth.service.generic_access; url: generic_access.xml#
text: org.bluetooth.service.heart_rate; url: heart_rate.xml#
spec: ui-events; urlPrefix: https://www.w3.org/TR/uievents/#
type: event
text: keypress; url: event-type-keypress
type: attribute
for: KeyboardEvent; text: key; url: widl-KeyboardEvent-key
</pre>
<style>
.atrisk::before {
content: '\25C0 May depend on implementation details';
}
</style>
<h2 id="introduction">Introduction</h2>
<em>This section is non-normative.</em>
Writing cross-browser tests for the
<a href="https://webbluetoothcg.github.io/web-bluetooth/">Web Bluetooth API</a> is
difficult because it interacts with devices that live outside the browser. This
document describes APIs that aid in this testing, and can be implemented by each
browser to either mock out the external interaction, or to configure an external
test device to behave as the test needs.
Tests using these functions are currently in <a
href="https://github.com/web-platform-tests/wpt/tree/master/bluetooth">web-platform-tests</a>
and in <a
href="https://code.google.com/p/chromium/codesearch/#chromium/src/third_party/WebKit/LayoutTests/bluetooth/">Chromium's
repository</a>.
<h2 id="security-and-privacy">Security and privacy considerations</h2>
These functions MUST NOT be exposed to web content. Only trusted testing
code may access them.
<h2 id="test-interfaces">Testing interfaces</h2>
<pre class="idl">
partial interface Window {
readonly attribute TestRunner testRunner;
readonly attribute EventSender eventSender;
};
</pre>
<h2 id="test-runner">testRunner</h2>
<pre class="idl">
callback BluetoothManualChooserEventsCallback = void(sequence<DOMString> events);
interface TestRunner {
void setBluetoothMockDataSet(DOMString dataSetName);
void setBluetoothManualChooser();
void getBluetoothManualChooserEvents(BluetoothManualChooserEventsCallback callback);
void sendBluetoothManualChooserEvent(DOMString event, DOMString argument);
};
</pre>
<h3 id="setBluetoothMockDataSet">setBluetoothMockDataSet</h3>
When invoked, <dfn method
for="TestRunner">setBluetoothMockDataSet(dataSetName)</dfn> MUST replace the
user prompt used in {{Bluetooth/requestDevice()}} with one that resolves the
promise with the first discovered device, or rejects the promise if discovery
can't start or times out. Then it must configure the UA's Bluetooth system to
respond depending on the {{dataSetName}}:
: <code>"NotPresentAdapter"</code>
:: The UA has no Bluetooth implementation at all.
: <code>"NotPoweredAdapter"</code>
:: The UA's Bluetooth radio is disabled.
: <code class="atrisk">"ScanFilterCheckingAdapter"</code>
:: The UA may fail the test unless the test asks the adapter to start a
Bluetooth scan filtered to the {{org.bluetooth.service.glucose}},
{{org.bluetooth.service.heart_rate}}, and
{{org.bluetooth.service.battery_service}} Service UUIDs. The adapter
discovers a <a>BatteryDevice</a>.
: <code>"EmptyAdapter"</code>
:: No devices are nearby.
: <code>"FailStartDiscoveryAdapter"</code>
:: The UA fails to start a scan for devices.
: <code>"FailStopDiscoveryAdapter"</code>
:: Behaves like a GenericAccessAdapter, but the UA fails to stop the scan for
devices.
: <code>"GlucoseHeartRateAdapter"</code>
:: The UA discovers a <a>HeartRateDevice</a> and a <a>GlucoseDevice</a>.
: <code>"SecondDiscoveryFindsHeartRateAdapter"</code>
:: In the first discovery session, the UA finds no devices. In the second, it
discovers a <a>HeartRateDevice</a>.
: <code>"MissingServiceGenericAccessAdapter"</code>
:: The UA discovers a <a>MissingServiceGenericAccessDevice</a>.
: <code>"MissingCharacteristicGenericAccessAdapter"</code>
:: The UA discovers a <a>MissingCharacteristicGenericAccessDevice</a>.
: <code>"MissingDescriptorGenericAccessAdapter"</code>
:: The UA discovers a <a>MissingDescriptorGenericAccessDevice</a>.
: <code>"GenericAccessAdapter"</code>
:: The UA discovers a <a>GenericAccessDevice</a>.
: <code>"FailingGATTOperationsAdapter"</code>
:: The UA discovers a <a>FailingGATTOperationsDevice</a>.
<h4 dfn-type="dfn">BatteryDevice</h4>
Has a MAC address of
<code>00:00:00:00:00:01</code>, the name <code>"Battery Device"</code>, and
advertises {{org.bluetooth.service.battery_service}}.
<h4 dfn-type="dfn">GlucoseDevice</h4>
Has a MAC address of
<code>00:00:00:00:00:02</code>, the name <code>"Glucose Device"</code>, and
advertises {{org.bluetooth.service.glucose}}.
<h4 dfn-type="dfn">HeartRateDevice</h4>
Has a MAC address of
<code>00:00:00:00:00:03</code>, the name <code>"Heart Rate Device"</code>, and
advertises {{org.bluetooth.service.heart_rate}}.
<h4 dfn-type="dfn">MissingServiceGenericAccessDevice</h4>
Has a MAC address of
<code>00:00:00:00:00:00</code>, the name <code>"Generic Access
Device"</code>, and accepts GATT connections. Its GATT Server is empty.
<h4 dfn-type="dfn">MissingCharacteristicGenericAccessDevice</h4>
In addition to the properties of a <a>MissingServiceGenericAccessDevice</a>, its
GATT Server contains a primary {{org.bluetooth.service.generic_access}} service.
This service contains no characteristics.
<h4 dfn-type="dfn">MissingDescriptorGenericAccessDevice</h4>
In addition to the properties of a
<a>MissingCharacteristicGenericAccessDevice</a>, its
{{org.bluetooth.service.generic_access}} service contains the
{{org.bluetooth.characteristic.gap.device_name}} characteristic. This
characteristic returns <code>"GenericAccessDevice"</code> when read, and
responds that writes have succeeded (without changing the value read).
<h4 dfn-type="dfn">GenericAccessDevice</h4>
In addition to the properties of a
<a>MissingDescriptorGenericAccessDevice</a>, its
{{org.bluetooth.characteristic.gap.device_name}} characteristic contains the following descriptors:
: {{org.bluetooth.descriptor.gatt.characteristic_extended_properties}}
:: Has the Writable Auxiliaries bit set.
: {{org.bluetooth.descriptor.gatt.characteristic_user_description}}
:: Returns <code>"Device Name"</code> when read, and responds that writes
have succeeded (without changing the value read).
<h4 dfn-type="dfn">FailingGATTOperationsDevice</h4>
Let <code><dfn abstract-op>errorUUID</dfn>(unsigned long id)</code> be the
<a>valid UUID</a> consisting of <code>id.toString(16)</code> left-padded with
<code>"0"</code>s to 8 characters, and then concatenated with
<code>"-97e5-4cd7-b9f1-f5a427670c59"</code>. (These lower 96 bits were generated
as a type 4 (random) UUID.)
The
<a>FailingGATTOperationsDevice</a> has a MAC address of
<code>00:00:00:00:00:00</code>, the name <code>"Errors Device"</code>, and
accepts GATT connections. Its GATT Server contains one service with UUID
<code>[$errorUUID$](0x100)</code>. This service contains 255 characteristics
with UUIDs <code>[$errorUUID$](0x101)</code> through
<code>[$errorUUID$](0x1ff)</code>. When read or written, the characteristic with
UUID <code>[$errorUUID$](which)</code> returns an Error Response
([[!BLUETOOTH42]] 3.F.3.4.1.1) with an error code of <code>which - 0x100</code>.
<h3 dfn-type="method" for="TestRunner">setBluetoothManualChooser()</h3>
When invoked, {{TestRunner/setBluetoothManualChooser()}} MUST replace the user
prompt used in {{Bluetooth/requestDevice()}} with a "<dfn>manual chooser</dfn>"
that records events that would otherwise be shown to the user (see
{{TestRunner/getBluetoothManualChooserEvents()}}), and which can simulate user
interaction with the prompt (see
{{TestRunner/sendBluetoothManualChooserEvent()}}).
<h3 dfn-type="method" for="TestRunner">getBluetoothManualChooserEvents(callback)</h3>
When invoked, {{TestRunner/getBluetoothManualChooserEvents(callback)}} MUST call `callback` with the
list of events that have been recorded by the <a>manual chooser</a> since
{{TestRunner/getBluetoothManualChooserEvents()}} was last called. Each event is
encoded as string, as follows:
: The chooser is opened following a request by origin <var>O</var>.
:: <code>"chooser-opened(<var>O</var>)"</code>
: The Bluetooth adapter is removed from the UA.
:: <code>"adapter-removed"</code>
: The Bluetooth adapter becomes present but disabled.
:: <code>"adapter-disabled"</code>
: The Bluetooth adapter becomes present and enabled.
:: <code>"adapter-enabled"</code>
: The Bluetooth adapter begins scanning for nearby devices.
:: <code>"discovering"</code>
: The Bluetooth adapter stops scanning for nearby devices.
:: <code>"discovery-idle"</code>
: The Bluetooth adapter attempts to begin scanning for nearby devices, but fails.
:: <code>"discovery-failed-to-start"</code>
: A device is added to the user prompt with {{BluetoothDevice/id}}
<var>device-id</var> and {{BluetoothDevice/name}} <var>device-name</var>.
:: <code>"add-device(<var>device-name</var>)=<var>device-id</var>"</code>
Note: The <var>device-id</var> might not be the device's MAC address. For
example, MacOS and iOS generate a random ID when testing against physical
devices.
: The UA discovers that a device with {{BluetoothDevice/id}}
<var>device-id</var> is no longer nearby.
:: <code>"remove-device(<var>device-id</var>)"</code>
<h3 dfn-type="method" for="TestRunner">sendBluetoothManualChooserEvent(event, argument)</h3>
When invoked, {{TestRunner/sendBluetoothManualChooserEvent(event, argument)}}
MUST cause the <a>manual chooser</a> to inform the UA that the user has taken an
action corresponding to the {{event}}:
: <code>"cancelled"</code>
:: The user cancelled the prompt.
: <code>"selected"</code>
:: The user selected the device with an {{BluetoothDevice/id}} of {{argument}}.
: <code>"rescan"</code>
:: The user requested another bluetooth scan.
<h2 id="event-sender">eventSender</h2>
<pre class="idl">
interface EventSender {
void keyDown(DOMString code);
};
</pre>
<dfn method for="EventSender">keyDown(code)</dfn> must <a>fire an event</a>
named {{keypress}} to <a>the body element</a>, with its
{{KeyboardEvent/key}} attribute initialized to {{code}}.