michael@0: /** michael@0: * Load the browser with the given url and then invokes the given function. michael@0: */ michael@0: function openBrowserWindow(aFunc, aURL, aRect) michael@0: { michael@0: gBrowserContext.testFunc = aFunc; michael@0: gBrowserContext.startURL = aURL; michael@0: gBrowserContext.browserRect = aRect; michael@0: michael@0: addLoadEvent(openBrowserWindowIntl); michael@0: } michael@0: michael@0: /** michael@0: * Close the browser window. michael@0: */ michael@0: function closeBrowserWindow() michael@0: { michael@0: gBrowserContext.browserWnd.close(); michael@0: } michael@0: michael@0: /** michael@0: * Return the browser window object. michael@0: */ michael@0: function browserWindow() michael@0: { michael@0: return gBrowserContext.browserWnd; michael@0: } michael@0: michael@0: /** michael@0: * Return the document of the browser window. michael@0: */ michael@0: function browserDocument() michael@0: { michael@0: return browserWindow().document; michael@0: } michael@0: michael@0: /** michael@0: * Return tab browser object. michael@0: */ michael@0: function tabBrowser() michael@0: { michael@0: return browserWindow().gBrowser; michael@0: } michael@0: michael@0: /** michael@0: * Return browser element of the current tab. michael@0: */ michael@0: function currentBrowser() michael@0: { michael@0: return tabBrowser().selectedBrowser; michael@0: } michael@0: michael@0: /** michael@0: * Return DOM document of the current tab. michael@0: */ michael@0: function currentTabDocument() michael@0: { michael@0: return currentBrowser().contentDocument; michael@0: } michael@0: michael@0: /** michael@0: * Return window of the current tab. michael@0: */ michael@0: function currentTabWindow() michael@0: { michael@0: return currentTabDocument().defaultView; michael@0: } michael@0: michael@0: /** michael@0: * Return browser element of the tab at the given index. michael@0: */ michael@0: function browserAt(aIndex) michael@0: { michael@0: return tabBrowser().getBrowserAtIndex(aIndex); michael@0: } michael@0: michael@0: /** michael@0: * Return DOM document of the tab at the given index. michael@0: */ michael@0: function tabDocumentAt(aIndex) michael@0: { michael@0: return browserAt(aIndex).contentDocument; michael@0: } michael@0: michael@0: /** michael@0: * Return input element of address bar. michael@0: */ michael@0: function urlbarInput() michael@0: { michael@0: return browserWindow().document.getElementById("urlbar").inputField; michael@0: } michael@0: michael@0: /** michael@0: * Return reload button. michael@0: */ michael@0: function reloadButton() michael@0: { michael@0: return browserWindow().document.getElementById("urlbar-reload-button"); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // private section michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: var gBrowserContext = michael@0: { michael@0: browserWnd: null, michael@0: testFunc: null, michael@0: startURL: "" michael@0: }; michael@0: michael@0: function openBrowserWindowIntl() michael@0: { michael@0: var params = "chrome,all,dialog=no"; michael@0: var rect = gBrowserContext.browserRect; michael@0: if (rect) { michael@0: if ("left" in rect) michael@0: params += ",left=" + rect.left; michael@0: if ("top" in rect) michael@0: params += ",top=" + rect.top; michael@0: if ("width" in rect) michael@0: params += ",width=" + rect.width; michael@0: if ("height" in rect) michael@0: params += ",height=" + rect.height; michael@0: } michael@0: michael@0: gBrowserContext.browserWnd = michael@0: window.openDialog(Services.prefs.getCharPref("browser.chromeURL"), michael@0: "_blank", params, michael@0: gBrowserContext.startURL); michael@0: michael@0: whenDelayedStartupFinished(browserWindow(), function () { michael@0: addA11yLoadEvent(startBrowserTests, browserWindow()); michael@0: }); michael@0: } michael@0: michael@0: function startBrowserTests() michael@0: { michael@0: if (gBrowserContext.startURL) // wait for load michael@0: addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow); michael@0: else michael@0: gBrowserContext.testFunc(); michael@0: } michael@0: michael@0: function whenDelayedStartupFinished(aWindow, aCallback) { michael@0: Services.obs.addObserver(function observer(aSubject, aTopic) { michael@0: if (aWindow == aSubject) { michael@0: Services.obs.removeObserver(observer, aTopic); michael@0: setTimeout(aCallback, 0); michael@0: } michael@0: }, "browser-delayed-startup-finished", false); michael@0: }