tor-browser

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

getregistration.https.html (3905B)


      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 async_test(function(t) {
      7    var documentURL = 'no-such-worker';
      8    navigator.serviceWorker.getRegistration(documentURL)
      9      .then(function(value) {
     10          assert_equals(value, undefined,
     11                        'getRegistration should resolve with undefined');
     12          t.done();
     13        })
     14      .catch(unreached_rejection(t));
     15  }, 'getRegistration');
     16 
     17 promise_test(function(t) {
     18    var scope = 'resources/scope/getregistration/normal';
     19    var registration;
     20    return service_worker_unregister_and_register(t, 'resources/empty-worker.js',
     21                                                  scope)
     22      .then(function(r) {
     23          t.add_cleanup(function() {
     24              return service_worker_unregister(t, scope);
     25            });
     26 
     27          registration = r;
     28          return navigator.serviceWorker.getRegistration(scope);
     29        })
     30      .then(function(value) {
     31          assert_equals(
     32              value, registration,
     33              'getRegistration should resolve to the same registration object');
     34        });
     35  }, 'Register then getRegistration');
     36 
     37 promise_test(function(t) {
     38    var scope = 'resources/scope/getregistration/url-with-fragment';
     39    var documentURL = scope + '#ref';
     40    var registration;
     41    return service_worker_unregister_and_register(t, 'resources/empty-worker.js',
     42                                                  scope)
     43      .then(function(r) {
     44          t.add_cleanup(function() {
     45              return service_worker_unregister(t, scope);
     46            });
     47 
     48          registration = r;
     49          return navigator.serviceWorker.getRegistration(documentURL);
     50        })
     51      .then(function(value) {
     52          assert_equals(
     53              value, registration,
     54              'getRegistration should resolve to the same registration object');
     55        });
     56  }, 'Register then getRegistration with a URL having a fragment');
     57 
     58 async_test(function(t) {
     59    var documentURL = 'http://example.com/';
     60    navigator.serviceWorker.getRegistration(documentURL)
     61      .then(function() {
     62          assert_unreached(
     63              'getRegistration with an out of origin URL should fail');
     64      }, function(reason) {
     65          assert_equals(
     66              reason.name, 'SecurityError',
     67              'getRegistration with an out of origin URL should fail');
     68          t.done();
     69      })
     70      .catch(unreached_rejection(t));
     71  }, 'getRegistration with a cross origin URL');
     72 
     73 async_test(function(t) {
     74    var scope = 'resources/scope/getregistration/register-unregister';
     75    service_worker_unregister_and_register(t, 'resources/empty-worker.js',
     76                                           scope)
     77      .then(function(registration) {
     78          return registration.unregister();
     79        })
     80      .then(function() {
     81          return navigator.serviceWorker.getRegistration(scope);
     82        })
     83      .then(function(value) {
     84          assert_equals(value, undefined,
     85                        'getRegistration should resolve with undefined');
     86          t.done();
     87        })
     88      .catch(unreached_rejection(t));
     89  }, 'Register then Unregister then getRegistration');
     90 
     91 
     92 promise_test(async function(t) {
     93  const scope = 'resources/scope/getregistration/register-unregister';
     94  const registration = await service_worker_unregister_and_register(
     95    t, 'resources/empty-worker.js', scope
     96  );
     97 
     98  const frame = await with_iframe(scope);
     99  t.add_cleanup(() => frame.remove());
    100 
    101  const frameNav = frame.contentWindow.navigator;
    102  await registration.unregister();
    103  const value = await frameNav.serviceWorker.getRegistration(scope);
    104 
    105  assert_equals(value, undefined, 'getRegistration should resolve with undefined');
    106 }, 'Register then Unregister then getRegistration in controlled iframe');
    107 
    108 </script>