|
1 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
2 /* |
|
3 * Any copyright is dedicated to the Public Domain. |
|
4 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
5 */ |
|
6 |
|
7 // Tests that the Web Console limits the number of lines displayed according to |
|
8 // the limit set for each category. |
|
9 |
|
10 const TEST_URI = "http://example.com/browser/browser/devtools/" + |
|
11 "webconsole/test/test-bug-644419-log-limits.html"; |
|
12 |
|
13 let hud, outputNode; |
|
14 |
|
15 function test() { |
|
16 addTab("data:text/html;charset=utf-8,Web Console test for bug 644419: Console should " + |
|
17 "have user-settable log limits for each message category"); |
|
18 browser.addEventListener("load", onLoad, true); |
|
19 } |
|
20 |
|
21 function onLoad(aEvent) { |
|
22 browser.removeEventListener(aEvent.type, onLoad, true); |
|
23 |
|
24 openConsole(null, function(aHud) { |
|
25 aHud.jsterm.clearOutput(); |
|
26 hud = aHud; |
|
27 outputNode = aHud.outputNode; |
|
28 |
|
29 browser.addEventListener("load", testWebDevLimits, true); |
|
30 expectUncaughtException(); |
|
31 content.location = TEST_URI; |
|
32 }); |
|
33 } |
|
34 |
|
35 function testWebDevLimits(aEvent) { |
|
36 browser.removeEventListener(aEvent.type, testWebDevLimits, true); |
|
37 Services.prefs.setIntPref("devtools.hud.loglimit.console", 10); |
|
38 |
|
39 // Find the sentinel entry. |
|
40 waitForMessages({ |
|
41 webconsole: hud, |
|
42 messages: [{ |
|
43 text: "bar is not defined", |
|
44 category: CATEGORY_JS, |
|
45 severity: SEVERITY_ERROR, |
|
46 }], |
|
47 }).then(testWebDevLimits2); |
|
48 } |
|
49 |
|
50 function testWebDevLimits2() { |
|
51 // Fill the log with Web Developer errors. |
|
52 for (let i = 0; i < 11; i++) { |
|
53 content.console.log("test message " + i); |
|
54 } |
|
55 |
|
56 waitForMessages({ |
|
57 webconsole: hud, |
|
58 messages: [{ |
|
59 text: "test message 10", |
|
60 category: CATEGORY_WEBDEV, |
|
61 severity: SEVERITY_LOG, |
|
62 }], |
|
63 }).then(() => { |
|
64 testLogEntry(outputNode, "test message 0", "first message is pruned", false, true); |
|
65 findLogEntry("test message 1"); |
|
66 // Check if the sentinel entry is still there. |
|
67 findLogEntry("bar is not defined"); |
|
68 |
|
69 Services.prefs.clearUserPref("devtools.hud.loglimit.console"); |
|
70 testJsLimits(); |
|
71 }); |
|
72 } |
|
73 |
|
74 function testJsLimits() { |
|
75 Services.prefs.setIntPref("devtools.hud.loglimit.exception", 10); |
|
76 |
|
77 hud.jsterm.clearOutput(); |
|
78 content.console.log("testing JS limits"); |
|
79 |
|
80 // Find the sentinel entry. |
|
81 waitForMessages({ |
|
82 webconsole: hud, |
|
83 messages: [{ |
|
84 text: "testing JS limits", |
|
85 category: CATEGORY_WEBDEV, |
|
86 severity: SEVERITY_LOG, |
|
87 }], |
|
88 }).then(testJsLimits2); |
|
89 } |
|
90 |
|
91 function testJsLimits2() { |
|
92 // Fill the log with JS errors. |
|
93 let head = content.document.getElementsByTagName("head")[0]; |
|
94 for (let i = 0; i < 11; i++) { |
|
95 var script = content.document.createElement("script"); |
|
96 script.text = "fubar" + i + ".bogus(6);"; |
|
97 expectUncaughtException(); |
|
98 head.insertBefore(script, head.firstChild); |
|
99 } |
|
100 |
|
101 waitForMessages({ |
|
102 webconsole: hud, |
|
103 messages: [{ |
|
104 text: "fubar10 is not defined", |
|
105 category: CATEGORY_JS, |
|
106 severity: SEVERITY_ERROR, |
|
107 }], |
|
108 }).then(() => { |
|
109 testLogEntry(outputNode, "fubar0 is not defined", "first message is pruned", false, true); |
|
110 findLogEntry("fubar1 is not defined"); |
|
111 // Check if the sentinel entry is still there. |
|
112 findLogEntry("testing JS limits"); |
|
113 |
|
114 Services.prefs.clearUserPref("devtools.hud.loglimit.exception"); |
|
115 testNetLimits(); |
|
116 }); |
|
117 } |
|
118 |
|
119 var gCounter, gImage; |
|
120 |
|
121 function testNetLimits() { |
|
122 Services.prefs.setIntPref("devtools.hud.loglimit.network", 10); |
|
123 |
|
124 hud.jsterm.clearOutput(); |
|
125 content.console.log("testing Net limits"); |
|
126 |
|
127 // Find the sentinel entry. |
|
128 waitForMessages({ |
|
129 webconsole: hud, |
|
130 messages: [{ |
|
131 text: "testing Net limits", |
|
132 category: CATEGORY_WEBDEV, |
|
133 severity: SEVERITY_LOG, |
|
134 }], |
|
135 }).then(() => { |
|
136 // Fill the log with network messages. |
|
137 gCounter = 0; |
|
138 loadImage(); |
|
139 }); |
|
140 } |
|
141 |
|
142 function loadImage() { |
|
143 if (gCounter < 11) { |
|
144 let body = content.document.getElementsByTagName("body")[0]; |
|
145 gImage && gImage.removeEventListener("load", loadImage, true); |
|
146 gImage = content.document.createElement("img"); |
|
147 gImage.src = "test-image.png?_fubar=" + gCounter; |
|
148 body.insertBefore(gImage, body.firstChild); |
|
149 gImage.addEventListener("load", loadImage, true); |
|
150 gCounter++; |
|
151 return; |
|
152 } |
|
153 |
|
154 is(gCounter, 11, "loaded 11 files"); |
|
155 |
|
156 waitForMessages({ |
|
157 webconsole: hud, |
|
158 messages: [{ |
|
159 text: "test-image.png", |
|
160 url: "test-image.png?_fubar=10", |
|
161 category: CATEGORY_NETWORK, |
|
162 severity: SEVERITY_LOG, |
|
163 }], |
|
164 }).then(() => { |
|
165 let msgs = outputNode.querySelectorAll(".message[category=network]"); |
|
166 is(msgs.length, 10, "number of network messages"); |
|
167 isnot(msgs[0].url.indexOf("fubar=1"), -1, "first network message"); |
|
168 isnot(msgs[1].url.indexOf("fubar=2"), -1, "second network message"); |
|
169 findLogEntry("testing Net limits"); |
|
170 |
|
171 Services.prefs.clearUserPref("devtools.hud.loglimit.network"); |
|
172 testCssLimits(); |
|
173 }); |
|
174 } |
|
175 |
|
176 function testCssLimits() { |
|
177 Services.prefs.setIntPref("devtools.hud.loglimit.cssparser", 10); |
|
178 |
|
179 hud.jsterm.clearOutput(); |
|
180 content.console.log("testing CSS limits"); |
|
181 |
|
182 // Find the sentinel entry. |
|
183 waitForMessages({ |
|
184 webconsole: hud, |
|
185 messages: [{ |
|
186 text: "testing CSS limits", |
|
187 category: CATEGORY_WEBDEV, |
|
188 severity: SEVERITY_LOG, |
|
189 }], |
|
190 }).then(testCssLimits2); |
|
191 } |
|
192 |
|
193 function testCssLimits2() { |
|
194 // Fill the log with CSS errors. |
|
195 let body = content.document.getElementsByTagName("body")[0]; |
|
196 for (let i = 0; i < 11; i++) { |
|
197 var div = content.document.createElement("div"); |
|
198 div.setAttribute("style", "-moz-foobar" + i + ": 42;"); |
|
199 body.insertBefore(div, body.firstChild); |
|
200 } |
|
201 |
|
202 waitForMessages({ |
|
203 webconsole: hud, |
|
204 messages: [{ |
|
205 text: "-moz-foobar10", |
|
206 category: CATEGORY_CSS, |
|
207 severity: SEVERITY_WARNING, |
|
208 }], |
|
209 }).then(() => { |
|
210 testLogEntry(outputNode, "Unknown property '-moz-foobar0'", |
|
211 "first message is pruned", false, true); |
|
212 findLogEntry("Unknown property '-moz-foobar1'"); |
|
213 // Check if the sentinel entry is still there. |
|
214 findLogEntry("testing CSS limits"); |
|
215 |
|
216 Services.prefs.clearUserPref("devtools.hud.loglimit.cssparser"); |
|
217 finishTest(); |
|
218 }); |
|
219 } |