Add a test that document.open doesn't break popovers

Per more conversation on [1], this CL adds more testing of event
listener corner cases.

[1] https://github.com/whatwg/html/issues/7785#issuecomment-1299403287

Bug: 1307772
Change-Id: Iab7e0e13e28647119cc0501d7c76be2b611870e2
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4000621
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1067170}
diff --git a/html/semantics/popovers/popover-document-open.tentative.html b/html/semantics/popovers/popover-document-open.tentative.html
new file mode 100644
index 0000000..429fd89
--- /dev/null
+++ b/html/semantics/popovers/popover-document-open.tentative.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<link rel="author" href="mailto:masonf@chromium.org">
+<link rel=help href="https://open-ui.org/components/popup.research.explainer">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<div popover id=popover1>Popover</div>
+
+<script>
+  window.onload = () => {
+    test((t) => {
+      const popover1 = document.querySelector('#popover1');
+      popover1.showPopover();
+      assert_true(popover1.matches(':open'));
+      assert_true(!document.querySelector('#popover2'));
+      document.open();
+      document.write('<!DOCTYPE html><div popover id=popover2>Popover</div>');
+      document.close();
+      assert_true(!document.querySelector('#popover1'),'popover1 should be removed from the document');
+      assert_true(!!document.querySelector('#popover2'),'popover2 should be in the document');
+      assert_false(popover1.matches(':open'),'popover1 should have been hidden when it was removed from the document');
+      assert_false(popover1.matches(':open'),'popover2 shouldn\'t be showing yet');
+      popover2.showPopover();
+      assert_true(popover2.matches(':open'),'popover2 should be able to be shown');
+      popover2.hidePopover();
+    },'document.open should not break popovers');
+  };
+</script>