summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html
diff options
context:
space:
mode:
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.html79
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>