accessible/tests/mochitest/browser.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial