summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_reset.https.html
blob: a1124e9220150ea48e016d805ead1f210a247a25 (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
<!doctype html>
<meta charset="utf-8">
<title>Cookie Store API: reset cookie change subscription list</title>
<link rel="help" href="https://github.com/WICG/cookie-store">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js">
</script>
<script src='resources/helpers.js'></script>
<script>
'use strict';

promise_test(async t => {
  const registration = await service_worker_unregister_and_register(
      t, 'resources/empty_sw.js', 'resources/does/not/exist');
  t.add_cleanup(() => registration.unregister());
  await wait_for_state(t, registration.installing, 'activated');
  await registration.cookies.subscribe(
      [{ name: 'cookie-name' }]);
  const original_subscriptions = await registration.cookies.getSubscriptions();
  assert_equals(original_subscriptions.length, 1,
                'subscription count before unregistration');

  await registration.unregister();

  const new_registration = await navigator.serviceWorker.register(
    'resources/empty_sw.js', { scope: 'resources/does/not/exist' });
  t.add_cleanup(() => new_registration.unregister());
  await wait_for_state(t, new_registration.installing, 'activated');

  const new_subscriptions = await new_registration.cookies.getSubscriptions();
  assert_equals(new_subscriptions.length, 0,
                'subscription count after unregistration');
}, 'cookiechange subscriptions reset across service worker unregistrations');

promise_test(async t => {
  const registration = await service_worker_unregister_and_register(
      t, 'resources/always_changing_sw.sub.js', 'resources/does/not/exist');
  t.add_cleanup(() => registration.unregister());
  await wait_for_state(t, registration.installing, 'activated');
  await registration.cookies.subscribe(
      [{ name: 'cookie-name' }]);
  const original_subscriptions = await registration.cookies.getSubscriptions();
  assert_equals(original_subscriptions.length, 1,
                'subscription count before update');

  await registration.update();
  const worker = await wait_for_update(t, registration);
  await wait_for_state(t, worker, 'activated');

  const update_subscriptions = await registration.cookies.getSubscriptions();
  assert_equals(update_subscriptions.length, 1,
                'subscription count after update');
}, 'cookiechange subscriptions persist across service worker updates');
</script>