mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 14:20:14 +02:00
Automatic update from web-platform-testsUpdate WebUSB terminate child context tests This change updates tests for WebUSB where a child context is terminated while having a USB device open. The existing tests are modified to send the MojoHandle intercepted by MojoInterfaceInterceptor through a MessageChannel to allow a new test for a worker context to be created. As a result, the MojoHandle class is made transferable over a MessageChannel. Bug: 841510, 852878 Change-Id: Ib7f74d172b9dcc16a4821a4063cfffc196466a88 Reviewed-on: https://chromium-review.googlesource.com/1162351 Commit-Queue: Ovidio Henriquez <odejesush@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/master@{#586942} -- wpt-commits: 1922679c94b3e31ccbd146ee82ada9c33c1b5d42 wpt-pr: 12299
40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// This polyfill prepares a child context to be attached to a parent context.
|
|
// The parent must call navigator.usb.test.attachToContext() to attach to the
|
|
// child context.
|
|
(() => {
|
|
if (this.constructor.name === 'DedicatedWorkerGlobalScope' ||
|
|
this !== window.top) {
|
|
|
|
// Run Chromium specific set up code.
|
|
if (typeof MojoInterfaceInterceptor !== 'undefined') {
|
|
let messageChannel = new MessageChannel();
|
|
messageChannel.port1.onmessage = async (messageEvent) => {
|
|
if (messageEvent.data.type === 'Attach') {
|
|
messageEvent.data.interfaces.forEach(interfaceName => {
|
|
let interfaceInterceptor =
|
|
new MojoInterfaceInterceptor(interfaceName);
|
|
interfaceInterceptor.oninterfacerequest =
|
|
e => messageChannel.port1.postMessage({
|
|
type: interfaceName,
|
|
handle: e.handle
|
|
}, [e.handle]);
|
|
interfaceInterceptor.start();
|
|
});
|
|
|
|
// Wait for a call to GetDevices() to ensure that the interface
|
|
// handles are forwarded to the parent context.
|
|
await navigator.usb.getDevices();
|
|
messageChannel.port1.postMessage({ type: 'Complete' });
|
|
}
|
|
};
|
|
|
|
let message = { type: 'ReadyForAttachment', port: messageChannel.port2 };
|
|
if (typeof Window !== 'undefined')
|
|
parent.postMessage(message, '*', [messageChannel.port2]);
|
|
else
|
|
postMessage(message, [messageChannel.port2]);
|
|
}
|
|
}
|
|
})();
|