1 var { AppConstants } = ChromeUtils.import(
2 "resource://gre/modules/AppConstants.jsm"
6 * Load the browser with the given url and then invokes the given function.
8 function openBrowserWindow(aFunc, aURL, aRect) {
9 gBrowserContext.testFunc = aFunc;
10 gBrowserContext.startURL = aURL;
11 gBrowserContext.browserRect = aRect;
13 addLoadEvent(openBrowserWindowIntl);
17 * Close the browser window.
19 function closeBrowserWindow() {
20 gBrowserContext.browserWnd.close();
24 * Return the browser window object.
26 function browserWindow() {
27 return gBrowserContext.browserWnd;
31 * Return the document of the browser window.
33 function browserDocument() {
34 return browserWindow().document;
38 * Return tab browser object.
40 function tabBrowser() {
41 return browserWindow().gBrowser;
45 * Return browser element of the current tab.
47 function currentBrowser() {
48 return tabBrowser().selectedBrowser;
52 * Return DOM document of the current tab.
54 function currentTabDocument() {
55 return currentBrowser().contentDocument;
59 * Return window of the current tab.
61 function currentTabWindow() {
62 return currentTabDocument().defaultView;
66 * Return browser element of the tab at the given index.
68 function browserAt(aIndex) {
69 return tabBrowser().getBrowserAtIndex(aIndex);
73 * Return DOM document of the tab at the given index.
75 function tabDocumentAt(aIndex) {
76 return browserAt(aIndex).contentDocument;
80 * Return input element of address bar.
82 function urlbarInput() {
83 return browserWindow().document.getElementById("urlbar").inputField;
87 * Return reload button.
89 function reloadButton() {
90 return browserWindow().document.getElementById("urlbar-reload-button");
93 // //////////////////////////////////////////////////////////////////////////////
96 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
98 var gBrowserContext = {
104 function openBrowserWindowIntl() {
105 var params = "chrome,all,dialog=no,non-remote";
106 var rect = gBrowserContext.browserRect;
108 if ("left" in rect) {
109 params += ",left=" + rect.left;
112 params += ",top=" + rect.top;
114 if ("width" in rect) {
115 params += ",width=" + rect.width;
117 if ("height" in rect) {
118 params += ",height=" + rect.height;
122 gBrowserContext.browserWnd = window.openDialog(
123 AppConstants.BROWSER_CHROME_URL,
126 gBrowserContext.startURL || "data:text/html,<html></html>"
129 whenDelayedStartupFinished(browserWindow(), function() {
130 addA11yLoadEvent(startBrowserTests, browserWindow());
134 function startBrowserTests() {
135 if (gBrowserContext.startURL) {
137 addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow);
139 gBrowserContext.testFunc();
143 function whenDelayedStartupFinished(aWindow, aCallback) {
144 Services.obs.addObserver(function observer(aSubject, aTopic) {
145 if (aWindow == aSubject) {
146 Services.obs.removeObserver(observer, aTopic);
147 setTimeout(aCallback, 0);
149 }, "browser-delayed-startup-finished");