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