blob: dac8b87673d7b18189835cae5ccc92d784de5c5a [file] [log] [blame]
<!doctype html>
<meta charset="utf-8">
<title>Cookie Store: cookieStore handles special cookie names correctly</title>
<link rel="help" href="https://github.com/WICG/cookie-store">
<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
['__Secure-', '__Host-'].forEach(prefix => {
promise_test(async testCase => {
await promise_rejects(
testCase, new TypeError(),
cookieStore.set(`${prefix}cookie-name`, `secure-cookie-value`),
`Setting ${prefix} cookies should fail in non-secure contexts`);
try { await cookieStore.delete(`${prefix}cookie-name`); } catch (e) {}
}, `cookieStore.set with ${prefix} name on non-secure origin`);
promise_test(async testCase => {
await promise_rejects(
testCase, new TypeError(),
cookieStore.set(
`${prefix}cookie-name`, `secure-cookie-value`, {
expires: Date.now() - (24 * 60 * 60 * 1000)
}),
`Setting expired ${prefix} cookies should fail in non-secure contexts`);
try { await cookieStore.delete(`${prefix}cookie-name`); } catch (e) {}
}, `cookieStore.set of expired ${prefix} cookie on non-secure origin`);
promise_test(async testCase => {
assert_equals(
await cookieStore.get(`${prefix}cookie-name`),
null,
'get with ${prefix} prefix should not reject');
assert_equals(
await cookieStore.get({name: `${prefix}cookie-name`}),
null,
'get with ${prefix} prefix name option should not reject');
assert_equals(
await cookieStore.get({name: prefix, matchType: 'starts-with'}),
null,
'get with ${prefix} name and starts-with options should not reject');
}, `cookieStore.get with ${prefix} name on non-secure origin`);
promise_test(async testCase => {
assert_array_equals(
await cookieStore.getAll(`${prefix}cookie-name`),
[],
'getAll with ${prefix} prefix should not reject');
assert_array_equals(
await cookieStore.getAll({name: `${prefix}cookie-name`}),
[],
'getAll with ${prefix} prefix name option should not reject');
assert_array_equals(
await cookieStore.getAll({name: prefix, matchType: 'starts-with'}),
[],
'getAll with ${prefix} name and starts-with options should not reject');
}, `cookieStore.getAll with ${prefix} name on non-secure origin`);
promise_test(async testCase => {
await promise_rejects(
testCase, new TypeError(),
cookieStore.delete(`${prefix}cookie-name`, `host-cookie-value`),
`Deleting ${prefix} cookies should fail in non-secure contexts`);
}, `cookieStore.delete with ${prefix} name on non-secure origin`);
});
</script>