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

Unified Diff: third_party/WebKit/Source/platform/scroll/ScrollAnimatorTest.cpp

Issue 1842623003: Correctly reset ScrollAnimator animation state after cancelling animation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollAnimatorCompositorCoordinator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/scroll/ScrollAnimatorTest.cpp
diff --git a/third_party/WebKit/Source/platform/scroll/ScrollAnimatorTest.cpp b/third_party/WebKit/Source/platform/scroll/ScrollAnimatorTest.cpp
index 32fd13f8eb9b9c6c663977262d79368f6f12b608..fd8195010b68b6c992c6852caa68dd033c316674 100644
--- a/third_party/WebKit/Source/platform/scroll/ScrollAnimatorTest.cpp
+++ b/third_party/WebKit/Source/platform/scroll/ScrollAnimatorTest.cpp
@@ -389,4 +389,67 @@ TEST(ScrollAnimatorTest, Disabled)
reset(*scrollAnimator);
}
+// Test that cancelling an animation resets the animation state.
+// See crbug.com/598548.
+TEST(ScrollAnimatorTest, CancellingAnimationResetsState)
+{
+ OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea =
+ MockScrollableArea::create(true);
+ OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(
+ new ScrollAnimator(scrollableArea.get(), getMockedTime));
+
+ EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
+ .WillRepeatedly(Return(IntPoint()));
+ EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
+ .WillRepeatedly(Return(IntPoint(1000, 1000)));
+ // Called from first userScroll, setCurrentPosition, and second userScroll.
+ EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3);
+ // Called from userScroll, updateCompositorAnimations.
+ EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4);
+ EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
+ .WillRepeatedly(Return(true));
+
+ EXPECT_EQ(0, scrollAnimator->currentPosition().x());
+ EXPECT_EQ(0, scrollAnimator->currentPosition().y());
+
+ // WaitingToSendToCompositor
+ scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0));
+ EXPECT_EQ(scrollAnimator->m_runState,
+ ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor);
+
+ // RunningOnMainThread
+ gMockedTime += 0.05;
+ scrollAnimator->updateCompositorAnimations();
+ EXPECT_EQ(scrollAnimator->m_runState,
+ ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread);
+ scrollAnimator->tickAnimation(getMockedTime());
+ EXPECT_EQ(scrollAnimator->m_runState,
+ ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread);
+
+ // Amount scrolled so far.
+ float offsetX = scrollAnimator->currentPosition().x();
+
+ // Interrupt user scroll.
+ scrollAnimator->cancelAnimation();
+ EXPECT_EQ(scrollAnimator->m_runState,
+ ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup);
+
+ // Another userScroll after modified scroll offset.
+ scrollAnimator->setCurrentPosition(FloatPoint(offsetX + 15, 0));
+ scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0));
+ EXPECT_EQ(scrollAnimator->m_runState,
+ ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor);
+
+ // Finish scroll animation.
+ gMockedTime += 1.0;
+ scrollAnimator->updateCompositorAnimations();
+ scrollAnimator->tickAnimation(getMockedTime());
+ EXPECT_EQ(scrollAnimator->m_runState,
+ ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup);
+
+ EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x());
+ EXPECT_EQ(0, scrollAnimator->currentPosition().y());
+ reset(*scrollAnimator);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollAnimatorCompositorCoordinator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698