Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test an external import map</title>
<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'.");
    // 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>
// eslint-disable-next-line no-unused-vars
function testLoaded() {
  SimpleTest.waitForExplicitFinish();
  /* global gotMsg */
  ok(gotMsg, "Should have got the console warning.");
  SimpleTest.finish();
}
// eslint-disable-next-line no-unused-vars
function scriptLoaded() {
  ok(false, "Loading external import map script should have failed.");
}
// eslint-disable-next-line no-unused-vars
function scriptError() {
  ok(true, "Loading external import map script failed.");
}
</script>
<body onload='testLoaded()'></body>