michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests that the basic console.log()-style APIs and filtering work. michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; michael@0: michael@0: let hud, outputNode; michael@0: michael@0: function test() { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: Task.spawn(runner); michael@0: }, true); michael@0: michael@0: function* runner() { michael@0: hud = yield openConsole(); michael@0: outputNode = hud.outputNode; michael@0: michael@0: let methods = ["log", "info", "warn", "error", "exception", "debug"]; michael@0: for (let method of methods) { michael@0: yield testMethod(method); michael@0: } michael@0: michael@0: executeSoon(finishTest); michael@0: } michael@0: } michael@0: michael@0: function* testMethod(aMethod) { michael@0: let console = content.console; michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: console[aMethod]("foo-bar-baz"); michael@0: console[aMethod]("baar-baz"); michael@0: michael@0: yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "foo-bar-baz", michael@0: }, { michael@0: text: "baar-baz", michael@0: }], michael@0: }); michael@0: michael@0: setStringFilter("foo"); michael@0: michael@0: is(outputNode.querySelectorAll(".filtered-by-string").length, 1, michael@0: "1 hidden " + aMethod + " node via string filtering") michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: // now toggle the current method off - make sure no visible message michael@0: // TODO: move all filtering tests into a separate test file: see bug 608135 michael@0: michael@0: console[aMethod]("foo-bar-baz"); michael@0: yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "foo-bar-baz", michael@0: }], michael@0: }); michael@0: michael@0: setStringFilter(""); michael@0: let filter; michael@0: switch(aMethod) { michael@0: case "debug": michael@0: filter = "log"; michael@0: break; michael@0: case "exception": michael@0: filter = "error"; michael@0: break; michael@0: default: michael@0: filter = aMethod; michael@0: break; michael@0: } michael@0: michael@0: hud.setFilterState(filter, false); michael@0: michael@0: is(outputNode.querySelectorAll(".filtered-by-type").length, 1, michael@0: "1 message hidden for " + aMethod + " (logging turned off)") michael@0: michael@0: hud.setFilterState(filter, true); michael@0: michael@0: is(outputNode.querySelectorAll(".message:not(.filtered-by-type)").length, 1, michael@0: "1 message shown for " + aMethod + " (logging turned on)") michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: // test for multiple arguments. michael@0: console[aMethod]("foo", "bar"); michael@0: michael@0: yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: '"foo" "bar"', michael@0: category: CATEGORY_WEBDEV, michael@0: }], michael@0: }) michael@0: } michael@0: michael@0: function setStringFilter(aValue) { michael@0: hud.ui.filterBox.value = aValue; michael@0: hud.ui.adjustVisibilityOnSearchStringChange(); michael@0: } michael@0: