-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1930534 [wpt PR 49108] - Run ShadowRealm tests in multiple scopes…
…, a=testonly Automatic update from web-platform-tests Change 'shadowrealm' global into a shorthand for all possible ShadowRealm scopes In order to automatically run tests not only in a ShadowRealm created in a window scope, but also in ShadowRealms created in other realms, change the 'shadowrealm' global type to a collection, and rename the existing ShadowRealm handler to 'shadowrealm-in-window'. -- Remove monkeypatch of globalThis.self in ShadowRealm As per whatwg/html#9893, ShadowRealmGlobalScope should have a `self` attribute already. There is no need to monkeypatch it for the test harness. -- Factor out JS code that will be common to multiple ShadowRealm handlers We will add multiple ShadowRealm handlers, and they will all need to set up certain global properties. Avoid repeating this code in each handler as well as in idlharness-shadowrealm.js. This should also increase readability, which is good since the ShadowRealm setup code can be confusing. -- Add 'shadowrealm-in-shadowrealm' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-shadowrealm.html variant. The test wrapper creates an outer ShadowRealm, which creates an inner ShadowRealm and runs the tests inside that, relaying the results through the outer ShadowRealm. -- Add 'shadowrealm-in-dedicatedworker' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-dedicatedworker.html variant. The test loads an intermediate .any.worker-shadowrealm.js wrapper into a Worker, and forwards the message port to the Worker's message port so that fetch_tests_from_worker can receive the results. -- Add 'shadowrealm-in-sharedworker' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-sharedworker.html variant. The test loads the same intermediate .any.worker-shadowrealm.js wrapper as .any.shadowrealm-in-dedicatedworker.html, but populates a 'port' variable with the port received from the connect event, instead of calling the global postMessage since that won't work in a SharedWorker. -- Add 'shadowrealm-in-serviceworker' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-serviceworker.html variant. We have to use a slightly different .any.serviceworker-shadowrealm.js wrapper from the wrapper used for the other types of workers, because dynamic import() is forbidden in ServiceWorker scopes. Instead, add a utility function to set up a fakeDynamicImport() function inside the ShadowRealm which uses the fetch adaptor to get the module's source text and evaluate it in the shadowRealm. Also add a case for ServiceWorkers to getPostMessageFunc(), which returns a postMessage() drop-in replacement that broadcasts the message to all clients, since test result messages from the ShadowRealm are not in response to any particular message received by the ServiceWorker. Note '.https.' needs to be added to the test path. -- 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. -- wpt-commits: 9c8db8af89efbe0f67b215af2a6b49e9564e2971, 65a205aea5d02ff5bea7b1a0579287035d02d6c4, eb9c8e7259ef8bd5cca5019c1ca15ccd430e81dc, 3a20c56893472783b5e20c0d61cbb7b7b278cc6d, 7d8458ed291b139307430a102180c9a617d7876e, 42160ae827c863ac6787c8451fe377901c8f0652, 59367bb21d053abb9ed6de3cca5409486816acc9, 60d6c48e5fa76876bc3924b9d6185dfb56c9ab1c wpt-pr: 49108 UltraBlame original commit: 0a625225a525e60a048bbd6f3a94e2605c7e375b
- Loading branch information
Showing
19 changed files
with
494 additions
and
63 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/compression/idlharness-shadowrealm.window.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
|
||
idl_test_shadowrealm(["compression"], ["streams"]); |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
|
||
|
||
|
||
idl_test_shadowrealm(["console"], []); |
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
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/dom/idlharness-shadowrealm.window.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
|
||
idl_test_shadowrealm(["dom"], ["html"]); |
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/encoding/idlharness-shadowrealm.window.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
|
||
idl_test_shadowrealm(["encoding"], ["streams"]); |
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
|
||
idl_test_shadowrealm(["hr-time"], ["html", "dom"]); |
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/html/dom/idlharness-shadowrealm.window.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
|
||
idl_test_shadowrealm(["html"], ["wai-aria", "SVG", "cssom", "touch-events", "uievents", "dom", "xhr", "FileAPI", "mediacapture-streams", "performance-timeline"]); |
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/performance-timeline/idlharness-shadowrealm.window.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
|
||
idl_test_shadowrealm(["performance-timeline"], ["hr-time", "dom"]); |
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
52 changes: 52 additions & 0 deletions
52
testing/web-platform/tests/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,52 @@ | ||
|
||
|
||
|
||
|
||
globalThis.TestRunner = class TestRunner extends AudioWorkletProcessor { | ||
constructor() { | ||
super(); | ||
this.createShadowRealmAndStartTests(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
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 createShadowRealmAndStartTests() { | ||
throw new Error("Forgot to overwrite this method!"); | ||
} | ||
|
||
|
||
process() { | ||
return false; | ||
} | ||
}; | ||
registerProcessor("test-runner", TestRunner); |
27 changes: 27 additions & 0 deletions
27
testing/web-platform/tests/resources/testharness-shadowrealm-inner.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,27 @@ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
globalThis.setShadowRealmGlobalProperties = function (queryString, fetchAdaptor) { | ||
globalThis.fetch_json = (resource) => { | ||
const executor = fetchAdaptor(resource); | ||
return new Promise(executor).then((s) => JSON.parse(s)); | ||
}; | ||
|
||
globalThis.location = { search: queryString }; | ||
}; | ||
|
||
globalThis.GLOBAL = { | ||
isWindow: function() { return false; }, | ||
isWorker: function() { return false; }, | ||
isShadowRealm: function() { return true; }, | ||
}; |
127 changes: 127 additions & 0 deletions
127
testing/web-platform/tests/resources/testharness-shadowrealm-outer.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,127 @@ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
globalThis.shadowRealmEvalAsync = function (realm, asyncBody) { | ||
return new Promise(realm.evaluate(` | ||
(resolve, reject) => { | ||
(async () => { | ||
${asyncBody} | ||
})().then(resolve, (e) => reject(e.toString())); | ||
} | ||
`)); | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
globalThis.fetchAdaptor = (resource) => (resolve, reject) => { | ||
fetch(resource) | ||
.then(res => res.text()) | ||
.then(resolve, (e) => reject(e.toString())); | ||
}; | ||
|
||
let sharedWorkerMessagePortPromise; | ||
|
||
|
||
|
||
|
||
|
||
|
||
globalThis.getPostMessageFunc = async function () { | ||
if (typeof postMessage === "function") { | ||
return postMessage; | ||
} | ||
|
||
if (typeof clients === "object") { | ||
|
||
|
||
const allClients = await clients.matchAll({ includeUncontrolled: true }); | ||
return function broadcast(msg) { | ||
allClients.map(client => client.postMessage(msg)); | ||
} | ||
} | ||
|
||
if (sharedWorkerMessagePortPromise) { | ||
return await sharedWorkerMessagePortPromise; | ||
} | ||
|
||
throw new Error("getPostMessageFunc is intended for Worker scopes"); | ||
} | ||
|
||
|
||
let savedResolver; | ||
if (globalThis.constructor.name === "SharedWorkerGlobalScope") { | ||
sharedWorkerMessagePortPromise = new Promise((resolve) => { | ||
savedResolver = resolve; | ||
}); | ||
addEventListener("connect", function (event) { | ||
const port = event.ports[0]; | ||
savedResolver(port.postMessage.bind(port)); | ||
}); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
globalThis.setupFakeDynamicImportInShadowRealm = function(realm, adaptor) { | ||
function fetchModuleTextExecutor(url) { | ||
return (resolve, reject) => { | ||
new Promise(adaptor(url)) | ||
.then(text => realm.evaluate(text + ";\nundefined")) | ||
.then(resolve, (e) => reject(e.toString())); | ||
} | ||
} | ||
|
||
realm.evaluate(` | ||
(fetchModuleTextExecutor) => { | ||
globalThis.fakeDynamicImport = function (url) { | ||
return new Promise(fetchModuleTextExecutor(url)); | ||
} | ||
} | ||
`)(fetchModuleTextExecutor); | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
globalThis.setupFakeFetchOverMessagePort = function (port) { | ||
port.addEventListener("message", (event) => { | ||
if (typeof event.data !== "string" || !event.data.startsWith("fetchRequest::")) { | ||
return; | ||
} | ||
|
||
fetch(event.data.slice("fetchRequest::".length)) | ||
.then(res => res.text()) | ||
.then( | ||
text => port.postMessage(`fetchResult::success::${text}`), | ||
error => port.postMessage(`fetchResult::fail::${error}`), | ||
); | ||
}); | ||
port.start(); | ||
} |
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/streams/idlharness-shadowrealm.window.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
|
||
idl_test_shadowrealm(["streams"], ["dom"]); |
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
Oops, something went wrong.