browser/devtools/webconsole/test/browser_webconsole_bug_644419_log_limits.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial