michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* ***** BEGIN LICENSE BLOCK ***** 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: * Patrick Walton michael@0: * Mihai Șucan michael@0: * michael@0: * ***** END LICENSE BLOCK ***** */ michael@0: michael@0: // Tests that the Web Console limits the number of lines displayed according to michael@0: // the user's preferences. michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf8,test for bug 585237"; michael@0: let hud, testDriver; michael@0: michael@0: function test() { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, function(aHud) { michael@0: hud = aHud; michael@0: testDriver = testGen(); michael@0: testNext(); michael@0: }); michael@0: }, true); michael@0: } michael@0: michael@0: function testNext() { michael@0: testDriver.next(); michael@0: } michael@0: michael@0: function testGen() { michael@0: let console = content.console; michael@0: outputNode = hud.outputNode; michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: let prefBranch = Services.prefs.getBranch("devtools.hud.loglimit."); michael@0: prefBranch.setIntPref("console", 20); michael@0: michael@0: for (let i = 0; i < 30; i++) { michael@0: console.log("foo #" + i); // must change message to prevent repeats michael@0: } michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "foo #29", 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: is(countMessageNodes(), 20, "there are 20 message nodes in the output " + michael@0: "when the log limit is set to 20"); michael@0: michael@0: console.log("bar bug585237"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "bar bug585237", 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: is(countMessageNodes(), 20, "there are still 20 message nodes in the " + michael@0: "output when adding one more"); michael@0: michael@0: prefBranch.setIntPref("console", 30); michael@0: for (let i = 0; i < 20; i++) { michael@0: console.log("boo #" + i); // must change message to prevent repeats michael@0: } michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "boo #19", 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: is(countMessageNodes(), 30, "there are 30 message nodes in the output " + michael@0: "when the log limit is set to 30"); michael@0: michael@0: prefBranch.clearUserPref("console"); michael@0: hud = testDriver = prefBranch = console = outputNode = null; michael@0: finishTest(); michael@0: michael@0: yield undefined; michael@0: } michael@0: michael@0: function countMessageNodes() { michael@0: return outputNode.querySelectorAll(".message").length; michael@0: } michael@0: