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: michael@0: // Tests that the Web Console limits the number of lines displayed according to michael@0: // the limit set for each category. michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/" + michael@0: "webconsole/test/test-bug-644419-log-limits.html"; michael@0: michael@0: let hud, outputNode; michael@0: michael@0: function test() { michael@0: addTab("data:text/html;charset=utf-8,Web Console test for bug 644419: Console should " + michael@0: "have user-settable log limits for each message category"); michael@0: browser.addEventListener("load", onLoad, true); michael@0: } michael@0: michael@0: function onLoad(aEvent) { michael@0: browser.removeEventListener(aEvent.type, onLoad, true); michael@0: michael@0: openConsole(null, function(aHud) { michael@0: aHud.jsterm.clearOutput(); michael@0: hud = aHud; michael@0: outputNode = aHud.outputNode; michael@0: michael@0: browser.addEventListener("load", testWebDevLimits, true); michael@0: expectUncaughtException(); michael@0: content.location = TEST_URI; michael@0: }); michael@0: } michael@0: michael@0: function testWebDevLimits(aEvent) { michael@0: browser.removeEventListener(aEvent.type, testWebDevLimits, true); michael@0: Services.prefs.setIntPref("devtools.hud.loglimit.console", 10); michael@0: michael@0: // Find the sentinel entry. michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "bar is not defined", michael@0: category: CATEGORY_JS, michael@0: severity: SEVERITY_ERROR, michael@0: }], michael@0: }).then(testWebDevLimits2); michael@0: } michael@0: michael@0: function testWebDevLimits2() { michael@0: // Fill the log with Web Developer errors. michael@0: for (let i = 0; i < 11; 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 10", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(() => { michael@0: testLogEntry(outputNode, "test message 0", "first message is pruned", false, true); michael@0: findLogEntry("test message 1"); michael@0: // Check if the sentinel entry is still there. michael@0: findLogEntry("bar is not defined"); michael@0: michael@0: Services.prefs.clearUserPref("devtools.hud.loglimit.console"); michael@0: testJsLimits(); michael@0: }); michael@0: } michael@0: michael@0: function testJsLimits() { michael@0: Services.prefs.setIntPref("devtools.hud.loglimit.exception", 10); michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: content.console.log("testing JS limits"); michael@0: michael@0: // Find the sentinel entry. michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "testing JS limits", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(testJsLimits2); michael@0: } michael@0: michael@0: function testJsLimits2() { michael@0: // Fill the log with JS errors. michael@0: let head = content.document.getElementsByTagName("head")[0]; michael@0: for (let i = 0; i < 11; i++) { michael@0: var script = content.document.createElement("script"); michael@0: script.text = "fubar" + i + ".bogus(6);"; michael@0: expectUncaughtException(); michael@0: head.insertBefore(script, head.firstChild); michael@0: } michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "fubar10 is not defined", michael@0: category: CATEGORY_JS, michael@0: severity: SEVERITY_ERROR, michael@0: }], michael@0: }).then(() => { michael@0: testLogEntry(outputNode, "fubar0 is not defined", "first message is pruned", false, true); michael@0: findLogEntry("fubar1 is not defined"); michael@0: // Check if the sentinel entry is still there. michael@0: findLogEntry("testing JS limits"); michael@0: michael@0: Services.prefs.clearUserPref("devtools.hud.loglimit.exception"); michael@0: testNetLimits(); michael@0: }); michael@0: } michael@0: michael@0: var gCounter, gImage; michael@0: michael@0: function testNetLimits() { michael@0: Services.prefs.setIntPref("devtools.hud.loglimit.network", 10); michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: content.console.log("testing Net limits"); michael@0: michael@0: // Find the sentinel entry. michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "testing Net limits", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(() => { michael@0: // Fill the log with network messages. michael@0: gCounter = 0; michael@0: loadImage(); michael@0: }); michael@0: } michael@0: michael@0: function loadImage() { michael@0: if (gCounter < 11) { michael@0: let body = content.document.getElementsByTagName("body")[0]; michael@0: gImage && gImage.removeEventListener("load", loadImage, true); michael@0: gImage = content.document.createElement("img"); michael@0: gImage.src = "test-image.png?_fubar=" + gCounter; michael@0: body.insertBefore(gImage, body.firstChild); michael@0: gImage.addEventListener("load", loadImage, true); michael@0: gCounter++; michael@0: return; michael@0: } michael@0: michael@0: is(gCounter, 11, "loaded 11 files"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "test-image.png", michael@0: url: "test-image.png?_fubar=10", michael@0: category: CATEGORY_NETWORK, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(() => { michael@0: let msgs = outputNode.querySelectorAll(".message[category=network]"); michael@0: is(msgs.length, 10, "number of network messages"); michael@0: isnot(msgs[0].url.indexOf("fubar=1"), -1, "first network message"); michael@0: isnot(msgs[1].url.indexOf("fubar=2"), -1, "second network message"); michael@0: findLogEntry("testing Net limits"); michael@0: michael@0: Services.prefs.clearUserPref("devtools.hud.loglimit.network"); michael@0: testCssLimits(); michael@0: }); michael@0: } michael@0: michael@0: function testCssLimits() { michael@0: Services.prefs.setIntPref("devtools.hud.loglimit.cssparser", 10); michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: content.console.log("testing CSS limits"); michael@0: michael@0: // Find the sentinel entry. michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "testing CSS limits", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(testCssLimits2); michael@0: } michael@0: michael@0: function testCssLimits2() { michael@0: // Fill the log with CSS errors. michael@0: let body = content.document.getElementsByTagName("body")[0]; michael@0: for (let i = 0; i < 11; i++) { michael@0: var div = content.document.createElement("div"); michael@0: div.setAttribute("style", "-moz-foobar" + i + ": 42;"); michael@0: body.insertBefore(div, body.firstChild); michael@0: } michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "-moz-foobar10", michael@0: category: CATEGORY_CSS, michael@0: severity: SEVERITY_WARNING, michael@0: }], michael@0: }).then(() => { michael@0: testLogEntry(outputNode, "Unknown property '-moz-foobar0'", michael@0: "first message is pruned", false, true); michael@0: findLogEntry("Unknown property '-moz-foobar1'"); michael@0: // Check if the sentinel entry is still there. michael@0: findLogEntry("testing CSS limits"); michael@0: michael@0: Services.prefs.clearUserPref("devtools.hud.loglimit.cssparser"); michael@0: finishTest(); michael@0: }); michael@0: }