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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollAnimatorTest.cpp

Issue 1534813004: Run smooth scroll animations on the compositor when possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years 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
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 MOCK_METHOD2(setScrollOffset, void(const IntPoint&, ScrollType)); 66 MOCK_METHOD2(setScrollOffset, void(const IntPoint&, ScrollType));
67 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); 67 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void());
68 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); 68 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*());
69 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); 69 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint());
70 MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint()); 70 MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint());
71 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); 71 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect));
72 MOCK_CONST_METHOD0(contentsSize, IntSize()); 72 MOCK_CONST_METHOD0(contentsSize, IntSize());
73 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); 73 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool());
74 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); 74 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect());
75 MOCK_METHOD0(registerForAnimation, void()); 75 MOCK_METHOD0(registerForAnimation, void());
76 MOCK_METHOD0(scheduleAnimation, bool());
76 77
77 bool userInputScrollable(ScrollbarOrientation) const override { return true; } 78 bool userInputScrollable(ScrollbarOrientation) const override { return true; }
78 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } 79 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; }
79 IntPoint scrollPosition() const override { return IntPoint(); } 80 IntPoint scrollPosition() const override { return IntPoint(); }
80 int visibleHeight() const override { return 768; } 81 int visibleHeight() const override { return 768; }
81 int visibleWidth() const override { return 1024; } 82 int visibleWidth() const override { return 1024; }
82 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled ; } 83 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled ; }
83 int pageStep(ScrollbarOrientation) const override { return 0; } 84 int pageStep(ScrollbarOrientation) const override { return 0; }
84 85
85 DEFINE_INLINE_VIRTUAL_TRACE() 86 DEFINE_INLINE_VIRTUAL_TRACE()
86 { 87 {
87 ScrollableArea::trace(visitor); 88 ScrollableArea::trace(visitor);
88 } 89 }
89 90
90 private: 91 private:
91 explicit MockScrollableArea(bool scrollAnimatorEnabled) 92 explicit MockScrollableArea(bool scrollAnimatorEnabled)
92 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } 93 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { }
93 94
94 bool m_scrollAnimatorEnabled; 95 bool m_scrollAnimatorEnabled;
95 }; 96 };
96 97
97 } // namespace 98 } // namespace
98 99
99 static void reset(ScrollAnimator& scrollAnimator) 100 static void reset(ScrollAnimator& scrollAnimator)
100 { 101 {
101 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); 102 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint());
102 } 103 }
103 104
104 TEST(ScrollAnimatorTest, Enabled) 105 TEST(ScrollAnimatorTest, MainThreadEnabled)
105 { 106 {
106 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(true); 107 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(true);
107 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime)); 108 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime));
108 109
109 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 110 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint()));
110 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000))); 111 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
111 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(12); 112 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9);
112 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); 113 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
114 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)).WillRepe atedly(Return(true));
113 115
114 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); 116 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
115 117
116 ScrollResultOneDimensional result = scrollAnimator->userScroll(HorizontalScr ollbar, ScrollByLine, 100, -1); 118 ScrollResultOneDimensional result = scrollAnimator->userScroll(HorizontalScr ollbar, ScrollByLine, 100, -1);
117 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); 119 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
118 EXPECT_FALSE(result.didScroll); 120 EXPECT_FALSE(result.didScroll);
119 EXPECT_FLOAT_EQ(-1.0f, result.unusedScrollDelta); 121 EXPECT_FLOAT_EQ(-1.0f, result.unusedScrollDelta);
120 122
121 result = scrollAnimator->userScroll(HorizontalScrollbar, ScrollByLine, 100, 1); 123 result = scrollAnimator->userScroll(HorizontalScrollbar, ScrollByLine, 100, 1);
122 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); 124 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService());
123 EXPECT_TRUE(result.didScroll); 125 EXPECT_TRUE(result.didScroll);
124 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDelta); 126 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDelta);
125 127
126 gMockedTime += 0.05; 128 gMockedTime += 0.05;
127 scrollAnimator->serviceScrollAnimations(); 129 scrollAnimator->updateCompositorAnimations();
130 scrollAnimator->tickAnimation(getMockedTime());
128 131
129 EXPECT_NE(100, scrollAnimator->currentPosition().x()); 132 EXPECT_NE(100, scrollAnimator->currentPosition().x());
130 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 133 EXPECT_NE(0, scrollAnimator->currentPosition().x());
131 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 134 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
132 reset(*scrollAnimator); 135 reset(*scrollAnimator);
133 136
134 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPage, 100, 1); 137 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPage, 100, 1);
135 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); 138 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService());
136 139
137 gMockedTime += 0.05; 140 gMockedTime += 0.05;
138 scrollAnimator->serviceScrollAnimations(); 141 scrollAnimator->updateCompositorAnimations();
142 scrollAnimator->tickAnimation(getMockedTime());
139 143
140 EXPECT_NE(100, scrollAnimator->currentPosition().x()); 144 EXPECT_NE(100, scrollAnimator->currentPosition().x());
141 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 145 EXPECT_NE(0, scrollAnimator->currentPosition().x());
142 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 146 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
143 reset(*scrollAnimator); 147 reset(*scrollAnimator);
144 148
145 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 4, 25); 149 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 4, 25);
146 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); 150 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService());
147 151
148 gMockedTime += 0.05; 152 gMockedTime += 0.05;
149 scrollAnimator->serviceScrollAnimations(); 153 scrollAnimator->updateCompositorAnimations();
154 scrollAnimator->tickAnimation(getMockedTime());
150 155
151 EXPECT_NE(100, scrollAnimator->currentPosition().x()); 156 EXPECT_NE(100, scrollAnimator->currentPosition().x());
152 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 157 EXPECT_NE(0, scrollAnimator->currentPosition().x());
153 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 158 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
154 159
155 gMockedTime += 1.0; 160 gMockedTime += 1.0;
156 scrollAnimator->serviceScrollAnimations(); 161 scrollAnimator->updateCompositorAnimations();
162 scrollAnimator->tickAnimation(getMockedTime());
157 163
158 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); 164 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
159 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 165 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
160 166
161 reset(*scrollAnimator); 167 reset(*scrollAnimator);
162 168
163 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPrecisePixel, 4, 25) ; 169 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPrecisePixel, 4, 25) ;
164 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); 170 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
165 171
166 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 172 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
167 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 173 EXPECT_NE(0, scrollAnimator->currentPosition().x());
168 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 174 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
169 reset(*scrollAnimator); 175 reset(*scrollAnimator);
170 } 176 }
171 177
172 TEST(ScrollAnimatorTest, Disabled) 178 TEST(ScrollAnimatorTest, Disabled)
173 { 179 {
174 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false); 180 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false);
(...skipping 19 matching lines...) Expand all
194 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 200 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
195 reset(*scrollAnimator); 201 reset(*scrollAnimator);
196 202
197 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 100, 1); 203 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 100, 1);
198 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 204 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
199 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 205 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
200 reset(*scrollAnimator); 206 reset(*scrollAnimator);
201 } 207 }
202 208
203 } // namespace blink 209 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698