5 <title>Scroll customization methods are called appropriately.
</title>
6 <script src=
"../../../resources/testharness.js"></script>
7 <script src=
"../../../resources/testharnessreport.js"></script>
15 *::-webkit-scrollbar {
29 background-color:purple;
41 background-color:green;
63 assert_true('ScrollState' in window
, "'ScrollState' in window");
64 }, "These tests only work with scroll customization enabled.");
66 internals
.settings
.setScrollAnimatorEnabled(false);
68 var originalApplyScrolls
= [];
69 var originalDistributeScrolls
= [];
70 var deltas
= [-85, -75, -65, -55, -45];
73 document
.getElementById("d"),
74 document
.getElementById("c"),
75 document
.getElementById("b"),
76 document
.getElementById("a"),
77 document
.scrollingElement
];
79 var scrollableElements
= [elements
[1], elements
[3], elements
[4]];
81 document
.scrollingElement
.id
= "scrollingElement";
84 for (var i
= 0; i
< elements
.length
; ++i
) {
85 elements
[i
].scrollTop
= 0;
86 elements
[i
].unappliedDeltaY
= [];
87 elements
[i
].distributedDeltaY
= [];
88 elements
[i
].numberOfScrollBegins
= 0;
89 elements
[i
].numberOfScrollEnds
= 0;
91 elements
[i
].setApplyScroll((function(scrollState
){
92 if (!scrollState
.isEnding
&& !scrollState
.isBeginning
)
93 this.unappliedDeltaY
.push(scrollState
.deltaY
);
94 }).bind(elements
[i
]), "perform-after-native-scroll");
96 elements
[i
].setDistributeScroll((function(scrollState
) {
97 if (scrollState
.isBeginning
)
98 this.numberOfScrollBegins
++;
99 else if (scrollState
.isEnding
)
100 this.numberOfScrollEnds
++;
102 this.distributedDeltaY
.push(scrollState
.deltaY
);
103 }).bind(elements
[i
]), "perform-before-native-scroll");
105 // Add a gc, to ensure that these callbacks don't get collected.
110 function applyDelta(d
) {
111 eventSender
.gestureScrollBegin(10, 10);
112 eventSender
.gestureScrollUpdate(0, d
);
113 eventSender
.gestureScrollEnd(0, 0);
116 if ('ScrollState' in window
) {
120 // Scroll five times, with three scrollable elements.
121 var cScrollTop
= [85, 100, 100, 100, 100];
122 var aScrollTop
= [0, 0, 65, 100, 100];
123 var scrollingElementScrollTop
= [0, 0, 0, 0, 45];
125 for (var i
= 0; i
< deltas
.length
; ++i
) {
126 applyDelta(deltas
[i
]);
127 assert_equals(a
.scrollTop
, aScrollTop
[i
], "For id 'a' on step " + i
);
128 assert_equals(c
.scrollTop
, cScrollTop
[i
], "For id 'c' on step " + i
);
129 assert_equals(document
.scrollingElement
.scrollTop
, scrollingElementScrollTop
[i
], "For scrollingElement on step " + i
);
131 }, "Scroll offsets are modified correctly.");
136 // Scroll five times, with five elements.
138 // d, the innermost element, never applies any scroll.
139 [-85, -75, -65, -55, -45],
140 // c applies the first two scrolls, and then hits its scroll extents.
141 [0, 0, -65, -55, -45],
142 // b doesn't scroll, and so leaves the same deltas unapplied as c.
143 [0, 0, -65, -55, -45],
144 // a hits its scroll extent on the second last step.
146 // The scrollingElement performs the frame scroll.
149 for (var i
= 0; i
< deltas
.length
; ++i
)
150 applyDelta(deltas
[i
]);
152 for (var i
= 0; i
< elements
.length
; ++i
) {
153 var el
= elements
[i
];
154 // Every element sees the same deltas being distributed.
155 assert_array_equals(el
.distributedDeltaY
, deltas
, "distributed delta for " + el
.id
+ ":");
156 assert_array_equals(el
.unappliedDeltaY
, unapplied
[i
], "unapplied delta for " + el
.id
+ ":");
159 // Ensure that the document leaves scroll unapplied when appropriate.
160 var documentUnapplied
= document
.scrollingElement
.unappliedDeltaY
;
162 assert_equals(documentUnapplied
[documentUnapplied
.length
- 1], 0);
164 assert_equals(documentUnapplied
[documentUnapplied
.length
- 1], -4000);
165 }, "Correct amount of delta is consumed.");
170 // Consume one pixel of delta per call to applyScroll.
171 for (var i
= 0; i
< elements
.length
; ++i
) {
172 if (scrollableElements
.indexOf(elements
[i
]) == -1)
174 elements
[i
].setApplyScroll((function(scrollState
) {
175 if (scrollState
.deltaY
!== 0)
176 scrollState
.consumeDelta(0, -1);
177 }).bind(elements
[i
]), "perform-before-native-scroll");
180 // Scroll five times, with three scrollable elements.
181 // The scroll distance is decreased more the higher up the scroll chain the element is.
182 var cScrollTop
= [85 - 1, 100, 100, 100, 100];
183 var aScrollTop
= [0, 0, 65 - 2, 100, 100];
184 var scrollingElementScrollTop
= [0, 0, 0, 0, 45 - 3];
185 for (var i
= 0; i
< deltas
.length
; ++i
) {
186 applyDelta(deltas
[i
]);
187 assert_equals(c
.scrollTop
, cScrollTop
[i
], "For id 'c' on step " + i
);
188 assert_equals(a
.scrollTop
, aScrollTop
[i
], "For id 'a' on step " + i
);
189 assert_equals(document
.scrollingElement
.scrollTop
, scrollingElementScrollTop
[i
], "For scrollingElement on step " + i
);
191 }, "Consuming deltas prevents scrolling.");
196 for (var i
= 0; i
< deltas
.length
; ++i
)
197 applyDelta(deltas
[i
]);
199 for (var i
= 0; i
< elements
.length
; ++i
) {
200 assert_equals(elements
[i
].numberOfScrollBegins
, deltas
.length
, "Incorrect number of begin events for " + elements
[i
].id
);
201 assert_equals(elements
[i
].numberOfScrollEnds
, deltas
.length
, "Incorrect number of end events for " + elements
[i
].id
);
203 }, "Correct number of scroll end and begin events observed.");
206 // NOTE - this async test needs to be run last, as it shares state with the
207 // other tests. If other tests are run after it, they'll modify the state
208 // while this test is still running.
209 var flingTest
= async_test("Touchscreen fling doesn't propagate.");
212 function assertScrollTops(cTop
, aTop
, scrollingElementTop
, step
) {
213 assert_equals(c
.scrollTop
, cTop
, "For id 'c' on step " + step
);
214 assert_equals(a
.scrollTop
, aTop
, "For id 'a' on step " + step
);
215 assert_equals(document
.scrollingElement
.scrollTop
, scrollingElementTop
, "For scrollingElement on step " + step
);
218 var frame_actions
= [
220 eventSender
.gestureFlingStart(10, 10, -1000000, -1000000, "touchscreen");
222 flingTest
.step_func(function() {
223 assertScrollTops(0, 0, 0, 1);
225 flingTest
.step_func(function() {
226 assertScrollTops(100, 0, 0, 2);
228 flingTest
.step_func(function() {
229 assertScrollTops(100, 0, 0, 3);
231 flingTest
.step_func(function() {
232 assertScrollTops(100, 0, 0, 4);
237 function executeFrameActions(frame_actions
) {
240 frame_actions
[frame
]();
242 if (frame
>= frame_actions
.length
)
244 window
.requestAnimationFrame(raf
);
246 window
.requestAnimationFrame(raf
);
249 executeFrameActions(frame_actions
);