browser/devtools/webconsole/test/browser_webconsole_notifications.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 /* 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