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