tor-browser

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

unregister.https.html (4794B)


      1 <!DOCTYPE html>
      2 <title>ServiceWorkerGlobalScope: unregister</title>
      3 <script src='/resources/testharness.js'></script>
      4 <script src='/resources/testharnessreport.js'></script>
      5 <script src='../resources/test-helpers.sub.js'></script>
      6 <script>
      7 
      8 promise_test(function(t) {
      9    var script = 'resources/unregister-worker.js?evaluation';
     10    var scope = 'resources/scope/unregister-on-script-evaluation';
     11 
     12    return service_worker_unregister_and_register(t, script, scope)
     13      .then(function(registration) {
     14          t.add_cleanup(function() {
     15              return service_worker_unregister(t, scope);
     16            });
     17 
     18          return wait_for_state(t, registration.installing, 'redundant');
     19        })
     20      .then(function() {
     21          return navigator.serviceWorker.getRegistration(scope);
     22        })
     23      .then(function(result) {
     24          assert_equals(
     25            result,
     26            undefined,
     27            'After unregister(), the registration should not found');
     28        });
     29  }, 'Unregister on script evaluation');
     30 
     31 promise_test(function(t) {
     32    var script = 'resources/unregister-worker.js?install';
     33    var scope = 'resources/scope/unregister-on-install-event';
     34 
     35    return service_worker_unregister_and_register(t, script, scope)
     36      .then(function(registration) {
     37          t.add_cleanup(function() {
     38              return service_worker_unregister(t, scope);
     39            });
     40 
     41          return wait_for_state(t, registration.installing, 'redundant');
     42        })
     43      .then(function() {
     44          return navigator.serviceWorker.getRegistration(scope);
     45        })
     46      .then(function(result) {
     47          assert_equals(
     48            result,
     49            undefined,
     50            'After unregister(), the registration should not found');
     51        });
     52  }, 'Unregister on installing event');
     53 
     54 promise_test(function(t) {
     55    var script = 'resources/unregister-worker.js?activate';
     56    var scope = 'resources/scope/unregister-on-activate-event';
     57 
     58    return service_worker_unregister_and_register(t, script, scope)
     59      .then(function(registration) {
     60          t.add_cleanup(function() {
     61              return service_worker_unregister(t, scope);
     62            });
     63 
     64          return wait_for_state(t, registration.installing, 'redundant');
     65        })
     66      .then(function() {
     67          return navigator.serviceWorker.getRegistration(scope);
     68        })
     69      .then(function(result) {
     70          assert_equals(
     71            result,
     72            undefined,
     73            'After unregister(), the registration should not found');
     74        });
     75  }, 'Unregister on activate event');
     76 
     77 promise_test(function(t) {
     78    var script = 'resources/unregister-worker.js';
     79    var scope = 'resources/unregister-controlling-worker.html';
     80 
     81    var controller;
     82    var frame;
     83 
     84    return service_worker_unregister_and_register(t, script, scope)
     85      .then(function(registration) {
     86          t.add_cleanup(function() {
     87              return service_worker_unregister(t, scope);
     88            });
     89 
     90          return wait_for_state(t, registration.installing, 'activated');
     91        })
     92      .then(function() { return with_iframe(scope); })
     93      .then(function(f) {
     94          frame = f;
     95          controller = frame.contentWindow.navigator.serviceWorker.controller;
     96 
     97          assert_equals(
     98            controller.scriptURL,
     99            normalizeURL(script),
    100            'Service worker should control a new document')
    101 
    102          // Wait for the completion of unregister() on the worker.
    103          var channel = new MessageChannel();
    104          var promise = new Promise(function(resolve) {
    105              channel.port1.onmessage = t.step_func(function(e) {
    106                  assert_true(e.data.result,
    107                              'unregister() should successfully finish');
    108                  resolve();
    109                });
    110            });
    111          controller.postMessage({port: channel.port2}, [channel.port2]);
    112          return promise;
    113        })
    114      .then(function() {
    115          return navigator.serviceWorker.getRegistration(scope);
    116        })
    117      .then(function(result) {
    118          assert_equals(
    119            result,
    120            undefined,
    121            'After unregister(), the registration should not found');
    122          assert_equals(
    123            frame.contentWindow.navigator.serviceWorker.controller,
    124            controller,
    125            'After unregister(), the worker should still control the document');
    126          return with_iframe(scope);
    127        })
    128      .then(function(new_frame) {
    129          assert_equals(
    130            new_frame.contentWindow.navigator.serviceWorker.controller,
    131            null,
    132            'After unregister(), the worker should not control a new document');
    133 
    134          frame.remove();
    135          new_frame.remove();
    136        })
    137  }, 'Unregister controlling service worker');
    138 
    139 </script>