summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/close-watcher/esc-key
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/close-watcher/esc-key')
-rw-r--r--testing/web-platform/tests/close-watcher/esc-key/README.md4
-rw-r--r--testing/web-platform/tests/close-watcher/esc-key/keydown.html21
-rw-r--r--testing/web-platform/tests/close-watcher/esc-key/keypress.html21
-rw-r--r--testing/web-platform/tests/close-watcher/esc-key/keyup.html21
-rw-r--r--testing/web-platform/tests/close-watcher/esc-key/not-user-activation.html19
-rw-r--r--testing/web-platform/tests/close-watcher/esc-key/synthetic-keyboard-event.html28
6 files changed, 114 insertions, 0 deletions
diff --git a/testing/web-platform/tests/close-watcher/esc-key/README.md b/testing/web-platform/tests/close-watcher/esc-key/README.md
new file mode 100644
index 0000000000..817edc09ab
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/esc-key/README.md
@@ -0,0 +1,4 @@
+Tests in this directory 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.
diff --git a/testing/web-platform/tests/close-watcher/esc-key/keydown.html b/testing/web-platform/tests/close-watcher/esc-key/keydown.html
new file mode 100644
index 0000000000..cb0ddf0638
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/esc-key/keydown.html
@@ -0,0 +1,21 @@
+<!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>
+
+<body>
+<script>
+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");
+</script>
diff --git a/testing/web-platform/tests/close-watcher/esc-key/keypress.html b/testing/web-platform/tests/close-watcher/esc-key/keypress.html
new file mode 100644
index 0000000000..8dd58b064d
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/esc-key/keypress.html
@@ -0,0 +1,21 @@
+<!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>
+
+<body>
+<script>
+promise_test(async t => {
+ let events = [];
+ let watcher = createRecordingCloseWatcher(t, events);
+
+ window.onkeypress = e => e.preventDefault();
+
+ await sendEscKey();
+
+ assert_array_equals(events, ["close"]);
+}, "A keypress listener can NOT prevent the Esc keypress from being interpreted as a close request");
+</script>
diff --git a/testing/web-platform/tests/close-watcher/esc-key/keyup.html b/testing/web-platform/tests/close-watcher/esc-key/keyup.html
new file mode 100644
index 0000000000..341012d6bc
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/esc-key/keyup.html
@@ -0,0 +1,21 @@
+<!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>
+
+<body>
+<script>
+promise_test(async t => {
+ let events = [];
+ let watcher = createRecordingCloseWatcher(t, events);
+
+ window.onkeyup = e => e.preventDefault();
+
+ await sendEscKey();
+
+ assert_array_equals(events, ["close"]);
+}, "A keyup listener can NOT prevent the Esc keypress from being interpreted as a close request");
+</script>
diff --git a/testing/web-platform/tests/close-watcher/esc-key/not-user-activation.html b/testing/web-platform/tests/close-watcher/esc-key/not-user-activation.html
new file mode 100644
index 0000000000..ac29f84f06
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/esc-key/not-user-activation.html
@@ -0,0 +1,19 @@
+<!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>
+
+<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");
+</script>
diff --git a/testing/web-platform/tests/close-watcher/esc-key/synthetic-keyboard-event.html b/testing/web-platform/tests/close-watcher/esc-key/synthetic-keyboard-event.html
new file mode 100644
index 0000000000..37b5507ac4
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/esc-key/synthetic-keyboard-event.html
@@ -0,0 +1,28 @@
+<!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>
+
+<body>
+<script>
+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>