dom/tests/mochitest/beacon/test_beaconCookies.html

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 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=936340
     5 -->
     6 <head>
     7   <title>Test whether sendBeacon sets cookies</title>
     8   <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936340">Mozilla Bug 936340</a>
    13 <p id="display"></p>
    14 <div id="content" style="display: none">
    16 </div>
    17 <pre id="test">
    18 <script class="testbody" type="text/javascript">
    20 // not enabled by default yet.
    21 SimpleTest.waitForExplicitFinish();
    22 SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, beginTest);
    24 var Ci = Components.interfaces;
    25 var Cu = Components.utils;
    26 Cu.import("resource://gre/modules/Services.jsm");
    28 var baseURL = "http://mochi.test:8888/chrome/dom/tests/mochitest/beacon/";
    30 function whenDelayedStartupFinished(aWindow, aCallback) {
    31   Services.obs.addObserver(function observer(aSubject, aTopic) {
    32     if (aWindow == aSubject) {
    33       Services.obs.removeObserver(observer, aTopic);
    34       setTimeout(aCallback, 0);
    35     }
    36   }, "browser-delayed-startup-finished", false);
    37 }
    39 function testOnWindow(options, callback) {
    40   var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
    41                          .getInterface(Ci.nsIWebNavigation)
    42                          .QueryInterface(Ci.nsIDocShellTreeItem)
    43                          .rootTreeItem
    44                          .QueryInterface(Ci.nsIInterfaceRequestor)
    45                          .getInterface(Ci.nsIDOMWindow);
    47   var win = mainWindow.OpenBrowserWindow(options);
    48   windowsToClose.push(win);
    49   whenDelayedStartupFinished(win, function() {
    50     callback(win);
    51   });
    52 };
    54 var windowsToClose = [];
    55 var next;
    57 function beginTest() {
    58   testOnWindow({}, function(aNormalWindow) {
    59     Services.obs.addObserver(function waitCookie() {
    60       Services.obs.removeObserver(waitCookie, "cookie-changed");
    61       ok(true, "cookie set by beacon request in normal window");
    62       testOnPrivateWindow();
    63     }, "cookie-changed", false);
    64     aNormalWindow.gBrowser.selectedBrowser.loadURI(baseURL + "file_beaconCookies.html");
    65   });
    66 }
    68 function testOnPrivateWindow() {
    69   testOnWindow({private: true}, function(aPrivateWindow) {
    70     Services.obs.addObserver(function waitCookie() {
    71       Services.obs.removeObserver(waitCookie, "private-cookie-changed");
    72       ok(true, "private cookie set by beacon request in private window");
    73       cleanup();
    74     }, "private-cookie-changed", false);
    75     aPrivateWindow.gBrowser.selectedBrowser.loadURI(baseURL + "file_beaconCookies.html");
    76   });
    77 }
    79 function cleanup() {
    80   for (var i = 0; i < windowsToClose.length; ++i) {
    81     windowsToClose[i].close();
    82   }
    83   SimpleTest.finish();
    84 }
    86 </script>
    87 </pre>
    88 </body>
    89 </html>

mercurial