1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_613642_prune_scroll.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.5 +/* 1.6 + * Any copyright is dedicated to the Public Domain. 1.7 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.8 + * 1.9 + * Contributor(s): 1.10 + * Mihai Șucan <mihai.sucan@gmail.com> 1.11 + */ 1.12 + 1.13 +let hud, testDriver; 1.14 + 1.15 +function testNext() { 1.16 + testDriver.next(); 1.17 +} 1.18 + 1.19 +function testGen() { 1.20 + hud.jsterm.clearOutput(); 1.21 + 1.22 + let outputNode = hud.outputNode; 1.23 + 1.24 + Services.prefs.setIntPref("devtools.hud.loglimit.console", 140); 1.25 + let scrollBoxElement = outputNode.parentNode; 1.26 + 1.27 + for (let i = 0; i < 150; i++) { 1.28 + content.console.log("test message " + i); 1.29 + } 1.30 + 1.31 + waitForMessages({ 1.32 + webconsole: hud, 1.33 + messages: [{ 1.34 + text: "test message 149", 1.35 + category: CATEGORY_WEBDEV, 1.36 + severity: SEVERITY_LOG, 1.37 + }], 1.38 + }).then(testNext); 1.39 + 1.40 + yield undefined; 1.41 + 1.42 + let oldScrollTop = scrollBoxElement.scrollTop; 1.43 + isnot(oldScrollTop, 0, "scroll location is not at the top"); 1.44 + 1.45 + let firstNode = outputNode.firstChild; 1.46 + ok(firstNode, "found the first message"); 1.47 + 1.48 + let msgNode = outputNode.children[80]; 1.49 + ok(msgNode, "found the 80th message"); 1.50 + 1.51 + // scroll to the middle message node 1.52 + msgNode.scrollIntoView(false); 1.53 + 1.54 + isnot(scrollBoxElement.scrollTop, oldScrollTop, 1.55 + "scroll location updated (scrolled to message)"); 1.56 + 1.57 + oldScrollTop = scrollBoxElement.scrollTop; 1.58 + 1.59 + // add a message 1.60 + content.console.log("hello world"); 1.61 + 1.62 + waitForMessages({ 1.63 + webconsole: hud, 1.64 + messages: [{ 1.65 + text: "hello world", 1.66 + category: CATEGORY_WEBDEV, 1.67 + severity: SEVERITY_LOG, 1.68 + }], 1.69 + }).then(testNext); 1.70 + 1.71 + yield undefined; 1.72 + 1.73 + // Scroll location needs to change, because one message is also removed, and 1.74 + // we need to scroll a bit towards the top, to keep the current view in sync. 1.75 + isnot(scrollBoxElement.scrollTop, oldScrollTop, 1.76 + "scroll location updated (added a message)"); 1.77 + 1.78 + isnot(outputNode.firstChild, firstNode, 1.79 + "first message removed"); 1.80 + 1.81 + Services.prefs.clearUserPref("devtools.hud.loglimit.console"); 1.82 + 1.83 + hud = testDriver = null; 1.84 + finishTest(); 1.85 + 1.86 + yield undefined; 1.87 +} 1.88 + 1.89 +function test() { 1.90 + addTab("data:text/html;charset=utf-8,Web Console test for bug 613642: maintain scroll with pruning of old messages"); 1.91 + browser.addEventListener("load", function tabLoad(aEvent) { 1.92 + browser.removeEventListener(aEvent.type, tabLoad, true); 1.93 + 1.94 + openConsole(null, function(aHud) { 1.95 + hud = aHud; 1.96 + testDriver = testGen(); 1.97 + testDriver.next(); 1.98 + }); 1.99 + }, true); 1.100 +}