Files
ladybird/Tests/LibWeb/Text/input/css-has-invalidation/baseline-subject-has.html
Andreas Kling a72fae8d36 LibWeb: Add test-only counters for :has() invalidation work
Introduce a small set of counters on Document that track the work done
while processing :has() invalidation: how often the upward walk runs,
how many elements it visits, how often matches_has_pseudo_class() is
invoked, how well the per-pass result cache performs, and how many
elements transition from clean to needs-style-update.

Expose the counters through internals so tests can assert precise bounds
on the invalidation work triggered by a mutation, which regular
reference tests cannot express.

Add a css-has-invalidation test suite that covers subject-position,
non-subject-position, sibling-combinator, and no-:has() cases. The
baseline tests share a helper script so later coverage can reuse the
same counter-printing path.

The counters are test-only observation; they do not affect style
computation itself.
2026-04-20 13:20:41 +02:00

37 lines
1.2 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script src="_helpers.js"></script>
<style>
.anchor:has(.match) { color: red; }
</style>
<div id="a1">
<div id="a2">
<div id="a3" class="anchor">
<div id="a4">
<div id="a5">
<span id="target">target</span>
</div>
</div>
</div>
</div>
</div>
<script>
test(() => {
// Force a style pass before measuring so initial-matching counters are not in scope.
getComputedStyle(document.getElementById("a3")).color;
internals.resetStyleInvalidationCounters();
// Subject-position :has() mutation: add matching class to deep descendant.
document.getElementById("target").classList.add("match");
getComputedStyle(document.getElementById("a3")).color;
printCounters("after add .match on target");
internals.resetStyleInvalidationCounters();
// Remove the class again.
document.getElementById("target").classList.remove("match");
getComputedStyle(document.getElementById("a3")).color;
printCounters("after remove .match on target");
});
</script>