test_externalImportMap.html (1611B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Test an external import map</title> 4 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 5 6 <script> 7 // eslint-disable-next-line no-unused-vars 8 let gotMsg = false; 9 let console = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); 10 let listener = { 11 QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]), 12 observe(msg) { 13 info("console message:" + msg); 14 ok(msg.logLevel == Ci.nsIConsoleMessage.warn, "log level should be 'warn'."); 15 // The message will be localized, so we just test the strings won't be 16 // localized. 17 ok(msg.message.match(/<script type='importmap'>.*src/), 18 "The error message should contain \"<script type='importmap'>\""); 19 console.unregisterListener(this); 20 gotMsg = true; 21 } 22 }; 23 console.registerListener(listener); 24 </script> 25 26 <!--Import maps spec doesn't clearly define the format of an external import map script.--> 27 <script src="external_importMap.js" type="importmap" onload="scriptLoaded()" onerror="scriptError()"></script> 28 29 <script> 30 // eslint-disable-next-line no-unused-vars 31 function testLoaded() { 32 SimpleTest.waitForExplicitFinish(); 33 /* global gotMsg */ 34 ok(gotMsg, "Should have got the console warning."); 35 SimpleTest.finish(); 36 } 37 38 // eslint-disable-next-line no-unused-vars 39 function scriptLoaded() { 40 ok(false, "Loading external import map script should have failed."); 41 } 42 43 // eslint-disable-next-line no-unused-vars 44 function scriptError() { 45 ok(true, "Loading external import map script failed."); 46 } 47 </script> 48 <body onload='testLoaded()'></body>