|
1 <!DOCTYPE HTML> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="utf8"> |
|
5 <title>Test for 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> |
|
13 |
|
14 <script class="testbody" type="text/javascript;version=1.8"> |
|
15 SimpleTest.waitForExplicitFinish(); |
|
16 |
|
17 let expectedConsoleCalls = []; |
|
18 |
|
19 function doConsoleCalls(aState) |
|
20 { |
|
21 let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 2)).join("a"); |
|
22 |
|
23 top.console.log("foobarBaz-log", undefined); |
|
24 top.console.info("foobarBaz-info", null); |
|
25 top.console.warn("foobarBaz-warn", top.document.documentElement); |
|
26 top.console.debug(null); |
|
27 top.console.trace(); |
|
28 top.console.dir(top.document, top.location); |
|
29 top.console.log("foo", longString); |
|
30 |
|
31 expectedConsoleCalls = [ |
|
32 { |
|
33 level: "log", |
|
34 filename: /test_consoleapi/, |
|
35 functionName: "doConsoleCalls", |
|
36 timeStamp: /^\d+$/, |
|
37 arguments: ["foobarBaz-log", { type: "undefined" }], |
|
38 }, |
|
39 { |
|
40 level: "info", |
|
41 filename: /test_consoleapi/, |
|
42 functionName: "doConsoleCalls", |
|
43 timeStamp: /^\d+$/, |
|
44 arguments: ["foobarBaz-info", { type: "null" }], |
|
45 }, |
|
46 { |
|
47 level: "warn", |
|
48 filename: /test_consoleapi/, |
|
49 functionName: "doConsoleCalls", |
|
50 timeStamp: /^\d+$/, |
|
51 arguments: ["foobarBaz-warn", { type: "object", actor: /[a-z]/ }], |
|
52 }, |
|
53 { |
|
54 level: "debug", |
|
55 filename: /test_consoleapi/, |
|
56 functionName: "doConsoleCalls", |
|
57 timeStamp: /^\d+$/, |
|
58 arguments: [{ type: "null" }], |
|
59 }, |
|
60 { |
|
61 level: "trace", |
|
62 filename: /test_consoleapi/, |
|
63 functionName: "doConsoleCalls", |
|
64 timeStamp: /^\d+$/, |
|
65 stacktrace: [ |
|
66 { |
|
67 filename: /test_consoleapi/, |
|
68 functionName: "doConsoleCalls", |
|
69 }, |
|
70 { |
|
71 filename: /test_consoleapi/, |
|
72 functionName: "onAttach", |
|
73 }, |
|
74 ], |
|
75 }, |
|
76 { |
|
77 level: "dir", |
|
78 filename: /test_consoleapi/, |
|
79 functionName: "doConsoleCalls", |
|
80 timeStamp: /^\d+$/, |
|
81 arguments: [ |
|
82 { |
|
83 type: "object", |
|
84 actor: /[a-z]/, |
|
85 class: "XULDocument", |
|
86 }, |
|
87 { |
|
88 type: "object", |
|
89 actor: /[a-z]/, |
|
90 class: "Location", |
|
91 } |
|
92 ], |
|
93 }, |
|
94 { |
|
95 level: "log", |
|
96 filename: /test_consoleapi/, |
|
97 functionName: "doConsoleCalls", |
|
98 timeStamp: /^\d+$/, |
|
99 arguments: [ |
|
100 "foo", |
|
101 { |
|
102 type: "longString", |
|
103 initial: longString.substring(0, |
|
104 DebuggerServer.LONG_STRING_INITIAL_LENGTH), |
|
105 length: longString.length, |
|
106 actor: /[a-z]/, |
|
107 }, |
|
108 ], |
|
109 }, |
|
110 ]; |
|
111 } |
|
112 |
|
113 function startTest() |
|
114 { |
|
115 removeEventListener("load", startTest); |
|
116 |
|
117 attachConsole(["ConsoleAPI"], onAttach, true); |
|
118 } |
|
119 |
|
120 function onAttach(aState, aResponse) |
|
121 { |
|
122 onConsoleAPICall = onConsoleAPICall.bind(null, aState); |
|
123 aState.dbgClient.addListener("consoleAPICall", onConsoleAPICall); |
|
124 doConsoleCalls(aState.actor); |
|
125 } |
|
126 |
|
127 let consoleCalls = []; |
|
128 |
|
129 function onConsoleAPICall(aState, aType, aPacket) |
|
130 { |
|
131 info("received message level: " + aPacket.message.level); |
|
132 is(aPacket.from, aState.actor, "console API call actor"); |
|
133 |
|
134 consoleCalls.push(aPacket.message); |
|
135 if (consoleCalls.length != expectedConsoleCalls.length) { |
|
136 return; |
|
137 } |
|
138 |
|
139 aState.dbgClient.removeListener("consoleAPICall", onConsoleAPICall); |
|
140 |
|
141 expectedConsoleCalls.forEach(function(aMessage, aIndex) { |
|
142 info("checking received console call #" + aIndex); |
|
143 checkConsoleAPICall(consoleCalls[aIndex], expectedConsoleCalls[aIndex]); |
|
144 }); |
|
145 |
|
146 |
|
147 consoleCalls = []; |
|
148 |
|
149 closeDebugger(aState, function() { |
|
150 SimpleTest.finish(); |
|
151 }); |
|
152 } |
|
153 |
|
154 addEventListener("load", startTest); |
|
155 </script> |
|
156 </body> |
|
157 </html> |