Bug 1568151 - Replace `target.getInspector()` by `target.getFront("inspector")`....
[gecko.git] / accessible / tests / mochitest / browser.js
blobe489d1265f4c9ca8eac78e82968aa90ebe0c8dea
1 var { AppConstants } = ChromeUtils.import(
2   "resource://gre/modules/AppConstants.jsm"
3 );
5 /**
6  * Load the browser with the given url and then invokes the given function.
7  */
8 function openBrowserWindow(aFunc, aURL, aRect) {
9   gBrowserContext.testFunc = aFunc;
10   gBrowserContext.startURL = aURL;
11   gBrowserContext.browserRect = aRect;
13   addLoadEvent(openBrowserWindowIntl);
16 /**
17  * Close the browser window.
18  */
19 function closeBrowserWindow() {
20   gBrowserContext.browserWnd.close();
23 /**
24  * Return the browser window object.
25  */
26 function browserWindow() {
27   return gBrowserContext.browserWnd;
30 /**
31  * Return the document of the browser window.
32  */
33 function browserDocument() {
34   return browserWindow().document;
37 /**
38  * Return tab browser object.
39  */
40 function tabBrowser() {
41   return browserWindow().gBrowser;
44 /**
45  * Return browser element of the current tab.
46  */
47 function currentBrowser() {
48   return tabBrowser().selectedBrowser;
51 /**
52  * Return DOM document of the current tab.
53  */
54 function currentTabDocument() {
55   return currentBrowser().contentDocument;
58 /**
59  * Return window of the current tab.
60  */
61 function currentTabWindow() {
62   return currentTabDocument().defaultView;
65 /**
66  * Return browser element of the tab at the given index.
67  */
68 function browserAt(aIndex) {
69   return tabBrowser().getBrowserAtIndex(aIndex);
72 /**
73  * Return DOM document of the tab at the given index.
74  */
75 function tabDocumentAt(aIndex) {
76   return browserAt(aIndex).contentDocument;
79 /**
80  * Return input element of address bar.
81  */
82 function urlbarInput() {
83   return browserWindow().document.getElementById("urlbar").inputField;
86 /**
87  * Return reload button.
88  */
89 function reloadButton() {
90   return browserWindow().document.getElementById("urlbar-reload-button");
93 // //////////////////////////////////////////////////////////////////////////////
94 // private section
96 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
98 var gBrowserContext = {
99   browserWnd: null,
100   testFunc: null,
101   startURL: "",
104 function openBrowserWindowIntl() {
105   var params = "chrome,all,dialog=no,non-remote";
106   var rect = gBrowserContext.browserRect;
107   if (rect) {
108     if ("left" in rect) {
109       params += ",left=" + rect.left;
110     }
111     if ("top" in rect) {
112       params += ",top=" + rect.top;
113     }
114     if ("width" in rect) {
115       params += ",width=" + rect.width;
116     }
117     if ("height" in rect) {
118       params += ",height=" + rect.height;
119     }
120   }
122   gBrowserContext.browserWnd = window.openDialog(
123     AppConstants.BROWSER_CHROME_URL,
124     "_blank",
125     params,
126     gBrowserContext.startURL || "data:text/html,<html></html>"
127   );
129   whenDelayedStartupFinished(browserWindow(), function() {
130     addA11yLoadEvent(startBrowserTests, browserWindow());
131   });
134 function startBrowserTests() {
135   if (gBrowserContext.startURL) {
136     // wait for load
137     addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow);
138   } else {
139     gBrowserContext.testFunc();
140   }
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);
148     }
149   }, "browser-delayed-startup-finished");