Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[popover] Make element.togglePopover() return a boolean
https://bugs.webkit.org/show_bug.cgi?id=257769 Reviewed by Tim Nguyen. Implement togglePopover API change: whatwg/html#9393 * LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/togglePopover-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/togglePopover.html: Added. * Source/WebCore/html/HTMLElement.cpp: (WebCore::HTMLElement::togglePopover): * Source/WebCore/html/HTMLElement.h: * Source/WebCore/html/HTMLElement.idl: Canonical link: https://commits.webkit.org/265064@main
- Loading branch information
Showing
5 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...tTests/imported/w3c/web-platform-tests/html/semantics/popovers/togglePopover-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
PASS togglePopover should toggle the popover and return true or false as specified. | ||
PASS togglePopover's return value should reflect what the end state is, not just the force parameter. | ||
|
48 changes: 48 additions & 0 deletions
48
LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/togglePopover.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<link rel=author href="mailto:jarhar@chromium.org"> | ||
<link rel=help href="https://github.com/whatwg/html/issues/9043"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<div id=popover popover=auto>popover</div> | ||
<div id=popover2 popover=auto>popover</div> | ||
|
||
<script> | ||
test(() => { | ||
assert_false(popover.matches(':popover-open'), | ||
'Popover should be closed when the test starts.'); | ||
|
||
assert_true(popover.togglePopover(), | ||
'togglePopover() should return true.'); | ||
assert_true(popover.matches(':popover-open'), | ||
'togglePopover() should open the popover.'); | ||
|
||
assert_true(popover.togglePopover(/*force=*/true), | ||
'togglePopover(true) should return true.'); | ||
assert_true(popover.matches(':popover-open'), | ||
'togglePopover(true) should open the popover.'); | ||
|
||
assert_false(popover.togglePopover(), | ||
'togglePopover() should return false.'); | ||
assert_false(popover.matches(':popover-open'), | ||
'togglePopover() should close the popover.'); | ||
|
||
assert_false(popover.togglePopover(/*force=*/false), | ||
'togglePopover(false) should return false.'); | ||
assert_false(popover.matches(':popover-open'), | ||
'togglePopover(false) should close the popover.'); | ||
}, 'togglePopover should toggle the popover and return true or false as specified.'); | ||
|
||
test(() => { | ||
const popover = document.getElementById('popover2'); | ||
popover.addEventListener('beforetoggle', event => event.preventDefault(), {once: true}); | ||
assert_false(popover.togglePopover(/*force=*/true), | ||
'togglePopover(true) should return false when the popover does not get opened.'); | ||
assert_false(popover.matches(':popover-open')); | ||
|
||
// We could also add a test for the return value of togglePopover(false), | ||
// but every way to prevent that from hiding the popover also throws an | ||
// exception, so the return value is not testable. | ||
}, `togglePopover's return value should reflect what the end state is, not just the force parameter.`); | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters