content/base/test/test_bug622088.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript" 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">
    13 <iframe id='iframe' src='file_bug622088_inner.html'></iframe>
    15 <iframe id='dataWindow' src="data:text/html,<html><head>
    16 <script>function getXHRObject() { return new XMLHttpRequest(); }</script>
    17 </head><body onload='parent.dataWindowLoaded()'>Hello!!</body></html>"></iframe>
    19 <script class="testbody" type="application/javascript;version=1.8">
    21 // Bug 622088 - Test that XHR gives the referrer corresponding to the
    22 // dynamic script context.
    24 const kOriginalLocation = location.href;
    26 SimpleTest.waitForExplicitFinish();
    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, inner.document.location, 'Expected inner frame location');
    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, inner.document.location, 'Expected inner frame location after pushstate');
    41   innerFinishedLoading = true;
    42 }
    44 var dataWindowFinishedLoading = false;
    45 function dataWindowLoaded() {
    46   dataWindowFinishedLoading = true;
    47 }
    49 function callXHR() {
    50   if (innerFinishedLoading && dataWindowFinishedLoading) {
    51     var inner = document.getElementById('iframe').contentWindow;
    52     var referrer = inner.doXHR();
    53     is (referrer, inner.document.location,
    54         'Expected inner frame location when called from outer frame.');
    56     var referrer = inner.doXHR(new XMLHttpRequest());
    57     is (referrer, document.location,
    58         "Expected outer frame location when called with outer's XHR object.");
    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, document.location,
    66         "Expected outer frame location when called with data's XHR object.");
    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());
    73     var referrer = inner.doXHR(dataWindow.getXHRObject());
    74     todo_is (referrer, document.location,
    75              "Expected outer frame location when called with data's XHR object " +
    76              "after replaceState.");
    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.
    82     history.replaceState('', '', kOriginalLocation);
    83     SimpleTest.finish();
    84   }
    85   else {
    86     // ugh.
    87     setTimeout(callXHR, 0);
    88   }
    89 }
    91 callXHR();
    93 </script>
    94 </pre>
    95 </body>
    96 </html>

mercurial