1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_585237_line_limit.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.5 +/* ***** BEGIN LICENSE BLOCK ***** 1.6 + * Any copyright is dedicated to the Public Domain. 1.7 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.8 + * 1.9 + * Contributor(s): 1.10 + * Patrick Walton <pcwalton@mozilla.com> 1.11 + * Mihai Șucan <mihai.sucan@gmail.com> 1.12 + * 1.13 + * ***** END LICENSE BLOCK ***** */ 1.14 + 1.15 +// Tests that the Web Console limits the number of lines displayed according to 1.16 +// the user's preferences. 1.17 + 1.18 +const TEST_URI = "data:text/html;charset=utf8,test for bug 585237"; 1.19 +let hud, testDriver; 1.20 + 1.21 +function test() { 1.22 + addTab(TEST_URI); 1.23 + browser.addEventListener("load", function onLoad() { 1.24 + browser.removeEventListener("load", onLoad, true); 1.25 + openConsole(null, function(aHud) { 1.26 + hud = aHud; 1.27 + testDriver = testGen(); 1.28 + testNext(); 1.29 + }); 1.30 + }, true); 1.31 +} 1.32 + 1.33 +function testNext() { 1.34 + testDriver.next(); 1.35 +} 1.36 + 1.37 +function testGen() { 1.38 + let console = content.console; 1.39 + outputNode = hud.outputNode; 1.40 + 1.41 + hud.jsterm.clearOutput(); 1.42 + 1.43 + let prefBranch = Services.prefs.getBranch("devtools.hud.loglimit."); 1.44 + prefBranch.setIntPref("console", 20); 1.45 + 1.46 + for (let i = 0; i < 30; i++) { 1.47 + console.log("foo #" + i); // must change message to prevent repeats 1.48 + } 1.49 + 1.50 + waitForMessages({ 1.51 + webconsole: hud, 1.52 + messages: [{ 1.53 + text: "foo #29", 1.54 + category: CATEGORY_WEBDEV, 1.55 + severity: SEVERITY_LOG, 1.56 + }], 1.57 + }).then(testNext); 1.58 + 1.59 + yield undefined; 1.60 + 1.61 + is(countMessageNodes(), 20, "there are 20 message nodes in the output " + 1.62 + "when the log limit is set to 20"); 1.63 + 1.64 + console.log("bar bug585237"); 1.65 + 1.66 + waitForMessages({ 1.67 + webconsole: hud, 1.68 + messages: [{ 1.69 + text: "bar bug585237", 1.70 + category: CATEGORY_WEBDEV, 1.71 + severity: SEVERITY_LOG, 1.72 + }], 1.73 + }).then(testNext); 1.74 + 1.75 + yield undefined; 1.76 + 1.77 + is(countMessageNodes(), 20, "there are still 20 message nodes in the " + 1.78 + "output when adding one more"); 1.79 + 1.80 + prefBranch.setIntPref("console", 30); 1.81 + for (let i = 0; i < 20; i++) { 1.82 + console.log("boo #" + i); // must change message to prevent repeats 1.83 + } 1.84 + 1.85 + waitForMessages({ 1.86 + webconsole: hud, 1.87 + messages: [{ 1.88 + text: "boo #19", 1.89 + category: CATEGORY_WEBDEV, 1.90 + severity: SEVERITY_LOG, 1.91 + }], 1.92 + }).then(testNext); 1.93 + 1.94 + yield undefined; 1.95 + 1.96 + is(countMessageNodes(), 30, "there are 30 message nodes in the output " + 1.97 + "when the log limit is set to 30"); 1.98 + 1.99 + prefBranch.clearUserPref("console"); 1.100 + hud = testDriver = prefBranch = console = outputNode = null; 1.101 + finishTest(); 1.102 + 1.103 + yield undefined; 1.104 +} 1.105 + 1.106 +function countMessageNodes() { 1.107 + return outputNode.querySelectorAll(".message").length; 1.108 +} 1.109 +