summaryrefslogtreecommitdiffstats
path: root/dom/base/test/jsmodules/importmaps/test_externalImportMap.html
blob: 1345f61947592a6b39d1d40d8df6a0b62ccc4da3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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>