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

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

Issue 850443002: Scroll Customization Prototype (Not for review, WIP) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase / cleanup / minor bug fixes Created 5 years, 9 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>ScrollState constructor behaves correctly</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
63 if (!window.internals || !window.internals.runtimeFlags.scrollCustomizationEnabl ed || !window.eventSender) {
64 console.log("These tests only work with window.internals and " +
65 "window.eventSender exposed, and require scroll customization.");
66 done();
67 }
68
69 var originalApplyScroll = Element.prototype.applyScroll;
70 var originalDistributeScroll = Element.prototype.distributeScroll;
71 var deltas = [-85, -75, -65, -55, -45];
72
73 var elements = [
74 document.getElementById("d"),
75 document.getElementById("c"),
76 document.getElementById("b"),
77 document.getElementById("a"),
78 document.body,
79 document.documentElement];
80
81 document.body.id = "body";
82 document.documentElement.id = "document";
83
84 function reset() {
85 for (var i = 0; i < elements.length; ++i) {
86 elements[i].scrollTop = 0;
87 elements[i].unappliedDeltaY = [];
88 elements[i].distributedDeltaY = [];
89 elements[i].numberOfScrollEnds = 0;
90 }
91
92 Element.prototype.applyScroll = function(scrollState) {
93 originalApplyScroll.call(this, scrollState);
94 if (!scrollState.isEnding)
95 this.unappliedDeltaY.push(scrollState.deltaY);
96 }
97
98 Element.prototype.distributeScroll = function(scrollState) {
99 if (!scrollState.isEnding)
100 this.distributedDeltaY.push(scrollState.deltaY);
101 else
102 this.numberOfScrollEnds++;
103 originalDistributeScroll.call(this, scrollState);
104 }
105 }
106
107 function applyDelta(d) {
108 eventSender.gestureScrollBegin(10, 10);
109 eventSender.gestureScrollUpdate(0, d);
110 eventSender.gestureScrollEnd(0, 0);
111 }
112
113 test(function() {
114 reset();
115
116 // Scroll five times, with four scrollable elements.
117 var cScrollTop = [85, 100, 100, 100, 100];
118 var aScrollTop = [0, 0, 65, 100, 100];
119 var bodyScrollTop = [0, 0, 0, 0, 45];
120
121 for (var i = 0; i < deltas.length; ++i) {
122 applyDelta(deltas[i]);
123 assert_equals(a.scrollTop, aScrollTop[i], "For id 'a' on step " + i);
124 assert_equals(c.scrollTop, cScrollTop[i], "For id 'c' on step " + i);
125 assert_equals(document.body.scrollTop, bodyScrollTop[i], "For body on step " + i);
126 }
127 }, "Scroll offsets are modified correctly.");
128
129 test(function() {
130 reset();
131
132 // Scroll five times, with six elements.
133 var unapplied = [
134 // d, the innermost element, never applies any scroll.
135 [-85, -75, -65, -55, -45],
136 // c applies the first two scrolls, and then hits its scroll extents.
137 [0, 0, -65, -55, -45],
138 // b doesn't scroll, and so leaves the same deltas unapplied as c.
139 [0, 0, -65, -55, -45],
140 // a hits its scroll extent on the second last step.
141 [0, 0, 0, 0, -45],
142 // body doesn't scroll (it's the documentElement that scrolls, but the body' s
143 // scrollTop updates), and so leaves the same deltas unapplied as a.
144 [0, 0, 0, 0, -45],
145 // The documentElement performs the frame scroll.
146 [0, 0, 0, 0, 0]];
147
148 for (var i = 0; i < deltas.length; ++i)
149 applyDelta(deltas[i]);
150
151 for (var i = 0; i < elements.length; ++i) {
152 var el = elements[i];
153 // Every element sees the same deltas being distributed.
154 assert_array_equals(el.distributedDeltaY, deltas, "distributed delta for " + el.id);
155 assert_array_equals(el.unappliedDeltaY, unapplied[i], "unapplied delta for " + el.id);
156 }
157
158 // Ensure that the document leaves scroll unapplied when appropriate.
159 var documentUnapplied = document.documentElement.unappliedDeltaY;
160 applyDelta(-4000);
161 assert_equals(documentUnapplied[documentUnapplied.length - 1], 0);
162 applyDelta(-4000);
163 assert_equals(documentUnapplied[documentUnapplied.length - 1], -4000);
164 }, "Correct amount of delta is consumed.");
165
166 test(function() {
167 reset();
168
169 // Consume one pixel of delta per call to applyScroll.
170 var applyScroll = Element.prototype.applyScroll;
171 Element.prototype.applyScroll = function(scrollState) {
172 if (scrollState.deltaY !== 0)
173 scrollState.consumeDelta(0, -1);
174 applyScroll.call(this, scrollState);
175 }
176
177 // Scroll five times, with four scrollable elements.
178 // The scroll distance is decreased more the higher up the scroll chain the el ement is.
179 var cScrollTop = [85 - 2, 100, 100, 100, 100];
180 var aScrollTop = [0, 0, 65 - 4, 100, 100];
181 var bodyScrollTop = [0, 0, 0, 0, 45 - 6];
182
183 for (var i = 0; i < deltas.length; ++i) {
184 applyDelta(deltas[i]);
185 assert_equals(c.scrollTop, cScrollTop[i], "For id 'c' on step " + i);
186 assert_equals(a.scrollTop, aScrollTop[i], "For id 'a' on step " + i);
187 assert_equals(document.body.scrollTop, bodyScrollTop[i], "For body on step " + i);
188 }
189 }, "Consuming deltas prevents scrolling.");
190
191 test(function() {
192 reset();
193
194 for (var i = 0; i < deltas.length; ++i)
195 applyDelta(deltas[i]);
196
197 for (var i = 0; i < elements.length; ++i)
198 assert_equals(elements[i].numberOfScrollEnds, deltas.length);
199 }, "Correct number of scroll ends observed.");
200
201 {
202 var flingTest = async_test("Touchscreen fling doesn't propagate.");
203 reset();
204
205 function assertScrollTops(cTop, aTop, bodyTop, step) {
206 assert_equals(c.scrollTop, cTop, "For id 'c' on step " + step);
207 assert_equals(a.scrollTop, aTop, "For id 'a' on step " + step);
208 assert_equals(document.body.scrollTop, bodyTop, "For body on step " + step);
209 };
210
211 var frame_actions = [
212 function() {
213 eventSender.gestureFlingStart(10, 10, -1000000, -1000000, "touchscreen");
214 },
215 flingTest.step_func(function() {
216 assertScrollTops(0, 0, 0, 1);
217 }),
218 flingTest.step_func(function() {
219 assertScrollTops(100, 0, 0, 2);
220 }),
221 flingTest.step_func(function() {
222 assertScrollTops(100, 0, 0, 3);
223 }),
224 flingTest.step_func(function() {
225 assertScrollTops(100, 0, 0, 4);
226 flingTest.done();
227 })
228 ]
229
230 function executeFrameActions(frame_actions) {
231 var frame = 0;
232 function raf() {
233 frame_actions[frame]();
234 if (frame >= frame_actions.length)
235 return;
236 frame++;
237 window.requestAnimationFrame(raf);
238 }
239 window.requestAnimationFrame(raf);
240 }
241
242 executeFrameActions(frame_actions);
243 }
244 </script>
245 </body>
246 </html>
OLDNEW
« no previous file with comments | « LayoutTests/fast/scroll-behavior/scroll-customization/scrollstate-simple.html ('k') | Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698