accessible/tests/mochitest/browser.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:3376133ee90e
1 /**
2 * Load the browser with the given url and then invokes the given function.
3 */
4 function openBrowserWindow(aFunc, aURL, aRect)
5 {
6 gBrowserContext.testFunc = aFunc;
7 gBrowserContext.startURL = aURL;
8 gBrowserContext.browserRect = aRect;
9
10 addLoadEvent(openBrowserWindowIntl);
11 }
12
13 /**
14 * Close the browser window.
15 */
16 function closeBrowserWindow()
17 {
18 gBrowserContext.browserWnd.close();
19 }
20
21 /**
22 * Return the browser window object.
23 */
24 function browserWindow()
25 {
26 return gBrowserContext.browserWnd;
27 }
28
29 /**
30 * Return the document of the browser window.
31 */
32 function browserDocument()
33 {
34 return browserWindow().document;
35 }
36
37 /**
38 * Return tab browser object.
39 */
40 function tabBrowser()
41 {
42 return browserWindow().gBrowser;
43 }
44
45 /**
46 * Return browser element of the current tab.
47 */
48 function currentBrowser()
49 {
50 return tabBrowser().selectedBrowser;
51 }
52
53 /**
54 * Return DOM document of the current tab.
55 */
56 function currentTabDocument()
57 {
58 return currentBrowser().contentDocument;
59 }
60
61 /**
62 * Return window of the current tab.
63 */
64 function currentTabWindow()
65 {
66 return currentTabDocument().defaultView;
67 }
68
69 /**
70 * Return browser element of the tab at the given index.
71 */
72 function browserAt(aIndex)
73 {
74 return tabBrowser().getBrowserAtIndex(aIndex);
75 }
76
77 /**
78 * Return DOM document of the tab at the given index.
79 */
80 function tabDocumentAt(aIndex)
81 {
82 return browserAt(aIndex).contentDocument;
83 }
84
85 /**
86 * Return input element of address bar.
87 */
88 function urlbarInput()
89 {
90 return browserWindow().document.getElementById("urlbar").inputField;
91 }
92
93 /**
94 * Return reload button.
95 */
96 function reloadButton()
97 {
98 return browserWindow().document.getElementById("urlbar-reload-button");
99 }
100
101 ////////////////////////////////////////////////////////////////////////////////
102 // private section
103
104 Components.utils.import("resource://gre/modules/Services.jsm");
105
106 var gBrowserContext =
107 {
108 browserWnd: null,
109 testFunc: null,
110 startURL: ""
111 };
112
113 function openBrowserWindowIntl()
114 {
115 var params = "chrome,all,dialog=no";
116 var rect = gBrowserContext.browserRect;
117 if (rect) {
118 if ("left" in rect)
119 params += ",left=" + rect.left;
120 if ("top" in rect)
121 params += ",top=" + rect.top;
122 if ("width" in rect)
123 params += ",width=" + rect.width;
124 if ("height" in rect)
125 params += ",height=" + rect.height;
126 }
127
128 gBrowserContext.browserWnd =
129 window.openDialog(Services.prefs.getCharPref("browser.chromeURL"),
130 "_blank", params,
131 gBrowserContext.startURL);
132
133 whenDelayedStartupFinished(browserWindow(), function () {
134 addA11yLoadEvent(startBrowserTests, browserWindow());
135 });
136 }
137
138 function startBrowserTests()
139 {
140 if (gBrowserContext.startURL) // wait for load
141 addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow);
142 else
143 gBrowserContext.testFunc();
144 }
145
146 function whenDelayedStartupFinished(aWindow, aCallback) {
147 Services.obs.addObserver(function observer(aSubject, aTopic) {
148 if (aWindow == aSubject) {
149 Services.obs.removeObserver(observer, aTopic);
150 setTimeout(aCallback, 0);
151 }
152 }, "browser-delayed-startup-finished", false);
153 }

mercurial