tor-browser

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

register-same-scope-different-script-url.https.html (10172B)


      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 script1 = normalizeURL('resources/empty-worker.js');
      7 var script2 = normalizeURL('resources/empty-worker.js?new');
      8 
      9 async_test(function(t) {
     10    var scope = 'resources/scope/register-new-script-concurrently';
     11    var register_promise1;
     12    var register_promise2;
     13 
     14    service_worker_unregister(t, scope)
     15      .then(function() {
     16          register_promise1 = navigator.serviceWorker.register(script1,
     17                                                               {scope: scope});
     18          register_promise2 = navigator.serviceWorker.register(script2,
     19                                                               {scope: scope});
     20          return register_promise1;
     21        })
     22      .then(function(registration) {
     23          assert_equals(registration.installing.scriptURL, script1,
     24                        'on first register, first script should be installing');
     25          assert_equals(registration.waiting, null,
     26                        'on first register, waiting should be null');
     27          assert_equals(registration.active, null,
     28                        'on first register, active should be null');
     29          return register_promise2;
     30        })
     31      .then(function(registration) {
     32          assert_equals(
     33              registration.installing.scriptURL, script2,
     34              'on second register, second script should be installing');
     35          // Spec allows racing: the first register may have finished
     36          // or the second one could have terminated the installing worker.
     37          assert_true(registration.waiting == null ||
     38                      registration.waiting.scriptURL == script1,
     39                      'on second register, .waiting should be null or the ' +
     40                      'first script');
     41          assert_true(registration.active == null ||
     42                      (registration.waiting == null &&
     43                       registration.active.scriptURL == script1),
     44                      'on second register, .active should be null or the ' +
     45                      'first script');
     46          return registration.unregister();
     47        })
     48      .then(function() {
     49          t.done();
     50        })
     51      .catch(unreached_rejection(t));
     52  }, 'Register different scripts concurrently');
     53 
     54 async_test(function(t) {
     55    var scope = 'resources/scope/register-then-register-new-script';
     56    var registration;
     57 
     58    service_worker_unregister_and_register(t, script1, scope)
     59      .then(function(r) {
     60          registration = r;
     61          return wait_for_state(t, registration.installing, 'activated');
     62        })
     63      .then(function() {
     64          assert_equals(registration.installing, null,
     65                        'on activated, installing should be null');
     66          assert_equals(registration.waiting, null,
     67                        'on activated, waiting should be null');
     68          assert_equals(registration.active.scriptURL, script1,
     69                        'on activated, the first script should be active');
     70          return navigator.serviceWorker.register(script2, {scope:scope});
     71        })
     72      .then(function(r) {
     73          registration = r;
     74          assert_equals(registration.installing.scriptURL, script2,
     75                        'on second register, the second script should be ' +
     76                        'installing');
     77          assert_equals(registration.waiting, null,
     78                        'on second register, waiting should be null');
     79          assert_equals(registration.active.scriptURL, script1,
     80                        'on second register, the first script should be ' +
     81                        'active');
     82          return wait_for_state(t, registration.installing, 'installed');
     83        })
     84      .then(function() {
     85          assert_equals(registration.installing, null,
     86                        'on installed, installing should be null');
     87          assert_equals(registration.waiting.scriptURL, script2,
     88                        'on installed, the second script should be waiting');
     89          assert_equals(registration.active.scriptURL, script1,
     90                        'on installed, the first script should be active');
     91          return registration.unregister();
     92        })
     93      .then(function() {
     94          t.done();
     95        })
     96      .catch(unreached_rejection(t));
     97  }, 'Register then register new script URL');
     98 
     99 async_test(function(t) {
    100    var scope = 'resources/scope/register-then-register-new-script-404';
    101    var registration;
    102 
    103    service_worker_unregister_and_register(t, script1, scope)
    104      .then(function(r) {
    105          registration = r;
    106          return wait_for_state(t, registration.installing, 'activated');
    107        })
    108      .then(function() {
    109          assert_equals(registration.installing, null,
    110                        'on activated, installing should be null');
    111          assert_equals(registration.waiting, null,
    112                        'on activated, waiting should be null');
    113          assert_equals(registration.active.scriptURL, script1,
    114                        'on activated, the first script should be active');
    115          return navigator.serviceWorker.register('this-will-404.js',
    116                                                  {scope:scope});
    117        })
    118      .then(
    119        function() { assert_unreached('register should reject'); },
    120        function(error) {
    121          assert_equals(registration.installing, null,
    122                        'on rejected, installing should be null');
    123          assert_equals(registration.waiting, null,
    124                        'on rejected, waiting should be null');
    125          assert_equals(registration.active.scriptURL, script1,
    126                        'on rejected, the first script should be active');
    127          return registration.unregister();
    128        })
    129      .then(function() {
    130          t.done();
    131        })
    132      .catch(unreached_rejection(t));
    133  }, 'Register then register new script URL that 404s');
    134 
    135 async_test(function(t) {
    136    var scope = 'resources/scope/register-then-register-new-script-reject-install';
    137    var reject_script = normalizeURL('resources/reject-install-worker.js');
    138    var registration;
    139 
    140    service_worker_unregister_and_register(t, script1, scope)
    141      .then(function(r) {
    142          registration = r;
    143          return wait_for_state(t, registration.installing, 'activated');
    144        })
    145      .then(function() {
    146          assert_equals(registration.installing, null,
    147                        'on activated, installing should be null');
    148          assert_equals(registration.waiting, null,
    149                        'on activated, waiting should be null');
    150          assert_equals(registration.active.scriptURL, script1,
    151                        'on activated, the first script should be active');
    152          return navigator.serviceWorker.register(reject_script, {scope:scope});
    153        })
    154      .then(function(r) {
    155          registration = r;
    156          assert_equals(registration.installing.scriptURL, reject_script,
    157                        'on update, the second script should be installing');
    158          assert_equals(registration.waiting, null,
    159                        'on update, waiting should be null');
    160          assert_equals(registration.active.scriptURL, script1,
    161                        'on update, the first script should be active');
    162          return wait_for_state(t, registration.installing, 'redundant');
    163        })
    164      .then(function() {
    165          assert_equals(registration.installing, null,
    166                        'on redundant, installing should be null');
    167          assert_equals(registration.waiting, null,
    168                        'on redundant, waiting should be null');
    169          assert_equals(registration.active.scriptURL, script1,
    170                        'on redundant, the first script should be active');
    171          return registration.unregister();
    172        })
    173      .then(function() {
    174          t.done();
    175        })
    176      .catch(unreached_rejection(t));
    177  }, 'Register then register new script that does not install');
    178 
    179 async_test(function(t) {
    180    var scope = 'resources/scope/register-new-script-controller';
    181    var iframe;
    182    var registration;
    183 
    184    service_worker_unregister_and_register(t, script1, scope)
    185      .then(function(r) {
    186          registration = r;
    187          return wait_for_state(t, registration.installing, 'activated');
    188        })
    189      .then(function() {
    190          return with_iframe(scope);
    191        })
    192      .then(function(frame) {
    193          iframe = frame;
    194          return navigator.serviceWorker.register(script2, { scope: scope })
    195        })
    196      .then(function(r) {
    197          registration = r;
    198          return wait_for_state(t, registration.installing, 'installed');
    199        })
    200      .then(function() {
    201          var sw_container = iframe.contentWindow.navigator.serviceWorker;
    202          assert_equals(sw_container.controller.scriptURL, script1,
    203                        'the old version should control the old doc');
    204          return with_iframe(scope);
    205        })
    206      .then(function(frame) {
    207          var sw_container = frame.contentWindow.navigator.serviceWorker;
    208          assert_equals(sw_container.controller.scriptURL, script1,
    209                        'the old version should control a new doc');
    210          var onactivated_promise = wait_for_state(t,
    211                                                   registration.waiting,
    212                                                   'activated');
    213          frame.remove();
    214          iframe.remove();
    215          return onactivated_promise;
    216        })
    217      .then(function() {
    218          return with_iframe(scope);
    219        })
    220      .then(function(frame) {
    221          var sw_container = frame.contentWindow.navigator.serviceWorker;
    222          assert_equals(sw_container.controller.scriptURL, script2,
    223                        'the new version should control a new doc');
    224          frame.remove();
    225          return registration.unregister();
    226        })
    227      .then(function() {
    228          t.done();
    229        })
    230      .catch(unreached_rejection(t));
    231  }, 'Register same-scope new script url effect on controller');
    232 
    233 </script>