incumbent.html (1437B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Incumbent settings object for host functions</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <!-- This is the entry page. --> 8 9 <iframe src="resources/incumbent-incumbent.html"></iframe> 10 11 <script> 12 setup({ explicit_done: true }); 13 14 // postMessage should pick the incumbent page as its .source value to set on the MessageEvent, even 15 // inside host functions. 16 const expectedURL = (new URL("resources/incumbent-incumbent.html", location.href)).href; 17 18 let testId = 0; 19 20 window.onload = () => { 21 const relevantWindow = frames[0].document.querySelector("#r").contentWindow; 22 23 function setupTest(t) { 24 ++testId; 25 const thisTestId = testId; 26 27 relevantWindow.addEventListener("messagereceived", t.step_func(e => { 28 const [receivedTestId, receivedSourceURL] = e.detail; 29 30 if (receivedTestId !== thisTestId) { 31 return; 32 } 33 34 assert_equals(receivedSourceURL, expectedURL); 35 t.done(); 36 })); 37 38 return thisTestId; 39 } 40 41 async_test(t => { 42 const thisTestId = setupTest(t); 43 44 frames[0].runWindowPostMessageVeryIndirectly(thisTestId, "*"); 45 }, "Sanity check: this all works as expected synchronously"); 46 47 async_test(t => { 48 const thisTestId = setupTest(t); 49 frames[0].runWindowPostMessageVeryIndirectlyWithNoUserCode(thisTestId, "*"); 50 }, "Start function"); 51 52 done(); 53 }; 54 </script>