Skip to content

Commit

Permalink
Make togglePopover throw more exceptions
Browse files Browse the repository at this point in the history
This patch makes sure that togglePopover will throw exceptions when it
is disconnected from the document or doesn't have a popover attribute.

This is being discussed here: whatwg/html#8999

Change-Id: Iac7a486cd64b09b5657a157dbf3e9e54c1be2a27
  • Loading branch information
josepharhar authored and chromium-wpt-export-bot committed Jun 21, 2023
1 parent 95d67cd commit cd20864
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions html/semantics/popovers/togglePopover.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,33 @@
// 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>

0 comments on commit cd20864

Please sign in to comment.