accessible/tests/mochitest/browser.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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;
    10   addLoadEvent(openBrowserWindowIntl);
    11 }
    13 /**
    14  * Close the browser window.
    15  */
    16 function closeBrowserWindow()
    17 {
    18   gBrowserContext.browserWnd.close();
    19 }
    21 /**
    22  * Return the browser window object.
    23  */
    24 function browserWindow()
    25 {
    26   return gBrowserContext.browserWnd;
    27 }
    29 /**
    30  * Return the document of the browser window.
    31  */
    32 function browserDocument()
    33 {
    34   return browserWindow().document;
    35 }
    37 /**
    38  * Return tab browser object.
    39  */
    40 function tabBrowser()
    41 {
    42   return browserWindow().gBrowser;
    43 }
    45 /**
    46  * Return browser element of the current tab.
    47  */
    48 function currentBrowser()
    49 {
    50   return tabBrowser().selectedBrowser;
    51 }
    53 /**
    54  * Return DOM document of the current tab.
    55  */
    56 function currentTabDocument()
    57 {
    58   return currentBrowser().contentDocument;
    59 }
    61 /**
    62  * Return window of the current tab.
    63  */
    64 function currentTabWindow()
    65 {
    66   return currentTabDocument().defaultView;
    67 }
    69 /**
    70  * Return browser element of the tab at the given index.
    71  */
    72 function browserAt(aIndex)
    73 {
    74   return tabBrowser().getBrowserAtIndex(aIndex);
    75 }
    77 /**
    78  * Return DOM document of the tab at the given index.
    79  */
    80 function tabDocumentAt(aIndex)
    81 {
    82   return browserAt(aIndex).contentDocument;
    83 }
    85 /**
    86  * Return input element of address bar.
    87  */
    88 function urlbarInput()
    89 {
    90   return browserWindow().document.getElementById("urlbar").inputField;
    91 }
    93 /**
    94  * Return reload button.
    95  */
    96 function reloadButton()
    97 {
    98   return browserWindow().document.getElementById("urlbar-reload-button");
    99 }
   101 ////////////////////////////////////////////////////////////////////////////////
   102 // private section
   104 Components.utils.import("resource://gre/modules/Services.jsm");
   106 var gBrowserContext =
   107 {
   108   browserWnd: null,
   109   testFunc: null,
   110   startURL: ""
   111 };
   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   }
   128   gBrowserContext.browserWnd =
   129     window.openDialog(Services.prefs.getCharPref("browser.chromeURL"),
   130                       "_blank", params,
   131                       gBrowserContext.startURL);
   133   whenDelayedStartupFinished(browserWindow(), function () {
   134     addA11yLoadEvent(startBrowserTests, browserWindow());
   135   });
   136 }
   138 function startBrowserTests()
   139 {
   140   if (gBrowserContext.startURL) // wait for load
   141     addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow);
   142   else
   143     gBrowserContext.testFunc();
   144 }
   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