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

Unified Diff: LayoutTests/fast/scroll-behavior/resources/scroll-interruption-test.js

Issue 134443003: Implement CSSOM Smooth Scroll API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/scroll-behavior/resources/scroll-interruption-test.js
diff --git a/LayoutTests/fast/scroll-behavior/resources/scroll-interruption-test.js b/LayoutTests/fast/scroll-behavior/resources/scroll-interruption-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..73b48f93698b2b1fe4c2077a018b0b716b9a5ef7
--- /dev/null
+++ b/LayoutTests/fast/scroll-behavior/resources/scroll-interruption-test.js
@@ -0,0 +1,196 @@
+(function() {
+ var instantTest = async_test('interrupt with instant scroll');
+ var smoothTest = async_test('interrupt with smooth scroll');
+ var touchTest = async_test('interrupt with touch scroll');
+ var wheelTest = async_test('interrupt with mouse wheel');
+ var testElement;
+ var testCase;
+ var testInnerPoint;
+ var previousScrollTop;
+ var previousTimestamp;
+
+
+ function verifyScrollOffsetUnchangedAfterInstantScroll()
+ {
+ instantTest.step(function() {
+ assert_equals(testElement.scrollTop, testCase.y3);
Ian Vollick 2014/02/06 16:02:31 I don't like the assumptions about the contents of
+ });
+ instantTest.done();
+ window.requestAnimationFrame(startSmoothTest);
+ }
+
+ function verifyProgressTowardsNewDestination()
+ {
+ var previousDelta = testCase.y3 - previousScrollTop;
+ var currentDelta = testCase.y3 - testElement.scrollTop;
+ if (Math.abs(currentDelta) < Math.abs(previousDelta)) {
+ smoothTest.done();
+ window.requestAnimationFrame(startTouchTest);
+ return;
+ }
+ previousScrollTop = testElement.scrollTop;
+ window.requestAnimationFrame(verifyProgressTowardsNewDestination);
+ }
+
+ function verifyScrollOffsetStopsChangingAfterTouchScroll(timestamp)
+ {
+ if (previousScrollTop == testElement.scrollTop) {
+ // Ensure that the animation has really stopped, not that we just have
+ // two frames that are so close together that the animation only seems to
+ // have stopped.
+ if (timestamp - previousTimestamp > 16) {
+ touchTest.done();
+ window.requestAnimationFrame(startWheelTest);
+ } else {
+ window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterTouchScroll);
+ }
+ return;
+ }
+
+ previousTimestamp = timestamp;
+ previousScrollTop = testElement.scrollTop;
+ touchTest.step(function() {
+ assert_not_equals(previousScrollTop, testCase.y2);
+ });
+ window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterTouchScroll);
+ }
+
+ function verifyScrollOffsetStopsChangingAfterWheelScroll(timestamp)
+ {
+ if (previousScrollTop == testElement.scrollTop) {
+ // Ensure that the animation has really stopped, not that we just have
+ // two frames that are so close together that the animation only seems to
+ // have stopped.
+ if (timestamp - previousTimestamp > 16) {
+ wheelTest.done();
+ } else {
+ window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterWheelScroll);
+ }
+ return;
+ }
+
+ previousTimestamp = timestamp;
+ previousScrollTop = testElement.scrollTop;
+ wheelTest.step(function() {
+ assert_not_equals(previousScrollTop, testCase.y2);
+ });
+ window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterWheelScroll);
+ }
+
+ function interruptWithInstantScroll()
+ {
+ if (testElement.scrollTop == testCase.y1) {
+ window.requestAnimationFrame(interruptWithInstantScroll);
+ return;
+ }
+
+ instantlyScrollTo(testCase.y3);
+ instantTest.step(function() {
+ assert_equals(testElement.scrollTop, testCase.y3);
+ });
+ window.requestAnimationFrame(verifyScrollOffsetUnchangedAfterInstantScroll);
+ }
+
+ function interruptWithSmoothScroll()
+ {
+ if (testElement.scrollTop == testCase.y1) {
+ window.requestAnimationFrame(interruptWithSmoothScroll);
+ return;
+ }
+
+ previousScrollTop = testElement.scrollTop;
+ smoothlyScrollTo(testCase.y3);
+ smoothTest.step(function() {
+ assert_equals(testElement.scrollTop, previousScrollTop);
+ });
+ window.requestAnimationFrame(verifyProgressTowardsNewDestination);
+ }
+
+ function interruptWithTouchScroll(timestamp)
+ {
+ if (testElement.scrollTop == testCase.y1) {
+ window.requestAnimationFrame(interruptWithTouchScroll);
+ return;
+ }
+
+ previousScrollTop = testElement.scrollTop;
+ previousTimestamp = timestamp;
+ if (window.eventSender) {
+ eventSender.gestureScrollBegin(testInnerPoint.x, testInnerPoint.y);
+ eventSender.gestureScrollUpdate(0, -10);
+ eventSender.gestureScrollEnd(0, 0);
+ } else {
+ document.write("This test does not work in manual mode.");
+ }
+
+ window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterTouchScroll);
+ }
+
+ function interruptWithWheelScroll(timestamp)
+ {
+ if (testElement.scrollTop == testCase.y1) {
+ window.requestAnimationFrame(interruptWithWheelScroll);
+ return;
+ }
+
+ previousScrollTop = testElement.scrollTop;
+ previousTimestamp = timestamp;
+ if (window.eventSender) {
+ eventSender.mouseMoveTo(testInnerPoint.x, testInnerPoint.y);
+ eventSender.mouseScrollBy(0, -10);
+ } else {
+ document.write("This test does not work in manual mode.");
+ }
+
+ window.requestAnimationFrame(verifyScrollOffsetStopsChangingAfterWheelScroll);
+ }
+
+ function smoothlyScrollTo(y)
+ {
+ testElement.style.scrollBehavior = "smooth";
+ testElement.scrollTop = y;
+ }
+
+ function instantlyScrollTo(y)
+ {
+ testElement.style.scrollBehavior = "instant";
+ testElement.scrollTop = y;
+ }
+
+ function startInstantTest()
+ {
+ instantlyScrollTo(testCase.y1);
+ smoothlyScrollTo(testCase.y2);
+ window.requestAnimationFrame(interruptWithInstantScroll);
+ }
+
+ function startSmoothTest()
+ {
+ instantlyScrollTo(testCase.y1);
+ smoothlyScrollTo(testCase.y2);
+ window.requestAnimationFrame(interruptWithSmoothScroll);
+ }
+
+ function startTouchTest()
+ {
+ instantlyScrollTo(testCase.y1);
+ smoothlyScrollTo(testCase.y2);
+ window.requestAnimationFrame(interruptWithTouchScroll);
+ }
+
+ function startWheelTest()
+ {
+ instantlyScrollTo(testCase.y1);
+ smoothlyScrollTo(testCase.y2);
+ window.requestAnimationFrame(interruptWithWheelScroll);
+ }
+
+ runScrollInterruptionTests = function runScrollInterruptionTests(element,
Ian Vollick 2014/02/06 16:02:31 Does this function need to be named?
+ scrolls,
+ innerPoint) {
+ testElement = element;
+ testCase = scrolls;
+ testInnerPoint = innerPoint;
Ian Vollick 2014/02/06 16:02:31 It's a bit funky that startInstantTest does more t
+ startInstantTest();
+ }
+})();

Powered by Google App Engine
This is Rietveld 408576698