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