browser/devtools/webconsole/test/browser_webconsole_bug_601352_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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 // Test that the console output scrolls to JS eval results when there are many
     6 // messages displayed. See bug 601352.
     8 function test() {
     9   Task.spawn(runner).then(finishTest);
    11   function* runner() {
    12     let {tab} = yield loadTab("data:text/html;charset=utf-8,Web Console test for bug 601352");
    13     let hud = yield openConsole(tab);
    14     hud.jsterm.clearOutput();
    16     let longMessage = "";
    17     for (let i = 0; i < 50; i++) {
    18       longMessage += "LongNonwrappingMessage";
    19     }
    21     for (let i = 0; i < 50; i++) {
    22       content.console.log("test1 message " + i);
    23     }
    25     content.console.log(longMessage);
    27     for (let i = 0; i < 50; i++) {
    28       content.console.log("test2 message " + i);
    29     }
    31     yield waitForMessages({
    32       webconsole: hud,
    33       messages: [{
    34         text: "test1 message 0",
    35       }, {
    36         text: "test1 message 49",
    37       }, {
    38         text: "LongNonwrappingMessage",
    39       }, {
    40         text: "test2 message 0",
    41       }, {
    42         text: "test2 message 49",
    43       }],
    44     });
    46     let nodeDeferred = promise.defer();
    47     hud.jsterm.execute("1+1", (node) => { nodeDeferred.resolve(node); });
    48     let node = yield nodeDeferred.promise;
    50     let scrollNode = hud.outputNode.parentNode;
    51     let rectNode = node.getBoundingClientRect();
    52     let rectOutput = scrollNode.getBoundingClientRect();
    53     console.debug("rectNode", rectNode, "rectOutput", rectOutput);
    54     console.log("scrollNode scrollHeight", scrollNode.scrollHeight, "scrollTop", scrollNode.scrollTop, "clientHeight", scrollNode.clientHeight);
    56     isnot(scrollNode.scrollTop, 0, "scroll location is not at the top");
    58     // The bounding client rect .top/left coordinates are relative to the
    59     // console iframe.
    61     // Visible scroll viewport.
    62     let height = rectOutput.height;
    64     // Top and bottom coordinates of the last message node, relative to the outputNode.
    65     let top = rectNode.top - rectOutput.top;
    66     let bottom = top + rectNode.height;
    67     info("node top " + top + " node bottom " + bottom + " node clientHeight " + node.clientHeight);
    69     ok(top >= 0 && bottom <= height, "last message is visible");
    70   }
    71 }

mercurial