browser/fuel/test/browser_Application.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 // This listens for the next opened window and checks it is of the right url.
     2 // opencallback is called when the new window is fully loaded
     3 // closecallback is called when the window is closed
     4 function WindowOpenListener(url, opencallback, closecallback) {
     5   this.url = url;
     6   this.opencallback = opencallback;
     7   this.closecallback = closecallback;
     9   Services.wm.addListener(this);
    10 }
    12 WindowOpenListener.prototype = {
    13   url: null,
    14   opencallback: null,
    15   closecallback: null,
    16   window: null,
    17   domwindow: null,
    19   handleEvent: function(event) {
    20     is(this.domwindow.document.location.href, this.url, "Should have opened the correct window");
    22     this.domwindow.removeEventListener("load", this, false);
    23     // Allow any other load handlers to execute
    24     var self = this;
    25     executeSoon(function() { self.opencallback(self.domwindow); } );
    26   },
    28   onWindowTitleChange: function(window, title) {
    29   },
    31   onOpenWindow: function(window) {
    32     if (this.window)
    33       return;
    35     this.window = window;
    36     this.domwindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
    37                            .getInterface(Ci.nsIDOMWindow);
    38     this.domwindow.addEventListener("load", this, false);
    39   },
    41   onCloseWindow: function(window) {
    42     if (this.window != window)
    43       return;
    45     Services.wm.removeListener(this);
    46     this.opencallback = null;
    47     this.window = null;
    48     this.domwindow = null;
    50     // Let the window close complete
    51     executeSoon(this.closecallback);
    52     this.closecallback = null;
    53   }
    54 };
    56 function test() {
    57   ok(Application, "Check global access to Application");
    59   // I'd test these against a specific value, but that is bound to flucuate
    60   ok(Application.id, "Check to see if an ID exists for the Application");
    61   ok(Application.name, "Check to see if a name exists for the Application");
    62   ok(Application.version, "Check to see if a version exists for the Application");
    64   var wMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
    65   var console = wMediator.getMostRecentWindow("global:console");
    66   waitForExplicitFinish();
    67   ok(!console, "Console should not already be open");
    69   new WindowOpenListener("chrome://global/content/console.xul", consoleOpened, consoleClosed);
    70   Application.console.open();
    71 }
    73 function consoleOpened(win) {
    74   win.close();
    75 }
    77 function consoleClosed() {
    78   finish();
    79 }

mercurial