beforematch-element-removal-001.html (2181B)
1 <!DOCTYPE html> 2 <link rel="author" title="Tim Nguyen" href="https://github.com/nt1m"> 3 <link rel="help" href="https://html.spec.whatwg.org/#ancestor-revealing-algorithm"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <details id="a3"> 8 <div id="a2" hidden="until-found"> 9 <details id="a1" hidden="until-found"> 10 <div id="a1child">Hidden</div> 11 </details> 12 </div> 13 </details> 14 15 <script> 16 function test_state({ a1open, a1hidden, a2hidden, a3open }) { 17 assert_equals(a1.open, a1open, `a1 should ${a1open ? "" : "not "}be open`); 18 assert_equals(a1.hidden, a1hidden ? "until-found" : false, `a1 should ${a1hidden ? "" : "not "}be hidden`); 19 assert_equals(a2.hidden, a2hidden ? "until-found" : false, `a2 should ${a2hidden ? "" : "not "}be hidden`); 20 assert_equals(a3.open, a3open, `a3 should ${a3open ? "" : "not "}be open`); 21 } 22 t = async_test("hidden=until-found and details revealing algorithm should abort if revealed node is removed."); 23 test_state({ 24 a1open: false, 25 a1hidden: true, 26 a2hidden: true, 27 a3open: false 28 }); 29 a1.addEventListener("beforematch", t.step_func(() => { 30 test_state({ 31 a1open: true, // We find the <details> element before finding hidden=until-found as a consequence of tree-traversal order. 32 a1hidden: true, // hidden=until-found removal happens after beforematch event. 33 a2hidden: true, 34 a3open: false 35 }); 36 a2.addEventListener("beforematch", t.step_func((e) => { 37 assert_equals(e.target, a1, "a1 beforematch event bubbles up"); 38 // No change in state, since it's part of the same event dispatch as above. 39 test_state({ 40 a1open: true, 41 a1hidden: true, 42 a2hidden: true, 43 a3open: false 44 }); 45 a1.remove(); 46 a2.addEventListener("beforematch", t.unreached_func("Algorithm should have aborted due to node removal.")); 47 a3.addEventListener("toggle", t.unreached_func("Algorithm should have aborted due to node removal.")); 48 t.done(); 49 }), { once: true }); 50 }), { once: true }); 51 52 location.hash = "#a1child"; 53 </script>