|
| 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 | + HUDConsoleUI.toggleBrowserConsole().then(consoleOpened); |
| 11 | + let hud = null; |
| 12 | + |
| 13 | + function consoleOpened(aHud) |
| 14 | + { |
| 15 | + hud = aHud; |
| 16 | + hud.jsterm.clearOutput(true); |
| 17 | + |
| 18 | + let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console; |
| 19 | + |
| 20 | + console.time("foobarTimer"); |
| 21 | + let foobar = { bug851231prop: "bug851231value" }; |
| 22 | + |
| 23 | + console.log("bug851231-log"); |
| 24 | + console.info("bug851231-info"); |
| 25 | + console.warn("bug851231-warn"); |
| 26 | + console.error("bug851231-error", foobar); |
| 27 | + console.debug("bug851231-debug"); |
| 28 | + console.trace(); |
| 29 | + console.dir(document); |
| 30 | + console.timeEnd("foobarTimer"); |
| 31 | + |
| 32 | + info("wait for the Console.jsm messages"); |
| 33 | + |
| 34 | + waitForMessages({ |
| 35 | + webconsole: hud, |
| 36 | + messages: [ |
| 37 | + { |
| 38 | + name: "console.log output", |
| 39 | + text: "bug851231-log", |
| 40 | + category: CATEGORY_WEBDEV, |
| 41 | + severity: SEVERITY_LOG, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "console.info output", |
| 45 | + text: "bug851231-info", |
| 46 | + category: CATEGORY_WEBDEV, |
| 47 | + severity: SEVERITY_INFO, |
| 48 | + }, |
| 49 | + { |
| 50 | + name: "console.warn output", |
| 51 | + text: "bug851231-warn", |
| 52 | + category: CATEGORY_WEBDEV, |
| 53 | + severity: SEVERITY_WARNING, |
| 54 | + }, |
| 55 | + { |
| 56 | + name: "console.error output", |
| 57 | + text: /\bbug851231-error\b.+\[object Object\]/, |
| 58 | + category: CATEGORY_WEBDEV, |
| 59 | + severity: SEVERITY_ERROR, |
| 60 | + objects: true, |
| 61 | + }, |
| 62 | + { |
| 63 | + name: "console.debug output", |
| 64 | + text: "bug851231-debug", |
| 65 | + category: CATEGORY_WEBDEV, |
| 66 | + severity: SEVERITY_LOG, |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "console.trace output", |
| 70 | + consoleTrace: { |
| 71 | + file: "browser_console_consolejsm_output.js", |
| 72 | + fn: "consoleOpened", |
| 73 | + }, |
| 74 | + }, |
| 75 | + { |
| 76 | + name: "console.dir output", |
| 77 | + consoleDir: "[object XULDocument]", |
| 78 | + }, |
| 79 | + { |
| 80 | + name: "console.time output", |
| 81 | + consoleTime: "foobarTimer", |
| 82 | + }, |
| 83 | + { |
| 84 | + name: "console.timeEnd output", |
| 85 | + consoleTimeEnd: "foobarTimer", |
| 86 | + }, |
| 87 | + ], |
| 88 | + }).then((aResults) => { |
| 89 | + let consoleErrorMsg = aResults[3]; |
| 90 | + ok(consoleErrorMsg, "console.error message element found"); |
| 91 | + let clickable = consoleErrorMsg.clickableElements[0]; |
| 92 | + ok(clickable, "clickable object found for console.error"); |
| 93 | + |
| 94 | + let onFetch = (aEvent, aVar) => { |
| 95 | + // Skip the notification from console.dir variablesview-fetched. |
| 96 | + if (aVar._variablesView != hud.jsterm._variablesView) { |
| 97 | + return; |
| 98 | + } |
| 99 | + hud.jsterm.off("variablesview-fetched", onFetch); |
| 100 | + |
| 101 | + ok(aVar, "object inspector opened on click"); |
| 102 | + |
| 103 | + findVariableViewProperties(aVar, [{ |
| 104 | + name: "bug851231prop", |
| 105 | + value: "bug851231value", |
| 106 | + }], { webconsole: hud }).then(finishTest); |
| 107 | + }; |
| 108 | + |
| 109 | + hud.jsterm.on("variablesview-fetched", onFetch); |
| 110 | + |
| 111 | + scrollOutputToNode(clickable); |
| 112 | + |
| 113 | + info("wait for variablesview-fetched"); |
| 114 | + executeSoon(() => |
| 115 | + EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow)); |
| 116 | + }); |
| 117 | + } |
| 118 | +} |
0 commit comments