tor-browser

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

registration-iframe.https.html (4096B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Service Worker: Registration for iframe</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="resources/test-helpers.sub.js"></script>
      7 <body>
      8 <script>
      9 
     10 // Set script url and scope url relative to the iframe's document's url. Assert
     11 // the implementation parses the urls against the iframe's document's url.
     12 async_test(function(t) {
     13  const url = 'resources/blank.html';
     14  const iframe_scope = 'registration-with-valid-scope';
     15  const scope = normalizeURL('resources/' + iframe_scope);
     16  const iframe_script = 'empty-worker.js';
     17  const script = normalizeURL('resources/' + iframe_script);
     18  var frame;
     19  var registration;
     20 
     21  service_worker_unregister(t, scope)
     22    .then(function() { return with_iframe(url); })
     23    .then(function(f) {
     24        frame = f;
     25        return frame.contentWindow.navigator.serviceWorker.register(
     26            iframe_script,
     27            { scope: iframe_scope });
     28      })
     29    .then(function(r) {
     30        registration = r;
     31        return wait_for_state(t, r.installing, 'activated');
     32      })
     33    .then(function() {
     34        assert_equals(registration.scope, scope,
     35                      'registration\'s scope must be parsed against the ' +
     36                      '"relevant global object"');
     37        assert_equals(registration.active.scriptURL, script,
     38                      'worker\'s scriptURL must be parsed against the ' +
     39                      '"relevant global object"');
     40        return registration.unregister();
     41      })
     42    .then(function() {
     43        frame.remove();
     44        t.done();
     45      })
     46    .catch(unreached_rejection(t));
     47  }, 'register method should use the "relevant global object" to parse its ' +
     48     'scriptURL and scope - normal case');
     49 
     50 // Set script url and scope url relative to the parent frame's document's url.
     51 // Assert the implementation throws a TypeError exception.
     52 async_test(function(t) {
     53  const url = 'resources/blank.html';
     54  const iframe_scope = 'resources/registration-with-scope-to-non-existing-url';
     55  const scope = normalizeURL('resources/' + iframe_scope);
     56  const script = 'resources/empty-worker.js';
     57  var frame;
     58  var registration;
     59 
     60  service_worker_unregister(t, scope)
     61    .then(function() { return with_iframe(url); })
     62    .then(function(f) {
     63        frame = f;
     64        return frame.contentWindow.navigator.serviceWorker.register(
     65            script,
     66            { scope: iframe_scope });
     67      })
     68    .then(
     69      function() {
     70        assert_unreached('register() should reject');
     71      },
     72      function(e) {
     73        assert_equals(e.name, 'TypeError',
     74                      'register method with scriptURL and scope parsed to ' +
     75                      'nonexistent location should reject with TypeError');
     76        frame.remove();
     77        t.done();
     78      })
     79    .catch(unreached_rejection(t));
     80  }, 'register method should use the "relevant global object" to parse its ' +
     81     'scriptURL and scope - error case');
     82 
     83 // Set the scope url to a non-subdirectory of the script url. Assert the
     84 // implementation throws a SecurityError exception.
     85 async_test(function(t) {
     86  const url = 'resources/blank.html';
     87  const scope = 'registration-with-disallowed-scope';
     88  const iframe_scope = '../' + scope;
     89  const script = 'empty-worker.js';
     90  var frame;
     91  var registration;
     92 
     93  service_worker_unregister(t, scope)
     94    .then(function() { return with_iframe(url); })
     95    .then(function(f) {
     96        frame = f;
     97        return frame.contentWindow.navigator.serviceWorker.register(
     98            script,
     99            { scope: iframe_scope });
    100      })
    101    .then(
    102      function() {
    103        assert_unreached('register() should reject');
    104      },
    105      function(e) {
    106        assert_equals(e.name, 'SecurityError',
    107                      'The scope set to a non-subdirectory of the scriptURL ' +
    108                      'should reject with SecurityError');
    109        frame.remove();
    110        t.done();
    111      })
    112    .catch(unreached_rejection(t));
    113  }, 'A scope url should start with the given script url');
    114 
    115 </script>
    116 </body>