Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<meta charset='utf-8'>
<title>Async Cookies: cookieStore basic API on creation URL with fragments</title>
<link rel='help' href='https://github.com/WICG/cookie-store'>
<link rel='author' href='baku@mozilla.com' title='Andrea Marchesini'>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script src='resources/helpers.js'></script>
<style>iframe { display: none; }</style>
<script>
'use strict';
const kUrl = '/cookie-store/resources/helper_iframe.sub.html';
promise_test(async t => {
const url = new URL(kUrl, location);
const iframe = await createIframe(url + "#fragment", t);
assert_true(iframe != null);
iframe.contentWindow.postMessage({
opname: 'set-cookie',
name: 'cookie-name',
value: 'cookie-value',
}, '*');
t.add_cleanup(async () => {
await cookieStore.delete({ name: 'cookie-name', domain: '{{host}}' });
});
await waitForMessage();
iframe.contentWindow.postMessage({
opname: 'get-cookie',
name: 'cookie-name',
options: { url: url.href }
}, '*');
const message = await waitForMessage();
const { frameCookie } = message;
assert_not_equals(frameCookie, null);
assert_equals(frameCookie.name, 'cookie-name');
assert_equals(frameCookie.value, 'cookie-value');
}, 'cookieStore.get() option url ignores fragments');
promise_test(async t => {
const url = new URL(kUrl, location);
const iframe = await createIframe(url + "#fragment", t);
assert_true(iframe != null);
iframe.contentWindow.postMessage({
opname: 'set-cookie',
name: 'cookie-name',
value: 'cookie-value',
}, '*');
t.add_cleanup(async () => {
await cookieStore.delete({ name: 'cookie-name', domain: '{{host}}' });
});
await waitForMessage();
iframe.contentWindow.postMessage({
opname: 'push-state',
}, '*');
await waitForMessage();
iframe.contentWindow.postMessage({
opname: 'get-cookie',
name: 'cookie-name',
options: { url: url.href }
}, '*');
const message = await waitForMessage();
const { frameCookie } = message;
assert_not_equals(frameCookie, null);
assert_equals(frameCookie.name, 'cookie-name');
assert_equals(frameCookie.value, 'cookie-value');
}, 'cookieStore.get() option url + pushState()');
</script>