summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookie-store/cookieStore_get_set_ordering.https.any.js
blob: 6b7e73950cbd652309dbbd35bb780e84294f1a70 (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
// META: title=Cookie Store API: Cookie ordering
// META: global=window,serviceworker

'use strict';

promise_test(async t => {
  await cookieStore.set('ordered-1', 'cookie-value1');
  await cookieStore.set('ordered-2', 'cookie-value2');
  await cookieStore.set('ordered-3', 'cookie-value3');
  // NOTE: this assumes no concurrent writes from elsewhere; it also
  // uses three separate cookie jar read operations where a single getAll
  // would be more efficient, but this way the CookieStore does the filtering
  // for us.
  const matchingValues = await Promise.all(['1', '2', '3'].map(
      async suffix => (await cookieStore.get('ordered-' + suffix)).value));
  const actual = matchingValues.join(';');
  const expected = 'cookie-value1;cookie-value2;cookie-value3';
  assert_equals(actual, expected);
}, 'Set three simple origin session cookies sequentially and ensure ' +
            'they all end up in the cookie jar in order.');

promise_test(async t => {
  await Promise.all([
    cookieStore.set('ordered-unordered1', 'unordered-cookie-value1'),
    cookieStore.set('ordered-unordered2', 'unordered-cookie-value2'),
    cookieStore.set('ordered-unordered3', 'unordered-cookie-value3')
  ]);
  // NOTE: this assumes no concurrent writes from elsewhere; it also
  // uses three separate cookie jar read operations where a single getAll
  // would be more efficient, but this way the CookieStore does the filtering
  // for us and we do not need to sort.
  const matchingCookies = await Promise.all(['1', '2', '3'].map(
    suffix => cookieStore.get('ordered-unordered' + suffix)));
  const actual = matchingCookies.map(({ value }) => value).join(';');
  const expected =
      'unordered-cookie-value1;' +
      'unordered-cookie-value2;' +
      'unordered-cookie-value3';
  assert_equals(actual, expected);
}, 'Set three simple origin session cookies in undefined order using ' +
            'Promise.all and ensure they all end up in the cookie jar in any ' +
            'order. ');