tor-browser

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

test_bug622088.html (3478B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 622088 - Test that XHR gives the referrer corresponding to the dynamic script context.</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script src="/tests/SimpleTest/EventUtils.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=622088">Mozilla Bug 622088</a>
     11 <pre id="test">
     12 
     13 <iframe id='iframe' src='file_bug622088_inner.html'></iframe>
     14 
     15 <iframe id='dataWindow' srcdoc="<html><head>
     16 <script>function getXHRObject() { return new XMLHttpRequest(); }</script>
     17 </head><body onload='parent.dataWindowLoaded()'>Hello!!</body></html>"></iframe>
     18 
     19 <script class="testbody" type="application/javascript">
     20 
     21 // Bug 622088 - Test that XHR gives the referrer corresponding to the
     22 // dynamic script context.
     23 
     24 const kOriginalLocation = location.href;
     25 
     26 SimpleTest.waitForExplicitFinish();
     27 
     28 var innerFinishedLoading = false;
     29 function innerLoaded(inner) {
     30  // Here, we're being called through inner's onload handler, so our referrer
     31  // should be inner's URL.
     32  var referrer = inner.doXHR();
     33  is (referrer, String(inner.document.location), 'Expected inner frame location');
     34 
     35  // Now change the location of the inner frame.  This should be reflected in
     36  // the XHR's referrer.
     37  inner.history.pushState('', '', Math.random());
     38  referrer = inner.doXHR();
     39  is (referrer, String(inner.document.location), 'Expected inner frame location after pushstate');
     40 
     41  innerFinishedLoading = true;
     42 }
     43 
     44 var dataWindowFinishedLoading = false;
     45 function dataWindowLoaded() {
     46  dataWindowFinishedLoading = true;
     47 }
     48 
     49 function callXHR() {
     50  if (innerFinishedLoading && dataWindowFinishedLoading) {
     51    var inner = document.getElementById('iframe').contentWindow;
     52    var referrer = inner.doXHR();
     53    is (referrer, String(inner.document.location),
     54        'Expected inner frame location when called from outer frame.');
     55 
     56    var referrer = inner.doXHR(new XMLHttpRequest());
     57    is (referrer, String(document.location),
     58        "Expected outer frame location when called with outer's XHR object.");
     59 
     60    // Now do a request within the inner window using an XMLHttpRequest
     61    // retrieved from a data: URI.  The referrer should be this window, not the
     62    // data: URI.
     63    var dataWindow = document.getElementById('dataWindow').contentWindow;
     64    var referrer = inner.doXHR(dataWindow.getXHRObject());
     65    is (referrer, String(document.location),
     66        "Expected outer frame location when called with data's XHR object.");
     67 
     68    // Now do that test again, but after having changed the outer window's URI.
     69    // This currently fails, due to basically bug 631949.  It's not even clear
     70    // what the right behavior is.  So marking as a todo for now.
     71    history.replaceState('', '', Math.random());
     72 
     73    var referrer = inner.doXHR(dataWindow.getXHRObject());
     74    todo_is (referrer, String(document.location),
     75             "Expected outer frame location when called with data's XHR object " +
     76             "after replaceState.");
     77 
     78    // In case you're temped, you probably don't want to do history.pushState
     79    // here and test again with the outer frame.  Calling pushState on the
     80    // outer frame messes up Mochitest in subtle ways.
     81 
     82    history.replaceState('', '', kOriginalLocation);
     83    SimpleTest.finish();
     84  }
     85  else {
     86    // ugh.
     87    setTimeout(callXHR, 0);
     88  }
     89 }
     90 
     91 callXHR();
     92 
     93 </script>
     94 </pre>
     95 </body>
     96 </html>