summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookie-store/cookieStore_get_set_across_origins.sub.https.html
blob: c67ef98bcc944dbfb815993734dcfae7dbd3eb9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<meta charset='utf-8'>
<title>Async Cookies: cookieStore basic API across origins</title>
<link rel='help' href='https://github.com/WICG/cookie-store'>
<link rel='author' href='jarrydg@chromium.org' title='Jarryd Goodman'>
<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 kPath = '/cookie-store/resources/helper_iframe.sub.html';
const kCorsBase = `https://{{domains[www1]}}:{{ports[https][0]}}`;
const kCorsUrl = `${kCorsBase}${kPath}`;

promise_test(async t => {
  const iframe = await createIframe(kCorsUrl, t);
  assert_true(iframe != null);

  iframe.contentWindow.postMessage({
    opname: 'set-cookie',
    name: 'cookie-name',
    value: 'cookie-value',
  }, kCorsBase);
  t.add_cleanup(async () => {
    await cookieStore.delete({ name: 'cookie-name', domain: '{{host}}' });
  });
  await waitForMessage();

  const cookies = await cookieStore.getAll();
  assert_equals(cookies.length, 1);
  assert_equals(cookies[0].name, 'cookie-name');
  assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.get() sees cookieStore.set() in cross-origin frame');

promise_test(async t => {
  const iframe = await createIframe(kCorsUrl, t);
  assert_true(iframe != null);

  await cookieStore.set({
    name: 'cookie-name',
    value: 'cookie-value',
    domain: '{{host}}',
  });

  const cookie = await cookieStore.get('cookie-name');
  assert_equals(cookie.value, 'cookie-value');

  iframe.contentWindow.postMessage({
    opname: 'get-cookie',
    name: 'cookie-name',
  }, kCorsBase);
  t.add_cleanup(async () => {
    await cookieStore.delete({ name: 'cookie-name', domain: '{{host}}' });
  });

  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() in cross-origin frame sees cookieStore.set()');
</script>