dom/tests/mochitest/beacon/test_beaconCookies.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial