File: beforematch-attribute-removal-001.html

package info (click to toggle)
thunderbird 1%3A144.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,725,312 kB
  • sloc: cpp: 7,869,225; javascript: 5,974,276; ansic: 3,946,747; python: 1,421,062; xml: 654,642; asm: 474,045; java: 183,117; sh: 110,973; makefile: 20,398; perl: 14,362; objc: 13,086; yacc: 4,583; pascal: 3,448; lex: 1,720; ruby: 999; exp: 762; sql: 731; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (53 lines) | stat: -rw-r--r-- 2,302 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<link rel="author" title="Tim Nguyen" href="https://github.com/nt1m">
<link rel="help" href="https://html.spec.whatwg.org/#ancestor-revealing-algorithm">
<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 attribute states are mutated on beforematch events.");
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.hidden = true;
        a2.addEventListener("beforematch", t.unreached_func("Algorithm should have aborted due to hidden attribute no longer being in the until-found state."));
        a3.addEventListener("toggle", t.unreached_func("Algorithm should have aborted due to hidden attribute no longer being in the until-found state."));
        t.done();
    }), { once: true });
}), { once: true });

location.hash = "#a1child";
</script>