document-base-url-about-srcdoc.https.window.js (988B)
1 // META: script=/common/get-host-info.sub.js 2 3 // Load about:srcdoc in a sandboxed iframe. Check the document.baseURI is 4 // correct. 5 const runTest = (description, iframe_sandbox) => { 6 promise_test(async test => { 7 const iframe = document.createElement("iframe"); 8 iframe.sandbox = iframe_sandbox; 9 iframe.srcdoc = ` 10 <script> 11 parent.postMessage(document.baseURI, '*'); 12 </scr`+`ipt> 13 `; 14 const child_base_uri = new Promise(r => onmessage = e => r(e.data)); 15 document.body.appendChild(iframe); 16 // [spec]: https://html.spec.whatwg.org/C/#fallback-base-url 17 // Step 1: If document is an iframe srcdoc document, then return the 18 // document base URL of document's browsing context's container 19 // document. 20 assert_equals(await child_base_uri, document.baseURI); 21 }, description); 22 } 23 24 onload = () => { 25 runTest("allow-same-origin", "allow-scripts allow-same-origin"); 26 runTest("disallow-same-origin", "allow-scripts"); 27 }