1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Bug 1639195 - Test triggeringPrincipal for iframe same-origin navigations</title>
<!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<iframe style="width:100%;" id="testframe" src="http://example.com/"></iframe>
<script type="text/javascript">
/* We load an third-party iframe which then gets navigated by the iframe's
* parent by calling iframe.setAttribute("src", same-origin url) later in the
* test. We then verify the TriggeringPrincipal and LoadingPrincipal of the
* navigated iframe.
*
* +------------------------------------------+
* | |
* | +------------------+ |
* | | testframe | |
* | +------------------+ |
* | |
* | iframe.setAttribute("src", |
* | same-origin url) |
* | |
* +------------------------------------------+
*/
var testframe = document.getElementById("testframe");
window.addEventListener("message", receiveMessage);
const TRIGGERING_PRINCIPAL_URI =
"http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_frame_same_origin_nav.html";
const LOADING_PRINCIPAL_URI = TRIGGERING_PRINCIPAL_URI;
function receiveMessage(event) {
is(event.data.triggeringPrincipalURI.split("?")[0], TRIGGERING_PRINCIPAL_URI,
"TriggeringPrincipal should be the parent iframe");
is(event.data.loadingPrincipalURI.split("?")[0], TRIGGERING_PRINCIPAL_URI,
"LoadingPrincipal should be the parent iframe");
window.removeEventListener("message", receiveMessage);
SimpleTest.finish();
}
function performNavigation() {
testframe.removeEventListener("load", performNavigation);
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
testframe.setAttribute("src", "http://example.com/tests/docshell/test/navigation/file_triggeringprincipal_subframe_same_origin_nav.html");
}
// start the test
SimpleTest.waitForExplicitFinish();
testframe.addEventListener("load", performNavigation);
</script>
</body>
</html>
|