browser/devtools/webconsole/test/browser_webconsole_notifications.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_notifications.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +const TEST_URI = "data:text/html;charset=utf-8,<p>Web Console test for notifications";
    1.10 +
    1.11 +function test() {
    1.12 +  observer.init();
    1.13 +  addTab(TEST_URI);
    1.14 +  browser.addEventListener("load", onLoad, true);
    1.15 +}
    1.16 +
    1.17 +function webConsoleCreated(aID)
    1.18 +{
    1.19 +  Services.obs.removeObserver(observer, "web-console-created");
    1.20 +  ok(HUDService.getHudReferenceById(aID), "We have a hud reference");
    1.21 +  content.wrappedJSObject.console.log("adding a log message");
    1.22 +}
    1.23 +
    1.24 +function webConsoleDestroyed(aID)
    1.25 +{
    1.26 +  Services.obs.removeObserver(observer, "web-console-destroyed");
    1.27 +  ok(!HUDService.getHudReferenceById(aID), "We do not have a hud reference");
    1.28 +  executeSoon(finishTest);
    1.29 +}
    1.30 +
    1.31 +function webConsoleMessage(aID, aNodeID)
    1.32 +{
    1.33 +  Services.obs.removeObserver(observer, "web-console-message-created");
    1.34 +  ok(aID, "we have a console ID");
    1.35 +  is(typeof aNodeID, "string", "message node id is a string");
    1.36 +  executeSoon(closeConsole);
    1.37 +}
    1.38 +
    1.39 +let observer = {
    1.40 +
    1.41 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
    1.42 +
    1.43 +  observe: function observe(aSubject, aTopic, aData)
    1.44 +  {
    1.45 +    aSubject = aSubject.QueryInterface(Ci.nsISupportsString);
    1.46 +
    1.47 +    switch(aTopic) {
    1.48 +      case "web-console-created":
    1.49 +        webConsoleCreated(aSubject.data);
    1.50 +        break;
    1.51 +      case "web-console-destroyed":
    1.52 +        webConsoleDestroyed(aSubject.data);
    1.53 +        break;
    1.54 +      case "web-console-message-created":
    1.55 +        webConsoleMessage(aSubject, aData);
    1.56 +        break;
    1.57 +      default:
    1.58 +        break;
    1.59 +    }
    1.60 +  },
    1.61 +
    1.62 +  init: function init()
    1.63 +  {
    1.64 +    Services.obs.addObserver(this, "web-console-created", false);
    1.65 +    Services.obs.addObserver(this, "web-console-destroyed", false);
    1.66 +    Services.obs.addObserver(this, "web-console-message-created", false);
    1.67 +  }
    1.68 +};
    1.69 +
    1.70 +function onLoad() {
    1.71 +  browser.removeEventListener("load", onLoad, true);
    1.72 +  openConsole();
    1.73 +}

mercurial