|
1 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
2 /* ***** BEGIN LICENSE BLOCK ***** |
|
3 * Any copyright is dedicated to the Public Domain. |
|
4 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
5 * |
|
6 * Contributor(s): |
|
7 * Patrick Walton <pcwalton@mozilla.com> |
|
8 * Mihai Șucan <mihai.sucan@gmail.com> |
|
9 * |
|
10 * ***** END LICENSE BLOCK ***** */ |
|
11 |
|
12 // Tests that the Web Console limits the number of lines displayed according to |
|
13 // the user's preferences. |
|
14 |
|
15 const TEST_URI = "data:text/html;charset=utf8,test for bug 585237"; |
|
16 let hud, testDriver; |
|
17 |
|
18 function test() { |
|
19 addTab(TEST_URI); |
|
20 browser.addEventListener("load", function onLoad() { |
|
21 browser.removeEventListener("load", onLoad, true); |
|
22 openConsole(null, function(aHud) { |
|
23 hud = aHud; |
|
24 testDriver = testGen(); |
|
25 testNext(); |
|
26 }); |
|
27 }, true); |
|
28 } |
|
29 |
|
30 function testNext() { |
|
31 testDriver.next(); |
|
32 } |
|
33 |
|
34 function testGen() { |
|
35 let console = content.console; |
|
36 outputNode = hud.outputNode; |
|
37 |
|
38 hud.jsterm.clearOutput(); |
|
39 |
|
40 let prefBranch = Services.prefs.getBranch("devtools.hud.loglimit."); |
|
41 prefBranch.setIntPref("console", 20); |
|
42 |
|
43 for (let i = 0; i < 30; i++) { |
|
44 console.log("foo #" + i); // must change message to prevent repeats |
|
45 } |
|
46 |
|
47 waitForMessages({ |
|
48 webconsole: hud, |
|
49 messages: [{ |
|
50 text: "foo #29", |
|
51 category: CATEGORY_WEBDEV, |
|
52 severity: SEVERITY_LOG, |
|
53 }], |
|
54 }).then(testNext); |
|
55 |
|
56 yield undefined; |
|
57 |
|
58 is(countMessageNodes(), 20, "there are 20 message nodes in the output " + |
|
59 "when the log limit is set to 20"); |
|
60 |
|
61 console.log("bar bug585237"); |
|
62 |
|
63 waitForMessages({ |
|
64 webconsole: hud, |
|
65 messages: [{ |
|
66 text: "bar bug585237", |
|
67 category: CATEGORY_WEBDEV, |
|
68 severity: SEVERITY_LOG, |
|
69 }], |
|
70 }).then(testNext); |
|
71 |
|
72 yield undefined; |
|
73 |
|
74 is(countMessageNodes(), 20, "there are still 20 message nodes in the " + |
|
75 "output when adding one more"); |
|
76 |
|
77 prefBranch.setIntPref("console", 30); |
|
78 for (let i = 0; i < 20; i++) { |
|
79 console.log("boo #" + i); // must change message to prevent repeats |
|
80 } |
|
81 |
|
82 waitForMessages({ |
|
83 webconsole: hud, |
|
84 messages: [{ |
|
85 text: "boo #19", |
|
86 category: CATEGORY_WEBDEV, |
|
87 severity: SEVERITY_LOG, |
|
88 }], |
|
89 }).then(testNext); |
|
90 |
|
91 yield undefined; |
|
92 |
|
93 is(countMessageNodes(), 30, "there are 30 message nodes in the output " + |
|
94 "when the log limit is set to 30"); |
|
95 |
|
96 prefBranch.clearUserPref("console"); |
|
97 hud = testDriver = prefBranch = console = outputNode = null; |
|
98 finishTest(); |
|
99 |
|
100 yield undefined; |
|
101 } |
|
102 |
|
103 function countMessageNodes() { |
|
104 return outputNode.querySelectorAll(".message").length; |
|
105 } |
|
106 |