Skip to content

Commit 76c0092

Browse files
odejesushchromium-wpt-export-bot
authored andcommitted
Create WebUSB idlharness test for workers
This change creates an idlharness test for the workers to ensure that all the interfaces are exposed in the worker. This change also updates the webusb.idl file to match the exposure of the interfaces. Bug: 841510 Change-Id: Iad72f242ee0cdbf9a3057828bd4bd5542f6fe063 Reviewed-on: https://chromium-review.googlesource.com/1053063 Commit-Queue: Ovidio Henriquez <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Reviewed-by: Chong Zhang <[email protected]> Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: Hitoshi Yoshida <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Cr-Commit-Position: refs/heads/master@{#560399}
1 parent cf00fe1 commit 76c0092

File tree

5 files changed

+137
-13
lines changed

5 files changed

+137
-13
lines changed

interfaces/webusb.idl

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,37 @@ dictionary USBDeviceRequestOptions {
1414
required sequence<USBDeviceFilter> filters;
1515
};
1616

17+
[Exposed=(DedicatedWorker, SharedWorker, Window), SecureContext]
1718
interface USB : EventTarget {
1819
attribute EventHandler onconnect;
1920
attribute EventHandler ondisconnect;
2021
Promise<sequence<USBDevice>> getDevices();
21-
Promise<USBDevice> requestDevice(USBDeviceRequestOptions options);
22+
[Exposed=Window] Promise<USBDevice> requestDevice(USBDeviceRequestOptions options);
2223
};
2324

24-
[SecureContext]
25+
[Exposed=Window, SecureContext]
2526
partial interface Navigator {
2627
[SameObject] readonly attribute USB usb;
2728
};
2829

30+
[Exposed=(DedicatedWorker, SharedWorker), SecureContext]
31+
partial interface WorkerNavigator {
32+
[SameObject] readonly attribute USB usb;
33+
};
34+
2935
dictionary USBConnectionEventInit : EventInit {
3036
required USBDevice device;
3137
};
3238

33-
[Constructor(DOMString type, USBConnectionEventInit eventInitDict)]
39+
[
40+
Constructor(DOMString type, USBConnectionEventInit eventInitDict),
41+
Exposed=(DedicatedWorker, SharedWorker, Window)
42+
]
3443
interface USBConnectionEvent : Event {
3544
[SameObject] readonly attribute USBDevice device;
3645
};
3746

47+
[Exposed=(DedicatedWorker, SharedWorker, Window)]
3848
interface USBDevice {
3949
readonly attribute octet usbVersionMajor;
4050
readonly attribute octet usbVersionMinor;
@@ -96,57 +106,84 @@ dictionary USBControlTransferParameters {
96106
required unsigned short index;
97107
};
98108

99-
[Constructor(USBTransferStatus status, optional DataView? data)]
109+
[
110+
Constructor(USBTransferStatus status, optional DataView? data),
111+
Exposed=(DedicatedWorker, SharedWorker, Window)
112+
]
100113
interface USBInTransferResult {
101114
readonly attribute DataView? data;
102115
readonly attribute USBTransferStatus status;
103116
};
104117

105-
[Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0)]
118+
[
119+
Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0),
120+
Exposed=(DedicatedWorker, SharedWorker, Window)
121+
]
106122
interface USBOutTransferResult {
107123
readonly attribute unsigned long bytesWritten;
108124
readonly attribute USBTransferStatus status;
109125
};
110126

111-
[Constructor(USBTransferStatus status, optional DataView? data)]
127+
[
128+
Constructor(USBTransferStatus status, optional DataView? data),
129+
Exposed=(DedicatedWorker, SharedWorker, Window)
130+
]
112131
interface USBIsochronousInTransferPacket {
113132
readonly attribute DataView? data;
114133
readonly attribute USBTransferStatus status;
115134
};
116135

117-
[Constructor(sequence<USBIsochronousInTransferPacket> packets, optional DataView? data)]
136+
[
137+
Constructor(sequence<USBIsochronousInTransferPacket> packets, optional DataView? data),
138+
Exposed=(DedicatedWorker, SharedWorker, Window)
139+
]
118140
interface USBIsochronousInTransferResult {
119141
readonly attribute DataView? data;
120142
readonly attribute FrozenArray<USBIsochronousInTransferPacket> packets;
121143
};
122144

123-
[Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0)]
145+
[
146+
Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0),
147+
Exposed=(DedicatedWorker, SharedWorker, Window)
148+
]
124149
interface USBIsochronousOutTransferPacket {
125150
readonly attribute unsigned long bytesWritten;
126151
readonly attribute USBTransferStatus status;
127152
};
128153

129-
[Constructor(sequence<USBIsochronousOutTransferPacket> packets)]
154+
[
155+
Constructor(sequence<USBIsochronousOutTransferPacket> packets),
156+
Exposed=(DedicatedWorker, SharedWorker, Window)
157+
]
130158
interface USBIsochronousOutTransferResult {
131159
readonly attribute FrozenArray<USBIsochronousOutTransferPacket> packets;
132160
};
133161

134-
[Constructor(USBDevice device, octet configurationValue)]
162+
[
163+
Constructor(USBDevice device, octet configurationValue),
164+
Exposed=(DedicatedWorker, SharedWorker, Window)
165+
]
135166
interface USBConfiguration {
136167
readonly attribute octet configurationValue;
137168
readonly attribute DOMString? configurationName;
138169
readonly attribute FrozenArray<USBInterface> interfaces;
139170
};
140171

141-
[Constructor(USBConfiguration configuration, octet interfaceNumber)]
172+
[
173+
Constructor(USBConfiguration configuration, octet interfaceNumber),
174+
Exposed=(DedicatedWorker, SharedWorker, Window)
175+
]
142176
interface USBInterface {
143177
readonly attribute octet interfaceNumber;
144178
readonly attribute USBAlternateInterface alternate;
145179
readonly attribute FrozenArray<USBAlternateInterface> alternates;
146180
readonly attribute boolean claimed;
147181
};
148182

149-
[Constructor(USBInterface deviceInterface, octet alternateSetting)]
183+
[
184+
Constructor(USBInterface deviceInterface, octet alternateSetting),
185+
Exposed=(DedicatedWorker, SharedWorker, Window)
186+
]
150187
interface USBAlternateInterface {
151188
readonly attribute octet alternateSetting;
152189
readonly attribute octet interfaceClass;
@@ -167,7 +204,10 @@ enum USBEndpointType {
167204
"isochronous"
168205
};
169206

170-
[Constructor(USBAlternateInterface alternate, octet endpointNumber, USBDirection direction)]
207+
[
208+
Constructor(USBAlternateInterface alternate, octet endpointNumber, USBDirection direction),
209+
Exposed=(DedicatedWorker, SharedWorker, Window)
210+
]
171211
interface USBEndpoint {
172212
readonly attribute octet endpointNumber;
173213
readonly attribute USBDirection direction;

webusb/idlharness.https.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
idl_array.add_untested_idls('dictionary EventInit {};');
3636
idl_array.add_untested_idls('interface EventTarget {};');
3737
idl_array.add_untested_idls('interface Navigator {};');
38+
idl_array.add_untested_idls('interface WorkerNavigator {};');
3839

3940
let {device} = await getFakeDevice();
4041

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
importScripts('/resources/testharness.js');
3+
importScripts('/resources/WebIDLParser.js');
4+
importScripts('/resources/idlharness.js');
5+
importScripts('/webusb/resources/fake-devices.js');
6+
importScripts('/webusb/resources/usb-helpers.js');
7+
8+
// Object instances used by the IDL test.
9+
var usbDevice;
10+
var usbConfiguration;
11+
var usbInterface;
12+
var usbAlternateInterface;
13+
var usbEndpoint;
14+
var usbConnectionEvent;
15+
16+
usb_test(async () => {
17+
let webUSBResponse = await fetch('/interfaces/webusb.idl');
18+
let domResponse = await fetch('/interfaces/dom.idl');
19+
let webusb_idl_text = await webUSBResponse.text();
20+
let dom_idl_text = await domResponse.text();
21+
let idl_array = new IdlArray();
22+
idl_array.add_idls(webusb_idl_text);
23+
24+
// Untested IDL interfaces
25+
idl_array.add_untested_idls(dom_idl_text, { only: ['Event', 'EventTarget'] });
26+
idl_array.add_untested_idls('interface EventHandler {};');
27+
idl_array.add_untested_idls('dictionary EventInit {};');
28+
idl_array.add_untested_idls('interface Navigator {};');
29+
idl_array.add_untested_idls('interface WorkerNavigator {};');
30+
31+
let {device} = await getFakeDevice();
32+
33+
usbDevice = device;
34+
usbConfiguration = usbDevice.configurations[0];
35+
usbInterface = usbConfiguration.interfaces[0];
36+
usbAlternateInterface = usbInterface.alternates[0];
37+
usbEndpoint = usbAlternateInterface.endpoints[0];
38+
usbConnectionEvent =
39+
new USBConnectionEvent('connect', { device: usbDevice })
40+
41+
idl_array.add_objects({
42+
WorkerNavigator: ['navigator'],
43+
USB: ['navigator.usb'],
44+
USBAlternateInterface: ['usbAlternateInterface'],
45+
USBConfiguration: ['usbConfiguration'],
46+
USBConnectionEvent: ['usbConnectionEvent'],
47+
USBDevice: ['usbDevice'],
48+
USBEndpoint: ['usbEndpoint'],
49+
USBInterface: ['usbInterface'],
50+
USBInTransferResult: ['new USBInTransferResult("ok")'],
51+
USBOutTransferResult: ['new USBOutTransferResult("ok")'],
52+
USBIsochronousInTransferResult: ['new USBIsochronousInTransferResult([])'],
53+
USBIsochronousOutTransferResult: ['new USBIsochronousOutTransferResult([])'],
54+
USBIsochronousInTransferPacket: ['new USBIsochronousInTransferPacket("ok")'],
55+
USBIsochronousOutTransferPacket: ['new USBIsochronousOutTransferPacket("ok")'],
56+
});
57+
58+
idl_array.test();
59+
}, 'WebUSB on Workers IDL test');
60+
61+
done();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<div id="log"></div>
5+
<script>
6+
'use strict';
7+
8+
fetch_tests_from_worker(new Worker(
9+
'/webusb/resources/idlharness.dedicatedworker.sharedworker.js'));
10+
11+
</script>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<div id="log"></div>
5+
<script>
6+
'use strict';
7+
8+
fetch_tests_from_worker(new SharedWorker(
9+
'/webusb/resources/idlharness.dedicatedworker.sharedworker.js'));
10+
11+
</script>

0 commit comments

Comments
 (0)