1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_console_logging_api.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// Tests that the basic console.log()-style APIs and filtering work. 1.10 + 1.11 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; 1.12 + 1.13 +let hud, outputNode; 1.14 + 1.15 +function test() { 1.16 + addTab(TEST_URI); 1.17 + browser.addEventListener("load", function onLoad() { 1.18 + browser.removeEventListener("load", onLoad, true); 1.19 + Task.spawn(runner); 1.20 + }, true); 1.21 + 1.22 + function* runner() { 1.23 + hud = yield openConsole(); 1.24 + outputNode = hud.outputNode; 1.25 + 1.26 + let methods = ["log", "info", "warn", "error", "exception", "debug"]; 1.27 + for (let method of methods) { 1.28 + yield testMethod(method); 1.29 + } 1.30 + 1.31 + executeSoon(finishTest); 1.32 + } 1.33 +} 1.34 + 1.35 +function* testMethod(aMethod) { 1.36 + let console = content.console; 1.37 + 1.38 + hud.jsterm.clearOutput(); 1.39 + 1.40 + console[aMethod]("foo-bar-baz"); 1.41 + console[aMethod]("baar-baz"); 1.42 + 1.43 + yield waitForMessages({ 1.44 + webconsole: hud, 1.45 + messages: [{ 1.46 + text: "foo-bar-baz", 1.47 + }, { 1.48 + text: "baar-baz", 1.49 + }], 1.50 + }); 1.51 + 1.52 + setStringFilter("foo"); 1.53 + 1.54 + is(outputNode.querySelectorAll(".filtered-by-string").length, 1, 1.55 + "1 hidden " + aMethod + " node via string filtering") 1.56 + 1.57 + hud.jsterm.clearOutput(); 1.58 + 1.59 + // now toggle the current method off - make sure no visible message 1.60 + // TODO: move all filtering tests into a separate test file: see bug 608135 1.61 + 1.62 + console[aMethod]("foo-bar-baz"); 1.63 + yield waitForMessages({ 1.64 + webconsole: hud, 1.65 + messages: [{ 1.66 + text: "foo-bar-baz", 1.67 + }], 1.68 + }); 1.69 + 1.70 + setStringFilter(""); 1.71 + let filter; 1.72 + switch(aMethod) { 1.73 + case "debug": 1.74 + filter = "log"; 1.75 + break; 1.76 + case "exception": 1.77 + filter = "error"; 1.78 + break; 1.79 + default: 1.80 + filter = aMethod; 1.81 + break; 1.82 + } 1.83 + 1.84 + hud.setFilterState(filter, false); 1.85 + 1.86 + is(outputNode.querySelectorAll(".filtered-by-type").length, 1, 1.87 + "1 message hidden for " + aMethod + " (logging turned off)") 1.88 + 1.89 + hud.setFilterState(filter, true); 1.90 + 1.91 + is(outputNode.querySelectorAll(".message:not(.filtered-by-type)").length, 1, 1.92 + "1 message shown for " + aMethod + " (logging turned on)") 1.93 + 1.94 + hud.jsterm.clearOutput(); 1.95 + 1.96 + // test for multiple arguments. 1.97 + console[aMethod]("foo", "bar"); 1.98 + 1.99 + yield waitForMessages({ 1.100 + webconsole: hud, 1.101 + messages: [{ 1.102 + text: '"foo" "bar"', 1.103 + category: CATEGORY_WEBDEV, 1.104 + }], 1.105 + }) 1.106 +} 1.107 + 1.108 +function setStringFilter(aValue) { 1.109 + hud.ui.filterBox.value = aValue; 1.110 + hud.ui.adjustVisibilityOnSearchStringChange(); 1.111 +} 1.112 +