diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/base/test/jsmodules/importmaps | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/jsmodules/importmaps')
25 files changed, 638 insertions, 0 deletions
diff --git a/dom/base/test/jsmodules/importmaps/chrome.ini b/dom/base/test/jsmodules/importmaps/chrome.ini new file mode 100644 index 0000000000..4fca7e97fa --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/chrome.ini @@ -0,0 +1,29 @@ +[DEFAULT] +support-files = + external_importMap.js + insert_a_base_element.js + module_simpleImportMap.js + module_simpleImportMap_dir.js + module_simpleImportMap_remap.js + module_simpleImportMap_remap_https.js + module_simpleExport.js + module_sortedImportMap.js + scope1/module_simpleExport.js + scope1/module_simpleImportMap.js + scope1/scope2/module_simpleExport.js + scope1/scope2/module_simpleImportMap.js +prefs = + dom.importMaps.enabled=true + +[test_dynamic_import_reject_importMap.html] +[test_externalImportMap.html] +[test_import_meta_resolve_importMap.html] +[test_inline_module_reject_importMap.html] +[test_load_importMap_with_base.html] +[test_load_importMap_with_base2.html] +[test_module_script_reject_importMap.html] +[test_parse_importMap_failed.html] +[test_reject_multiple_importMaps.html] +[test_simpleImportMap.html] +[test_sortedImportMap.html] + diff --git a/dom/base/test/jsmodules/importmaps/external_importMap.js b/dom/base/test/jsmodules/importmaps/external_importMap.js new file mode 100644 index 0000000000..e89d9f618f --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/external_importMap.js @@ -0,0 +1,5 @@ +let imap = { + imports: { + foo: "./foo.js", + }, +}; diff --git a/dom/base/test/jsmodules/importmaps/insert_a_base_element.js b/dom/base/test/jsmodules/importmaps/insert_a_base_element.js new file mode 100644 index 0000000000..435af97d1e --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/insert_a_base_element.js @@ -0,0 +1,4 @@ +const el = document.createElement("base"); +el.href = + "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/"; +document.currentScript.after(el); diff --git a/dom/base/test/jsmodules/importmaps/module_simpleExport.js b/dom/base/test/jsmodules/importmaps/module_simpleExport.js new file mode 100644 index 0000000000..9714d6d0ab --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/module_simpleExport.js @@ -0,0 +1 @@ +export let x = 42; diff --git a/dom/base/test/jsmodules/importmaps/module_simpleImportMap.js b/dom/base/test/jsmodules/importmaps/module_simpleImportMap.js new file mode 100644 index 0000000000..153b84e6de --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/module_simpleImportMap.js @@ -0,0 +1,2 @@ +import { x } from "simple"; +result = x; diff --git a/dom/base/test/jsmodules/importmaps/module_simpleImportMap_dir.js b/dom/base/test/jsmodules/importmaps/module_simpleImportMap_dir.js new file mode 100644 index 0000000000..554cc6a7bd --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/module_simpleImportMap_dir.js @@ -0,0 +1,2 @@ +import { x } from "dir/module_simpleExport.js"; +result_dir = x + 1; diff --git a/dom/base/test/jsmodules/importmaps/module_simpleImportMap_remap.js b/dom/base/test/jsmodules/importmaps/module_simpleImportMap_remap.js new file mode 100644 index 0000000000..5ebaa30188 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/module_simpleImportMap_remap.js @@ -0,0 +1,2 @@ +import { x } from "./module.js"; +result_remap = x + 2; diff --git a/dom/base/test/jsmodules/importmaps/module_simpleImportMap_remap_https.js b/dom/base/test/jsmodules/importmaps/module_simpleImportMap_remap_https.js new file mode 100644 index 0000000000..c047fd28c3 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/module_simpleImportMap_remap_https.js @@ -0,0 +1,2 @@ +import { x } from "https://example.com/module.js"; +result_remap_https = x + 3; diff --git a/dom/base/test/jsmodules/importmaps/module_sortedImportMap.js b/dom/base/test/jsmodules/importmaps/module_sortedImportMap.js new file mode 100644 index 0000000000..41b2903097 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/module_sortedImportMap.js @@ -0,0 +1,4 @@ +import { x } from "scope1/scope2/module_simpleExport.js"; +import { x as y } from "scope1/scope2/scope3/scope4/module_simpleExport.js"; +sorted_result = x; +sorted_result2 = y; diff --git a/dom/base/test/jsmodules/importmaps/moz.build b/dom/base/test/jsmodules/importmaps/moz.build new file mode 100644 index 0000000000..1a7d5281ea --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/moz.build @@ -0,0 +1,7 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +MOCHITEST_CHROME_MANIFESTS += ["chrome.ini"] diff --git a/dom/base/test/jsmodules/importmaps/scope1/module_simpleExport.js b/dom/base/test/jsmodules/importmaps/scope1/module_simpleExport.js new file mode 100644 index 0000000000..e6b0ed1c0c --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/scope1/module_simpleExport.js @@ -0,0 +1 @@ +export let x = 84; diff --git a/dom/base/test/jsmodules/importmaps/scope1/module_simpleImportMap.js b/dom/base/test/jsmodules/importmaps/scope1/module_simpleImportMap.js new file mode 100644 index 0000000000..b1682e1900 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/scope1/module_simpleImportMap.js @@ -0,0 +1,2 @@ +import { x } from "simple"; +result_scope1 = x; diff --git a/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleExport.js b/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleExport.js new file mode 100644 index 0000000000..ba2bbae16b --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleExport.js @@ -0,0 +1 @@ +export let x = 126; diff --git a/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleImportMap.js b/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleImportMap.js new file mode 100644 index 0000000000..ecb38b7b21 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleImportMap.js @@ -0,0 +1,2 @@ +import { x } from "simple"; +result_scope2 = x; diff --git a/dom/base/test/jsmodules/importmaps/test_dynamic_import_reject_importMap.html b/dom/base/test/jsmodules/importmaps/test_dynamic_import_reject_importMap.html new file mode 100644 index 0000000000..75471064f9 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_dynamic_import_reject_importMap.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test import map should be rejected.</title> +</head> +<body onload='testLoaded()'> +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<!--There is a dynamic import before the import map tag, so the import map--> +<!--cannot be accepted according to the spec.--> +<!--And because the import map is rejected, so the module specifier--> +<!--"./module_simpleExport.js" won't be remapped to--> +<!--"./scope1/module_simpleExport.js".--> + +<script> + import("./module_simpleExport.js"); +</script> + +<script type="importmap" onerror='importMapError()'> +{ + "imports": { + "./module_simpleExport.js": "./scope1/module_simpleExport.js" + } +} +</script> + +<script> + SimpleTest.waitForExplicitFinish(); + + let hasError = false; + function importMapError() { + hasError = true; + } + + function testLoaded() { + import("./module_simpleExport.js").then((ns) => { + ok(ns.x == 42, 'Check simple imported value result: ' + ns.x); + ok(hasError, "onerror of the import map should be called."); + }).catch((e) => { + ok(false, "throws " + e); + }).then(() => { + SimpleTest.finish(); + }); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_externalImportMap.html b/dom/base/test/jsmodules/importmaps/test_externalImportMap.html new file mode 100644 index 0000000000..1345f61947 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_externalImportMap.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Test an external import map</title> +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +let gotMsg = false; +let console = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); +let listener = { + QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]), + observe(msg) { + info("console message:" + msg); + ok(msg.logLevel == Ci.nsIConsoleMessage.warn, "log level should be 'warn'."); + // The message will be localized, so we just test the strings won't be + // localized. + ok(msg.message.match(/<script type='importmap'>.*src/), + "The error message should contain \"<script type='importmap'>\""); + console.unregisterListener(this); + gotMsg = true; + } +}; +console.registerListener(listener); +</script> + +<!--Import maps spec doesn't clearly define the format of an external import map script.--> +<script src="external_importMap.js" type="importmap" onload="scriptLoaded()" onerror="scriptError()"></script> + +<script> +function testLoaded() { + SimpleTest.waitForExplicitFinish(); + ok(gotMsg, "Should have got the console warning."); + SimpleTest.finish(); +} + +function scriptLoaded() { + ok(false, "Loading external import map script should have failed."); +} + +function scriptError() { + ok(true, "Loading external import map script failed."); +} +</script> +<body onload='testLoaded()'></body> diff --git a/dom/base/test/jsmodules/importmaps/test_import_meta_resolve_importMap.html b/dom/base/test/jsmodules/importmaps/test_import_meta_resolve_importMap.html new file mode 100644 index 0000000000..df1bed2e56 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_import_meta_resolve_importMap.html @@ -0,0 +1,49 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test import.meta.resolve with import maps</title> +</head> +<body onload='testLoaded()'> + +<script type="importmap"> +{ + "imports": { + "simple": "./module_simpleExport.js" + } +} +</script> + +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<script> + var wasRun = false; + var hasThrown = false; + window.onerror = handleError; + + function handleError(msg, url, line, col, error) { + ok(error instanceof TypeError, "Thrown error should be TypeError."); + hasThrown = true; + } +</script> + +<script type="module"> + ok(import.meta.resolve("simple") == + "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/module_simpleExport.js", + "calling import.meta.resolve with a specifier from import map."); + wasRun = true; +</script> + +<script type="module"> + // should throw a TypeError + import.meta.resolve("fail"); +</script> + +<script> + SimpleTest.waitForExplicitFinish(); + + function testLoaded() { + ok(wasRun, "Check inline module has run."); + ok(hasThrown, "Check inline module has thrown."); + SimpleTest.finish(); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_inline_module_reject_importMap.html b/dom/base/test/jsmodules/importmaps/test_inline_module_reject_importMap.html new file mode 100644 index 0000000000..2001cbcfb9 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_inline_module_reject_importMap.html @@ -0,0 +1,61 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test import map should be rejected.</title> +</head> +<body onload='testLoaded()'> +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +let gotMsg = false; +let console = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); +let listener = { + QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]), + observe(msg) { + info("console message:" + msg); + ok(msg.logLevel == Ci.nsIConsoleMessage.warn, "log level should be 'warn'."); + console.unregisterListener(this); + gotMsg = true; + } +}; +console.registerListener(listener); +</script> + +<!--There is an inline module before the import map tag, so the import map--> +<!--cannot be accepted according to the spec.--> +<!--And because the import map is rejected, so the module specifier--> +<!--"./module_simpleExport.js" won't be remapped to--> +<!--"./scope1/module_simpleExport.js".--> + +<script type="module"> +</script> + +<script type="importmap" onerror='importMapError()'> +{ + "imports": { + "./module_simpleExport.js": "./scope1/module_simpleExport.js" + } +} +</script> + +<script> + SimpleTest.waitForExplicitFinish(); + + let hasError = false; + function importMapError() { + hasError = true; + } + + function testLoaded() { + import("./module_simpleExport.js").then((ns) => { + ok(ns.x == 42, 'Check simple imported value result: ' + ns.x); + ok(hasError, "onerror of the import map should be called."); + ok(gotMsg, "Should have got the console warning."); + }).catch((e) => { + ok(false, "throws " + e); + }).then(() => { + SimpleTest.finish(); + }); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_load_importMap_with_base.html b/dom/base/test/jsmodules/importmaps/test_load_importMap_with_base.html new file mode 100644 index 0000000000..3139a60d37 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_load_importMap_with_base.html @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test a simple import map with a base element</title> +</head> +<body onload='testLoaded()'> + +<!-- This will change the baseURL of the document.--> +<base href="chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/"> + +<!-- +With the <base> element, the correct "module_simpleExport.js" should be mapped +to "scope1/module_simpleExport.js", instead of "./module_simpleExport.js". +--> + +<script type="importmap"> +{ + "imports": { + "simple": "./module_simpleExport.js" + } +} +</script> + +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script type="module"> + import { x } from "simple"; + result2 = x; +</script> + +<script type="module" src="module_simpleImportMap.js"></script> + +<script> + var result_scope1, result2; + + SimpleTest.waitForExplicitFinish(); + + function testLoaded() { + ok(result_scope1 == 84, 'Check imported value result_scope1: ' + result_scope1); + ok(result2 == 84, 'Check imported value result2: ' + result2); + + import("simple").then((ns) => { + ok(ns.x == 84, 'Check simple imported value result: ' + ns.x); + }).catch((e) => { + ok(false, "throws " + e); + }).then(() => { + SimpleTest.finish(); + }); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_load_importMap_with_base2.html b/dom/base/test/jsmodules/importmaps/test_load_importMap_with_base2.html new file mode 100644 index 0000000000..ed000512fd --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_load_importMap_with_base2.html @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test a simple import map with a script creates a base element</title> +</head> +<body onload='testLoaded()'> + +<!--This script will create a base element.--> +<script src="insert_a_base_element.js"></script> + +<!-- +With the <base> element, the correct "module_simpleExport.js" should be mapped +to "scope1/module_simpleExport.js", instead of "./module_simpleExport.js". +--> + +<script type="importmap"> +{ + "imports": { + "simple": "./module_simpleExport.js" + } +} +</script> + +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script type="module"> + import { x } from "simple"; + result2 = x; +</script> + +<script type="module" src="module_simpleImportMap.js"></script> + +<script> + var result_scope1, result2; + + SimpleTest.waitForExplicitFinish(); + + function testLoaded() { + ok(result_scope1 == 84, 'Check imported value result_scope1: ' + result_scope1); + ok(result2 == 84, 'Check imported value result2: ' + result2); + + import("simple").then((ns) => { + ok(ns.x == 84, 'Check simple imported value result: ' + ns.x); + }).catch((e) => { + ok(false, "throws " + e); + }).then(() => { + SimpleTest.finish(); + }); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_module_script_reject_importMap.html b/dom/base/test/jsmodules/importmaps/test_module_script_reject_importMap.html new file mode 100644 index 0000000000..bc73a60fc9 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_module_script_reject_importMap.html @@ -0,0 +1,45 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test import map should be rejected.</title> +</head> +<body onload='testLoaded()'> +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<!--There is a module load before the import map tag, so the import map cannot--> +<!--be accepted according to the spec.--> +<!--And because the import map is rejected, so the module specifier--> +<!--"./module_simpleExport.js" won't be remapped to--> +<!--"./scope1/module_simpleExport.js".--> + +<script src="./module_simpleExport.js" type="module"> +</script> + +<script type="importmap" onerror='importMapError()'> +{ + "imports": { + "./module_simpleExport.js": "./scope1/module_simpleExport.js" + } +} +</script> + +<script> + SimpleTest.waitForExplicitFinish(); + + let hasError = false; + function importMapError() { + hasError = true; + } + + function testLoaded() { + import("./module_simpleExport.js").then((ns) => { + ok(ns.x == 42, 'Check simple imported value result: ' + ns.x); + ok(hasError, "onerror of the import map should be called."); + }).catch((e) => { + ok(false, "throws " + e); + }).then(() => { + SimpleTest.finish(); + }); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_parse_importMap_failed.html b/dom/base/test/jsmodules/importmaps/test_parse_importMap_failed.html new file mode 100644 index 0000000000..b304acd943 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_parse_importMap_failed.html @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test the error message when parsing import maps failed</title> +</head> +<body onload='testLoaded()'> +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +let gotMsg = false; +window.onerror = function(event, src, lineno, colno, error) { + info("error: " + error.message); + ok(error instanceof SyntaxError, "error should be SyntaxError."); + ok(error.message.match(/import map/), + "error.message should contain 'import map'"); + gotMsg = true; +}; +</script> + +<!-- +An import map with invalid JSON format. A SyntaxError will be thrown when parsing +the import map. + --> +<script type="importmap" onerror='importMapError()'> +{ + "imports": {{ + "foo": "./foo.js" + } +} +</script> + +<script> + SimpleTest.waitForExplicitFinish(); + + function testLoaded() { + ok(gotMsg, "Should have thrown a SyntaxError."); + SimpleTest.finish(); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_reject_multiple_importMaps.html b/dom/base/test/jsmodules/importmaps/test_reject_multiple_importMaps.html new file mode 100644 index 0000000000..cc41163101 --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_reject_multiple_importMaps.html @@ -0,0 +1,64 @@ +<!DOCTYPE html> +<head> + <meta charset=utf-8> + <title>Test the 2nd import map should be rejected.</title> +</head> +<body onload='testLoaded()'> +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +let gotMsg = false; +let console = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); +let listener = { + QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]), + observe(msg) { + info("console message:" + msg); + ok(msg.logLevel == Ci.nsIConsoleMessage.warn, "log level should be 'warn'."); + console.unregisterListener(this); + gotMsg = true; + } +}; +console.registerListener(listener); +</script> + +<script type="importmap" onerror='importMapError1()'> +{ + "imports": { + "./module_simpleExport.js": "./scope1/module_simpleExport.js" + } +} +</script> + +<!--The 2nd import map should be rejected.--> +<script type="importmap" onerror='importMapError2()'> +{ + "imports": { + "./module_simpleExport.js": "./scope1/module_simpleExport.js" + } +} +</script> + +<script> + SimpleTest.waitForExplicitFinish(); + + let hasError = false; + function importMapError1() { + ok(false, "The first import map should be accepted."); + } + function importMapError2() { + hasError = true; + } + + function testLoaded() { + import("./module_simpleExport.js").then((ns) => { + ok(ns.x == 84, 'Check simple imported value result: ' + ns.x); + ok(hasError, "onerror of the import map should be called."); + ok(gotMsg, "Should have got the console warning."); + }).catch((e) => { + ok(false, "throws " + e); + }).then(() => { + SimpleTest.finish(); + }); + } +</script> +</body> diff --git a/dom/base/test/jsmodules/importmaps/test_simpleImportMap.html b/dom/base/test/jsmodules/importmaps/test_simpleImportMap.html new file mode 100644 index 0000000000..6a46ff770e --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_simpleImportMap.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Test a simple import map</title> +<script type="importmap"> +{ + "imports": { + "simple": "./module_simpleExport.js", + "dir/": "/content/chrome/dom/base/test/jsmodules/importmaps/", + "./module.js": "/content/chrome/dom/base/test/jsmodules/importmaps/module_simpleExport.js", + "https://example.com/module.js": "./module_simpleExport.js" + }, + "scopes": { + "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/": { + "simple": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/module_simpleExport.js" + }, + "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/": { + "simple": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleExport.js" + } + } +} +</script> + +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> + var result, result_dir, result_remap, result_remap_https; + var result_scope1, result_scope2; + + SimpleTest.waitForExplicitFinish(); + + function testLoaded() { + ok(result == 42, 'Check imported value result: ' + result); + ok(result_dir == 43, 'Check imported value result_dir: ' + result_dir); + ok(result_remap == 44, 'Check imported value result_remap: ' + result_remap); + ok(result_remap_https == 45, + 'Check imported value result_remap_https: ' + result_remap_https); + ok(result_scope1 == 84, 'Check imported value result_scope1: ' + result_scope1); + ok(result_scope2 == 126, 'Check imported value result_scope2: ' + result_scope2); + + import("simple").then((ns) => { + ok(ns.x == 42, 'Check simple imported value result: ' + ns.x); + return import("dir/module_simpleExport.js"); + }).then((ns) => { + ok(ns.x == 42, 'Check dir imported value result: ' + ns.x); + return import("./module.js"); + }).then((ns) => { + ok(ns.x == 42, 'Check remap imported value result: ' + ns.x); + return import("https://example.com/module.js"); + }).then((ns) => { + ok(ns.x == 42, 'Check remap https imported value result: ' + ns.x); + SimpleTest.finish(); + }); + } +</script> +<script type="module" src="module_simpleImportMap.js"></script> +<script type="module" src="module_simpleImportMap_dir.js"></script> +<script type="module" src="module_simpleImportMap_remap.js"></script> +<script type="module" src="module_simpleImportMap_remap_https.js"></script> +<script type="module" src="module_simpleImportMap_remap_https.js"></script> +<script type="module" src="scope1/module_simpleImportMap.js"></script> +<script type="module" src="scope1/scope2/module_simpleImportMap.js"></script> +<body onload='testLoaded()'></body> diff --git a/dom/base/test/jsmodules/importmaps/test_sortedImportMap.html b/dom/base/test/jsmodules/importmaps/test_sortedImportMap.html new file mode 100644 index 0000000000..17e4049d1a --- /dev/null +++ b/dom/base/test/jsmodules/importmaps/test_sortedImportMap.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Test a sorted import map</title> + +<!-- +According to Import maps spec, the entries in "imports" and "scopes" need to be +sorted. Key with longest prefix should be chosen. So "a/b/" should take +precendence over "a/". +This test is verifying that requirement. + +In "imports" below, "scope1/scope2/" and "scope1/scope2/scope3/scope4/" should +be chosen over "scope1" and "scope1/scope2/scop3/" respectively. +Also "scope1/scope2/" is listed _after_ "scope1/ and +"scope1/scope2/scope3/scope4" is listed _before_ "scope1/scope2/scope3/" to make +sure the map is sorted. + +For "scopes" below, the "scope1/" is listed before "scope1/scope2/" in +test_simpleImportMap.html, here we reverse the order, for example, we list +"scope1/" after "scope1/scope2/" in this test. + +See: +https://html.spec.whatwg.org/multipage/webappapis.html#sorting-and-normalizing-a-module-specifier-map, Step 3. +https://html.spec.whatwg.org/multipage/webappapis.html#sorting-and-normalizing-scopes, Step 3. +--> + +<script type="importmap"> +{ + "imports": { + "scope1/": "/content/chrome/dom/base/test/jsmodules/importmaps/", + "scope1/scope2/": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/", + "scope1/scope2/scope3/scope4/": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/", + "scope1/scope2/scope3/": "/content/chrome/dom/base/test/jsmodules/importmaps/" + }, + "scopes": { + "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/": { + "simple": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleExport.js" + }, + "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/": { + "simple": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/module_simpleExport.js" + } + } +} +</script> + +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> + var sorted_result, sorted_result2; + var result_scope2; + + SimpleTest.waitForExplicitFinish(); + + function testLoaded() { + ok(sorted_result == 126, 'Check imported value sorted_result: ' + sorted_result); + ok(sorted_result2 == 126, 'Check imported value sorted_result: ' + sorted_result2); + ok(result_scope2 == 126, 'Check imported value result_scope2: ' + result_scope2); + SimpleTest.finish(); + } +</script> +<script type="module" src="module_sortedImportMap.js"></script> +<script type="module" src="scope1/scope2/module_simpleImportMap.js"></script> +<body onload='testLoaded()'></body> |