1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
/* 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/browser/devtools/" +
"webconsole/test/test-bug-644419-log-limits.html";
let hud, outputNode;
function test() {
addTab("data:text/html;charset=utf-8,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, onLoad, true);
openConsole(null, function(aHud) {
aHud.jsterm.clearOutput();
hud = aHud;
outputNode = aHud.outputNode;
browser.addEventListener("load", testWebDevLimits, true);
expectUncaughtException();
content.location = TEST_URI;
});
}
function testWebDevLimits(aEvent) {
browser.removeEventListener(aEvent.type, testWebDevLimits, true);
Services.prefs.setIntPref("devtools.hud.loglimit.console", 10);
// Find the sentinel entry.
waitForMessages({
webconsole: hud,
messages: [{
text: "bar is not defined",
category: CATEGORY_JS,
severity: SEVERITY_ERROR,
}],
}).then(testWebDevLimits2);
}
function testWebDevLimits2() {
// Fill the log with Web Developer errors.
for (let i = 0; i < 11; i++) {
content.console.log("test message " + i);
}
waitForMessages({
webconsole: hud,
messages: [{
text: "test message 10",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
}],
}).then(() => {
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.clearUserPref("devtools.hud.loglimit.console");
testJsLimits();
});
}
function testJsLimits() {
Services.prefs.setIntPref("devtools.hud.loglimit.exception", 10);
hud.jsterm.clearOutput();
content.console.log("testing JS limits");
// Find the sentinel entry.
waitForMessages({
webconsole: hud,
messages: [{
text: "testing JS limits",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
}],
}).then(testJsLimits2);
}
function testJsLimits2() {
// 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);";
expectUncaughtException();
head.insertBefore(script, head.firstChild);
}
waitForMessages({
webconsole: hud,
messages: [{
text: "fubar10 is not defined",
category: CATEGORY_JS,
severity: SEVERITY_ERROR,
}],
}).then(() => {
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.clearUserPref("devtools.hud.loglimit.exception");
testNetLimits();
});
}
var gCounter, gImage;
function testNetLimits() {
Services.prefs.setIntPref("devtools.hud.loglimit.network", 10);
hud.jsterm.clearOutput();
content.console.log("testing Net limits");
// Find the sentinel entry.
waitForMessages({
webconsole: hud,
messages: [{
text: "testing Net limits",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
}],
}).then(() => {
// 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");
waitForMessages({
webconsole: hud,
messages: [{
text: "test-image.png",
url: "test-image.png?_fubar=10",
category: CATEGORY_NETWORK,
severity: SEVERITY_LOG,
}],
}).then(() => {
let msgs = outputNode.querySelectorAll(".message[category=network]");
is(msgs.length, 10, "number of network messages");
isnot(msgs[0].url.indexOf("fubar=1"), -1, "first network message");
isnot(msgs[1].url.indexOf("fubar=2"), -1, "second network message");
findLogEntry("testing Net limits");
Services.prefs.clearUserPref("devtools.hud.loglimit.network");
testCssLimits();
});
}
function testCssLimits() {
Services.prefs.setIntPref("devtools.hud.loglimit.cssparser", 10);
hud.jsterm.clearOutput();
content.console.log("testing CSS limits");
// Find the sentinel entry.
waitForMessages({
webconsole: hud,
messages: [{
text: "testing CSS limits",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
}],
}).then(testCssLimits2);
}
function testCssLimits2() {
// 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);
}
waitForMessages({
webconsole: hud,
messages: [{
text: "-moz-foobar10",
category: CATEGORY_CSS,
severity: SEVERITY_WARNING,
}],
}).then(() => {
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.clearUserPref("devtools.hud.loglimit.cssparser");
finishTest();
});
}
|