tor-browser

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

window-location.sub.html (4660B)


      1 <!DOCTYPE html>
      2 <!--
      3 [%provenance%]
      4 -->
      5 <html lang="en">
      6  <meta charset="utf-8">
      7  {%- if subtests|length > 10 %}
      8  <meta name="timeout" content="long">
      9  {%- endif %}
     10  <title>HTTP headers on request for navigation via the HTML Location API</title>
     11  <script src="/resources/testharness.js"></script>
     12  <script src="/resources/testharnessreport.js"></script>
     13  {%- if subtests|selectattr('userActivated')|list %}
     14  <script src="/resources/testdriver.js"></script>
     15  <script src="/resources/testdriver-vendor.js"></script>
     16  {%- endif %}
     17  <script src="/fetch/metadata/resources/helper.sub.js"></script>
     18  <body>
     19  <script>
     20  'use strict';
     21 
     22  function induceRequest(url, navigate, userActivated) {
     23    const win = window.open();
     24 
     25    return new Promise((resolve) => {
     26        addEventListener('message', function(event) {
     27          if (event.source === win) {
     28            resolve();
     29          }
     30        });
     31 
     32        if (userActivated) {
     33          test_driver.bless('enable user activation', () => {
     34            navigate(win, url);
     35          });
     36        } else {
     37          navigate(win, url);
     38        }
     39      })
     40      .then(() => win.close());
     41  }
     42 
     43  const responseParams = {
     44    mime: 'text/html',
     45    body: `<script>opener.postMessage('done', '*')</${''}script>`
     46  };
     47  {%- for subtest in subtests %}
     48 
     49  promise_test(() => {
     50    const key = '{{uuid()}}';
     51    const url = makeRequestURL(key, [% subtest.origins %], responseParams);
     52 
     53    const navigate = (win, path) => {
     54      win.location = path;
     55    };
     56    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
     57      .then(() => retrieve(key))
     58      .then((headers) => {
     59        {%- if subtest.expected == none %}
     60          assert_not_own_property(headers, '[%subtest.headerName%]');
     61        {%- else %}
     62          assert_own_property(headers, '[%subtest.headerName%]');
     63          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
     64        {%- endif %}
     65        });
     66  }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location[% " with user activation" if subtest.userActivated%]');
     67 
     68  promise_test(() => {
     69    const key = '{{uuid()}}';
     70    const url = makeRequestURL(key, [% subtest.origins %], responseParams);
     71 
     72    const navigate = (win, path) => {
     73      win.location.href = path;
     74    };
     75    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
     76      .then(() => retrieve(key))
     77      .then((headers) => {
     78        {%- if subtest.expected == none %}
     79          assert_not_own_property(headers, '[%subtest.headerName%]');
     80        {%- else %}
     81          assert_own_property(headers, '[%subtest.headerName%]');
     82          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
     83        {%- endif %}
     84        });
     85  }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location.href[% " with user activation" if subtest.userActivated%]');
     86 
     87  promise_test(() => {
     88    const key = '{{uuid()}}';
     89    const url = makeRequestURL(key, [% subtest.origins %], responseParams);
     90 
     91    const navigate = (win, path) => {
     92      win.location.assign(path);
     93    };
     94    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
     95      .then(() => retrieve(key))
     96      .then((headers) => {
     97        {%- if subtest.expected == none %}
     98          assert_not_own_property(headers, '[%subtest.headerName%]');
     99        {%- else %}
    100          assert_own_property(headers, '[%subtest.headerName%]');
    101          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
    102        {%- endif %}
    103        });
    104  }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location.assign[% " with user activation" if subtest.userActivated%]');
    105 
    106  promise_test(() => {
    107    const key = '{{uuid()}}';
    108    const url = makeRequestURL(key, [% subtest.origins %], responseParams);
    109 
    110    const navigate = (win, path) => {
    111      win.location.replace(path);
    112    };
    113    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
    114      .then(() => retrieve(key))
    115      .then((headers) => {
    116        {%- if subtest.expected == none %}
    117          assert_not_own_property(headers, '[%subtest.headerName%]');
    118        {%- else %}
    119          assert_own_property(headers, '[%subtest.headerName%]');
    120          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
    121        {%- endif %}
    122        });
    123  }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location.replace[% " with user activation" if subtest.userActivated%]');
    124 
    125  {%- endfor %}
    126  </script>
    127  </body>
    128 </html>