Skip to content

Commit

Permalink
HTML: window.opener clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk committed Mar 13, 2019
1 parent fd3bdd7 commit d1f6fc9
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions html/browsers/windows/opener-clearing.window.js
Original file line number Diff line number Diff line change
@@ -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 = "<iframe></iframe>";
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 (<iframe>)");

async_test(t => {
// Initially I had one less window.open() call, but Chrome forbids window.open() on about:blank
// from creating a new window. This works however.
const openee = window.open(),
thename = window.open("", "theevenbettername"),
furtherOpenee = openee.open("", "theevenbettername");
assert_equals(openee.opener, self);
assert_equals(furtherOpenee.opener, openee);
openee.onunload = t.step_func(() => {
assert_equals(furtherOpenee.opener, openee);
t.step_timeout(() => {
assert_equals(furtherOpenee.opener, null);
furtherOpenee.close();
t.done();
}, 0);
});
openee.close();
assert_equals(furtherOpenee.opener, openee);
}, "Set the opener browsing context to null when discarded (window.open)");

0 comments on commit d1f6fc9

Please sign in to comment.