tor-browser

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

navigation.sub.html (5286B)


      1 <!doctype html>
      2 <meta charset={{GET[encoding]}}> <!-- ends up as <meta charset> by default which is windows-1252 -->
      3 <meta name=variant content="?encoding=windows-1252">
      4 <meta name=variant content="?encoding=x-cp1251">
      5 <meta name=variant content="?encoding=utf8">
      6 <script src=/resources/testharness.js></script>
      7 <script src=/resources/testharnessreport.js></script>
      8 <script src="/common/utils.js"></script>
      9 <link rel=help href=https://html.spec.whatwg.org/multipage/#following-hyperlinks>
     10 <link rel=help href=https://html.spec.whatwg.org/multipage/#hyperlink-auditing>
     11 <link rel=help href=https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv-refresh>
     12 <div id=log></div>
     13 <script>
     14 function expected(encoding) {
     15  return {
     16    "UTF-8": "%C3%BF",
     17    "windows-1251": "%26%23255%3B",
     18    "windows-1252": "%FF"
     19  }[encoding];
     20 }
     21 var encoding = document.characterSet;
     22 var blank = 'resources/blank.py?encoding=' + encoding;
     23 var stash_put = 'resources/stash.py?q=\u00FF&action=put&id=';
     24 var stash_take = 'resources/stash.py?action=take&id=';
     25 var input_url_html = 'resources/resource.py?q=\u00FF&encoding=' + encoding + '&type=html';
     26 var expected_current = expected(encoding);
     27 var expected_utf8 = expected('UTF-8');
     28 
     29 function assert_ends_with(input, endsWith) {
     30  assert_true(input.endsWith(endsWith), input + " did not end with " + endsWith);
     31 }
     32 
     33 
     34 function poll_for_stash(test_obj, uuid, expected) {
     35  var start = new Date();
     36  var poll = test_obj.step_func(function () {
     37    var xhr = new XMLHttpRequest();
     38    xhr.open('GET', stash_take + uuid);
     39    xhr.onload = test_obj.step_func(function(e) {
     40      if (xhr.response == "") {
     41        if (new Date() - start > 10000) {
     42          // If we set the status to TIMEOUT here we avoid a race between the
     43          // page and the test timing out
     44          test_obj.force_timeout();
     45        }
     46        test_obj.step_timeout(poll, 200);
     47      } else {
     48        assert_equals(xhr.response, expected);
     49        test_obj.done();
     50      }
     51    });
     52    xhr.send();
     53  })
     54  test_obj.step_timeout(poll, 200);
     55 }
     56 
     57 function setup_navigation(elm, iframe, id, test_obj) {
     58  iframe.name = id;
     59  elm.target = id;
     60  elm.setAttribute('href', input_url_html);
     61  document.body.appendChild(iframe);
     62  document.body.appendChild(elm);
     63  test_obj.add_cleanup(function() {
     64    document.body.removeChild(iframe);
     65    document.body.removeChild(elm);
     66  });
     67 }
     68 
     69 // follow hyperlink
     70 function test_follow_link(tag) {
     71  async_test(function() {
     72    var elm = document.createElement(tag);
     73    var iframe = document.createElement('iframe');
     74    setup_navigation(elm, iframe, 'test_follow_link_'+tag, this);
     75    iframe.onload = this.step_func_done(function() { // when the page navigated to has loaded
     76      assert_equals(iframe.contentDocument.body.textContent, expected_current);
     77    });
     78    // follow the hyperlink
     79    elm.click();
     80    // check that navigation succeeded by ...??? XXX
     81  }, 'follow hyperlink <'+tag+' href>');
     82 }
     83 
     84 'a, area'.split(', ').forEach(function(str) {
     85  test_follow_link(str);
     86 });
     87 
     88 async_test(function() {
     89  const iframe = document.createElement('iframe');
     90  iframe.name = 'test_dont_follow_link';
     91  document.body.appendChild(iframe);
     92 
     93  const link = document.createElement('link');
     94  link.target = iframe.name;
     95  link.setAttribute('href', input_url_html);
     96  document.body.appendChild(link);
     97 
     98  const anchor = document.createElement('a');
     99  anchor.target = iframe.name;
    100  anchor.setAttribute('href', blank);
    101  document.body.appendChild(anchor);
    102 
    103  this.add_cleanup(function() {
    104    iframe.remove();
    105    link.remove();
    106    anchor.remove();
    107  });
    108 
    109  iframe.onload = this.step_func_done(() => {
    110    assert_equals(
    111      iframe.contentDocument.location.pathname,
    112      '/html/infrastructure/urls/resolving-urls/query-encoding/resources/blank.py',
    113      'The <a> navigation should occur instead of the <link> navigation.');
    114  });
    115 
    116  anchor.click();
    117  link.click();
    118 }, `don't follow hyperlink <link href>`);
    119 
    120 // follow hyperlink with ping attribute
    121 function test_follow_link_ping(tag) {
    122  async_test(function() {
    123    var uuid = token();
    124    var elm = document.createElement(tag);
    125    // check if ping is supported
    126    assert_true('ping' in elm, 'ping not supported');
    127    elm.setAttribute('ping', stash_put + uuid);
    128    var iframe = document.createElement('iframe');
    129    setup_navigation(elm, iframe, 'test_follow_link_ping_'+tag, this);
    130    // follow the hyperlink
    131    elm.click();
    132    // check that navigation succeeded by ...??? XXX
    133    // check that the right URL was requested for the ping
    134    poll_for_stash(this, uuid, expected_current);
    135  }, 'hyperlink auditing <'+tag+' ping>');
    136 }
    137 
    138 'a, area'.split(', ').forEach(function(str) {
    139  test_follow_link_ping(str);
    140 });
    141 
    142 // navigating with meta refresh
    143 async_test(function() {
    144  var iframe = document.createElement('iframe');
    145  iframe.src = blank;
    146  document.body.appendChild(iframe);
    147  this.add_cleanup(function() {
    148    document.body.removeChild(iframe);
    149  });
    150  iframe.onload = this.step_func_done(function() {
    151    var doc = iframe.contentDocument;
    152    var got = doc.body.textContent;
    153    if (got == '') {
    154      doc.write('<meta http-equiv=refresh content="0; URL='+input_url_html+'">REFRESH');
    155      doc.close();
    156      return;
    157    }
    158    assert_equals(got, expected_current);
    159  });
    160 }, 'meta refresh');
    161 
    162 </script>