tor-browser

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

unregister-controller.https.html (3733B)


      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 var worker_url = 'resources/simple-intercept-worker.js';
      7 
      8 async_test(function(t) {
      9    var scope =
     10        'resources/unregister-controller-page.html?load-before-unregister';
     11    var frame_window;
     12    var controller;
     13    var registration;
     14    var frame;
     15 
     16    service_worker_unregister_and_register(t, worker_url, scope)
     17      .then(function(r) {
     18          registration = r;
     19          return wait_for_state(t, r.installing, 'activated');
     20        })
     21      .then(function() {
     22          return with_iframe(scope);
     23        })
     24      .then(function(f) {
     25          frame = f;
     26          frame_window = frame.contentWindow;
     27          controller = frame_window.navigator.serviceWorker.controller;
     28          assert_true(controller instanceof frame_window.ServiceWorker,
     29                      'document should load with a controller');
     30          return registration.unregister();
     31        })
     32      .then(function() {
     33          assert_equals(frame_window.navigator.serviceWorker.controller,
     34                        controller,
     35                        'unregistration should not modify controller');
     36          return frame_window.fetch_url('simple.txt');
     37        })
     38      .then(function(response) {
     39          assert_equals(response, 'intercepted by service worker',
     40                        'controller should intercept requests');
     41          frame.remove();
     42          t.done();
     43        })
     44      .catch(unreached_rejection(t));
     45  }, 'Unregister does not affect existing controller');
     46 
     47 async_test(function(t) {
     48    var scope =
     49        'resources/unregister-controller-page.html?load-after-unregister';
     50    var registration;
     51    var frame;
     52 
     53    service_worker_unregister_and_register(t, worker_url, scope)
     54      .then(function(r) {
     55          registration = r;
     56          return wait_for_state(t, r.installing, 'activated');
     57        })
     58      .then(function() {
     59          return registration.unregister();
     60        })
     61      .then(function() {
     62          return with_iframe(scope);
     63        })
     64      .then(function(f) {
     65          frame = f;
     66          var frame_window = frame.contentWindow;
     67          assert_equals(frame_window.navigator.serviceWorker.controller, null,
     68                        'document should not have a controller');
     69          return frame_window.fetch_url('simple.txt');
     70        })
     71      .then(function(response) {
     72          assert_equals(response, 'a simple text file\n',
     73                        'requests should not be intercepted');
     74          frame.remove();
     75          t.done();
     76        })
     77      .catch(unreached_rejection(t));
     78  }, 'Unregister prevents control of subsequent navigations');
     79 
     80 async_test(function(t) {
     81    var scope =
     82        'resources/scope/no-new-controllee-even-if-registration-is-still-used';
     83    var registration;
     84 
     85    service_worker_unregister_and_register(t, worker_url, scope)
     86      .then(function(r) {
     87          registration = r;
     88          return wait_for_state(t, r.installing, 'activated');
     89        })
     90      .then(function() {
     91          return with_iframe(scope);
     92        })
     93      .then(function(frame) {
     94          return registration.unregister();
     95        })
     96      .then(function() {
     97          return with_iframe(scope);
     98        })
     99      .then(function(frame) {
    100          assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
    101                        null,
    102                        'document should not have a controller');
    103          frame.remove();
    104          t.done();
    105        })
    106      .catch(unreached_rejection(t));
    107  }, 'Unregister prevents new controllee even if registration is still in use');
    108 </script>