diff options
Diffstat (limited to 'testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt')
16 files changed, 207 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001-1.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001-1.html new file mode 100644 index 0000000000..b68afc49ec --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001-1.html @@ -0,0 +1,10 @@ +<script> +addEventListener("beforeunload", +function() { + parent.events.push("beforeunload"); +}, false); +parent.events.push("before src change"); + +location.href = "001-2.html&pipe=trickle(d2)"; +parent.events.push("after src change"); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001-2.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001-2.html new file mode 100644 index 0000000000..9da0f9395c --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001-2.html @@ -0,0 +1 @@ +001-2 diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001.html new file mode 100644 index 0000000000..109dcc1393 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/001.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>beforeunload event order</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var t = async_test(); +events = []; +onload = t.step_func(function() { + assert_array_equals(events, ["before src change", "beforeunload", "after src change"]); + t.done(); +}) +</script> +<iframe src="001-1.html"></iframe> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/002-1.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/002-1.html new file mode 100644 index 0000000000..c5f57375da --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/002-1.html @@ -0,0 +1,7 @@ +<script> +addEventListsner("beforeunload", parent.t.step_func( +function(e) { + parent.do_test(e); +}, false); +location.href = "001-2.html&pipe=trickle(d2)"; +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/002.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/002.html new file mode 100644 index 0000000000..d8f4fc60a9 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/002.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>beforeunload event properties</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var t = async_test(); + +function do_test(e) { + assert_equals(e.type, "beforeunload"); + assert_false(e.bubbles, "bubbles"); + assert_true(e.cancelable, "bubbles"); + assert_equals(e.returnValue, ""); +} + +onload = t.step_func(function() { + t.done(); +}) +</script> +<iframe src="001-1.html"></iframe> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/003.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/003.html new file mode 100644 index 0000000000..5683f1b120 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/003.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>beforeunload event in child frame for parent navigation</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var t = async_test(); + +function do_test(e) { + assert_equals(e.type, "beforeunload"); + assert_false(e.bubbles, "bubbles"); + assert_true(e.cancelable, "bubbles"); + assert_equals(e.returnValue, ""); +} + +onload = t.step_func(function() { + t.done(); +}) +</script> +<iframe src="001-1.html"></iframe> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004-1.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004-1.html new file mode 100644 index 0000000000..a3ca82f520 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004-1.html @@ -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> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004-2.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004-2.html new file mode 100644 index 0000000000..1a605b1b3d --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004-2.html @@ -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> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004.html new file mode 100644 index 0000000000..7076a4dd18 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/004.html @@ -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> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-001.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-001.html new file mode 100644 index 0000000000..3b7ef74b71 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-001.html @@ -0,0 +1,9 @@ +<!doctype html> +<title>Prompt when beforeunload is canceled</title> +<script> +addEventListener("beforeunload", +function(e) {e.preventDefault()}, +false); +</script> +<p>When clicking the link below, you should get a prompt asking if you want to unload the document</p> +<a href="next.html">Click here</a> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-002.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-002.html new file mode 100644 index 0000000000..7be8a3301f --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-002.html @@ -0,0 +1,9 @@ +<!doctype html> +<title>Prompt when beforeunload has returnValue set</title> +<script> +addEventListener("beforeunload", +function(e) {e.returnValue = "PASS if you see this"}, +false); +</script> +<p>When clicking the link below, you should get a prompt asking if you want to unload the document</p> +<a href="next.html">Click here</a> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-003.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-003.html new file mode 100644 index 0000000000..ff72b67055 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-003.html @@ -0,0 +1,11 @@ +<!doctype html> +<title>Prompt when beforeunload is canceled</title> +<script> +addEventListener("beforeunload", +function(e) {e.preventDefault()}, +false); +</script> +<p>When clicking the button below, you should get a prompt asking if you want to unload the document</p> +<form method="get" action="next.html"> +<input type="submit" value="Click here"> +</form> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-004.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-004.html new file mode 100644 index 0000000000..a4d2968922 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-004.html @@ -0,0 +1,11 @@ +<!doctype html> +<title>Prompt on form submit</title> +<script> +addEventListener("beforeunload", +function(e) {e.preventDefault()}, +false); +</script> +<p>When clicking the button below, you should get a prompt asking if you want to unload the document</p> +<form method="get" action="next.html"> +<input type="submit" value="Click here"> +</form> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-005.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-005.html new file mode 100644 index 0000000000..71ff0a241d --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-005.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>Event loop pause for beforeunload</title> +<script> +var counter = 0; + +onload = function count() { + document.getElementById("log").textContent = counter++ + setTimeout(count, 200); +} + +addEventListener("beforeunload", +function(e) { + e.preventDefault() +}, +false); +</script> +<ul> +<li>Click on the link below. When the prompt appears the counter at the bottom must stop incrementing. +<li>Opt not to leave the page. The counter must start incrementing again +</ul> +<p><a href="">Click here</a> +<div id="log"></div> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-006.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-006.html new file mode 100644 index 0000000000..dae0340ad9 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/manual-006.html @@ -0,0 +1,9 @@ +<!doctype html> +<title>Prompt when beforeunload returns string value</title> +<script> +addEventListener("beforeunload", +function(e) {return "PASS if you see this"}, +false); +</script> +<p>When clicking the link below, you should get a prompt asking if you want to unload the document</p> +<a href="next.html">Click here</a> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/next.html b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/next.html new file mode 100644 index 0000000000..38e7cdd5e0 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/unloading-documents/prompt/next.html @@ -0,0 +1,2 @@ +<!doctype html> +<p>You should have seen a prompt asking you to unload the previous document |