window-top-inner.html (2121B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="utils.js"></script> 4 <title>Fenced frame content to report the value of window.top</title> 5 6 <body> 7 <script> 8 async function init() { // Needed in order to use top-level await. 9 // This file is meant to run in a <fencedframe>. It reports back to the 10 // outermost page whether or not the value of `window.top` was correct for: 11 // 1.) Top-level fenced frames 12 // 2.) Nested iframes inside a fenced frame 13 // 3.) Nested fenced frames 14 const url = new URL(location.href); 15 16 const [window_top_key, window_top_ack_key, nested] = parseKeylist(); 17 18 // Report whether or not `window.top` was correct. 19 let pass_string = ""; 20 if (nested == "nested") 21 pass_string = "pass: fenced frame > fenced frame"; 22 else 23 pass_string = "pass: fenced frame"; 24 25 let result = (window.top == window) ? pass_string : "fail"; 26 writeValueToServer(window_top_key, result); 27 28 // If this page is a nested fenced frame, all we need to do is report the 29 // top-level value. 30 if (nested == "nested") 31 return; 32 33 // Wait for ACK, so we know that the outer page has read the last value from 34 // the `window_top_key` stash and we can write to it again. 35 await nextValueFromServer(window_top_ack_key); 36 37 // Now test `window.top` inside an iframe. 38 const iframe = document.createElement('iframe'); 39 iframe.src = "dummy.html"; 40 const load_promise = new Promise((resolve, reject) => { 41 iframe.onload = resolve; 42 iframe.onerror = reject; 43 }); 44 document.body.append(iframe); 45 46 await load_promise; 47 48 // Report whether or not the subframe's `window.top` was correct. 49 result = (iframe.contentWindow.top == window) ? 50 "pass: fenced frame > iframe" : "fail"; 51 writeValueToServer(window_top_key, result); 52 53 // Wait for ACK, so we know that the outer page has read the last value from 54 // the `window_top_key` stash and we can write to it again. 55 await nextValueFromServer(window_top_ack_key); 56 57 attachFencedFrame(generateURL("window-top-inner.html", 58 [window_top_key, window_top_ack_key, "nested"])); 59 } 60 61 init(); 62 </script> 63 </body>