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

Side by Side Diff: LayoutTests/fast/scroll-behavior/scroll-customization/touch-scroll-customization.html

Issue 1057603002: Expose scroll customization for touch to JS (behind REF). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address haraken's comments. Created 5 years, 6 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 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Scroll customization methods are called appropriately.</title>
6 <script src="../../../resources/testharness.js"></script>
7 <script src="../../../resources/testharnessreport.js"></script>
8 <style>
9
10 * {
11 margin:0;
12 padding:0;
13 }
14
15 *::-webkit-scrollbar {
16 width: 0 !important;
17 height: 0 !important;
18 }
19
20 #a {
21 height:400px;
22 width:400px;
23 overflow:scroll;
24 }
25
26 #b {
27 height:500px;
28 width:500px;
29 background-color:purple;
30 }
31
32 #c {
33 height:300px;
34 width:300px;
35 overflow:scroll;
36 }
37
38 #d {
39 height:400px;
40 width:400px;
41 background-color:green;
42 }
43
44 body {
45 height:3000px;
46 }
47
48 </style>
49 </head>
50 <body>
51
52 <div id="a">
53 <div id="b">
54 <div id="c">
55 <div id="d">
56 </div>
57 </div>
58 </div>
59 </div>
60
61 <script>
62 test(function() {
63 assert_true('ScrollState' in window, "'ScrollState' in window");
64 }, "These tests only work with scroll customization enabled.");
65
66 var originalApplyScrolls = [];
67 var originalDistributeScrolls = [];
68 var deltas = [-85, -75, -65, -55, -45];
69
70 var elements = [
71 document.getElementById("d"),
72 document.getElementById("c"),
73 document.getElementById("b"),
74 document.getElementById("a"),
75 document.scrollingElement];
76
77 var scrollableElements = [elements[1], elements[3], elements[4]];
78
79 document.scrollingElement.id = "scrollingElement";
80
81 for (var i = 0; i < elements.length; ++i) {
82 originalApplyScrolls[i] = elements[i].applyScroll;
83 originalDistributeScrolls[i] = elements[i].distributeScroll;
84 }
85
86 function reset() {
87 for (var i = 0; i < elements.length; ++i) {
88 var j = i;
89 elements[i].scrollTop = 0;
90 elements[i].unappliedDeltaY = [];
91 elements[i].distributedDeltaY = [];
92 elements[i].numberOfScrollBegins = 0;
93 elements[i].numberOfScrollEnds = 0;
94
95 elements[i].applyScroll = (function(originalApplyScroll) {
96 return function(scrollState) {
97 originalApplyScroll.call(this, scrollState);
98 if (!scrollState.isEnding && !scrollState.isBeginning)
99 this.unappliedDeltaY.push(scrollState.deltaY);
100 }
101 })(originalApplyScrolls[i]);
102
103 elements[i].distributeScroll = (function(originalDistributeScroll) {
104 return function(scrollState) {
105 if (scrollState.isBeginning)
106 this.numberOfScrollBegins++;
107 else if (scrollState.isEnding)
108 this.numberOfScrollEnds++;
109 else
110 this.distributedDeltaY.push(scrollState.deltaY);
111 originalDistributeScroll.call(this, scrollState);
112 }
113 })(originalDistributeScrolls[i]);
114 }
115 }
116
117 function applyDelta(d) {
118 eventSender.gestureScrollBegin(10, 10);
119 eventSender.gestureScrollUpdate(0, d);
120 eventSender.gestureScrollEnd(0, 0);
121 }
122
123 if ('ScrollState' in window) {
124 test(function() {
125 reset();
126
127 // Scroll five times, with three scrollable elements.
128 var cScrollTop = [85, 100, 100, 100, 100];
129 var aScrollTop = [0, 0, 65, 100, 100];
130 var scrollingElementScrollTop = [0, 0, 0, 0, 45];
131
132 for (var i = 0; i < deltas.length; ++i) {
133 applyDelta(deltas[i]);
134 assert_equals(a.scrollTop, aScrollTop[i], "For id 'a' on step " + i);
135 assert_equals(c.scrollTop, cScrollTop[i], "For id 'c' on step " + i);
136 assert_equals(document.scrollingElement.scrollTop, scrollingElementScrollT op[i], "For scrollingElement on step " + i);
137 }
138 }, "Scroll offsets are modified correctly.");
139
140 test(function() {
141 reset();
142
143 // Scroll five times, with five elements.
144 var unapplied = [
145 // d, the innermost element, never applies any scroll.
146 [-85, -75, -65, -55, -45],
147 // c applies the first two scrolls, and then hits its scroll extents.
148 [0, 0, -65, -55, -45],
149 // b doesn't scroll, and so leaves the same deltas unapplied as c.
150 [0, 0, -65, -55, -45],
151 // a hits its scroll extent on the second last step.
152 [0, 0, 0, 0, -45],
153 // The scrollingElement performs the frame scroll.
154 [0, 0, 0, 0, 0]];
155
156 for (var i = 0; i < deltas.length; ++i)
157 applyDelta(deltas[i]);
158
159 for (var i = 0; i < elements.length; ++i) {
160 var el = elements[i];
161 // Every element sees the same deltas being distributed.
162 assert_array_equals(el.distributedDeltaY, deltas, "distributed delta for " + el.id);
163 assert_array_equals(el.unappliedDeltaY, unapplied[i], "unapplied delta for " + el.id);
164 }
165
166 // Ensure that the document leaves scroll unapplied when appropriate.
167 var documentUnapplied = document.scrollingElement.unappliedDeltaY;
168 applyDelta(-4000);
169 assert_equals(documentUnapplied[documentUnapplied.length - 1], 0);
170 applyDelta(-4000);
171 assert_equals(documentUnapplied[documentUnapplied.length - 1], -4000);
172 }, "Correct amount of delta is consumed.");
173
174 test(function() {
175 reset();
176 // Consume one pixel of delta per call to applyScroll.
177 for (var i = 0; i < elements.length; ++i) {
178 if (scrollableElements.indexOf(elements[i]) == -1)
179 continue;
180 elements[i].applyScroll = (function(originalApplyScroll) {
181 return function(scrollState) {
182 if (scrollState.deltaY !== 0)
183 scrollState.consumeDelta(0, -1);
184 originalApplyScroll.call(this, scrollState);
185 }
186 })(originalApplyScrolls[i]);
187 }
188 // Scroll five times, with three scrollable elements.
189 // The scroll distance is decreased more the higher up the scroll chain the element is.
190 var cScrollTop = [85 - 1, 100, 100, 100, 100];
191 var aScrollTop = [0, 0, 65 - 2, 100, 100];
192 var scrollingElementScrollTop = [0, 0, 0, 0, 45 - 3];
193
194 for (var i = 0; i < deltas.length; ++i) {
195 applyDelta(deltas[i]);
196 assert_equals(c.scrollTop, cScrollTop[i], "For id 'c' on step " + i);
197 assert_equals(a.scrollTop, aScrollTop[i], "For id 'a' on step " + i);
198 assert_equals(document.scrollingElement.scrollTop, scrollingElementScrollT op[i], "For scrollingElement on step " + i);
199 }
200 }, "Consuming deltas prevents scrolling.");
201
202 test(function() {
203 reset();
204
205 for (var i = 0; i < deltas.length; ++i)
206 applyDelta(deltas[i]);
207 for (var i = 0; i < elements.length; ++i) {
208 assert_equals(elements[i].numberOfScrollBegins, deltas.length, "Incorrect number of begin events for " + elements[i].id);
209 assert_equals(elements[i].numberOfScrollEnds, deltas.length, "Incorrect nu mber of end events for " + elements[i].id);
210 }
211 }, "Correct number of scroll end and begin events observed.");
212
213 test(function() {
214 // toPerform is an array of length 4, specifying whether to
215 // perform method |original| on |element| for scroll begin, first
216 // update, second update and scroll end.
217 function performSomeOf(element, original, toPerform) {
218 var updateCount = 0;
219 return function(scrollState) {
220 if (scrollState.isBeginning && scrollState.isEnding)
221 throw "performSomeOf requires that the scroll not both begin and end";
222
223 var isUpdate = !scrollState.isBeginning && !scrollState.isEnding;
224
225 if ((scrollState.isBeginning && toPerform[0]) ||
226 (scrollState.isEnding && toPerform[3]) ||
227 (isUpdate && updateCount === 0 && toPerform[1]) ||
228 (isUpdate && updateCount > 0 && toPerform[2])) {
229 original.call(element, scrollState);
230 }
231
232 if (isUpdate)
233 updateCount++;
234 };
235 }
236
237 // Generates an array of all arrays of booleans of length n.
238 // e.g. genPermutations(2) =>
239 // [[true, true], [true, false], [false, true], [false, false]].
240 function genPermutations(n) {
241 if (n === 0)
242 return [[]];
243 var perms = genPermutations(n - 1);
244 return perms.map(function(x) {
245 return x.concat([true]);
246 }).concat(perms.map(function(x) {
247 return x.concat([false]);
248 }));
249 }
250
251 function applyDeltaWithTwoUpdates(d) {
252 eventSender.gestureScrollBegin(10, 10);
253 eventSender.gestureScrollUpdate(0, d/2);
254 eventSender.gestureScrollUpdate(0, d/2);
255 eventSender.gestureScrollEnd(0, 0);
256 }
257
258 var scroller = document.scrollingElement;
259
260 for (applyScrollPermutation of genPermutations(4)) {
261 reset();
262 scroller.applyScroll = performSomeOf(scroller, scroller.applyScroll, apply ScrollPermutation);
263
264 for (distributeScrollPermutation of genPermutations(4)) {
265 scroller.distributeScroll = performSomeOf(scroller, scroller.distributeS croll, distributeScrollPermutation);
266 applyDeltaWithTwoUpdates(-50);
267 }
268 }
269 }, "Ensure that any subset of the native scroll methods can be called, without crashing");
270
271 {
272 // NOTE - this async test needs to be run last, as it shares state with the
273 // other tests. If other tests are run after it, they'll modify the state
274 // while this test is still running.
275 var flingTest = async_test("Touchscreen fling doesn't propagate.");
276 reset();
277
278 function assertScrollTops(cTop, aTop, scrollingElementTop, step) {
279 assert_equals(c.scrollTop, cTop, "For id 'c' on step " + step);
280 assert_equals(a.scrollTop, aTop, "For id 'a' on step " + step);
281 assert_equals(document.scrollingElement.scrollTop, scrollingElementTop, "F or scrollingElement on step " + step);
282 };
283
284 var frame_actions = [
285 function() {
286 eventSender.gestureFlingStart(10, 10, -1000000, -1000000, "touchscreen") ;
287 },
288 flingTest.step_func(function() {
289 assertScrollTops(0, 0, 0, 1);
290 }),
291 flingTest.step_func(function() {
292 assertScrollTops(100, 0, 0, 2);
293 }),
294 flingTest.step_func(function() {
295 assertScrollTops(100, 0, 0, 3);
296 }),
297 flingTest.step_func(function() {
298 assertScrollTops(100, 0, 0, 4);
299 flingTest.done();
300 })
301 ]
302
303 function executeFrameActions(frame_actions) {
304 var frame = 0;
305 function raf() {
306 frame_actions[frame]();
307 frame++;
308 if (frame >= frame_actions.length)
309 return;
310 window.requestAnimationFrame(raf);
311 }
312 window.requestAnimationFrame(raf);
313 }
314
315 executeFrameActions(frame_actions);
316 }
317 }
318
319 </script>
320 </body>
321 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698