tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_beaconCookies.html (2579B)


      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 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">
     15  
     16 </div>
     17 <pre id="test">
     18 <script class="testbody" type="text/javascript">
     19 
     20 // not enabled by default yet.
     21 SimpleTest.waitForExplicitFinish();
     22 SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, beginTest);
     23 
     24 const {BrowserTestUtils} = ChromeUtils.importESModule(
     25  "resource://testing-common/BrowserTestUtils.sys.mjs"
     26 );
     27 
     28 var baseURL = "http://mochi.test:8888/chrome/dom/tests/mochitest/beacon/";
     29 
     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");
     37 }
     38 
     39 function testOnWindow(options, callback) {
     40  var mainWindow = window.browsingContext.topChromeWindow;
     41 
     42  var win = mainWindow.OpenBrowserWindow(options);
     43  windowsToClose.push(win);
     44  whenDelayedStartupFinished(win, function() {
     45    callback(win);
     46  });
     47 };
     48 
     49 var windowsToClose = [];
     50 var next;
     51 
     52 function beginTest() {
     53  testOnWindow({}, function(aNormalWindow) {
     54    Services.obs.addObserver(function waitCookie() {
     55      Services.obs.removeObserver(waitCookie, "cookie-changed");
     56      ok(true, "cookie set by beacon request in normal window");
     57      testOnPrivateWindow();
     58    }, "cookie-changed");
     59    BrowserTestUtils.startLoadingURIString(aNormalWindow.gBrowser.selectedBrowser, baseURL + "file_beaconCookies.html");
     60  });
     61 }
     62 
     63 function testOnPrivateWindow() {
     64  testOnWindow({private: true}, function(aPrivateWindow) {
     65    Services.obs.addObserver(function waitCookie() {
     66      Services.obs.removeObserver(waitCookie, "private-cookie-changed");
     67      ok(true, "private cookie set by beacon request in private window");
     68      cleanup();
     69    }, "private-cookie-changed");
     70    BrowserTestUtils.startLoadingURIString(aPrivateWindow.gBrowser.selectedBrowser, baseURL + "file_beaconCookies.html");
     71  });
     72 }
     73 
     74 function cleanup() {
     75  for (var i = 0; i < windowsToClose.length; ++i) {
     76    windowsToClose[i].close();
     77  }
     78  SimpleTest.finish();
     79 }
     80 
     81 </script>
     82 </pre>
     83 </body>
     84 </html>