tor-browser

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

multiple-register.https.html (4311B)


      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 <body>
      6 <script>
      7 var worker_url = 'resources/empty-worker.js';
      8 
      9 async_test(function(t) {
     10  var scope = 'resources/scope/subsequent-register-from-same-window';
     11  var registration;
     12 
     13  service_worker_unregister_and_register(t, worker_url, scope)
     14    .then(function(r) {
     15        registration = r;
     16        return wait_for_state(t, r.installing, 'activated');
     17      })
     18    .then(function() {
     19        return navigator.serviceWorker.register(worker_url, { scope: scope });
     20      })
     21    .then(function(new_registration) {
     22        assert_equals(new_registration, registration,
     23                      'register should resolve to the same registration');
     24        assert_equals(new_registration.active, registration.active,
     25                      'register should resolve to the same worker');
     26        assert_equals(new_registration.active.state, 'activated',
     27                      'the worker should be in state "activated"');
     28        return registration.unregister();
     29      })
     30    .then(function() { t.done(); })
     31    .catch(unreached_rejection(t));
     32 }, 'Subsequent registrations resolve to the same registration object');
     33 
     34 async_test(function(t) {
     35  var scope = 'resources/scope/subsequent-register-from-different-iframe';
     36  var frame;
     37  var registration;
     38 
     39  service_worker_unregister_and_register(t, worker_url, scope)
     40    .then(function(r) {
     41        registration = r;
     42        return wait_for_state(t, r.installing, 'activated');
     43      })
     44    .then(function() { return with_iframe('resources/404.py'); })
     45    .then(function(f) {
     46        frame = f;
     47        return frame.contentWindow.navigator.serviceWorker.register(
     48            'empty-worker.js',
     49            { scope: 'scope/subsequent-register-from-different-iframe' });
     50      })
     51    .then(function(new_registration) {
     52        assert_not_equals(
     53          registration, new_registration,
     54          'register should resolve to a different registration');
     55        assert_equals(
     56          registration.scope, new_registration.scope,
     57          'registrations should have the same scope');
     58 
     59        assert_equals(
     60          registration.installing, null,
     61          'installing worker should be null');
     62        assert_equals(
     63          new_registration.installing, null,
     64          'installing worker should be null');
     65        assert_equals(
     66          registration.waiting, null,
     67          'waiting worker should be null')
     68        assert_equals(
     69          new_registration.waiting, null,
     70          'waiting worker should be null')
     71 
     72        assert_not_equals(
     73          registration.active, new_registration.active,
     74          'registration should have a different active worker');
     75        assert_equals(
     76          registration.active.scriptURL,
     77          new_registration.active.scriptURL,
     78          'active workers should have the same script URL');
     79        assert_equals(
     80          registration.active.state,
     81          new_registration.active.state,
     82          'active workers should be in the same state');
     83 
     84        frame.remove();
     85        return registration.unregister();
     86      })
     87    .then(function() { t.done(); })
     88    .catch(unreached_rejection(t));
     89 }, 'Subsequent registrations from a different iframe resolve to the ' +
     90       'different registration object but they refer to the same ' +
     91       'registration and workers');
     92 
     93 async_test(function(t) {
     94  var scope = 'resources/scope/concurrent-register';
     95 
     96  service_worker_unregister(t, scope)
     97    .then(function() {
     98        var promises = [];
     99        for (var i = 0; i < 10; ++i) {
    100          promises.push(navigator.serviceWorker.register(worker_url,
    101                                                         { scope: scope }));
    102        }
    103        return Promise.all(promises);
    104      })
    105    .then(function(registrations) {
    106        registrations.forEach(function(registration) {
    107            assert_equals(registration, registrations[0],
    108                          'register should resolve to the same registration');
    109          });
    110        return registrations[0].unregister();
    111      })
    112    .then(function() { t.done(); })
    113    .catch(unreached_rejection(t));
    114 }, 'Concurrent registrations resolve to the same registration object');
    115 
    116 </script>
    117 </body>