require-corp-about-srcdoc.https.html (1975B)
1 <script src=/resources/testharness.js></script> 2 <script src=/resources/testharnessreport.js></script> 3 <script> 4 5 promise_test(t => { 6 return new Promise(resolve => { 7 window.addEventListener("DOMContentLoaded", resolve); 8 }); 9 }, "Wait for the DOM to be built."); 10 11 promise_test(async t => { 12 let iframe = document.createElement("iframe"); 13 let iframe_loaded = new Promise(resolve => iframe.onload = resolve); 14 iframe.srcdoc = "loaded document"; 15 document.body.appendChild(iframe); 16 17 // The about:srcdoc document can load. 18 await iframe_loaded; 19 assert_not_equals(iframe.contentDocument, null); 20 assert_equals(iframe.contentDocument.body.innerText, "loaded document"); 21 }, "about:srcdoc can always be embedded by a 'require-corp' document"); 22 23 promise_test(async t => { 24 let iframe_C = document.createElement("iframe"); 25 let iframe_B = document.createElement("iframe"); 26 iframe_B.srcdoc = "dummy content"; 27 iframe_C.src = "/common/blank.html"; 28 let iframe_B_loaded = new Promise(resolve => iframe_B.onload = resolve); 29 document.body.appendChild(iframe_B); 30 31 // The about:srcdoc frame must be able to load. 32 await iframe_B_loaded; 33 assert_not_equals(iframe_B.contentDocument, null); 34 assert_equals(iframe_B.contentDocument.body.innerText, "dummy content"); 35 iframe_B.contentDocument.body.appendChild(iframe_C); 36 37 // The document nested under about:srcdoc must not load because it does not 38 // specify the Cross-Origin-Embedder-Policy: require-corp header. 39 // An error page must be displayed instead. 40 // See https://github.com/whatwg/html/issues/125 for why a timeout is used 41 // here. Long term all network error handling should be similar and have a 42 // reliable event. 43 assert_equals(iframe_C.contentWindow.location.href, "about:blank"); 44 assert_not_equals(iframe_C.contentDocument, null); 45 await t.step_wait(() => iframe_C.contentDocument === null); 46 }, "A(B(C)) A=require-corp, B=about:srcdoc, C=no-require-corp => C can't load"); 47 48 </script>