iframe-loads.html (1435B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/common/get-host-info.sub.js"></script> 7 </head> 8 <body> 9 <script> 10 const host = get_host_info(); 11 const remoteBaseURL = host.HTTP_REMOTE_ORIGIN + window.location.pathname.replace(/\/[^\/]*$/, '/') ; 12 const localBaseURL = host.HTTP_ORIGIN + window.location.pathname.replace(/\/[^\/]*$/, '/') ; 13 14 function with_iframe(url) { 15 return new Promise(function(resolve) { 16 var frame = document.createElement('iframe'); 17 frame.src = url; 18 frame.onload = function() { resolve(frame); }; 19 document.body.appendChild(frame); 20 }); 21 } 22 23 promise_test(async() => { 24 const url = remoteBaseURL + "resources/iframe.py?corp=same-origin"; 25 26 await new Promise((resolve, reject) => { 27 return fetch(url, { mode: "no-cors" }).then(reject, resolve); 28 }); 29 30 const iframe = await with_iframe(url); 31 return new Promise((resolve, reject) => { 32 window.addEventListener("message", (event) => { 33 if (event.data !== "pong") { 34 reject(event.data); 35 return; 36 } 37 resolve(); 38 }, false); 39 iframe.contentWindow.postMessage("ping", "*"); 40 }).finally(() => { 41 iframe.remove(); 42 }); 43 }, "Load an iframe that has Cross-Origin-Resource-Policy header"); 44 </script> 45 </body> 46 </html>