tor-browser

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

fetch-event-referrer-policy.https.html (14387B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="/common/get-host-info.sub.js"></script>
      5 <script src="resources/test-helpers.sub.js"></script>
      6 <body>
      7 <script>
      8 var worker = 'resources/fetch-event-test-worker.js';
      9 
     10 function do_test(referrer, value, expected, name)
     11 {
     12    test(() => {
     13          assert_equals(value, expected);
     14    }, name + (referrer ? " - Custom Referrer" : " - Default Referrer"));
     15 }
     16 
     17 function run_referrer_policy_tests(frame, referrer, href, origin) {
     18    return frame.contentWindow.fetch('resources/simple.html?referrerFull',
     19                                     {method: "GET", referrer: referrer})
     20      .then(function(response) { return response.text(); })
     21      .then(function(response_text) {
     22          do_test(referrer,
     23            response_text,
     24            'Referrer: ' + href + '\n' +
     25            'ReferrerPolicy: strict-origin-when-cross-origin',
     26            'Service Worker should respond to fetch with the referrer URL when a member of RequestInit is present');
     27          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
     28                         '/resources/simple.html?referrerFull';
     29          return frame.contentWindow.fetch(http_url,
     30                                           {method: "GET", referrer: referrer});
     31        })
     32      .then(function(response) { return response.text(); })
     33      .then(function(response_text) {
     34          do_test(referrer,
     35            response_text,
     36            'Referrer: \n' +
     37            'ReferrerPolicy: strict-origin-when-cross-origin',
     38            'Service Worker should respond to fetch with no referrer when a member of RequestInit is present with an HTTP request');
     39          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
     40                                           {referrerPolicy: "", referrer: referrer});
     41        })
     42      .then(function(response) { return response.text(); })
     43      .then(function(response_text) {
     44          do_test(referrer,
     45            response_text,
     46            'Referrer: ' + href + '\n' +
     47            'ReferrerPolicy: strict-origin-when-cross-origin',
     48            'Service Worker should respond to fetch with the referrer with ""');
     49          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
     50                         '/resources/simple.html?referrerFull';
     51          return frame.contentWindow.fetch(http_url,
     52                                           {referrerPolicy: "", referrer: referrer});
     53        })
     54      .then(function(response) { return response.text(); })
     55      .then(function(response_text) {
     56          do_test(referrer,
     57            response_text,
     58            'Referrer: \n' +
     59            'ReferrerPolicy: strict-origin-when-cross-origin',
     60            'Service Worker should respond to fetch with no referrer with ""');
     61          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
     62                                           {referrerPolicy: "origin", referrer: referrer});
     63        })
     64      .then(function(response) { return response.text(); })
     65      .then(function(response_text) {
     66          do_test(referrer,
     67            response_text,
     68            'Referrer: ' + origin + '/' + '\n' +
     69            'ReferrerPolicy: origin',
     70            'Service Worker should respond to fetch with the referrer origin with "origin" and a same origin request');
     71          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
     72                         '/resources/simple.html?referrerFull';
     73          return frame.contentWindow.fetch(http_url,
     74                                           {referrerPolicy: "origin", referrer: referrer});
     75        })
     76      .then(function(response) { return response.text(); })
     77      .then(function(response_text) {
     78          do_test(referrer,
     79            response_text,
     80            'Referrer: ' + origin + '/' + '\n' +
     81            'ReferrerPolicy: origin',
     82            'Service Worker should respond to fetch with the referrer origin with "origin" and a cross origin request');
     83          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
     84                                           {referrerPolicy: "origin-when-cross-origin", referrer: referrer});
     85        })
     86      .then(function(response) { return response.text(); })
     87      .then(function(response_text) {
     88          do_test(referrer,
     89            response_text,
     90            'Referrer: ' + href + '\n' +
     91            'ReferrerPolicy: origin-when-cross-origin',
     92            'Service Worker should respond to fetch with the referrer URL with "origin-when-cross-origin" and a same origin request');
     93          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
     94                         '/resources/simple.html?referrerFull';
     95          return frame.contentWindow.fetch(http_url,
     96                                           {referrerPolicy: "origin-when-cross-origin", referrer: referrer});
     97        })
     98      .then(function(response) { return response.text(); })
     99      .then(function(response_text) {
    100          do_test(referrer,
    101            response_text,
    102            'Referrer: ' + origin + '/' + '\n' +
    103            'ReferrerPolicy: origin-when-cross-origin',
    104            'Service Worker should respond to fetch with the referrer origin with "origin-when-cross-origin" and a cross origin request');
    105          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
    106                                           {referrerPolicy: "no-referrer-when-downgrade", referrer: referrer});
    107        })
    108      .then(function(response) { return response.text(); })
    109      .then(function(response_text) {
    110          do_test(referrer,
    111            response_text,
    112            'Referrer: ' + href + '\n' +
    113            'ReferrerPolicy: no-referrer-when-downgrade',
    114            'Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and a same origin request');
    115          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
    116                         '/resources/simple.html?referrerFull';
    117          return frame.contentWindow.fetch(http_url,
    118                                           {referrerPolicy: "no-referrer-when-downgrade", referrer: referrer});
    119        })
    120      .then(function(response) { return response.text(); })
    121      .then(function(response_text) {
    122          do_test(referrer,
    123            response_text,
    124            'Referrer: \n' +
    125            'ReferrerPolicy: no-referrer-when-downgrade',
    126            'Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and an HTTP request');
    127          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
    128                         '/resources/simple.html?referrerFull';
    129          return frame.contentWindow.fetch(http_url, {referrerPolicy: "unsafe-url", referrer: referrer});
    130        })
    131      .then(function(response) { return response.text(); })
    132      .then(function(response_text) {
    133          do_test(referrer,
    134            response_text,
    135            'Referrer: ' + href + '\n' +
    136            'ReferrerPolicy: unsafe-url',
    137            'Service Worker should respond to fetch with no referrer with "unsafe-url"');
    138          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
    139                                           {referrerPolicy: "no-referrer", referrer: referrer});
    140        })
    141      .then(function(response) { return response.text(); })
    142      .then(function(response_text) {
    143          do_test(referrer,
    144            response_text,
    145            'Referrer: \n' +
    146            'ReferrerPolicy: no-referrer',
    147            'Service Worker should respond to fetch with no referrer URL with "no-referrer"');
    148          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
    149                                           {referrerPolicy: "same-origin", referrer: referrer});
    150        })
    151      .then(function(response) { return response.text(); })
    152      .then(function(response_text) {
    153          do_test(referrer,
    154            response_text,
    155            'Referrer: ' + href + '\n' +
    156            'ReferrerPolicy: same-origin',
    157            'Service Worker should respond to fetch with referrer URL with "same-origin" and a same origin request');
    158          var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() +
    159                         '/resources/simple.html?referrerFull';
    160          return frame.contentWindow.fetch(http_url,
    161                                           {referrerPolicy: "same-origin", referrer: referrer});
    162        })
    163      .then(function(response) { return response.text(); })
    164      .then(function(response_text) {
    165          do_test(referrer,
    166            response_text,
    167            'Referrer: \n' +
    168            'ReferrerPolicy: same-origin',
    169            'Service Worker should respond to fetch with no referrer with "same-origin" and cross origin request');
    170          var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() +
    171                         '/resources/simple.html?referrerFull';
    172          return frame.contentWindow.fetch(http_url,
    173                                           {referrerPolicy: "strict-origin", referrer: referrer});
    174        })
    175      .then(function(response) { return response.text(); })
    176      .then(function(response_text) {
    177          do_test(referrer,
    178            response_text,
    179            'Referrer: ' + origin + '/' + '\n' +
    180            'ReferrerPolicy: strict-origin',
    181            'Service Worker should respond to fetch with the referrer origin  with "strict-origin" and a HTTPS cross origin request');
    182          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
    183                                           {referrerPolicy: "strict-origin", referrer: referrer});
    184        })
    185      .then(function(response) { return response.text(); })
    186      .then(function(response_text) {
    187          do_test(referrer,
    188            response_text,
    189            'Referrer: ' + origin + '/' + '\n' +
    190            'ReferrerPolicy: strict-origin',
    191            'Service Worker should respond to fetch with the referrer origin with "strict-origin" and a same origin request');
    192          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
    193                         '/resources/simple.html?referrerFull';
    194          return frame.contentWindow.fetch(http_url,
    195                                           {referrerPolicy: "strict-origin", referrer: referrer});
    196        })
    197      .then(function(response) { return response.text(); })
    198      .then(function(response_text) {
    199          do_test(referrer,
    200            response_text,
    201            'Referrer: \n' +
    202            'ReferrerPolicy: strict-origin',
    203            'Service Worker should respond to fetch with no referrer with "strict-origin" and a HTTP request');
    204          return frame.contentWindow.fetch('resources/simple.html?referrerFull',
    205                                           {referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer});
    206        })
    207      .then(function(response) { return response.text(); })
    208      .then(function(response_text) {
    209          do_test(referrer,
    210            response_text,
    211            'Referrer: ' + href + '\n' +
    212            'ReferrerPolicy: strict-origin-when-cross-origin',
    213            'Service Worker should respond to fetch with the referrer URL with "strict-origin-when-cross-origin" and a same origin request');
    214          var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() +
    215                         '/resources/simple.html?referrerFull';
    216          return frame.contentWindow.fetch(http_url,
    217                                           {referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer});
    218        })
    219      .then(function(response) { return response.text(); })
    220      .then(function(response_text) {
    221          do_test(referrer,
    222            response_text,
    223            'Referrer: ' + origin + '/' + '\n' +
    224            'ReferrerPolicy: strict-origin-when-cross-origin',
    225            'Service Worker should respond to fetch with the referrer origin with "strict-origin-when-cross-origin" and a HTTPS cross origin request');
    226          var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
    227                         '/resources/simple.html?referrerFull';
    228          return frame.contentWindow.fetch(http_url,
    229                                           {referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer});
    230        })
    231      .then(function(response) { return response.text(); })
    232      .then(function(response_text) {
    233          do_test(referrer,
    234            response_text,
    235            'Referrer: \n' +
    236            'ReferrerPolicy: strict-origin-when-cross-origin',
    237            'Service Worker should respond to fetch with no referrer with "strict-origin-when-cross-origin" and a HTTP request');
    238        });
    239 }
    240 
    241 promise_test(function(t) {
    242    var scope = 'resources/simple.html?referrerPolicy';
    243    var frame;
    244    return service_worker_unregister_and_register(t, worker, scope)
    245      .then(function(reg) {
    246          t.add_cleanup(function() {
    247              return service_worker_unregister(t, scope);
    248            });
    249 
    250          return wait_for_state(t, reg.installing, 'activated');
    251        })
    252      .then(function() { return with_iframe(scope); })
    253      .then(function(f) {
    254          frame = f;
    255          test(() => {
    256            assert_equals(frame.contentDocument.body.textContent, 'ReferrerPolicy: strict-origin-when-cross-origin');
    257          }, 'Service Worker should respond to fetch with the default referrer policy');
    258          // First, run the referrer policy tests without passing a referrer in RequestInit.
    259          return run_referrer_policy_tests(frame, undefined, frame.contentDocument.location.href,
    260                                           frame.contentDocument.location.origin);
    261        })
    262      .then(function() {
    263          // Now, run the referrer policy tests while passing a referrer in RequestInit.
    264          var referrer = get_host_info()['HTTPS_ORIGIN'] + base_path() + 'resources/fake-referrer';
    265          return run_referrer_policy_tests(frame, 'fake-referrer', referrer,
    266                                           frame.contentDocument.location.origin);
    267        })
    268      .then(function() {
    269          frame.remove();
    270        });
    271  }, 'Service Worker responds to fetch event with the referrer policy');
    272 
    273 </script>
    274 </body>