1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/browser.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,153 @@ 1.4 +/** 1.5 + * Load the browser with the given url and then invokes the given function. 1.6 + */ 1.7 +function openBrowserWindow(aFunc, aURL, aRect) 1.8 +{ 1.9 + gBrowserContext.testFunc = aFunc; 1.10 + gBrowserContext.startURL = aURL; 1.11 + gBrowserContext.browserRect = aRect; 1.12 + 1.13 + addLoadEvent(openBrowserWindowIntl); 1.14 +} 1.15 + 1.16 +/** 1.17 + * Close the browser window. 1.18 + */ 1.19 +function closeBrowserWindow() 1.20 +{ 1.21 + gBrowserContext.browserWnd.close(); 1.22 +} 1.23 + 1.24 +/** 1.25 + * Return the browser window object. 1.26 + */ 1.27 +function browserWindow() 1.28 +{ 1.29 + return gBrowserContext.browserWnd; 1.30 +} 1.31 + 1.32 +/** 1.33 + * Return the document of the browser window. 1.34 + */ 1.35 +function browserDocument() 1.36 +{ 1.37 + return browserWindow().document; 1.38 +} 1.39 + 1.40 +/** 1.41 + * Return tab browser object. 1.42 + */ 1.43 +function tabBrowser() 1.44 +{ 1.45 + return browserWindow().gBrowser; 1.46 +} 1.47 + 1.48 +/** 1.49 + * Return browser element of the current tab. 1.50 + */ 1.51 +function currentBrowser() 1.52 +{ 1.53 + return tabBrowser().selectedBrowser; 1.54 +} 1.55 + 1.56 +/** 1.57 + * Return DOM document of the current tab. 1.58 + */ 1.59 +function currentTabDocument() 1.60 +{ 1.61 + return currentBrowser().contentDocument; 1.62 +} 1.63 + 1.64 +/** 1.65 + * Return window of the current tab. 1.66 + */ 1.67 +function currentTabWindow() 1.68 +{ 1.69 + return currentTabDocument().defaultView; 1.70 +} 1.71 + 1.72 +/** 1.73 + * Return browser element of the tab at the given index. 1.74 + */ 1.75 +function browserAt(aIndex) 1.76 +{ 1.77 + return tabBrowser().getBrowserAtIndex(aIndex); 1.78 +} 1.79 + 1.80 +/** 1.81 + * Return DOM document of the tab at the given index. 1.82 + */ 1.83 +function tabDocumentAt(aIndex) 1.84 +{ 1.85 + return browserAt(aIndex).contentDocument; 1.86 +} 1.87 + 1.88 +/** 1.89 + * Return input element of address bar. 1.90 + */ 1.91 +function urlbarInput() 1.92 +{ 1.93 + return browserWindow().document.getElementById("urlbar").inputField; 1.94 +} 1.95 + 1.96 +/** 1.97 + * Return reload button. 1.98 + */ 1.99 +function reloadButton() 1.100 +{ 1.101 + return browserWindow().document.getElementById("urlbar-reload-button"); 1.102 +} 1.103 + 1.104 +//////////////////////////////////////////////////////////////////////////////// 1.105 +// private section 1.106 + 1.107 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.108 + 1.109 +var gBrowserContext = 1.110 +{ 1.111 + browserWnd: null, 1.112 + testFunc: null, 1.113 + startURL: "" 1.114 +}; 1.115 + 1.116 +function openBrowserWindowIntl() 1.117 +{ 1.118 + var params = "chrome,all,dialog=no"; 1.119 + var rect = gBrowserContext.browserRect; 1.120 + if (rect) { 1.121 + if ("left" in rect) 1.122 + params += ",left=" + rect.left; 1.123 + if ("top" in rect) 1.124 + params += ",top=" + rect.top; 1.125 + if ("width" in rect) 1.126 + params += ",width=" + rect.width; 1.127 + if ("height" in rect) 1.128 + params += ",height=" + rect.height; 1.129 + } 1.130 + 1.131 + gBrowserContext.browserWnd = 1.132 + window.openDialog(Services.prefs.getCharPref("browser.chromeURL"), 1.133 + "_blank", params, 1.134 + gBrowserContext.startURL); 1.135 + 1.136 + whenDelayedStartupFinished(browserWindow(), function () { 1.137 + addA11yLoadEvent(startBrowserTests, browserWindow()); 1.138 + }); 1.139 +} 1.140 + 1.141 +function startBrowserTests() 1.142 +{ 1.143 + if (gBrowserContext.startURL) // wait for load 1.144 + addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow); 1.145 + else 1.146 + gBrowserContext.testFunc(); 1.147 +} 1.148 + 1.149 +function whenDelayedStartupFinished(aWindow, aCallback) { 1.150 + Services.obs.addObserver(function observer(aSubject, aTopic) { 1.151 + if (aWindow == aSubject) { 1.152 + Services.obs.removeObserver(observer, aTopic); 1.153 + setTimeout(aCallback, 0); 1.154 + } 1.155 + }, "browser-delayed-startup-finished", false); 1.156 +}