From 4f76b5c85b83efe787793b2a33d2793950057ea3 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Wed, 22 Feb 2023 11:05:14 -0800 Subject: [PATCH] Update popover events test to check bubbles/cancelable Per a request [1], this adds a few more checks to ensure the toggle events have the right values for bubbles and cancelable. [1] https://github.com/whatwg/html/issues/8888#issuecomment-1439007393 Bug: 1307772 Change-Id: I8f3116703bbcb9dbc98df9be25c1fa03b7c2b97c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4278524 Commit-Queue: Joey Arhar Reviewed-by: Joey Arhar Auto-Submit: Mason Freed Cr-Commit-Position: refs/heads/main@{#1108470} --- html/semantics/popovers/popover-events.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/html/semantics/popovers/popover-events.html b/html/semantics/popovers/popover-events.html index 1ccd9967c5c9df..95cd5ad2add38e 100644 --- a/html/semantics/popovers/popover-events.html +++ b/html/semantics/popovers/popover-events.html @@ -28,21 +28,27 @@ let hideCount = 0; let afterHideCount = 0; function listener(e) { + assert_false(e.bubbles,'toggle events should not bubble'); if (e.type === "beforetoggle") { if (e.newState === "open") { ++showCount; assert_equals(e.oldState,"closed",'The "beforetoggle" event should be fired before the popover is open'); 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.'); + assert_true(e.cancelable,'beforetoggle should be cancelable only for the "show" transition'); } else { ++hideCount; assert_equals(e.newState,"closed",'Popover toggleevent states should be "open" and "closed"'); assert_equals(e.oldState,"open",'The "beforetoggle" event should be fired before the popover is 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.'); + assert_false(e.cancelable,'beforetoggle should be cancelable only for the "show" transition'); + e.preventDefault(); // beforetoggle should be cancelable only for the "show" transition } } else { assert_equals(e.type,"toggle",'Popover events should be "beforetoggle" and "toggle"') + assert_false(e.cancelable,'toggle should never be cancelable'); + e.preventDefault(); // toggle should never be cancelable if (e.newState === "open") { ++afterShowCount; if (document.body.contains(e.target)) {