|
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; |
|
8 |
|
9 Services.wm.addListener(this); |
|
10 } |
|
11 |
|
12 WindowOpenListener.prototype = { |
|
13 url: null, |
|
14 opencallback: null, |
|
15 closecallback: null, |
|
16 window: null, |
|
17 domwindow: null, |
|
18 |
|
19 handleEvent: function(event) { |
|
20 is(this.domwindow.document.location.href, this.url, "Should have opened the correct window"); |
|
21 |
|
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 }, |
|
27 |
|
28 onWindowTitleChange: function(window, title) { |
|
29 }, |
|
30 |
|
31 onOpenWindow: function(window) { |
|
32 if (this.window) |
|
33 return; |
|
34 |
|
35 this.window = window; |
|
36 this.domwindow = window.QueryInterface(Ci.nsIInterfaceRequestor) |
|
37 .getInterface(Ci.nsIDOMWindow); |
|
38 this.domwindow.addEventListener("load", this, false); |
|
39 }, |
|
40 |
|
41 onCloseWindow: function(window) { |
|
42 if (this.window != window) |
|
43 return; |
|
44 |
|
45 Services.wm.removeListener(this); |
|
46 this.opencallback = null; |
|
47 this.window = null; |
|
48 this.domwindow = null; |
|
49 |
|
50 // Let the window close complete |
|
51 executeSoon(this.closecallback); |
|
52 this.closecallback = null; |
|
53 } |
|
54 }; |
|
55 |
|
56 function test() { |
|
57 ok(Application, "Check global access to Application"); |
|
58 |
|
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"); |
|
63 |
|
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"); |
|
68 |
|
69 new WindowOpenListener("chrome://global/content/console.xul", consoleOpened, consoleClosed); |
|
70 Application.console.open(); |
|
71 } |
|
72 |
|
73 function consoleOpened(win) { |
|
74 win.close(); |
|
75 } |
|
76 |
|
77 function consoleClosed() { |
|
78 finish(); |
|
79 } |