1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_601352_scroll.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// Test that the console output scrolls to JS eval results when there are many 1.9 +// messages displayed. See bug 601352. 1.10 + 1.11 +function test() { 1.12 + Task.spawn(runner).then(finishTest); 1.13 + 1.14 + function* runner() { 1.15 + let {tab} = yield loadTab("data:text/html;charset=utf-8,Web Console test for bug 601352"); 1.16 + let hud = yield openConsole(tab); 1.17 + hud.jsterm.clearOutput(); 1.18 + 1.19 + let longMessage = ""; 1.20 + for (let i = 0; i < 50; i++) { 1.21 + longMessage += "LongNonwrappingMessage"; 1.22 + } 1.23 + 1.24 + for (let i = 0; i < 50; i++) { 1.25 + content.console.log("test1 message " + i); 1.26 + } 1.27 + 1.28 + content.console.log(longMessage); 1.29 + 1.30 + for (let i = 0; i < 50; i++) { 1.31 + content.console.log("test2 message " + i); 1.32 + } 1.33 + 1.34 + yield waitForMessages({ 1.35 + webconsole: hud, 1.36 + messages: [{ 1.37 + text: "test1 message 0", 1.38 + }, { 1.39 + text: "test1 message 49", 1.40 + }, { 1.41 + text: "LongNonwrappingMessage", 1.42 + }, { 1.43 + text: "test2 message 0", 1.44 + }, { 1.45 + text: "test2 message 49", 1.46 + }], 1.47 + }); 1.48 + 1.49 + let nodeDeferred = promise.defer(); 1.50 + hud.jsterm.execute("1+1", (node) => { nodeDeferred.resolve(node); }); 1.51 + let node = yield nodeDeferred.promise; 1.52 + 1.53 + let scrollNode = hud.outputNode.parentNode; 1.54 + let rectNode = node.getBoundingClientRect(); 1.55 + let rectOutput = scrollNode.getBoundingClientRect(); 1.56 + console.debug("rectNode", rectNode, "rectOutput", rectOutput); 1.57 + console.log("scrollNode scrollHeight", scrollNode.scrollHeight, "scrollTop", scrollNode.scrollTop, "clientHeight", scrollNode.clientHeight); 1.58 + 1.59 + isnot(scrollNode.scrollTop, 0, "scroll location is not at the top"); 1.60 + 1.61 + // The bounding client rect .top/left coordinates are relative to the 1.62 + // console iframe. 1.63 + 1.64 + // Visible scroll viewport. 1.65 + let height = rectOutput.height; 1.66 + 1.67 + // Top and bottom coordinates of the last message node, relative to the outputNode. 1.68 + let top = rectNode.top - rectOutput.top; 1.69 + let bottom = top + rectNode.height; 1.70 + info("node top " + top + " node bottom " + bottom + " node clientHeight " + node.clientHeight); 1.71 + 1.72 + ok(top >= 0 && bottom <= height, "last message is visible"); 1.73 + } 1.74 +}