tor-browser

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

unregister-then-register-new-script.https.html (4610B)


      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/unregister-then-register-new-script-that-exists';
     10  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     11  t.add_cleanup(() => registration.unregister());
     12 
     13  const newWorkerURL = worker_url + '?new';
     14  await wait_for_state(t, registration.installing, 'activated');
     15 
     16  const iframe = await with_iframe(scope);
     17  t.add_cleanup(() => iframe.remove());
     18 
     19  await registration.unregister();
     20 
     21  const newRegistration = await navigator.serviceWorker.register(newWorkerURL, { scope });
     22  t.add_cleanup(() => newRegistration.unregister());
     23 
     24  assert_equals(
     25    registration.installing,
     26    null,
     27    'before activated registration.installing'
     28  );
     29  assert_equals(
     30    registration.waiting,
     31    null,
     32    'before activated registration.waiting'
     33  );
     34  assert_equals(
     35    registration.active.scriptURL,
     36    normalizeURL(worker_url),
     37    'before activated registration.active'
     38  );
     39  assert_equals(
     40    newRegistration.installing.scriptURL,
     41    normalizeURL(newWorkerURL),
     42    'before activated newRegistration.installing'
     43  );
     44  assert_equals(
     45    newRegistration.waiting,
     46    null,
     47    'before activated newRegistration.waiting'
     48  );
     49  assert_equals(
     50    newRegistration.active,
     51    null,
     52    'before activated newRegistration.active'
     53  );
     54  iframe.remove();
     55 
     56  await wait_for_state(t, newRegistration.installing, 'activated');
     57 
     58  assert_equals(
     59    newRegistration.installing,
     60    null,
     61    'after activated newRegistration.installing'
     62  );
     63  assert_equals(
     64    newRegistration.waiting,
     65    null,
     66    'after activated newRegistration.waiting'
     67  );
     68  assert_equals(
     69    newRegistration.active.scriptURL,
     70    normalizeURL(newWorkerURL),
     71    'after activated newRegistration.active'
     72  );
     73 
     74  const newIframe = await with_iframe(scope);
     75  t.add_cleanup(() => newIframe.remove());
     76 
     77  assert_equals(
     78    newIframe.contentWindow.navigator.serviceWorker.controller.scriptURL,
     79    normalizeURL(newWorkerURL),
     80    'the new worker should control a new document'
     81  );
     82 }, 'Registering a new script URL while an unregistered registration is in use');
     83 
     84 promise_test(async function(t) {
     85  const scope = 'resources/scope/unregister-then-register-new-script-that-404s';
     86  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     87  t.add_cleanup(() => registration.unregister());
     88 
     89  await wait_for_state(t, registration.installing, 'activated');
     90 
     91  const iframe = await with_iframe(scope);
     92  t.add_cleanup(() => iframe.remove());
     93 
     94  await registration.unregister();
     95 
     96  await promise_rejects_js(
     97    t, TypeError,
     98    navigator.serviceWorker.register('this-will-404', { scope })
     99  );
    100 
    101  assert_equals(registration.installing, null, 'registration.installing');
    102  assert_equals(registration.waiting, null, 'registration.waiting');
    103  assert_equals(registration.active.scriptURL, normalizeURL(worker_url), 'registration.active');
    104 
    105  const newIframe = await with_iframe(scope);
    106  t.add_cleanup(() => newIframe.remove());
    107 
    108  assert_equals(newIframe.contentWindow.navigator.serviceWorker.controller, null, 'Document should not be controlled');
    109 }, 'Registering a new script URL that 404s does not resurrect unregistered registration');
    110 
    111 promise_test(async function(t) {
    112  const scope = 'resources/scope/unregister-then-register-reject-install-worker';
    113  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
    114  t.add_cleanup(() => registration.unregister());
    115 
    116  await wait_for_state(t, registration.installing, 'activated');
    117 
    118  const iframe = await with_iframe(scope);
    119  t.add_cleanup(() => iframe.remove());
    120 
    121  await registration.unregister();
    122 
    123  const newRegistration = await navigator.serviceWorker.register(
    124    'resources/reject-install-worker.js', { scope }
    125  );
    126  t.add_cleanup(() => newRegistration.unregister());
    127 
    128  await wait_for_state(t, newRegistration.installing, 'redundant');
    129 
    130  assert_equals(registration.installing, null, 'registration.installing');
    131  assert_equals(registration.waiting, null, 'registration.waiting');
    132  assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
    133                'registration.active');
    134  assert_not_equals(registration, newRegistration, 'New registration is different');
    135 }, 'Registering a new script URL that fails to install does not resurrect unregistered registration');
    136 </script>