tor-browser

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

multiple-update.https.html (4527B)


      1 <!DOCTYPE html>
      2 <!-- In Bug 1217367, we will try to merge update events for same registration
      3     if possible. This testcase is used to make sure the optimization algorithm
      4     doesn't go wrong. -->
      5 <title>Service Worker: Trigger multiple updates</title>
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="resources/test-helpers.sub.js"></script>
      9 <script>
     10 promise_test(function(t) {
     11    var script = 'resources/update-nocookie-worker.py';
     12    var scope = 'resources/scope/update';
     13    var expected_url = normalizeURL(script);
     14    var registration;
     15 
     16    return service_worker_unregister_and_register(t, expected_url, scope)
     17      .then(function(r) {
     18          t.add_cleanup(function() {
     19              return service_worker_unregister(t, scope);
     20            });
     21 
     22          registration = r;
     23          return wait_for_state(t, registration.installing, 'activated');
     24        })
     25      .then(function() {
     26          // Test single update works before triggering multiple update events
     27          return Promise.all([registration.update(),
     28                              wait_for_update(t, registration)]);
     29        })
     30      .then(function() {
     31          assert_equals(registration.installing.scriptURL, expected_url,
     32                        'new installing should be set after update resolves.');
     33          assert_equals(registration.waiting, null,
     34                        'waiting should still be null after update resolves.');
     35          assert_equals(registration.active.scriptURL, expected_url,
     36                        'active should still exist after update found.');
     37          return wait_for_state(t, registration.installing, 'installed');
     38        })
     39      .then(function() {
     40          assert_equals(registration.installing, null,
     41                        'installing should be null after installing.');
     42          if (registration.waiting) {
     43            assert_equals(registration.waiting.scriptURL, expected_url,
     44                          'waiting should be set after installing.');
     45            assert_equals(registration.active.scriptURL, expected_url,
     46                          'active should still exist after installing.');
     47            return wait_for_state(t, registration.waiting, 'activated');
     48          }
     49        })
     50      .then(function() {
     51          // Test triggering multiple update events at the same time.
     52          var promiseList = [];
     53          const burstUpdateCount = 10;
     54          for (var i = 0; i < burstUpdateCount; i++) {
     55            promiseList.push(registration.update());
     56          }
     57          promiseList.push(wait_for_update(t, registration));
     58          return Promise.all(promiseList);
     59        })
     60      .then(function() {
     61          assert_equals(registration.installing.scriptURL, expected_url,
     62                        'new installing should be set after update resolves.');
     63          assert_equals(registration.waiting, null,
     64                        'waiting should still be null after update resolves.');
     65          assert_equals(registration.active.scriptURL, expected_url,
     66                        'active should still exist after update found.');
     67          return wait_for_state(t, registration.installing, 'installed');
     68        })
     69      .then(function() {
     70          assert_equals(registration.installing, null,
     71                        'installing should be null after installing.');
     72          if (registration.waiting) {
     73            assert_equals(registration.waiting.scriptURL, expected_url,
     74                          'waiting should be set after installing.');
     75            assert_equals(registration.active.scriptURL, expected_url,
     76                          'active should still exist after installing.');
     77            return wait_for_state(t, registration.waiting, 'activated');
     78          }
     79        })
     80      .then(function() {
     81          // Test update still works after handling update event burst.
     82          return Promise.all([registration.update(),
     83                              wait_for_update(t, registration)]);
     84        })
     85      .then(function() {
     86          assert_equals(registration.installing.scriptURL, expected_url,
     87                        'new installing should be set after update resolves.');
     88          assert_equals(registration.waiting, null,
     89                        'waiting should be null after activated.');
     90          assert_equals(registration.active.scriptURL, expected_url,
     91                        'active should still exist after update found.');
     92        });
     93  }, 'Trigger multiple updates.');
     94 </script>