-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't allow popups during page unloading times.
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
1 parent
69e4ebb
commit ffeba23
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
...gating-browsing-contexts-by-name/no_window_open_when_term_nesting_level_nonzero.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |