michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: * michael@0: * Contributor(s): michael@0: * Mihai Șucan michael@0: */ michael@0: michael@0: let hud, testDriver; michael@0: michael@0: function testNext() { michael@0: testDriver.next(); michael@0: } michael@0: michael@0: function testGen() { michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: let outputNode = hud.outputNode; michael@0: michael@0: Services.prefs.setIntPref("devtools.hud.loglimit.console", 140); michael@0: let scrollBoxElement = outputNode.parentNode; michael@0: michael@0: for (let i = 0; i < 150; i++) { michael@0: content.console.log("test message " + i); michael@0: } michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "test message 149", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(testNext); michael@0: michael@0: yield undefined; michael@0: michael@0: let oldScrollTop = scrollBoxElement.scrollTop; michael@0: isnot(oldScrollTop, 0, "scroll location is not at the top"); michael@0: michael@0: let firstNode = outputNode.firstChild; michael@0: ok(firstNode, "found the first message"); michael@0: michael@0: let msgNode = outputNode.children[80]; michael@0: ok(msgNode, "found the 80th message"); michael@0: michael@0: // scroll to the middle message node michael@0: msgNode.scrollIntoView(false); michael@0: michael@0: isnot(scrollBoxElement.scrollTop, oldScrollTop, michael@0: "scroll location updated (scrolled to message)"); michael@0: michael@0: oldScrollTop = scrollBoxElement.scrollTop; michael@0: michael@0: // add a message michael@0: content.console.log("hello world"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "hello world", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(testNext); michael@0: michael@0: yield undefined; michael@0: michael@0: // Scroll location needs to change, because one message is also removed, and michael@0: // we need to scroll a bit towards the top, to keep the current view in sync. michael@0: isnot(scrollBoxElement.scrollTop, oldScrollTop, michael@0: "scroll location updated (added a message)"); michael@0: michael@0: isnot(outputNode.firstChild, firstNode, michael@0: "first message removed"); michael@0: michael@0: Services.prefs.clearUserPref("devtools.hud.loglimit.console"); michael@0: michael@0: hud = testDriver = null; michael@0: finishTest(); michael@0: michael@0: yield undefined; michael@0: } michael@0: michael@0: function test() { michael@0: addTab("data:text/html;charset=utf-8,Web Console test for bug 613642: maintain scroll with pruning of old messages"); michael@0: browser.addEventListener("load", function tabLoad(aEvent) { michael@0: browser.removeEventListener(aEvent.type, tabLoad, true); michael@0: michael@0: openConsole(null, function(aHud) { michael@0: hud = aHud; michael@0: testDriver = testGen(); michael@0: testDriver.next(); michael@0: }); michael@0: }, true); michael@0: }