summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookie-store/cookieStoreManager_getSubscriptions_empty.https.any.js
blob: 8cfd732f304509582ff8c9be97e8e90e6c06e8ed (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
// META: title=Cookie Store API: ServiceWorker without cookie change subscriptions
// META: global=window,serviceworker
// META: script=/service-workers/service-worker/resources/test-helpers.sub.js

'use strict';

promise_test(async testCase => {
  if (self.GLOBAL.isWindow()) {
    const registration = await service_worker_unregister_and_register(
        testCase, 'resources/empty_sw.js', 'resources/does/not/exist');
    testCase.add_cleanup(() => registration.unregister());

    // Wait for this service worker to become active before snapshotting the
    // subscription state, for consistency with other tests.
    await wait_for_state(testCase, registration.installing, 'activated');

    self.registration = registration;
  } else {
    // Wait for this service worker to become active before snapshotting the
    // subscription state, for consistency with other tests.
    await new Promise(resolve => {
      self.addEventListener('activate', event => { resolve(); });
    });
  }

  const subscriptions = await registration.cookies.getSubscriptions();
  assert_equals(subscriptions.length, 0);
}, 'getSubscriptions returns an empty array when there are no subscriptions');