|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 // Test that Console.jsm outputs messages to the Browser Console, bug 851231. |
|
7 |
|
8 function test() |
|
9 { |
|
10 let storage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(Ci.nsIConsoleAPIStorage); |
|
11 storage.clearEvents(); |
|
12 |
|
13 let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console; |
|
14 console.log("bug861338-log-cached"); |
|
15 |
|
16 HUDService.toggleBrowserConsole().then(consoleOpened); |
|
17 let hud = null; |
|
18 |
|
19 function consoleOpened(aHud) |
|
20 { |
|
21 hud = aHud; |
|
22 waitForMessages({ |
|
23 webconsole: hud, |
|
24 messages: [{ |
|
25 name: "cached console.log message", |
|
26 text: "bug861338-log-cached", |
|
27 category: CATEGORY_WEBDEV, |
|
28 severity: SEVERITY_LOG, |
|
29 }], |
|
30 }).then(onCachedMessage); |
|
31 } |
|
32 |
|
33 function onCachedMessage() |
|
34 { |
|
35 hud.jsterm.clearOutput(true); |
|
36 |
|
37 console.time("foobarTimer"); |
|
38 let foobar = { bug851231prop: "bug851231value" }; |
|
39 |
|
40 console.log("bug851231-log"); |
|
41 console.info("bug851231-info"); |
|
42 console.warn("bug851231-warn"); |
|
43 console.error("bug851231-error", foobar); |
|
44 console.debug("bug851231-debug"); |
|
45 console.trace(); |
|
46 console.dir(document); |
|
47 console.timeEnd("foobarTimer"); |
|
48 |
|
49 info("wait for the Console.jsm messages"); |
|
50 |
|
51 waitForMessages({ |
|
52 webconsole: hud, |
|
53 messages: [ |
|
54 { |
|
55 name: "console.log output", |
|
56 text: "bug851231-log", |
|
57 category: CATEGORY_WEBDEV, |
|
58 severity: SEVERITY_LOG, |
|
59 }, |
|
60 { |
|
61 name: "console.info output", |
|
62 text: "bug851231-info", |
|
63 category: CATEGORY_WEBDEV, |
|
64 severity: SEVERITY_INFO, |
|
65 }, |
|
66 { |
|
67 name: "console.warn output", |
|
68 text: "bug851231-warn", |
|
69 category: CATEGORY_WEBDEV, |
|
70 severity: SEVERITY_WARNING, |
|
71 }, |
|
72 { |
|
73 name: "console.error output", |
|
74 text: /\bbug851231-error\b.+\{\s*bug851231prop:\s"bug851231value"\s*\}/, |
|
75 category: CATEGORY_WEBDEV, |
|
76 severity: SEVERITY_ERROR, |
|
77 objects: true, |
|
78 }, |
|
79 { |
|
80 name: "console.debug output", |
|
81 text: "bug851231-debug", |
|
82 category: CATEGORY_WEBDEV, |
|
83 severity: SEVERITY_LOG, |
|
84 }, |
|
85 { |
|
86 name: "console.trace output", |
|
87 consoleTrace: { |
|
88 file: "browser_console_consolejsm_output.js", |
|
89 fn: "onCachedMessage", |
|
90 }, |
|
91 }, |
|
92 { |
|
93 name: "console.dir output", |
|
94 consoleDir: /XULDocument\s+.+\s+chrome:\/\/.+\/browser\.xul/, |
|
95 }, |
|
96 { |
|
97 name: "console.time output", |
|
98 consoleTime: "foobarTimer", |
|
99 }, |
|
100 { |
|
101 name: "console.timeEnd output", |
|
102 consoleTimeEnd: "foobarTimer", |
|
103 }, |
|
104 ], |
|
105 }).then((aResults) => { |
|
106 let consoleErrorMsg = aResults[3]; |
|
107 ok(consoleErrorMsg, "console.error message element found"); |
|
108 let clickable = consoleErrorMsg.clickableElements[0]; |
|
109 ok(clickable, "clickable object found for console.error"); |
|
110 |
|
111 let onFetch = (aEvent, aVar) => { |
|
112 // Skip the notification from console.dir variablesview-fetched. |
|
113 if (aVar._variablesView != hud.jsterm._variablesView) { |
|
114 return; |
|
115 } |
|
116 hud.jsterm.off("variablesview-fetched", onFetch); |
|
117 |
|
118 ok(aVar, "object inspector opened on click"); |
|
119 |
|
120 findVariableViewProperties(aVar, [{ |
|
121 name: "bug851231prop", |
|
122 value: "bug851231value", |
|
123 }], { webconsole: hud }).then(finishTest); |
|
124 }; |
|
125 |
|
126 hud.jsterm.on("variablesview-fetched", onFetch); |
|
127 |
|
128 clickable.scrollIntoView(false); |
|
129 |
|
130 info("wait for variablesview-fetched"); |
|
131 executeSoon(() => |
|
132 EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow)); |
|
133 }); |
|
134 } |
|
135 } |