tor-browser

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

registration-service-worker-attributes.https.html (3217B)


      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 'use strict';
      7 promise_test(function(t) {
      8    var scope = 'resources/scope/installing-waiting-active-after-registration';
      9    var worker_url = 'resources/empty-worker.js';
     10    var expected_url = normalizeURL(worker_url);
     11    var newest_worker;
     12    var registration;
     13 
     14    return service_worker_unregister_and_register(t, worker_url, scope)
     15      .then(function(r) {
     16          t.add_cleanup(function() {
     17              return r.unregister();
     18            });
     19          registration = r;
     20          newest_worker = registration.installing;
     21          assert_equals(registration.installing.scriptURL, expected_url,
     22                        'installing before updatefound');
     23          assert_equals(registration.waiting, null,
     24                        'waiting before updatefound');
     25          assert_equals(registration.active, null,
     26                        'active before updatefound');
     27          return wait_for_update(t, registration);
     28        })
     29      .then(function() {
     30          assert_equals(registration.installing, newest_worker,
     31                        'installing after updatefound');
     32          assert_equals(registration.waiting, null,
     33                        'waiting after updatefound');
     34          assert_equals(registration.active, null,
     35                        'active after updatefound');
     36          return wait_for_state(t, registration.installing, 'installed');
     37        })
     38      .then(function() {
     39          assert_equals(registration.installing, null,
     40                        'installing after installed');
     41          assert_equals(registration.waiting, newest_worker,
     42                        'waiting after installed');
     43          assert_equals(registration.active, null,
     44                        'active after installed');
     45          return wait_for_state(t, registration.waiting, 'activated');
     46        })
     47      .then(function() {
     48          assert_equals(registration.installing, null,
     49                        'installing after activated');
     50          assert_equals(registration.waiting, null,
     51                        'waiting after activated');
     52          assert_equals(registration.active, newest_worker,
     53                        'active after activated');
     54          return Promise.all([
     55              wait_for_state(t, registration.active, 'redundant'),
     56              registration.unregister()
     57            ]);
     58        })
     59      .then(function() {
     60          assert_equals(registration.installing, null,
     61                        'installing after redundant');
     62          assert_equals(registration.waiting, null,
     63                        'waiting after redundant');
     64          // According to spec, Clear Registration runs Update State which is
     65          // immediately followed by setting active to null, which means by the
     66          // time the event loop turns and the Promise for statechange is
     67          // resolved, this will be gone.
     68          assert_equals(registration.active, null,
     69                        'active should be null after redundant');
     70        });
     71  }, 'installing/waiting/active after registration');
     72 </script>