|
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/. */ |
|
5 |
|
6 // Tests that the basic console.log()-style APIs and filtering work. |
|
7 |
|
8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; |
|
9 |
|
10 let hud, outputNode; |
|
11 |
|
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); |
|
18 |
|
19 function* runner() { |
|
20 hud = yield openConsole(); |
|
21 outputNode = hud.outputNode; |
|
22 |
|
23 let methods = ["log", "info", "warn", "error", "exception", "debug"]; |
|
24 for (let method of methods) { |
|
25 yield testMethod(method); |
|
26 } |
|
27 |
|
28 executeSoon(finishTest); |
|
29 } |
|
30 } |
|
31 |
|
32 function* testMethod(aMethod) { |
|
33 let console = content.console; |
|
34 |
|
35 hud.jsterm.clearOutput(); |
|
36 |
|
37 console[aMethod]("foo-bar-baz"); |
|
38 console[aMethod]("baar-baz"); |
|
39 |
|
40 yield waitForMessages({ |
|
41 webconsole: hud, |
|
42 messages: [{ |
|
43 text: "foo-bar-baz", |
|
44 }, { |
|
45 text: "baar-baz", |
|
46 }], |
|
47 }); |
|
48 |
|
49 setStringFilter("foo"); |
|
50 |
|
51 is(outputNode.querySelectorAll(".filtered-by-string").length, 1, |
|
52 "1 hidden " + aMethod + " node via string filtering") |
|
53 |
|
54 hud.jsterm.clearOutput(); |
|
55 |
|
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 |
|
58 |
|
59 console[aMethod]("foo-bar-baz"); |
|
60 yield waitForMessages({ |
|
61 webconsole: hud, |
|
62 messages: [{ |
|
63 text: "foo-bar-baz", |
|
64 }], |
|
65 }); |
|
66 |
|
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 } |
|
80 |
|
81 hud.setFilterState(filter, false); |
|
82 |
|
83 is(outputNode.querySelectorAll(".filtered-by-type").length, 1, |
|
84 "1 message hidden for " + aMethod + " (logging turned off)") |
|
85 |
|
86 hud.setFilterState(filter, true); |
|
87 |
|
88 is(outputNode.querySelectorAll(".message:not(.filtered-by-type)").length, 1, |
|
89 "1 message shown for " + aMethod + " (logging turned on)") |
|
90 |
|
91 hud.jsterm.clearOutput(); |
|
92 |
|
93 // test for multiple arguments. |
|
94 console[aMethod]("foo", "bar"); |
|
95 |
|
96 yield waitForMessages({ |
|
97 webconsole: hud, |
|
98 messages: [{ |
|
99 text: '"foo" "bar"', |
|
100 category: CATEGORY_WEBDEV, |
|
101 }], |
|
102 }) |
|
103 } |
|
104 |
|
105 function setStringFilter(aValue) { |
|
106 hud.ui.filterBox.value = aValue; |
|
107 hud.ui.adjustVisibilityOnSearchStringChange(); |
|
108 } |
|
109 |