tor-browser

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

get.https.window.js (2761B)


      1 // META: script=/service-workers/service-worker/resources/test-helpers.sub.js
      2 // META: script=resources/utils.js
      3 'use strict';
      4 
      5 // Covers functionality provided by BackgroundFetchManager.get(), which
      6 // exposes the keys of active background fetches.
      7 //
      8 // https://wicg.github.io/background-fetch/#background-fetch-manager-get
      9 
     10 promise_test(async test => {
     11  const script = 'service_workers/sw.js';
     12  const scope = 'service_workers/' + location.pathname;
     13 
     14  const serviceWorkerRegistration =
     15      await service_worker_unregister_and_register(test, script, scope);
     16 
     17  assert_equals(
     18      serviceWorkerRegistration.active, null,
     19      'There must not be an activated worker');
     20 
     21  const registration = await serviceWorkerRegistration.backgroundFetch.get('x');
     22  assert_equals(registration, undefined);
     23 
     24 }, 'BackgroundFetchManager.get() does not require an activated worker');
     25 
     26 backgroundFetchTest(async (test, backgroundFetch) => {
     27  // The |id| parameter to the BackgroundFetchManager.get() method is required.
     28  await promise_rejects_js(test, TypeError, backgroundFetch.get());
     29  await promise_rejects_js(test, TypeError, backgroundFetch.get(''));
     30 
     31  const registration = await backgroundFetch.get('my-id');
     32  assert_equals(registration, undefined);
     33 
     34 }, 'Getting non-existing registrations yields `undefined`');
     35 
     36 backgroundFetchTest(async (test, backgroundFetch) => {
     37  const registrationId = uniqueId();
     38  const registration = await backgroundFetch.fetch(
     39      registrationId, 'resources/feature-name.txt', {downloadTotal: 1234});
     40 
     41  assert_equals(registration.id, registrationId);
     42  assert_equals(registration.uploadTotal, 0);
     43  assert_equals(registration.uploaded, 0);
     44  assert_equals(registration.downloadTotal, 1234);
     45  assert_equals(registration.result, '');
     46  assert_equals(registration.failureReason, '');
     47  assert_true(registration.recordsAvailable);
     48  // Skip `downloaded`, as the transfer may have started already.
     49 
     50  const secondRegistration = await backgroundFetch.get(registrationId);
     51  assert_not_equals(secondRegistration, null);
     52 
     53  assert_equals(secondRegistration.id, registration.id);
     54  assert_equals(secondRegistration.uploadTotal, registration.uploadTotal);
     55  assert_equals(secondRegistration.uploaded, registration.uploaded);
     56  assert_equals(secondRegistration.downloadTotal, registration.downloadTotal);
     57  assert_equals(secondRegistration.failureReason, registration.failureReason);
     58  assert_equals(secondRegistration.recordsAvailable, registration.recordsAvailable);
     59 
     60  // While the transfer might have started, both BackgroundFetchRegistration
     61  // objects should have the latest progress values.
     62  assert_equals(secondRegistration.downloaded, registration.downloaded);
     63 
     64 }, 'Getting an existing registration has the expected values');