diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/html/webappapis/user-prompts | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/webappapis/user-prompts')
11 files changed, 286 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/confirm-different-origin-frame.sub.html b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/confirm-different-origin-frame.sub.html new file mode 100644 index 0000000000..693cde2192 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/confirm-different-origin-frame.sub.html @@ -0,0 +1,24 @@ +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> + setup({ single_test: true }); + function handleEvent(e) { + assert_equals(e.data, 'pass'); + done(); + } + function on_iframe_load() { + var frameWin = document.getElementById('confirmFrame').contentWindow; + frameWin.postMessage('Confirm', '*'); + } + window.addEventListener('message', handleEvent); +</script> + +<body> + <iframe id='confirmFrame' + src='http://{{hosts[alt][www]}}:{{ports[http][0]}}/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/confirm.html' + onload='on_iframe_load()'></iframe> +</body> + +</html> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/prompt-different-origin-frame.sub.html b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/prompt-different-origin-frame.sub.html new file mode 100644 index 0000000000..151def9b5a --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/prompt-different-origin-frame.sub.html @@ -0,0 +1,24 @@ +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> + setup({ single_test: true }); + function handleEvent(e) { + assert_equals(e.data, 'pass'); + done(); + } + function on_iframe_load() { + var frameWin = document.getElementById('promptFrame').contentWindow; + frameWin.postMessage('Prompt', '*'); + } + window.addEventListener('message', handleEvent); +</script> + +<body> + <iframe id='promptFrame' + src='http://{{hosts[alt][www]}}:{{ports[http][0]}}/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/prompt.html' + onload='on_iframe_load()'></iframe> +</body> + +</html> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/confirm.html b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/confirm.html new file mode 100644 index 0000000000..80b2c61b39 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/confirm.html @@ -0,0 +1,11 @@ +<script> + function handleEvent(e) { + var conf = window.confirm('Confirm Dialog'); + if (conf == false) { + window.parent.postMessage('pass', '*'); + } else { + window.parent.postMessage('fail', '*'); + } + } + window.addEventListener('message', handleEvent); +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/prompt.html b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/prompt.html new file mode 100644 index 0000000000..db40774770 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/cannot-show-simple-dialogs/support/prompt.html @@ -0,0 +1,11 @@ +<script> + function handleEvent(e) { + var conf = window.prompt('Prompt Dialog'); + if (conf == null) { + window.parent.postMessage('pass', '*'); + } else { + window.parent.postMessage('fail', '*'); + } + } + window.addEventListener('message', handleEvent); +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/newline-normalization-manual.html b/testing/web-platform/tests/html/webappapis/user-prompts/newline-normalization-manual.html new file mode 100644 index 0000000000..55cb5ce527 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/newline-normalization-manual.html @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Newline normalization in simple dialogs</title> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#simple-dialogs"> + +<p>The dialogs should all contain text looking like:</p> + +<pre>Line 1.1 +Line 1.2 +Line 1.3 +Line 1.4 + +Line 2.1</pre> + +<script> +"use strict"; + +for (const func of [alert, confirm, prompt]) { + func('Line 1.1\nLine 1.2\rLine 1.3\r\nLine 1.4\n\rLine 2.1'); +} +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/print-during-beforeunload.html b/testing/web-platform/tests/html/webappapis/user-prompts/print-during-beforeunload.html new file mode 100644 index 0000000000..5925bdde4d --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/print-during-beforeunload.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>print() during beforeunload</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<body> +<script> +"use strict"; + +async_test(t => { + const w = window.open("resources/print-during-event.sub.html?event=beforeunload"); + t.add_cleanup(() => w.close()); + + const messages = []; + window.addEventListener("message", t.step_func(({ data }) => { + messages.push(data); + + if (messages.length === 1) { + assert_array_equals(messages, ["start"]); + w.location.href = "resources/destination.html"; + } else if (messages.length === 2) { + // The test passes if we've reached this point because the print() dialog did not block the navigation. + assert_array_equals(messages, ["start", "destination"]); + t.done(); + } + })); +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/print-during-unload.html b/testing/web-platform/tests/html/webappapis/user-prompts/print-during-unload.html new file mode 100644 index 0000000000..81259a9fe0 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/print-during-unload.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>print() during unload</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<body> +<script> +"use strict"; + +async_test(t => { + const w = window.open("resources/print-during-event.sub.html?event=unload"); + t.add_cleanup(() => w.close()); + + const messages = []; + window.addEventListener("message", t.step_func(({ data }) => { + messages.push(data); + + if (messages.length === 1) { + assert_array_equals(messages, ["start"]); + w.location.href = "resources/destination.html"; + } else if (messages.length === 2) { + // The test passes if we've reached this point because the print() dialog did not block the navigation. + assert_array_equals(messages, ["start", "destination"]); + t.done(); + } + })); +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/print-in-detached-frame.html b/testing/web-platform/tests/html/webappapis/user-prompts/print-in-detached-frame.html new file mode 100644 index 0000000000..474f4f4d2a --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/print-in-detached-frame.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>print() in a detached iframe</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<body> +<script> +"use strict"; + +test(() => { + const iframe = document.createElement("iframe"); + document.body.append(iframe); + const print = iframe.contentWindow.print; + iframe.remove(); + + print(); +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/print-manual.html b/testing/web-platform/tests/html/webappapis/user-prompts/print-manual.html new file mode 100644 index 0000000000..67cbd0dd48 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/print-manual.html @@ -0,0 +1,93 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Printing</title> +<link rel=help href="https://html.spec.whatwg.org/#printing"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +setup({explicit_timeout: true}) +</script> + +<p>Click on the button below.</p> +<p>If the browser offers to print the current page, dismiss the prompt to +return to this page. The following should then appear in the box marked as +"Output":</p> +<pre> +before calling print() +beforeprint +afterprint +after calling print() +</pre> +<p>If no user dialog appears, either the above or the following should be +printed in the box marked as "Output":</p> +<pre> +before calling print() +after calling print() +</pre> +<p>The test passes if the above criteria are satisfied and "PASS" appears in a +table below this paragraph. The test fails otherwise.</p> + +<button onclick="testBtn(this)">Click here!</button> +<h3>Output</h3> +<pre id=output></pre> + +<script> +"use strict"; +// This test is actually synchronous, but we use async_test()'s nice +// infrastructure around t.step() to capture errors in event listeners. This is +// necessary since it seems like in Chrome, exceptions in beforeprint/afterprint +// event listeners are not propagated to error events. See +// https://crbug.com/977828. +const t = async_test(); +const log = []; +function out(str) { + log.push(str); + output.appendChild(document.createTextNode(str + "\n")); +} +function testBtn(btn) { + btn.remove(); + window.addEventListener("beforeprint", function (ev) { + // t.step_func() does not preserve `this`, which we test below. + t.step(() => { + out("beforeprint"); + assert_equals(Object.getPrototypeOf(ev), Event.prototype); + assert_equals(this, window); + assert_equals(ev.target, window); + assert_equals(ev.type, "beforeprint"); + }); + }); + window.addEventListener("afterprint", function (ev) { + // t.step_func() does not preserve `this`, which we test below. + t.step(() => { + out("afterprint"); + assert_equals(Object.getPrototypeOf(ev), Event.prototype); + assert_equals(this, window); + assert_equals(ev.target, window); + assert_equals(ev.type, "afterprint"); + }); + }); + out("before calling print()"); + print(); + out("after calling print()"); + t.step(() => { + try { + assert_array_equals(log, [ + "before calling print()", + "beforeprint", + "afterprint", + "after calling print()", + ]); + } catch (err) { + try { + assert_array_equals(log, [ + "before calling print()", + "after calling print()", + ]); + } catch (err) { + assert_unreached("Output does not match either possibility"); + } + } + }); + t.done(); +} +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/resources/destination.html b/testing/web-platform/tests/html/webappapis/user-prompts/resources/destination.html new file mode 100644 index 0000000000..87fb35cea3 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/resources/destination.html @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<meta charset="utf-8"> + +<script> +"use strict"; + +opener.postMessage("destination", "*"); +</script> diff --git a/testing/web-platform/tests/html/webappapis/user-prompts/resources/print-during-event.sub.html b/testing/web-platform/tests/html/webappapis/user-prompts/resources/print-during-event.sub.html new file mode 100644 index 0000000000..6f6a78b03c --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/user-prompts/resources/print-during-event.sub.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Page that tries to print during an event</title> + +<script> +"use strict"; + +window.on{{GET[event]}} = () => { + try { + window.print(); + } catch (e) { + window.opener.postMessage(`error: ${e.message}`); + } +}; + +window.opener.postMessage("start", "*"); +</script> |