browser/devtools/webconsole/test/browser_webconsole_console_logging_api.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // Tests that the basic console.log()-style APIs and filtering work.
michael@0 7
michael@0 8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
michael@0 9
michael@0 10 let hud, outputNode;
michael@0 11
michael@0 12 function test() {
michael@0 13 addTab(TEST_URI);
michael@0 14 browser.addEventListener("load", function onLoad() {
michael@0 15 browser.removeEventListener("load", onLoad, true);
michael@0 16 Task.spawn(runner);
michael@0 17 }, true);
michael@0 18
michael@0 19 function* runner() {
michael@0 20 hud = yield openConsole();
michael@0 21 outputNode = hud.outputNode;
michael@0 22
michael@0 23 let methods = ["log", "info", "warn", "error", "exception", "debug"];
michael@0 24 for (let method of methods) {
michael@0 25 yield testMethod(method);
michael@0 26 }
michael@0 27
michael@0 28 executeSoon(finishTest);
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 function* testMethod(aMethod) {
michael@0 33 let console = content.console;
michael@0 34
michael@0 35 hud.jsterm.clearOutput();
michael@0 36
michael@0 37 console[aMethod]("foo-bar-baz");
michael@0 38 console[aMethod]("baar-baz");
michael@0 39
michael@0 40 yield waitForMessages({
michael@0 41 webconsole: hud,
michael@0 42 messages: [{
michael@0 43 text: "foo-bar-baz",
michael@0 44 }, {
michael@0 45 text: "baar-baz",
michael@0 46 }],
michael@0 47 });
michael@0 48
michael@0 49 setStringFilter("foo");
michael@0 50
michael@0 51 is(outputNode.querySelectorAll(".filtered-by-string").length, 1,
michael@0 52 "1 hidden " + aMethod + " node via string filtering")
michael@0 53
michael@0 54 hud.jsterm.clearOutput();
michael@0 55
michael@0 56 // now toggle the current method off - make sure no visible message
michael@0 57 // TODO: move all filtering tests into a separate test file: see bug 608135
michael@0 58
michael@0 59 console[aMethod]("foo-bar-baz");
michael@0 60 yield waitForMessages({
michael@0 61 webconsole: hud,
michael@0 62 messages: [{
michael@0 63 text: "foo-bar-baz",
michael@0 64 }],
michael@0 65 });
michael@0 66
michael@0 67 setStringFilter("");
michael@0 68 let filter;
michael@0 69 switch(aMethod) {
michael@0 70 case "debug":
michael@0 71 filter = "log";
michael@0 72 break;
michael@0 73 case "exception":
michael@0 74 filter = "error";
michael@0 75 break;
michael@0 76 default:
michael@0 77 filter = aMethod;
michael@0 78 break;
michael@0 79 }
michael@0 80
michael@0 81 hud.setFilterState(filter, false);
michael@0 82
michael@0 83 is(outputNode.querySelectorAll(".filtered-by-type").length, 1,
michael@0 84 "1 message hidden for " + aMethod + " (logging turned off)")
michael@0 85
michael@0 86 hud.setFilterState(filter, true);
michael@0 87
michael@0 88 is(outputNode.querySelectorAll(".message:not(.filtered-by-type)").length, 1,
michael@0 89 "1 message shown for " + aMethod + " (logging turned on)")
michael@0 90
michael@0 91 hud.jsterm.clearOutput();
michael@0 92
michael@0 93 // test for multiple arguments.
michael@0 94 console[aMethod]("foo", "bar");
michael@0 95
michael@0 96 yield waitForMessages({
michael@0 97 webconsole: hud,
michael@0 98 messages: [{
michael@0 99 text: '"foo" "bar"',
michael@0 100 category: CATEGORY_WEBDEV,
michael@0 101 }],
michael@0 102 })
michael@0 103 }
michael@0 104
michael@0 105 function setStringFilter(aValue) {
michael@0 106 hud.ui.filterBox.value = aValue;
michael@0 107 hud.ui.adjustVisibilityOnSearchStringChange();
michael@0 108 }
michael@0 109

mercurial