diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/test/mochitests/test_1331680_xhr.html | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/mochitests/test_1331680_xhr.html')
-rw-r--r-- | netwerk/test/mochitests/test_1331680_xhr.html | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/netwerk/test/mochitests/test_1331680_xhr.html b/netwerk/test/mochitests/test_1331680_xhr.html new file mode 100644 index 0000000000..0649d33ff4 --- /dev/null +++ b/netwerk/test/mochitests/test_1331680_xhr.html @@ -0,0 +1,90 @@ +<!DOCTYPE HTML> +<html> +<!-- +--> +<head> + <title>Cookie changes from XHR requests are observed in content processes.</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + +<script type="text/javascript"> +SimpleTest.waitForExplicitFinish(); + +const XHR_COOKIE_NAMES = ["xhr1", "xhr2"]; + +var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('file_1331680.js')); +gScript.addMessageListener("cookieName", confirmCookieName); +gScript.addMessageListener("removeObserver:return", finishTest); +gScript.sendAsyncMessage('createObserver'); + +// Confirm the notify which represents the cookie is updating. +var testsNum = 0; +function confirmCookieName(name) { + testsNum++; + switch(testsNum) { + case 1: + is(name, "xhr1=xhr_val1", "The cookie which names " + name + " is update to db"); + break; + case 2: + is(document.cookie, "xhr1=xhr_val1", "Confirm the cookie string"); + for (var i = 0; i < XHR_COOKIE_NAMES.length; i++) { + document.cookie = XHR_COOKIE_NAMES[i] + "=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT"; + } + break; + case 3: + is(document.cookie, "", "Confirm the cookie string"); + gScript.sendAsyncMessage('removeObserver'); + break; + } +} + +function finishTest() { + SpecialPowers.clearUserPref("network.cookie.sameSite.laxByDefault"); + SimpleTest.finish(); +} + +function createXHR(url) { + return new Promise(function (resolve, reject) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); // async request + xhr.onload = function () { + if (this.status >= 200 && this.status < 300) { + resolve(xhr.response); + } else { + reject({ + status: this.status, + statusText: xhr.statusText + }); + } + }; + xhr.onerror = function () { + reject({ + status: this.status, + statusText: xhr.statusText + }); + }; + xhr.send(); + }); +} + +/* Test XHR + * 1. Create two XHR. + * 2. One of the XHR create a cookie names "xhr1", and other one create a http-only cookie names "xhr2". + * 3. Child process only set xhr1 to cookies hash table. + * 4. Child process only can get the xhr1 cookie from cookies hash table. + */ +SpecialPowers.pushPrefEnv({ + // Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default" + set: [["network.cookie.sameSite.laxByDefault", false]], +}).then(_ => createXHR('set_cookie_xhr.sjs?xhr1')) + .then(_ => createXHR('set_cookie_xhr.sjs?xhr2')); + +</script> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"></div> +<pre id="test"> +</pre> +</body> +</html> |