1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug622088.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Bug 622088 - Test that XHR gives the referrer corresponding to the dynamic script context.</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=622088">Mozilla Bug 622088</a> 1.14 +<pre id="test"> 1.15 + 1.16 +<iframe id='iframe' src='file_bug622088_inner.html'></iframe> 1.17 + 1.18 +<iframe id='dataWindow' src="data:text/html,<html><head> 1.19 +<script>function getXHRObject() { return new XMLHttpRequest(); }</script> 1.20 +</head><body onload='parent.dataWindowLoaded()'>Hello!!</body></html>"></iframe> 1.21 + 1.22 +<script class="testbody" type="application/javascript;version=1.8"> 1.23 + 1.24 +// Bug 622088 - Test that XHR gives the referrer corresponding to the 1.25 +// dynamic script context. 1.26 + 1.27 +const kOriginalLocation = location.href; 1.28 + 1.29 +SimpleTest.waitForExplicitFinish(); 1.30 + 1.31 +var innerFinishedLoading = false; 1.32 +function innerLoaded(inner) { 1.33 + // Here, we're being called through inner's onload handler, so our referrer 1.34 + // should be inner's URL. 1.35 + var referrer = inner.doXHR(); 1.36 + is (referrer, inner.document.location, 'Expected inner frame location'); 1.37 + 1.38 + // Now change the location of the inner frame. This should be reflected in 1.39 + // the XHR's referrer. 1.40 + inner.history.pushState('', '', Math.random()); 1.41 + referrer = inner.doXHR(); 1.42 + is (referrer, inner.document.location, 'Expected inner frame location after pushstate'); 1.43 + 1.44 + innerFinishedLoading = true; 1.45 +} 1.46 + 1.47 +var dataWindowFinishedLoading = false; 1.48 +function dataWindowLoaded() { 1.49 + dataWindowFinishedLoading = true; 1.50 +} 1.51 + 1.52 +function callXHR() { 1.53 + if (innerFinishedLoading && dataWindowFinishedLoading) { 1.54 + var inner = document.getElementById('iframe').contentWindow; 1.55 + var referrer = inner.doXHR(); 1.56 + is (referrer, inner.document.location, 1.57 + 'Expected inner frame location when called from outer frame.'); 1.58 + 1.59 + var referrer = inner.doXHR(new XMLHttpRequest()); 1.60 + is (referrer, document.location, 1.61 + "Expected outer frame location when called with outer's XHR object."); 1.62 + 1.63 + // Now do a request within the inner window using an XMLHttpRequest 1.64 + // retrieved from a data: URI. The referrer should be this window, not the 1.65 + // data: URI. 1.66 + var dataWindow = document.getElementById('dataWindow').contentWindow; 1.67 + var referrer = inner.doXHR(dataWindow.getXHRObject()); 1.68 + is (referrer, document.location, 1.69 + "Expected outer frame location when called with data's XHR object."); 1.70 + 1.71 + // Now do that test again, but after having changed the outer window's URI. 1.72 + // This currently fails, due to basically bug 631949. It's not even clear 1.73 + // what the right behavior is. So marking as a todo for now. 1.74 + history.replaceState('', '', Math.random()); 1.75 + 1.76 + var referrer = inner.doXHR(dataWindow.getXHRObject()); 1.77 + todo_is (referrer, document.location, 1.78 + "Expected outer frame location when called with data's XHR object " + 1.79 + "after replaceState."); 1.80 + 1.81 + // In case you're temped, you probably don't want to do history.pushState 1.82 + // here and test again with the outer frame. Calling pushState on the 1.83 + // outer frame messes up Mochitest in subtle ways. 1.84 + 1.85 + history.replaceState('', '', kOriginalLocation); 1.86 + SimpleTest.finish(); 1.87 + } 1.88 + else { 1.89 + // ugh. 1.90 + setTimeout(callXHR, 0); 1.91 + } 1.92 +} 1.93 + 1.94 +callXHR(); 1.95 + 1.96 +</script> 1.97 +</pre> 1.98 +</body> 1.99 +</html>