Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 5 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/popovers/imperative-invokers.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<link rel=author href="mailto:masonf@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=unrelated></div>
<div id=popover popover=auto>
<div id=contained></div>
popover 1
</div>
<div id=popover2 popover=auto style="top:50px">
popover 2
</div>
<script>
function testOneCase(shouldBeIndependent,popover2Opener,msg) {
test((t) => {
assert_false(popover.matches(':popover-open'),'starting state');
assert_false(popover2.matches(':popover-open'),'starting state');
t.add_cleanup(() => {popover.hidePopover();popover2.hidePopover()});
popover.showPopover();
assert_true(popover.matches(':popover-open'));
popover2Opener();
assert_true(popover2.matches(':popover-open'),'opener should open popover2');
if (shouldBeIndependent) {
assert_false(popover.matches(':popover-open'),'popovers should not be related');
} else {
assert_true(popover.matches(':popover-open'),'popovers should be related to each other');
}
},msg);
}
testOneCase(true,() => popover2.showPopover(),'normal opening');
testOneCase(true,() => popover2.showPopover({source: unrelated}),'showPopover(unrelated)');
testOneCase(false,() => popover2.showPopover({source: popover}),'showPopover(popover)');
testOneCase(false,() => popover2.showPopover({source: contained}),'showPopover(contained)');
testOneCase(true,() => popover2.togglePopover(true),'togglePopover(true)');
testOneCase(true,() => popover2.togglePopover({force:true}),'togglePopover({force})');
testOneCase(true,() => popover2.togglePopover({source:unrelated}),'togglePopover(unrelated)');
testOneCase(false,() => popover2.togglePopover({source: popover}),'togglePopover(popover)');
testOneCase(false,() => popover2.togglePopover({force:true, source: popover}),'togglePopover({force, popover})');
test(() => {
assert_false(popover.matches(':popover-open'));
assert_throws_js(TypeError,() => popover2.showPopover({source: null}),'showPopover(null)');
assert_throws_js(TypeError,() => popover2.togglePopover({source:null}),'togglePopover(null)');
assert_false(popover.matches(':popover-open'));
},'null isn\'t a valid Element');
</script>