Optimized querySelector(All) when selector contains #id
[WebKit-https.git] / LayoutTests / fast / selectors / querySelector-id-filtering.html
1 <!doctype html>
2 <html id=htmlDocument>
3 <head>
4 <script src="../../resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <div style="display:none">
8     <!-- Simple case -->
9     <div id=simple>
10         <ul>
11             <li id=simpleTarget></li>
12         </ul>
13     </div>
14
15     <!-- Duplicated IDs case -->
16     <div id=duplicated>
17         <ul>
18             <li id=duplicatedTarget1></li>
19         </ul>
20         <div id=duplicated>
21             <ul>
22                 <li id=duplicatedTarget2></li>
23             </ul>
24         </div>
25     </div>
26     <div>
27         <ul>
28             <li id=siblingOfDuplicated1></li>
29         </ul>
30     </div>
31
32     <div id=duplicated>
33         <ul>
34             <li id=duplicatedTarget3></li>
35         </ul>
36     </div>
37     <div>
38         <ul>
39             <li id=siblingOfDuplicated2></li>
40         </ul>
41     </div>
42
43     <!-- Duplicated IDs in a non-duplicated ID -->
44     <div id=nonDuplicatedParentOfDuplicate>
45         <div id=deduplicated>
46             <ul>
47                 <li id=deduplicatedTarget1></li>
48             </ul>
49             <div id=deduplicated>
50                 <ul>
51                     <li id=deduplicatedTarget2></li>
52                 </ul>
53             </div>
54         </div>
55         <div>
56             <ul>
57                 <li id=siblingOfDeduplicated1></li>
58             </ul>
59         </div>
60
61         <div id=deduplicated>
62             <ul>
63                 <li id=deduplicatedTarget3></li>
64             </ul>
65         </div>
66         <div>
67             <ul>
68                 <li id=siblingOfDeduplicated2></li>
69             </ul>
70         </div>
71     </div>
72     <div>
73         <ul>
74             <li id=siblingOfNonDuplicatedParentOfDuplicate></li>
75         </ul>
76     </div>
77
78     <!-- ID adjacent of target -->
79     <div id=directAdjacentRoot></div>
80     <div>
81         <ul>
82             <li id="directAdjacentTarget"></li>
83         </ul>
84     </div>
85
86     <!-- ID indirect adjacent of target -->
87     <div id=indirectAdjacentRoot></div>
88     <div></div>
89     <div></div>
90     <div>
91         <ul>
92             <li id="indirectAdjacentTarget"></li>
93         </ul>
94     </div>
95 </div>
96 </body>
97 <script>
98 description('Test various cases when we constrain a selector matching to a subtree selected by #ID');
99
100 debug("Missing id.");
101 shouldBe('document.body.querySelectorAll("#notThere *").length', '0');
102
103 debug("<br>Trivial filtering.");
104 shouldBe('document.body.querySelectorAll("#simple li").length', '1');
105 shouldBeEqualToString('document.body.querySelectorAll("#simple li")[0].id', 'simpleTarget');
106
107 debug("<br>ID is adjacent of target.");
108 shouldBe('document.body.querySelectorAll("#directAdjacentRoot+div li").length', '1');
109 shouldBeEqualToString('document.body.querySelectorAll("#directAdjacentRoot+div li")[0].id', 'directAdjacentTarget');
110 shouldBe('document.body.querySelectorAll("#indirectAdjacentRoot~div li").length', '1');
111 shouldBeEqualToString('document.body.querySelectorAll("#indirectAdjacentRoot~div li")[0].id', 'indirectAdjacentTarget');
112
113 debug("<br>Duplicated IDs.");
114 shouldBe('document.body.querySelectorAll("#duplicated li").length', '3');
115 shouldBeEqualToString('document.body.querySelectorAll("#duplicated li")[0].id', 'duplicatedTarget1');
116 shouldBeEqualToString('document.body.querySelectorAll("#duplicated li")[1].id', 'duplicatedTarget2');
117 shouldBeEqualToString('document.body.querySelectorAll("#duplicated li")[2].id', 'duplicatedTarget3');
118 shouldBe('document.body.querySelectorAll("#duplicated+div li").length', '2');
119 shouldBeEqualToString('document.body.querySelectorAll("#duplicated+div li")[0].id', 'siblingOfDuplicated1');
120 shouldBeEqualToString('document.body.querySelectorAll("#duplicated+div li")[1].id', 'siblingOfDuplicated2');
121
122 debug("<br>Duplicated IDs with a non-duplicated ancestor.");
123 shouldBe('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate #deduplicated li").length', '3');
124 shouldBeEqualToString('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate #deduplicated li")[0].id', 'deduplicatedTarget1');
125 shouldBeEqualToString('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate #deduplicated li")[1].id', 'deduplicatedTarget2');
126 shouldBeEqualToString('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate #deduplicated li")[2].id', 'deduplicatedTarget3');
127 shouldBe('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate #deduplicated+div li").length', '2');
128 shouldBeEqualToString('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate #deduplicated+div li")[0].id', 'siblingOfDeduplicated1');
129 shouldBeEqualToString('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate #deduplicated+div li")[1].id', 'siblingOfDeduplicated2');
130 shouldBe('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate+div li").length', '1');
131 shouldBeEqualToString('document.body.querySelectorAll("#nonDuplicatedParentOfDuplicate+div li")[0].id', 'siblingOfNonDuplicatedParentOfDuplicate');
132
133 debug("<br>Sibling of HTML document.");
134 shouldBe('document.body.querySelectorAll("#htmlDocument~* *").length', '0');
135
136 </script>
137 <script src="../../resources/js-test-post.js"></script>
138 </html>