summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/selectors/invalidation/has-complexity.html
blob: 0bdcdec13b97d8a2b3973f86773512474988519c (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Selector Invalidation: :has() invalidation should not be O(n^2)</title>
<link rel="author" title="Antti Koivisto" href="mailto:antti@apple.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://drafts.csswg.org/selectors/#relational">
<style>
div, main { color: grey }
main:has(span) .subject { color: red }
main:has(span + span) .subject { color: green }
main:has(span + final) .subject { color: blue }
main:has(nonexistent + span) .subject { color: black }
main:has(span) span { color: black }
main:has(nonexistent) span { color: black }
main:has(div div span) .subject { color: purple }
</style>
<main>
    <div id=container>
        <span></span>
    </div>
    <div id=subject class=subject></div>
</main>
<script>
const grey = 'rgb(128, 128, 128)';
const red = 'rgb(255, 0, 0)';
const green = 'rgb(0, 128, 0)';
const blue = 'rgb(0, 0, 255)';
const purple = 'rgb(128, 0, 128)';

function testColor(test_name, color) {
    test(function() {
        assert_equals(getComputedStyle(subject).color, color);
    }, test_name);
}

const count = 25000;

testColor(`Before appending ${count} elements`, red);

for (let i = 0; i < count; ++i) {
    const span = document.createElement("span");
    container.appendChild(span);
}

testColor(`After appending ${count} elements. This should not time out.`, green);

for (let i = 0; i < count - 1; ++i) {
    const span = document.createElement("span");
    container.appendChild(span);
}

const final = document.createElement("final");
container.appendChild(final);

testColor(`After appending another ${count} elements. This should not time out.`, blue);

const div = document.createElement("div");
for (let i = 0; i < count; ++i) {
    const span = document.createElement("span");
    div.appendChild(span);
}
container.appendChild(div);

testColor(`After appending div with ${count} elements. This should not time out.`, purple);

div.remove();

testColor(`After removing div with ${count} elements. This should not time out.`, blue);

for (let i = 0; i < count; ++i)
    container.lastChild.remove();

testColor(`After removing ${count} elements one-by-one. This should not time out.`, green);

container.replaceChildren();

testColor(`After removing the remaining elements. This should not time out.`, grey);

</script>