diff --git a/html/semantics/popovers/togglePopover.html b/html/semantics/popovers/togglePopover.html index 115db8e2ac02c3..f17220f2ea4a15 100644 --- a/html/semantics/popovers/togglePopover.html +++ b/html/semantics/popovers/togglePopover.html @@ -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.');