-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'shadowrealm-in-audioworklet' global
This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-audioworklet.html variant. The wrapper here is similar to the one for ServiceWorkers, since dynamic import() is also forbidden in worklet scopes. But additionally fetch() is not exposed, so we add a utility function to set up the ability to call the window realm's fetch() through the AudioWorklet's message port. We also add /resources/testharness-shadowrealm-audioworkletprocessor.js to contain most of the AudioWorklet setup boilerplate, so that it isn't written inline in serve.py. Note '.https.' needs to be added to the test path.
- Loading branch information
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
resources/testharness-shadowrealm-audioworkletprocessor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* AudioWorkletProcessor intended for hosting a ShadowRealm and running a test | ||
* inside of that ShadowRealm. | ||
*/ | ||
globalThis.TestRunner = class TestRunner extends AudioWorkletProcessor { | ||
constructor() { | ||
super(); | ||
this.createShadowRealmAndStartTests(); | ||
} | ||
|
||
/** | ||
* Fetch adaptor function intended as a drop-in replacement for fetchAdaptor() | ||
* (see testharness-shadowrealm-outer.js), but it does not assume fetch() is | ||
* present in the realm. Instead, it relies on setupFakeFetchOverMessagePort() | ||
* having been called on the port on the other side of this.port's channel. | ||
*/ | ||
fetchOverPortExecutor(resource) { | ||
return (resolve, reject) => { | ||
const listener = (event) => { | ||
if (typeof event.data !== "string" || !event.data.startsWith("fetchResult::")) | ||
return; | ||
|
||
const result = event.data.slice("fetchResult::".length); | ||
if (result.startsWith("success::")) | ||
resolve(result.slice("success::".length)); | ||
else | ||
reject(result.slice("fail::".length)); | ||
|
||
this.port.removeEventListener("message", listener); | ||
} | ||
this.port.addEventListener("message", listener); | ||
this.port.start(); | ||
this.port.postMessage(`fetchRequest::${resource}`); | ||
} | ||
} | ||
|
||
/** | ||
* Async method, which is patched over in | ||
* (test).any.audioworklet-shadowrealm.js; see serve.py | ||
*/ | ||
async createShadowRealmAndStartTests() { | ||
throw new Error("Forgot to overwrite this method!"); | ||
} | ||
|
||
/** Overrides AudioWorkletProcessor.prototype.process() */ | ||
process() { | ||
return false; | ||
} | ||
}; | ||
registerProcessor("test-runner", TestRunner); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters