diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/tests/mochitest/beacon/test_beaconCookies.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/mochitest/beacon/test_beaconCookies.html')
-rw-r--r-- | dom/tests/mochitest/beacon/test_beaconCookies.html | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/dom/tests/mochitest/beacon/test_beaconCookies.html b/dom/tests/mochitest/beacon/test_beaconCookies.html new file mode 100644 index 0000000000..5e634664eb --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconCookies.html @@ -0,0 +1,84 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=936340 +--> +<head> + <title>Test whether sendBeacon sets cookies</title> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936340">Mozilla Bug 936340</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +// not enabled by default yet. +SimpleTest.waitForExplicitFinish(); +SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, beginTest); + +const {BrowserTestUtils} = ChromeUtils.importESModule( + "resource://testing-common/BrowserTestUtils.sys.mjs" +); + +var baseURL = "http://mochi.test:8888/chrome/dom/tests/mochitest/beacon/"; + +function whenDelayedStartupFinished(aWindow, aCallback) { + Services.obs.addObserver(function observer(aSubject, aTopic) { + if (aWindow == aSubject) { + Services.obs.removeObserver(observer, aTopic); + setTimeout(aCallback, 0); + } + }, "browser-delayed-startup-finished"); +} + +function testOnWindow(options, callback) { + var mainWindow = window.browsingContext.topChromeWindow; + + var win = mainWindow.OpenBrowserWindow(options); + windowsToClose.push(win); + whenDelayedStartupFinished(win, function() { + callback(win); + }); +}; + +var windowsToClose = []; +var next; + +function beginTest() { + testOnWindow({}, function(aNormalWindow) { + Services.obs.addObserver(function waitCookie() { + Services.obs.removeObserver(waitCookie, "cookie-changed"); + ok(true, "cookie set by beacon request in normal window"); + testOnPrivateWindow(); + }, "cookie-changed"); + BrowserTestUtils.startLoadingURIString(aNormalWindow.gBrowser.selectedBrowser, baseURL + "file_beaconCookies.html"); + }); +} + +function testOnPrivateWindow() { + testOnWindow({private: true}, function(aPrivateWindow) { + Services.obs.addObserver(function waitCookie() { + Services.obs.removeObserver(waitCookie, "private-cookie-changed"); + ok(true, "private cookie set by beacon request in private window"); + cleanup(); + }, "private-cookie-changed"); + BrowserTestUtils.startLoadingURIString(aPrivateWindow.gBrowser.selectedBrowser, baseURL + "file_beaconCookies.html"); + }); +} + +function cleanup() { + for (var i = 0; i < windowsToClose.length; ++i) { + windowsToClose[i].close(); + } + SimpleTest.finish(); +} + +</script> +</pre> +</body> +</html> |