diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/close-watcher/abortsignal.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/close-watcher/abortsignal.html')
-rw-r--r-- | testing/web-platform/tests/close-watcher/abortsignal.html | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/testing/web-platform/tests/close-watcher/abortsignal.html b/testing/web-platform/tests/close-watcher/abortsignal.html new file mode 100644 index 0000000000..eb70ffed1b --- /dev/null +++ b/testing/web-platform/tests/close-watcher/abortsignal.html @@ -0,0 +1,123 @@ +<!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> + +<div id='d' style='height: 100px; width: 100px'></div> +<script> +// *not* \uu001B; see https://w3c.github.io/webdriver/#keyboard-actions +const ESC = '\uE00C'; + +test(() => { + let watcher = new CloseWatcher({ signal: AbortSignal.abort() }); + let oncancel_called = false; + let onclose_called = false; + watcher.oncancel = () => oncancel_called = true; + watcher.onclose = () => onclose_called = true; + + watcher.close(); + + assert_false(oncancel_called); + assert_false(onclose_called); +}, "already-aborted AbortSignal then close() fires no events"); + +test(() => { + let controller = new AbortController(); + let watcher = new CloseWatcher({ signal: controller.signal }); + let oncancel_called = false; + let onclose_called = false; + watcher.oncancel = () => oncancel_called = true; + watcher.onclose = () => onclose_called = true; + + controller.abort(); + watcher.close(); + + assert_false(oncancel_called); + assert_false(onclose_called); +}, "abortController.abort() then close() fires no events"); + +test(() => { + let controller = new AbortController(); + let watcher = new CloseWatcher({ signal: controller.signal }); + let oncancel_call_count_ = 0; + let onclose_call_count_ = 0; + watcher.oncancel = () => oncancel_call_count_++; + watcher.onclose = () => onclose_call_count_++; + + watcher.close(); + controller.abort(); + + assert_equals(oncancel_call_count_, 0); + assert_equals(onclose_call_count_, 1); +}, "close() then abortController.abort() fires only one close event"); + +promise_test(async () => { + let watcher = new CloseWatcher({ signal: AbortSignal.abort() }); + let oncancel_called = false; + let onclose_called = false; + watcher.oncancel = () => oncancel_called = true; + watcher.onclose = () => onclose_called = true; + + await test_driver.send_keys(document.getElementById('d'), ESC); + + assert_false(oncancel_called); + assert_false(onclose_called); +}, "already-aborted AbortSignal then Esc key fires no events"); + +promise_test(async t => { + let controller = new AbortController(); + let watcher = new CloseWatcher({ signal: controller.signal }); + let oncancel_called = false; + let onclose_called = false; + watcher.oncancel = () => oncancel_called = true; + watcher.onclose = () => onclose_called = true; + + controller.abort(); + await test_driver.send_keys(document.getElementById('d'), ESC); + + assert_false(oncancel_called); + assert_false(onclose_called); +}, "abortController.abort() then close via Esc key fires no events"); + +promise_test(async t => { + let controller = new AbortController(); + let watcher = new CloseWatcher({ signal: controller.signal }); + let oncancel_call_count_ = 0; + let onclose_call_count_ = 0; + watcher.oncancel = () => oncancel_call_count_++; + watcher.onclose = () => onclose_call_count_++; + + await test_driver.send_keys(document.getElementById('d'), ESC); + controller.abort(); + + assert_equals(oncancel_call_count_, 0); + assert_equals(onclose_call_count_, 1); +}, "Esc key then abortController.abort() fires only one close event"); + +test(t => { + let controller = new AbortController(); + let watcher = new CloseWatcher({ signal: controller.signal }); + controller.abort(); + let watcher2 = new CloseWatcher(); + t.add_cleanup(() => watcher2.destroy()); +}, "abortController.abort()ing a free CloseWatcher allows a new one to be created without a user activation"); + +promise_test(async t => { + let controller = new AbortController(); + let watcher = new CloseWatcher({ signal: controller.signal }); + watcher.oncancel = () => { controller.abort(); } + watcher.onclose = t.unreached_func("onclose"); + await test_driver.bless("give user activation so that cancel will fire", () => { + watcher.close(); + }); +}, "abortController.abort() inside oncancel"); + +test(t => { + let controller = new AbortController(); + let watcher = new CloseWatcher({ signal: controller.signal }); + watcher.onclose = () => { controller.abort(); } + watcher.close(); +}, "abortController.abort() inside onclose is benign"); +</script> |