2012-01-27 02:22:19 -08:00
|
|
|
/**
|
|
|
|
* Load the browser with the given url and then invokes the given function.
|
|
|
|
*/
|
2012-02-21 18:07:43 -08:00
|
|
|
function openBrowserWindow(aFunc, aURL, aRect)
|
2012-01-27 02:22:19 -08:00
|
|
|
{
|
|
|
|
gBrowserContext.testFunc = aFunc;
|
|
|
|
gBrowserContext.startURL = aURL;
|
2012-02-21 18:07:43 -08:00
|
|
|
gBrowserContext.browserRect = aRect;
|
2012-01-27 02:22:19 -08:00
|
|
|
|
|
|
|
addLoadEvent(openBrowserWindowIntl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the browser window.
|
|
|
|
*/
|
|
|
|
function closeBrowserWindow()
|
|
|
|
{
|
|
|
|
gBrowserContext.browserWnd.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the browser window object.
|
|
|
|
*/
|
|
|
|
function browserWindow()
|
|
|
|
{
|
|
|
|
return gBrowserContext.browserWnd;
|
|
|
|
}
|
|
|
|
|
2012-02-03 03:19:17 -08:00
|
|
|
/**
|
|
|
|
* Return the document of the browser window.
|
|
|
|
*/
|
|
|
|
function browserDocument()
|
|
|
|
{
|
|
|
|
return browserWindow().document;
|
|
|
|
}
|
|
|
|
|
2012-01-27 02:22:19 -08:00
|
|
|
/**
|
|
|
|
* Return tab browser object.
|
|
|
|
*/
|
|
|
|
function tabBrowser()
|
|
|
|
{
|
|
|
|
return browserWindow().gBrowser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return browser element of the current tab.
|
|
|
|
*/
|
|
|
|
function currentBrowser()
|
|
|
|
{
|
|
|
|
return tabBrowser().selectedBrowser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return DOM document of the current tab.
|
|
|
|
*/
|
|
|
|
function currentTabDocument()
|
|
|
|
{
|
|
|
|
return currentBrowser().contentDocument;
|
|
|
|
}
|
|
|
|
|
2012-02-21 18:07:43 -08:00
|
|
|
/**
|
|
|
|
* Return window of the current tab.
|
|
|
|
*/
|
|
|
|
function currentTabWindow()
|
|
|
|
{
|
|
|
|
return currentTabDocument().defaultView;
|
|
|
|
}
|
|
|
|
|
2012-01-31 21:17:42 -08:00
|
|
|
/**
|
|
|
|
* Return browser element of the tab at the given index.
|
|
|
|
*/
|
|
|
|
function browserAt(aIndex)
|
|
|
|
{
|
|
|
|
return tabBrowser().getBrowserAtIndex(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return DOM document of the tab at the given index.
|
|
|
|
*/
|
|
|
|
function tabDocumentAt(aIndex)
|
|
|
|
{
|
|
|
|
return browserAt(aIndex).contentDocument;
|
|
|
|
}
|
|
|
|
|
2012-01-27 02:22:19 -08:00
|
|
|
/**
|
|
|
|
* Return input element of address bar.
|
|
|
|
*/
|
|
|
|
function urlbarInput()
|
|
|
|
{
|
|
|
|
return browserWindow().document.getElementById("urlbar").inputField;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return reload button.
|
|
|
|
*/
|
|
|
|
function reloadButton()
|
|
|
|
{
|
|
|
|
return browserWindow().document.getElementById("urlbar-reload-button");
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// private section
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
var gBrowserContext =
|
|
|
|
{
|
|
|
|
browserWnd: null,
|
|
|
|
testFunc: null,
|
|
|
|
startURL: ""
|
|
|
|
};
|
|
|
|
|
|
|
|
function openBrowserWindowIntl()
|
|
|
|
{
|
2012-02-21 18:07:43 -08:00
|
|
|
var params = "chrome,all,dialog=no";
|
|
|
|
var rect = gBrowserContext.browserRect;
|
|
|
|
if (rect) {
|
|
|
|
if ("left" in rect)
|
|
|
|
params += ",left=" + rect.left;
|
|
|
|
if ("top" in rect)
|
|
|
|
params += ",top=" + rect.top;
|
|
|
|
if ("width" in rect)
|
|
|
|
params += ",width=" + rect.width;
|
|
|
|
if ("height" in rect)
|
|
|
|
params += ",height=" + rect.height;
|
|
|
|
}
|
|
|
|
|
2012-01-27 02:22:19 -08:00
|
|
|
gBrowserContext.browserWnd =
|
|
|
|
window.openDialog(Services.prefs.getCharPref("browser.chromeURL"),
|
2012-02-21 18:07:43 -08:00
|
|
|
"_blank", params,
|
2012-01-27 02:22:19 -08:00
|
|
|
gBrowserContext.startURL);
|
|
|
|
|
|
|
|
addA11yLoadEvent(startBrowserTests, browserWindow());
|
|
|
|
}
|
|
|
|
|
|
|
|
function startBrowserTests()
|
|
|
|
{
|
|
|
|
if (gBrowserContext.startURL) // wait for load
|
|
|
|
addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow);
|
|
|
|
else
|
|
|
|
gBrowserContext.testFunc();
|
|
|
|
}
|