navigate-child-function-parent-then-fragment.html (1540B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title> 4 Set location from a parent, then do a fragment navigation from within the 5 frame. 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <iframe></iframe> 10 <script> 11 promise_test(async test => { 12 // Wait for the DOM to be ready before inserting an <iframe> into it. 13 await new Promise(resolve => { onload = resolve }); 14 // Insert an <iframe> and wait for a dummy document to be loaded into it. 15 let iframe = document.createElement("iframe"); 16 iframe.src = "support/dummy.html"; 17 let iframe_loaded = new Promise(resolve => { iframe.onload = resolve }); 18 document.body.appendChild(iframe); 19 await iframe_loaded; 20 // The referrer is the main frame's URL since it initiated the iframe 21 // creation. 22 assert_equals(iframe.contentDocument.referrer, document.URL); 23 // Do a fragment navigation from the frame, which will fire the 24 // 'hashchange' function. 25 let hash_changed = new Promise(resolve => { 26 iframe.contentWindow.onhashchange = resolve 27 }); 28 let navigateScript = iframe.contentDocument.createElement("script"); 29 navigateScript.innerHTML = "location.href = '#foo'"; 30 iframe.contentDocument.body.appendChild(navigateScript); 31 await hash_changed; 32 // The referrer stays the same, even when the last navigation was 33 // initiated by the iframe (instead of the main frame document). 34 assert_equals(iframe.contentDocument.referrer, document.URL); 35 }); 36 </script>