window-parent-null.html (2627B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>window.parent: `null`</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <div id="log"></div> 7 <script> 8 async_test(t => { 9 var iframe = document.createElement('iframe'); 10 iframe.onload = t.step_func_done(() => { 11 var iWindow = iframe.contentWindow; 12 assert_equals(iWindow.parent, window); 13 document.body.removeChild(iframe); 14 assert_equals(iWindow.parent, null); 15 }); 16 17 document.body.appendChild(iframe); 18 }, '`window.parent` is null when browsing context container element removed'); 19 20 async_test(t => { 21 var iframe = document.createElement('iframe'); 22 var iframe2, removedEl; 23 24 var testFunc = t.step_func(() => { 25 var frameWindow = iframe.contentWindow; 26 var frame2Window = iframe2.contentWindow; 27 28 assert_equals(frameWindow.parent, window); 29 assert_equals(frame2Window.parent, frameWindow); 30 31 iframe.removeEventListener('load', nestFrame); 32 iframe2.removeEventListener('load', testFunc); 33 removedEl = document.body.removeChild(iframe); 34 35 assert_equals(frameWindow.parent, null); 36 assert_equals(frame2Window.parent, null); 37 38 removedEl.addEventListener('load', t.step_func_done(() => { 39 // reattached iframe's browsing context will report window.parent again 40 assert_equals(removedEl.contentWindow.parent, window); 41 // The following window s are no longer referenced by active browsing contexts 42 assert_equals(frameWindow.parent, null); 43 assert_equals(frame2Window.parent, null); 44 // Per #the-iframe-element, reattaching a removed iframe will result in the 45 // browser creating a new browsing context once again, with a fresh 46 // document in our case, so the second iframe or any other elements 47 // previously added to iframe.contentDocument will be gone 48 assert_equals(removedEl.contentDocument.querySelector('iframe'), null); 49 assert_equals(removedEl.contentDocument.querySelector('hr'), null); 50 })); 51 document.body.appendChild(removedEl); 52 }); 53 54 var nestFrame = function () { 55 iframe.contentDocument.body.appendChild(document.createElement('hr')); 56 iframe2 = iframe.contentDocument.createElement('iframe'); 57 // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1229707 58 iframe2.src = '/common/blank.html'; 59 iframe2.addEventListener('load', testFunc); 60 iframe.contentDocument.body.appendChild(iframe2); 61 }; 62 63 iframe.addEventListener('load', nestFrame); 64 document.body.appendChild(iframe); 65 }, '`window.parent` null when parent browsing context container removed'); 66 </script>