From d1f6fc9c98e4aa0a9c89482dca5d26ab695b75cc Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 13 Mar 2019 16:37:16 +0100 Subject: [PATCH] HTML: window.opener clearing For https://github.com/whatwg/html/issues/4429. --- .../windows/opener-clearing.window.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 html/browsers/windows/opener-clearing.window.js diff --git a/html/browsers/windows/opener-clearing.window.js b/html/browsers/windows/opener-clearing.window.js new file mode 100644 index 00000000000000..2c78de2ff3ccb7 --- /dev/null +++ b/html/browsers/windows/opener-clearing.window.js @@ -0,0 +1,54 @@ +async_test(t => { + // See also https://github.com/whatwg/html/issues/4428 + const frames = ["iframe", "iframe"].map(val => document.createElement(val)); + frames[0].srcdoc = ""; + frames[1].name = "thename"; + document.body.append(...frames); + t.add_cleanup(() => { frames.map(val => val.remove()) }); + frames[0].onload = t.step_func(() => { + const frameWs = frames.map(val => val.contentWindow), + deepW = frameWs[0][0] + openee = deepW.open("", "thename"); + assert_equals(openee, frameWs[1]); + assert_equals(openee.opener, deepW); + frames[0].onload = t.step_func_done(() => { + // It'd be interesting to use something like history.back() here that works to see if it's + // still null, but that doesn't seem possible. + assert_equals(openee.opener, null); + }); + frames[0].srcdoc = ""; + }); +}, "Set opener browsing context to null when it's in session history"); + +test(t => { + const frames = ["iframe", "iframe"].map(val => document.createElement(val)); + frames[1].name = "thebettername"; + document.body.append(...frames); + t.add_cleanup(() => { frames.map(val => val.remove()) }); + const frameWs = frames.map(val => val.contentWindow), + openee = frameWs[0].open("", "thebettername"); + assert_equals(openee, frameWs[1]); + assert_equals(openee.opener, frameWs[0]); + frames[0].remove(); + assert_equals(openee.opener, null); +}, "Set the opener browsing context to null when discarded (