1
0
Fork 0
firefox/netwerk/cookie/test/unit/test_bug643051.js
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

45 lines
1.3 KiB
JavaScript

const { NetUtil } = ChromeUtils.importESModule(
"resource://gre/modules/NetUtil.sys.mjs"
);
const { CookieXPCShellUtils } = ChromeUtils.importESModule(
"resource://testing-common/CookieXPCShellUtils.sys.mjs"
);
CookieXPCShellUtils.init(this);
CookieXPCShellUtils.createServer({ hosts: ["example.net"] });
add_task(async () => {
Services.prefs.setBoolPref("dom.security.https_first", false);
// Allow all cookies.
Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
Services.prefs.setBoolPref(
"network.cookieJarSettings.unblocked_for_testing",
true
);
let uri = NetUtil.newURI("http://example.org/");
let channel = NetUtil.newChannel({
uri,
loadUsingSystemPrincipal: true,
contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
});
let set = "foo=bar\nbaz=foo";
let expected = "foo=bar; baz=foo";
set
.split("\n")
.forEach(s => Services.cookies.setCookieStringFromHttp(uri, s, channel));
let actual = Services.cookies.getCookieStringFromHttp(uri, channel);
Assert.equal(actual, expected);
await CookieXPCShellUtils.setCookieToDocument("http://example.net/", set);
actual = await CookieXPCShellUtils.getCookieStringFromDocument(
"http://example.net/"
);
expected = "";
Assert.equal(actual, expected);
Services.prefs.clearUserPref("dom.security.https_first");
});