Bug 644419 - Console should have user-settable log limits for each message category; f=rcampbell r=rcampbell,gavin.sharp

This commit is contained in:
Panos Astithas 2011-05-19 17:15:36 -03:00
Родитель 3b63b34933
Коммит fcf33de8c1
8 изменённых файлов: 208 добавлений и 28 удалений

Просмотреть файл

@ -1009,6 +1009,13 @@ pref("devtools.hud.height", 0);
// window - in a separate window/popup panel.
pref("devtools.webconsole.position", "above");
// The number of lines that are displayed in the web console for the Net,
// CSS, JS and Web Developer categories.
pref("devtools.hud.loglimit.network", 200);
pref("devtools.hud.loglimit.cssparser", 200);
pref("devtools.hud.loglimit.exception", 200);
pref("devtools.hud.loglimit.console", 200);
// Whether the character encoding menu is under the main Firefox button. This
// preference is a string so that localizers can alter it.
pref("browser.menu.showCharacterEncoding", "chrome://browser/locale/browser.properties");

Просмотреть файл

@ -128,9 +128,9 @@ const NEW_GROUP_DELAY = 5000;
// search.
const SEARCH_DELAY = 200;
// The number of lines that are displayed in the console output by default.
// The user can change this number by adjusting the hidden
// "devtools.hud.loglimit" preference.
// The number of lines that are displayed in the console output by default, for
// each category. The user can change this number by adjusting the hidden
// "devtools.hud.loglimit.{network,cssparser,exception,console}" preferences.
const DEFAULT_LOG_LIMIT = 200;
// The various categories of messages. We start numbering at zero so we can
@ -1193,22 +1193,24 @@ NetworkPanel.prototype =
//// Private utility functions for the HUD service
/**
* Destroys lines of output if more lines than the allowed log limit are
* present.
* Ensures that the number of message nodes of type aCategory don't exceed that
* category's line limit by removing old messages as needed.
*
* @param nsIDOMNode aConsoleNode
* The DOM node (richlistbox aka outputNode) that holds the output of the
* console.
* @param integer aCategory
* The category of message nodes to limit.
* @return number
* The current user-selected log limit.
*/
function pruneConsoleOutputIfNecessary(aConsoleNode)
function pruneConsoleOutputIfNecessary(aConsoleNode, aCategory)
{
// Get the log limit, either from the pref or from the constant.
let logLimit;
try {
let prefBranch = Services.prefs.getBranch("devtools.hud.");
logLimit = prefBranch.getIntPref("loglimit");
let prefName = CATEGORY_CLASS_FRAGMENTS[aCategory];
logLimit = Services.prefs.getIntPref("devtools.hud.loglimit." + prefName);
} catch (e) {
logLimit = DEFAULT_LOG_LIMIT;
}
@ -1219,7 +1221,8 @@ function pruneConsoleOutputIfNecessary(aConsoleNode)
let hudRef = HUDService.getHudReferenceForOutputNode(aConsoleNode);
// Prune the nodes.
let messageNodes = aConsoleNode.querySelectorAll(".hud-msg-node");
let messageNodes = aConsoleNode.querySelectorAll(".webconsole-msg-" +
CATEGORY_CLASS_FRAGMENTS[aCategory]);
let removeNodes = messageNodes.length - logLimit;
for (let i = 0; i < removeNodes; i++) {
if (messageNodes[i].classList.contains("webconsole-msg-cssparser")) {
@ -4183,7 +4186,7 @@ function JSPropertyProvider(aScope, aInputValue)
for (let i = 0; i < properties.length; i++) {
let prop = properties[i].trim();
// If obj is undefined or null, then there is no change to run completion
// If obj is undefined or null, then there is no chance to run completion
// on it. Exit here.
if (typeof obj === "undefined" || obj === null) {
return null;
@ -4201,7 +4204,7 @@ function JSPropertyProvider(aScope, aInputValue)
matchProp = properties[0].trimLeft();
}
// If obj is undefined or null, then there is no change to run
// If obj is undefined or null, then there is no chance to run
// completion on it. Exit here.
if (typeof obj === "undefined" || obj === null) {
return null;
@ -4515,8 +4518,6 @@ JSTerm.prototype = {
get codeInputString()
{
// TODO: filter the input for windows line breaks, conver to unix
// see bug 572812
return this.inputNode.value;
},
@ -5810,7 +5811,7 @@ ConsoleUtils = {
HUDService.regroupOutput(outputNode);
if (pruneConsoleOutputIfNecessary(outputNode) == 0) {
if (pruneConsoleOutputIfNecessary(outputNode, aNode.category) == 0) {
// We can't very well scroll to make the message node visible if the log
// limit is zero and the node was destroyed in the first place.
return;

Просмотреть файл

@ -135,6 +135,7 @@ _BROWSER_TEST_FILES = \
browser_webconsole_bug_585956_console_trace.js \
browser_webconsole_bug_595223_file_uri.js \
browser_webconsole_bug_632275_getters_document_width.js \
browser_webconsole_bug_644419_log_limits.js \
browser_webconsole_bug_646025_console_file_location.js \
browser_webconsole_position_ui.js \
browser_webconsole_bug_642615_autocomplete.js \
@ -207,6 +208,7 @@ _BROWSER_TEST_PAGES = \
test-bug-621644-jsterm-dollar.html \
test-bug-632347-iterators-generators.html \
test-bug-585956-console-trace.html \
test-bug-644419-log-limits.html \
test-bug-632275-getters.html \
test-bug-646025-console-file-location.html \
test-file-location.js \

Просмотреть файл

@ -28,8 +28,8 @@ function testLineLimit() {
let console = browser.contentWindow.wrappedJSObject.console;
hudBox = HUDService.getHeadsUpDisplay(hudId);
let prefBranch = Services.prefs.getBranch("devtools.hud.");
prefBranch.setIntPref("loglimit", 20);
let prefBranch = Services.prefs.getBranch("devtools.hud.loglimit.");
prefBranch.setIntPref("console", 20);
for (let i = 0; i < 20; i++) {
console.log("foo #" + i); // must change message to prevent repeats
@ -42,7 +42,7 @@ function testLineLimit() {
is(countMessageNodes(), 20, "there are still 20 message nodes in the " +
"output when adding one more");
prefBranch.setIntPref("loglimit", 30);
prefBranch.setIntPref("console", 30);
for (let i = 0; i < 20; i++) {
console.log("boo #" + i); // must change message to prevent repeats
}
@ -50,12 +50,12 @@ function testLineLimit() {
is(countMessageNodes(), 30, "there are 30 message nodes in the output " +
"when the log limit is set to 30");
prefBranch.setIntPref("loglimit", 0);
prefBranch.setIntPref("console", 0);
console.log("baz");
is(countMessageNodes(), 0, "there are no message nodes in the output when " +
"the log limit is set to zero");
prefBranch.clearUserPref("loglimit");
prefBranch.clearUserPref("console");
prefBranch = console = null;
finishTest();
}

Просмотреть файл

@ -15,13 +15,9 @@ function tabLoad(aEvent) {
let hudId = HUDService.getHudIdByWindow(content);
let hud = HUDService.hudReferences[hudId];
let outputNode = hud.outputNode;
let oldPref = 200;
try {
oldPref = Services.prefs.getIntPref("devtools.hud.loglimit");
}
catch (ex) { }
let oldPref = Services.prefs.getIntPref("devtools.hud.loglimit.console");
Services.prefs.setIntPref("devtools.hud.loglimit", 140);
Services.prefs.setIntPref("devtools.hud.loglimit.console", 140);
let scrollBoxElement = outputNode.scrollBoxObject.element;
let boxObject = outputNode.scrollBoxObject;
@ -57,7 +53,7 @@ function tabLoad(aEvent) {
isnot(outputNode.firstChild, firstNode,
"first message removed");
Services.prefs.setIntPref("devtools.hud.loglimit", oldPref);
Services.prefs.setIntPref("devtools.hud.loglimit.console", oldPref);
finishTest();
}

Просмотреть файл

@ -44,8 +44,8 @@ function populateConsole(aHudRef) {
}
function testCSSPruning() {
let prefBranch = Services.prefs.getBranch("devtools.hud.");
prefBranch.setIntPref("loglimit", LOG_LIMIT);
let prefBranch = Services.prefs.getBranch("devtools.hud.loglimit.");
prefBranch.setIntPref("cssparser", LOG_LIMIT);
browser.removeEventListener("DOMContentLoaded",testCSSPruning, false);

Просмотреть файл

@ -0,0 +1,154 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests that the Web Console limits the number of lines displayed according to
// the limit set for each category.
const TEST_URI = "http://example.com/browser/toolkit/components/console/" +
"hudservice/tests/browser/test-bug-644419-log-limits.html";
var gOldPref, gHudId;
function test() {
addTab("data:text/html,Web Console test for bug 644419: Console should " +
"have user-settable log limits for each message category");
browser.addEventListener("load", onLoad, true);
}
function onLoad(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
openConsole();
gHudId = HUDService.getHudIdByWindow(content);
browser.addEventListener("load", testWebDevLimits, true);
content.location = TEST_URI;
}
function testWebDevLimits(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
gOldPref = Services.prefs.getIntPref("devtools.hud.loglimit.console");
Services.prefs.setIntPref("devtools.hud.loglimit.console", 10);
let hud = HUDService.hudReferences[gHudId];
outputNode = hud.outputNode;
executeSoon(function() {
// Find the sentinel entry.
findLogEntry("bar is not defined");
// Fill the log with Web Developer errors.
for (let i = 0; i < 11; i++) {
hud.console.log("test message " + i);
}
testLogEntry(outputNode, "test message 0", "first message is pruned", false, true);
findLogEntry("test message 1");
// Check if the sentinel entry is still there.
findLogEntry("bar is not defined");
Services.prefs.setIntPref("devtools.hud.loglimit.console", gOldPref);
testJsLimits();
});
}
function testJsLimits(aEvent) {
HUDService.clearDisplay(gHudId);
gOldPref = Services.prefs.getIntPref("devtools.hud.loglimit.exception");
Services.prefs.setIntPref("devtools.hud.loglimit.exception", 10);
let hud = HUDService.hudReferences[gHudId];
outputNode = hud.outputNode;
hud.console.log("testing JS limits");
// Find the sentinel entry.
findLogEntry("testing JS limits");
// Fill the log with JS errors.
let head = content.document.getElementsByTagName("head")[0];
for (let i = 0; i < 11; i++) {
var script = content.document.createElement("script");
script.text = "fubar" + i + ".bogus(6);";
head.insertBefore(script, head.firstChild);
}
executeSoon(function() {
testLogEntry(outputNode, "fubar0 is not defined", "first message is pruned", false, true);
findLogEntry("fubar1 is not defined");
// Check if the sentinel entry is still there.
findLogEntry("testing JS limits");
Services.prefs.setIntPref("devtools.hud.loglimit.exception", gOldPref);
testNetLimits();
});
}
var gCounter, gImage;
function testNetLimits(aEvent) {
HUDService.clearDisplay(gHudId);
gOldPref = Services.prefs.getIntPref("devtools.hud.loglimit.network");
Services.prefs.setIntPref("devtools.hud.loglimit.network", 10);
let hud = HUDService.hudReferences[gHudId];
outputNode = hud.outputNode;
hud.console.log("testing Net limits");
// Find the sentinel entry.
findLogEntry("testing Net limits");
// Fill the log with network messages.
gCounter = 0;
loadImage();
}
function loadImage() {
if (gCounter < 11) {
let body = content.document.getElementsByTagName("body")[0];
gImage && gImage.removeEventListener("load", loadImage, true);
gImage = content.document.createElement("img");
gImage.src = "test-image.png?_fubar=" + gCounter;
body.insertBefore(gImage, body.firstChild);
gImage.addEventListener("load", loadImage, true);
gCounter++;
return;
}
is(gCounter, 11, "loaded 11 files");
testLogEntry(outputNode, "test-image.png?_fubar=0", "first message is pruned", false, true);
findLogEntry("test-image.png?_fubar=1");
// Check if the sentinel entry is still there.
findLogEntry("testing Net limits");
Services.prefs.setIntPref("devtools.hud.loglimit.network", gOldPref);
testCssLimits();
}
function testCssLimits(aEvent) {
HUDService.clearDisplay(gHudId);
gOldPref = Services.prefs.getIntPref("devtools.hud.loglimit.cssparser");
Services.prefs.setIntPref("devtools.hud.loglimit.cssparser", 10);
let hud = HUDService.hudReferences[gHudId];
outputNode = hud.outputNode;
hud.console.log("testing CSS limits");
// Find the sentinel entry.
findLogEntry("testing CSS limits");
// Fill the log with CSS errors.
let body = content.document.getElementsByTagName("body")[0];
for (let i = 0; i < 11; i++) {
var div = content.document.createElement("div");
div.setAttribute("style", "-moz-foobar" + i + ": 42;");
body.insertBefore(div, body.firstChild);
}
executeSoon(function() {
testLogEntry(outputNode, "Unknown property '-moz-foobar0'", "first message is pruned", false, true);
findLogEntry("Unknown property '-moz-foobar1'");
// Check if the sentinel entry is still there.
findLogEntry("testing CSS limits");
Services.prefs.setIntPref("devtools.hud.loglimit.cssparser", gOldPref);
finishTest();
});
}

Просмотреть файл

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<head>
<title>Test for bug 644419: console log limits</title>
</head>
<body>
<h1>Test for bug 644419: Console should have user-settable log limits for
each message category</h1>
<script type="text/javascript">
function foo() {
bar.baz();
}
foo();
</script>
</body>
</html>