tor-browser

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

register-default-scope.https.html (2661B)


      1 <!DOCTYPE html>
      2 <title>register() and scope</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="resources/testharness-helpers.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="resources/test-helpers.sub.js"></script>
      7 <script>
      8 
      9 promise_test(function(t) {
     10    var script = 'resources/empty-worker.js';
     11    var script_url = new URL(script, location.href);
     12    var expected_scope = new URL('./', script_url).href;
     13    return service_worker_unregister(t, expected_scope)
     14      .then(function() {
     15        return navigator.serviceWorker.register('resources/empty-worker.js');
     16      }).then(function(registration) {
     17        assert_equals(registration.scope, expected_scope,
     18                      'The default scope should be URL("./", script_url)');
     19        return registration.unregister();
     20      }).then(function() {
     21        t.done();
     22      });
     23  }, 'default scope');
     24 
     25 promise_test(function(t) {
     26    // This script must be different than the 'default scope' test, or else
     27    // the scopes will collide.
     28    var script = 'resources/empty.js';
     29    var script_url = new URL(script, location.href);
     30    var expected_scope = new URL('./', script_url).href;
     31    return service_worker_unregister(t, expected_scope)
     32      .then(function() {
     33        return navigator.serviceWorker.register('resources/empty.js',
     34                                                { scope: undefined });
     35      }).then(function(registration) {
     36        assert_equals(registration.scope, expected_scope,
     37                      'The default scope should be URL("./", script_url)');
     38        return registration.unregister();
     39      }).then(function() {
     40        t.done();
     41      });
     42  }, 'undefined scope');
     43 
     44 promise_test(function(t) {
     45    var script = 'resources/simple-fetch-worker.js';
     46    var script_url = new URL(script, location.href);
     47    var expected_scope = new URL('./', script_url).href;
     48    return service_worker_unregister(t, expected_scope)
     49      .then(function() {
     50        return navigator.serviceWorker.register('resources/empty.js',
     51                                                { scope: null });
     52      })
     53      .then(
     54        function(registration) {
     55          t.add_cleanup(function() {
     56              return service_worker_unregister(t, registration.scope);
     57            });
     58 
     59          assert_unreached('register should fail');
     60        },
     61        function(error) {
     62          assert_equals(error.name, 'SecurityError',
     63                        'passing a null scope should be interpreted as ' +
     64                        'scope="null" which violates the path restriction');
     65          t.done();
     66        });
     67  }, 'null scope');
     68 
     69 </script>