2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // Tests for the ScrollAnimatorNone class.
29 #include "platform/scroll/ScrollAnimatorNone.h"
31 #include "platform/Logging.h"
32 #include "platform/geometry/FloatPoint.h"
33 #include "platform/geometry/IntRect.h"
34 #include "platform/scroll/ScrollAnimator.h"
35 #include "platform/scroll/ScrollableArea.h"
36 #include <gmock/gmock.h>
37 #include <gtest/gtest.h>
41 using testing::AtLeast
;
42 using testing::Return
;
45 class MockScrollableArea
: public NoBaseWillBeGarbageCollectedFinalized
<MockScrollableArea
>, public ScrollableArea
{
46 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea
);
48 static PassOwnPtrWillBeRawPtr
<MockScrollableArea
> create(bool scrollAnimatorEnabled
)
50 return adoptPtrWillBeNoop(new MockScrollableArea(scrollAnimatorEnabled
));
53 MOCK_CONST_METHOD0(isActive
, bool());
54 MOCK_CONST_METHOD1(scrollSize
, int(ScrollbarOrientation
));
55 MOCK_METHOD2(invalidateScrollbar
, void(Scrollbar
*, const IntRect
&));
56 MOCK_CONST_METHOD0(isScrollCornerVisible
, bool());
57 MOCK_CONST_METHOD0(scrollCornerRect
, IntRect());
58 MOCK_METHOD2(setScrollOffset
, void(const IntPoint
&, ScrollType
));
59 MOCK_METHOD2(invalidateScrollbarRect
, void(Scrollbar
*, const IntRect
&));
60 MOCK_METHOD1(invalidateScrollCornerRect
, void(const IntRect
&));
61 MOCK_CONST_METHOD0(enclosingScrollableArea
, ScrollableArea
*());
62 MOCK_CONST_METHOD0(minimumScrollPosition
, IntPoint());
63 MOCK_CONST_METHOD0(maximumScrollPosition
, IntPoint());
64 MOCK_CONST_METHOD1(visibleContentRect
, IntRect(IncludeScrollbarsInRect
));
65 MOCK_CONST_METHOD0(contentsSize
, IntSize());
66 MOCK_CONST_METHOD0(scrollbarsCanBeActive
, bool());
67 MOCK_CONST_METHOD0(scrollableAreaBoundingBox
, IntRect());
69 bool userInputScrollable(ScrollbarOrientation
) const override
{ return true; }
70 bool shouldPlaceVerticalScrollbarOnLeft() const override
{ return false; }
71 IntPoint
scrollPosition() const override
{ return IntPoint(); }
72 int visibleHeight() const override
{ return 768; }
73 int visibleWidth() const override
{ return 1024; }
74 bool scrollAnimatorEnabled() const override
{ return m_scrollAnimatorEnabled
; }
75 int pageStep(ScrollbarOrientation
) const override
{ return 0; }
77 DEFINE_INLINE_VIRTUAL_TRACE()
79 ScrollableArea::trace(visitor
);
83 explicit MockScrollableArea(bool scrollAnimatorEnabled
)
84 : m_scrollAnimatorEnabled(scrollAnimatorEnabled
) { }
86 bool m_scrollAnimatorEnabled
;
89 class MockScrollAnimatorNone
: public ScrollAnimatorNone
{
91 static PassOwnPtr
<MockScrollAnimatorNone
> create(ScrollableArea
* scrollableArea
)
93 return adoptPtr(new MockScrollAnimatorNone(scrollableArea
));
96 float currentX() { return m_currentPosX
; }
97 float currentY() { return m_currentPosY
; }
104 stopAnimationTimerIfNeeded();
107 m_horizontalData
.reset();
108 m_verticalData
.reset();
109 m_fp
= FloatPoint::zero();
113 virtual void fireUpAnAnimation(FloatPoint fp
)
120 explicit MockScrollAnimatorNone(ScrollableArea
* scrollableArea
)
121 : ScrollAnimatorNone(scrollableArea
) { }
125 TEST(ScrollAnimatorEnabled
, Enabled
)
127 OwnPtrWillBeRawPtr
<MockScrollableArea
> scrollableArea
= MockScrollableArea::create(true);
128 OwnPtr
<MockScrollAnimatorNone
> scrollAnimatorNone
= MockScrollAnimatorNone::create(scrollableArea
.get());
130 EXPECT_CALL(*scrollableArea
, scrollSize(_
)).Times(AtLeast(1)).WillRepeatedly(Return(1000));
131 EXPECT_CALL(*scrollableArea
, minimumScrollPosition()).Times(AtLeast(1)).WillRepeatedly(Return(IntPoint()));
132 EXPECT_CALL(*scrollableArea
, maximumScrollPosition()).Times(AtLeast(1)).WillRepeatedly(Return(IntPoint(1000, 1000)));
133 EXPECT_CALL(*scrollableArea
, setScrollOffset(_
, _
)).Times(4);
135 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByLine
, 100, 1);
136 EXPECT_NE(100, scrollAnimatorNone
->currentX());
137 EXPECT_NE(0, scrollAnimatorNone
->currentX());
138 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
139 scrollAnimatorNone
->reset();
141 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByPage
, 100, 1);
142 EXPECT_NE(100, scrollAnimatorNone
->currentX());
143 EXPECT_NE(0, scrollAnimatorNone
->currentX());
144 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
145 scrollAnimatorNone
->reset();
147 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByPixel
, 4, 25);
148 EXPECT_NE(100, scrollAnimatorNone
->currentX());
149 EXPECT_NE(0, scrollAnimatorNone
->currentX());
150 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
151 scrollAnimatorNone
->reset();
153 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByPrecisePixel
, 4, 25);
154 EXPECT_EQ(100, scrollAnimatorNone
->currentX());
155 EXPECT_NE(0, scrollAnimatorNone
->currentX());
156 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
157 scrollAnimatorNone
->reset();
160 TEST(ScrollAnimatorEnabled
, Disabled
)
162 OwnPtrWillBeRawPtr
<MockScrollableArea
> scrollableArea
= MockScrollableArea::create(false);
163 OwnPtr
<MockScrollAnimatorNone
> scrollAnimatorNone
= MockScrollAnimatorNone::create(scrollableArea
.get());
165 EXPECT_CALL(*scrollableArea
, minimumScrollPosition()).Times(AtLeast(1)).WillRepeatedly(Return(IntPoint()));
166 EXPECT_CALL(*scrollableArea
, maximumScrollPosition()).Times(AtLeast(1)).WillRepeatedly(Return(IntPoint(1000, 1000)));
167 EXPECT_CALL(*scrollableArea
, setScrollOffset(_
, _
)).Times(4);
169 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByLine
, 100, 1);
170 EXPECT_EQ(100, scrollAnimatorNone
->currentX());
171 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
172 scrollAnimatorNone
->reset();
174 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByPage
, 100, 1);
175 EXPECT_EQ(100, scrollAnimatorNone
->currentX());
176 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
177 scrollAnimatorNone
->reset();
179 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByDocument
, 100, 1);
180 EXPECT_EQ(100, scrollAnimatorNone
->currentX());
181 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
182 scrollAnimatorNone
->reset();
184 scrollAnimatorNone
->userScroll(HorizontalScrollbar
, ScrollByPixel
, 100, 1);
185 EXPECT_EQ(100, scrollAnimatorNone
->currentX());
186 EXPECT_EQ(0, scrollAnimatorNone
->currentY());
187 scrollAnimatorNone
->reset();
190 class ScrollAnimatorNoneTest
: public testing::Test
{
192 struct SavePerAxisData
: public ScrollAnimatorNone::PerAxisData
{
193 SavePerAxisData(const ScrollAnimatorNone::PerAxisData
& data
)
194 : ScrollAnimatorNone::PerAxisData(0, 768)
195 , m_mockScrollableArea(MockScrollableArea::create(true))
196 , m_mockScrollAnimatorNone(MockScrollAnimatorNone::create(m_mockScrollableArea
.get()))
198 this->m_currentVelocity
= data
.m_currentVelocity
;
199 this->m_desiredPosition
= data
.m_desiredPosition
;
200 this->m_desiredVelocity
= data
.m_desiredVelocity
;
201 this->m_startPosition
= data
.m_startPosition
;
202 this->m_startTime
= data
.m_startTime
;
203 this->m_startVelocity
= data
.m_startVelocity
;
204 this->m_animationTime
= data
.m_animationTime
;
205 this->m_lastAnimationTime
= data
.m_lastAnimationTime
;
206 this->m_attackPosition
= data
.m_attackPosition
;
207 this->m_attackTime
= data
.m_attackTime
;
208 this->m_attackCurve
= data
.m_attackCurve
;
209 this->m_releasePosition
= data
.m_releasePosition
;
210 this->m_releaseTime
= data
.m_releaseTime
;
211 this->m_releaseCurve
= data
.m_releaseCurve
;
214 bool operator==(const SavePerAxisData
& other
) const
216 return m_currentVelocity
== other
.m_currentVelocity
&& m_desiredPosition
== other
.m_desiredPosition
&& m_desiredVelocity
== other
.m_desiredVelocity
&& m_startPosition
== other
.m_startPosition
&& m_startTime
== other
.m_startTime
&& m_startVelocity
== other
.m_startVelocity
&& m_animationTime
== other
.m_animationTime
&& m_lastAnimationTime
== other
.m_lastAnimationTime
&& m_attackPosition
== other
.m_attackPosition
&& m_attackTime
== other
.m_attackTime
&& m_attackCurve
== other
.m_attackCurve
&& m_releasePosition
== other
.m_releasePosition
&& m_releaseTime
== other
.m_releaseTime
&& m_releaseCurve
== other
.m_releaseCurve
;
218 OwnPtrWillBePersistent
<MockScrollableArea
> m_mockScrollableArea
;
219 OwnPtr
<MockScrollAnimatorNone
> m_mockScrollAnimatorNone
;
222 ScrollAnimatorNoneTest()
223 : m_mockScrollableArea(MockScrollableArea::create(true))
224 , m_mockScrollAnimatorNone(MockScrollAnimatorNone::create(m_mockScrollableArea
.get()))
228 void SetUp() override
230 m_currentPosition
= 100;
231 m_data
= new ScrollAnimatorNone::PerAxisData(&m_currentPosition
, 768);
233 void TearDown() override
239 bool updateDataFromParameters(float step
, float multiplier
, float scrollableSize
, double currentTime
, ScrollAnimatorNone::Parameters
*);
240 bool animateScroll(double currentTime
);
242 double attackArea(ScrollAnimatorNone::Curve
, double startT
, double endT
);
243 double releaseArea(ScrollAnimatorNone::Curve
, double startT
, double endT
);
244 double attackCurve(ScrollAnimatorNone::Curve
, double deltaT
, double curveT
, double startPosition
, double attackPosition
);
245 double releaseCurve(ScrollAnimatorNone::Curve
, double deltaT
, double curveT
, double releasePosition
, double desiredPosition
);
246 double coastCurve(ScrollAnimatorNone::Curve
, double factor
);
248 void curveTestInner(ScrollAnimatorNone::Curve
, double step
, double time
);
249 void curveTest(ScrollAnimatorNone::Curve
);
251 void checkDesiredPosition(float expectedPosition
);
252 void checkSoftLanding(float expectedPosition
);
254 static double kTickTime
;
255 static double kAnimationTime
;
256 static double kStartTime
;
257 static double kEndTime
;
258 float m_currentPosition
;
259 OwnPtrWillBePersistent
<MockScrollableArea
> m_mockScrollableArea
;
260 OwnPtr
<MockScrollAnimatorNone
> m_mockScrollAnimatorNone
;
261 bool m_scrollingDown
;
262 ScrollAnimatorNone::PerAxisData
* m_data
;
265 double ScrollAnimatorNoneTest::kTickTime
= 1 / 60.0;
266 double ScrollAnimatorNoneTest::kAnimationTime
= 0.01;
267 double ScrollAnimatorNoneTest::kStartTime
= 10.0;
268 double ScrollAnimatorNoneTest::kEndTime
= 20.0;
270 void ScrollAnimatorNoneTest::reset()
273 m_scrollingDown
= true;
276 bool ScrollAnimatorNoneTest::updateDataFromParameters(float step
, float multiplier
, float scrollableSize
, double currentTime
, ScrollAnimatorNone::Parameters
* parameters
)
278 if (step
* multiplier
)
279 m_scrollingDown
= (step
* multiplier
> 0);
281 double oldVelocity
= m_data
->m_currentVelocity
;
282 double oldDesiredVelocity
= m_data
->m_desiredVelocity
;
283 double oldTimeLeft
= m_data
->m_animationTime
- (m_data
->m_lastAnimationTime
- m_data
->m_startTime
);
284 bool result
= m_data
->updateDataFromParameters(step
, multiplier
, scrollableSize
, currentTime
, parameters
);
286 EXPECT_LE(oldVelocity
, m_data
->m_currentVelocity
);
288 EXPECT_GE(oldVelocity
, m_data
->m_currentVelocity
);
290 double deltaTime
= m_data
->m_lastAnimationTime
- m_data
->m_startTime
;
291 double timeLeft
= m_data
->m_animationTime
- deltaTime
;
292 double releaseTimeLeft
= std::min(timeLeft
, m_data
->m_releaseTime
);
293 double attackTimeLeft
= std::max(0., m_data
->m_attackTime
- deltaTime
);
294 double sustainTimeLeft
= std::max(0., timeLeft
- releaseTimeLeft
- attackTimeLeft
);
296 // If we're getting near the finish, the desired velocity can decrease since the time left gets increased.
297 if (step
* multiplier
) {
298 double allowedVelocityDecreaseFactor
= 0.99 * oldTimeLeft
/ timeLeft
;
299 allowedVelocityDecreaseFactor
*= allowedVelocityDecreaseFactor
;
301 EXPECT_LE(oldDesiredVelocity
* allowedVelocityDecreaseFactor
, m_data
->m_desiredVelocity
);
303 EXPECT_GE(oldDesiredVelocity
* allowedVelocityDecreaseFactor
, m_data
->m_desiredVelocity
);
305 double startPosition
= attackTimeLeft
? m_data
->m_attackPosition
: m_currentPosition
;
306 double expectedReleasePosition
= startPosition
+ sustainTimeLeft
* m_data
->m_desiredVelocity
;
307 EXPECT_NEAR(expectedReleasePosition
, m_data
->m_releasePosition
, result
? .0001 : 1);
313 bool ScrollAnimatorNoneTest::animateScroll(double currentTime
)
315 double oldPosition
= *m_data
->m_currentPosition
;
316 bool testEstimatedMaxVelocity
= m_data
->m_startTime
+ m_data
->m_animationTime
- m_data
->m_lastAnimationTime
> m_data
->m_releaseTime
;
318 bool result
= m_data
->animateScroll(currentTime
);
320 double deltaTime
= m_data
->m_lastAnimationTime
- m_data
->m_startTime
;
321 double timeLeft
= m_data
->m_animationTime
- deltaTime
;
322 double releaseTimeLeft
= std::min(timeLeft
, m_data
->m_releaseTime
);
323 double attackTimeLeft
= std::max(0., m_data
->m_attackTime
- deltaTime
);
324 double sustainTimeLeft
= std::max(0., timeLeft
- releaseTimeLeft
- attackTimeLeft
);
325 double distanceLeft
= m_data
->m_desiredPosition
- *m_data
->m_currentPosition
;
327 if (m_scrollingDown
) {
328 EXPECT_LE(0, m_data
->m_currentVelocity
);
329 EXPECT_LE(oldPosition
, *m_data
->m_currentPosition
);
331 EXPECT_GE(0, m_data
->m_currentVelocity
);
332 EXPECT_GE(oldPosition
, *m_data
->m_currentPosition
);
334 EXPECT_GE(fabs(m_data
->m_desiredVelocity
) * 2, fabs(m_data
->m_currentVelocity
));
335 if (testEstimatedMaxVelocity
)
336 EXPECT_GE(fabs(distanceLeft
/ sustainTimeLeft
) * 1.2, fabs(m_data
->m_currentVelocity
));
341 double ScrollAnimatorNoneTest::attackArea(ScrollAnimatorNone::Curve curve
, double startT
, double endT
)
343 return ScrollAnimatorNone::PerAxisData::attackArea(curve
, startT
, endT
);
346 double ScrollAnimatorNoneTest::releaseArea(ScrollAnimatorNone::Curve curve
, double startT
, double endT
)
348 return ScrollAnimatorNone::PerAxisData::releaseArea(curve
, startT
, endT
);
351 double ScrollAnimatorNoneTest::attackCurve(ScrollAnimatorNone::Curve curve
, double deltaT
, double curveT
, double startPosition
, double attackPosition
)
353 return ScrollAnimatorNone::PerAxisData::attackCurve(curve
, deltaT
, curveT
, startPosition
, attackPosition
);
356 double ScrollAnimatorNoneTest::releaseCurve(ScrollAnimatorNone::Curve curve
, double deltaT
, double curveT
, double releasePosition
, double desiredPosition
)
358 return ScrollAnimatorNone::PerAxisData::releaseCurve(curve
, deltaT
, curveT
, releasePosition
, desiredPosition
);
361 double ScrollAnimatorNoneTest::coastCurve(ScrollAnimatorNone::Curve curve
, double factor
)
363 return ScrollAnimatorNone::PerAxisData::coastCurve(curve
, factor
);
366 void ScrollAnimatorNoneTest::curveTestInner(ScrollAnimatorNone::Curve curve
, double step
, double time
)
368 const double kPosition
= 1000;
371 double oldVelocity
= 0;
372 double accumulate
= 0;
374 for (double t
= step
; t
<= time
; t
+= step
) {
375 double newPos
= attackCurve(curve
, t
, time
, 0, kPosition
);
376 double delta
= newPos
- oldPos
;
377 double velocity
= delta
/ step
;
378 double velocityDelta
= velocity
- oldVelocity
;
380 accumulate
+= (oldPos
+ newPos
) / 2 * (step
/ time
);
382 oldVelocity
= velocity
;
383 if (curve
!= ScrollAnimatorNone::Bounce
) {
384 EXPECT_LE(-.0001, velocityDelta
);
388 double area
= attackArea(curve
, 0, t
/ time
) * kPosition
;
390 EXPECT_NEAR(accumulate
, area
, 1.0);
395 accumulate
= releaseArea(curve
, 0, 1) * kPosition
;
396 for (double t
= step
; t
<= time
; t
+= step
) {
397 double newPos
= releaseCurve(curve
, t
, time
, 0, kPosition
);
398 double delta
= newPos
- oldPos
;
399 double velocity
= delta
/ step
;
400 double velocityDelta
= velocity
- oldVelocity
;
402 accumulate
-= (kPosition
- (oldPos
+ newPos
) / 2) * (step
/ time
);
404 oldVelocity
= velocity
;
405 if (curve
!= ScrollAnimatorNone::Bounce
) {
406 EXPECT_GE(0.01, velocityDelta
);
410 double area
= releaseArea(curve
, t
/ time
, 1) * kPosition
;
412 EXPECT_NEAR(accumulate
, area
, 1.0);
416 void ScrollAnimatorNoneTest::curveTest(ScrollAnimatorNone::Curve curve
)
418 curveTestInner(curve
, 0.01, 0.25);
419 curveTestInner(curve
, 0.2, 10);
420 curveTestInner(curve
, 0.025, 10);
421 curveTestInner(curve
, 0.01, 1);
422 curveTestInner(curve
, 0.25, 40);
425 void ScrollAnimatorNoneTest::checkDesiredPosition(float expectedPosition
)
427 EXPECT_EQ(expectedPosition
, m_data
->m_desiredPosition
);
430 void ScrollAnimatorNoneTest::checkSoftLanding(float expectedPosition
)
432 EXPECT_EQ(expectedPosition
, m_currentPosition
);
433 EXPECT_LE(m_data
->m_desiredVelocity
/ 2, m_data
->m_currentVelocity
);
436 TEST_F(ScrollAnimatorNoneTest
, CurveMathLinear
)
438 curveTest(ScrollAnimatorNone::Linear
);
441 TEST_F(ScrollAnimatorNoneTest
, CurveMathQuadratic
)
443 curveTest(ScrollAnimatorNone::Quadratic
);
446 TEST_F(ScrollAnimatorNoneTest
, CurveMathCubic
)
448 curveTest(ScrollAnimatorNone::Cubic
);
451 TEST_F(ScrollAnimatorNoneTest
, CurveMathQuartic
)
453 curveTest(ScrollAnimatorNone::Quartic
);
456 TEST_F(ScrollAnimatorNoneTest
, CurveMathBounce
)
458 curveTest(ScrollAnimatorNone::Bounce
);
461 TEST_F(ScrollAnimatorNoneTest
, CurveMathCoast
)
463 for (double t
= .25; t
< 1; t
+= .25) {
464 EXPECT_EQ(t
, coastCurve(ScrollAnimatorNone::Linear
, t
));
465 EXPECT_LT(t
, coastCurve(ScrollAnimatorNone::Quadratic
, t
));
466 EXPECT_LT(t
, coastCurve(ScrollAnimatorNone::Cubic
, t
));
467 EXPECT_LT(coastCurve(ScrollAnimatorNone::Quadratic
, t
), coastCurve(ScrollAnimatorNone::Cubic
, t
));
468 EXPECT_LT(t
, coastCurve(ScrollAnimatorNone::Quartic
, t
));
469 EXPECT_LT(coastCurve(ScrollAnimatorNone::Cubic
, t
), coastCurve(ScrollAnimatorNone::Quartic
, t
));
473 TEST_F(ScrollAnimatorNoneTest
, ScrollOnceLinear
)
475 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Linear
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
477 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
479 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kAnimationTime
)
480 result
= animateScroll(t
);
483 TEST_F(ScrollAnimatorNoneTest
, ScrollOnceQuadratic
)
485 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
487 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
489 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kAnimationTime
)
490 result
= animateScroll(t
);
493 TEST_F(ScrollAnimatorNoneTest
, ScrollLongQuadratic
)
495 ScrollAnimatorNone::Parameters
parameters(true, 20 * kTickTime
, 0, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
497 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
499 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kAnimationTime
)
500 result
= animateScroll(t
);
503 TEST_F(ScrollAnimatorNoneTest
, ScrollQuadraticNoSustain
)
505 ScrollAnimatorNone::Parameters
parameters(true, 8 * kTickTime
, 0, ScrollAnimatorNone::Quadratic
, 4 * kTickTime
, ScrollAnimatorNone::Quadratic
, 4 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
507 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
509 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kAnimationTime
)
510 result
= animateScroll(t
);
513 TEST_F(ScrollAnimatorNoneTest
, ScrollQuadraticSmoothed
)
515 ScrollAnimatorNone::Parameters
parameters(true, 8 * kTickTime
, 8 * kTickTime
, ScrollAnimatorNone::Quadratic
, 4 * kTickTime
, ScrollAnimatorNone::Quadratic
, 4 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
517 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
519 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kAnimationTime
)
520 result
= animateScroll(t
);
523 TEST_F(ScrollAnimatorNoneTest
, ScrollOnceCubic
)
525 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
527 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
529 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kAnimationTime
)
530 result
= animateScroll(t
);
533 TEST_F(ScrollAnimatorNoneTest
, ScrollOnceQuartic
)
535 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Quartic
, 3 * kTickTime
, ScrollAnimatorNone::Quartic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
537 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
539 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kAnimationTime
)
540 result
= animateScroll(t
);
543 TEST_F(ScrollAnimatorNoneTest
, ScrollOnceShort
)
545 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
547 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
549 for (double t
= kStartTime
; result
&& t
< kEndTime
; t
+= kTickTime
)
550 result
= animateScroll(t
);
553 TEST_F(ScrollAnimatorNoneTest
, ScrollTwiceQuadratic
)
555 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
557 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
560 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
561 result
= animateScroll(t
);
563 result
= result
&& animateScroll(t
);
564 double before
= m_currentPosition
;
565 result
= result
&& updateDataFromParameters(1, 40, 1000, t
, ¶meters
);
566 result
= result
&& animateScroll(t
);
567 double after
= m_currentPosition
;
568 EXPECT_NEAR(before
, after
, 10);
572 result
= result
&& animateScroll(t
);
573 before
= m_currentPosition
;
574 result
= result
&& updateDataFromParameters(1, 40, 1000, t
, ¶meters
);
575 result
= result
&& animateScroll(t
);
576 after
= m_currentPosition
;
577 EXPECT_NEAR(before
, after
, 10);
580 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
581 result
= animateScroll(t
);
584 TEST_F(ScrollAnimatorNoneTest
, ScrollLotsQuadratic
)
586 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
588 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime
, ¶meters
));
591 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
592 result
= animateScroll(t
);
594 for (int i
= 0; i
< 20; ++i
) {
596 result
= result
&& animateScroll(t
);
597 result
= result
&& updateDataFromParameters(3, 40, 10000, t
, ¶meters
);
601 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
602 result
= result
&& animateScroll(t
);
605 TEST_F(ScrollAnimatorNoneTest
, ScrollLotsQuadraticSmoothed
)
607 ScrollAnimatorNone::Parameters
parameters(true, 10 * kTickTime
, 6 * kTickTime
, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Quadratic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
609 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime
, ¶meters
));
612 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
613 result
= animateScroll(t
);
615 for (int i
= 0; i
< 20; ++i
) {
617 result
= result
&& animateScroll(t
);
618 result
= result
&& updateDataFromParameters(3, 40, 10000, t
, ¶meters
);
622 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
623 result
= result
&& animateScroll(t
);
626 TEST_F(ScrollAnimatorNoneTest
, ScrollTwiceCubic
)
628 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
630 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
633 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
634 result
= animateScroll(t
);
636 result
= result
&& animateScroll(t
);
637 double before
= m_currentPosition
;
638 result
= result
&& updateDataFromParameters(1, 40, 1000, t
, ¶meters
);
639 result
= result
&& animateScroll(t
);
640 double after
= m_currentPosition
;
641 EXPECT_NEAR(before
, after
, 10);
645 result
= result
&& animateScroll(t
);
646 before
= m_currentPosition
;
647 result
= result
&& updateDataFromParameters(1, 40, 1000, t
, ¶meters
);
648 result
= result
&& animateScroll(t
);
649 after
= m_currentPosition
;
650 EXPECT_NEAR(before
, after
, 10);
653 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
654 result
= animateScroll(t
);
657 TEST_F(ScrollAnimatorNoneTest
, ScrollLotsCubic
)
659 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
661 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime
, ¶meters
));
664 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
665 result
= animateScroll(t
);
667 for (int i
= 0; i
< 20; ++i
) {
669 result
= result
&& animateScroll(t
);
670 result
= result
&& updateDataFromParameters(3, 40, 10000, t
, ¶meters
);
674 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
675 result
= result
&& animateScroll(t
);
678 TEST_F(ScrollAnimatorNoneTest
, ScrollLotsCubicSmoothed
)
680 ScrollAnimatorNone::Parameters
parameters(true, 10 * kTickTime
, 6 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
682 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime
, ¶meters
));
685 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
686 result
= animateScroll(t
);
688 for (int i
= 0; i
< 20; ++i
) {
690 result
= result
&& animateScroll(t
);
691 result
= result
&& updateDataFromParameters(3, 40, 10000, t
, ¶meters
);
695 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
696 result
= result
&& animateScroll(t
);
699 TEST_F(ScrollAnimatorNoneTest
, ScrollWheelTrace
)
701 ScrollAnimatorNone::Parameters
parameters(true, 11 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
703 // Constructed from an actual scroll wheel trace that exhibited a glitch.
704 bool result
= updateDataFromParameters(1, 53.33f
, 1000, 100.5781f
, ¶meters
);
705 result
= animateScroll(100.5933);
706 result
= result
&& animateScroll(100.6085);
707 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.6485f
, ¶meters
);
708 result
= result
&& animateScroll(100.6515);
709 result
= result
&& animateScroll(100.6853);
710 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.6863f
, ¶meters
);
711 result
= result
&& animateScroll(100.7005);
712 result
= result
&& animateScroll(100.7157);
713 result
= result
&& animateScroll(100.7312);
714 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.7379f
, ¶meters
);
715 result
= result
&& animateScroll(100.7464);
716 result
= result
&& animateScroll(100.7617);
717 result
= result
&& animateScroll(100.7775);
718 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.7779f
, ¶meters
);
719 for (double t
= 100.7928; result
&& t
< 200; t
+= 0.015)
720 result
= result
&& animateScroll(t
);
723 TEST_F(ScrollAnimatorNoneTest
, ScrollWheelTraceSmoothed
)
725 ScrollAnimatorNone::Parameters
parameters(true, 11 * kTickTime
, 7 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
727 // Constructed from an actual scroll wheel trace that exhibited a glitch.
728 bool result
= updateDataFromParameters(1, 53.33f
, 1000, 100.5781f
, ¶meters
);
729 result
= animateScroll(100.5933);
730 result
= result
&& animateScroll(100.6085);
731 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.6485f
, ¶meters
);
732 result
= result
&& animateScroll(100.6515);
733 result
= result
&& animateScroll(100.6853);
734 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.6863f
, ¶meters
);
735 result
= result
&& animateScroll(100.7005);
736 result
= result
&& animateScroll(100.7157);
737 result
= result
&& animateScroll(100.7312);
738 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.7379f
, ¶meters
);
739 result
= result
&& animateScroll(100.7464);
740 result
= result
&& animateScroll(100.7617);
741 result
= result
&& animateScroll(100.7775);
742 result
= result
&& updateDataFromParameters(1, 53.33f
, 1000, 100.7779f
, ¶meters
);
743 for (double t
= 100.7928; result
&& t
< 200; t
+= 0.015)
744 result
= result
&& animateScroll(t
);
747 TEST_F(ScrollAnimatorNoneTest
, LinuxTrackPadTrace
)
749 ScrollAnimatorNone::Parameters
parameters(true, 11 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
751 bool result
= updateDataFromParameters(1.00, 60.00, 1000, 100.6863, ¶meters
);
752 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.6897, ¶meters
);
753 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7001, ¶meters
);
754 result
= result
&& animateScroll(100.7015);
755 result
= result
&& animateScroll(100.7169);
756 result
= result
&& updateDataFromParameters(1.00, 40.00, 1000, 100.7179, ¶meters
);
757 result
= result
&& animateScroll(100.7322);
758 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7332, ¶meters
);
759 result
= result
&& animateScroll(100.7491);
760 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7519, ¶meters
);
761 result
= result
&& animateScroll(100.7676);
762 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7698, ¶meters
);
763 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7830, ¶meters
);
764 result
= result
&& animateScroll(100.7834);
765 result
= result
&& animateScroll(100.7997);
766 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8019, ¶meters
);
767 result
= result
&& animateScroll(100.8154);
768 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8241, ¶meters
);
769 result
= result
&& animateScroll(100.8335);
770 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8465, ¶meters
);
771 result
= result
&& animateScroll(100.8513);
772 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8623, ¶meters
);
773 for (double t
= 100.8674; result
&& t
< 200; t
+= 0.015)
774 result
= result
&& animateScroll(t
);
777 TEST_F(ScrollAnimatorNoneTest
, LinuxTrackPadTraceSmoothed
)
779 ScrollAnimatorNone::Parameters
parameters(true, 11 * kTickTime
, 7 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
781 bool result
= updateDataFromParameters(1.00, 60.00, 1000, 100.6863, ¶meters
);
782 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.6897, ¶meters
);
783 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7001, ¶meters
);
784 result
= result
&& animateScroll(100.7015);
785 result
= result
&& animateScroll(100.7169);
786 result
= result
&& updateDataFromParameters(1.00, 40.00, 1000, 100.7179, ¶meters
);
787 result
= result
&& animateScroll(100.7322);
788 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7332, ¶meters
);
789 result
= result
&& animateScroll(100.7491);
790 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7519, ¶meters
);
791 result
= result
&& animateScroll(100.7676);
792 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7698, ¶meters
);
793 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.7830, ¶meters
);
794 result
= result
&& animateScroll(100.7834);
795 result
= result
&& animateScroll(100.7997);
796 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8019, ¶meters
);
797 result
= result
&& animateScroll(100.8154);
798 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8241, ¶meters
);
799 result
= result
&& animateScroll(100.8335);
800 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8465, ¶meters
);
801 result
= result
&& animateScroll(100.8513);
802 result
= result
&& updateDataFromParameters(1.00, 20.00, 1000, 100.8623, ¶meters
);
803 for (double t
= 100.8674; result
&& t
< 200; t
+= 0.015)
804 result
= result
&& animateScroll(t
);
807 TEST_F(ScrollAnimatorNoneTest
, ScrollDownToBumper
)
809 ScrollAnimatorNone::Parameters
parameters(true, 10 * kTickTime
, 7 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
811 EXPECT_TRUE(updateDataFromParameters(1, 20, 200, kStartTime
, ¶meters
));
813 double t
= kStartTime
;
814 for (int i
= 0; i
< 10; ++i
) {
816 result
= result
&& animateScroll(t
);
817 updateDataFromParameters(1, 20, 200, t
, ¶meters
);
819 checkDesiredPosition(200);
822 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
823 result
= result
&& animateScroll(t
);
824 checkSoftLanding(200);
827 TEST_F(ScrollAnimatorNoneTest
, ScrollUpToBumper
)
829 ScrollAnimatorNone::Parameters
parameters(true, 10 * kTickTime
, 7 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
831 EXPECT_TRUE(updateDataFromParameters(1, -20, 200, kStartTime
, ¶meters
));
833 double t
= kStartTime
;
834 for (int i
= 0; i
< 10; ++i
) {
836 result
= result
&& animateScroll(t
);
837 updateDataFromParameters(1, -20, 200, t
, ¶meters
);
839 checkDesiredPosition(0);
842 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
843 result
= result
&& animateScroll(t
);
847 TEST_F(ScrollAnimatorNoneTest
, ScrollUpToBumperCoast
)
849 ScrollAnimatorNone::Parameters
parameters(true, 11 * kTickTime
, 2 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 1);
851 m_currentPosition
= 40000;
852 EXPECT_TRUE(updateDataFromParameters(1, -10000, 50000, kStartTime
, ¶meters
));
854 double t
= kStartTime
;
855 for (int i
= 0; i
< 10; ++i
) {
857 result
= result
&& animateScroll(t
);
858 updateDataFromParameters(1, -10000, 50000, t
, ¶meters
);
860 checkDesiredPosition(0);
863 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
864 result
= result
&& animateScroll(t
);
868 TEST_F(ScrollAnimatorNoneTest
, ScrollDownToBumperCoast
)
870 ScrollAnimatorNone::Parameters
parameters(true, 11 * kTickTime
, 2 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 1);
872 m_currentPosition
= 10000;
873 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime
, ¶meters
));
875 double t
= kStartTime
;
876 for (int i
= 0; i
< 10; ++i
) {
878 result
= result
&& animateScroll(t
);
879 updateDataFromParameters(1, 10000, 50000, t
, ¶meters
);
881 checkDesiredPosition(50000);
884 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
885 result
= result
&& animateScroll(t
);
886 checkSoftLanding(50000);
889 TEST_F(ScrollAnimatorNoneTest
, VaryingInputsEquivalency
)
891 ScrollAnimatorNone::Parameters
parameters(true, 15 * kTickTime
, 10 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
894 EXPECT_TRUE(updateDataFromParameters(1, 300, 50000, kStartTime
, ¶meters
));
895 SavePerAxisData
dataSingle(*m_data
);
898 EXPECT_TRUE(updateDataFromParameters(1, 150, 50000, kStartTime
, ¶meters
));
899 EXPECT_TRUE(updateDataFromParameters(1, 150, 50000, kStartTime
, ¶meters
));
900 SavePerAxisData
dataDouble(*m_data
);
903 EXPECT_TRUE(updateDataFromParameters(1, 100, 50000, kStartTime
, ¶meters
));
904 EXPECT_TRUE(updateDataFromParameters(1, 100, 50000, kStartTime
, ¶meters
));
905 EXPECT_TRUE(updateDataFromParameters(1, 100, 50000, kStartTime
, ¶meters
));
906 SavePerAxisData
dataTriple(*m_data
);
909 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
));
910 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
));
911 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
));
912 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
));
913 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
));
914 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
));
915 SavePerAxisData
dataMany(*m_data
);
917 EXPECT_EQ(dataSingle
, dataDouble
);
918 EXPECT_EQ(dataSingle
, dataTriple
);
919 EXPECT_EQ(dataSingle
, dataMany
);
922 TEST_F(ScrollAnimatorNoneTest
, VaryingInputsEquivalencyCoast
)
924 ScrollAnimatorNone::Parameters
parameters(true, 15 * kTickTime
, 10 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Linear
, 1);
927 updateDataFromParameters(1, 300, 50000, kStartTime
, ¶meters
);
928 SavePerAxisData
dataSingle(*m_data
);
931 updateDataFromParameters(1, 150, 50000, kStartTime
, ¶meters
);
932 updateDataFromParameters(1, 150, 50000, kStartTime
, ¶meters
);
933 SavePerAxisData
dataDouble(*m_data
);
936 updateDataFromParameters(1, 100, 50000, kStartTime
, ¶meters
);
937 updateDataFromParameters(1, 100, 50000, kStartTime
, ¶meters
);
938 updateDataFromParameters(1, 100, 50000, kStartTime
, ¶meters
);
939 SavePerAxisData
dataTriple(*m_data
);
942 updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
);
943 updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
);
944 updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
);
945 updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
);
946 updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
);
947 updateDataFromParameters(1, 50, 50000, kStartTime
, ¶meters
);
948 SavePerAxisData
dataMany(*m_data
);
950 EXPECT_EQ(dataSingle
, dataDouble
);
951 EXPECT_EQ(dataSingle
, dataTriple
);
952 EXPECT_EQ(dataSingle
, dataMany
);
955 TEST_F(ScrollAnimatorNoneTest
, VaryingInputsEquivalencyCoastLarge
)
957 ScrollAnimatorNone::Parameters
parameters(true, 15 * kTickTime
, 10 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Linear
, 1);
960 EXPECT_TRUE(updateDataFromParameters(1, 30000, 50000, kStartTime
, ¶meters
));
961 SavePerAxisData
dataSingle(*m_data
);
964 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime
, ¶meters
));
965 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime
, ¶meters
));
966 SavePerAxisData
dataDouble(*m_data
);
969 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime
, ¶meters
));
970 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime
, ¶meters
));
971 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime
, ¶meters
));
972 SavePerAxisData
dataTriple(*m_data
);
975 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
976 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
977 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
978 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
979 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
980 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
981 SavePerAxisData
dataMany(*m_data
);
983 EXPECT_EQ(dataSingle
, dataDouble
);
984 EXPECT_EQ(dataSingle
, dataTriple
);
985 EXPECT_EQ(dataSingle
, dataMany
);
988 TEST_F(ScrollAnimatorNoneTest
, VaryingInputsEquivalencyCoastSteep
)
990 ScrollAnimatorNone::Parameters
parameters(true, 15 * kTickTime
, 10 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Cubic
, 5 * kTickTime
, ScrollAnimatorNone::Quadratic
, 1);
993 EXPECT_TRUE(updateDataFromParameters(1, 30000, 50000, kStartTime
, ¶meters
));
994 SavePerAxisData
dataSingle(*m_data
);
997 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime
, ¶meters
));
998 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime
, ¶meters
));
999 SavePerAxisData
dataDouble(*m_data
);
1002 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime
, ¶meters
));
1003 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime
, ¶meters
));
1004 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime
, ¶meters
));
1005 SavePerAxisData
dataTriple(*m_data
);
1008 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
1009 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
1010 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
1011 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
1012 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
1013 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime
, ¶meters
));
1014 SavePerAxisData
dataMany(*m_data
);
1016 EXPECT_EQ(dataSingle
, dataDouble
);
1017 EXPECT_EQ(dataSingle
, dataTriple
);
1018 EXPECT_EQ(dataSingle
, dataMany
);
1021 TEST_F(ScrollAnimatorNoneTest
, ScrollStopInMiddle
)
1023 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
1025 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
1028 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
1029 result
= animateScroll(t
);
1031 result
= result
&& animateScroll(t
);
1032 EXPECT_TRUE(result
);
1033 double before
= m_currentPosition
;
1034 result
= result
&& updateDataFromParameters(0, 0, 1000, t
, ¶meters
);
1035 EXPECT_FALSE(result
);
1036 result
= result
&& animateScroll(t
);
1037 double after
= m_currentPosition
;
1038 EXPECT_EQ(before
, after
);
1039 checkDesiredPosition(after
);
1042 TEST_F(ScrollAnimatorNoneTest
, ReverseInMiddle
)
1044 ScrollAnimatorNone::Parameters
parameters(true, 7 * kTickTime
, 0, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Cubic
, 3 * kTickTime
, ScrollAnimatorNone::Linear
, 0);
1046 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime
, ¶meters
));
1049 for (t
= kStartTime
; result
&& t
< kStartTime
+ 1.5 * kTickTime
; t
+= kAnimationTime
)
1050 result
= animateScroll(t
);
1052 result
= result
&& animateScroll(t
);
1053 EXPECT_TRUE(result
);
1054 double before
= m_currentPosition
;
1055 result
= result
&& updateDataFromParameters(1, -10, 1000, t
, ¶meters
);
1056 EXPECT_TRUE(result
);
1057 result
= result
&& animateScroll(t
);
1058 double after
= m_currentPosition
;
1059 EXPECT_GE(before
, after
);
1061 t
+= kAnimationTime
;
1062 for (; result
&& t
< kEndTime
; t
+= kAnimationTime
)
1063 result
= result
&& animateScroll(t
);
1064 EXPECT_GE(before
, m_currentPosition
);
1067 } // namespace blink