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