tor-browser

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

registration-attribute.https.html (4013B)


      1 <!DOCTYPE html>
      2 <title>ServiceWorkerGlobalScope: registration</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/registration-attribute-worker.js';
     10    var scope = 'resources/scope/registration-attribute';
     11    var registration;
     12    return service_worker_unregister_and_register(t, script, scope)
     13      .then(function(reg) {
     14          registration = reg;
     15          add_result_callback(function() { registration.unregister(); });
     16          return wait_for_state(t, registration.installing, 'activated');
     17        })
     18      .then(function() { return with_iframe(scope); })
     19      .then(function(frame) {
     20          var expected_events_seen = [
     21            'updatefound',
     22            'install',
     23            'statechange(installed)',
     24            'statechange(activating)',
     25            'activate',
     26            'statechange(activated)',
     27            'fetch',
     28          ];
     29 
     30          assert_equals(
     31              frame.contentDocument.body.textContent,
     32              expected_events_seen.toString(),
     33              'Service Worker should respond to fetch');
     34          frame.remove();
     35          return registration.unregister();
     36        });
     37  }, 'Verify registration attributes on ServiceWorkerGlobalScope');
     38 
     39 promise_test(function(t) {
     40    var script = 'resources/registration-attribute-worker.js';
     41    var newer_script = 'resources/registration-attribute-newer-worker.js';
     42    var scope = 'resources/scope/registration-attribute';
     43    var newer_worker;
     44    var registration;
     45 
     46    return service_worker_unregister_and_register(t, script, scope)
     47      .then(function(reg) {
     48          registration = reg;
     49          add_result_callback(function() { registration.unregister(); });
     50          return wait_for_state(t, registration.installing, 'activated');
     51        })
     52      .then(function() {
     53          return navigator.serviceWorker.register(newer_script, {scope: scope});
     54        })
     55      .then(function(reg) {
     56          assert_equals(reg, registration);
     57          newer_worker = registration.installing;
     58          return wait_for_state(t, registration.installing, 'activated');
     59        })
     60      .then(function() {
     61          var channel = new MessageChannel;
     62          var saw_message = new Promise(function(resolve) {
     63              channel.port1.onmessage = function(e) { resolve(e.data); };
     64            });
     65          newer_worker.postMessage({port: channel.port2}, [channel.port2]);
     66          return saw_message;
     67        })
     68      .then(function(results) {
     69          var script_url = normalizeURL(script);
     70          var newer_script_url = normalizeURL(newer_script);
     71          var expectations = [
     72            'evaluate',
     73            '  installing: empty',
     74            '  waiting: empty',
     75            '  active: ' + script_url,
     76            'updatefound',
     77            '  installing: ' + newer_script_url,
     78            '  waiting: empty',
     79            '  active: ' + script_url,
     80            'install',
     81            '  installing: ' + newer_script_url,
     82            '  waiting: empty',
     83            '  active: ' + script_url,
     84            'statechange(installed)',
     85            '  installing: empty',
     86            '  waiting: ' + newer_script_url,
     87            '  active: ' + script_url,
     88            'statechange(activating)',
     89            '  installing: empty',
     90            '  waiting: empty',
     91            '  active: ' + newer_script_url,
     92            'activate',
     93            '  installing: empty',
     94            '  waiting: empty',
     95            '  active: ' + newer_script_url,
     96            'statechange(activated)',
     97            '  installing: empty',
     98            '  waiting: empty',
     99            '  active: ' + newer_script_url,
    100          ];
    101          assert_array_equals(results, expectations);
    102          return registration.unregister();
    103        });
    104  }, 'Verify registration attributes on ServiceWorkerGlobalScope of the ' +
    105     'newer worker');
    106 
    107 </script>