From e6d2ecbc488dcaa856e3075a049bb81694d1fe8d Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Sun, 1 Dec 2024 01:00:33 +0000 Subject: [PATCH] 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 https://github.com/whatwg/html/pull/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: 6e028bd2e67651237d696535280054f7c544f251 --- .../idlharness-shadowrealm.window.js | 16 + .../console/idlharness-shadowrealm.window.js | 16 + .../tests/docs/writing-tests/testharness.md | 272 ++ .../dom/idlharness-shadowrealm.window.js | 16 + .../encoding/idlharness-shadowrealm.window.js | 16 + .../hr-time/idlharness-shadowrealm.window.js | 16 + .../html/dom/idlharness-shadowrealm.window.js | 16 + .../idlharness-shadowrealm.window.js | 16 + .../tests/resources/idlharness-shadowrealm.js | 161 +- ...rness-shadowrealm-audioworkletprocessor.js | 372 +++ .../testharness-shadowrealm-inner.js | 217 ++ .../testharness-shadowrealm-outer.js | 985 +++++++ .../streams/idlharness-shadowrealm.window.js | 16 + .../tests/tools/manifest/sourcefile.py | 173 ++ .../web-platform/tests/tools/serve/serve.py | 2358 ++++++++++++++--- .../url/idlharness-shadowrealm.window.js | 16 + .../idlharness-shadowrealm.window.js | 16 + .../jsapi/idlharness-shadowrealm.window.js | 16 + .../webidl/idlharness-shadowrealm.window.js | 16 + 19 files changed, 4182 insertions(+), 548 deletions(-) create mode 100644 testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js create mode 100644 testing/web-platform/tests/resources/testharness-shadowrealm-inner.js create mode 100644 testing/web-platform/tests/resources/testharness-shadowrealm-outer.js diff --git a/testing/web-platform/tests/compression/idlharness-shadowrealm.window.js b/testing/web-platform/tests/compression/idlharness-shadowrealm.window.js index 0f94434652ce5..c4499f90ae8ad 100644 --- a/testing/web-platform/tests/compression/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/compression/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/console/idlharness-shadowrealm.window.js b/testing/web-platform/tests/console/idlharness-shadowrealm.window.js index 8585a57ea98e1..4f542a37ffbd2 100644 --- a/testing/web-platform/tests/console/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/console/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/docs/writing-tests/testharness.md b/testing/web-platform/tests/docs/writing-tests/testharness.md index 0e7981fd1125c..4841b8a7b8bc5 100644 --- a/testing/web-platform/tests/docs/writing-tests/testharness.md +++ b/testing/web-platform/tests/docs/writing-tests/testharness.md @@ -1544,6 +1544,10 @@ worker scopes * shadowrealm +- +in +- +window : runs the @@ -1596,12 +1600,280 @@ var any . shadowrealm +- +in +- +window +. +html +< +/ +code +> +* +shadowrealm +- +in +- +shadowrealm +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +another +ShadowRealm +context +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +shadowrealm +- +in +- +shadowrealm +. +html +< +/ +code +> +* +shadowrealm +- +in +- +dedicatedworker +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +a +dedicated +worker +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +shadowrealm +- +in +- +dedicatedworker . html < / code > +* +shadowrealm +- +in +- +sharedworker +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +a +shared +worker +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +shadowrealm +- +in +- +sharedworker +. +html +< +/ +code +> +* +shadowrealm +- +in +- +serviceworker +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +a +service +worker +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +https +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +< +/ +code +> +* +shadowrealm +- +in +- +audioworklet +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +an +AudioWorklet +processor +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +https +. +any +. +shadowrealm +- +in +- +audioworklet +. +html +< +/ +code +> +* +shadowrealm +: +shorthand +for +all +of +the +ShadowRealm +scopes To check what diff --git a/testing/web-platform/tests/dom/idlharness-shadowrealm.window.js b/testing/web-platform/tests/dom/idlharness-shadowrealm.window.js index d8389c92388c4..3ff4a0eaeaa9a 100644 --- a/testing/web-platform/tests/dom/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/dom/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/encoding/idlharness-shadowrealm.window.js b/testing/web-platform/tests/encoding/idlharness-shadowrealm.window.js index 720d58327bf36..a8f4f2d44f551 100644 --- a/testing/web-platform/tests/encoding/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/encoding/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.js b/testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.js index 0b056039b136a..d71d76b750839 100644 --- a/testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/html/dom/idlharness-shadowrealm.window.js b/testing/web-platform/tests/html/dom/idlharness-shadowrealm.window.js index 8d5575b41cb7e..c6362063f8a5f 100644 --- a/testing/web-platform/tests/html/dom/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/html/dom/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/performance-timeline/idlharness-shadowrealm.window.js b/testing/web-platform/tests/performance-timeline/idlharness-shadowrealm.window.js index 9cfdbc5f70b69..2f8244b48c129 100644 --- a/testing/web-platform/tests/performance-timeline/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/performance-timeline/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/resources/idlharness-shadowrealm.js b/testing/web-platform/tests/resources/idlharness-shadowrealm.js index b53e4a11f018b..28e14d74f1a8f 100644 --- a/testing/web-platform/tests/resources/idlharness-shadowrealm.js +++ b/testing/web-platform/tests/resources/idlharness-shadowrealm.js @@ -1,4 +1,23 @@ / +* +global +shadowRealmEvalAsync +* +/ +/ +/ +requires +/ +resources +/ +idlharness +- +shadowrealm +- +outer +. +js +/ / TODO : @@ -231,90 +250,6 @@ ShadowRealm ( ) ; -/ -/ -https -: -/ -/ -github -. -com -/ -web -- -platform -- -tests -/ -wpt -/ -issues -/ -31996 -realm -. -evaluate -( -" -globalThis -. -self -= -globalThis -; -undefined -; -" -) -; -realm -. -evaluate -( -globalThis -. -self -. -GLOBAL -= -{ -isWindow -: -function -( -) -{ -return -false -; -} -isWorker -: -function -( -) -{ -return -false -; -} -isShadowRealm -: -function -( -) -{ -return -true -; -} -} -; -undefined -; -) -; const specs = @@ -368,27 +303,26 @@ specs ) ; await -new -Promise +shadowRealmEvalAsync ( realm -. -evaluate -( -( -resolve -reject -) -= -> -{ -( -async +await +import ( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" ) -= -> -{ +; await import ( @@ -519,31 +453,6 @@ test ( ) ; -} -) -( -) -. -then -( -resolve -( -e -) -= -> -reject -( -e -. -toString -( -) -) -) -; -} -) ) ; await diff --git a/testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js b/testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js new file mode 100644 index 0000000000000..8034cc5b0e8e0 --- /dev/null +++ b/testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js @@ -0,0 +1,372 @@ +/ +* +* +* +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 +) +; diff --git a/testing/web-platform/tests/resources/testharness-shadowrealm-inner.js b/testing/web-platform/tests/resources/testharness-shadowrealm-inner.js new file mode 100644 index 0000000000000..089cae369efba --- /dev/null +++ b/testing/web-platform/tests/resources/testharness-shadowrealm-inner.js @@ -0,0 +1,217 @@ +/ +/ +testharness +file +with +ShadowRealm +utilities +to +be +imported +inside +ShadowRealm +/ +* +* +* +Set +up +all +properties +on +the +ShadowRealm +' +s +global +object +that +tests +will +* +expect +to +be +present +. +* +* +param +{ +string +} +queryString +- +string +to +use +as +value +for +location +. +search +* +used +for +subsetting +some +tests +* +param +{ +function +} +fetchAdaptor +- +a +function +that +takes +a +resource +URI +and +* +returns +a +function +which +itself +takes +a +( +resolve +reject +) +pair +from +the +* +hosting +realm +and +calls +resolve +with +the +text +result +of +fetching +the +* +resource +or +reject +with +a +string +indicating +the +error +that +occurred +* +/ +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 +; +} +} +; diff --git a/testing/web-platform/tests/resources/testharness-shadowrealm-outer.js b/testing/web-platform/tests/resources/testharness-shadowrealm-outer.js new file mode 100644 index 0000000000000..751506d274e06 --- /dev/null +++ b/testing/web-platform/tests/resources/testharness-shadowrealm-outer.js @@ -0,0 +1,985 @@ +/ +/ +testharness +file +with +ShadowRealm +utilities +to +be +imported +in +the +realm +/ +/ +hosting +the +ShadowRealm +/ +* +* +* +Convenience +function +for +evaluating +some +async +code +in +the +ShadowRealm +and +* +waiting +for +the +result +. +* +* +param +{ +ShadowRealm +} +realm +- +the +ShadowRealm +to +evaluate +the +code +in +* +param +{ +string +} +asyncBody +- +the +code +to +evaluate +; +will +be +put +in +the +body +of +* +an +async +function +and +must +return +a +value +explicitly +if +a +value +is +to +be +* +returned +to +the +hosting +realm +. +* +/ +globalThis +. +shadowRealmEvalAsync += +function +( +realm +asyncBody +) +{ +return +new +Promise +( +realm +. +evaluate +( +( +resolve +reject +) += +> +{ +( +async +( +) += +> +{ +{ +asyncBody +} +} +) +( +) +. +then +( +resolve +( +e +) += +> +reject +( +e +. +toString +( +) +) +) +; +} +) +) +; +} +; +/ +* +* +* +Convenience +adaptor +function +for +fetch +( +) +that +can +be +passed +to +* +setShadowRealmGlobalProperties +( +) +( +see +testharness +- +shadowrealm +- +inner +. +js +) +. +* +Used +to +adapt +the +hosting +realm +' +s +fetch +( +) +if +present +to +fetch +a +resource +* +and +pass +its +text +through +the +callable +boundary +to +the +ShadowRealm +. +* +/ +globalThis +. +fetchAdaptor += +( +resource +) += +> +( +resolve +reject +) += +> +{ +fetch +( +resource +) +. +then +( +res += +> +res +. +text +( +) +) +. +then +( +resolve +( +e +) += +> +reject +( +e +. +toString +( +) +) +) +; +} +; +let +sharedWorkerMessagePortPromise +; +/ +* +* +* +Used +when +the +hosting +realm +is +a +worker +. +This +value +is +a +Promise +that +* +resolves +to +a +function +that +posts +a +message +to +the +worker +' +s +message +port +* +just +like +postMessage +( +) +. +The +message +port +is +only +available +asynchronously +in +* +SharedWorkers +and +ServiceWorkers +. +* +/ +globalThis +. +getPostMessageFunc += +async +function +( +) +{ +if +( +typeof +postMessage += += += +" +function +" +) +{ +return +postMessage +; +/ +/ +postMessage +available +directly +in +dedicated +worker +} +if +( +typeof +clients += += += +" +object +" +) +{ +/ +/ +Messages +from +the +ShadowRealm +are +not +in +response +to +any +message +received +/ +/ +from +the +ServiceWorker +' +s +client +so +broadcast +them +to +all +clients +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 +" +) +; +} +/ +/ +Port +available +asynchronously +in +shared +worker +but +not +via +an +async +func +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 +) +) +; +} +) +; +} +/ +* +* +* +Used +when +the +hosting +realm +does +not +permit +dynamic +import +e +. +g +. +in +* +ServiceWorkers +or +AudioWorklets +. +Requires +an +adaptor +function +such +as +* +fetchAdaptor +( +) +above +or +an +equivalent +if +fetch +( +) +is +not +present +in +the +* +hosting +realm +. +* +* +param +{ +ShadowRealm +} +realm +- +the +ShadowRealm +in +which +to +setup +a +* +fakeDynamicImport +( +) +global +function +. +* +param +{ +function +} +adaptor +- +an +adaptor +function +that +does +what +fetchAdaptor +( +) +* +does +. +* +/ +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 +) +; +} +; +/ +* +* +* +Used +when +the +hosting +realm +does +not +expose +fetch +( +) +i +. +e +. +in +worklets +. +The +* +port +on +the +other +side +of +the +channel +needs +to +send +messages +starting +with +* +' +fetchRequest +: +: +' +and +listen +for +messages +starting +with +' +fetchResult +: +: +' +. +See +* +testharness +- +shadowrealm +- +audioworkletprocessor +. +js +. +* +* +param +{ +port +} +MessagePort +- +the +message +port +on +which +to +listen +for +fetch +* +requests +* +/ +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 +( +) +; +} diff --git a/testing/web-platform/tests/streams/idlharness-shadowrealm.window.js b/testing/web-platform/tests/streams/idlharness-shadowrealm.window.js index 9f70c7df91553..7eca47ff00ec7 100644 --- a/testing/web-platform/tests/streams/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/streams/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/tools/manifest/sourcefile.py b/testing/web-platform/tests/tools/manifest/sourcefile.py index 02a87bf644257..cca6f5b1fb3b3 100644 --- a/testing/web-platform/tests/tools/manifest/sourcefile.py +++ b/testing/web-platform/tests/tools/manifest/sourcefile.py @@ -638,11 +638,184 @@ { } +" +shadowrealm +- +in +- +window +" +: +{ +} + +" +shadowrealm +- +in +- +shadowrealm +" +: +{ +} + +" +shadowrealm +- +in +- +dedicatedworker +" +: +{ +} + +" +shadowrealm +- +in +- +sharedworker +" +: +{ +} + +" +shadowrealm +- +in +- +serviceworker +" +: +{ + +" +force_https +" +: +True + +" +suffix +" +: +" +. +https +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +" + +} + +" +shadowrealm +- +in +- +audioworklet +" +: +{ + +" +force_https +" +: +True + +" +suffix +" +: +" +. +https +. +any +. +shadowrealm +- +in +- +audioworklet +. +html +" + +} + " shadowrealm " : { +" +longhand +" +: +{ + +" +shadowrealm +- +in +- +window +" + +" +shadowrealm +- +in +- +shadowrealm +" + +" +shadowrealm +- +in +- +dedicatedworker +" + +" +shadowrealm +- +in +- +sharedworker +" + +" +shadowrealm +- +in +- +serviceworker +" + +" +shadowrealm +- +in +- +audioworklet +" + +} } " diff --git a/testing/web-platform/tests/tools/serve/serve.py b/testing/web-platform/tests/tools/serve/serve.py index bace671c327d4..5ef4bcafb442b 100644 --- a/testing/web-platform/tests/tools/serve/serve.py +++ b/testing/web-platform/tests/tools/serve/serve.py @@ -3515,7 +3515,7 @@ " " class -ShadowRealmHandler +ShadowRealmInWindowHandler ( HtmlWrapperHandler ) @@ -3525,6 +3525,10 @@ = " shadowrealm +- +in +- +window " path_replace @@ -3536,6 +3540,10 @@ any . shadowrealm +- +in +- +window . html " @@ -3607,6 +3615,27 @@ > < script +src += +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +> +< +/ +script +> +< +script > ( async @@ -3624,127 +3653,43 @@ ) ; -r -. -evaluate +await +shadowRealmEvalAsync ( -" -globalThis -. -self -= -globalThis -; -undefined -; -" -) -; - r -. -evaluate -( -func -= -> -{ -globalThis -. -fetch_json -= -( -resource -) -= -> -{ - -const -thenMethod -= -func -( -resource -) -; - -return -new -Promise -( -( -resolve -reject -) -= -> -thenMethod -( -( -s -) -= -> -resolve +await +import ( -JSON +" +/ +resources +/ +testharness +- +shadowrealm +- +inner . -parse -( -s -) -) -reject -) +js +" ) ; -} -; - -} -) -( -( -resource -) -= -> -function -( -resolve -reject -) -{ - -fetch -( -resource -) -. -then -( -res -= -> -res -. -text +await +import ( -) -String -) +" +/ +resources +/ +testharness . -then -( -resolve -reject +js +" ) ; -} ) ; @@ -3752,120 +3697,29 @@ . evaluate ( -s -= -> -{ - -globalThis -. -location -= -{ -search -: -s -} -; - -} +" +setShadowRealmGlobalProperties +" ) ( location . search +fetchAdaptor ) ; await -new -Promise +shadowRealmEvalAsync ( r -. -evaluate -( -( -resolve -reject -) -= -> -{ - -( -async -( -) -= -> -{ - -globalThis -. -self -. -GLOBAL -= -{ - -isWindow -: -function -( -) -{ -return -false -; -} - -isWorker -: -function -( -) -{ -return -false -; -} - -isShadowRealm -: -function -( -) -{ -return -true -; -} - -} -; - -await -import -( -" -/ -resources -/ -testharness -. -js -" -) -; - % ( script ) s - + await import ( @@ -3878,34 +3732,7 @@ " ) ; - -} -) -( -) -. -then -( -resolve -( -e -) -= -> -reject -( -e -. -toString -( -) -) -) -; - -} -) ) ; @@ -3969,44 +3796,1239 @@ return None class -BaseWorkerHandler +ShadowRealmInShadowRealmHandler ( -WrapperHandler +HtmlWrapperHandler ) : -headers +global_type = -[ +" +shadowrealm +- +in +- +shadowrealm +" + +path_replace += +[ +( +" +. +any +. +shadowrealm +- +in +- +shadowrealm +. +html +" +" +. +any +. +js +" +) +] + +wrapper += +" +" +" +< +! +doctype +html +> +< +meta +charset += +utf +- +8 +> +% +( +meta +) +s +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +> +< +/ +script +> +< +script +> +( +async +function +( +) +{ + +const +outer += +new +ShadowRealm +( +) +; + +outer +. +evaluate +( + +var +inner += +new +ShadowRealm +( +) +; + +) +; + +await +shadowRealmEvalAsync +( +outer + +await +import +( +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +) +; + +await +shadowRealmEvalAsync +( +inner +\ +\ + +await +import +( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" +) +; + +await +import +( +" +/ +resources +/ +testharness +. +js +" +) +; + +\ +\ +) +; + +) +; + +outer +. +evaluate +( + +inner +. +evaluate +( +" +setShadowRealmGlobalProperties +" +) + +) +( +location +. +search +fetchAdaptor +) +; + +await +shadowRealmEvalAsync +( +outer + +await +shadowRealmEvalAsync +( +inner +\ +\ + +% +( +script +) +s + +await +import +( +" +% +( +path +) +s +" +) +; + +\ +\ +) +; + +) +; + +outer +. +evaluate +( + +function +begin_shadow_realm_tests +( +windowCallback +) +{ + +inner +. +evaluate +( +" +begin_shadow_realm_tests +" +) +( +windowCallback +) +; + +} + +) +; + +await +fetch_tests_from_shadow_realm +( +outer +) +; + +done +( +) +; +} +) +( +) +; +< +/ +script +> +" +" +" + +def +_script_replacement +( +self +key +value +) +: + +if +key += += +" +script +" +: + +return +' +await +import +( +" +% +s +" +) +; +' +% +value + +return +None +class +ShadowRealmInDedicatedWorkerHandler +( +WorkersHandler +) +: + +global_type += +" +shadowrealm +- +in +- +dedicatedworker +" + +path_replace += +[ +( +" +. +any +. +shadowrealm +- +in +- +dedicatedworker +. +html +" + +" +. +any +. +js +" + +" +. +any +. +worker +- +shadowrealm +. +js +" +) +] +class +ShadowRealmInSharedWorkerHandler +( +SharedWorkersHandler +) +: + +global_type += +" +shadowrealm +- +in +- +sharedworker +" + +path_replace += +[ +( +" +. +any +. +shadowrealm +- +in +- +sharedworker +. +html +" + +" +. +any +. +js +" + +" +. +any +. +worker +- +shadowrealm +. +js +" +) +] +class +ShadowRealmInServiceWorkerHandler +( +ServiceWorkersHandler +) +: + +global_type += +" +shadowrealm +- +in +- +serviceworker +" + +path_replace += +[ +( +" +. +https +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +" + +" +. +any +. +js +" + +" +. +any +. +serviceworker +- +shadowrealm +. +js +" +) +] +class +ShadowRealmInAudioWorkletHandler +( +HtmlWrapperHandler +) +: + +global_type += +" +shadowrealm +- +in +- +audioworklet +" + +path_replace += +[ +( +" +. +https +. +any +. +shadowrealm +- +in +- +audioworklet +. +html +" +" +. +any +. +js +" + +" +. +any +. +audioworklet +- +shadowrealm +. +js +" +) +] + +wrapper += +" +" +" +< +! +doctype +html +> +< +meta +charset += +utf +- +8 +> +% +( +meta +) +s +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +> +< +/ +script +> +< +script +> +( +async +function +( +) +{ + +const +context += +new +AudioContext +( +) +; + +await +context +. +audioWorklet +. +addModule +( + +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +) +; + +await +context +. +audioWorklet +. +addModule +( + +" +/ +resources +/ +testharness +- +shadowrealm +- +audioworkletprocessor +. +js +" +) +; + +await +context +. +audioWorklet +. +addModule +( +" +% +( +path +) +s +% +( +query +) +s +" +) +; + +const +node += +new +AudioWorkletNode +( +context +" +test +- +runner +" +) +; + +setupFakeFetchOverMessagePort +( +node +. +port +) +; + +fetch_tests_from_worker +( +node +. +port +) +; +} +) +( +) +; +< +/ +script +> +" +" +" +class +BaseWorkerHandler +( +WrapperHandler +) +: + +headers += +[ +( +' +Content +- +Type +' +' +text +/ +javascript +' +) +] + +def +_meta_replacement +( +self +key +value +) +: + +return +None + +abc +. +abstractmethod + +def +_create_script_import +( +self +attribute +) +: + +# +Take +attribute +( +a +string +URL +to +a +JS +script +) +and +return +JS +source +to +import +the +script + +# +into +the +worker +. + +pass + +def +_script_replacement +( +self +key +value +) +: + +if +key += += +" +script +" +: + +attribute += +value +. +replace +( +" +\ +\ +" +" +\ +\ +\ +\ +" +) +. +replace +( +' +" +' +' +\ +\ +" +' +) + +return +self +. +_create_script_import +( +attribute +) + +if +key += += +" +title +" +: + +value += +value +. +replace +( +" +\ +\ +" +" +\ +\ +\ +\ +" +) +. +replace +( +' +" +' +' +\ +\ +" +' +) + +return +' +self +. +META_TITLE += +" +% +s +" +; +' +% +value + +return +None +class +ClassicWorkerHandler +( +BaseWorkerHandler +) +: + +path_replace += +[ +( +" +. +any +. +worker +. +js +" +" +. +any +. +js +" +) +] + +wrapper += +" +" +" +% +( +meta +) +s +self +. +GLOBAL += +{ + +isWindow +: +function +( +) +{ +return +false +; +} + +isWorker +: +function +( +) +{ +return +true +; +} + +isShadowRealm +: +function +( +) +{ +return +false +; +} +} +; +importScripts +( +" +/ +resources +/ +testharness +. +js +" +) +; +% +( +script +) +s +importScripts +( +" +% +( +path +) +s +" +) +; +done +( +) +; +" +" +" + +def +_create_script_import +( +self +attribute +) +: + +return +' +importScripts +( +" +% +s +" +) +' +% +attribute +class +ModuleWorkerHandler +( +BaseWorkerHandler +) +: + +path_replace += +[ +( +" +. +any +. +worker +- +module +. +js +" +" +. +any +. +js +" +) +] + +wrapper += +" +" +" +% +( +meta +) +s +self +. +GLOBAL += +{ + +isWindow +: +function +( +) +{ +return +false +; +} + +isWorker +: +function +( +) +{ +return +true +; +} + +isShadowRealm +: +function +( +) +{ +return +false +; +} +} +; +import +" +/ +resources +/ +testharness +. +js +" +; +% +( +script +) +s +import +" +% ( -' -Content -- -Type -' -' -text -/ -javascript -' +path ) -] - -def -_meta_replacement +s +" +; +done ( -self -key -value ) -: - -return -None - -abc -. -abstractmethod +; +" +" +" def _create_script_import @@ -4016,149 +5038,250 @@ ) : -# -Take +return +' +import +" +% +s +" +; +' +% attribute +class +ShadowRealmWorkerWrapperHandler ( -a -string -URL -to -a -JS -script +BaseWorkerHandler ) -and -return -JS -source -to -import -the -script - -# -into -the +: + +path_replace += +[ +( +" +. +any +. worker +- +shadowrealm . - -pass +js +" +" +. +any +. +js +" +) +] -def -_script_replacement +wrapper += +" +" +" +% ( -self -key -value +meta ) -: - -if -key -= -= +s +importScripts +( " -script +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js " -: - -attribute +) +; +( +async +function +( +) +{ + +const +r = -value -. -replace +new +ShadowRealm +( +) +; + +await +shadowRealmEvalAsync +( +r + +await +import ( " -\ -\ +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js " +) +; + +await +import +( " -\ -\ -\ -\ +/ +resources +/ +testharness +. +js " ) +; + +) +; + +r . -replace +evaluate ( -' " -' -' -\ -\ +setShadowRealmGlobalProperties " -' ) - -return -self -. -_create_script_import ( -attribute +" +% +( +query ) - -if -key -= -= +s " -title +fetchAdaptor +) +; + +await +shadowRealmEvalAsync +( +r + +% +( +script +) +s + +await +import +( " -: - -value +% +( +path +) +s +" +) +; + +) +; + +const +postMessageFunc = -value +await +getPostMessageFunc +( +) +; + +function +forwardMessage +( +msgJSON +) +{ + +postMessageFunc +( +JSON . -replace +parse ( -" -\ -\ -" -" -\ -\ -\ -\ -" +msgJSON ) +) +; + +} + +r . -replace +evaluate ( ' -" -' +begin_shadow_realm_tests ' -\ -\ +) +( +forwardMessage +) +; +} +) +( +) +; " -' +" +" + +def +_create_script_import +( +self +attribute ) - +: + return ' -self -. -META_TITLE -= +await +import +( " % s " +) ; ' % -value - -return -None +attribute class -ClassicWorkerHandler +ShadowRealmServiceWorkerWrapperHandler ( BaseWorkerHandler ) @@ -4172,7 +5295,9 @@ . any . -worker +serviceworker +- +shadowrealm . js " @@ -4195,47 +5320,70 @@ meta ) s -self +importScripts +( +" +/ +resources +/ +testharness +- +shadowrealm +- +outer . -GLOBAL -= -{ - -isWindow -: +js +" +) +; +( +async function ( ) { -return -false -; -} -isWorker -: -function +const +r += +new +ShadowRealm ( ) -{ -return -true ; -} -isShadowRealm -: -function +setupFakeDynamicImportInShadowRealm ( +r +fetchAdaptor ) -{ -return -false ; -} -} + +await +shadowRealmEvalAsync +( +r + +await +fakeDynamicImport +( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" +) ; -importScripts + +await +fakeDynamicImport ( " / @@ -4247,12 +5395,43 @@ " ) ; + +) +; + +r +. +evaluate +( +" +setShadowRealmGlobalProperties +" +) +( +" +% +( +query +) +s +" +fetchAdaptor +) +; + +await +shadowRealmEvalAsync +( +r + % ( script ) s -importScripts + +await +fakeDynamicImport ( " % @@ -4263,7 +5442,53 @@ " ) ; -done + +) +; + +const +postMessageFunc += +await +getPostMessageFunc +( +) +; + +function +forwardMessage +( +msgJSON +) +{ + +postMessageFunc +( +JSON +. +parse +( +msgJSON +) +) +; + +} + +r +. +evaluate +( +" +begin_shadow_realm_tests +" +) +( +forwardMessage +) +; +} +) ( ) ; @@ -4281,18 +5506,20 @@ return ' -importScripts +await +fakeDynamicImport ( " % s " ) +; ' % attribute class -ModuleWorkerHandler +ShadowRealmAudioWorkletWrapperHandler ( BaseWorkerHandler ) @@ -4306,9 +5533,9 @@ . any . -worker +audioworklet - -module +shadowrealm . js " @@ -4331,47 +5558,108 @@ meta ) s -self +TestRunner . -GLOBAL +prototype +. +createShadowRealmAndStartTests = +async +function +( +) { -isWindow +const +queryPart += +import +. +meta +. +url +. +split +( +' +? +' +) +[ +1 +] +; + +const +locationSearch += +queryPart +? +' +? +' ++ +queryPart : -function +' +' +; + +const +r += +new +ShadowRealm +( +) +; + +const +adaptor += +this +. +fetchOverPortExecutor +. +bind ( +this ) -{ -return -false ; -} -isWorker -: -function +setupFakeDynamicImportInShadowRealm ( +r +adaptor ) -{ -return -true ; -} -isShadowRealm -: -function +await +shadowRealmEvalAsync +( +r + +await +fakeDynamicImport ( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" ) -{ -return -false -; -} -} ; -import + +await +fakeDynamicImport +( " / resources @@ -4380,13 +5668,40 @@ . js " +) +; + +) +; + +r +. +evaluate +( +" +setShadowRealmGlobalProperties +" +) +( +locationSearch +adaptor +) ; + +await +shadowRealmEvalAsync +( +r + % ( script ) s -import + +await +fakeDynamicImport +( " % ( @@ -4394,11 +5709,49 @@ ) s " +) ; -done + +) +; + +const +forwardMessage += +( +msgJSON +) += +> + +this +. +port +. +postMessage +( +JSON +. +parse +( +msgJSON +) +) +; + +r +. +evaluate +( +" +begin_shadow_realm_tests +" +) ( +forwardMessage ) ; +} " " " @@ -4413,11 +5766,14 @@ return ' -import +await +fakeDynamicImport +( " % s " +) ; ' % @@ -4995,10 +6351,114 @@ any . shadowrealm +- +in +- +window +. +html +" +ShadowRealmInWindowHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +shadowrealm +. +html +" +ShadowRealmInShadowRealmHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +dedicatedworker +. +html +" +ShadowRealmInDedicatedWorkerHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +sharedworker +. +html +" +ShadowRealmInSharedWorkerHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +" +ShadowRealmInServiceWorkerHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +audioworklet . html " -ShadowRealmHandler +ShadowRealmInAudioWorkletHandler ) ( @@ -5053,6 +6513,60 @@ ModuleWorkerHandler ) +( +" +GET +" +" +* +. +any +. +serviceworker +- +shadowrealm +. +js +" +ShadowRealmServiceWorkerWrapperHandler +) + +( +" +GET +" +" +* +. +any +. +worker +- +shadowrealm +. +js +" +ShadowRealmWorkerWrapperHandler +) + +( +" +GET +" +" +* +. +any +. +audioworklet +- +shadowrealm +. +js +" +ShadowRealmAudioWorkletWrapperHandler +) + ( " GET diff --git a/testing/web-platform/tests/url/idlharness-shadowrealm.window.js b/testing/web-platform/tests/url/idlharness-shadowrealm.window.js index 938b5a3bd7549..e7f859ecd4cc7 100644 --- a/testing/web-platform/tests/url/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/url/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js b/testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js index 44c3f5048e614..d0e313f7aa6c3 100644 --- a/testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/wasm/jsapi/idlharness-shadowrealm.window.js b/testing/web-platform/tests/wasm/jsapi/idlharness-shadowrealm.window.js index 2bde10e98bf90..7adc45597b359 100644 --- a/testing/web-platform/tests/wasm/jsapi/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/wasm/jsapi/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm diff --git a/testing/web-platform/tests/webidl/idlharness-shadowrealm.window.js b/testing/web-platform/tests/webidl/idlharness-shadowrealm.window.js index fa2e24fbaf504..4ea1fc60bf900 100644 --- a/testing/web-platform/tests/webidl/idlharness-shadowrealm.window.js +++ b/testing/web-platform/tests/webidl/idlharness-shadowrealm.window.js @@ -7,6 +7,22 @@ script / resources / +testharness +- +shadowrealm +- +outer +. +js +/ +/ +META +: +script += +/ +resources +/ idlharness - shadowrealm