Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!doctype html>
<meta charset="utf-8" />
<meta name="author" title="Keith Cirkel" href="mailto:wpt@keithcirkel.co.uk" />
<meta name="timeout" content="long" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/invoker-utils.js"></script>
<div id="invokee" popover>
<button id="containedinvoker" invoketarget="invokee"></button>
</div>
<button id="invokerbutton" invoketarget="invokee"></button>
<script>
// auto
promise_test(async function (t) {
assert_false(invokee.matches(":popover-open"));
invokee.addEventListener("invoke", (e) => { invokerbutton.setAttribute('invokeaction', 'hidepopover'); }, {
once: true,
});
await clickOn(invokerbutton);
t.add_cleanup(() => {
invokee.hidePopover();
invokerbutton.removeAttribute("invokeaction");
});
assert_true(invokee.matches(":popover-open"));
}, "changing invokeaction attribute inside invokeevent doesn't impact the invocation");
function resetState() {
invokerbutton.removeAttribute("invokeaction");
containedinvoker.removeAttribute("invokeaction");
try {
invokee.hidePopover();
} catch {}
invokee.setAttribute("popover", "");
}
// Open actions
[
null,
"",
"togglepopover",
"showpopover",
/* test case sensitivity */
"tOgGlEpOpOvEr",
"sHoWpOpOvEr",
].forEach((action) => {
promise_test(
async function (t) {
t.add_cleanup(resetState);
if (action !== null) invokerbutton.invokeAction = action;
assert_false(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_true(invokee.matches(":popover-open"));
},
`invoking (as ${
action === null ? "auto" : action || "explicit empty"
}) closed popover opens`,
);
promise_test(
async function (t) {
t.add_cleanup(resetState);
if (action !== null) invokerbutton.invokeAction = action;
assert_false(invokee.matches(":popover-open"));
invokee.addEventListener("invoke", (e) => e.preventDefault(), {
once: true,
});
await clickOn(invokerbutton);
assert_false(invokee.matches(":popover-open"));
},
`invoking (as ${
action === null ? "auto" : action || "explicit empty"
}) closed popover with preventDefault does not open`,
);
});
// Close actions
[
null,
"",
"togglepopover",
"hidepopover",
/* test case sensitivity */
"tOgGlEpOpOvEr",
"hIdEpOpOvEr",
].forEach((action) => {
promise_test(
async function (t) {
t.add_cleanup(resetState);
if (action !== null) invokerbutton.invokeAction = action;
invokee.showPopover();
assert_true(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_false(invokee.matches(":popover-open"));
},
`invoking (as ${
action === null ? "auto" : action || "explicit empty"
}) open popover closes`,
);
promise_test(
async function (t) {
t.add_cleanup(resetState);
if (action !== null) containedinvoker.invokeAction = action;
invokee.showPopover();
assert_true(invokee.matches(":popover-open"));
await clickOn(containedinvoker);
assert_false(invokee.matches(":popover-open"));
},
`invoking (as ${
action === null ? "auto" : action || "explicit empty"
}) from within open popover closes`,
);
promise_test(
async function (t) {
t.add_cleanup(resetState);
if (action !== null) invcontainedinvokervokeaction = action;
invokee.showPopover();
invokee.addEventListener("invoke", (e) => e.preventDefault(), {
once: true,
});
assert_true(invokee.matches(":popover-open"));
await clickOn(containedinvoker);
assert_true(invokee.matches(":popover-open"));
},
`invoking (as ${
action === null ? "auto" : action || "explicit empty"
}) open popover with preventDefault does not close`,
);
});
// showpopover specific
promise_test(async function (t) {
t.add_cleanup(resetState);
invokerbutton.setAttribute("invokeaction", "showpopover");
invokee.showPopover();
assert_true(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_true(invokee.matches(":popover-open"));
}, "invoking (as showpopover) open popover is noop");
// hidepopover specific
promise_test(async function (t) {
t.add_cleanup(resetState);
invokerbutton.setAttribute("invokeaction", "hidepopover");
assert_false(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_false(invokee.matches(":popover-open"));
}, "invoking (as hidepopover) closed popover is noop");
</script>