1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_console_consolejsm_output.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,135 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Test that Console.jsm outputs messages to the Browser Console, bug 851231. 1.10 + 1.11 +function test() 1.12 +{ 1.13 + let storage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(Ci.nsIConsoleAPIStorage); 1.14 + storage.clearEvents(); 1.15 + 1.16 + let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console; 1.17 + console.log("bug861338-log-cached"); 1.18 + 1.19 + HUDService.toggleBrowserConsole().then(consoleOpened); 1.20 + let hud = null; 1.21 + 1.22 + function consoleOpened(aHud) 1.23 + { 1.24 + hud = aHud; 1.25 + waitForMessages({ 1.26 + webconsole: hud, 1.27 + messages: [{ 1.28 + name: "cached console.log message", 1.29 + text: "bug861338-log-cached", 1.30 + category: CATEGORY_WEBDEV, 1.31 + severity: SEVERITY_LOG, 1.32 + }], 1.33 + }).then(onCachedMessage); 1.34 + } 1.35 + 1.36 + function onCachedMessage() 1.37 + { 1.38 + hud.jsterm.clearOutput(true); 1.39 + 1.40 + console.time("foobarTimer"); 1.41 + let foobar = { bug851231prop: "bug851231value" }; 1.42 + 1.43 + console.log("bug851231-log"); 1.44 + console.info("bug851231-info"); 1.45 + console.warn("bug851231-warn"); 1.46 + console.error("bug851231-error", foobar); 1.47 + console.debug("bug851231-debug"); 1.48 + console.trace(); 1.49 + console.dir(document); 1.50 + console.timeEnd("foobarTimer"); 1.51 + 1.52 + info("wait for the Console.jsm messages"); 1.53 + 1.54 + waitForMessages({ 1.55 + webconsole: hud, 1.56 + messages: [ 1.57 + { 1.58 + name: "console.log output", 1.59 + text: "bug851231-log", 1.60 + category: CATEGORY_WEBDEV, 1.61 + severity: SEVERITY_LOG, 1.62 + }, 1.63 + { 1.64 + name: "console.info output", 1.65 + text: "bug851231-info", 1.66 + category: CATEGORY_WEBDEV, 1.67 + severity: SEVERITY_INFO, 1.68 + }, 1.69 + { 1.70 + name: "console.warn output", 1.71 + text: "bug851231-warn", 1.72 + category: CATEGORY_WEBDEV, 1.73 + severity: SEVERITY_WARNING, 1.74 + }, 1.75 + { 1.76 + name: "console.error output", 1.77 + text: /\bbug851231-error\b.+\{\s*bug851231prop:\s"bug851231value"\s*\}/, 1.78 + category: CATEGORY_WEBDEV, 1.79 + severity: SEVERITY_ERROR, 1.80 + objects: true, 1.81 + }, 1.82 + { 1.83 + name: "console.debug output", 1.84 + text: "bug851231-debug", 1.85 + category: CATEGORY_WEBDEV, 1.86 + severity: SEVERITY_LOG, 1.87 + }, 1.88 + { 1.89 + name: "console.trace output", 1.90 + consoleTrace: { 1.91 + file: "browser_console_consolejsm_output.js", 1.92 + fn: "onCachedMessage", 1.93 + }, 1.94 + }, 1.95 + { 1.96 + name: "console.dir output", 1.97 + consoleDir: /XULDocument\s+.+\s+chrome:\/\/.+\/browser\.xul/, 1.98 + }, 1.99 + { 1.100 + name: "console.time output", 1.101 + consoleTime: "foobarTimer", 1.102 + }, 1.103 + { 1.104 + name: "console.timeEnd output", 1.105 + consoleTimeEnd: "foobarTimer", 1.106 + }, 1.107 + ], 1.108 + }).then((aResults) => { 1.109 + let consoleErrorMsg = aResults[3]; 1.110 + ok(consoleErrorMsg, "console.error message element found"); 1.111 + let clickable = consoleErrorMsg.clickableElements[0]; 1.112 + ok(clickable, "clickable object found for console.error"); 1.113 + 1.114 + let onFetch = (aEvent, aVar) => { 1.115 + // Skip the notification from console.dir variablesview-fetched. 1.116 + if (aVar._variablesView != hud.jsterm._variablesView) { 1.117 + return; 1.118 + } 1.119 + hud.jsterm.off("variablesview-fetched", onFetch); 1.120 + 1.121 + ok(aVar, "object inspector opened on click"); 1.122 + 1.123 + findVariableViewProperties(aVar, [{ 1.124 + name: "bug851231prop", 1.125 + value: "bug851231value", 1.126 + }], { webconsole: hud }).then(finishTest); 1.127 + }; 1.128 + 1.129 + hud.jsterm.on("variablesview-fetched", onFetch); 1.130 + 1.131 + clickable.scrollIntoView(false); 1.132 + 1.133 + info("wait for variablesview-fetched"); 1.134 + executeSoon(() => 1.135 + EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow)); 1.136 + }); 1.137 + } 1.138 +}