|
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 let outputNode = hud.outputNode; |
|
19 let scrollBox = outputNode.parentNode; |
|
20 |
|
21 for (let i = 0; i < 150; i++) { |
|
22 content.console.log("test message " + i); |
|
23 } |
|
24 |
|
25 waitForMessages({ |
|
26 webconsole: hud, |
|
27 messages: [{ |
|
28 text: "test message 149", |
|
29 category: CATEGORY_WEBDEV, |
|
30 severity: SEVERITY_LOG, |
|
31 }], |
|
32 }).then(testNext); |
|
33 |
|
34 yield undefined; |
|
35 |
|
36 ok(scrollBox.scrollTop > 0, "scroll location is not at the top"); |
|
37 |
|
38 // scroll to the first node |
|
39 outputNode.focus(); |
|
40 |
|
41 scrollBox.onscroll = () => { |
|
42 info("onscroll top " + scrollBox.scrollTop); |
|
43 if (scrollBox.scrollTop != 0) { |
|
44 // Wait for scroll to 0. |
|
45 return; |
|
46 } |
|
47 scrollBox.onscroll = null; |
|
48 is(scrollBox.scrollTop, 0, "scroll location updated (moved to top)"); |
|
49 testNext(); |
|
50 }; |
|
51 EventUtils.synthesizeKey("VK_HOME", {}, hud.iframeWindow); |
|
52 |
|
53 yield undefined; |
|
54 |
|
55 // add a message and make sure scroll doesn't change |
|
56 content.console.log("test message 150"); |
|
57 |
|
58 waitForMessages({ |
|
59 webconsole: hud, |
|
60 messages: [{ |
|
61 text: "test message 150", |
|
62 category: CATEGORY_WEBDEV, |
|
63 severity: SEVERITY_LOG, |
|
64 }], |
|
65 }).then(testNext); |
|
66 |
|
67 yield undefined; |
|
68 |
|
69 scrollBox.onscroll = () => { |
|
70 if (scrollBox.scrollTop != 0) { |
|
71 // Wait for scroll to stabilize at the top. |
|
72 return; |
|
73 } |
|
74 scrollBox.onscroll = null; |
|
75 is(scrollBox.scrollTop, 0, "scroll location is still at the top"); |
|
76 testNext(); |
|
77 }; |
|
78 |
|
79 // Make sure that scroll stabilizes at the top. executeSoon() is needed for |
|
80 // the yield to work. |
|
81 executeSoon(scrollBox.onscroll); |
|
82 |
|
83 yield undefined; |
|
84 |
|
85 // scroll back to the bottom |
|
86 outputNode.lastChild.focus(); |
|
87 |
|
88 scrollBox.onscroll = () => { |
|
89 if (scrollBox.scrollTop == 0) { |
|
90 // Wait for scroll to bottom. |
|
91 return; |
|
92 } |
|
93 scrollBox.onscroll = null; |
|
94 isnot(scrollBox.scrollTop, 0, "scroll location updated (moved to bottom)"); |
|
95 testNext(); |
|
96 }; |
|
97 EventUtils.synthesizeKey("VK_END", {}); |
|
98 yield undefined; |
|
99 |
|
100 let oldScrollTop = scrollBox.scrollTop; |
|
101 |
|
102 content.console.log("test message 151"); |
|
103 |
|
104 scrollBox.onscroll = () => { |
|
105 if (scrollBox.scrollTop == oldScrollTop) { |
|
106 // Wait for scroll to change. |
|
107 return; |
|
108 } |
|
109 scrollBox.onscroll = null; |
|
110 isnot(scrollBox.scrollTop, oldScrollTop, "scroll location updated (moved to bottom again)"); |
|
111 hud = testDriver = null; |
|
112 finishTest(); |
|
113 }; |
|
114 |
|
115 yield undefined; |
|
116 } |
|
117 |
|
118 function test() { |
|
119 addTab("data:text/html;charset=utf-8,Web Console test for bug 613642: remember scroll location"); |
|
120 browser.addEventListener("load", function tabLoad(aEvent) { |
|
121 browser.removeEventListener(aEvent.type, tabLoad, true); |
|
122 openConsole(null, function(aHud) { |
|
123 hud = aHud; |
|
124 testDriver = testGen(); |
|
125 testDriver.next(); |
|
126 }); |
|
127 }, true); |
|
128 } |