Skip to content

Commit

Permalink
Don't allow popups during page unloading times.
Browse files Browse the repository at this point in the history
Precisely, this disallows them when the event loop's
termination nesting level is nonzero.

This is now part of the spec,
https://html.spec.whatwg.org/#apis-for-creating-and-navigating-browsing-contexts-by-name

> The window open steps, given a string url, a string target, and a string features, are as follows:
> 1. If the event loop's termination nesting level is nonzero, return null.

BUG=844455

Change-Id: I85fb003063f5ed051049c7c263391835421902ac
Reviewed-on: https://chromium-review.googlesource.com/c/1180296
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: Nate Chapin <japhet@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605025}
  • Loading branch information
Avi Drissman authored and chromium-wpt-export-bot committed Nov 2, 2018
1 parent 69e4ebb commit ffeba23
Showing 1 changed file with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
test(function() {
var test_window = window.open('', '', 'height=1,width=1');
var test_document = test_window.document;

var frame = test_document.createElement('iframe');
test_document.body.appendChild(frame);

frame.contentWindow.onpagehide = function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during pagehide");
};
frame.contentDocument.onvisibilitychange = function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during visibilitychange");
};
frame.contentWindow.onbeforeunload = function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during beforeunload");
};
frame.contentWindow.onunload = function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during unload");
};

frame.remove();
}, 'no popups with frame removal');

async_test(function(t) {
var test_window = window.open('', '', 'height=1,width=1');
var test_document = test_window.document;

var frame = test_document.createElement('iframe');
test_document.body.appendChild(frame);

frame.contentWindow.onpagehide = t.step_func(function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during pagehide");
});
frame.contentDocument.onvisibilitychange = t.step_func(function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during visibilitychange");
});
frame.contentWindow.onbeforeunload = t.step_func(function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during beforeunload");
});
frame.contentWindow.onunload = t.step_func(function(evt) {
assert_equals(frame.contentWindow.open('', '', 'height=1,width=1'), null,
"expected no popup during unload");
});

frame.onload = t.step_func_done();

frame.contentWindow.location.href = "about:blank";
}, 'no popups with frame navigation');

async_test(function(t) {
var test_window = window.open('', '', 'height=1,width=1');
var test_document = test_window.document;

var frame = test_document.createElement('iframe');
test_document.body.appendChild(frame);

frame.contentWindow.onpagehide = t.step_func(function(evt) {
assert_equals(test_window.open('', '', 'height=1,width=1'), null,
"expected no popup during pagehide");
});
frame.contentDocument.onvisibilitychange = t.step_func(function(evt) {
assert_equals(test_window.open('', '', 'height=1,width=1'), null,
"expected no popup during visibilitychange");
});
frame.contentWindow.onbeforeunload = t.step_func(function(evt) {
assert_equals(test_window.open('', '', 'height=1,width=1'), null,
"expected no popup during beforeunload");
});
frame.contentWindow.onunload = t.step_func(function(evt) {
assert_equals(test_window.open('', '', 'height=1,width=1'), null,
"expected no popup during unload");
});

frame.onload = t.step_func_done();

frame.contentWindow.location.href = "about:blank";
}, 'no popups from synchronously reachable window');

async_test(function(t) {
var test_window = window.open('', '', 'height=1,width=1');
var test_document = test_window.document;

var frame = test_document.createElement('iframe');
test_document.body.appendChild(frame);

frame.contentWindow.onpagehide = t.step_func(function(evt) {
assert_equals(window.open('', '', 'height=1,width=1'), null,
"expected no popup during pagehide");
});
frame.contentDocument.onvisibilitychange = t.step_func(function(evt) {
assert_equals(window.open('', '', 'height=1,width=1'), null,
"expected no popup during visibilitychange");
});
frame.contentWindow.onbeforeunload = t.step_func(function(evt) {
assert_equals(window.open('', '', 'height=1,width=1'), null,
"expected no popup during beforeunload");
});
frame.contentWindow.onunload = t.step_func(function(evt) {
assert_equals(window.open('', '', 'height=1,width=1'), null,
"expected no popup during unload");
});

frame.onload = t.step_func_done();

frame.contentWindow.location.href = "about:blank";
}, 'no popups from another synchronously reachable window');

0 comments on commit ffeba23

Please sign in to comment.