From 744035d1c7114b2ef7b18a5c60f5bf275bcc941e Mon Sep 17 00:00:00 2001 From: Ovidio Henriquez Date: Wed, 23 May 2018 17:16:00 +0000 Subject: [PATCH] Bug 1462454 [wpt PR 11050] - Create WebUSB idlharness test for workers, a=testonly Automatic update from web-platform-testsCreate 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 Reviewed-by: Reilly Grant Reviewed-by: Chong Zhang Reviewed-by: Yuki Shiino Reviewed-by: Hitoshi Yoshida Reviewed-by: Kentaro Hara Cr-Commit-Position: refs/heads/master@{#560399} -- wpt-commits: 76c0092916ee8a9171396e62c472d85a0f2623fb wpt-pr: 11050 --- testing/web-platform/meta/MANIFEST.json | 33 +++++++++- .../web-platform/tests/interfaces/webusb.idl | 66 +++++++++++++++---- .../tests/webusb/idlharness.https.html | 1 + ...idlharness.dedicatedworker.sharedworker.js | 61 +++++++++++++++++ .../idlharness.dedicatedworker.https.html | 11 ++++ .../worker/idlharness.sharedworker.https.html | 11 ++++ 6 files changed, 168 insertions(+), 15 deletions(-) create mode 100644 testing/web-platform/tests/webusb/resources/idlharness.dedicatedworker.sharedworker.js create mode 100644 testing/web-platform/tests/webusb/worker/idlharness.dedicatedworker.https.html create mode 100644 testing/web-platform/tests/webusb/worker/idlharness.sharedworker.https.html diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 48bb686b7243..404fcd940c1e 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -299835,6 +299835,11 @@ {} ] ], + "webusb/resources/idlharness.dedicatedworker.sharedworker.js": [ + [ + {} + ] + ], "webusb/resources/open-in-iframe.html": [ [ {} @@ -376909,6 +376914,18 @@ {} ] ], + "webusb/worker/idlharness.dedicatedworker.https.html": [ + [ + "/webusb/worker/idlharness.dedicatedworker.https.html", + {} + ] + ], + "webusb/worker/idlharness.sharedworker.https.html": [ + [ + "/webusb/worker/idlharness.sharedworker.https.html", + {} + ] + ], "webusb/worker/usb.dedicatedworker.https.html": [ [ "/webusb/worker/usb.dedicatedworker.https.html", @@ -583919,7 +583936,7 @@ "support" ], "interfaces/webusb.idl": [ - "7b5749e1fece69552e0a8bfac7af401fac15394d", + "e609a866d40f70f59f682a1a5ec82cf713863969", "support" ], "interfaces/webvtt.idl": [ @@ -617463,13 +617480,17 @@ "support" ], "webusb/idlharness.https.html": [ - "135ae431cdac90d34b85fe1ea355abaf9a9fb732", + "5a97c893eb0e23e3cba14501de9955cfbb0b385a", "testharness" ], "webusb/resources/fake-devices.js": [ "2cfce7b35b9441529946c4bcea9427e261808c36", "support" ], + "webusb/resources/idlharness.dedicatedworker.sharedworker.js": [ + "2a847fbeded0fe0b895cb5675f90b685f749f40a", + "support" + ], "webusb/resources/open-in-iframe.html": [ "6e6050f742e0da58fc94a5c0a0aa75f16dfcede9", "support" @@ -617554,6 +617575,14 @@ "f08a98a927d57cda8b780a8304a0fa6cf727cc81", "testharness" ], + "webusb/worker/idlharness.dedicatedworker.https.html": [ + "159ede02aac087e0409632c2fcbac3a597ec4c45", + "testharness" + ], + "webusb/worker/idlharness.sharedworker.https.html": [ + "4dc8b85f2590397f6e8bcbf63dc64381b1f95559", + "testharness" + ], "webusb/worker/usb.dedicatedworker.https.html": [ "556e26de5f184609e0e49f02795f96aef524a7c2", "testharness" diff --git a/testing/web-platform/tests/interfaces/webusb.idl b/testing/web-platform/tests/interfaces/webusb.idl index bad8383c5ec6..03e03b068c01 100644 --- a/testing/web-platform/tests/interfaces/webusb.idl +++ b/testing/web-platform/tests/interfaces/webusb.idl @@ -14,27 +14,37 @@ dictionary USBDeviceRequestOptions { required sequence filters; }; +[Exposed=(DedicatedWorker, SharedWorker, Window), SecureContext] interface USB : EventTarget { attribute EventHandler onconnect; attribute EventHandler ondisconnect; Promise> getDevices(); - Promise requestDevice(USBDeviceRequestOptions options); + [Exposed=Window] Promise requestDevice(USBDeviceRequestOptions options); }; -[SecureContext] +[Exposed=Window, SecureContext] partial interface Navigator { [SameObject] readonly attribute USB usb; }; +[Exposed=(DedicatedWorker, SharedWorker), SecureContext] +partial interface WorkerNavigator { + [SameObject] readonly attribute USB usb; +}; + dictionary USBConnectionEventInit : EventInit { required USBDevice device; }; -[Constructor(DOMString type, USBConnectionEventInit eventInitDict)] +[ + Constructor(DOMString type, USBConnectionEventInit eventInitDict), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBConnectionEvent : Event { [SameObject] readonly attribute USBDevice device; }; +[Exposed=(DedicatedWorker, SharedWorker, Window)] interface USBDevice { readonly attribute octet usbVersionMajor; readonly attribute octet usbVersionMinor; @@ -96,49 +106,73 @@ dictionary USBControlTransferParameters { required unsigned short index; }; -[Constructor(USBTransferStatus status, optional DataView? data)] +[ + Constructor(USBTransferStatus status, optional DataView? data), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBInTransferResult { readonly attribute DataView? data; readonly attribute USBTransferStatus status; }; -[Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0)] +[ + Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBOutTransferResult { readonly attribute unsigned long bytesWritten; readonly attribute USBTransferStatus status; }; -[Constructor(USBTransferStatus status, optional DataView? data)] +[ + Constructor(USBTransferStatus status, optional DataView? data), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBIsochronousInTransferPacket { readonly attribute DataView? data; readonly attribute USBTransferStatus status; }; -[Constructor(sequence packets, optional DataView? data)] +[ + Constructor(sequence packets, optional DataView? data), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBIsochronousInTransferResult { readonly attribute DataView? data; readonly attribute FrozenArray packets; }; -[Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0)] +[ + Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBIsochronousOutTransferPacket { readonly attribute unsigned long bytesWritten; readonly attribute USBTransferStatus status; }; -[Constructor(sequence packets)] +[ + Constructor(sequence packets), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBIsochronousOutTransferResult { readonly attribute FrozenArray packets; }; -[Constructor(USBDevice device, octet configurationValue)] +[ + Constructor(USBDevice device, octet configurationValue), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBConfiguration { readonly attribute octet configurationValue; readonly attribute DOMString? configurationName; readonly attribute FrozenArray interfaces; }; -[Constructor(USBConfiguration configuration, octet interfaceNumber)] +[ + Constructor(USBConfiguration configuration, octet interfaceNumber), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBInterface { readonly attribute octet interfaceNumber; readonly attribute USBAlternateInterface alternate; @@ -146,7 +180,10 @@ interface USBInterface { readonly attribute boolean claimed; }; -[Constructor(USBInterface deviceInterface, octet alternateSetting)] +[ + Constructor(USBInterface deviceInterface, octet alternateSetting), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBAlternateInterface { readonly attribute octet alternateSetting; readonly attribute octet interfaceClass; @@ -167,7 +204,10 @@ enum USBEndpointType { "isochronous" }; -[Constructor(USBAlternateInterface alternate, octet endpointNumber, USBDirection direction)] +[ + Constructor(USBAlternateInterface alternate, octet endpointNumber, USBDirection direction), + Exposed=(DedicatedWorker, SharedWorker, Window) +] interface USBEndpoint { readonly attribute octet endpointNumber; readonly attribute USBDirection direction; diff --git a/testing/web-platform/tests/webusb/idlharness.https.html b/testing/web-platform/tests/webusb/idlharness.https.html index f69c53c61b65..a2568781a6c8 100644 --- a/testing/web-platform/tests/webusb/idlharness.https.html +++ b/testing/web-platform/tests/webusb/idlharness.https.html @@ -35,6 +35,7 @@ idl_array.add_untested_idls('dictionary EventInit {};'); idl_array.add_untested_idls('interface EventTarget {};'); idl_array.add_untested_idls('interface Navigator {};'); + idl_array.add_untested_idls('interface WorkerNavigator {};'); let {device} = await getFakeDevice(); diff --git a/testing/web-platform/tests/webusb/resources/idlharness.dedicatedworker.sharedworker.js b/testing/web-platform/tests/webusb/resources/idlharness.dedicatedworker.sharedworker.js new file mode 100644 index 000000000000..99eb5a199b66 --- /dev/null +++ b/testing/web-platform/tests/webusb/resources/idlharness.dedicatedworker.sharedworker.js @@ -0,0 +1,61 @@ +'use strict'; +importScripts('/resources/testharness.js'); +importScripts('/resources/WebIDLParser.js'); +importScripts('/resources/idlharness.js'); +importScripts('/webusb/resources/fake-devices.js'); +importScripts('/webusb/resources/usb-helpers.js'); + +// Object instances used by the IDL test. +var usbDevice; +var usbConfiguration; +var usbInterface; +var usbAlternateInterface; +var usbEndpoint; +var usbConnectionEvent; + +usb_test(async () => { + let webUSBResponse = await fetch('/interfaces/webusb.idl'); + let domResponse = await fetch('/interfaces/dom.idl'); + let webusb_idl_text = await webUSBResponse.text(); + let dom_idl_text = await domResponse.text(); + let idl_array = new IdlArray(); + idl_array.add_idls(webusb_idl_text); + + // Untested IDL interfaces + idl_array.add_untested_idls(dom_idl_text, { only: ['Event', 'EventTarget'] }); + idl_array.add_untested_idls('interface EventHandler {};'); + idl_array.add_untested_idls('dictionary EventInit {};'); + idl_array.add_untested_idls('interface Navigator {};'); + idl_array.add_untested_idls('interface WorkerNavigator {};'); + + let {device} = await getFakeDevice(); + + usbDevice = device; + usbConfiguration = usbDevice.configurations[0]; + usbInterface = usbConfiguration.interfaces[0]; + usbAlternateInterface = usbInterface.alternates[0]; + usbEndpoint = usbAlternateInterface.endpoints[0]; + usbConnectionEvent = + new USBConnectionEvent('connect', { device: usbDevice }) + + idl_array.add_objects({ + WorkerNavigator: ['navigator'], + USB: ['navigator.usb'], + USBAlternateInterface: ['usbAlternateInterface'], + USBConfiguration: ['usbConfiguration'], + USBConnectionEvent: ['usbConnectionEvent'], + USBDevice: ['usbDevice'], + USBEndpoint: ['usbEndpoint'], + USBInterface: ['usbInterface'], + USBInTransferResult: ['new USBInTransferResult("ok")'], + USBOutTransferResult: ['new USBOutTransferResult("ok")'], + USBIsochronousInTransferResult: ['new USBIsochronousInTransferResult([])'], + USBIsochronousOutTransferResult: ['new USBIsochronousOutTransferResult([])'], + USBIsochronousInTransferPacket: ['new USBIsochronousInTransferPacket("ok")'], + USBIsochronousOutTransferPacket: ['new USBIsochronousOutTransferPacket("ok")'], + }); + + idl_array.test(); +}, 'WebUSB on Workers IDL test'); + +done(); \ No newline at end of file diff --git a/testing/web-platform/tests/webusb/worker/idlharness.dedicatedworker.https.html b/testing/web-platform/tests/webusb/worker/idlharness.dedicatedworker.https.html new file mode 100644 index 000000000000..9ff21839f896 --- /dev/null +++ b/testing/web-platform/tests/webusb/worker/idlharness.dedicatedworker.https.html @@ -0,0 +1,11 @@ + + + +
+ diff --git a/testing/web-platform/tests/webusb/worker/idlharness.sharedworker.https.html b/testing/web-platform/tests/webusb/worker/idlharness.sharedworker.https.html new file mode 100644 index 000000000000..362e182e1cef --- /dev/null +++ b/testing/web-platform/tests/webusb/worker/idlharness.sharedworker.https.html @@ -0,0 +1,11 @@ + + + +
+ \ No newline at end of file