Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<head>
<meta charset=utf-8>
<title>Test import map should be rejected.</title>
</head>
<body onload='testLoaded()'>
<!--Note: This test should be replaced by-->
<!--test_importMap_after_module_load.html when the pref-->
<!--"dom.multiple_import_maps.enabled" is turned on.-->
<!--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.mjs" won't be remapped to-->
<!--"./scope1/module_simpleExport.mjs".-->
<script src="./module_simpleExport.mjs" type="module"> </script>
<script type="importmap" onerror='importMapError()'>
{
"imports": {
"./module_simpleExport.mjs": "./scope1/module_simpleExport.mjs"
}
}
</script>
<script>
SimpleTest.waitForExplicitFinish();
let hasError = false;
// eslint-disable-next-line no-unused-vars
function importMapError() {
hasError = true;
}
// If the multiple import maps is supported, the import map will be accepted,
// otherwise it is ignored.
const pref = SpecialPowers.getBoolPref("dom.multiple_import_maps.enabled");
const expectedValue = pref ? 84 : 42;
const onerrorExpected = !pref;
const msgExpected = !pref;
// eslint-disable-next-line no-unused-vars
function testLoaded() {
import("./module_simpleExport.mjs").then((ns) => {
ok(ns.x == expectedValue, 'Check simple imported value result: ' + ns.x);
ok(hasError == onerrorExpected, "onerror of the import map should be called.");
}).catch((e) => {
ok(false, "throws " + e);
}).then(() => {
SimpleTest.finish();
});
}
</script>
</body>