browser/devtools/webconsole/test/browser_webconsole_bug_644419_log_limits.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_644419_log_limits.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,219 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/*
     1.6 + * Any copyright is dedicated to the Public Domain.
     1.7 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.8 + */
     1.9 +
    1.10 +// Tests that the Web Console limits the number of lines displayed according to
    1.11 +// the limit set for each category.
    1.12 +
    1.13 +const TEST_URI = "http://example.com/browser/browser/devtools/" +
    1.14 +                 "webconsole/test/test-bug-644419-log-limits.html";
    1.15 +
    1.16 +let hud, outputNode;
    1.17 +
    1.18 +function test() {
    1.19 +  addTab("data:text/html;charset=utf-8,Web Console test for bug 644419: Console should " +
    1.20 +         "have user-settable log limits for each message category");
    1.21 +  browser.addEventListener("load", onLoad, true);
    1.22 +}
    1.23 +
    1.24 +function onLoad(aEvent) {
    1.25 +  browser.removeEventListener(aEvent.type, onLoad, true);
    1.26 +
    1.27 +  openConsole(null, function(aHud) {
    1.28 +    aHud.jsterm.clearOutput();
    1.29 +    hud = aHud;
    1.30 +    outputNode = aHud.outputNode;
    1.31 +
    1.32 +    browser.addEventListener("load", testWebDevLimits, true);
    1.33 +    expectUncaughtException();
    1.34 +    content.location = TEST_URI;
    1.35 +  });
    1.36 +}
    1.37 +
    1.38 +function testWebDevLimits(aEvent) {
    1.39 +  browser.removeEventListener(aEvent.type, testWebDevLimits, true);
    1.40 +  Services.prefs.setIntPref("devtools.hud.loglimit.console", 10);
    1.41 +
    1.42 +  // Find the sentinel entry.
    1.43 +  waitForMessages({
    1.44 +    webconsole: hud,
    1.45 +    messages: [{
    1.46 +      text: "bar is not defined",
    1.47 +      category: CATEGORY_JS,
    1.48 +      severity: SEVERITY_ERROR,
    1.49 +    }],
    1.50 +  }).then(testWebDevLimits2);
    1.51 +}
    1.52 +
    1.53 +function testWebDevLimits2() {
    1.54 +  // Fill the log with Web Developer errors.
    1.55 +  for (let i = 0; i < 11; i++) {
    1.56 +    content.console.log("test message " + i);
    1.57 +  }
    1.58 +
    1.59 +  waitForMessages({
    1.60 +    webconsole: hud,
    1.61 +    messages: [{
    1.62 +      text: "test message 10",
    1.63 +      category: CATEGORY_WEBDEV,
    1.64 +      severity: SEVERITY_LOG,
    1.65 +    }],
    1.66 +  }).then(() => {
    1.67 +    testLogEntry(outputNode, "test message 0", "first message is pruned", false, true);
    1.68 +    findLogEntry("test message 1");
    1.69 +    // Check if the sentinel entry is still there.
    1.70 +    findLogEntry("bar is not defined");
    1.71 +
    1.72 +    Services.prefs.clearUserPref("devtools.hud.loglimit.console");
    1.73 +    testJsLimits();
    1.74 +  });
    1.75 +}
    1.76 +
    1.77 +function testJsLimits() {
    1.78 +  Services.prefs.setIntPref("devtools.hud.loglimit.exception", 10);
    1.79 +
    1.80 +  hud.jsterm.clearOutput();
    1.81 +  content.console.log("testing JS limits");
    1.82 +
    1.83 +  // Find the sentinel entry.
    1.84 +  waitForMessages({
    1.85 +    webconsole: hud,
    1.86 +    messages: [{
    1.87 +      text: "testing JS limits",
    1.88 +      category: CATEGORY_WEBDEV,
    1.89 +      severity: SEVERITY_LOG,
    1.90 +    }],
    1.91 +  }).then(testJsLimits2);
    1.92 +}
    1.93 +
    1.94 +function testJsLimits2() {
    1.95 +  // Fill the log with JS errors.
    1.96 +  let head = content.document.getElementsByTagName("head")[0];
    1.97 +  for (let i = 0; i < 11; i++) {
    1.98 +    var script = content.document.createElement("script");
    1.99 +    script.text = "fubar" + i + ".bogus(6);";
   1.100 +    expectUncaughtException();
   1.101 +    head.insertBefore(script, head.firstChild);
   1.102 +  }
   1.103 +
   1.104 +  waitForMessages({
   1.105 +    webconsole: hud,
   1.106 +    messages: [{
   1.107 +      text: "fubar10 is not defined",
   1.108 +      category: CATEGORY_JS,
   1.109 +      severity: SEVERITY_ERROR,
   1.110 +    }],
   1.111 +  }).then(() => {
   1.112 +    testLogEntry(outputNode, "fubar0 is not defined", "first message is pruned", false, true);
   1.113 +    findLogEntry("fubar1 is not defined");
   1.114 +    // Check if the sentinel entry is still there.
   1.115 +    findLogEntry("testing JS limits");
   1.116 +
   1.117 +    Services.prefs.clearUserPref("devtools.hud.loglimit.exception");
   1.118 +    testNetLimits();
   1.119 +  });
   1.120 +}
   1.121 +
   1.122 +var gCounter, gImage;
   1.123 +
   1.124 +function testNetLimits() {
   1.125 +  Services.prefs.setIntPref("devtools.hud.loglimit.network", 10);
   1.126 +
   1.127 +  hud.jsterm.clearOutput();
   1.128 +  content.console.log("testing Net limits");
   1.129 +
   1.130 +  // Find the sentinel entry.
   1.131 +  waitForMessages({
   1.132 +    webconsole: hud,
   1.133 +    messages: [{
   1.134 +      text: "testing Net limits",
   1.135 +      category: CATEGORY_WEBDEV,
   1.136 +      severity: SEVERITY_LOG,
   1.137 +    }],
   1.138 +  }).then(() => {
   1.139 +    // Fill the log with network messages.
   1.140 +    gCounter = 0;
   1.141 +    loadImage();
   1.142 +  });
   1.143 +}
   1.144 +
   1.145 +function loadImage() {
   1.146 +  if (gCounter < 11) {
   1.147 +    let body = content.document.getElementsByTagName("body")[0];
   1.148 +    gImage && gImage.removeEventListener("load", loadImage, true);
   1.149 +    gImage = content.document.createElement("img");
   1.150 +    gImage.src = "test-image.png?_fubar=" + gCounter;
   1.151 +    body.insertBefore(gImage, body.firstChild);
   1.152 +    gImage.addEventListener("load", loadImage, true);
   1.153 +    gCounter++;
   1.154 +    return;
   1.155 +  }
   1.156 +
   1.157 +  is(gCounter, 11, "loaded 11 files");
   1.158 +
   1.159 +  waitForMessages({
   1.160 +    webconsole: hud,
   1.161 +    messages: [{
   1.162 +      text: "test-image.png",
   1.163 +      url: "test-image.png?_fubar=10",
   1.164 +      category: CATEGORY_NETWORK,
   1.165 +      severity: SEVERITY_LOG,
   1.166 +    }],
   1.167 +  }).then(() => {
   1.168 +    let msgs = outputNode.querySelectorAll(".message[category=network]");
   1.169 +    is(msgs.length, 10, "number of network messages");
   1.170 +    isnot(msgs[0].url.indexOf("fubar=1"), -1, "first network message");
   1.171 +    isnot(msgs[1].url.indexOf("fubar=2"), -1, "second network message");
   1.172 +    findLogEntry("testing Net limits");
   1.173 +
   1.174 +    Services.prefs.clearUserPref("devtools.hud.loglimit.network");
   1.175 +    testCssLimits();
   1.176 +  });
   1.177 +}
   1.178 +
   1.179 +function testCssLimits() {
   1.180 +  Services.prefs.setIntPref("devtools.hud.loglimit.cssparser", 10);
   1.181 +
   1.182 +  hud.jsterm.clearOutput();
   1.183 +  content.console.log("testing CSS limits");
   1.184 +
   1.185 +  // Find the sentinel entry.
   1.186 +  waitForMessages({
   1.187 +    webconsole: hud,
   1.188 +    messages: [{
   1.189 +      text: "testing CSS limits",
   1.190 +      category: CATEGORY_WEBDEV,
   1.191 +      severity: SEVERITY_LOG,
   1.192 +    }],
   1.193 +  }).then(testCssLimits2);
   1.194 +}
   1.195 +
   1.196 +function testCssLimits2() {
   1.197 +  // Fill the log with CSS errors.
   1.198 +  let body = content.document.getElementsByTagName("body")[0];
   1.199 +  for (let i = 0; i < 11; i++) {
   1.200 +    var div = content.document.createElement("div");
   1.201 +    div.setAttribute("style", "-moz-foobar" + i + ": 42;");
   1.202 +    body.insertBefore(div, body.firstChild);
   1.203 +  }
   1.204 +
   1.205 +  waitForMessages({
   1.206 +    webconsole: hud,
   1.207 +    messages: [{
   1.208 +      text: "-moz-foobar10",
   1.209 +      category: CATEGORY_CSS,
   1.210 +      severity: SEVERITY_WARNING,
   1.211 +    }],
   1.212 +  }).then(() => {
   1.213 +    testLogEntry(outputNode, "Unknown property '-moz-foobar0'",
   1.214 +                 "first message is pruned", false, true);
   1.215 +    findLogEntry("Unknown property '-moz-foobar1'");
   1.216 +    // Check if the sentinel entry is still there.
   1.217 +    findLogEntry("testing CSS limits");
   1.218 +
   1.219 +    Services.prefs.clearUserPref("devtools.hud.loglimit.cssparser");
   1.220 +    finishTest();
   1.221 +  });
   1.222 +}

mercurial