Commit c4aad864 authored by Ziran Sun's avatar Ziran Sun
Browse files

Bug 1829318 - Throw exception when calling dialog.show() on an open popover. r=emilio

parent c2e11e3c
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -69,10 +69,16 @@ void HTMLDialogElement::Close(
  eventDispatcher->PostDOMEvent();
}

void HTMLDialogElement::Show() {
void HTMLDialogElement::Show(ErrorResult& aError) {
  if (Open()) {
    return;
  }

  if (IsPopoverOpen()) {
    return aError.ThrowInvalidStateError(
        "Dialog element is already an open popover.");
  }

  SetOpen(true, IgnoreErrors());

  StorePreviouslyFocusedElement();
@@ -124,6 +130,11 @@ void HTMLDialogElement::ShowModal(ErrorResult& aError) {
        "Dialog element already has an 'open' attribute");
  }

  if (IsPopoverOpen()) {
    return aError.ThrowInvalidStateError(
        "Dialog element is already an open popover.");
  }

  AddToTopLayerIfNeeded();

  SetOpen(true, aError);
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class HTMLDialogElement final : public nsGenericHTMLElement {
  void UnbindFromTree(bool aNullParent = true) override;

  void Close(const mozilla::dom::Optional<nsAString>& aReturnValue);
  void Show();
  void Show(ErrorResult& aError);
  void ShowModal(ErrorResult& aError);

  bool IsInTopLayer() const;
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ interface HTMLDialogElement : HTMLElement {
  [CEReactions, SetterThrows]
  attribute boolean open;
  attribute DOMString returnValue;
  [CEReactions]
  [CEReactions, Throws]
  undefined show();
  [CEReactions, Throws]
  undefined showModal();
+0 −12
Original line number Diff line number Diff line
[popover-top-layer-combinations.html]
  [Popover combination: Popover Dialog]
    expected: FAIL

  [Popover combination: Open Non-modal Popover Dialog]
    expected: FAIL

  [Popover combination: Fullscreen Popover]
    expected: FAIL

  [Popover combination: Fullscreen Popover Dialog]
    expected: FAIL

  [Popover combination: Fullscreen Open Non-modal Popover Dialog]
    expected: FAIL