Source code

Revision control

Copy as Markdown

Other Tools

<!DOCTYPE html>
<link rel="author" title="Tim Nguyen" href="https://github.com/nt1m">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<details id="a3">
<div id="a2" hidden="until-found">
<details id="a1" hidden="until-found">
<div id="a1child">Hidden</div>
</details>
</div>
</details>
<script>
function test_state({ a1open, a1hidden, a2hidden, a3open }) {
assert_equals(a1.open, a1open, `a1 should ${a1open ? "" : "not "}be open`);
assert_equals(a1.hidden, a1hidden ? "until-found" : false, `a1 should ${a1hidden ? "" : "not "}be hidden`);
assert_equals(a2.hidden, a2hidden ? "until-found" : false, `a2 should ${a2hidden ? "" : "not "}be hidden`);
assert_equals(a3.open, a3open, `a3 should ${a3open ? "" : "not "}be open`);
}
t = async_test("hidden=until-found and details revealing algorithm should abort if revealed node is removed.");
test_state({
a1open: false,
a1hidden: true,
a2hidden: true,
a3open: false
});
a1.addEventListener("beforematch", t.step_func(() => {
test_state({
a1open: true, // We find the <details> element before finding hidden=until-found as a consequence of tree-traversal order.
a1hidden: true, // hidden=until-found removal happens after beforematch event.
a2hidden: true,
a3open: false
});
a2.addEventListener("beforematch", t.step_func((e) => {
assert_equals(e.target, a1, "a1 beforematch event bubbles up");
// No change in state, since it's part of the same event dispatch as above.
test_state({
a1open: true,
a1hidden: true,
a2hidden: true,
a3open: false
});
a1.remove();
a2.addEventListener("beforematch", t.unreached_func("Algorithm should have aborted due to node removal."));
a3.addEventListener("toggle", t.unreached_func("Algorithm should have aborted due to node removal."));
t.done();
}), { once: true });
}), { once: true });
location.hash = "#a1child";
</script>