diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions')
13 files changed, 137 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.any.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.any.js new file mode 100644 index 0000000000..7efb2050b7 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/dynamic-import-with-assertion-argument.any.js @@ -0,0 +1,18 @@ +// 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 => { + return promise_rejects_js(test, TypeError, + import("./export-hello.js", { assert: { unsupportedAssertionKey: "unsupportedAssertionValue"} }), + "Dynamic import with an unsupported import assertion should fail"); +}, "Dynamic import with an unsupported import assertion should fail"); + +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/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause.html new file mode 100644 index 0000000000..3a7c371189 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<title>Handling of empty import assertion clause</title> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + window.log = []; + + window.addEventListener("error", ev => log.push(ev.error)); + + const test_load = async_test( + "Test that no error occurs when an empty import assertion clause is provided."); + window.addEventListener("load", test_load.step_func_done(ev => { + assert_array_equals(window.log, ["hello", "empty-assertion-clause"]); + })); + + function unreachable() { log.push("unexpected"); } +</script> +<script type="module" src="./empty-assertion-clause.js" onerror="unreachable()"></script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause.js new file mode 100644 index 0000000000..6913dd61df --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause.js @@ -0,0 +1,2 @@ +import "./hello.js" assert { }; +log.push("empty-assertion-clause"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-type-assertion.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-type-assertion.js new file mode 100644 index 0000000000..5bb9b1ddb8 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-type-assertion.js @@ -0,0 +1,2 @@ +import "./hello.js#2" assert { type: "" }; +log.push("empty-type-assertion"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/export-hello.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/export-hello.js new file mode 100644 index 0000000000..34b58e6e12 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/export-hello.js @@ -0,0 +1 @@ +export default "hello"; diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/hello.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/hello.js new file mode 100644 index 0000000000..2f34844460 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/hello.js @@ -0,0 +1 @@ +log.push("hello");
\ No newline at end of file diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-import-errors-order.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-import-errors-order.html new file mode 100644 index 0000000000..17c95faea0 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-import-errors-order.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<title>Handling of invalid module type import attributes</title> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + setup({allow_uncaught_exception: true}); + + var log = []; + window.addEventListener("error", ev => log.push(ev.error)); + + const test_load = async_test( + "Test that the errors order for invalid import declarations is" + + " specifier, then attribute key, and then type attribute value."); + window.addEventListener("load", test_load.step_func_done(ev => { + assert_equals(log.length, 3); + assert_equals(log[0].constructor, SyntaxError); + assert_equals(log[1].constructor, SyntaxError); + assert_equals(log[2].constructor, SyntaxError); + })); + + function unreachable() { log.push("unexpected"); } +</script> +<script type="module" onerror="unreachable()"> + // unknown attribute is reported before invalid specifier + import "INVALID" assert { unknown: "foo" }; +</script> +<script type="module" onerror="unreachable()"> + // unknown attribute is reported before unknown type + import "./valid" assert { unknown: "foo", type: "unknown" }; +</script> +<script type="module" onerror="unreachable()"> + // unknown attribute is reported before invalid specifier in subsequent import + import "./valid" assert { unknown: "foo" }; + import "INVALID"; +</script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error.html new file mode 100644 index 0000000000..0adcc47569 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<title>Handling of invalid module type import assertions</title> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + setup({allow_uncaught_exception: true}); + + window.log = []; + + window.addEventListener("error", ev => log.push(ev.error)); + + 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, 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/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion.js new file mode 100644 index 0000000000..e28c0176d5 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion.js @@ -0,0 +1,2 @@ +import "./hello.js#1" assert { type: "notARealType" }; +log.push("invalid-type-assertion"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/javascript-type-assertion.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/javascript-type-assertion.js new file mode 100644 index 0000000000..cc0f531026 --- /dev/null +++ b/testing/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/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/js-type-assertion.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/js-type-assertion.js new file mode 100644 index 0000000000..c649c95ffe --- /dev/null +++ b/testing/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/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion.html new file mode 100644 index 0000000000..72977347a7 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion.html @@ -0,0 +1,22 @@ +<!DOCTYPE html> +<title>Handling of unsupported assertion</title> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + setup({allow_uncaught_exception: true}); + + window.log = []; + + window.addEventListener("error", ev => log.push(ev.error)); + + const test_load = async_test( + "Test that invalid module assertion leads to SyntaxError on window."); + window.addEventListener("load", test_load.step_func_done(ev => { + assert_equals(log.length, 1); + assert_equals(log[0].constructor, SyntaxError); + })); + + function unreachable() { log.push("unexpected"); } +</script> +<script type="module" src="./unsupported-assertion.js" onerror="unreachable()"></script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion.js new file mode 100644 index 0000000000..45f6d60c9d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion.js @@ -0,0 +1,2 @@ +import "./hello.js" assert { unsupportedAssertionKey: "unsupportedAssertionValue" }; +log.push("unsupported-assertion"); |