Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: browser/components/enterprisepolicies/tests/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
const HOSTNAME_DOMAIN = "browser_policy_clear_blocked_cookies.com";
const ORIGIN_DOMAIN = "browser_policy_clear_blocked_cookies.org";
add_task(async function setup() {
const expiry = Date.now() + 24 * 60 * 60;
Services.cookies.add(
HOSTNAME_DOMAIN,
"/",
"secure",
"true",
true,
false,
false,
expiry,
{},
Ci.nsICookie.SAMESITE_NONE,
Ci.nsICookie.SCHEME_HTTPS
);
Services.cookies.add(
HOSTNAME_DOMAIN,
"/",
"insecure",
"true",
false,
false,
false,
expiry,
{},
Ci.nsICookie.SAMESITE_NONE,
Ci.nsICookie.SCHEME_HTTP
);
Services.cookies.add(
ORIGIN_DOMAIN,
"/",
"secure",
"true",
true,
false,
false,
expiry,
{},
Ci.nsICookie.SAMESITE_NONE,
Ci.nsICookie.SCHEME_HTTPS
);
Services.cookies.add(
ORIGIN_DOMAIN,
"/",
"insecure",
"true",
false,
false,
false,
expiry,
{},
Ci.nsICookie.SAMESITE_NONE,
Ci.nsICookie.SCHEME_HTTP
);
Services.cookies.add(
"example.net",
"/",
"secure",
"true",
true,
false,
false,
expiry,
{},
Ci.nsICookie.SAMESITE_NONE,
Ci.nsICookie.SCHEME_HTTPS
);
await setupPolicyEngineWithJson({
},
});
});
function retrieve_all_cookies(host) {
const values = [];
for (let cookie of Services.cookies.getCookiesFromHost(host, {})) {
values.push({
host: cookie.host,
name: cookie.name,
path: cookie.path,
});
}
return values;
}
add_task(async function test_cookies_for_blocked_sites_cleared() {
const cookies = {
hostname: retrieve_all_cookies(HOSTNAME_DOMAIN),
origin: retrieve_all_cookies(ORIGIN_DOMAIN),
keep: retrieve_all_cookies("example.net"),
};
const expected = {
hostname: [],
origin: [],
keep: [{ host: "example.net", name: "secure", path: "/" }],
};
equal(
JSON.stringify(cookies),
JSON.stringify(expected),
"All stored cookies for blocked origins should be cleared"
);
});
add_task(function teardown() {
for (let host of [HOSTNAME_DOMAIN, ORIGIN_DOMAIN, "example.net"]) {
Services.cookies.removeCookiesWithOriginAttributes("{}", host);
}
});