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/module/dynamic-import/string-compilation-base-url-inline-classic.html | |
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/module/dynamic-import/string-compilation-base-url-inline-classic.html')
-rw-r--r-- | testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html new file mode 100644 index 0000000000..2fe1f75535 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-inline-classic.html @@ -0,0 +1,73 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<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"> + +<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; + window.errorTest = reject; + }); +} + +const dummyDiv = document.querySelector("#dummy"); + +function doTest(label, evaluator, path) { + promise_test(t => { + t.add_cleanup(() => { + dummyDiv.removeAttribute("onclick"); + delete window.evaluated_imports_a; + }); + + const promise = createTestPromise(); + + 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> |