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-other-document.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-other-document.html')
-rw-r--r-- | testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html new file mode 100644 index 0000000000..3b1d98f6b1 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html @@ -0,0 +1,79 @@ +<!doctype html> +<meta charset=utf-8> +<title>Check import() works when active script is in another document</title> +<link rel="author" title="Jon Coppeard" href="mailto:jcoppeard@mozilla.com"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> + +<iframe id="frame" src="resources/empty-iframe.html"></iframe> + +<script> + +function startTest() { + const otherWindow = document.getElementById("frame").contentWindow; + const otherDiv = otherWindow.document.getElementById("dummy"); + + function createTestPromise() { + return new Promise((resolve, reject) => { + otherWindow.continueTest = resolve; + otherWindow.errorTest = reject; + }); + } + + const evaluators = { + eval: otherWindow.eval, + setTimeout: otherWindow.setTimeout, + "the Function constructor"(x) { + otherWindow.Function(x)(); + }, + }; + + for (const [label, evaluator] of Object.entries(evaluators)) { + promise_test(t => { + t.add_cleanup(() => { + otherDiv.removeAttribute("onclick"); + delete otherWindow.evaluated_imports_a; + }); + + const promise = createTestPromise(); + + evaluator(`import('../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); + + return promise.then(module => { + assert_true(otherWindow.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"); + }; + + const eventHandlerEvaluators = { + "reflected inline event handlers"(x) { + otherDiv.setAttribute("onclick", x); + otherDiv.onclick(); + }, + "inline event handlers triggered by JS"(x) { + otherDiv.setAttribute("onclick", x); + otherDiv.click(); // different from .**on**click() + } + }; + + for (const [label, evaluator] of Object.entries(eventHandlerEvaluators)) { + promise_test(t => { + t.add_cleanup(() => { + otherDiv.removeAttribute("onclick"); + delete otherWindow.evaluated_imports_a; + }); + + const promise = createTestPromise(); + + evaluator(`import('../../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); + + return promise.then(module => { + assert_true(otherWindow.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"); + }; +} +</script> +<body onLoad="startTest()"></body> |