michael@0: // This listens for the next opened window and checks it is of the right url. michael@0: // opencallback is called when the new window is fully loaded michael@0: // closecallback is called when the window is closed michael@0: function WindowOpenListener(url, opencallback, closecallback) { michael@0: this.url = url; michael@0: this.opencallback = opencallback; michael@0: this.closecallback = closecallback; michael@0: michael@0: Services.wm.addListener(this); michael@0: } michael@0: michael@0: WindowOpenListener.prototype = { michael@0: url: null, michael@0: opencallback: null, michael@0: closecallback: null, michael@0: window: null, michael@0: domwindow: null, michael@0: michael@0: handleEvent: function(event) { michael@0: is(this.domwindow.document.location.href, this.url, "Should have opened the correct window"); michael@0: michael@0: this.domwindow.removeEventListener("load", this, false); michael@0: // Allow any other load handlers to execute michael@0: var self = this; michael@0: executeSoon(function() { self.opencallback(self.domwindow); } ); michael@0: }, michael@0: michael@0: onWindowTitleChange: function(window, title) { michael@0: }, michael@0: michael@0: onOpenWindow: function(window) { michael@0: if (this.window) michael@0: return; michael@0: michael@0: this.window = window; michael@0: this.domwindow = window.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindow); michael@0: this.domwindow.addEventListener("load", this, false); michael@0: }, michael@0: michael@0: onCloseWindow: function(window) { michael@0: if (this.window != window) michael@0: return; michael@0: michael@0: Services.wm.removeListener(this); michael@0: this.opencallback = null; michael@0: this.window = null; michael@0: this.domwindow = null; michael@0: michael@0: // Let the window close complete michael@0: executeSoon(this.closecallback); michael@0: this.closecallback = null; michael@0: } michael@0: }; michael@0: michael@0: function test() { michael@0: ok(Application, "Check global access to Application"); michael@0: michael@0: // I'd test these against a specific value, but that is bound to flucuate michael@0: ok(Application.id, "Check to see if an ID exists for the Application"); michael@0: ok(Application.name, "Check to see if a name exists for the Application"); michael@0: ok(Application.version, "Check to see if a version exists for the Application"); michael@0: michael@0: var wMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); michael@0: var console = wMediator.getMostRecentWindow("global:console"); michael@0: waitForExplicitFinish(); michael@0: ok(!console, "Console should not already be open"); michael@0: michael@0: new WindowOpenListener("chrome://global/content/console.xul", consoleOpened, consoleClosed); michael@0: Application.console.open(); michael@0: } michael@0: michael@0: function consoleOpened(win) { michael@0: win.close(); michael@0: } michael@0: michael@0: function consoleClosed() { michael@0: finish(); michael@0: }