summaryrefslogtreecommitdiffstats
path: root/dom/base/test/jsmodules
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/test/jsmodules')
-rw-r--r--dom/base/test/jsmodules/chrome.toml12
-rw-r--r--dom/base/test/jsmodules/export_star_ambiguous.mjs1
-rw-r--r--dom/base/test/jsmodules/import_ambiguous_export.mjs1
-rw-r--r--dom/base/test/jsmodules/import_ambiguous_export_star.mjs1
-rw-r--r--dom/base/test/jsmodules/import_circular.mjs1
-rw-r--r--dom/base/test/jsmodules/import_circular_1.mjs1
-rw-r--r--dom/base/test/jsmodules/import_no_export.mjs2
-rw-r--r--dom/base/test/jsmodules/import_no_indirect_export.mjs2
-rw-r--r--dom/base/test/jsmodules/importmaps/classic_script.js1
-rw-r--r--dom/base/test/jsmodules/importmaps/mochitest.toml7
-rw-r--r--dom/base/test/jsmodules/importmaps/module_chain_1.mjs2
-rw-r--r--dom/base/test/jsmodules/importmaps/module_chain_2.mjs1
-rw-r--r--dom/base/test/jsmodules/importmaps/module_importMap_with_nonexisting_module.mjs4
-rw-r--r--dom/base/test/jsmodules/importmaps/test_dynamic_importMap_load_completes.html33
-rw-r--r--dom/base/test/jsmodules/importmaps/test_dynamic_importMap_with_external_script.html81
-rw-r--r--dom/base/test/jsmodules/importmaps/test_importMap_with_nonexisting_module.html25
-rw-r--r--dom/base/test/jsmodules/module_a.mjs2
-rw-r--r--dom/base/test/jsmodules/module_b.mjs2
-rw-r--r--dom/base/test/jsmodules/module_c.mjs3
-rw-r--r--dom/base/test/jsmodules/module_d.mjs1
-rw-r--r--dom/base/test/jsmodules/module_e.mjs1
-rw-r--r--dom/base/test/jsmodules/test_import_errorMessage.html40
-rw-r--r--dom/base/test/jsmodules/test_import_errorMessage2.html35
23 files changed, 236 insertions, 23 deletions
diff --git a/dom/base/test/jsmodules/chrome.toml b/dom/base/test/jsmodules/chrome.toml
index 82d02ad4df..8b8a614bfb 100644
--- a/dom/base/test/jsmodules/chrome.toml
+++ b/dom/base/test/jsmodules/chrome.toml
@@ -3,11 +3,21 @@ support-files = [
"ambiguous_export.mjs",
"import_ambiguous.mjs",
"import_ambiguous_indirect_export.mjs",
+ "import_ambiguous_export.mjs",
+ "import_ambiguous_export_star.mjs",
+ "import_circular.mjs",
+ "import_circular_1.mjs",
"import_no_export.mjs",
"import_no_indirect_export.mjs",
"exportA1.mjs",
"exportA2.mjs",
"export_ambiguous.mjs",
+ "export_star_ambiguous.mjs",
+ "module_a.mjs",
+ "module_b.mjs",
+ "module_c.mjs",
+ "module_d.mjs",
+ "module_e.mjs",
"module_setRan.mjs",
"module_testSyntax.mjs",
"module_badSyntax.mjs",
@@ -47,6 +57,8 @@ support-files = [
["test_import_errorMessage.html"]
+["test_import_errorMessage2.html"]
+
["test_import_meta_resolve.html"]
["test_importedModuleMemoization.html"]
diff --git a/dom/base/test/jsmodules/export_star_ambiguous.mjs b/dom/base/test/jsmodules/export_star_ambiguous.mjs
new file mode 100644
index 0000000000..35cc979dee
--- /dev/null
+++ b/dom/base/test/jsmodules/export_star_ambiguous.mjs
@@ -0,0 +1 @@
+export * from "./ambiguous_export.mjs";
diff --git a/dom/base/test/jsmodules/import_ambiguous_export.mjs b/dom/base/test/jsmodules/import_ambiguous_export.mjs
new file mode 100644
index 0000000000..f5c12ff086
--- /dev/null
+++ b/dom/base/test/jsmodules/import_ambiguous_export.mjs
@@ -0,0 +1 @@
+import { a } from "./ambiguous_export.mjs";
diff --git a/dom/base/test/jsmodules/import_ambiguous_export_star.mjs b/dom/base/test/jsmodules/import_ambiguous_export_star.mjs
new file mode 100644
index 0000000000..1ee2a56d37
--- /dev/null
+++ b/dom/base/test/jsmodules/import_ambiguous_export_star.mjs
@@ -0,0 +1 @@
+import { a } from "./export_star_ambiguous.mjs";
diff --git a/dom/base/test/jsmodules/import_circular.mjs b/dom/base/test/jsmodules/import_circular.mjs
new file mode 100644
index 0000000000..bb3a46bd5e
--- /dev/null
+++ b/dom/base/test/jsmodules/import_circular.mjs
@@ -0,0 +1 @@
+export { a } from "./import_circular_1.mjs";
diff --git a/dom/base/test/jsmodules/import_circular_1.mjs b/dom/base/test/jsmodules/import_circular_1.mjs
new file mode 100644
index 0000000000..eb7c038c77
--- /dev/null
+++ b/dom/base/test/jsmodules/import_circular_1.mjs
@@ -0,0 +1 @@
+export { a } from "./import_circular.mjs";
diff --git a/dom/base/test/jsmodules/import_no_export.mjs b/dom/base/test/jsmodules/import_no_export.mjs
index 47cabac557..d989498c88 100644
--- a/dom/base/test/jsmodules/import_no_export.mjs
+++ b/dom/base/test/jsmodules/import_no_export.mjs
@@ -1 +1 @@
-import x from "./no_export.mjs";
+import { x } from "./no_export.mjs";
diff --git a/dom/base/test/jsmodules/import_no_indirect_export.mjs b/dom/base/test/jsmodules/import_no_indirect_export.mjs
index dd1ca847fc..bfcdcedbc5 100644
--- a/dom/base/test/jsmodules/import_no_indirect_export.mjs
+++ b/dom/base/test/jsmodules/import_no_indirect_export.mjs
@@ -1,2 +1,2 @@
/* eslint-disable import/default */
-import x from "./no_indirect_export.mjs";
+import { a } from "./no_indirect_export.mjs";
diff --git a/dom/base/test/jsmodules/importmaps/classic_script.js b/dom/base/test/jsmodules/importmaps/classic_script.js
new file mode 100644
index 0000000000..d7ae0be054
--- /dev/null
+++ b/dom/base/test/jsmodules/importmaps/classic_script.js
@@ -0,0 +1 @@
+// Empty script.
diff --git a/dom/base/test/jsmodules/importmaps/mochitest.toml b/dom/base/test/jsmodules/importmaps/mochitest.toml
index 4229455722..1f95b155ac 100644
--- a/dom/base/test/jsmodules/importmaps/mochitest.toml
+++ b/dom/base/test/jsmodules/importmaps/mochitest.toml
@@ -3,6 +3,9 @@ support-files = [
"bug_1865410_module_a.mjs",
"bug_1865410_module_b.mjs",
"bug_1873417.mjs",
+ "classic_script.js",
+ "module_chain_1.mjs",
+ "module_chain_2.mjs",
"module_importMap_with_external_script_0.mjs",
"module_importMap_with_external_script_1.mjs",
"module_importMap_with_external_script_2.mjs",
@@ -13,6 +16,7 @@ support-files = [
"module_importMap_with_external_script_6.mjs",
"module_importMap_with_external_script_6.mjs^headers^",
"module_importMap_with_external_script_7.mjs",
+ "module_importMap_with_nonexisting_module.mjs",
"bad/module_2.mjs",
"bad/module_3.mjs",
"bad/module_4.mjs",
@@ -31,3 +35,6 @@ support-files = [
["test_bug_1873417.html"]
["test_importMap_with_external_script.html"]
+["test_importMap_with_nonexisting_module.html"]
+["test_dynamic_importMap_with_external_script.html"]
+["test_dynamic_importMap_load_completes.html"]
diff --git a/dom/base/test/jsmodules/importmaps/module_chain_1.mjs b/dom/base/test/jsmodules/importmaps/module_chain_1.mjs
new file mode 100644
index 0000000000..d9515fab7f
--- /dev/null
+++ b/dom/base/test/jsmodules/importmaps/module_chain_1.mjs
@@ -0,0 +1,2 @@
+// eslint-disable-next-line import/no-unassigned-import
+import {} from "./module_chain_2.mjs";
diff --git a/dom/base/test/jsmodules/importmaps/module_chain_2.mjs b/dom/base/test/jsmodules/importmaps/module_chain_2.mjs
new file mode 100644
index 0000000000..ce12406a76
--- /dev/null
+++ b/dom/base/test/jsmodules/importmaps/module_chain_2.mjs
@@ -0,0 +1 @@
+loaded = true;
diff --git a/dom/base/test/jsmodules/importmaps/module_importMap_with_nonexisting_module.mjs b/dom/base/test/jsmodules/importmaps/module_importMap_with_nonexisting_module.mjs
new file mode 100644
index 0000000000..4f9981bbe3
--- /dev/null
+++ b/dom/base/test/jsmodules/importmaps/module_importMap_with_nonexisting_module.mjs
@@ -0,0 +1,4 @@
+/* eslint-disable import/no-unassigned-import, import/no-unresolved */
+// Bareword specifier should be mapped to ./good/module_0.mjs.
+import {} from "bare";
+import * as test from "nonexistingmodule";
diff --git a/dom/base/test/jsmodules/importmaps/test_dynamic_importMap_load_completes.html b/dom/base/test/jsmodules/importmaps/test_dynamic_importMap_load_completes.html
new file mode 100644
index 0000000000..da354c1ca0
--- /dev/null
+++ b/dom/base/test/jsmodules/importmaps/test_dynamic_importMap_load_completes.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<head>
+<title>Test script loading complets when there's a dynamicly inserted import map</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+
+<!--
+ This test case used to fail intermittently with some modules never
+ being loaded.
+-->
+
+<script>
+ let loaded = false; // Set by module_chain_2.mjs.
+</script>
+
+<script src="classic_script.js"></script>
+
+<script>
+ const script = document.createElement('script');
+ script.type = 'importmap';
+ script.textContent = `{}`;
+ document.head.appendChild(script);
+</script>
+
+<script src="module_chain_1.mjs" type="module"></script>
+
+<script type="module">
+ ok(loaded, "Expected all modules loaded");
+</script>
+
+<body></body>
diff --git a/dom/base/test/jsmodules/importmaps/test_dynamic_importMap_with_external_script.html b/dom/base/test/jsmodules/importmaps/test_dynamic_importMap_with_external_script.html
new file mode 100644
index 0000000000..b78992fb87
--- /dev/null
+++ b/dom/base/test/jsmodules/importmaps/test_dynamic_importMap_with_external_script.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<head>
+<title>Test speculative preload of external script doesn't conflict with import map</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+
+<!--
+ These tests check that speculative preloading, which could happen before
+ the import map is installed, doesn't load the wrong modules. This version
+ dynamically inserts the import map script element after speculative
+ preloading has started.
+-->
+
+<script>
+ const script = document.createElement('script');
+ script.type = 'importmap';
+ script.textContent =
+ `{
+ "imports": {
+ "bare": "./good/module_0.mjs",
+ "./bad/module_1.mjs": "./good/module_1.mjs",
+ "./bad/module_2.mjs": "./good/module_2.mjs",
+ "./bad/module_3.mjs": "./good/module_3.mjs",
+ "./bad/module_4.mjs": "./good/module_4.mjs",
+ "./bad/module_7.mjs": "./good/module_7.mjs"
+ }
+ }`;
+ document.head.appendChild(script);
+</script>
+
+<!--
+Test bareword import (not supported before import map installed).
+-->
+<script type="module" src="module_importMap_with_external_script_0.mjs"></script>
+
+<!--
+Test mapping from missing resource to existing resource (not found before
+import map installed).
+-->
+<script type="module" src="module_importMap_with_external_script_1.mjs"></script>
+
+<!--
+Test mapping from one existing resource to another (would load wrong resource before
+import map installed).
+-->
+<script type="module" src="module_importMap_with_external_script_2.mjs"></script>
+
+<!--
+Test mapping from one existing resource to another with circular dependency.
+-->
+<script type="module" src="module_importMap_with_external_script_3.mjs"></script>
+
+<!--
+Test with redirect, script_6.mjs -> script_5.mjs -> script_4.mjs.
+We redirect twice here, as sometimes one redirect can't reproduce the crash
+from bug 1835468.
+-->
+<script type="module" src="module_importMap_with_external_script_6.mjs"></script>
+
+<!--
+Test with async attribute
+-->
+<script type="module" async src="module_importMap_with_external_script_7.mjs"></script>
+
+<script>
+ SimpleTest.waitForExplicitFinish();
+
+ let passCount = 0;
+ const expectedCount = 6;
+
+ function success(name) {
+ ok(true, "Test passed, loaded " + name);
+ passCount++;
+ if (passCount == expectedCount) {
+ SimpleTest.finish();
+ }
+ }
+</script>
+<body></body>
diff --git a/dom/base/test/jsmodules/importmaps/test_importMap_with_nonexisting_module.html b/dom/base/test/jsmodules/importmaps/test_importMap_with_nonexisting_module.html
new file mode 100644
index 0000000000..57cfd5e5a1
--- /dev/null
+++ b/dom/base/test/jsmodules/importmaps/test_importMap_with_nonexisting_module.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Test an import map with an nonexisting module specifier</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+
+<script type="importmap">
+{
+ "imports": {
+ "bare": "./good/module_0.mjs"
+ }
+}
+</script>
+
+
+<script>
+ SimpleTest.waitForExplicitFinish();
+
+ window.onerror = (event, src, lineno, colno, error) => {
+ ok(error instanceof TypeError, "Should be a TypeError");
+ SimpleTest.finish();
+ };
+
+</script>
+<script type="module" src="module_importMap_with_nonexisting_module.mjs"></script>
diff --git a/dom/base/test/jsmodules/module_a.mjs b/dom/base/test/jsmodules/module_a.mjs
new file mode 100644
index 0000000000..0b0c3304ff
--- /dev/null
+++ b/dom/base/test/jsmodules/module_a.mjs
@@ -0,0 +1,2 @@
+export var a = 1;
+export var b = 2;
diff --git a/dom/base/test/jsmodules/module_b.mjs b/dom/base/test/jsmodules/module_b.mjs
new file mode 100644
index 0000000000..79da84736d
--- /dev/null
+++ b/dom/base/test/jsmodules/module_b.mjs
@@ -0,0 +1,2 @@
+export var b = 3;
+export var c = 4;
diff --git a/dom/base/test/jsmodules/module_c.mjs b/dom/base/test/jsmodules/module_c.mjs
new file mode 100644
index 0000000000..5a2a7e3e09
--- /dev/null
+++ b/dom/base/test/jsmodules/module_c.mjs
@@ -0,0 +1,3 @@
+/* eslint-disable import/export */
+export * from "./module_a.mjs";
+export * from "./module_b.mjs";
diff --git a/dom/base/test/jsmodules/module_d.mjs b/dom/base/test/jsmodules/module_d.mjs
new file mode 100644
index 0000000000..04dc02d27a
--- /dev/null
+++ b/dom/base/test/jsmodules/module_d.mjs
@@ -0,0 +1 @@
+import { a } from "./module_c.mjs";
diff --git a/dom/base/test/jsmodules/module_e.mjs b/dom/base/test/jsmodules/module_e.mjs
new file mode 100644
index 0000000000..544c424fcb
--- /dev/null
+++ b/dom/base/test/jsmodules/module_e.mjs
@@ -0,0 +1 @@
+import { b } from "./module_c.mjs";
diff --git a/dom/base/test/jsmodules/test_import_errorMessage.html b/dom/base/test/jsmodules/test_import_errorMessage.html
index 6ab0b1dd74..2330b46dd9 100644
--- a/dom/base/test/jsmodules/test_import_errorMessage.html
+++ b/dom/base/test/jsmodules/test_import_errorMessage.html
@@ -8,40 +8,38 @@
let count = 0;
window.onerror = function (event, src, lineno, colno, error) {
- info("window.onerror :" + error.message);
+ info("window.onerror: message: " + error.message);
+ info("window.onerror: src: " + src);
ok(error instanceof SyntaxError, "Should be a SyntaxError.");
- // import_no_indirect_export.mjs and import_ambiguous_indirect_export.mjs
- // are related to indirect import/export.
- if (count < 2) {
- ok(error.message.match("indirect"), "Should contain 'indirect'");
- }
-
- // import_ambiguous_indirect_export.mjs and import_ambiguous.mjs both
- // have ambiguous import/export.
- if (count % 2 === 1) {
- ok(error.message.match("ambiguous"), "Should contain 'ambiguous'");
- }
-
- if (count === 2) {
- ok(!error.message.match("ambiguous") && !error.message.match("indirect"),
- "Should NOT contain 'indirect' nor 'ambiguous'");
+ if (src.match("no_indirect_export.mjs") ||
+ src.match("import_no_export.mjs")) {
+ ok(error.message.match("doesn't provide an export named"));
+ } else if(src.match("export_ambiguous.mjs") ||
+ src.match("import_ambiguous_export_star.mjs") ||
+ src.match("import_ambiguous_export.mjs") ||
+ src.match("import_ambiguous.mjs")) {
+ ok(error.message.match("contains ambiguous star export"));
+ } else if (src.match("import_circular_1.mjs")) {
+ ok(error.message.match("contains circular import"));
+ } else {
+ ok(false, "unknown src " + src);
}
count++;
};
function testLoaded() {
- ok(count === 4, "Should have 4 SynaxErrors thrown.");
+ ok(count === 7, "Should have 7 SynaxErrors thrown.");
SimpleTest.finish();
}
+
</script>
-<!--
-In window.onerror will test the error messages, so if the order is changed,
-the code in window.onerror should be updated as well.
--->
<script type="module" src="import_no_indirect_export.mjs"></script>
<script type="module" src="import_ambiguous_indirect_export.mjs"></script>
+<script type="module" src="import_ambiguous_export_star.mjs"></script>
+<script type="module" src="import_ambiguous_export.mjs"></script>
<script type="module" src="import_no_export.mjs"></script>
<script type="module" src="import_ambiguous.mjs"></script>
+<script type="module" src="import_circular.mjs"></script>
<body onload='testLoaded()'></body>
diff --git a/dom/base/test/jsmodules/test_import_errorMessage2.html b/dom/base/test/jsmodules/test_import_errorMessage2.html
new file mode 100644
index 0000000000..ed4227362e
--- /dev/null
+++ b/dom/base/test/jsmodules/test_import_errorMessage2.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Test to get the filename of the requested module after it has been evaluated</title>
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+ SimpleTest.waitForExplicitFinish();
+
+ let count = 0;
+
+ window.onerror = function (event, src, lineno, colno, error) {
+ info("window.onerror: message: " + error.message);
+ info("window.onerror: src: " + src);
+ ok(error instanceof SyntaxError, "Should be a SyntaxError.");
+
+ if (src.match("module_e.mjs")) {
+ ok(error.message.match("contains ambiguous star export"));
+ } else {
+ ok(false, "unknown src " + src);
+ }
+ count++;
+ };
+
+ function testLoaded() {
+ ok(count === 1, "Should have 1 SynaxError thrown.");
+ SimpleTest.finish();
+ }
+
+</script>
+
+<!--module_c.mjs will be evaluated here-->
+<script type="module" src="module_d.mjs"></script>
+
+<!--module_c.mjs will be linked again here-->
+<script type="module" src="module_e.mjs"></script>
+<body onload='testLoaded()'></body>