tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cookieStoreManager_getSubscriptions_single.https.any.js (1799B)


      1 // META: title=Cookie Store API: ServiceWorker with one cookie change subscription
      2 // META: global=window,serviceworker
      3 // META: script=/service-workers/service-worker/resources/test-helpers.sub.js
      4 
      5 'use strict';
      6 
      7 promise_test(async testCase => {
      8  let scope;
      9 
     10  if (self.GLOBAL.isWindow()) {
     11    scope = '/cookiestore/resources/does/not/exist';
     12 
     13    const registration = await service_worker_unregister_and_register(
     14        testCase, 'resources/empty_sw.js', scope);
     15    testCase.add_cleanup(() => registration.unregister());
     16 
     17    // Must wait for the service worker to enter the 'activated' state before
     18    // subscribing to cookiechange events.
     19    await wait_for_state(testCase, registration.installing, 'activated');
     20 
     21    self.registration = registration;
     22  } else {
     23    scope = '/cookiestore/does/not/exist';
     24 
     25    // Must wait for the service worker to enter the 'activated' state before
     26    // subscribing to cookiechange events.
     27    await new Promise(resolve => {
     28      self.addEventListener('activate', event => { resolve(); });
     29    });
     30  }
     31 
     32  {
     33    const subscriptions = [{ name: 'cookie-name', url: `${scope}/path` }];
     34    await registration.cookies.subscribe(subscriptions);
     35    testCase.add_cleanup(() => {
     36      // For non-ServiceWorker environments, registration.unregister() cleans up
     37      // cookie subscriptions.
     38      if (self.GLOBAL.isWorker()) {
     39        return registration.cookies.unsubscribe(subscriptions);
     40      }
     41    });
     42  }
     43 
     44  const subscriptions = await registration.cookies.getSubscriptions();
     45  assert_equals(subscriptions.length, 1);
     46 
     47  assert_equals(subscriptions[0].name, 'cookie-name');
     48  assert_equals(subscriptions[0].url,
     49                (new URL(`${scope}/path`, self.location.href)).href);
     50 }, 'getSubscriptions returns a subscription passed to subscribe');