tor-browser

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

unregister-then-register.https.html (4296B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="resources/test-helpers.sub.js"></script>
      5 <script>
      6 var worker_url = 'resources/empty-worker.js';
      7 
      8 promise_test(async function(t) {
      9    const scope = 'resources/scope/re-register-resolves-to-new-value';
     10    const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     11    t.add_cleanup(() => registration.unregister());
     12 
     13    await wait_for_state(t, registration.installing, 'activated');
     14    await registration.unregister();
     15    const newRegistration = await navigator.serviceWorker.register(worker_url, { scope });
     16    t.add_cleanup(() => newRegistration.unregister());
     17 
     18    assert_not_equals(
     19      registration, newRegistration,
     20      'register should resolve to a new value'
     21    );
     22  }, 'Unregister then register resolves to a new value');
     23 
     24 promise_test(async function(t) {
     25  const scope = 'resources/scope/re-register-while-old-registration-in-use';
     26  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     27  t.add_cleanup(() => registration.unregister());
     28 
     29  await wait_for_state(t, registration.installing, 'activated');
     30  const frame = await with_iframe(scope);
     31  t.add_cleanup(() => frame.remove());
     32 
     33  await registration.unregister();
     34  const newRegistration = await navigator.serviceWorker.register(worker_url, { scope });
     35  t.add_cleanup(() => newRegistration.unregister());
     36 
     37  assert_not_equals(
     38    registration, newRegistration,
     39    'Unregister and register should always create a new registration'
     40  );
     41 }, 'Unregister then register does not resolve to the original value even if the registration is in use.');
     42 
     43 promise_test(function(t) {
     44    var scope = 'resources/scope/re-register-does-not-affect-existing-controllee';
     45    var iframe;
     46    var registration;
     47    var controller;
     48 
     49    return service_worker_unregister_and_register(t, worker_url, scope)
     50      .then(function(r) {
     51          t.add_cleanup(function() {
     52            return service_worker_unregister(t, scope);
     53          });
     54 
     55          registration = r;
     56          return wait_for_state(t, r.installing, 'activated');
     57        })
     58      .then(function() {
     59          return with_iframe(scope);
     60        })
     61      .then(function(frame) {
     62          iframe = frame;
     63          controller = iframe.contentWindow.navigator.serviceWorker.controller;
     64          return registration.unregister();
     65        })
     66      .then(function() {
     67          return navigator.serviceWorker.register(worker_url, { scope: scope });
     68        })
     69      .then(function(newRegistration) {
     70          assert_equals(registration.installing, null,
     71                        'installing version is null');
     72          assert_equals(registration.waiting, null, 'waiting version is null');
     73          assert_equals(
     74              iframe.contentWindow.navigator.serviceWorker.controller,
     75              controller,
     76              'the worker from the first registration is the controller');
     77          iframe.remove();
     78        });
     79  }, 'Unregister then register does not affect existing controllee');
     80 
     81 promise_test(async function(t) {
     82  const scope = 'resources/scope/resurrection';
     83  const altWorkerURL = worker_url + '?alt';
     84  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     85  t.add_cleanup(() => registration.unregister());
     86 
     87  await wait_for_state(t, registration.installing, 'activating');
     88  const iframe = await with_iframe(scope);
     89  t.add_cleanup(() => iframe.remove());
     90 
     91  await registration.unregister();
     92  const newRegistration = await navigator.serviceWorker.register(altWorkerURL, { scope });
     93  t.add_cleanup(() => newRegistration.unregister());
     94 
     95  assert_equals(newRegistration.active, null, 'Registration is new');
     96 
     97  await wait_for_state(t, newRegistration.installing, 'activating');
     98 
     99  const newIframe = await with_iframe(scope);
    100  t.add_cleanup(() => newIframe.remove());
    101 
    102  const iframeController = iframe.contentWindow.navigator.serviceWorker.controller;
    103  const newIframeController = newIframe.contentWindow.navigator.serviceWorker.controller;
    104 
    105  assert_not_equals(iframeController, newIframeController, 'iframes have different controllers');
    106 }, 'Unregister then register does not resurrect the registration');
    107 </script>