prevent overwriting of salvageable state in later prompt/unload steps

This commit is contained in:
Gregory Terzian 2018-05-20 23:49:15 +08:00
parent a297e8f288
commit 57c0d82944
5 changed files with 101 additions and 5 deletions

View file

@ -0,0 +1,28 @@
<!doctype html>
004-1
<script>
var handleBeforeUnload = function() {
parent.beforeunload_fired = true;
removeListener();
setTimeout(function() {
parent.timeout_fired = true;
}, 1000);
}
var removeListener = function() {
assert_true(window.removeEventListener('beforeunload', handleBeforeUnload, false));
}
window.addEventListener('beforeunload', handleBeforeUnload, false);
onload = function() {
if (!parent.loaded) {
parent.loaded = true;
location="004-2.html?" + Math.random();
}
}
</script>
// child frame with no onbeforeunload listener. Should leave the parent as unsalvageable.
// Adding the iframe prevents potential implementation bugs where the the recursive steps of #prompt-to-unload-a-document
// would overwrite the salvageable state of the parent.
<iframe></iframe>

View file

@ -0,0 +1,5 @@
<!doctype html>
004-2
<script>
onload = function() {setTimeout(parent.t.step_func(function() {parent.start_test(); history.go(-1)}), 100)}
</script>

View file

@ -0,0 +1,29 @@
<!doctype html>
<title>salvagable state of document after setting beforeunload listener</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test();
var loaded = false;
var beforeunload_fired = false;
var timeout_fired = false;
function start_test() {
step_timeout(
t.step_func(function() {
assert_true(beforeunload_fired);
assert_false(timeout_fired);
t.done()
}), 1000);
}
onload = function() {
var iframe = document.getElementsByTagName("iframe")[0]
onload = null;
iframe.src="004-1.html?" + Math.random();
};
</script>
<iframe></iframe>