OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/js-test.js"></script> |
3 <script src="helper-functions.js"></script> | 3 <script src="helper-functions.js"></script> |
4 <div style="width:100%; height:700px;"></div> | 4 <div style="width:100%; height:700px;"></div> |
5 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> | 5 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> |
6 <div style="width:100%; height:700px;"></div> | 6 <div style="width:100%; height:700px;"></div> |
7 | 7 |
8 <script> | 8 <script> |
9 description("Intersection observer test with multiple thresholds."); | 9 description("Intersection observer test with multiple thresholds."); |
10 var target = document.getElementById("target"); | 10 var target = document.getElementById("target"); |
11 var entries = []; | 11 var entries = []; |
12 | 12 var observer = new IntersectionObserver( |
13 observer_callback = function(changes) { | 13 changes => { entries = entries.concat(changes) }, |
14 for (var i in changes) | 14 { threshold: [0, 0.25, 0.5, 0.75, 1] } |
15 entries.push(changes[i]); | 15 ); |
16 }; | 16 |
17 var observer = new IntersectionObserver(observer_callback, { | 17 onload = function() { |
18 threshold: [0, 0.25, 0.5, 0.75, 1] | |
19 }); | |
20 observer.observe(target); | 18 observer.observe(target); |
21 | 19 entries = entries.concat(observer.takeRecords()); |
22 function step0() { | 20 shouldBeEqualToNumber("entries.length", 0); |
23 setTimeout(function() { | 21 // See README for explanation of double RAF. |
24 shouldBeEqualToNumber("entries.length", 0); | 22 requestAnimationFrame(() => { requestAnimationFrame(step0) }); |
25 document.scrollingElement.scrollTop = 120; | 23 } |
26 requestAnimationFrame(step1); | 24 |
27 }); | 25 function step0() { |
28 } | 26 entries = entries.concat(observer.takeRecords()); |
29 | 27 shouldBeEqualToNumber("entries.length", 0); |
30 function step1() { | 28 document.scrollingElement.scrollTop = 120; |
31 setTimeout(function() { | 29 requestAnimationFrame(step1); |
32 shouldBeEqualToNumber("entries.length", 1); | 30 } |
33 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | 31 |
34 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); | 32 function step1() { |
35 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 588); | 33 entries = entries.concat(observer.takeRecords()); |
36 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 688); | 34 shouldBeEqualToNumber("entries.length", 1); |
37 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | 35 if (entries.length > 0) { |
38 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | 36 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); |
39 shouldBeEqualToNumber("entries[0].intersectionRect.top", 588); | 37 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); |
40 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 600); | 38 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 588); |
41 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | 39 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 688); |
42 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); | 40 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); |
43 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | 41 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); |
44 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | 42 shouldBeEqualToNumber("entries[0].intersectionRect.top", 588); |
45 shouldEvaluateToSameObject("entries[0].target", target); | 43 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 600); |
46 document.scrollingElement.scrollTop = 160; | 44 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); |
47 requestAnimationFrame(step2); | 45 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); |
48 }); | 46 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); |
49 } | 47 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); |
50 | 48 shouldEvaluateToSameObject("entries[0].target", target); |
51 function step2() { | 49 } |
52 setTimeout(function() { | 50 document.scrollingElement.scrollTop = 160; |
53 shouldBeEqualToNumber("entries.length", 2); | 51 requestAnimationFrame(step2); |
54 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); | 52 } |
55 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108); | 53 |
56 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 548); | 54 function step2() { |
57 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 648); | 55 entries = entries.concat(observer.takeRecords()); |
58 shouldBeEqualToNumber("entries[1].intersectionRect.left", 8); | 56 shouldBeEqualToNumber("entries.length", 2); |
59 shouldBeEqualToNumber("entries[1].intersectionRect.right", 108); | 57 if (entries.length > 1) { |
60 shouldBeEqualToNumber("entries[1].intersectionRect.top", 548); | 58 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); |
61 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 600); | 59 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108); |
62 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | 60 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 548); |
63 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | 61 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 648); |
64 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | 62 shouldBeEqualToNumber("entries[1].intersectionRect.left", 8); |
65 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | 63 shouldBeEqualToNumber("entries[1].intersectionRect.right", 108); |
66 shouldEvaluateToSameObject("entries[1].target", target); | 64 shouldBeEqualToNumber("entries[1].intersectionRect.top", 548); |
67 document.scrollingElement.scrollTop = 200; | 65 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 600); |
68 requestAnimationFrame(step3); | 66 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); |
69 }); | 67 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); |
70 } | 68 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); |
71 | 69 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); |
72 function step3() { | 70 shouldEvaluateToSameObject("entries[1].target", target); |
73 setTimeout(function() { | 71 } |
74 shouldBeEqualToNumber("entries.length", 3); | 72 document.scrollingElement.scrollTop = 200; |
75 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 8); | 73 requestAnimationFrame(step3); |
76 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 108); | 74 } |
77 shouldBeEqualToNumber("entries[2].boundingClientRect.top", 508); | 75 |
78 shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 608); | 76 function step3() { |
79 shouldBeEqualToNumber("entries[2].intersectionRect.left", 8); | 77 entries = entries.concat(observer.takeRecords()); |
80 shouldBeEqualToNumber("entries[2].intersectionRect.right", 108); | 78 shouldBeEqualToNumber("entries.length", 3); |
81 shouldBeEqualToNumber("entries[2].intersectionRect.top", 508); | 79 if (entries.length > 2) { |
82 shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 600); | 80 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 8); |
83 shouldBeEqualToNumber("entries[2].rootBounds.left", 0); | 81 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 108); |
84 shouldBeEqualToNumber("entries[2].rootBounds.right", 785); | 82 shouldBeEqualToNumber("entries[2].boundingClientRect.top", 508); |
85 shouldBeEqualToNumber("entries[2].rootBounds.top", 0); | 83 shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 608); |
86 shouldBeEqualToNumber("entries[2].rootBounds.bottom", 600); | 84 shouldBeEqualToNumber("entries[2].intersectionRect.left", 8); |
87 shouldEvaluateToSameObject("entries[2].target", target); | 85 shouldBeEqualToNumber("entries[2].intersectionRect.right", 108); |
88 document.scrollingElement.scrollTop = 240; | 86 shouldBeEqualToNumber("entries[2].intersectionRect.top", 508); |
89 requestAnimationFrame(step4); | 87 shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 600); |
90 }); | 88 shouldBeEqualToNumber("entries[2].rootBounds.left", 0); |
91 } | 89 shouldBeEqualToNumber("entries[2].rootBounds.right", 785); |
92 | 90 shouldBeEqualToNumber("entries[2].rootBounds.top", 0); |
93 function step4() { | 91 shouldBeEqualToNumber("entries[2].rootBounds.bottom", 600); |
94 setTimeout(function() { | 92 shouldEvaluateToSameObject("entries[2].target", target); |
95 shouldBeEqualToNumber("entries.length", 4); | 93 } |
96 shouldBeEqualToNumber("entries[3].boundingClientRect.left", 8); | 94 document.scrollingElement.scrollTop = 240; |
97 shouldBeEqualToNumber("entries[3].boundingClientRect.right", 108); | 95 requestAnimationFrame(step4); |
98 shouldBeEqualToNumber("entries[3].boundingClientRect.top", 468); | 96 } |
99 shouldBeEqualToNumber("entries[3].boundingClientRect.bottom", 568); | 97 |
100 shouldBeEqualToNumber("entries[3].intersectionRect.left", 8); | 98 function step4() { |
101 shouldBeEqualToNumber("entries[3].intersectionRect.right", 108); | 99 entries = entries.concat(observer.takeRecords()); |
102 shouldBeEqualToNumber("entries[3].intersectionRect.top", 468); | 100 shouldBeEqualToNumber("entries.length", 4); |
103 shouldBeEqualToNumber("entries[3].intersectionRect.bottom", 568); | 101 if (entries.length > 3) { |
104 shouldBeEqualToNumber("entries[3].rootBounds.left", 0); | 102 shouldBeEqualToNumber("entries[3].boundingClientRect.left", 8); |
105 shouldBeEqualToNumber("entries[3].rootBounds.right", 785); | 103 shouldBeEqualToNumber("entries[3].boundingClientRect.right", 108); |
106 shouldBeEqualToNumber("entries[3].rootBounds.top", 0); | 104 shouldBeEqualToNumber("entries[3].boundingClientRect.top", 468); |
107 shouldBeEqualToNumber("entries[3].rootBounds.bottom", 600); | 105 shouldBeEqualToNumber("entries[3].boundingClientRect.bottom", 568); |
108 shouldEvaluateToSameObject("entries[3].target", target); | 106 shouldBeEqualToNumber("entries[3].intersectionRect.left", 8); |
109 document.scrollingElement.scrollTop = 740; | 107 shouldBeEqualToNumber("entries[3].intersectionRect.right", 108); |
110 requestAnimationFrame(step5); | 108 shouldBeEqualToNumber("entries[3].intersectionRect.top", 468); |
111 }); | 109 shouldBeEqualToNumber("entries[3].intersectionRect.bottom", 568); |
112 } | 110 shouldBeEqualToNumber("entries[3].rootBounds.left", 0); |
113 | 111 shouldBeEqualToNumber("entries[3].rootBounds.right", 785); |
114 function step5() { | 112 shouldBeEqualToNumber("entries[3].rootBounds.top", 0); |
115 setTimeout(function() { | 113 shouldBeEqualToNumber("entries[3].rootBounds.bottom", 600); |
116 shouldBeEqualToNumber("entries.length", 5); | 114 shouldEvaluateToSameObject("entries[3].target", target); |
117 shouldBeEqualToNumber("entries[4].boundingClientRect.left", 8); | 115 } |
118 shouldBeEqualToNumber("entries[4].boundingClientRect.right", 108); | 116 document.scrollingElement.scrollTop = 740; |
119 shouldBeEqualToNumber("entries[4].boundingClientRect.top", -32); | 117 requestAnimationFrame(step5); |
120 shouldBeEqualToNumber("entries[4].boundingClientRect.bottom", 68); | 118 } |
121 shouldBeEqualToNumber("entries[4].intersectionRect.left", 8); | 119 |
122 shouldBeEqualToNumber("entries[4].intersectionRect.right", 108); | 120 function step5() { |
123 shouldBeEqualToNumber("entries[4].intersectionRect.top", 0); | 121 entries = entries.concat(observer.takeRecords()); |
124 shouldBeEqualToNumber("entries[4].intersectionRect.bottom", 68); | 122 shouldBeEqualToNumber("entries.length", 5); |
125 shouldBeEqualToNumber("entries[4].rootBounds.left", 0); | 123 if (entries.length > 4) { |
126 shouldBeEqualToNumber("entries[4].rootBounds.right", 785); | 124 shouldBeEqualToNumber("entries[4].boundingClientRect.left", 8); |
127 shouldBeEqualToNumber("entries[4].rootBounds.top", 0); | 125 shouldBeEqualToNumber("entries[4].boundingClientRect.right", 108); |
128 shouldBeEqualToNumber("entries[4].rootBounds.bottom", 600); | 126 shouldBeEqualToNumber("entries[4].boundingClientRect.top", -32); |
129 shouldEvaluateToSameObject("entries[4].target", target); | 127 shouldBeEqualToNumber("entries[4].boundingClientRect.bottom", 68); |
130 document.scrollingElement.scrollTop = 760; | 128 shouldBeEqualToNumber("entries[4].intersectionRect.left", 8); |
131 requestAnimationFrame(step6); | 129 shouldBeEqualToNumber("entries[4].intersectionRect.right", 108); |
132 }); | 130 shouldBeEqualToNumber("entries[4].intersectionRect.top", 0); |
133 } | 131 shouldBeEqualToNumber("entries[4].intersectionRect.bottom", 68); |
134 | 132 shouldBeEqualToNumber("entries[4].rootBounds.left", 0); |
135 function step6() { | 133 shouldBeEqualToNumber("entries[4].rootBounds.right", 785); |
136 setTimeout(function() { | 134 shouldBeEqualToNumber("entries[4].rootBounds.top", 0); |
137 shouldBeEqualToNumber("entries.length", 6); | 135 shouldBeEqualToNumber("entries[4].rootBounds.bottom", 600); |
138 shouldBeEqualToNumber("entries[5].boundingClientRect.left", 8); | 136 shouldEvaluateToSameObject("entries[4].target", target); |
139 shouldBeEqualToNumber("entries[5].boundingClientRect.right", 108); | 137 } |
140 shouldBeEqualToNumber("entries[5].boundingClientRect.top", -52); | 138 document.scrollingElement.scrollTop = 760; |
141 shouldBeEqualToNumber("entries[5].boundingClientRect.bottom", 48); | 139 requestAnimationFrame(step6); |
142 shouldBeEqualToNumber("entries[5].intersectionRect.left", 8); | 140 } |
143 shouldBeEqualToNumber("entries[5].intersectionRect.right", 108); | 141 |
144 shouldBeEqualToNumber("entries[5].intersectionRect.top", 0); | 142 function step6() { |
145 shouldBeEqualToNumber("entries[5].intersectionRect.bottom", 48); | 143 entries = entries.concat(observer.takeRecords()); |
146 shouldBeEqualToNumber("entries[5].rootBounds.left", 0); | 144 shouldBeEqualToNumber("entries.length", 6); |
147 shouldBeEqualToNumber("entries[5].rootBounds.right", 785); | 145 if (entries.length > 5) { |
148 shouldBeEqualToNumber("entries[5].rootBounds.top", 0); | 146 shouldBeEqualToNumber("entries[5].boundingClientRect.left", 8); |
149 shouldBeEqualToNumber("entries[5].rootBounds.bottom", 600); | 147 shouldBeEqualToNumber("entries[5].boundingClientRect.right", 108); |
150 shouldEvaluateToSameObject("entries[5].target", target); | 148 shouldBeEqualToNumber("entries[5].boundingClientRect.top", -52); |
151 document.scrollingElement.scrollTop = 800; | 149 shouldBeEqualToNumber("entries[5].boundingClientRect.bottom", 48); |
152 requestAnimationFrame(step7); | 150 shouldBeEqualToNumber("entries[5].intersectionRect.left", 8); |
153 }); | 151 shouldBeEqualToNumber("entries[5].intersectionRect.right", 108); |
154 } | 152 shouldBeEqualToNumber("entries[5].intersectionRect.top", 0); |
155 | 153 shouldBeEqualToNumber("entries[5].intersectionRect.bottom", 48); |
156 function step7() { | 154 shouldBeEqualToNumber("entries[5].rootBounds.left", 0); |
157 setTimeout(function() { | 155 shouldBeEqualToNumber("entries[5].rootBounds.right", 785); |
158 shouldBeEqualToNumber("entries.length", 7); | 156 shouldBeEqualToNumber("entries[5].rootBounds.top", 0); |
159 shouldBeEqualToNumber("entries[6].boundingClientRect.left", 8); | 157 shouldBeEqualToNumber("entries[5].rootBounds.bottom", 600); |
160 shouldBeEqualToNumber("entries[6].boundingClientRect.right", 108); | 158 shouldEvaluateToSameObject("entries[5].target", target); |
161 shouldBeEqualToNumber("entries[6].boundingClientRect.top", -92); | 159 } |
162 shouldBeEqualToNumber("entries[6].boundingClientRect.bottom", 8); | 160 document.scrollingElement.scrollTop = 800; |
163 shouldBeEqualToNumber("entries[6].intersectionRect.left", 8); | 161 requestAnimationFrame(step7); |
164 shouldBeEqualToNumber("entries[6].intersectionRect.right", 108); | 162 } |
165 shouldBeEqualToNumber("entries[6].intersectionRect.top", 0); | 163 |
166 shouldBeEqualToNumber("entries[6].intersectionRect.bottom", 8); | 164 function step7() { |
167 shouldBeEqualToNumber("entries[6].rootBounds.left", 0); | 165 entries = entries.concat(observer.takeRecords()); |
168 shouldBeEqualToNumber("entries[6].rootBounds.right", 785); | 166 shouldBeEqualToNumber("entries.length", 7); |
169 shouldBeEqualToNumber("entries[6].rootBounds.top", 0); | 167 if (entries.length > 6) { |
170 shouldBeEqualToNumber("entries[6].rootBounds.bottom", 600); | 168 shouldBeEqualToNumber("entries[6].boundingClientRect.left", 8); |
171 shouldEvaluateToSameObject("entries[6].target", target); | 169 shouldBeEqualToNumber("entries[6].boundingClientRect.right", 108); |
172 document.scrollingElement.scrollTop = 820; | 170 shouldBeEqualToNumber("entries[6].boundingClientRect.top", -92); |
173 requestAnimationFrame(step8); | 171 shouldBeEqualToNumber("entries[6].boundingClientRect.bottom", 8); |
174 }); | 172 shouldBeEqualToNumber("entries[6].intersectionRect.left", 8); |
175 } | 173 shouldBeEqualToNumber("entries[6].intersectionRect.right", 108); |
176 | 174 shouldBeEqualToNumber("entries[6].intersectionRect.top", 0); |
177 function step8() { | 175 shouldBeEqualToNumber("entries[6].intersectionRect.bottom", 8); |
178 setTimeout(function() { | 176 shouldBeEqualToNumber("entries[6].rootBounds.left", 0); |
179 shouldBeEqualToNumber("entries.length", 8); | 177 shouldBeEqualToNumber("entries[6].rootBounds.right", 785); |
180 shouldBeEqualToNumber("entries[7].boundingClientRect.left", 8); | 178 shouldBeEqualToNumber("entries[6].rootBounds.top", 0); |
181 shouldBeEqualToNumber("entries[7].boundingClientRect.right", 108); | 179 shouldBeEqualToNumber("entries[6].rootBounds.bottom", 600); |
182 shouldBeEqualToNumber("entries[7].boundingClientRect.top", -112); | 180 shouldEvaluateToSameObject("entries[6].target", target); |
183 shouldBeEqualToNumber("entries[7].boundingClientRect.bottom", -12); | 181 } |
184 shouldBeEqualToNumber("entries[7].intersectionRect.left", 0); | 182 document.scrollingElement.scrollTop = 820; |
185 shouldBeEqualToNumber("entries[7].intersectionRect.right", 0); | 183 requestAnimationFrame(step8); |
186 shouldBeEqualToNumber("entries[7].intersectionRect.top", 0); | 184 } |
187 shouldBeEqualToNumber("entries[7].intersectionRect.bottom", 0); | 185 |
188 shouldBeEqualToNumber("entries[7].rootBounds.left", 0); | 186 function step8() { |
189 shouldBeEqualToNumber("entries[7].rootBounds.right", 785); | 187 entries = entries.concat(observer.takeRecords()); |
190 shouldBeEqualToNumber("entries[7].rootBounds.top", 0); | 188 shouldBeEqualToNumber("entries.length", 8); |
191 shouldBeEqualToNumber("entries[7].rootBounds.bottom", 600); | 189 if (entries.length > 7) { |
192 shouldEvaluateToSameObject("entries[7].target", target); | 190 shouldBeEqualToNumber("entries[7].boundingClientRect.left", 8); |
193 finishJSTest(); | 191 shouldBeEqualToNumber("entries[7].boundingClientRect.right", 108); |
194 document.scrollingElement.scrollTop = 0; | 192 shouldBeEqualToNumber("entries[7].boundingClientRect.top", -112); |
195 }); | 193 shouldBeEqualToNumber("entries[7].boundingClientRect.bottom", -12); |
196 } | 194 shouldBeEqualToNumber("entries[7].intersectionRect.left", 0); |
197 | 195 shouldBeEqualToNumber("entries[7].intersectionRect.right", 0); |
198 step0(); | 196 shouldBeEqualToNumber("entries[7].intersectionRect.top", 0); |
| 197 shouldBeEqualToNumber("entries[7].intersectionRect.bottom", 0); |
| 198 shouldBeEqualToNumber("entries[7].rootBounds.left", 0); |
| 199 shouldBeEqualToNumber("entries[7].rootBounds.right", 785); |
| 200 shouldBeEqualToNumber("entries[7].rootBounds.top", 0); |
| 201 shouldBeEqualToNumber("entries[7].rootBounds.bottom", 600); |
| 202 shouldEvaluateToSameObject("entries[7].target", target); |
| 203 } |
| 204 finishJSTest(); |
| 205 document.scrollingElement.scrollTop = 0; |
| 206 } |
199 </script> | 207 </script> |
OLD | NEW |