Skip to content

Commit

Permalink
Throw exception for popovers/dialogs in non-active documents
Browse files Browse the repository at this point in the history
See discussion at:
  whatwg/html#10659

and spec PR at:
  whatwg/html#10705

Web-facing change PSA:
https://groups.google.com/a/chromium.org/g/blink-dev/c/jRFiIIkXv_k/m/jnPTfg8WBgAJ

Fixed: 373684393
Change-Id: I50e400ee526775f915f006865301fff2f04016b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5943740
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Commit-Queue: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1375681}
  • Loading branch information
mfreed7 authored and chromium-wpt-export-bot committed Oct 30, 2024
1 parent fb143c3 commit 0b99ee5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" href="mailto:masonf@chromium.org">
<link rel=help href="https://github.com/whatwg/html/pull/10705">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
test(() => {
const doc = document.implementation.createHTMLDocument();
const dialog = doc.createElement('dialog');
doc.body.appendChild(dialog);
assert_throws_dom('InvalidStateError',() => dialog.showModal());
assert_false(dialog.matches('[open]'));
},'showModal should throw when the document isn\'t active');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@
doc.body.appendChild(d11);
this.add_cleanup(() => document.body.append(d11));
assert_false(d11.open);
d11.showModal();
assert_true(d11.open);
this.add_cleanup(() => d11.close());
}, "Although the document is not attached to any pages, showModal() should execute as normal.");
assert_throws_dom("INVALID_STATE_ERR", () => d11.showModal());
assert_false(d11.open);
}, "When the document is not attached to any pages, showModal() should throw.");
</script>
17 changes: 17 additions & 0 deletions html/semantics/popovers/popover-active-document.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" href="mailto:masonf@chromium.org">
<link rel=help href="https://github.com/whatwg/html/pull/10705">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
test(() => {
const doc = document.implementation.createHTMLDocument();
const popover = doc.createElement('div');
popover.setAttribute('popover','');
doc.body.appendChild(popover);
assert_throws_dom('InvalidStateError',() => popover.showPopover());
assert_false(popover.matches(':open'));
},'showPopover should throw when the document isn\'t active');
</script>

0 comments on commit 0b99ee5

Please sign in to comment.