Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!DOCTYPE html>
<head>
  <meta charset=utf-8>
  <title>Test the 2nd import map should be rejected.</title>
</head>
<body onload='testLoaded()'>
<script>
// eslint-disable-next-line no-unused-vars
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.mjs": "./scope1/module_simpleExport.mjs"
  }
}
</script>
<!--The 2nd import map should be rejected.-->
<script type="importmap" onerror='importMapError2()'>
{
  "imports": {
    "./module_simpleExport.mjs": "./scope1/module_simpleExport.mjs"
  }
}
</script>
<script>
  /* global gotMsg */
  SimpleTest.waitForExplicitFinish();
  let hasError = false;
  // eslint-disable-next-line no-unused-vars
  function importMapError1() {
    ok(false, "The first import map should be accepted.");
  }
  // eslint-disable-next-line no-unused-vars
  function importMapError2() {
    hasError = true;
  }
  // eslint-disable-next-line no-unused-vars
  function testLoaded() {
    import("./module_simpleExport.mjs").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>