browser/devtools/webconsole/test/browser_webconsole_bug_613642_maintain_scroll.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial