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.

     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();
    19   let outputNode = hud.outputNode;
    21   Services.prefs.setIntPref("devtools.hud.loglimit.console", 140);
    22   let scrollBoxElement = outputNode.parentNode;
    24   for (let i = 0; i < 150; i++) {
    25     content.console.log("test message " + i);
    26   }
    28   waitForMessages({
    29     webconsole: hud,
    30     messages: [{
    31       text: "test message 149",
    32       category: CATEGORY_WEBDEV,
    33       severity: SEVERITY_LOG,
    34     }],
    35   }).then(testNext);
    37   yield undefined;
    39   let oldScrollTop = scrollBoxElement.scrollTop;
    40   isnot(oldScrollTop, 0, "scroll location is not at the top");
    42   let firstNode = outputNode.firstChild;
    43   ok(firstNode, "found the first message");
    45   let msgNode = outputNode.children[80];
    46   ok(msgNode, "found the 80th message");
    48   // scroll to the middle message node
    49   msgNode.scrollIntoView(false);
    51   isnot(scrollBoxElement.scrollTop, oldScrollTop,
    52         "scroll location updated (scrolled to message)");
    54   oldScrollTop = scrollBoxElement.scrollTop;
    56   // add a message
    57   content.console.log("hello world");
    59   waitForMessages({
    60     webconsole: hud,
    61     messages: [{
    62       text: "hello world",
    63       category: CATEGORY_WEBDEV,
    64       severity: SEVERITY_LOG,
    65     }],
    66   }).then(testNext);
    68   yield undefined;
    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)");
    75   isnot(outputNode.firstChild, firstNode,
    76         "first message removed");
    78   Services.prefs.clearUserPref("devtools.hud.loglimit.console");
    80   hud = testDriver = null;
    81   finishTest();
    83   yield undefined;
    84 }
    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);
    91     openConsole(null, function(aHud) {
    92       hud = aHud;
    93       testDriver = testGen();
    94       testDriver.next();
    95     });
    96   }, true);
    97 }

mercurial