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