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