-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WPT] Test script's base URL used in dynamic imports
This CL checks base URL used in resolving relative URL-like specifiers in dynamic imports() from - `<script>`s, - worker top-level scripts, and - worker scripts imported by `importScripts()`. This is for whatwg/html#5751. Bug: 1082086 Change-Id: I778fb4d34b2e61f57799600006963c93aee5272c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2198835 Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/master@{#794492}
- Loading branch information
1 parent
983d351
commit 82ef69f
Showing
8 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...ntics/scripting-1/the-script-element/module/dynamic-import/alpha/base-url-worker.sub.html
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,10 @@ | ||
<!DOCTYPE html> | ||
<title>Base URLs used in resolving specifiers in dynamic imports from workers</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
fetch_tests_from_worker(new Worker( | ||
"../beta/redirect.py?location=http://{{host}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.js")); | ||
fetch_tests_from_worker(new Worker( | ||
"./worker-importScripts.sub.js")); | ||
</script> |
28 changes: 28 additions & 0 deletions
28
html/semantics/scripting-1/the-script-element/module/dynamic-import/alpha/base-url.sub.html
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,28 @@ | ||
<!DOCTYPE html> | ||
<title>Base URLs used in resolving specifiers in dynamic imports</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<script> | ||
self.testName = "same origin classic <script>"; | ||
self.baseUrlSanitized = false; | ||
</script> | ||
<script src="../beta/redirect.py?location=http://{{host}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.js"></script> | ||
|
||
<script> | ||
self.testName = "cross origin classic <script> without crossorigin attribute"; | ||
self.baseUrlSanitized = true; | ||
</script> | ||
<script src="../beta/redirect.py?location=http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.js"></script> | ||
|
||
<script> | ||
self.testName = "cross origin classic <script> with crossorigin attribute"; | ||
self.baseUrlSanitized = false; | ||
</script> | ||
<script src="../beta/redirect.py?location=http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.js%3Fpipe=header(Access-Control-Allow-Origin,*)" crossorigin></script> | ||
|
||
<script> | ||
self.testName = "cross origin module <script>"; | ||
self.baseUrlSanitized = false; | ||
</script> | ||
<script src="../beta/redirect.py?location=http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.js%3Fpipe=header(Access-Control-Allow-Origin,*)" type="module"></script> |
1 change: 1 addition & 0 deletions
1
html/semantics/scripting-1/the-script-element/module/dynamic-import/alpha/import.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 @@ | ||
export const A = { "from": "alpha/import.js" }; |
15 changes: 15 additions & 0 deletions
15
...cs/scripting-1/the-script-element/module/dynamic-import/alpha/worker-importScripts.sub.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,15 @@ | ||
"use strict"; | ||
|
||
importScripts("/resources/testharness.js"); | ||
|
||
// CORS-same-origin | ||
self.testName = "same-origin importScripts()"; | ||
self.baseUrlSanitized = false; | ||
importScripts("../beta/redirect.py?location=http://{{host}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.js"); | ||
|
||
// CORS-cross-origin | ||
self.testName = "cross-origin importScripts()"; | ||
self.baseUrlSanitized = true; | ||
importScripts("../beta/redirect.py?location=http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.js"); | ||
|
||
done(); |
1 change: 1 addition & 0 deletions
1
html/semantics/scripting-1/the-script-element/module/dynamic-import/beta/import.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 @@ | ||
export const A = { "from": "beta/import.js" }; |
19 changes: 19 additions & 0 deletions
19
html/semantics/scripting-1/the-script-element/module/dynamic-import/beta/redirect.py
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,19 @@ | ||
def main(request, response): | ||
"""Simple handler that causes redirection. | ||
The request should typically have two query parameters: | ||
status - The status to use for the redirection. Defaults to 302. | ||
location - The resource to redirect to. | ||
""" | ||
status = 302 | ||
if b"status" in request.GET: | ||
try: | ||
status = int(request.GET.first(b"status")) | ||
except ValueError: | ||
pass | ||
|
||
response.status = status | ||
|
||
location = request.GET.first(b"location") | ||
|
||
response.headers.set(b"Location", location) |
58 changes: 58 additions & 0 deletions
58
html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/base-url.sub.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,58 @@ | ||
"use strict"; | ||
|
||
// This script triggers import(), and thus the base URL of this script | ||
// (either loaded by `<script>` or `importScripts()`) is used as the base URL | ||
// of resolving relative URL-like specifiers in `import()`. | ||
|
||
// The following fields should be set by the callers of this script | ||
// (unless loaded as the worker top-level script): | ||
// - self.testName (string) | ||
// - self.baseUrlSanitized (boolean) | ||
|
||
// When this script is loaded as the worker top-level script: | ||
if ('DedicatedWorkerGlobalScope' in self && | ||
self instanceof DedicatedWorkerGlobalScope && | ||
!self.testName) { | ||
importScripts("/resources/testharness.js"); | ||
self.testName = 'worker top-level script'; | ||
// Worker top-level scripts are always same-origin. | ||
self.baseUrlSanitized = false; | ||
} | ||
|
||
{ | ||
// This could change by the time the test is executed, so we save it now. | ||
// As this script is loaded multiple times, savedBaseUrlSanitized is scoped. | ||
const savedBaseUrlSanitized = self.baseUrlSanitized; | ||
|
||
promise_test(() => { | ||
const promise = import("./import.js?pipe=header(Access-Control-Allow-Origin,*)&label=relative-" + self.testName); | ||
if (savedBaseUrlSanitized) { | ||
// The base URL is "about:blank" and thus import() here should fail. | ||
return promise.then(module => { | ||
// This code should be unreached, but assert_equals() is used here | ||
// to log `module.A["from"]` in case of unexpected resolution. | ||
assert_equals(module.A["from"], "(unreached)", | ||
"Relative URL-like specifier resolution should fail"); | ||
assert_unreached(); | ||
}, | ||
() => {}); | ||
} else { | ||
// The base URL is the response URL of this script, i.e. | ||
// `.../gamma/base-url.sub.js`. | ||
return promise.then(module => { | ||
assert_equals(module.A["from"], "gamma/import.js"); | ||
}); | ||
} | ||
}, | ||
"Relative URL-like from " + self.testName); | ||
} | ||
|
||
promise_test(() => { | ||
return import("http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/import.js?pipe=header(Access-Control-Allow-Origin,*)&label=absolute-" + self.testName) | ||
.then(module => { | ||
assert_equals(module.A["from"], "gamma/import.js"); | ||
}) | ||
}, | ||
"Absolute URL-like from " + self.testName); | ||
|
||
done(); |
1 change: 1 addition & 0 deletions
1
html/semantics/scripting-1/the-script-element/module/dynamic-import/gamma/import.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 @@ | ||
export const A = { "from": "gamma/import.js" }; |