browser/fuel/test/browser_Application.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/fuel/test/browser_Application.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +// This listens for the next opened window and checks it is of the right url.
     1.5 +// opencallback is called when the new window is fully loaded
     1.6 +// closecallback is called when the window is closed
     1.7 +function WindowOpenListener(url, opencallback, closecallback) {
     1.8 +  this.url = url;
     1.9 +  this.opencallback = opencallback;
    1.10 +  this.closecallback = closecallback;
    1.11 +
    1.12 +  Services.wm.addListener(this);
    1.13 +}
    1.14 +
    1.15 +WindowOpenListener.prototype = {
    1.16 +  url: null,
    1.17 +  opencallback: null,
    1.18 +  closecallback: null,
    1.19 +  window: null,
    1.20 +  domwindow: null,
    1.21 +
    1.22 +  handleEvent: function(event) {
    1.23 +    is(this.domwindow.document.location.href, this.url, "Should have opened the correct window");
    1.24 +
    1.25 +    this.domwindow.removeEventListener("load", this, false);
    1.26 +    // Allow any other load handlers to execute
    1.27 +    var self = this;
    1.28 +    executeSoon(function() { self.opencallback(self.domwindow); } );
    1.29 +  },
    1.30 +
    1.31 +  onWindowTitleChange: function(window, title) {
    1.32 +  },
    1.33 +
    1.34 +  onOpenWindow: function(window) {
    1.35 +    if (this.window)
    1.36 +      return;
    1.37 +
    1.38 +    this.window = window;
    1.39 +    this.domwindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.40 +                           .getInterface(Ci.nsIDOMWindow);
    1.41 +    this.domwindow.addEventListener("load", this, false);
    1.42 +  },
    1.43 +
    1.44 +  onCloseWindow: function(window) {
    1.45 +    if (this.window != window)
    1.46 +      return;
    1.47 +
    1.48 +    Services.wm.removeListener(this);
    1.49 +    this.opencallback = null;
    1.50 +    this.window = null;
    1.51 +    this.domwindow = null;
    1.52 +
    1.53 +    // Let the window close complete
    1.54 +    executeSoon(this.closecallback);
    1.55 +    this.closecallback = null;
    1.56 +  }
    1.57 +};
    1.58 +
    1.59 +function test() {
    1.60 +  ok(Application, "Check global access to Application");
    1.61 +  
    1.62 +  // I'd test these against a specific value, but that is bound to flucuate
    1.63 +  ok(Application.id, "Check to see if an ID exists for the Application");
    1.64 +  ok(Application.name, "Check to see if a name exists for the Application");
    1.65 +  ok(Application.version, "Check to see if a version exists for the Application");
    1.66 +  
    1.67 +  var wMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
    1.68 +  var console = wMediator.getMostRecentWindow("global:console");
    1.69 +  waitForExplicitFinish();
    1.70 +  ok(!console, "Console should not already be open");
    1.71 +
    1.72 +  new WindowOpenListener("chrome://global/content/console.xul", consoleOpened, consoleClosed);
    1.73 +  Application.console.open();
    1.74 +}
    1.75 +
    1.76 +function consoleOpened(win) {
    1.77 +  win.close();
    1.78 +}
    1.79 +
    1.80 +function consoleClosed() {
    1.81 +  finish();
    1.82 +}

mercurial