diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/html/semantics/popovers/popover-events.tentative.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/semantics/popovers/popover-events.tentative.html')
-rw-r--r-- | testing/web-platform/tests/html/semantics/popovers/popover-events.tentative.html | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/popovers/popover-events.tentative.html b/testing/web-platform/tests/html/semantics/popovers/popover-events.tentative.html new file mode 100644 index 0000000000..7d63ce74b7 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/popovers/popover-events.tentative.html @@ -0,0 +1,91 @@ +<!DOCTYPE html> +<meta charset="utf-8" /> +<title>Popover events</title> +<link rel="author" href="mailto:masonf@chromium.org"> +<link rel=help href="https://open-ui.org/components/popup.research.explainer"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/popover-utils.js"></script> + +<div popover>Popover</div> + +<script> +window.onload = () => { + for(const method of ["listener","attribute"]) { + promise_test(async t => { + const popover = document.querySelector('[popover]'); + assert_false(popover.matches(':open')); + let showCount = 0; + let hideCount = 0; + function listener(e) { + if (e.newState === "open") { + assert_equals(e.currentState,"closed",'Popover toggleevent states should be "open" and "closed"') + assert_true(e.target.matches(':closed'),'The popover should be in the :closed state when the opening event fires.'); + assert_false(e.target.matches(':open'),'The popover should *not* be in the :open state when the opening event fires.'); + ++showCount; + } else { + assert_equals(e.currentState,"open",'Popover toggleevent states should be "open" and "closed"') + assert_equals(e.newState,"closed",'Popover toggleevent states should be "open" and "closed"') + assert_true(e.target.matches(':open'),'The popover should be in the :open state when the hiding event fires.'); + assert_false(e.target.matches(':closed'),'The popover should *not* be in the :closed state when the hiding event fires.'); + ++hideCount; + } + }; + switch (method) { + case "listener": + const controller = new AbortController(); + const signal = controller.signal; + t.add_cleanup(() => controller.abort()); + // The 'beforetoggle' event bubbles. + document.addEventListener('beforetoggle', listener, {signal}); + break; + case "attribute": + assert_false(popover.hasAttribute('onbeforetoggle')); + t.add_cleanup(() => popover.removeAttribute('onbeforetoggle')); + popover.onbeforetoggle = listener; + break; + default: assert_unreached(); + } + assert_equals(0,showCount); + assert_equals(0,hideCount); + popover.showPopover(); + assert_true(popover.matches(':open')); + assert_equals(1,showCount); + assert_equals(0,hideCount); + await waitForRender(); + assert_true(popover.matches(':open')); + popover.hidePopover(); + assert_false(popover.matches(':open')); + assert_equals(1,showCount); + assert_equals(1,hideCount); + await waitForRender(); + // No additional events after animation frame + assert_false(popover.matches(':open')); + assert_equals(1,showCount); + assert_equals(1,hideCount); + }, `Toggle event (${method}) get properly dispatched for popovers`); + } + + promise_test(async t => { + const popover = document.querySelector('[popover]'); + const controller = new AbortController(); + const signal = controller.signal; + t.add_cleanup(() => controller.abort()); + let cancel = true; + popover.addEventListener('beforetoggle',(e) => { + if (e.newState !== "open") + return; + if (cancel) + e.preventDefault(); + }, {signal}); + assert_false(popover.matches(':open')); + popover.showPopover(); + assert_false(popover.matches(':open'),'The "beforetoggle" event should be cancelable for the "opening" transition'); + cancel = false; + popover.showPopover(); + assert_true(popover.matches(':open')); + popover.hidePopover(); + assert_false(popover.matches(':open')); + }, 'Toggle event is cancelable for the "opening" transition'); +}; +</script> |