Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Add RuntimeEnabled flags to all idl's, fix test expectations. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../resources/js-test.js"></script>
3 <script src="helper-functions.js"></script>
4 <div style="width:100%; height:700px;"></div>
5 <div id="target" style="background-color: green; width:100px; height:100px"></di v>
6 <div style="width:100%; height:700px;"></div>
7
8 <script>
9 description("Intersection observer test with multiple thresholds.");
10 var target = document.getElementById("target");
11 var entries = [];
12
13 observer_callback = function(changes) {
14 for (var i in changes)
15 entries.push(changes[i]);
16 };
17 var observer = new IntersectionObserver(observer_callback, {
18 threshold: [0, 0.25, 0.5, 0.75]
19 });
20 observer.observe(target);
21
22 // TODO(szager): It shouldn't be necessary to RAF after the call to observer()
23 // and before changing the scroll position, but it is.
24
25 function step0() {
26 setTimeout(function() {
27 shouldBeEqualToNumber("entries.length", 0);
28 document.scrollingElement.scrollTop = 120;
29 requestAnimationFrame(step1);
30 });
31 }
32
33 function step1() {
34 setTimeout(function() {
35 shouldBeEqualToNumber("entries.length", 1);
36 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8);
37 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108);
38 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 588);
39 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 688);
40 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8);
41 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108);
42 shouldBeEqualToNumber("entries[0].intersectionRect.top", 588);
43 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 600);
44 shouldBeEqualToNumber("entries[0].rootBounds.left", 0);
45 shouldBeEqualToNumber("entries[0].rootBounds.right", 785);
46 shouldBeEqualToNumber("entries[0].rootBounds.top", 0);
47 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600);
48 shouldEvaluateToSameObject("entries[0].target", target);
49 document.scrollingElement.scrollTop = 160;
50 requestAnimationFrame(step2);
51 });
52 }
53
54 function step2() {
55 setTimeout(function() {
56 shouldBeEqualToNumber("entries.length", 2);
57 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8);
58 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108);
59 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 548);
60 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 648);
61 shouldBeEqualToNumber("entries[1].intersectionRect.left", 8);
62 shouldBeEqualToNumber("entries[1].intersectionRect.right", 108);
63 shouldBeEqualToNumber("entries[1].intersectionRect.top", 548);
64 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 600);
65 shouldBeEqualToNumber("entries[1].rootBounds.left", 0);
66 shouldBeEqualToNumber("entries[1].rootBounds.right", 785);
67 shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
68 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600);
69 shouldEvaluateToSameObject("entries[1].target", target);
70 document.scrollingElement.scrollTop = 200;
71 requestAnimationFrame(step3);
72 });
73 }
74
75 function step3() {
76 setTimeout(function() {
77 shouldBeEqualToNumber("entries.length", 3);
78 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 8);
79 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 108);
80 shouldBeEqualToNumber("entries[2].boundingClientRect.top", 508);
81 shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 608);
82 shouldBeEqualToNumber("entries[2].intersectionRect.left", 8);
83 shouldBeEqualToNumber("entries[2].intersectionRect.right", 108);
84 shouldBeEqualToNumber("entries[2].intersectionRect.top", 508);
85 shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 600);
86 shouldBeEqualToNumber("entries[2].rootBounds.left", 0);
87 shouldBeEqualToNumber("entries[2].rootBounds.right", 785);
88 shouldBeEqualToNumber("entries[2].rootBounds.top", 0);
89 shouldBeEqualToNumber("entries[2].rootBounds.bottom", 600);
90 shouldEvaluateToSameObject("entries[2].target", target);
91 document.scrollingElement.scrollTop = 240;
92 requestAnimationFrame(step4);
93 });
94 }
95
96 function step4() {
97 setTimeout(function() {
98 shouldBeEqualToNumber("entries.length", 3);
99 document.scrollingElement.scrollTop = 740;
100 requestAnimationFrame(step5);
101 });
102 }
103
104 function step5() {
105 setTimeout(function() {
106 shouldBeEqualToNumber("entries.length", 4);
107 shouldBeEqualToNumber("entries[3].boundingClientRect.left", 8);
108 shouldBeEqualToNumber("entries[3].boundingClientRect.right", 108);
109 shouldBeEqualToNumber("entries[3].boundingClientRect.top", -32);
110 shouldBeEqualToNumber("entries[3].boundingClientRect.bottom", 68);
111 shouldBeEqualToNumber("entries[3].intersectionRect.left", 8);
112 shouldBeEqualToNumber("entries[3].intersectionRect.right", 108);
113 shouldBeEqualToNumber("entries[3].intersectionRect.top", 0);
114 shouldBeEqualToNumber("entries[3].intersectionRect.bottom", 68);
115 shouldBeEqualToNumber("entries[3].rootBounds.left", 0);
116 shouldBeEqualToNumber("entries[3].rootBounds.right", 785);
117 shouldBeEqualToNumber("entries[3].rootBounds.top", 0);
118 shouldBeEqualToNumber("entries[3].rootBounds.bottom", 600);
119 shouldEvaluateToSameObject("entries[3].target", target);
120 document.scrollingElement.scrollTop = 760;
121 requestAnimationFrame(step6);
122 });
123 }
124
125 function step6() {
126 setTimeout(function() {
127 shouldBeEqualToNumber("entries.length", 5);
128 shouldBeEqualToNumber("entries[4].boundingClientRect.left", 8);
129 shouldBeEqualToNumber("entries[4].boundingClientRect.right", 108);
130 shouldBeEqualToNumber("entries[4].boundingClientRect.top", -52);
131 shouldBeEqualToNumber("entries[4].boundingClientRect.bottom", 48);
132 shouldBeEqualToNumber("entries[4].intersectionRect.left", 8);
133 shouldBeEqualToNumber("entries[4].intersectionRect.right", 108);
134 shouldBeEqualToNumber("entries[4].intersectionRect.top", 0);
135 shouldBeEqualToNumber("entries[4].intersectionRect.bottom", 48);
136 shouldBeEqualToNumber("entries[4].rootBounds.left", 0);
137 shouldBeEqualToNumber("entries[4].rootBounds.right", 785);
138 shouldBeEqualToNumber("entries[4].rootBounds.top", 0);
139 shouldBeEqualToNumber("entries[4].rootBounds.bottom", 600);
140 shouldEvaluateToSameObject("entries[4].target", target);
141 document.scrollingElement.scrollTop = 800;
142 requestAnimationFrame(step7);
143 });
144 }
145
146 function step7() {
147 setTimeout(function() {
148 shouldBeEqualToNumber("entries.length", 6);
149 shouldBeEqualToNumber("entries[5].boundingClientRect.left", 8);
150 shouldBeEqualToNumber("entries[5].boundingClientRect.right", 108);
151 shouldBeEqualToNumber("entries[5].boundingClientRect.top", -92);
152 shouldBeEqualToNumber("entries[5].boundingClientRect.bottom", 8);
153 shouldBeEqualToNumber("entries[5].intersectionRect.left", 8);
154 shouldBeEqualToNumber("entries[5].intersectionRect.right", 108);
155 shouldBeEqualToNumber("entries[5].intersectionRect.top", 0);
156 shouldBeEqualToNumber("entries[5].intersectionRect.bottom", 8);
157 shouldBeEqualToNumber("entries[5].rootBounds.left", 0);
158 shouldBeEqualToNumber("entries[5].rootBounds.right", 785);
159 shouldBeEqualToNumber("entries[5].rootBounds.top", 0);
160 shouldBeEqualToNumber("entries[5].rootBounds.bottom", 600);
161 shouldEvaluateToSameObject("entries[5].target", target);
162 document.scrollingElement.scrollTop = 820;
163 requestAnimationFrame(step8);
164 });
165 }
166
167 function step8() {
168 setTimeout(function() {
169 shouldBeEqualToNumber("entries.length", 7);
170 shouldBeEqualToNumber("entries[6].boundingClientRect.left", 8);
171 shouldBeEqualToNumber("entries[6].boundingClientRect.right", 108);
172 shouldBeEqualToNumber("entries[6].boundingClientRect.top", -112);
173 shouldBeEqualToNumber("entries[6].boundingClientRect.bottom", -12);
174 shouldBeEqualToNumber("entries[6].intersectionRect.left", 0);
175 shouldBeEqualToNumber("entries[6].intersectionRect.right", 0);
176 shouldBeEqualToNumber("entries[6].intersectionRect.top", 0);
177 shouldBeEqualToNumber("entries[6].intersectionRect.bottom", 0);
178 shouldBeEqualToNumber("entries[6].rootBounds.left", 0);
179 shouldBeEqualToNumber("entries[6].rootBounds.right", 785);
180 shouldBeEqualToNumber("entries[6].rootBounds.top", 0);
181 shouldBeEqualToNumber("entries[6].rootBounds.bottom", 600);
182 shouldEvaluateToSameObject("entries[6].target", target);
183 finishTest();
184 document.scrollingElement.scrollTop = 0;
185 });
186 }
187 requestAnimationFrame(step0);
188 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698