browser/devtools/webconsole/test/browser_console_consolejsm_output.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 // Test that Console.jsm outputs messages to the Browser Console, bug 851231.
     8 function test()
     9 {
    10   let storage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(Ci.nsIConsoleAPIStorage);
    11   storage.clearEvents();
    13   let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console;
    14   console.log("bug861338-log-cached");
    16   HUDService.toggleBrowserConsole().then(consoleOpened);
    17   let hud = null;
    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   }
    33   function onCachedMessage()
    34   {
    35     hud.jsterm.clearOutput(true);
    37     console.time("foobarTimer");
    38     let foobar = { bug851231prop: "bug851231value" };
    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");
    49     info("wait for the Console.jsm messages");
    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");
   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);
   118         ok(aVar, "object inspector opened on click");
   120         findVariableViewProperties(aVar, [{
   121           name: "bug851231prop",
   122           value: "bug851231value",
   123         }], { webconsole: hud }).then(finishTest);
   124       };
   126       hud.jsterm.on("variablesview-fetched", onFetch);
   128       clickable.scrollIntoView(false);
   130       info("wait for variablesview-fetched");
   131       executeSoon(() =>
   132         EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow));
   133     });
   134   }
   135 }

mercurial