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: let outputNode = hud.outputNode; michael@0: let scrollBox = 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: ok(scrollBox.scrollTop > 0, "scroll location is not at the top"); michael@0: michael@0: // scroll to the first node michael@0: outputNode.focus(); michael@0: michael@0: scrollBox.onscroll = () => { michael@0: info("onscroll top " + scrollBox.scrollTop); michael@0: if (scrollBox.scrollTop != 0) { michael@0: // Wait for scroll to 0. michael@0: return; michael@0: } michael@0: scrollBox.onscroll = null; michael@0: is(scrollBox.scrollTop, 0, "scroll location updated (moved to top)"); michael@0: testNext(); michael@0: }; michael@0: EventUtils.synthesizeKey("VK_HOME", {}, hud.iframeWindow); michael@0: michael@0: yield undefined; michael@0: michael@0: // add a message and make sure scroll doesn't change michael@0: content.console.log("test message 150"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "test message 150", 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: scrollBox.onscroll = () => { michael@0: if (scrollBox.scrollTop != 0) { michael@0: // Wait for scroll to stabilize at the top. michael@0: return; michael@0: } michael@0: scrollBox.onscroll = null; michael@0: is(scrollBox.scrollTop, 0, "scroll location is still at the top"); michael@0: testNext(); michael@0: }; michael@0: michael@0: // Make sure that scroll stabilizes at the top. executeSoon() is needed for michael@0: // the yield to work. michael@0: executeSoon(scrollBox.onscroll); michael@0: michael@0: yield undefined; michael@0: michael@0: // scroll back to the bottom michael@0: outputNode.lastChild.focus(); michael@0: michael@0: scrollBox.onscroll = () => { michael@0: if (scrollBox.scrollTop == 0) { michael@0: // Wait for scroll to bottom. michael@0: return; michael@0: } michael@0: scrollBox.onscroll = null; michael@0: isnot(scrollBox.scrollTop, 0, "scroll location updated (moved to bottom)"); michael@0: testNext(); michael@0: }; michael@0: EventUtils.synthesizeKey("VK_END", {}); michael@0: yield undefined; michael@0: michael@0: let oldScrollTop = scrollBox.scrollTop; michael@0: michael@0: content.console.log("test message 151"); michael@0: michael@0: scrollBox.onscroll = () => { michael@0: if (scrollBox.scrollTop == oldScrollTop) { michael@0: // Wait for scroll to change. michael@0: return; michael@0: } michael@0: scrollBox.onscroll = null; michael@0: isnot(scrollBox.scrollTop, oldScrollTop, "scroll location updated (moved to bottom again)"); michael@0: hud = testDriver = null; michael@0: finishTest(); michael@0: }; 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: remember scroll location"); michael@0: browser.addEventListener("load", function tabLoad(aEvent) { michael@0: browser.removeEventListener(aEvent.type, tabLoad, true); 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: }