test_consoleapi_innerID.html (3784B)
1 <!DOCTYPE HTML> 2 <html lang="en"> 3 <head> 4 <meta charset="utf8"> 5 <title>Test for the innerID property of the Console API</title> 6 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 7 <script type="text/javascript" src="common.js"></script> 8 <!-- Any copyright is dedicated to the Public Domain. 9 - http://creativecommons.org/publicdomain/zero/1.0/ --> 10 </head> 11 <body> 12 <p>Test for the Console API</p> 13 14 <script class="testbody" type="text/javascript"> 15 "use strict"; 16 17 SimpleTest.waitForExplicitFinish(); 18 19 let expectedConsoleCalls = []; 20 21 function doConsoleCalls() 22 { 23 const { ConsoleAPI } = ChromeUtils.importESModule( 24 "resource://gre/modules/Console.sys.mjs" 25 ); 26 const console = new ConsoleAPI({ 27 innerID: window.top.windowGlobalChild.innerWindowId 28 }); 29 30 const longString = (new Array(DevToolsServer.LONG_STRING_LENGTH + 2)).join("a"); 31 32 console.log("foobarBaz-log", undefined); 33 console.info("foobarBaz-info", null); 34 console.warn("foobarBaz-warn", top.document.documentElement); 35 console.debug(null); 36 console.trace(); 37 console.dir(top.document, top.location); 38 console.log("foo", longString); 39 40 expectedConsoleCalls = [ 41 { 42 level: "log", 43 filename: /test_consoleapi/, 44 timeStamp: /^\d+$/, 45 arguments: ["foobarBaz-log", { type: "undefined" }], 46 }, 47 { 48 level: "info", 49 filename: /test_consoleapi/, 50 timeStamp: /^\d+$/, 51 arguments: ["foobarBaz-info", { type: "null" }], 52 }, 53 { 54 level: "warn", 55 filename: /test_consoleapi/, 56 timeStamp: /^\d+$/, 57 arguments: ["foobarBaz-warn", { type: "object", actor: /[a-z]/ }], 58 }, 59 { 60 level: "debug", 61 filename: /test_consoleapi/, 62 timeStamp: /^\d+$/, 63 arguments: [{ type: "null" }], 64 }, 65 { 66 level: "trace", 67 filename: /test_consoleapi/, 68 timeStamp: /^\d+$/, 69 stacktrace: [ 70 { 71 filename: /test_consoleapi/, 72 functionName: "doConsoleCalls", 73 }, 74 { 75 filename: /test_consoleapi/, 76 functionName: "onAttach", 77 }, 78 ], 79 }, 80 { 81 level: "dir", 82 filename: /test_consoleapi/, 83 timeStamp: /^\d+$/, 84 arguments: [ 85 { 86 type: "object", 87 actor: /[a-z]/, 88 class: "HTMLDocument", 89 }, 90 { 91 type: "object", 92 actor: /[a-z]/, 93 class: "Location", 94 } 95 ], 96 }, 97 { 98 level: "log", 99 filename: /test_consoleapi/, 100 timeStamp: /^\d+$/, 101 arguments: [ 102 "foo", 103 { 104 type: "longString", 105 initial: longString.substring(0, 106 DevToolsServer.LONG_STRING_INITIAL_LENGTH), 107 length: longString.length, 108 actor: /[a-z]/, 109 }, 110 ], 111 }, 112 ]; 113 } 114 115 async function startTest() 116 { 117 removeEventListener("load", startTest); 118 119 const {state} = await attachConsoleToTab(["ConsoleAPI"]); 120 onAttach(state); 121 } 122 123 function onAttach(state) 124 { 125 onConsoleAPICall = onConsoleAPICall.bind(null, state); 126 state.webConsoleFront.on("consoleAPICall", onConsoleAPICall); 127 doConsoleCalls(state.actor); 128 } 129 130 let consoleCalls = []; 131 132 function onConsoleAPICall(state, packet) 133 { 134 info("received message level: " + packet.message.level); 135 136 consoleCalls.push(packet.message); 137 if (consoleCalls.length != expectedConsoleCalls.length) { 138 return; 139 } 140 141 state.webConsoleFront.off("consoleAPICall", onConsoleAPICall); 142 143 expectedConsoleCalls.forEach(function(message, index) { 144 info("checking received console call #" + index); 145 checkConsoleAPICall(consoleCalls[index], expectedConsoleCalls[index]); 146 }); 147 148 149 consoleCalls = []; 150 151 closeDebugger(state, function() { 152 SimpleTest.finish(); 153 }); 154 } 155 156 addEventListener("load", startTest); 157 </script> 158 </body> 159 </html>