tor-browser

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

window.html (2245B)


      1 <!doctype html>
      2 <html>
      3 <head><title>Frozen Window</title></head>
      4 <script src="/resources/testdriver.js"></script>
      5 <script src="/resources/testdriver-vendor.js"></script>
      6 <script src="/common/utils.js"></script>
      7 <body>
      8 <h1>This window will be frozen</h1>
      9 <iframe id="child_frame" src="child.html"></iframe>
     10 <script>
     11 
     12 const freezingStepName = 'testOnFreeze';
     13 
     14 function testFetch(keepalive) {
     15  var request_token = token();
     16  var name = 'testfetch' + (keepalive ? 'with' : 'without') + 'keepalive';
     17  window.opener.add_step(name);
     18 
     19  function handler() {
     20    window.opener.step_fail(name);
     21  }
     22 
     23  fetch('beacon.py?token=' + request_token, {
     24    keepalive: keepalive
     25  }).then(() => handler()).catch(() => handler());
     26 
     27  window.opener.poll_for_result(request_token, name, keepalive);
     28 }
     29 
     30 function testXHR(async) {
     31  var request_token = token();
     32  var name = 'test' + (async ? 'Async' : 'Sync') + 'XHR';
     33  window.opener.add_step(name);
     34  var xhr = new XMLHttpRequest();
     35  xhr.onreadystatechange = () => {
     36    if (xhr.readyState === 4) {
     37      if (xhr.status === 0)
     38        window.opener.step_success(name);
     39      else
     40        window.opener.step_fail(name);
     41    }
     42  }
     43  xhr.open('GET', 'beacon.py?token=' + request_token, async);
     44  try {
     45    xhr.send(null);
     46    if (async) {
     47      window.opener.poll_for_result(request_token, name, false);
     48    }
     49  } catch {
     50    window.opener.step_success(name);
     51  };
     52 }
     53 
     54 function testSendBeacon() {
     55  var request_token = token();
     56  var name = 'testSendBeacon';
     57  window.opener.add_step(name);
     58  if (navigator.sendBeacon("beacon.py?token=" + request_token, "")) {
     59    window.opener.poll_for_result(request_token, name, true);
     60  } else {
     61    window.opener.step_fail(name);
     62  }
     63 }
     64 
     65 window.document.addEventListener("freeze", () => {
     66  // Testing fetch, only fetch keepalive should succeed.
     67  testFetch(true /* keepalive */);
     68  testFetch(false /* keepalive */);
     69  // Testing XHR, both sync and async should fail.
     70  testXHR(true /* async */);
     71  testXHR(false /* sync */);
     72  // Testing navigator.sendBeacon, which should be allowed.
     73  testSendBeacon();
     74  window.opener.step_success(freezingStepName);
     75 });
     76 
     77 onload = function() {
     78  window.opener.add_step(freezingStepName);
     79  test_driver.freeze();
     80 };
     81 
     82 </script>
     83 </body>
     84 </html>