dom/tests/mochitest/beacon/test_beaconCookies.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/beacon/test_beaconCookies.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=936340
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test whether sendBeacon sets cookies</title>
    1.11 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936340">Mozilla Bug 936340</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="text/javascript">
    1.22 +
    1.23 +// not enabled by default yet.
    1.24 +SimpleTest.waitForExplicitFinish();
    1.25 +SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, beginTest);
    1.26 +
    1.27 +var Ci = Components.interfaces;
    1.28 +var Cu = Components.utils;
    1.29 +Cu.import("resource://gre/modules/Services.jsm");
    1.30 +
    1.31 +var baseURL = "http://mochi.test:8888/chrome/dom/tests/mochitest/beacon/";
    1.32 +
    1.33 +function whenDelayedStartupFinished(aWindow, aCallback) {
    1.34 +  Services.obs.addObserver(function observer(aSubject, aTopic) {
    1.35 +    if (aWindow == aSubject) {
    1.36 +      Services.obs.removeObserver(observer, aTopic);
    1.37 +      setTimeout(aCallback, 0);
    1.38 +    }
    1.39 +  }, "browser-delayed-startup-finished", false);
    1.40 +}
    1.41 +
    1.42 +function testOnWindow(options, callback) {
    1.43 +  var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.44 +                         .getInterface(Ci.nsIWebNavigation)
    1.45 +                         .QueryInterface(Ci.nsIDocShellTreeItem)
    1.46 +                         .rootTreeItem
    1.47 +                         .QueryInterface(Ci.nsIInterfaceRequestor)
    1.48 +                         .getInterface(Ci.nsIDOMWindow);
    1.49 +
    1.50 +  var win = mainWindow.OpenBrowserWindow(options);
    1.51 +  windowsToClose.push(win);
    1.52 +  whenDelayedStartupFinished(win, function() {
    1.53 +    callback(win);
    1.54 +  });
    1.55 +};
    1.56 +
    1.57 +var windowsToClose = [];
    1.58 +var next;
    1.59 +
    1.60 +function beginTest() {
    1.61 +  testOnWindow({}, function(aNormalWindow) {
    1.62 +    Services.obs.addObserver(function waitCookie() {
    1.63 +      Services.obs.removeObserver(waitCookie, "cookie-changed");
    1.64 +      ok(true, "cookie set by beacon request in normal window");
    1.65 +      testOnPrivateWindow();
    1.66 +    }, "cookie-changed", false);
    1.67 +    aNormalWindow.gBrowser.selectedBrowser.loadURI(baseURL + "file_beaconCookies.html");
    1.68 +  });
    1.69 +}
    1.70 +
    1.71 +function testOnPrivateWindow() {
    1.72 +  testOnWindow({private: true}, function(aPrivateWindow) {
    1.73 +    Services.obs.addObserver(function waitCookie() {
    1.74 +      Services.obs.removeObserver(waitCookie, "private-cookie-changed");
    1.75 +      ok(true, "private cookie set by beacon request in private window");
    1.76 +      cleanup();
    1.77 +    }, "private-cookie-changed", false);
    1.78 +    aPrivateWindow.gBrowser.selectedBrowser.loadURI(baseURL + "file_beaconCookies.html");
    1.79 +  });
    1.80 +}
    1.81 +
    1.82 +function cleanup() {
    1.83 +  for (var i = 0; i < windowsToClose.length; ++i) {
    1.84 +    windowsToClose[i].close();
    1.85 +  }
    1.86 +  SimpleTest.finish();
    1.87 +}
    1.88 +
    1.89 +</script>
    1.90 +</pre>
    1.91 +</body>
    1.92 +</html>

mercurial