|
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 * Contributor(s): |
|
7 * Mihai Șucan <mihai.sucan@gmail.com> |
|
8 */ |
|
9 |
|
10 let hud, testDriver; |
|
11 |
|
12 function testNext() { |
|
13 testDriver.next(); |
|
14 } |
|
15 |
|
16 function testGen() { |
|
17 hud.jsterm.clearOutput(); |
|
18 |
|
19 let outputNode = hud.outputNode; |
|
20 |
|
21 Services.prefs.setIntPref("devtools.hud.loglimit.console", 140); |
|
22 let scrollBoxElement = outputNode.parentNode; |
|
23 |
|
24 for (let i = 0; i < 150; i++) { |
|
25 content.console.log("test message " + i); |
|
26 } |
|
27 |
|
28 waitForMessages({ |
|
29 webconsole: hud, |
|
30 messages: [{ |
|
31 text: "test message 149", |
|
32 category: CATEGORY_WEBDEV, |
|
33 severity: SEVERITY_LOG, |
|
34 }], |
|
35 }).then(testNext); |
|
36 |
|
37 yield undefined; |
|
38 |
|
39 let oldScrollTop = scrollBoxElement.scrollTop; |
|
40 isnot(oldScrollTop, 0, "scroll location is not at the top"); |
|
41 |
|
42 let firstNode = outputNode.firstChild; |
|
43 ok(firstNode, "found the first message"); |
|
44 |
|
45 let msgNode = outputNode.children[80]; |
|
46 ok(msgNode, "found the 80th message"); |
|
47 |
|
48 // scroll to the middle message node |
|
49 msgNode.scrollIntoView(false); |
|
50 |
|
51 isnot(scrollBoxElement.scrollTop, oldScrollTop, |
|
52 "scroll location updated (scrolled to message)"); |
|
53 |
|
54 oldScrollTop = scrollBoxElement.scrollTop; |
|
55 |
|
56 // add a message |
|
57 content.console.log("hello world"); |
|
58 |
|
59 waitForMessages({ |
|
60 webconsole: hud, |
|
61 messages: [{ |
|
62 text: "hello world", |
|
63 category: CATEGORY_WEBDEV, |
|
64 severity: SEVERITY_LOG, |
|
65 }], |
|
66 }).then(testNext); |
|
67 |
|
68 yield undefined; |
|
69 |
|
70 // Scroll location needs to change, because one message is also removed, and |
|
71 // we need to scroll a bit towards the top, to keep the current view in sync. |
|
72 isnot(scrollBoxElement.scrollTop, oldScrollTop, |
|
73 "scroll location updated (added a message)"); |
|
74 |
|
75 isnot(outputNode.firstChild, firstNode, |
|
76 "first message removed"); |
|
77 |
|
78 Services.prefs.clearUserPref("devtools.hud.loglimit.console"); |
|
79 |
|
80 hud = testDriver = null; |
|
81 finishTest(); |
|
82 |
|
83 yield undefined; |
|
84 } |
|
85 |
|
86 function test() { |
|
87 addTab("data:text/html;charset=utf-8,Web Console test for bug 613642: maintain scroll with pruning of old messages"); |
|
88 browser.addEventListener("load", function tabLoad(aEvent) { |
|
89 browser.removeEventListener(aEvent.type, tabLoad, true); |
|
90 |
|
91 openConsole(null, function(aHud) { |
|
92 hud = aHud; |
|
93 testDriver = testGen(); |
|
94 testDriver.next(); |
|
95 }); |
|
96 }, true); |
|
97 } |