test_jsm.xhtml (3673B)
1 <?xml version="1.0"?> 2 <!-- 3 Any copyright is dedicated to the Public Domain. 4 http://creativecommons.org/publicdomain/zero/1.0/ 5 --> 6 <window title="Console + MJS" 7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 8 onload="test();"> 9 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 11 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 12 <script src="head.js"/> 13 14 <script type="application/javascript"> 15 <![CDATA[ 16 17 const MJS = "chrome://mochitests/content/chrome/dom/console/tests/console.sys.mjs"; 18 19 let dumpCalled = 0; 20 function dumpFunction(msg) { 21 ok(msg.includes("_PREFIX_"), "we have a prefix"); 22 dump("Message received: " + msg); // Just for debugging 23 dumpCalled++; 24 } 25 26 function promiseConsoleListenerCalled() { 27 return new Promise(resolve => { 28 let consoleListener = { 29 count: 0, 30 31 observe(aSubject) { 32 var obj = aSubject.wrappedJSObject; 33 ok(obj.chromeContext, "MJS is always a chrome context"); 34 35 if (obj.innerID == MJS) { 36 is(obj.ID, "jsm", "ID and InnerID are correctly set."); 37 is(obj.arguments[0], "Hello world!", "Message matches"); 38 is(obj.consoleID, "", "No consoleID for console API"); 39 is(obj.prefix, "", "prefix is empty by default"); 40 41 // We want to see 2 messages from this innerID, the first is generated 42 // by console.log, the second one from createInstance().log(); 43 ++this.count; 44 } else if (obj.innerID == "CUSTOM INNER") { 45 is(obj.ID, "jsm", "ID and InnerID are correctly set."); 46 is(obj.arguments[0], "Hello world!", "Message matches"); 47 is(obj.consoleID, "wow", "consoleID is set by consoleInstance"); 48 is(obj.prefix, "_PREFIX_", "prefix is set by consoleInstance"); 49 // We expect to see 2 messages from this innerID. 50 ++this.count; 51 } else if (obj.innerID == "LEVEL") { 52 // Nothing special... just we don't want to see 'invisible' messages. 53 is(obj.ID, "jsm", "ID and InnerID are correctly set."); 54 is(obj.arguments[0], "Hello world!", "Message matches"); 55 is(obj.prefix, "", "prefix is empty by default"); 56 // We expect to see 2 messages from this innerID. 57 ++this.count; 58 } else if (obj.innerID == "NO PREF") { 59 // Nothing special... just we don't want to see 'invisible' messages. 60 is(obj.ID, "jsm", "ID and InnerID are correctly set."); 61 is(obj.arguments[0], "Hello world!", "Message matches"); 62 is(obj.prefix, "", "prefix is empty by default"); 63 // We expect to see 2 messages from this innerID. 64 ++this.count; 65 } 66 67 if (this.count == 8) { 68 is(dumpCalled, 2, "Dump has been called!"); 69 removeConsoleStorageListener(consoleListener); 70 resolve(); 71 } 72 } 73 } 74 addConsoleStorageListener(consoleListener); 75 }); 76 } 77 78 async function test() { 79 SimpleTest.waitForExplicitFinish(); 80 81 let consolePromise = promiseConsoleListenerCalled(); 82 let { ConsoleTest } = ChromeUtils.importESModule(MJS); 83 await SpecialPowers.pushPrefEnv({set: [["pref.test.console", "log"]]}) 84 ConsoleTest.go(dumpFunction); 85 86 // ConsoleTest.go() has already tested the console without this preference. 87 // This test checks that the addition of the preference is tracked and 88 // correctly applied. 89 await SpecialPowers.pushPrefEnv({ 90 set: [["pref.test.console.notset", "Log"]], 91 }); 92 ConsoleTest.go2(); 93 94 await consolePromise; 95 SimpleTest.finish(); 96 } 97 98 ]]> 99 </script> 100 101 <body xmlns="http://www.w3.org/1999/xhtml"> 102 </body> 103 </window>