tor-browser

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

fetch-request-no-freshness-headers.https.html (2146B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: the headers of FetchEvent shouldn't contain freshness headers</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="resources/test-helpers.sub.js?pipe=sub"></script>
      6 <script>
      7 promise_test(function(t) {
      8    var SCOPE = 'resources/fetch-request-no-freshness-headers-iframe.html';
      9    var SCRIPT = 'resources/fetch-request-no-freshness-headers-worker.js';
     10    var worker;
     11    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
     12      .then(function(registration) {
     13          t.add_cleanup(function() {
     14              return service_worker_unregister(t, SCOPE);
     15            });
     16 
     17          worker = registration.installing;
     18          return wait_for_state(t, worker, 'activated');
     19        })
     20      .then(function() { return with_iframe(SCOPE); })
     21      .then(function(frame) {
     22          return new Promise(function(resolve) {
     23              frame.onload = function() {
     24                  resolve(frame);
     25                };
     26              frame.contentWindow.location.reload();
     27            });
     28        })
     29      .then(function(frame) {
     30          return new Promise(function(resolve) {
     31              var channel = new MessageChannel();
     32              channel.port1.onmessage = t.step_func(function(msg) {
     33                  frame.remove();
     34                  resolve(msg);
     35                });
     36              worker.postMessage(
     37                {port: channel.port2}, [channel.port2]);
     38            });
     39        })
     40      .then(function(msg) {
     41          var freshness_headers = {
     42            'if-none-match': true,
     43            'if-modified-since': true
     44          };
     45          msg.data.requests.forEach(function(request) {
     46              request.headers.forEach(function(header) {
     47                  assert_false(
     48                      !!freshness_headers[header[0]],
     49                      header[0] + ' header must not be set in the ' +
     50                      'FetchEvent\'s request. (url = ' + request.url + ')');
     51                });
     52            })
     53        });
     54  }, 'The headers of FetchEvent shouldn\'t contain freshness headers.');
     55 </script>