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

mercurial