Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
7 <script type="text/javascript;version=1.8" 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>
14 <script class="testbody" type="text/javascript;version=1.8">
15 SimpleTest.waitForExplicitFinish();
17 let expectedConsoleCalls = [];
19 function doConsoleCalls(aState)
20 {
21 let { ConsoleAPI } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
22 let console = new ConsoleAPI({
23 innerID: window.QueryInterface(Ci.nsIInterfaceRequestor)
24 .getInterface(Ci.nsIDOMWindowUtils)
25 .currentInnerWindowID
26 });
28 let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 2)).join("a");
30 console.log("foobarBaz-log", undefined);
31 console.info("foobarBaz-info", null);
32 console.warn("foobarBaz-warn", top.document.documentElement);
33 console.debug(null);
34 console.trace();
35 console.dir(top.document, top.location);
36 console.log("foo", longString);
38 expectedConsoleCalls = [
39 {
40 level: "log",
41 filename: /test_consoleapi/,
42 functionName: "doConsoleCalls",
43 timeStamp: /^\d+$/,
44 arguments: ["foobarBaz-log", { type: "undefined" }],
45 },
46 {
47 level: "info",
48 filename: /test_consoleapi/,
49 functionName: "doConsoleCalls",
50 timeStamp: /^\d+$/,
51 arguments: ["foobarBaz-info", { type: "null" }],
52 },
53 {
54 level: "warn",
55 filename: /test_consoleapi/,
56 functionName: "doConsoleCalls",
57 timeStamp: /^\d+$/,
58 arguments: ["foobarBaz-warn", { type: "object", actor: /[a-z]/ }],
59 },
60 {
61 level: "debug",
62 filename: /test_consoleapi/,
63 functionName: "doConsoleCalls",
64 timeStamp: /^\d+$/,
65 arguments: [{ type: "null" }],
66 },
67 {
68 level: "trace",
69 filename: /test_consoleapi/,
70 functionName: "doConsoleCalls",
71 timeStamp: /^\d+$/,
72 stacktrace: [
73 {
74 filename: /test_consoleapi/,
75 functionName: "doConsoleCalls",
76 },
77 {
78 filename: /test_consoleapi/,
79 functionName: "onAttach",
80 },
81 ],
82 },
83 {
84 level: "dir",
85 filename: /test_consoleapi/,
86 functionName: "doConsoleCalls",
87 timeStamp: /^\d+$/,
88 arguments: [
89 {
90 type: "object",
91 actor: /[a-z]/,
92 class: "XULDocument",
93 },
94 {
95 type: "object",
96 actor: /[a-z]/,
97 class: "Location",
98 }
99 ],
100 },
101 {
102 level: "log",
103 filename: /test_consoleapi/,
104 functionName: "doConsoleCalls",
105 timeStamp: /^\d+$/,
106 arguments: [
107 "foo",
108 {
109 type: "longString",
110 initial: longString.substring(0,
111 DebuggerServer.LONG_STRING_INITIAL_LENGTH),
112 length: longString.length,
113 actor: /[a-z]/,
114 },
115 ],
116 },
117 ];
118 }
120 function startTest()
121 {
122 removeEventListener("load", startTest);
124 attachConsole(["ConsoleAPI"], onAttach, true);
125 }
127 function onAttach(aState, aResponse)
128 {
129 onConsoleAPICall = onConsoleAPICall.bind(null, aState);
130 aState.dbgClient.addListener("consoleAPICall", onConsoleAPICall);
131 doConsoleCalls(aState.actor);
132 }
134 let consoleCalls = [];
136 function onConsoleAPICall(aState, aType, aPacket)
137 {
138 info("received message level: " + aPacket.message.level);
139 is(aPacket.from, aState.actor, "console API call actor");
141 consoleCalls.push(aPacket.message);
142 if (consoleCalls.length != expectedConsoleCalls.length) {
143 return;
144 }
146 aState.dbgClient.removeListener("consoleAPICall", onConsoleAPICall);
148 expectedConsoleCalls.forEach(function(aMessage, aIndex) {
149 info("checking received console call #" + aIndex);
150 checkConsoleAPICall(consoleCalls[aIndex], expectedConsoleCalls[aIndex]);
151 });
154 consoleCalls = [];
156 closeDebugger(aState, function() {
157 SimpleTest.finish();
158 });
159 }
161 addEventListener("load", startTest);
162 </script>
163 </body>
164 </html>