michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Test that Console.jsm outputs messages to the Browser Console, bug 851231. michael@0: michael@0: function test() michael@0: { michael@0: let storage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(Ci.nsIConsoleAPIStorage); michael@0: storage.clearEvents(); michael@0: michael@0: let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console; michael@0: console.log("bug861338-log-cached"); michael@0: michael@0: HUDService.toggleBrowserConsole().then(consoleOpened); michael@0: let hud = null; michael@0: michael@0: function consoleOpened(aHud) michael@0: { michael@0: hud = aHud; michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: name: "cached console.log message", michael@0: text: "bug861338-log-cached", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(onCachedMessage); michael@0: } michael@0: michael@0: function onCachedMessage() michael@0: { michael@0: hud.jsterm.clearOutput(true); michael@0: michael@0: console.time("foobarTimer"); michael@0: let foobar = { bug851231prop: "bug851231value" }; michael@0: michael@0: console.log("bug851231-log"); michael@0: console.info("bug851231-info"); michael@0: console.warn("bug851231-warn"); michael@0: console.error("bug851231-error", foobar); michael@0: console.debug("bug851231-debug"); michael@0: console.trace(); michael@0: console.dir(document); michael@0: console.timeEnd("foobarTimer"); michael@0: michael@0: info("wait for the Console.jsm messages"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [ michael@0: { michael@0: name: "console.log output", michael@0: text: "bug851231-log", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }, michael@0: { michael@0: name: "console.info output", michael@0: text: "bug851231-info", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_INFO, michael@0: }, michael@0: { michael@0: name: "console.warn output", michael@0: text: "bug851231-warn", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_WARNING, michael@0: }, michael@0: { michael@0: name: "console.error output", michael@0: text: /\bbug851231-error\b.+\{\s*bug851231prop:\s"bug851231value"\s*\}/, michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_ERROR, michael@0: objects: true, michael@0: }, michael@0: { michael@0: name: "console.debug output", michael@0: text: "bug851231-debug", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }, michael@0: { michael@0: name: "console.trace output", michael@0: consoleTrace: { michael@0: file: "browser_console_consolejsm_output.js", michael@0: fn: "onCachedMessage", michael@0: }, michael@0: }, michael@0: { michael@0: name: "console.dir output", michael@0: consoleDir: /XULDocument\s+.+\s+chrome:\/\/.+\/browser\.xul/, michael@0: }, michael@0: { michael@0: name: "console.time output", michael@0: consoleTime: "foobarTimer", michael@0: }, michael@0: { michael@0: name: "console.timeEnd output", michael@0: consoleTimeEnd: "foobarTimer", michael@0: }, michael@0: ], michael@0: }).then((aResults) => { michael@0: let consoleErrorMsg = aResults[3]; michael@0: ok(consoleErrorMsg, "console.error message element found"); michael@0: let clickable = consoleErrorMsg.clickableElements[0]; michael@0: ok(clickable, "clickable object found for console.error"); michael@0: michael@0: let onFetch = (aEvent, aVar) => { michael@0: // Skip the notification from console.dir variablesview-fetched. michael@0: if (aVar._variablesView != hud.jsterm._variablesView) { michael@0: return; michael@0: } michael@0: hud.jsterm.off("variablesview-fetched", onFetch); michael@0: michael@0: ok(aVar, "object inspector opened on click"); michael@0: michael@0: findVariableViewProperties(aVar, [{ michael@0: name: "bug851231prop", michael@0: value: "bug851231value", michael@0: }], { webconsole: hud }).then(finishTest); michael@0: }; michael@0: michael@0: hud.jsterm.on("variablesview-fetched", onFetch); michael@0: michael@0: clickable.scrollIntoView(false); michael@0: michael@0: info("wait for variablesview-fetched"); michael@0: executeSoon(() => michael@0: EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow)); michael@0: }); michael@0: } michael@0: }