diff options
author | WPT Sync Bot <josh+wptsync@joshmatthews.net> | 2021-09-07 11:16:33 +0000 |
---|---|---|
committer | cybai <cyb.ai.815@gmail.com> | 2022-01-17 16:30:29 +0900 |
commit | 58e8ee674b032274959b4461fd46ceda8f709e96 (patch) | |
tree | 4953c044dba6b52224d5144747af1bc3773a7ebc /tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element | |
parent | 35e95f55a1b9e488d1c796c8fb39d764d090d660 (diff) | |
download | servo-58e8ee674b032274959b4461fd46ceda8f709e96.tar.gz servo-58e8ee674b032274959b4461fd46ceda8f709e96.zip |
Update web-platform-tests to revision b'468d01bbd84da2babf265c6af46947be68713440'
Diffstat (limited to 'tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element')
96 files changed, 1454 insertions, 373 deletions
diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005.htm b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005.htm index 7d79657bf7b..03f9adeb67e 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005.htm +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005.htm @@ -17,7 +17,10 @@ function timeout() { - t.step(function(){ assert_equals(document.getElementById("testresult").innerHTML, "2134")}); + t.step(function(){ + var actual = document.getElementById("testresult").innerHTML; + assert_in_array(actual, ["2134", "2341"]); + }); t.done(); } diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-2.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-2.html new file mode 100644 index 00000000000..535099b24a6 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-2.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<meta charset="windows-1250"> +<title>CSS modules: UTF-8 decoding</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script type="module"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/utf-8.css" assert { type: "css"}; + test(() => { + assert_equals(styleSheet.rules[0].style.content, "\"�湿�\""); + }, "CSS module should be loaded as utf-8 even though document's encoding is windows-1250"); +</script> +<script type="module"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/windows-1250.css&ct=text/css%3Bcharset=windows-1250" assert { type: "css"}; + test(() => { + assert_not_equals(styleSheet.rules[0].style.content, "\"�湿�\"", + 'Should be decoded as UTF-8'); + }, "CSS module should be loaded as utf-8 even if it is encoded in windows-1250 and served with a windows-1250 charset response header, and this document's encoding is windows-1250"); +</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-bom.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-bom.html new file mode 100644 index 00000000000..e26ee08d31d --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-bom.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<title>CSS Module scripts should ignore BOMs and always use UTF-8</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script type="module"> + import utf8BOMSheet from './resources/bom-utf-8.css' assert { type: 'css' }; + test(function() { + assert_equals(utf8BOMSheet.rules[0].selectorText, 'div', 'No UTF-8 BOM expected in selector'); + }, 'UTF-8 BOM should be stripped when decoding JSON module script'); + + import utf16BEBOMSheet from './resources/bom-utf-16be.css' assert { type: 'css' }; + test(function() { + assert_equals(utf16BEBOMSheet.rules[0].selectorText, '\ufffd\ufffd\ufffdd\ufffdi\ufffdv\ufffd \ufffd', 'Expected UTF-8 decoded selectorText with 0xfffd replacement characters'); + }, 'UTF-16BE BOM should be ignored, so CSS module should be UTF-8 decoded'); + + import utf16LEBOMSheet from './resources/bom-utf-16le.css' assert { type: 'css' }; + test(function() { + assert_equals(utf16LEBOMSheet.rules[0].selectorText, '\ufffd\ufffdd\ufffdi\ufffdv\ufffd \ufffd', 'Expected UTF-8 decoded selectorText with 0xfffd replacement characters'); + }, 'UTF-16LE BOM should be ignored, so CSS module should be UTF-8 decoded'); +</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset.html new file mode 100644 index 00000000000..8b72481814b --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>CSS modules: UTF-8 decoding</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script type="module" onerror="unreachable()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/utf-8.css&ct=text/css%3Bcharset=utf-8" assert { type: "css"}; + test(() => { + assert_equals(styleSheet.rules[0].style.content, "\"śćążź\""); + }, "CSS module should be loaded as utf-8 when charset=utf8 is specified"); +</script> +<script type="module" onerror="unreachable()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/utf-8.css&ct=text/css%3Bcharset=shift-jis" assert { type: "css"}; + test(() => { + assert_equals(styleSheet.rules[0].style.content, "\"śćążź\""); + }, "CSS module should be loaded as utf-8 when charset=shift-jis is specified"); +</script> +<script type="module" onerror="unreachable()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/utf-8.css&ct=text/css%3Bcharset=windows-1252" assert { type: "css"}; + test(() => { + assert_equals(styleSheet.rules[0].style.content, "\"śćążź\""); + }, "CSS module should be loaded as utf-8 when charset=windows-1252 is specified"); +</script> +<script type="module" onerror="unreachable()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/utf-8.css&ct=text/css%3Bcharset=utf-7" assert { type: "css"};; + test(() => { + assert_equals(styleSheet.rules[0].style.content, "\"śćążź\""); + }, "CSS module should be loaded as utf-8 when charset=utf-7 is specified"); +</script> +<script type="module" onerror="unreachable()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/windows-1250.css&ct=text/css%3Bcharset=windows-1250" assert { type: "css"}; + test(() => { + assert_not_equals(styleSheet.rules[0].style.content, "\"śćążź\"", + 'Should be decoded as UTF-8'); + }, "CSS module should be loaded as utf-8 even if it is encoded in windows-1250 and served with a windows-1250 charset response header"); +</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking.html new file mode 100644 index 00000000000..105c53c40d9 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>CSS modules: Content-Type</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +function check(t, styleSheet) { + t.step(() => { + assert_equals(styleSheet.rules[0].cssText, "#test { background-color: rgb(255, 0, 0); }"); + t.done(); + }); +} +const t1 = async_test("text/css"); +const t2 = async_test("application/css"); +const t3 = async_test("text/html+css"); +const t4 = async_test("text/css;boundary=something"); +const t5 = async_test("text/css;foo=bar"); +</script> +<script type="module" onerror="t1.unreached_func()()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/basic.css&ct=text/css" assert { type: "css"}; + check(t1, styleSheet); +</script> +<script type="module" onerror="t2.step_func_done()()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/basic.css&ct=application/css" assert { type: "css"}; + t2.unreached_func("Should not have loaded with MIME type application/css")(); +</script> +<script type="module" onerror="t3.step_func_done()()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/basic.css&ct=text/html+css" assert { type: "css"}; + t3.unreached_func("Should not have loaded with MIME type text/html+css")(); +</script> +<script type="module" onerror="t4.unreached_func()()"> + import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/basic.css&ct=text/css;boundary=something" assert { type: "css"}; + check(t4, styleSheet); +</script> +<script type="module" onerror="t5.unreached_func()()"> +import styleSheet from "../serve-with-content-type.py?fn=css-module/resources/basic.css&ct=text/css;foo=bar" assert { type: "css"}; +check(t5, styleSheet); +</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests.html new file mode 100644 index 00000000000..e699ef927ec --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests.html @@ -0,0 +1,33 @@ +<!doctype html> +<html> +<head> + <title>css-module-crossorigin</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <h1>css-module-crossorigin</h1> + <iframe id="import-WithCORS" src="resources/crossorigin-import-with-cors.sub.html"></iframe> + <iframe id="import-NoCORS" src="resources/crossorigin-import-without-cors.sub.html"></iframe> + <iframe id="import-parseerror-WithCors" src="resources/crossorigin-import-parse-error-with-cors.sub.html"></iframe> + <script> + + var tests = [ + { "obj": async_test("Imported CSS module, cross-origin with CORS"), "id": "import-WithCORS", "expected": "imported CSS: #test { background-color: rgb(255, 0, 0); }" }, + { "obj": async_test("Imported CSS module, cross-origin, missing CORS ACAO header"), "id": "import-NoCORS", "expected": "error" }, + { "obj": async_test("Imported CSS module with parse error, cross-origin, with CORS"), "id": "import-parseerror-WithCors", "expected": "imported CSS rules count: 0" }, + ]; + + window.addEventListener("load", function () { + tests.forEach(function (test) { + var target = document.getElementById(test.id); + test.obj.step(function () { + assert_equals(target.contentDocument._log, test.expected, "Unexpected _log value"); + }); + test.obj.done(); + }); + }); + + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub.html new file mode 100644 index 00000000000..0da573dad2b --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> +document.cookie = 'milk=1'; + +const setCookiePromise = fetch( + 'http://{{domains[www2]}}:{{ports[http][0]}}/cookies/resources/set-cookie.py?name=milk&path=/html/semantics/scripting-1/the-script-element/css-module/', + { + mode: 'no-cors', + credentials: 'include', + }); + +const windowLoadPromise = new Promise(resolve => { + window.addEventListener('load', () => { + resolve(); + }); +}); + +promise_test(t => { + const iframe = document.createElement('iframe'); + + return Promise.all([setCookiePromise, windowLoadPromise]).then(() => { + const messagePromise = new Promise(resolve => { + window.addEventListener('message', event => { + resolve(); + }); + }); + + iframe.src = 'resources/credentials-iframe.sub.html'; + document.body.appendChild(iframe); + + return messagePromise; + }).then(() => { + const w = iframe.contentWindow; + + assert_equals(w.sameOriginNoneDescendant, true, + 'Descendant CSS modules should be loaded with the credentials when the crossOrigin attribute is not specified and the target is same-origin'); + assert_equals(w.sameOriginAnonymousDescendant, true, + 'Descendant CSS modules should be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is same-origin'); + assert_equals(w.sameOriginUseCredentialsDescendant, true, + 'Descendant CSS modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is same-origin'); + assert_equals(w.crossOriginNoneDescendant, false, + 'Descendant CSS modules should not be loaded with the credentials when the crossOrigin attribute is not specified and the target is cross-origin'); + assert_equals(w.crossOriginAnonymousDescendant, false, + 'Descendant CSS modules should not be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is cross-origin'); + assert_equals(w.crossOriginUseCredentialsDescendant, true, + 'Descendant CSS modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is cross-origin'); +}); +}, 'CSS Modules should be loaded with or without the credentials based on the same-origin-ness and the crossOrigin attribute'); +</script> +<body> +</body> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic.html index 207d553c69e..4ea1790aabd 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic.html @@ -1,71 +1,83 @@ <!doctype html> - <head> <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> </head> - <body> + <div id="test">I am a test div.</div> + <div id="test2">I am a test div.</div> + <div id="test3">I am a test div.</div> + <div id="test3b">I am a test div.</div> + <div id="test4">I am a test div.</div> + <div id="test4b">I am a test div.</div> <script> - async_test(function (test) { - const iframe = document.createElement("iframe"); - iframe.src = "resources/css-module-basic-iframe.html"; - iframe.onload = test.step_func_done(function () { - assert_equals(getComputedStyle(iframe.contentDocument.querySelector('#test')) - .backgroundColor, "rgb(255, 0, 0)", - "CSS module import should succeed"); - }); - document.body.appendChild(iframe); + window.errorCount = 0; + window.onerror = (errorMsg, url, lineNumber, column, errorObj) => { + window.errorCount++; + }; + </script> + <script type="module" onerror="unreachable()"> + import sheet from "./resources/basic.css" assert { type: "css" }; + test(() => { + document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet]; + assert_equals(getComputedStyle(document.querySelector('#test')) + .backgroundColor, "rgb(255, 0, 0)", "CSS module import should succeed"); }, "A CSS Module should load"); - - async_test(function (test) { + </script> + <script type="module" onerror="unreachable()"> + import sheet from "./resources/basic-large.css" assert { type: "css" }; + test(() => { // This tests potential streaming compilation of modules in // Chromium that is triggered only for large (32>KiB) files in older // versions. - const iframe = document.createElement("iframe"); - iframe.src = "resources/css-module-basic-large-iframe.html"; - iframe.onload = test.step_func_done(function () { - assert_equals(getComputedStyle(iframe.contentDocument.querySelector('#test')) + document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet]; + assert_equals(getComputedStyle(document.querySelector('#test2')) .backgroundColor, "rgb(255, 0, 0)", "CSS module import should succeed"); - }); - document.body.appendChild(iframe); }, "A large CSS Module should load"); - - async_test(function (test) { - const iframe = document.createElement("iframe"); - iframe.src = "resources/css-module-at-import-iframe.html"; - iframe.onload = test.step_func_done(function () { - assert_equals(iframe.contentDocument.load_error, undefined); - assert_not_equals(getComputedStyle(iframe.contentDocument.querySelector('#test')) - .backgroundColor, "rgb(255, 0, 0)", - "CSS module @import should not succeed"); - }); - document.body.appendChild(iframe); + </script> + <script type="module" onerror="unreachable()"> + import sheet from "./resources/bad-import.css" assert { type: "css" }; + test(() => { + document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet]; + assert_equals(window.errorCount, 0); + assert_equals(sheet.cssRules.length, 1, "Parser should skip @import rule"); + assert_equals(getComputedStyle(document.querySelector('#test3b')) + .backgroundColor, "rgba(0, 0, 0, 0)", + "CSS module @import should not succeed"); + assert_equals(getComputedStyle(document.querySelector('#test3')) + .backgroundColor, "rgb(0, 255, 0)", + "Rule after @import should still be applied"); }, "An @import CSS Module should not load, but should not throw an exception"); - - async_test(function (test) { - const iframe = document.createElement("iframe"); - iframe.src = "resources/malformed-iframe.html"; - iframe.onload = test.step_func_done(function () { - assert_not_equals(getComputedStyle(iframe.contentDocument.querySelector('#test')) - .backgroundColor, "rgb(255, 0, 0)", - "Malformed CSS should not load"); - }); - document.body.appendChild(iframe); - }, "Malformed CSS should not load"); - - async_test(function (test) { + </script> + <script type="module" onerror="unreachable()"> + import sheet from "./resources/malformed.css" assert { type: "css" }; + test(() => { + document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet]; + assert_equals(window.errorCount, 0); + assert_equals(sheet.cssRules.length, 1, "Import of malformed CSS should succeed and rules after the parse error should still be parsed"); + assert_equals(getComputedStyle(document.querySelector('#test4')) + .backgroundColor, "rgba(0, 0, 0, 0)", + "Malformed CSS rule should not be applied"); + assert_equals(getComputedStyle(document.querySelector('#test4b')) + .backgroundColor, "rgb(0, 255, 0)", + "Parsing should recover and rules after malformed rules should be applied"); + }, "A parse error should not prevent subsequent rules from being included in a CSS module"); + </script> + <script type="module"> + promise_test(function (test) { const iframe = document.createElement("iframe"); iframe.src = "resources/css-module-without-assertion-iframe.html"; - iframe.onload = test.step_func_done(function () { + return new Promise(resolve => { + iframe.onload = resolve; + document.body.appendChild(iframe); + }).then(event => { assert_equals(iframe.contentDocument.window_onerror, undefined); assert_equals(iframe.contentDocument.script_onerror.type, "error"); - assert_not_equals(getComputedStyle(iframe.contentDocument.querySelector('#test')) - .backgroundColor, "rgb(255, 0, 0)", + assert_equals(getComputedStyle(iframe.contentDocument.querySelector('#test')) + .backgroundColor, "rgba(0, 0, 0, 0)", "CSS module without type assertion should result in a fetch error"); }); - document.body.appendChild(iframe); }, "CSS module without type assertion should result in a fetch error"); </script> </body> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-dynamic.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-dynamic.html index 4fbc11180fa..13967858cb3 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-dynamic.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-dynamic.html @@ -10,7 +10,8 @@ promise_test(async function (test) { const css_module = await import("./resources/basic.css", { assert: { type: "css" }}); assert_true(css_module.default instanceof CSSStyleSheet); - assert_equals(css_module.default.cssRules[0].cssText, "#test { background-color: red; }"); + assert_equals(css_module.default.cssRules[0].cssText, + "#test { background-color: rgb(255, 0, 0); }"); }, "Load a CSS module with dynamic import()"); promise_test(function (test) { diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity.html new file mode 100644 index 00000000000..1dd0dad470a --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title><script> integrity="" with CSS modules</title> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> +window.matchesLog = []; +window.matchesEvents = []; + +window.mismatchesLog = []; +window.mismatchesEvents = []; +</script> +<script type="module" src="resources/integrity-matches.js" integrity="sha384-xvbfmg9iJFHqmCoOS4VNMCwnFPPxEoIlW1Ojzl+fgEd+Wf8Pyez+SMWue+KNovjA" onload="window.matchesEvents.push('load');" onerror="window.matchesEvents.push('error')"></script> +<script type="module" src="resources/integrity-mismatches.js" integrity="sha384-doesnotmatch" onload="window.mismatchesEvents.push('load');" onerror="window.mismatchesEvents.push('error')"></script> + +<script type="module"> +test(() => { + assert_array_equals(window.matchesLog, ["integrity-matches,css:#test { background-color: rgb(255, 0, 0); }"], "The module and its dependency must have executed"); + assert_array_equals(window.matchesEvents, ["load"], "The load event must have fired"); +}, "The integrity attribute must be verified on the top-level of a module loading a CSS module and allow it to execute when it matches"); + +test(() => { + assert_array_equals(window.mismatchesLog, [], "The module and its dependency must not have executed"); + assert_array_equals(window.mismatchesEvents, ["error"], "The error event must have fired"); +}, "The integrity attribute must be verified on the top-level of a module loading a CSS module and not allow it to execute when there's a mismatch"); +</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events.html new file mode 100644 index 00000000000..3457452c936 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events.html @@ -0,0 +1,67 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<head> +<title>load/error events for CSS modules</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="../resources/load-error-events-helpers.js"></script> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block"> +</head> +<script> + "use strict"; + + var test1_load = event_test('inline, 200, parser-inserted', false, false); + var test1_error = event_test('inline, 404, parser-inserted', false, true); + + var test2_load = event_test('src, 200, parser-inserted', true, false); + var test2_error = event_test('src, 404, parser-inserted', false, true); + + var test3_dynamic_load = event_test('src, 200, not parser-inserted', true, false); + var test3_dynamic_error = event_test('src, 404, not parser-inserted', false, true); + + var test4_dynamic_load = event_test('inline, 200, not parser-inserted', false, false); + var test4_dynamic_error = event_test('inline, 404, not parser-inserted', false, true); + + var script3_dynamic_load = document.createElement('script'); + script3_dynamic_load.setAttribute('type', 'module'); + script3_dynamic_load.onload = () => onLoad(test3_dynamic_load); + script3_dynamic_load.onerror = () => onError(test3_dynamic_load); + script3_dynamic_load.src = "./resources/load-error-events.py?test=test3_dynamic_load"; + document.head.appendChild(script3_dynamic_load); + + var script3_dynamic_error = document.createElement('script'); + script3_dynamic_error.setAttribute('type', 'module'); + script3_dynamic_error.onload = () => onLoad(test3_dynamic_error); + script3_dynamic_error.onerror = () => onError(test3_dynamic_error); + script3_dynamic_error.src = "./resources/load-error-events.py?test=test3_dynamic_error"; + document.head.appendChild(script3_dynamic_error); + + var script4_dynamic_load = document.createElement('script'); + script4_dynamic_load.setAttribute('type', 'module'); + script4_dynamic_load.onload = () => onLoad(test4_dynamic_load); + script4_dynamic_load.onerror = () => onError(test4_dynamic_load); + script4_dynamic_load.async = true; + script4_dynamic_load.appendChild(document.createTextNode(` + import "./resources/basic.css" assert { type: "css" }; + onExecute(test4_dynamic_load);` + )); + document.head.appendChild(script4_dynamic_load); + + var script4_dynamic_error = document.createElement('script'); + script4_dynamic_error.setAttribute('type', 'module'); + script4_dynamic_error.onload = () => onLoad(test4_dynamic_error); + script4_dynamic_error.onerror = () => onError(test4_dynamic_error); + script4_dynamic_error.async = true; + script4_dynamic_error.appendChild(document.createTextNode(`import "./not_found.css" assert { type: "css" };`)); + document.head.appendChild(script4_dynamic_error); +</script> +<script onload="onLoad(test1_load);" onerror="onError(test1_load);" type="module"> + import "./resources/basic.css" assert { type: "css"}; + onExecute(test1_load); +</script> +<script onload="onLoad(test1_error);" onerror="onError(test1_error);" type="module"> + import "./not_found.css" assert { type: "css"}; + onExecute(test1_error); +</script> +<script src="./resources/load-error-events.py?test=test2_load" onload="onLoad(test2_load);" onerror="onError(test2_load);" type="module"></script> +<script src="./resources/load-error-events.py?test=test2_error" onload="onLoad(test2_error);" onerror="onError(test2_error);" type="module"></script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/referrer-policies.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/referrer-policies.sub.html new file mode 100644 index 00000000000..efa5340715f --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/referrer-policies.sub.html @@ -0,0 +1,84 @@ +<!DOCTYPE html> +<html> +<head> +<title>Referrers with CSS module requests</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<script type="module"> + // "name" parameter is necessary for bypassing the module map. + import referrerSame from "./resources/referrer-checker.py?name=sameNoReferrerPolicy" assert { type: "css"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/referrer-checker.py?name=remoteNoReferrerPolicy" assert { type: "css"}; + + const origin = (new URL(location.href)).origin + "/"; + const originUrl = location.href; + + test(t => { + assert_equals( + referrerSame.rules[0].style.content, '"' + originUrl + '"', + "Referrer URL should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the default referrer policy."); + + test(t => { + assert_equals( + referrerRemote.rules[0].style.content, '"' + origin + '"', + "Referrer origin should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the default referrer policy."); +</script> +<script type="module" referrerpolicy="origin"> + import referrerSame from "./resources/referrer-checker.py?name=sameReferrerPolicyOrigin" assert { type: "css"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/referrer-checker.py?name=remoteReferrerPolicyOrigin" assert { type: "css"}; + + const origin = (new URL(location.href)).origin + "/"; + + test(t => { + assert_equals( + referrerSame.rules[0].style.content, '"' + origin + '"', + "Referrer origin should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the origin policy."); + + test(t => { + assert_equals( + referrerRemote.rules[0].style.content, '"' + origin + '"', + "Referrer origin should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the origin policy."); + +</script> +<script type="module" referrerpolicy="no-referrer"> + import referrerSame from "./resources/referrer-checker.py?name=sameReferrerPolicyNoReferrer" assert { type: "css"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/referrer-checker.py?name=remoteReferrerPolicyNoReferrer" assert { type: "css"}; + + test(t => { + assert_equals( + referrerSame.rules[0].style.content, '""', + "No referrer should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the no-referrer policy."); + + test(t => { + assert_equals( + referrerRemote.rules[0].style.content, '""', + "No referrer should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the no-referrer policy."); + +</script> +<script type="module" referrerpolicy="unsafe-url"> + import referrerSame from "./resources/referrer-checker.py?name=sameNoReferrerPolicyUnsafeUrl" assert { type: "css"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/referrer-checker.py?name=remoteNoReferrerPolicyUnsafeUrl" assert { type: "css"}; + + const originUrl = location.href; + + test(t => { + assert_equals( + referrerSame.rules[0].style.content, '"' + originUrl + '"', + "Referrer URL should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the unsafe-url referrer policy."); + + test(t => { + assert_equals( + referrerRemote.rules[0].style.content, '"' + originUrl + '"', + "Referrer URL should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the unsafe-url referrer policy."); +</script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/relative-urls.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/relative-urls.html new file mode 100644 index 00000000000..e8476716964 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/relative-urls.html @@ -0,0 +1,18 @@ +<!doctype html> +<head> + <title>Test resolution of relative URL in CSS module</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <div id="target"></div> + <script type="module"> + import styleSheet from "./resources/load-relative-url.css" assert { type: "css"}; + test(() => { + const target = document.querySelector("#target"); + document.adoptedStyleSheets = [ styleSheet ]; + let backgroundStyle = window.getComputedStyle(target).background; + assert_not_equals(backgroundStyle.indexOf("css-module/resources/image.png"), -1); + }, "A relative URL in a CSS module should be resolved relative to the CSS file's URL, not the importing document's URL"); + </script> +</body> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/atImported.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/atImported.css new file mode 100644 index 00000000000..8629a846d14 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/atImported.css @@ -0,0 +1,3 @@ +#test3b { + background-color: #FF0000; +}
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bad-import.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bad-import.css index 796446b525c..a6e1a0f395d 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bad-import.css +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bad-import.css @@ -1 +1,4 @@ -@import "basic.css"
\ No newline at end of file +@import "atImported.css"; +#test3 { + background-color:#00FF00; +}
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic-large.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic-large.css index f5b0db5d6ed..555ab70d2ed 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic-large.css +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic-large.css @@ -1,4 +1,4 @@ -#test { +#test2 { background-color:red; } diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic.css index 3ea2ef45339..e034ed9ac7c 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic.css +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/basic.css @@ -1,3 +1,3 @@ #test { - background-color:red; + background-color: #FF0000; }
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-16be.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-16be.css Binary files differnew file mode 100644 index 00000000000..9e17902a1d3 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-16be.css diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-16le.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-16le.css Binary files differnew file mode 100644 index 00000000000..ef90843d8ed --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-16le.css diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-8.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-8.css new file mode 100644 index 00000000000..5cf81232b7a --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/bom-utf-8.css @@ -0,0 +1 @@ +div { background-color: blue; }
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/credentials-iframe.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/credentials-iframe.sub.html new file mode 100644 index 00000000000..38868dc95d0 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/credentials-iframe.sub.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<meta charset="utf-8"> + +<script type="module"> + import styleSheet from "./cross-origin.py?id=sameOriginNoneDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "css" }; + window.sameOriginNoneDescendant = (styleSheet.cssRules[0].cssText.indexOf(".requestHadCookies") !== -1); +</script> +<script type="module" crossOrigin="anonymous"> + import styleSheet from "./cross-origin.py?id=sameOriginAnonymousDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "css" }; + window.sameOriginAnonymousDescendant = (styleSheet.cssRules[0].cssText.indexOf(".requestHadCookies") !== -1); +</script> +<script type="module" crossOrigin="use-credentials"> + import styleSheet from "./cross-origin.py?id=sameOriginUseCredentialsDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "css" }; + window.sameOriginUseCredentialsDescendant = (styleSheet.cssRules[0].cssText.indexOf(".requestHadCookies") !== -1); +</script> +<script type="module"> + import styleSheet from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/cross-origin.py?id=crossOriginNoneDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "css" }; + window.crossOriginNoneDescendant = (styleSheet.cssRules[0].cssText.indexOf(".requestHadCookies") !== -1); +</script> +<script type="module" crossOrigin="anonymous"> + import styleSheet from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/cross-origin.py?id=crossOriginAnonymousDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "css" }; + window.crossOriginAnonymousDescendant = (styleSheet.cssRules[0].cssText.indexOf(".requestHadCookies") !== -1); +</script> +<script type="module" crossOrigin="use-credentials"> + import styleSheet from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/cross-origin.py?id=crossOriginUseCredentialsDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "css" }; + window.crossOriginUseCredentialsDescendant = (styleSheet.cssRules[0].cssText.indexOf(".requestHadCookies") !== -1); +</script> + +<script type="text/javascript"> +window.addEventListener('load', event => { + window.parent.postMessage({}, '*'); +}); +</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/cross-origin.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/cross-origin.py new file mode 100644 index 00000000000..d744fc9514d --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/cross-origin.py @@ -0,0 +1,17 @@ +def main(request, response): + + headers = [ + (b"Content-Type", b"text/css"), + (b"Access-Control-Allow-Origin", request.GET.first(b"origin")), + (b"Access-Control-Allow-Credentials", b"true") + ] + + milk = request.cookies.first(b"milk", None) + + # Send back + if milk is None: + return headers, u'.requestDidNotHaveCookies { }' + elif milk.value == b"1": + return headers, u'.requestHadCookies { }' + + return headers, u'.requestDidNotHaveCookies { }' diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-parse-error-with-cors.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-parse-error-with-cors.sub.html new file mode 100644 index 00000000000..1774ef36756 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-parse-error-with-cors.sub.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> +<head> + <title>css-module-import-cross-domain-parse-error-WithCORS</title> + <script src="../../module/crossorigin-common.js"></script> +</head> +<body> + <h1>css-module-import-cross-domain-parse-error-WithCORS</h1> + <script type="module" crossorigin> + import styleSheet from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/parse-error.css?pipe=header(Access-Control-Allow-Origin,*)" assert { type: "css" }; + // Push an event to the log indicating that the script was executed. + document._log.push(`imported CSS rules count: ${styleSheet.rules.length}`); + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-with-cors.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-with-cors.sub.html new file mode 100644 index 00000000000..f02a51d5569 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-with-cors.sub.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> +<head> + <title>css-module-import-cross-domain-WithCORS</title> + <script src="../../module/crossorigin-common.js"></script> +</head> +<body> + <h1>css-module-import-cross-domain-WithCORS</h1> + <script type="module" crossorigin> + import styleSheet from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/basic.css?pipe=header(Access-Control-Allow-Origin,*)" assert { type: "css" }; + // Push an event to the log indicating that the script was executed. + document._log.push(`imported CSS: ${styleSheet.rules[0].cssText}`); + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-without-cors.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-without-cors.sub.html new file mode 100644 index 00000000000..6236f79bc8f --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/crossorigin-import-without-cors.sub.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> +<head> + <title>css-module-import-cross-domain-NoCORS</title> + <script src="../../module/crossorigin-common.js"></script> +</head> +<body> + <h1>css-module-import-cross-domain-NoCORS</h1> + <script type="module" onerror="document._log.push('error');"> + import styleSheet from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/css-module/resources/basic.css" assert { type: "css" }; + // Push an event to the log indicating that the script was executed. + document._log.push(`imported CSS: ${styleSheet.rules[0].cssText}`); + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-at-import-iframe.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-at-import-iframe.html deleted file mode 100644 index cce9e2163d7..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-at-import-iframe.html +++ /dev/null @@ -1,18 +0,0 @@ -<!DOCTYPE html> -<body> - <script> - window.onerror = function (errorMsg, url, lineNumber, column, errorObj) - { - document.load_error = errorObj.name; - return true; - }; - </script> - <script type="module"> - import v from "./bad-import.css" assert { type: "css" }; - document.adoptedStyleSheets = [v]; - </script> - - <div id="test"> - I am a test div. - </div> -</body>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-basic-iframe.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-basic-iframe.html deleted file mode 100644 index e093d39898f..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-basic-iframe.html +++ /dev/null @@ -1,18 +0,0 @@ -<!DOCTYPE html> -<body> - <script> - window.onerror = function (errorMsg, url, lineNumber, column, errorObj) - { - document.load_error = errorObj.name; - return true; - }; - </script> - <script type="module"> - import v from "./basic.css" assert { type: "css" }; - document.adoptedStyleSheets = [v]; - </script> - - <div id="test"> - I am a test div. - </div> -</body>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-basic-large-iframe.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-basic-large-iframe.html deleted file mode 100644 index 0cf11e9139f..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/css-module-basic-large-iframe.html +++ /dev/null @@ -1,18 +0,0 @@ -<!DOCTYPE html> -<body> - <script> - window.onerror = function (errorMsg, url, lineNumber, column, errorObj) - { - document.load_error = errorObj.name; - return true; - }; - </script> - <script type="module"> - import v from "./basic-large.css" assert { type: "css" }; - document.adoptedStyleSheets = [v]; - </script> - - <div id="test"> - I am a test div. - </div> -</body> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/integrity-matches.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/integrity-matches.js new file mode 100644 index 00000000000..95be445311b --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/integrity-matches.js @@ -0,0 +1,2 @@ +import styleSheet from "./basic.css" assert { type: "css" }; +window.matchesLog.push(`integrity-matches,css:${styleSheet.cssRules[0].cssText}`); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/integrity-mismatches.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/integrity-mismatches.js new file mode 100644 index 00000000000..af6fc24de49 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/integrity-mismatches.js @@ -0,0 +1,2 @@ +import styleSheet from "./basic.css" assert { type: "css" }; +window.matchesLog.push(`integrity-mismatches,css:${styleSheet.cssRules[0].cssText}`); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/load-error-events.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/load-error-events.py new file mode 100644 index 00000000000..b61b1ca834e --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/load-error-events.py @@ -0,0 +1,14 @@ +import re + +def main(request, response): + headers = [(b"Content-Type", b"text/javascript")] + test = request.GET.first(b'test') + assert(re.match(b'^[a-zA-Z0-9_]+$', test)) + + status = 200 + if test.find(b'_load') >= 0: + content = b'import "./basic.css" assert { type: "css"}; %s.executed = true;' % test + else: + content = b'import "./not_found.css" assert { type: "css"}; %s.test.step(function() { assert_unreached("404 script should not be executed"); });' % test + + return status, headers, content diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/load-relative-url.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/load-relative-url.css new file mode 100644 index 00000000000..27f29876104 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/load-relative-url.css @@ -0,0 +1,5 @@ + +#target { + /* image.png doesn't exist, but that's irrelevant to the test. */ + background: url('./image.png'); +} diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/malformed-iframe.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/malformed-iframe.html deleted file mode 100644 index f5c64f6b59e..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/malformed-iframe.html +++ /dev/null @@ -1,11 +0,0 @@ -<!DOCTYPE html> -<body> - <script type="module"> - import v from "./malformed.css" assert { type: "css" }; - document.adoptedStyleSheets = [v]; - </script> - - <div id="test"> - I am a test div. - </div> -</body>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/malformed.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/malformed.css index fb20336584e..28819bfdf55 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/malformed.css +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/malformed.css @@ -1,3 +1,7 @@ -#test {{ - background-color:red; -}
\ No newline at end of file +#test4 } { + background-color: #FF0000; +} + +#test4b { + background-color: #00FF00; +} diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/parse-error.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/parse-error.css new file mode 100644 index 00000000000..2bee3ff9966 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/parse-error.css @@ -0,0 +1,2 @@ +div /* Opening bracket skipped intentionally. */ } + diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/referrer-checker.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/referrer-checker.py new file mode 100644 index 00000000000..c1eaed8e468 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/referrer-checker.py @@ -0,0 +1,7 @@ +def main(request, response): + referrer = request.headers.get(b"referer", b"") + response_headers = [(b"Content-Type", b"text/css"), + (b"Access-Control-Allow-Origin", b"*")] + # Put the referrer in a CSS rule that can be read by the importer through CSSOM + return (200, response_headers, + b'.referrer { content: "' + referrer + b'" }') diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/utf-8.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/utf-8.css new file mode 100644 index 00000000000..0a8b46656f1 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/utf-8.css @@ -0,0 +1,3 @@ +#test { + content: "śćążź"; +}
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/utf8.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/utf8.css deleted file mode 100644 index 35d16cd1c5b..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/utf8.css +++ /dev/null @@ -1,3 +0,0 @@ -#test { - content: "…"; -}
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/windows-1250.css b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/windows-1250.css new file mode 100644 index 00000000000..9beac4d6180 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/windows-1250.css @@ -0,0 +1,3 @@ +#test { + content: "�湿�"; +} diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/script-element-css-src.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/script-element-css-src.html new file mode 100644 index 00000000000..231d02db477 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/script-element-css-src.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<title><script> with CSS src</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + window.log = []; + + const test_load = async_test( + "Test that <script> doesn't load when the src is CSS."); + window.addEventListener("load", test_load.step_func_done(ev => { + assert_array_equals(log, ["error"]); + })); +</script> +<script type="module" src="./resources/basic.css" onload="t.unreached_func('CSS src should fail to load')" onerror="log.push('error')"></script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/utf8.tentative.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/utf8.tentative.html deleted file mode 100644 index 6adcd716328..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/utf8.tentative.html +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE html> -<meta charset="utf-8"> -<title>CSS modules: UTF-8 decoding</title> -<script src="/resources/testharness.js"></script> -<script src="/resources/testharnessreport.js"></script> -<script> -function check(t, v) { - t.step(() => { - assert_equals(typeof v, "object"); - assert_equals(v.rules[0].style.content, "\"…\""); - t.done(); - }); -} -const t1 = async_test("utf-8"); -const t2 = async_test("shift-jis"); -const t3 = async_test("windows-1252"); -const t4 = async_test("utf-7"); -</script> -<script type="module" onerror="t1.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=css-module/resources/utf8.css&ct=text/css%3Bcharset=utf-8" assert { type: "css" }; -check(t1, v); -</script> -<script type="module" onerror="t2.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=css-module/resources/utf8.css&ct=text/css%3Bcharset=shift-jis" assert { type: "css" }; -check(t2, v); -</script> -<script type="module" onerror="t3.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=css-module/resources/utf8.css&ct=text/css%3Bcharset=windows-1252" assert { type: "css" }; -check(t3, v); -</script> -<script type="module" onerror="t4.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=css-module/resources/utf8.css&ct=text/css%3Bcharset=utf-7" assert { type: "css" }; -check(t4, v); -</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/050.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/050.html index 143fc917e09..a400749f18e 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/050.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/050.html @@ -21,8 +21,28 @@ var t = async_test() function test() { - assert_array_equals(eventOrder, ['inline script #1', 'end script #1', 'include-5 before removing scripts', 'include-5 after removing scripts', 'external script #1', 'external script #2']), - t.done(); + // Per-spec, non-blocking/async scripts can execute at any time. + // Therefore, there are two possibilities for the script order here. + // 1. inline script first, followed by include-5 (async), then + // external script #1 (slow async) and finally external #2 + // (inline). + // 2. inline script, external '2, 'include 5', then include-1. + assert_array_equals(eventOrder.slice(0, 2), [ + 'inline script #1', 'end script #1' + ]); + if (eventOrder[2] == 'include-5 before removing scripts') { + assert_array_equals(eventOrder.slice(3), [ + 'include-5 after removing scripts', 'external script #1', + 'external script #2' + ]); + } else { + assert_array_equals(eventOrder.slice(2), ['external script #2', + 'include-5 before removing scripts', + 'include-5 after removing scripts', + 'external script #1' + ]); + } + t.done(); } onload = t.step_func(test) </script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/146-href.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/146-href.html new file mode 100644 index 00000000000..6c0869db541 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/146-href.html @@ -0,0 +1,22 @@ +<!DOCTYPE html> +<html><head> + <title>scheduler: SVG script adding src attribute </title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="testlib/testlib.js"></script> +</head> +<div id="log"></div> +<script>var t = async_test();</script> +<svg> +<script></script> +</svg> +<script> +t.step(function() { + var s = document.querySelector("svg > script"); + s.setAttribute("href", "scripts/include-1.js"); +}); +onload = t.step_func(function() { + assert_array_equals(eventOrder, ["external script #1"]); + t.done(); +}); +</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/146.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/146.html index 9cf6bb7b7ba..333ac3fa0fd 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/146.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/146.html @@ -16,7 +16,8 @@ t.step(function() { s.src = "scripts/include-1.js"; }); onload = t.step_func(function() { - assert_array_equals(eventOrder, ["external script #1"]); + // SVG <script> element uses href attribute, so src attribute is ignored. + assert_array_equals(eventOrder, []); t.done(); }); </script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/scripts/find-body.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/scripts/find-body.js index 22e1050ffc3..1ce198f13ed 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/scripts/find-body.js +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/scripts/find-body.js @@ -1,2 +1,4 @@ -log('document.body: '+(document.body?'<BODY>':null)); -var findBodyLoaded=true;
\ No newline at end of file +log( + 'document.body: ' + + (document.body ? '<' + document.body.localName.toUpperCase() + '>' : null)); +var findBodyLoaded=true; diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.any.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.any.js new file mode 100644 index 00000000000..ef032d27c57 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.any.js @@ -0,0 +1,17 @@ +// META: global=window,dedicatedworker,sharedworker + +promise_test(async test => { + const result = await import("./export-hello.js", { assert: { } }); + assert_equals(result.default, "hello"); +}, "Dynamic import with an empty assert clause should succeed"); + +promise_test(async test => { + const result = await import("./export-hello.js", { assert: { unsupportedAssertionKey: "unsupportedAssertionValue"} }); + assert_equals(result.default, "hello"); +}, "Dynamic import with an unsupported import assertion should succeed"); + +promise_test(test => { + return promise_rejects_js(test, TypeError, + import("./export-hello.js", { assert: { type: "notARealType"} } ), + "Dynamic import with an unsupported type assertion should fail"); +}, "Dynamic import with an unsupported type assertion should fail"); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.html deleted file mode 100644 index f90724f4f63..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.html +++ /dev/null @@ -1,22 +0,0 @@ -<!doctype html> - -<script src="/resources/testharness.js"></script> -<script src="/resources/testharnessreport.js"></script> - -<script> - promise_test(async test => { - const result = await import("./export-hello.js", { assert: { } }); - assert_equals(result.default, "hello"); - }, "Dynamic import with an empty assert clause should succeed"); - - promise_test(async test => { - const result = await import("./export-hello.js", { assert: { unsupportedAssertionKey: "unsupportedAssertionValue"} }); - assert_equals(result.default, "hello"); - }, "Dynamic import with an unsupported import assertion should succeed"); - - promise_test(test => { - return promise_rejects_js(test, TypeError, - import("./export-hello.js", { assert: { type: "notARealType"} } ), - "Dynamic import with an unsupported type assertion should fail"); - }, "Dynamic import with an unsupported type assertion should fail"); -</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error.html index d3399f085ce..0adcc475693 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error.html @@ -13,12 +13,16 @@ const test_load = async_test( "Test that invalid module type assertion leads to TypeError on window."); window.addEventListener("load", test_load.step_func_done(ev => { - assert_equals(log.length, 2); + assert_equals(log.length, 4); assert_equals(log[0].constructor, TypeError); assert_equals(log[1].constructor, TypeError); + assert_equals(log[2].constructor, TypeError); + assert_equals(log[3].constructor, TypeError); })); function unreachable() { log.push("unexpected"); } </script> <script type="module" src="./invalid-type-assertion.js" onerror="unreachable()"></script> <script type="module" src="./empty-type-assertion.js" onerror="unreachable()"></script> +<script type="module" src="./js-type-assertion.js" onerror="unreachable()"></script> +<script type="module" src="./javascript-type-assertion.js" onerror="unreachable()"></script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/javascript-type-assertion.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/javascript-type-assertion.js new file mode 100644 index 00000000000..cc0f531026e --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/javascript-type-assertion.js @@ -0,0 +1,2 @@ +import "./hello.js#4" assert { type: "javascript" }; +log.push("javascript-type-assertion"); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/js-type-assertion.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/js-type-assertion.js new file mode 100644 index 00000000000..c649c95ffea --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/js-type-assertion.js @@ -0,0 +1,2 @@ +import "./hello.js#3" assert { type: "js" }; +log.push("js-type-assertion"); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/README.md b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/README.md deleted file mode 100644 index 204fd59dcb1..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This directory contains an experimental feature that is not currently standardized due to a security -issue. Support was removed in https://github.com/whatwg/html/pull/4943. diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-16be.json b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-16be.json Binary files differnew file mode 100644 index 00000000000..d22a45a5910 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-16be.json diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-16le.json b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-16le.json Binary files differnew file mode 100644 index 00000000000..4d1aa264a69 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-16le.json diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-8.json b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-8.json new file mode 100644 index 00000000000..07ba933e860 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/bom-utf-8.json @@ -0,0 +1 @@ +{ "data": "hello" }
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-2.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-2.html new file mode 100644 index 00000000000..1bfd3fc00ae --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-2.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<meta charset="windows-1250"> +<title>JSON modules: UTF-8 decoding</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script type="module"> + import json from "../serve-with-content-type.py?fn=json-module/utf-8.json" assert { type: "json"}; + test(() => { + assert_equals(json.data, "śćążź"); + }, "JSON module should be loaded as utf-8 even though document's encoding is windows-1250"); +</script> +<script type="module"> + import json from "../serve-with-content-type.py?fn=json-module/windows-1250.json&ct=text/json%3Bcharset=windows-1250" assert { type: "json"}; + test(() => { + assert_not_equals(json.data, "śćążź", + 'Should be decoded as UTF-8'); + }, "JSON module should be loaded as utf-8 even if it is encoded in windows-1250 and served with a windows-1250 charset response header, and this document's encoding is windows-1250"); +</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-bom.any.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-bom.any.js new file mode 100644 index 00000000000..d2dbe3e468f --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-bom.any.js @@ -0,0 +1,17 @@ +// META: global=window,dedicatedworker,sharedworker +// META: script=/common/utils.js + +promise_test(async () => { + const jsonModule = await import('./bom-utf-8.json', { assert: { type: 'json' } }); + assert_equals(jsonModule.default.data, 'hello'); +}, 'UTF-8 BOM should be stripped when decoding JSON module script'); + +promise_test(async test => { + await promise_rejects_js(test, SyntaxError, + import('./bom-utf-16be.json', { assert: { type: 'json' } }), 'Expected parse error from UTF-16BE BOM'); +}, 'UTF-16BE BOM should result in parse error in JSON module script'); + +promise_test(async test => { + await promise_rejects_js(test, SyntaxError, + import('./bom-utf-16le.json', { assert: { type: 'json' } }), 'Expected parse error from UTF-16LE BOM'); +}, 'UTF-16LE BOM should result in parse error in JSON module script'); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset.html new file mode 100644 index 00000000000..de30de8c2e5 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>JSON modules: UTF-8 decoding</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script type="module" onerror="unreachable()"> + import json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=utf-8" assert { type: "json"}; + test(() => { + assert_equals(json.data, "śćążź"); + }, "JSON module should be loaded as utf-8 when charset=utf8 is specified"); +</script> +<script type="module" onerror="unreachable()"> + import json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=shift-jis" assert { type: "json"}; + test(() => { + assert_equals(json.data, "śćążź"); + }, "JSON module should be loaded as utf-8 when charset=shift-jis is specified"); +</script> +<script type="module" onerror="unreachable()"> + import json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=windows-1252" assert { type: "json"}; + test(() => { + assert_equals(json.data, "śćążź"); + }, "JSON module should be loaded as utf-8 when charset=windows-1252 is specified"); +</script> +<script type="module" onerror="unreachable()"> + import json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=utf-7" assert { type: "json"};; + test(() => { + assert_equals(json.data, "śćążź"); + }, "JSON module should be loaded as utf-8 when charset=utf-7 is specified"); +</script> +<script type="module" onerror="unreachable()"> + import json from "../serve-with-content-type.py?fn=json-module/windows-1250.json&ct=text/json%3Bcharset=windows-1250" assert { type: "json"}; + test(() => { + assert_not_equals(json.data, "śćążź", + 'Should be decoded as UTF-8'); + }, "JSON module should be loaded as utf-8 even if it is encoded in windows-1250 and served with a windows-1250 charset response header"); +</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests.html new file mode 100644 index 00000000000..99ff2f67e80 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests.html @@ -0,0 +1,33 @@ +<!doctype html> +<html> +<head> + <title>json-module-crossorigin</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <h1>json-module-crossorigin</h1> + <iframe id="import-WithCORS" src="crossorigin-import-with-cors.sub.html"></iframe> + <iframe id="import-NoCORS" src="crossorigin-import-without-cors.sub.html"></iframe> + <iframe id="import-parseerror-WithCors" src="crossorigin-import-parse-error-with-cors.sub.html"></iframe> + <script> + + var tests = [ + { "obj": async_test("Imported JSON module, cross-origin with CORS"), "id": "import-WithCORS", "expected": "imported JSON: 42" }, + { "obj": async_test("Imported JSON module, cross-origin, missing CORS ACAO header"), "id": "import-NoCORS", "expected": "error" }, + { "obj": async_test("Imported JSON module with parse error, cross-origin, with CORS"), "id": "import-parseerror-WithCors", "expected": "0-0" }, + ]; + + window.addEventListener("load", function () { + tests.forEach(function (test) { + var target = document.getElementById(test.id); + test.obj.step(function () { + assert_equals(target.contentDocument._log, test.expected, "Unexpected _log value"); + }); + test.obj.done(); + }); + }); + + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/credentials-iframe.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/credentials-iframe.sub.html new file mode 100644 index 00000000000..dbb9fe6d1a2 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/credentials-iframe.sub.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<meta charset="utf-8"> + +<script type="module"> + import json from "./cross-origin.py?id=sameOriginNoneDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "json" }; + window.sameOriginNoneDescendant = json.requestHadCookies; +</script> +<script type="module" crossOrigin="anonymous"> + import json from "./cross-origin.py?id=sameOriginAnonymousDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "json" }; + window.sameOriginAnonymousDescendant = json.requestHadCookies; +</script> +<script type="module" crossOrigin="use-credentials"> + import json from "./cross-origin.py?id=sameOriginUseCredentialsDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "json" }; + window.sameOriginUseCredentialsDescendant = json.requestHadCookies; +</script> +<script type="module"> + import json from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/cross-origin.py?id=crossOriginNoneDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "json" }; + window.crossOriginNoneDescendant = json.requestHadCookies; +</script> +<script type="module" crossOrigin="anonymous"> + import json from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/cross-origin.py?id=crossOriginAnonymousDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "json" }; + window.crossOriginAnonymousDescendant = json.requestHadCookies; +</script> +<script type="module" crossOrigin="use-credentials"> +import json from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/cross-origin.py?id=crossOriginUseCredentialsDescendant&origin=http://{{host}}:{{ports[http][0]}}" assert { type: "json" }; +window.crossOriginUseCredentialsDescendant = json.requestHadCookies; +</script> + +<script type="text/javascript"> +window.addEventListener('load', event => { + window.parent.postMessage({}, '*'); +}); +</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/credentials.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/credentials.sub.html new file mode 100644 index 00000000000..a6df506e214 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/credentials.sub.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> +document.cookie = 'milk=1'; + +const setCookiePromise = fetch( + 'http://{{domains[www2]}}:{{ports[http][0]}}/cookies/resources/set-cookie.py?name=milk&path=/html/semantics/scripting-1/the-script-element/json-module/', + { + mode: 'no-cors', + credentials: 'include', + }); + +const windowLoadPromise = new Promise(resolve => { + window.addEventListener('load', () => { + resolve(); + }); +}); + +promise_test(t => { + const iframe = document.createElement('iframe'); + + return Promise.all([setCookiePromise, windowLoadPromise]).then(() => { + const messagePromise = new Promise(resolve => { + window.addEventListener('message', event => { + resolve(); + }); + }); + + iframe.src = 'credentials-iframe.sub.html'; + document.body.appendChild(iframe); + + return messagePromise; + }).then(() => { + const w = iframe.contentWindow; + + assert_equals(w.sameOriginNoneDescendant, true, + 'Descendant JSON modules should be loaded with the credentials when the crossOrigin attribute is not specified and the target is same-origin'); + assert_equals(w.sameOriginAnonymousDescendant, true, + 'Descendant JSON modules should be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is same-origin'); + assert_equals(w.sameOriginUseCredentialsDescendant, true, + 'Descendant JSON modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is same-origin'); + assert_equals(w.crossOriginNoneDescendant, false, + 'Descendant JSON modules should not be loaded with the credentials when the crossOrigin attribute is not specified and the target is cross-origin'); + assert_equals(w.crossOriginAnonymousDescendant, false, + 'Descendant JSON modules should not be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is cross-origin'); + assert_equals(w.crossOriginUseCredentialsDescendant, true, + 'Descendant JSON modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is cross-origin'); +}); +}, 'JSON Modules should be loaded with or without the credentials based on the same-origin-ness and the crossOrigin attribute'); +</script> +<body> +</body> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cross-origin.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cross-origin.py new file mode 100644 index 00000000000..cd56c3628a0 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cross-origin.py @@ -0,0 +1,16 @@ +def main(request, response): + + headers = [ + (b"Content-Type", b"application/json"), + (b"Access-Control-Allow-Origin", request.GET.first(b"origin")), + (b"Access-Control-Allow-Credentials", b"true") + ] + + milk = request.cookies.first(b"milk", None) + + if milk is None: + return headers, u'{"requestHadCookies": false}' + elif milk.value == b"1": + return headers, u'{"requestHadCookies": true}' + + return headers, u'{"requestHadCookies": false}' diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-parse-error-with-cors.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-parse-error-with-cors.sub.html new file mode 100644 index 00000000000..12c6a608832 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-parse-error-with-cors.sub.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> +<head> + <title>json-module-import-cross-domain-parse-error-WithCORS</title> + <script src="../module/crossorigin-common.js"></script> +</head> +<body> + <h1>json-module-import-cross-domain-parse-error-WithCORS</h1> + <script type="module" crossorigin> + import json from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/parse-error.json?pipe=header(Access-Control-Allow-Origin,*)" assert { type: "json" }; + // Push an event to the log indicating that the script was executed. + document._log.push(`imported JSON: ${json.answer}`); + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-with-cors.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-with-cors.sub.html new file mode 100644 index 00000000000..01663d25169 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-with-cors.sub.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> +<head> + <title>json-module-import-cross-domain-WithCORS</title> + <script src="../module/crossorigin-common.js"></script> +</head> +<body> + <h1>json-module-import-cross-domain-WithCORS</h1> + <script type="module" crossorigin> + import json from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/data.json?pipe=header(Access-Control-Allow-Origin,*)" assert { type: "json" }; + // Push an event to the log indicating that the script was executed. + document._log.push(`imported JSON: ${json.answer}`); + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-without-cors.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-without-cors.sub.html new file mode 100644 index 00000000000..7849c6aeddf --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/crossorigin-import-without-cors.sub.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> +<head> + <title>json-module-import-cross-domain-NoCORS</title> + <script src="../module/crossorigin-common.js"></script> +</head> +<body> + <h1>json-module-import-cross-domain-NoCORS</h1> + <script type="module" onerror="document._log.push('error');"> + import json from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/data.json" assert { type: "json" }; + // Push an event to the log indicating that the script was executed. + document._log.push(`imported JSON: ${json.answer}`); + </script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/data.json b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/data.json new file mode 100644 index 00000000000..14a0526ebb2 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/data.json @@ -0,0 +1,3 @@ +{ + "answer": 42 +}
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-matches.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-matches.js new file mode 100644 index 00000000000..969c90c2907 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-matches.js @@ -0,0 +1,2 @@ +import json from "./data.json" assert { type: "json" }; +window.matchesLog.push(`integrity-matches,json:${json.answer}`); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-mismatches.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-mismatches.js new file mode 100644 index 00000000000..3c88a98dbc5 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-mismatches.js @@ -0,0 +1,2 @@ +import json "./data.json" assert { type: "json" }; +window.mismatchesLog.push(`integrity-mismatches,json:${json.answer}`); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity.html new file mode 100644 index 00000000000..68a794b9733 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title><script> integrity=""</title> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> +window.matchesLog = []; +window.matchesEvents = []; + +window.mismatchesLog = []; +window.mismatchesEvents = []; +</script> +<script type="module" src="integrity-matches.js" integrity="sha384-VmQQfGzBiLKdyzw4FA4kL4ohu4tyujV68ddgW1aN/1v3cBZNNBn2gDFdVQxfL7+a" onload="window.matchesEvents.push('load');" onerror="window.matchesEvents.push('error')"></script> +<script type="module" src="integrity-mismatches.js" integrity="sha384-doesnotmatch" onload="window.mismatchesEvents.push('load');" onerror="window.mismatchesEvents.push('error')"></script> + +<script type="module"> +test(() => { + assert_array_equals(window.matchesLog, ["integrity-matches,json:42"], "The module and its dependency must have executed"); + assert_array_equals(window.matchesEvents, ["load"], "The load event must have fired"); +}, "The integrity attribute must be verified on the top-level of a module loading a JSON module and allow it to execute when it matches"); + +test(() => { + assert_array_equals(window.mismatchesLog, [], "The module and its dependency must not have executed"); + assert_array_equals(window.mismatchesEvents, ["error"], "The error event must have fired"); +}, "The integrity attribute must be verified on the top-level of a module loading a JSON module and not allow it to execute when there's a mismatch"); +</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.any.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.any.js new file mode 100644 index 00000000000..cbccbd48429 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.any.js @@ -0,0 +1,17 @@ +// META: global=window,dedicatedworker,sharedworker + +const content_types = [ + "application/json+protobuf", + "application/json+blah", + "text/x-json", + "text/json+blah", + "application/blahjson", + "image/json", +]; +for (const content_type of content_types) { + promise_test(async test => { + await promise_rejects_js(test, TypeError, + import(`./module.json?pipe=header(Content-Type,${content_type})`, { assert: { type: "json"} }), + `Import of a JSON module with MIME type ${content_type} should fail`); + }, `Try importing JSON module with MIME type ${content_type}`); +} diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.tentative.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.tentative.html deleted file mode 100644 index e6da2db7ebc..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.tentative.html +++ /dev/null @@ -1,26 +0,0 @@ -<!DOCTYPE html> -<meta charset=utf-8> -<title>JSON modules: invalid Content-Type</title> -<script src="/resources/testharness.js"></script> -<script src="/resources/testharnessreport.js"></script> -<div id=log></div> -<script> -const content_types = [ - "application/json+protobuf", - "application/json+blah", - "text/x-json", - "text/json+blah", - "application/blahjson", - "image/json", -]; -for (const content_type of content_types) { - async_test(t => { - const script = document.createElement("script"); - script.onerror = t.step_func_done(); - script.onload = t.unreached_func("Should not load"); - script.type = "module"; - script.src = `module.json?pipe=header(Content-Type,${content_type})`; - document.body.appendChild(script); - }, content_type); -} -</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https.tentative.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https.html index cc47da1499f..cc47da1499f 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https.tentative.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https.html diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events.html new file mode 100644 index 00000000000..a9dfc1e6917 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events.html @@ -0,0 +1,67 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<head> +<title>load/error events for JSON modules</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="../resources/load-error-events-helpers.js"></script> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block"> +</head> +<script> + "use strict"; + + var test1_load = event_test('inline, 200, parser-inserted', false, false); + var test1_error = event_test('inline, 404, parser-inserted', false, true); + + var test2_load = event_test('src, 200, parser-inserted', true, false); + var test2_error = event_test('src, 404, parser-inserted', false, true); + + var test3_dynamic_load = event_test('src, 200, not parser-inserted', true, false); + var test3_dynamic_error = event_test('src, 404, not parser-inserted', false, true); + + var test4_dynamic_load = event_test('inline, 200, not parser-inserted', false, false); + var test4_dynamic_error = event_test('inline, 404, not parser-inserted', false, true); + + var script3_dynamic_load = document.createElement('script'); + script3_dynamic_load.setAttribute('type', 'module'); + script3_dynamic_load.onload = () => onLoad(test3_dynamic_load); + script3_dynamic_load.onerror = () => onError(test3_dynamic_load); + script3_dynamic_load.src = "./load-error-events.py?test=test3_dynamic_load"; + document.head.appendChild(script3_dynamic_load); + + var script3_dynamic_error = document.createElement('script'); + script3_dynamic_error.setAttribute('type', 'module'); + script3_dynamic_error.onload = () => onLoad(test3_dynamic_error); + script3_dynamic_error.onerror = () => onError(test3_dynamic_error); + script3_dynamic_error.src = "./load-error-events.py?test=test3_dynamic_error"; + document.head.appendChild(script3_dynamic_error); + + var script4_dynamic_load = document.createElement('script'); + script4_dynamic_load.setAttribute('type', 'module'); + script4_dynamic_load.onload = () => onLoad(test4_dynamic_load); + script4_dynamic_load.onerror = () => onError(test4_dynamic_load); + script4_dynamic_load.async = true; + script4_dynamic_load.appendChild(document.createTextNode(` + import "./module.json" assert { type: "json" }; + onExecute(test4_dynamic_load);` + )); + document.head.appendChild(script4_dynamic_load); + + var script4_dynamic_error = document.createElement('script'); + script4_dynamic_error.setAttribute('type', 'module'); + script4_dynamic_error.onload = () => onLoad(test4_dynamic_error); + script4_dynamic_error.onerror = () => onError(test4_dynamic_error); + script4_dynamic_error.async = true; + script4_dynamic_error.appendChild(document.createTextNode(`import "./not_found.json" assert { type: "json" };`)); + document.head.appendChild(script4_dynamic_error); +</script> +<script onload="onLoad(test1_load);" onerror="onError(test1_load);" type="module"> + import "./module.json" assert { type: "json"}; + onExecute(test1_load); +</script> +<script onload="onLoad(test1_error);" onerror="onError(test1_error);" type="module"> + import "./not_found.json" assert { type: "json"}; + onExecute(test1_error); +</script> +<script src="./load-error-events.py?test=test2_load" onload="onLoad(test2_load);" onerror="onError(test2_load);" type="module"></script> +<script src="./load-error-events.py?test=test2_error" onload="onLoad(test2_error);" onerror="onError(test2_error);" type="module"></script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events.py new file mode 100644 index 00000000000..4018adcdf7c --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events.py @@ -0,0 +1,14 @@ +import re + +def main(request, response): + headers = [(b"Content-Type", b"text/javascript")] + test = request.GET.first(b'test') + assert(re.match(b'^[a-zA-Z0-9_]+$', test)) + + status = 200 + if test.find(b'_load') >= 0: + content = b'import "./module.json" assert { type: "json"}; %s.executed = true;' % test + else: + content = b'import "./not_found.json" assert { type: "json"}; %s.test.step(function() { assert_unreached("404 script should not be executed"); });' % test + + return status, headers, content diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module.tentative.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module.html index a495d4ac186..a495d4ac186 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module.tentative.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module.html diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.tentative.any.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.js index 6d507177e1e..37fbcae9fab 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.tentative.any.js +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.js @@ -1,4 +1,4 @@ -// META: global=window,worker +// META: global=window,dedicatedworker,sharedworker for (const value of [null, true, false, "string"]) { promise_test(async t => { diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.tentative.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.html index 68d3ef0a9ad..68d3ef0a9ad 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.tentative.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.html diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py new file mode 100644 index 00000000000..e9f0f1789ba --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py @@ -0,0 +1,6 @@ +def main(request, response): + referrer = request.headers.get(b"referer", b"") + response_headers = [(b"Content-Type", b"application/json"), + (b"Access-Control-Allow-Origin", b"*")] + return (200, response_headers, + b'{"referrer": "' + referrer + b'"}') diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/referrer-policies.sub.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/referrer-policies.sub.html new file mode 100644 index 00000000000..83e103529dc --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/referrer-policies.sub.html @@ -0,0 +1,84 @@ +<!DOCTYPE html> +<html> +<head> +<title>Referrers with JSON module requests</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<script type="module"> + // "name" parameter is necessary for bypassing the module map. + import referrerSame from "./referrer-checker.py?name=sameNoReferrerPolicy" assert { type: "json"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteNoReferrerPolicy" assert { type: "json"}; + + const origin = (new URL(location.href)).origin + "/"; + const originUrl = location.href; + + test(t => { + assert_equals( + referrerSame.referrer, originUrl, + "Referrer URL should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the default referrer policy."); + + test(t => { + assert_equals( + referrerRemote.referrer, origin, + "Referrer origin should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the default referrer policy."); +</script> +<script type="module" referrerpolicy="origin"> + import referrerSame from "./referrer-checker.py?name=sameReferrerPolicyOrigin" assert { type: "json"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteReferrerPolicyOrigin" assert { type: "json"}; + + const origin = (new URL(location.href)).origin + "/"; + + test(t => { + assert_equals( + referrerSame.referrer, origin, + "Referrer origin should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the origin policy."); + + test(t => { + assert_equals( + referrerRemote.referrer, origin, + "Referrer origin should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the origin policy."); + +</script> +<script type="module" referrerpolicy="no-referrer"> + import referrerSame from "./referrer-checker.py?name=sameReferrerPolicyNoReferrer" assert { type: "json"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteReferrerPolicyNoReferrer" assert { type: "json"}; + + test(t => { + assert_equals( + referrerSame.referrer, "", + "No referrer should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the no-referrer policy."); + + test(t => { + assert_equals( + referrerRemote.referrer, "", + "No referrer should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the no-referrer policy."); + +</script> +<script type="module" referrerpolicy="unsafe-url"> + import referrerSame from "./referrer-checker.py?name=sameNoReferrerPolicyUnsafeUrl" assert { type: "json"}; + import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteNoReferrerPolicyUnsafeUrl" assert { type: "json"}; + + const originUrl = location.href; + + test(t => { + assert_equals( + referrerSame.referrer, originUrl, + "Referrer URL should be sent for the same-origin top-level script."); + }, "Importing a same-origin top-level script with the unsafe-url referrer policy."); + + test(t => { + assert_equals( + referrerRemote.referrer, originUrl, + "Referrer URL should be sent for the remote-origin top-level script."); + }, "Importing a remote-origin top-level script with the unsafe-url referrer policy."); +</script> +</body> +</html> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js new file mode 100644 index 00000000000..5cc3ee5b7c4 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js @@ -0,0 +1,65 @@ +// META: global=window,dedicatedworker,sharedworker +// META: script=/common/utils.js + +promise_test(async test => { + await promise_rejects_js(test, TypeError, + import("./module.json"), + "Dynamic import of a JSON module without a type assertion should fail"); + + // This time the import should succeed because we're using the correct + // import even though the previous attempt with the same specifier failed. + const result = await import("./module.json", { assert: { type: "json" } }); + assert_true(result.default.test); +}, "Importing a specifier that previously failed due to an incorrect type assertion can succeed if the correct assertion is later given"); + +promise_test(async test => { + // Append a URL fragment to the specifier so that this is independent + // from the previous test. + const result = await import("./module.json#2", { assert: { type: "json" } }); + assert_true(result.default.test); + + await promise_rejects_js(test, TypeError, + import("./module.json#2"), + "Dynamic import should fail with the type assertion missing even if the same specifier previously succeeded"); +}, "Importing a specifier that previously succeeded with the correct type assertion should fail if the incorrect assertion is later given"); + +promise_test(async test => { + const uuid_token = token(); + // serve-json-then-js.py gives us JSON the first time + const result_json = await import(`../serve-json-then-js.py?key=${uuid_token}`, { assert: { type: "json" } }); + assert_equals(result_json.default.hello, "world"); + + // Import using the same specifier again; this time we get JS, which + // should succeed since we're not asserting a non-JS type this time. + const result_js = await import(`../serve-json-then-js.py?key=${uuid_token}`); + assert_equals(result_js.default, "hello"); +}, "Two modules of different type with the same specifier can load if the server changes its responses"); + +promise_test(async test => { + const uuid_token = token(); + // serve-json-then-js.py gives us JSON the first time + await promise_rejects_js(test, TypeError, + import(`../serve-json-then-js.py?key=${uuid_token}`), + "Dynamic import of JS with a JSON type assertion should fail"); + + // Import using the same specifier/module type pair again; this time we get JS, + // but the import should still fail because the module map entry for this + // specifier/module type pair already contains a failure. + await promise_rejects_js(test, TypeError, + import(`../serve-json-then-js.py?key=${uuid_token}`), + "import should always fail if the same specifier/type assertion pair failed previously"); +}, "An import should always fail if the same specifier/type assertion pair failed previously"); + +promise_test(async test => { + const uuid_token = token(); + // serve-json-then-js.py gives us JSON the first time + const result_json = await import(`../serve-json-then-js.py?key=${uuid_token}`, { assert: { type: "json" } }); + assert_equals(result_json.default.hello, "world"); + + // If this were to do another fetch, the import would fail because + // serve-json-then-js.py would give us JS this time. But, the module map + // entry for this specifier/module type pair already exists, so we + // successfully reuse the entry instead of fetching again. + const result_json_2 = await import(`../serve-json-then-js.py?key=${uuid_token}`, { assert: { type: "json" } }); + assert_equals(result_json_2.default.hello, "world"); +}, "If an import previously succeeded for a given specifier/type assertion pair, future uses of that pair should yield the same result"); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.html deleted file mode 100644 index d1c2182102c..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.html +++ /dev/null @@ -1,68 +0,0 @@ -<!doctype html> -<script src="/resources/testharness.js"></script> -<script src="/resources/testharnessreport.js"></script> -<script src="/common/utils.js"></script> -<script> - promise_test(async test => { - await promise_rejects_js(test, TypeError, - import("./module.json"), - "Dynamic import of a JSON module without a type assertion should fail"); - - // This time the import should succeed because we're using the correct - // import even though the previous attempt with the same specifier failed. - const result = await import("./module.json", { assert: { type: "json" } }); - assert_true(result.default.test); - }, "Importing a specifier that previously failed due to an incorrect type assertion can succeed if the correct assertion is later given"); - - promise_test(async test => { - // Append a URL fragment to the specifier so that this is independent - // from the previous test. - const result = await import("./module.json#2", { assert: { type: "json" } }); - assert_true(result.default.test); - - await promise_rejects_js(test, TypeError, - import("./module.json#2"), - "Dynamic import should fail with the type assertion missing even if the same specifier previously succeeded"); - }, "Importing a specifier that previously succeeded with the correct type assertion should fail if the incorrect assertion is later given"); - - promise_test(async test => { - const uuid_token = token(); - // serve-json-then-js.py gives us JSON the first time - const result_json = await import(`../serve-json-then-js.py?key=${uuid_token}`, { assert: { type: "json" } }); - assert_equals(result_json.default.hello, "world"); - - // Import using the same specifier again; this time we get JS, which - // should succeed since we're not asserting a non-JS type this time. - const result_js = await import(`../serve-json-then-js.py?key=${uuid_token}`); - assert_equals(result_js.default, "hello"); - }, "Two modules of different type with the same specifier can load if the server changes its responses"); - - promise_test(async test => { - const uuid_token = token(); - // serve-json-then-js.py gives us JSON the first time - await promise_rejects_js(test, TypeError, - import(`../serve-json-then-js.py?key=${uuid_token}`), - "Dynamic import of JS with a JSON type assertion should fail"); - - // Import using the same specifier/module type pair again; this time we get JS, - // but the import should still fail because the module map entry for this - // specifier/module type pair already contains a failure. - await promise_rejects_js(test, TypeError, - import(`../serve-json-then-js.py?key=${uuid_token}`), - "import should always fail if the same specifier/type assertion pair failed previously"); - }, "An import should always fail if the same specifier/type assertion pair failed previously"); - - promise_test(async test => { - const uuid_token = token(); - // serve-json-then-js.py gives us JSON the first time - const result_json = await import(`../serve-json-then-js.py?key=${uuid_token}`, { assert: { type: "json" } }); - assert_equals(result_json.default.hello, "world"); - - // If this were to do another fetch, the import would fail because - // serve-json-then-js.py would give us JS this time. But, the module map - // entry for this specifier/module type pair already exists, so we - // successfully reuse the entry instead of fetching again. - const result_json_2 = await import(`../serve-json-then-js.py?key=${uuid_token}`, { assert: { type: "json" } }); - assert_equals(result_json_2.default.hello, "world"); - }, "If an import previously succeeded for a given specifier/type assertion pair, future uses of that pair should yield the same result"); -</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/script-element-json-src.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/script-element-json-src.html new file mode 100644 index 00000000000..c6d7c9a76e8 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/script-element-json-src.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<title><script> with JSON src</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + window.log = []; + + const test_load = async_test( + "Test that <script> doesn't load when the src is JSON."); + window.addEventListener("load", test_load.step_func_done(ev => { + assert_array_equals(log, ["error"]); + })); +</script> +<script type="module" src="./module.json" onload="t.unreached_func('JSON src should fail to load')" onerror="log.push('error')"></script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf-8.json b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf-8.json new file mode 100644 index 00000000000..088d9823587 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf-8.json @@ -0,0 +1,4 @@ +{ + "data": "śćążź", + "comment": "The data above are five Polish letters, similar to scazz. It can be read correctly only with utf-8 encoding." +} diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf8.json b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf8.json deleted file mode 100644 index 7bb9edd2f79..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf8.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "test": "…" -} diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf8.tentative.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf8.tentative.html deleted file mode 100644 index 24a6f109e1c..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/utf8.tentative.html +++ /dev/null @@ -1,36 +0,0 @@ -<!DOCTYPE html> -<meta charset=utf-8> -<title>JSON modules: UTF-8 decoding</title> -<script src="/resources/testharness.js"></script> -<script src="/resources/testharnessreport.js"></script> -<div id=log></div> -<script> -function check(t, v) { - t.step(() => { - assert_equals(typeof v, "object"); - assert_array_equals(Object.keys(v), ["test"]); - assert_equals(v.test, "\u2026"); - t.done(); - }); -} -const t1 = async_test("utf-8"); -const t2 = async_test("shift-jis"); -const t3 = async_test("windows-1252"); -const t4 = async_test("utf-7"); -</script> -<script type="module" onerror="t1.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=utf-8" assert { type: "json"}; -check(t1, v); -</script> -<script type="module" onerror="t2.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=shift-jis" assert { type: "json"}; -check(t2, v); -</script> -<script type="module" onerror="t3.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=windows-1252" assert { type: "json"}; -check(t3, v); -</script> -<script type="module" onerror="t4.step(() => assert_unreached(event))"> -import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=utf-7" assert { type: "json"};; -check(t4, v); -</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.tentative.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.html index ff5953cb700..75d6b756a40 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.tentative.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.html @@ -17,6 +17,8 @@ const t1 = async_test("text/json"); const t2 = async_test("application/json"); const t3 = async_test("text/html+json"); const t4 = async_test("image/svg+json"); +const t5 = async_test("text/json;boundary=something"); +const t6 = async_test("text/json;foo=bar"); </script> <script type="module" onerror="t1.step(() => assert_unreached(event))"> import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=text/json" assert { type: "json"}; @@ -34,3 +36,11 @@ check(t3, v); import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=image/svg+json" assert { type: "json"}; check(t4, v); </script> +<script type="module" onerror="t5.step(() => assert_unreached(event))"> +import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=text/json;boundary=something" assert { type: "json"}; +check(t5, v); +</script> +<script type="module" onerror="t6.step(() => assert_unreached(event))"> +import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=text/json;foo=bar" assert { type: "json"}; +check(t6, v); +</script>
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/windows-1250.json b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/windows-1250.json new file mode 100644 index 00000000000..490e752ce93 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/windows-1250.json @@ -0,0 +1,4 @@ +{ + "data": "�湿�", + "comment": "The data above are five Polish letters, similar to scazz. It can be read correctly only with windows1250 encoding." +} diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/inline-event-handlers-UA-code.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/inline-event-handlers-UA-code.js index eaf98f3807f..3202ce47b92 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/inline-event-handlers-UA-code.js +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/inline-event-handlers-UA-code.js @@ -1,3 +1,3 @@ // import()s in an event handler are resolved relative to the document base. -window.dummyDiv.setAttribute("onclick", `import('../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`); +window.dummyDiv.setAttribute("onclick", `import('./imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`); window.dummyDiv.click(); // different from **on**click() diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/reflected-inline-event-handlers.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/reflected-inline-event-handlers.js index 402219d0b4c..923eb7d8b61 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/reflected-inline-event-handlers.js +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/reflected-inline-event-handlers.js @@ -1,3 +1,3 @@ // import()s in an event handler are resolved relative to the document base. -window.dummyDiv.setAttribute("onclick", `import('../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`); +window.dummyDiv.setAttribute("onclick", `import('./imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`); window.dummyDiv.onclick(); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-classic.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-classic.html index 7cf2dac0ac6..855705e5859 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-classic.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-classic.html @@ -8,7 +8,18 @@ <div id="dummy"></div> +<base href="scripts/foo/"> <script> +// Tweak the base URL of the document here to distinguish: +// - document URL +// - document base URL = ../ +// - External scripts' base URL = ./scripts/eval.js etc. +// - This inline script's base URL = ./scripts/foo/ +document.querySelector("base").remove(); +const base = document.createElement("base"); +base.setAttribute("href", "../"); +document.body.appendChild(base); + function load(scriptSrc) { const el = document.createElement("script"); el.src = scriptSrc; @@ -41,7 +52,7 @@ for (const label of evaluators) { const promise = createTestPromise(); window.label = label; - load(`scripts/${label}.js`); + load(`dynamic-import/scripts/${label}.js`); return promise.then(module => { assert_true(window.evaluated_imports_a, "The module must have been evaluated"); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-module.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-module.html index 73986c2c997..d90af9c96ab 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-module.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-module.html @@ -8,7 +8,18 @@ <div id="dummy"></div> +<base href="scripts/foo/"> <script type="module"> +// Tweak the base URL of the document here to distinguish: +// - document URL +// - document base URL = ../ +// - External scripts' base URL = ./scripts/eval.js etc. +// - This inline script's base URL = ./scripts/foo/ +document.querySelector("base").remove(); +const base = document.createElement("base"); +base.setAttribute("href", "../"); +document.body.appendChild(base); + function load(scriptSrc) { const el = document.createElement("script"); el.type = "module"; @@ -42,7 +53,7 @@ for (const label of evaluators) { const promise = createTestPromise(); window.label = label; - load(`scripts/${label}.js`); + load(`dynamic-import/scripts/${label}.js`); return promise.then(module => { assert_true(window.evaluated_imports_a, "The module must have been evaluated"); diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html index 1bd6d7dfd75..2fe1f755358 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html @@ -3,14 +3,23 @@ <title>import() inside compiled strings uses the script base URL (= document base URL) inside an inline classic script</title> <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> -<base href=".."> - <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> +<body> <div id="dummy"></div> +<base href="scripts/foo/"> <script> +// Tweak the base URL of the document here to distinguish: +// - document URL +// - document base URL = ../ +// - This inline script's base URL = ./scripts/foo/ +document.querySelector("base").remove(); +const base = document.createElement("base"); +base.setAttribute("href", "../"); +document.body.appendChild(base); + function createTestPromise() { return new Promise((resolve, reject) => { window.continueTest = resolve; @@ -20,23 +29,7 @@ function createTestPromise() { const dummyDiv = document.querySelector("#dummy"); -const evaluators = { - setTimeout, - eval, - "the Function constructor"(x) { - Function(x)(); - }, - "reflected inline event handlers"(x) { - dummyDiv.setAttribute("onclick", x); - dummyDiv.onclick(); - }, - "inline event handlers triggered via UA code"(x) { - dummyDiv.setAttribute("onclick", x); - dummyDiv.click(); // different from .**on**click() - } -}; - -for (const [label, evaluator] of Object.entries(evaluators)) { +function doTest(label, evaluator, path) { promise_test(t => { t.add_cleanup(() => { dummyDiv.removeAttribute("onclick"); @@ -45,12 +38,36 @@ for (const [label, evaluator] of Object.entries(evaluators)) { const promise = createTestPromise(); - evaluator(`import('./imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); + evaluator(`import('${path}/imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); return promise.then(module => { assert_true(window.evaluated_imports_a, "The module must have been evaluated"); assert_equals(module.A.from, "imports-a.js", "The module namespace object must be correct"); }); }, label + " should successfully import"); -}; +} + +// Inline script's base URL should be used. +doTest("setTimeout", setTimeout, "../../.."); +doTest("eval", eval, "../../.."); +doTest("the Function constructor", + (x) => { + Function(x)(); + }, + "../../.."); + +// Document's base URL should be used, as there are no active scripts. +doTest("reflected inline event handlers", + (x) => { + dummyDiv.setAttribute("onclick", x); + dummyDiv.onclick(); + }, + "."); + +doTest("inline event handlers triggered via UA code", + (x) => { + dummyDiv.setAttribute("onclick", x); + dummyDiv.click(); // different from .**on**click() + }, + "."); </script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-module.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-module.html index f5b85740f55..1691550ecb1 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-module.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-module.html @@ -3,14 +3,23 @@ <title>import() inside compiled strings uses the script base URL (= document base URL) inside an inline module script</title> <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> -<base href=".."> - <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> +<body> <div id="dummy"></div> +<base href="scripts/foo/"> <script type="module"> +// Tweak the base URL of the document here to distinguish: +// - document URL +// - document base URL = ../ +// - This inline script's base URL = ./scripts/foo/ +document.querySelector("base").remove(); +const base = document.createElement("base"); +base.setAttribute("href", "../"); +document.body.appendChild(base); + function createTestPromise() { return new Promise((resolve, reject) => { window.continueTest = resolve; @@ -20,23 +29,7 @@ function createTestPromise() { const dummyDiv = document.querySelector("#dummy"); -const evaluators = { - setTimeout, - eval, - "the Function constructor"(x) { - Function(x)(); - }, - "reflected inline event handlers"(x) { - dummyDiv.setAttribute("onclick", x); - dummyDiv.onclick(); - }, - "inline event handlers triggered via UA code"(x) { - dummyDiv.setAttribute("onclick", x); - dummyDiv.click(); // different from .**on**click() - } -}; - -for (const [label, evaluator] of Object.entries(evaluators)) { +function doTest(label, evaluator, path) { promise_test(t => { t.add_cleanup(() => { dummyDiv.removeAttribute("onclick"); @@ -45,12 +38,36 @@ for (const [label, evaluator] of Object.entries(evaluators)) { const promise = createTestPromise(); - evaluator(`import('./imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); + evaluator(`import('${path}/imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); return promise.then(module => { assert_true(window.evaluated_imports_a, "The module must have been evaluated"); assert_equals(module.A.from, "imports-a.js", "The module namespace object must be correct"); }); }, label + " should successfully import"); -}; +} + +// Inline script's base URL should be used. +doTest("setTimeout", setTimeout, "../../.."); +doTest("eval", eval, "../../.."); +doTest("the Function constructor", + (x) => { + Function(x)(); + }, + "../../.."); + +// Document's base URL should be used, as there are no active scripts. +doTest("reflected inline event handlers", + (x) => { + dummyDiv.setAttribute("onclick", x); + dummyDiv.onclick(); + }, + "."); + +doTest("inline event handlers triggered via UA code", + (x) => { + dummyDiv.setAttribute("onclick", x); + dummyDiv.click(); // different from .**on**click() + }, + "."); </script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-3.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-3.html index 8fa2b8b8d3f..32f0a4a243e 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-3.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-3.html @@ -17,8 +17,14 @@ }); window.addEventListener("load", test_load.step_func_done(ev => { - const msg = log[0]; - assert_array_equals(log, [msg, 1, msg, 2, msg, 3]); + assert_equals(log.length, 6, 'Log length'); + assert_equals(log[1], 1); + assert_equals(log[3], 2); + assert_equals(log[5], 3); + assert_not_equals(log[0], log[2], + 'Instantiation error objects for different root scripts'); + assert_equals(log[0], log[4], + 'Instantiation error objects for the same root script'); })); function unreachable() { log.push("unexpected"); } diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-4.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-4.html index 238e8832c00..8d3f23819a1 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-4.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-4.html @@ -17,8 +17,11 @@ }); window.addEventListener("load", test_load.step_func_done(ev => { - const msg = log[0]; - assert_array_equals(log, [msg, 1, msg, 2]); + assert_equals(log.length, 4, 'Log length'); + assert_equals(log[1], 1); + assert_equals(log[3], 2); + assert_not_equals(log[0], log[2], + 'Instantiation error objects for different root scripts'); })); function unreachable() { log.push("unexpected"); } diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-5.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-5.html index de2b6ba7b34..20df0bb5c96 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-5.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-5.html @@ -17,8 +17,11 @@ }); window.addEventListener("load", test_load.step_func_done(ev => { - const msg = log[0]; - assert_array_equals(log, [msg, 1, msg, 2]); + assert_equals(log.length, 4, 'Log length'); + assert_equals(log[1], 1); + assert_equals(log[3], 2); + assert_not_equals(log[0], log[2], + 'Instantiation error objects for different root scripts'); })); function unreachable() { log.push("unexpected"); } diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-supports.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-supports.html new file mode 100644 index 00000000000..495056fce9a --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-supports.html @@ -0,0 +1,52 @@ +<!doctype html> +<meta charset=utf-8> +<title>HTMLScriptElement.supports</title> +<link rel=help href="https://html.spec.whatwg.org/#dom-script-supports"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(function() { + assert_equals(typeof HTMLScriptElement.supports, 'function'); +}, 'Type of HTMLScriptElement.supports is function'); + +test(function() { + assert_true(HTMLScriptElement.supports('classic')); +}, 'HTMLScriptElement.supports resurns true for \'classic\''); + +test(function() { + assert_true(HTMLScriptElement.supports('module')); +}, 'HTMLScriptElement.supports resurns true for \'module\''); + +test(function() { + assert_false(HTMLScriptElement.supports('application/ecmascript')); + assert_false(HTMLScriptElement.supports('application/javascript')); + assert_false(HTMLScriptElement.supports('application/x-ecmascript')); + assert_false(HTMLScriptElement.supports('application/x-javascript')); + assert_false(HTMLScriptElement.supports('text/ecmascript')); + assert_false(HTMLScriptElement.supports('text/javascript')); + assert_false(HTMLScriptElement.supports('text/javascript1.0')); + assert_false(HTMLScriptElement.supports('text/javascript1.1')); + assert_false(HTMLScriptElement.supports('text/javascript1.2')); + assert_false(HTMLScriptElement.supports('text/javascript1.3')); + assert_false(HTMLScriptElement.supports('text/javascript1.4')); + assert_false(HTMLScriptElement.supports('text/javascript1.5')); + assert_false(HTMLScriptElement.supports('text/jscript')); + assert_false(HTMLScriptElement.supports('text/livescript')); + assert_false(HTMLScriptElement.supports('text/x-ecmascript')); + assert_false(HTMLScriptElement.supports('text/x-javascript')); +}, 'HTMLScriptElement.supports returns false for JavaScript MIME types'); + +test(function() { + assert_false(HTMLScriptElement.supports('')); + assert_false(HTMLScriptElement.supports(' ')); + assert_false(HTMLScriptElement.supports('classic ')); + assert_false(HTMLScriptElement.supports('module ')); + assert_false(HTMLScriptElement.supports(' classic ')); + assert_false(HTMLScriptElement.supports(' module ')); + assert_false(HTMLScriptElement.supports('classics')); + assert_false(HTMLScriptElement.supports('modules')); + assert_false(HTMLScriptElement.supports('Classic')); + assert_false(HTMLScriptElement.supports('Module')); + assert_false(HTMLScriptElement.supports('unsupported')); +}, 'HTMLScriptElement.supports returns false for unsupported types'); +</script> |