Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 */
10 let hud, testDriver;
12 function testNext() {
13 testDriver.next();
14 }
16 function testGen() {
17 hud.jsterm.clearOutput();
18 let outputNode = hud.outputNode;
19 let scrollBox = outputNode.parentNode;
21 for (let i = 0; i < 150; i++) {
22 content.console.log("test message " + i);
23 }
25 waitForMessages({
26 webconsole: hud,
27 messages: [{
28 text: "test message 149",
29 category: CATEGORY_WEBDEV,
30 severity: SEVERITY_LOG,
31 }],
32 }).then(testNext);
34 yield undefined;
36 ok(scrollBox.scrollTop > 0, "scroll location is not at the top");
38 // scroll to the first node
39 outputNode.focus();
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);
53 yield undefined;
55 // add a message and make sure scroll doesn't change
56 content.console.log("test message 150");
58 waitForMessages({
59 webconsole: hud,
60 messages: [{
61 text: "test message 150",
62 category: CATEGORY_WEBDEV,
63 severity: SEVERITY_LOG,
64 }],
65 }).then(testNext);
67 yield undefined;
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 };
79 // Make sure that scroll stabilizes at the top. executeSoon() is needed for
80 // the yield to work.
81 executeSoon(scrollBox.onscroll);
83 yield undefined;
85 // scroll back to the bottom
86 outputNode.lastChild.focus();
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;
100 let oldScrollTop = scrollBox.scrollTop;
102 content.console.log("test message 151");
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 };
115 yield undefined;
116 }
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 }