Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body>
<script>
async function ValidateCookieStoreSet(testCase, cookieDomain, cookieName) {
await cookieStore.set(
{ name: cookieName, value: "cookie-value", domain: cookieDomain });
testCase.add_cleanup(async () => {
await cookieStore.delete("cookie-name");
});
const cookie = await cookieStore.get(cookieName);
assert_equals(cookie.name, cookieName);
assert_equals(cookie.value, "cookie-value");
}
const url = new URL(self.location.href);
const test = url.searchParams.get("test");
let cookieDomain;
switch (test) {
case "IDNA":
cookieDomain = url.hostname;
promise_test(async t => { await ValidateCookieStoreSet(t, cookieDomain, test) }, "cookieStore.set with domain on a IDNA host");
break;
case "IP":
cookieDomain = url.hostname;
promise_test(async t => { await ValidateCookieStoreSet(t, cookieDomain, test) }, "cookieStore.set with domain on an IP address host");
break;
case "uppercase":
cookieDomain = url.hostname;
// scramble the casing of the characters example.com ==> ExAmPlE.CoM
cookieDomain = cookieDomain.split("")
.map((char, index) =>
index % 2 === 0 ? char.toUpperCase() : char.toLowerCase()
)
.join("");
promise_test(async t => { await ValidateCookieStoreSet(t, cookieDomain, test) }, "cookieStore.set with domain set to the current hostname but differently cased");
break;
default:
throw new Error(`Invalid test parameter: ${test}`);
}
</script>
</body>
</html>