tor-browser

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

test_beaconRedirect.html (1789B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 1280692 - sendBeacon() should follow 30x redirect</title>
      5  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10  <p id="display"></p>
     11  <div id="content" style="visibility: hidden">
     12    <iframe style="width:100%;" id="testframe"></iframe>
     13  </div>
     14 
     15 <script class="testbody" type="text/javascript">
     16 
     17 /* Description of the test:
     18 *   We do perform a non simple sendBeacon request which should not use CORS and should follow
     19 *   a 30x cross origin redirect, which is allowed by the spec.
     20 */
     21 
     22 SimpleTest.waitForExplicitFinish();
     23 
     24 const BEACON_URL = "http://example.com/tests/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs?beacon";
     25 
     26 SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, runTest);
     27 
     28 var intervalID = null;
     29 
     30 function queryIfRedirectSucceeded() {
     31  clearInterval(intervalID);
     32  var xhr = new XMLHttpRequest();
     33  xhr.open("GET", "beacon-redirect-handler.sjs?verifyRedirectDidSucceed", true);
     34  xhr.onload = function() {
     35    is(xhr.responseText, "green", "SendBeacon should follow cross origin redirects!");
     36    SimpleTest.finish();
     37  };
     38  xhr.onerror = function() {
     39    ok(false, "xhr request returned error");
     40    SimpleTest.finish();
     41  };
     42  xhr.send();
     43 }
     44 
     45 function runTest() {
     46  var data = new Uint8Array([0,1,2,3]);
     47  navigator.sendBeacon(BEACON_URL, data);
     48 
     49  // we have to make sure the channel did follow the redirect hence
     50  // we have to wait for 4 seconds before we can query the result.
     51  intervalID = setInterval(queryIfRedirectSucceeded, 4000);
     52 }
     53 
     54 </script>
     55 </pre>
     56 </body>
     57 </html>