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" commandfor="invokee" command="hide-popover"></button>
</div>
<button id="invokerbutton" commandfor="invokee" command="toggle-popover"></button>
<script>
function resetState() {
invokerbutton.setAttribute("commandfor", "invokee");
invokerbutton.setAttribute("command", "toggle-popover");
containedinvoker.setAttribute("commandfor", "invokee");
containedinvoker.setAttribute("command", "hide-popover");
try {
invokee.hidePopover();
} catch {}
invokee.setAttribute("popover", "");
}
promise_test(async function (t) {
assert_false(invokee.matches(":popover-open"));
invokee.addEventListener("command", (e) => { invokerbutton.setAttribute('command', 'hide-popover'); }, {
once: true,
});
await clickOn(invokerbutton);
t.add_cleanup(resetState);
assert_true(invokee.matches(":popover-open"));
}, "changing command attribute inside invokeevent doesn't impact the invocation");
// Open actions
[
"toggle-popover",
"show-popover",
/* test case sensitivity */
"tOgGlE-pOpOvEr",
"sHoW-pOpOvEr",
].forEach((command) => {
promise_test(
async function (t) {
t.add_cleanup(resetState);
invokerbutton.command = command;
assert_false(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_true(invokee.matches(":popover-open"));
},
`invoking (as ${command}) closed popover opens`,
);
promise_test(
async function (t) {
t.add_cleanup(resetState);
invokerbutton.command = command;
assert_false(invokee.matches(":popover-open"));
invokee.addEventListener("command", (e) => e.preventDefault(), {
once: true,
});
await clickOn(invokerbutton);
assert_false(invokee.matches(":popover-open"));
},
`invoking (as ${command}) closed popover with preventDefault does not open`,
);
});
// Close actions
[
"toggle-popover",
"hide-popover",
/* test case sensitivity */
"tOgGlE-pOpOvEr",
"hIdE-pOpOvEr",
].forEach((command) => {
promise_test(
async function (t) {
t.add_cleanup(resetState);
invokerbutton.command = command;
invokee.showPopover();
assert_true(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_false(invokee.matches(":popover-open"));
},
`invoking (as ${command}) open popover closes`,
);
promise_test(
async function (t) {
t.add_cleanup(resetState);
invokerbutton.command = command;
invokee.showPopover();
assert_true(invokee.matches(":popover-open"));
invokee.addEventListener("command", (e) => e.preventDefault(), {
once: true,
});
await clickOn(invokerbutton);
assert_true(invokee.matches(":popover-open"));
},
`invoking (as ${command}) open popover with preventDefault does not close`,
);
promise_test(
async function (t) {
t.add_cleanup(resetState);
containedinvoker.command = command;
invokee.showPopover();
assert_true(invokee.matches(":popover-open"));
await clickOn(containedinvoker);
assert_false(invokee.matches(":popover-open"));
},
`invoking (as ${command}) from within open popover closes`,
);
promise_test(
async function (t) {
t.add_cleanup(resetState);
containedinvoker.command = command;
invokee.showPopover();
invokee.addEventListener("command", (e) => e.preventDefault(), {
once: true,
});
assert_true(invokee.matches(":popover-open"));
await clickOn(containedinvoker);
assert_true(invokee.matches(":popover-open"));
},
`invoking (as ${command}) from within open popover with preventDefault does not close`,
);
});
// show-popover specific
promise_test(async function (t) {
t.add_cleanup(resetState);
invokerbutton.setAttribute("command", "show-popover");
invokee.showPopover();
assert_true(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_true(invokee.matches(":popover-open"));
}, "invoking (as show-popover) open popover is noop");
// hide-popover specific
promise_test(async function (t) {
t.add_cleanup(resetState);
invokerbutton.setAttribute("command", "hide-popover");
assert_false(invokee.matches(":popover-open"));
await clickOn(invokerbutton);
assert_false(invokee.matches(":popover-open"));
}, "invoking (as hide-popover) closed popover is noop");
</script>