Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[popover] Make togglePopover throw more exceptions
https://bugs.webkit.org/show_bug.cgi?id=258574

Reviewed by Tim Nguyen.

Throw exceptions in togglePopover in case of a disconnected node or the popover
attribute not being set anymore, see whatwg/html#8999.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/togglePopover-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/togglePopover.html:
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::HTMLElement::togglePopover):

Canonical link: https://commits.webkit.org/265589@main
  • Loading branch information
rwlbuis committed Jun 28, 2023
1 parent 30f3214 commit 348e2c9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
@@ -1,4 +1,5 @@

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.
PASS togglePopover should throw an exception when there is no popover attribute.

Expand Up @@ -44,4 +44,34 @@
// 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.`);


test(() => {
const popover = document.createElement('div');
document.body.appendChild(popover);

assert_throws_dom('NotSupportedError', () => popover.togglePopover(),
'togglePopover() should throw an exception when the element has no popover attribute.');
assert_throws_dom('NotSupportedError', () => popover.togglePopover(true),
'togglePopover(true) should throw an exception when the element has no popover attribute.');
assert_throws_dom('NotSupportedError', () => popover.togglePopover(false),
'togglePopover(false) should throw an exception when the element has no popover attribute.');

popover.setAttribute('popover', 'auto');
popover.remove();

assert_throws_dom('InvalidStateError', () => popover.togglePopover(),
'togglePopover() should throw an exception when the element is disconnected.');
assert_throws_dom('InvalidStateError', () => popover.togglePopover(true),
'togglePopover(true) should throw an exception when the element is disconnected.');
assert_throws_dom('InvalidStateError', () => popover.togglePopover(false),
'togglePopover(false) should throw an exception when the element is disconnected.');

document.body.appendChild(popover);
// togglePopover(false) should not throw just because the popover is already hidden.
popover.togglePopover(false);
popover.showPopover();
// togglePopover(true) should not throw just because the popover is already showing.
popover.togglePopover(true);
}, 'togglePopover should throw an exception when there is no popover attribute.');
</script>
4 changes: 4 additions & 0 deletions Source/WebCore/html/HTMLElement.cpp
Expand Up @@ -1489,6 +1489,10 @@ ExceptionOr<bool> HTMLElement::togglePopover(std::optional<bool> force)
auto returnValue = showPopover();
if (returnValue.hasException())
return returnValue.releaseException();
} else {
auto check = checkPopoverValidity(*this, popoverData() ? popoverData()->visibilityState() : PopoverVisibilityState::Showing);
if (check.hasException())
return check.releaseException();
}
return isPopoverShowing();
}
Expand Down

0 comments on commit 348e2c9

Please sign in to comment.