summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/close-watcher/esc-key.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/close-watcher/esc-key.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/close-watcher/esc-key.html')
-rw-r--r--testing/web-platform/tests/close-watcher/esc-key.html77
1 files changed, 77 insertions, 0 deletions
diff --git a/testing/web-platform/tests/close-watcher/esc-key.html b/testing/web-platform/tests/close-watcher/esc-key.html
new file mode 100644
index 0000000000..16fcce6917
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/esc-key.html
@@ -0,0 +1,77 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="/resources/testdriver-actions.js"></script>
+<script src="resources/helpers.js"></script>
+
+<!--
+ Tests in this file are around the interaction of the Esc key specifically, not
+ the general concept of close requests. Ideally, all other tests would work
+ as-is if you changed the implementation of sendCloseRequest(). These tests
+ assume that Esc is the close request for the platform being tested.
+-->
+
+<body>
+<script>
+promise_test(async t => {
+ let events = [];
+ let watcher = createRecordingCloseWatcher(t, events);
+
+ await sendEscKey();
+
+ assert_array_equals(events, ["close"]);
+}, "Esc key does not count as user activation, so if it is the sole user interaction, that fires close but not cancel");
+
+promise_test(async t => {
+ let events = [];
+ let watcher = createRecordingCloseWatcher(t, events);
+
+ window.onkeydown = e => e.preventDefault();
+
+ await sendEscKey();
+
+ assert_array_equals(events, []);
+}, "A keydown listener can prevent the Esc keypress from being interpreted as a close request");
+
+promise_test(async t => {
+ let events = [];
+ let watcher = createRecordingCloseWatcher(t, events);
+
+ window.onkeyup = e => e.preventDefault();
+
+ await sendEscKey();
+
+ assert_array_equals(events, []);
+}, "A keyup listener can prevent the Esc keypress from being interpreted as a close request");
+
+promise_test(async t => {
+ let events = [];
+ let watcher = createRecordingCloseWatcher(t, events);
+
+ window.onkeypress = e => e.preventDefault();
+
+ await sendEscKey();
+
+ assert_array_equals(events, []);
+}, "A keypress listener can prevent the Esc keypress from being interpreted as a close request");
+
+test(t => {
+ let events = [];
+ let watcher = createRecordingCloseWatcher(t, events);
+
+ let keydown = new KeyboardEvent('keydown', {'key': 'Escape', 'keyCode': 27});
+ window.dispatchEvent(keydown);
+ let keyup = new KeyboardEvent('keyup', {'key': 'Escape', 'keyCode': 27});
+ window.dispatchEvent(keyup);
+
+ assert_array_equals(events, []);
+
+ let keyup2 = document.createEvent("Event");
+ keyup2.initEvent("keyup", true);
+ window.dispatchEvent(keyup2);
+
+ assert_array_equals(events, []);
+}, "close via synthesized Esc key must not work");
+</script>