embedded-opener-remove-frame.html (2476B)
1 <!doctype html> 2 <title>opener and discarded browsing contexts</title> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <div id=log></div> 6 <iframe name=matchesastring></iframe> 7 <script> 8 function testOpener(t, otherW, thisW, discardOtherBC, isDiscardedFromATask) { 9 assert_equals(otherW.opener, thisW, "opener before removal"); 10 11 const openerDesc = Object.getOwnPropertyDescriptor(otherW, "opener"), 12 openerGet = openerDesc.get; 13 14 assert_equals(openerGet(), thisW, "opener before removal via directly invoking the getter"); 15 discardOtherBC(); 16 if (isDiscardedFromATask) { 17 t.step_timeout(() => { 18 testOpenerRemainder(t, otherW, openerDesc, openerGet); 19 }, 250); 20 } else { 21 testOpenerRemainder(t, otherW, openerDesc, openerGet); 22 } 23 } 24 25 function testOpenerRemainder(t, otherW, openerDesc, openerGet) { 26 assert_equals(otherW.opener, null, "opener after removal"); 27 assert_equals(openerGet(), null, "opener after removal via directly invoking the getter"); 28 29 otherW.opener = null; 30 assert_equals(openerGet(), null, "opener after setting it null via directly invoking the getter"); 31 const openerDescNull = Object.getOwnPropertyDescriptor(otherW, "opener"); 32 assert_not_equals(openerDescNull, openerDesc); 33 assert_object_equals(openerDescNull, openerDesc); 34 35 otherW.opener = "immaterial"; 36 assert_equals(openerGet(), null, "opener after setting it \"immaterial\" via directly invoking the getter"); 37 const openerDescImmaterial = Object.getOwnPropertyDescriptor(otherW, "opener"); 38 assert_equals(openerDescImmaterial.value, "immaterial"); 39 assert_true(openerDescImmaterial.writable); 40 assert_true(openerDescImmaterial.enumerable); 41 assert_true(openerDescImmaterial.configurable); 42 43 t.done(); 44 } 45 46 async_test(t => { 47 const frame = document.querySelector("iframe"), 48 frameW = frame.contentWindow; 49 frame.onload = t.step_func(() => { 50 // Firefox and Chrome/Safari load differently 51 if (frame.contentWindow.location.href === "about:blank") { 52 return; 53 } 54 55 testOpener(t, frameW, window, () => frame.remove(), false); 56 }); 57 window.open("/common/blank.html", "matchesastring"); 58 }, "opener of discarded nested browsing context"); 59 60 async_test(t => { 61 const popupW = window.open("/common/blank.html"); 62 popupW.onload = t.step_func(() => { 63 testOpener(t, popupW, window, () => popupW.close(), true); 64 }); 65 }, "opener of discarded auxiliary browsing context"); 66 </script>