browser/devtools/webconsole/test/browser_webconsole_notifications.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* vim:set ts=2 sw=2 sts=2 et: */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 const TEST_URI = "data:text/html;charset=utf-8,<p>Web Console test for notifications";
     8 function test() {
     9   observer.init();
    10   addTab(TEST_URI);
    11   browser.addEventListener("load", onLoad, true);
    12 }
    14 function webConsoleCreated(aID)
    15 {
    16   Services.obs.removeObserver(observer, "web-console-created");
    17   ok(HUDService.getHudReferenceById(aID), "We have a hud reference");
    18   content.wrappedJSObject.console.log("adding a log message");
    19 }
    21 function webConsoleDestroyed(aID)
    22 {
    23   Services.obs.removeObserver(observer, "web-console-destroyed");
    24   ok(!HUDService.getHudReferenceById(aID), "We do not have a hud reference");
    25   executeSoon(finishTest);
    26 }
    28 function webConsoleMessage(aID, aNodeID)
    29 {
    30   Services.obs.removeObserver(observer, "web-console-message-created");
    31   ok(aID, "we have a console ID");
    32   is(typeof aNodeID, "string", "message node id is a string");
    33   executeSoon(closeConsole);
    34 }
    36 let observer = {
    38   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
    40   observe: function observe(aSubject, aTopic, aData)
    41   {
    42     aSubject = aSubject.QueryInterface(Ci.nsISupportsString);
    44     switch(aTopic) {
    45       case "web-console-created":
    46         webConsoleCreated(aSubject.data);
    47         break;
    48       case "web-console-destroyed":
    49         webConsoleDestroyed(aSubject.data);
    50         break;
    51       case "web-console-message-created":
    52         webConsoleMessage(aSubject, aData);
    53         break;
    54       default:
    55         break;
    56     }
    57   },
    59   init: function init()
    60   {
    61     Services.obs.addObserver(this, "web-console-created", false);
    62     Services.obs.addObserver(this, "web-console-destroyed", false);
    63     Services.obs.addObserver(this, "web-console-message-created", false);
    64   }
    65 };
    67 function onLoad() {
    68   browser.removeEventListener("load", onLoad, true);
    69   openConsole();
    70 }

mercurial