OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * | |
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. | |
13 * | |
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. | |
24 */ | |
25 | |
26 // Tests for the ScrollAnimator class. | |
27 | |
28 #include "config.h" | |
29 #include "platform/scroll/ScrollAnimator.h" | |
30 | |
31 #include "platform/Logging.h" | |
32 #include "platform/geometry/FloatPoint.h" | |
33 #include "platform/geometry/IntRect.h" | |
34 #include "platform/scroll/ScrollAnimatorBase.h" | |
35 #include "platform/scroll/ScrollableArea.h" | |
36 #include <gmock/gmock.h> | |
37 #include <gtest/gtest.h> | |
38 | |
39 namespace blink { | |
40 | |
41 using testing::AtLeast; | |
42 using testing::Return; | |
43 using testing::_; | |
44 | |
45 namespace { | |
46 | |
47 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro
llableArea>, public ScrollableArea { | |
48 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); | |
49 public: | |
50 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(bool scrollAnimator
Enabled) | |
51 { | |
52 return adoptPtrWillBeNoop(new MockScrollableArea(scrollAnimatorEnabled))
; | |
53 } | |
54 | |
55 MOCK_CONST_METHOD0(isActive, bool()); | |
56 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); | |
57 MOCK_METHOD2(invalidateScrollbar, void(Scrollbar*, const IntRect&)); | |
58 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); | |
59 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); | |
60 MOCK_METHOD2(setScrollOffset, void(const IntPoint&, ScrollType)); | |
61 MOCK_METHOD2(invalidateScrollbarRect, void(Scrollbar*, const IntRect&)); | |
62 MOCK_METHOD1(invalidateScrollCornerRect, void(const IntRect&)); | |
63 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); | |
64 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); | |
65 MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint()); | |
66 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); | |
67 MOCK_CONST_METHOD0(contentsSize, IntSize()); | |
68 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); | |
69 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); | |
70 | |
71 bool userInputScrollable(ScrollbarOrientation) const override { return true;
} | |
72 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } | |
73 IntPoint scrollPosition() const override { return IntPoint(); } | |
74 int visibleHeight() const override { return 768; } | |
75 int visibleWidth() const override { return 1024; } | |
76 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled
; } | |
77 int pageStep(ScrollbarOrientation) const override { return 0; } | |
78 | |
79 DEFINE_INLINE_VIRTUAL_TRACE() | |
80 { | |
81 ScrollableArea::trace(visitor); | |
82 } | |
83 | |
84 private: | |
85 explicit MockScrollableArea(bool scrollAnimatorEnabled) | |
86 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } | |
87 | |
88 bool m_scrollAnimatorEnabled; | |
89 }; | |
90 | |
91 class MockScrollAnimatorNone : public ScrollAnimator { | |
92 public: | |
93 static PassOwnPtr<MockScrollAnimatorNone> create(ScrollableArea* scrollableA
rea) | |
94 { | |
95 return adoptPtr(new MockScrollAnimatorNone(scrollableArea)); | |
96 } | |
97 | |
98 float currentX() { return m_currentPosX; } | |
99 float currentY() { return m_currentPosY; } | |
100 | |
101 FloatPoint m_fp; | |
102 int m_count; | |
103 | |
104 void reset() | |
105 { | |
106 stopAnimationTimerIfNeeded(); | |
107 m_currentPosX = 0; | |
108 m_currentPosY = 0; | |
109 m_horizontalData.reset(); | |
110 m_verticalData.reset(); | |
111 m_fp = FloatPoint::zero(); | |
112 m_count = 0; | |
113 } | |
114 | |
115 virtual void fireUpAnAnimation(FloatPoint fp) | |
116 { | |
117 m_fp = fp; | |
118 m_count++; | |
119 } | |
120 | |
121 private: | |
122 explicit MockScrollAnimatorNone(ScrollableArea* scrollableArea) | |
123 : ScrollAnimator(scrollableArea) { } | |
124 | |
125 }; | |
126 | |
127 } // namespace | |
128 | |
129 TEST(ScrollAnimatorEnabled, Enabled) | |
130 { | |
131 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::
create(true); | |
132 OwnPtr<MockScrollAnimatorNone> scrollAnimatorNone = MockScrollAnimatorNone::
create(scrollableArea.get()); | |
133 | |
134 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint())); | |
135 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint(1000, 1000))); | |
136 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(4); | |
137 | |
138 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByLine, 100, 1); | |
139 EXPECT_NE(100, scrollAnimatorNone->currentX()); | |
140 EXPECT_NE(0, scrollAnimatorNone->currentX()); | |
141 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
142 scrollAnimatorNone->reset(); | |
143 | |
144 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByPage, 100, 1); | |
145 EXPECT_NE(100, scrollAnimatorNone->currentX()); | |
146 EXPECT_NE(0, scrollAnimatorNone->currentX()); | |
147 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
148 scrollAnimatorNone->reset(); | |
149 | |
150 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByPixel, 4, 25); | |
151 EXPECT_NE(100, scrollAnimatorNone->currentX()); | |
152 EXPECT_NE(0, scrollAnimatorNone->currentX()); | |
153 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
154 scrollAnimatorNone->reset(); | |
155 | |
156 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByPrecisePixel, 4,
25); | |
157 EXPECT_EQ(100, scrollAnimatorNone->currentX()); | |
158 EXPECT_NE(0, scrollAnimatorNone->currentX()); | |
159 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
160 scrollAnimatorNone->reset(); | |
161 } | |
162 | |
163 TEST(ScrollAnimatorEnabled, Disabled) | |
164 { | |
165 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::
create(false); | |
166 OwnPtr<MockScrollAnimatorNone> scrollAnimatorNone = MockScrollAnimatorNone::
create(scrollableArea.get()); | |
167 | |
168 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint())); | |
169 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint(1000, 1000))); | |
170 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(4); | |
171 | |
172 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByLine, 100, 1); | |
173 EXPECT_EQ(100, scrollAnimatorNone->currentX()); | |
174 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
175 scrollAnimatorNone->reset(); | |
176 | |
177 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByPage, 100, 1); | |
178 EXPECT_EQ(100, scrollAnimatorNone->currentX()); | |
179 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
180 scrollAnimatorNone->reset(); | |
181 | |
182 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByDocument, 100, 1
); | |
183 EXPECT_EQ(100, scrollAnimatorNone->currentX()); | |
184 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
185 scrollAnimatorNone->reset(); | |
186 | |
187 scrollAnimatorNone->userScroll(HorizontalScrollbar, ScrollByPixel, 100, 1); | |
188 EXPECT_EQ(100, scrollAnimatorNone->currentX()); | |
189 EXPECT_EQ(0, scrollAnimatorNone->currentY()); | |
190 scrollAnimatorNone->reset(); | |
191 } | |
192 | |
193 class ScrollAnimatorTest : public testing::Test { | |
194 public: | |
195 struct SavePerAxisData : public ScrollAnimator::PerAxisData { | |
196 SavePerAxisData(const ScrollAnimator::PerAxisData& data) | |
197 : ScrollAnimator::PerAxisData(0, 768) | |
198 , m_mockScrollableArea(MockScrollableArea::create(true)) | |
199 , m_mockScrollAnimatorNone(MockScrollAnimatorNone::create(m_mockScro
llableArea.get())) | |
200 { | |
201 this->m_currentVelocity = data.m_currentVelocity; | |
202 this->m_desiredPosition = data.m_desiredPosition; | |
203 this->m_desiredVelocity = data.m_desiredVelocity; | |
204 this->m_startPosition = data.m_startPosition; | |
205 this->m_startTime = data.m_startTime; | |
206 this->m_startVelocity = data.m_startVelocity; | |
207 this->m_animationTime = data.m_animationTime; | |
208 this->m_lastAnimationTime = data.m_lastAnimationTime; | |
209 this->m_attackPosition = data.m_attackPosition; | |
210 this->m_attackTime = data.m_attackTime; | |
211 this->m_attackCurve = data.m_attackCurve; | |
212 this->m_releasePosition = data.m_releasePosition; | |
213 this->m_releaseTime = data.m_releaseTime; | |
214 this->m_releaseCurve = data.m_releaseCurve; | |
215 } | |
216 | |
217 bool operator==(const SavePerAxisData& other) const | |
218 { | |
219 return m_currentVelocity == other.m_currentVelocity && m_desiredPosi
tion == 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_animat
ionTime && 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_rel
easeTime == other.m_releaseTime && m_releaseCurve == other.m_releaseCurve; | |
220 } | |
221 OwnPtrWillBePersistent<MockScrollableArea> m_mockScrollableArea; | |
222 OwnPtr<MockScrollAnimatorNone> m_mockScrollAnimatorNone; | |
223 }; | |
224 | |
225 ScrollAnimatorTest() | |
226 : m_mockScrollableArea(MockScrollableArea::create(true)) | |
227 , m_mockScrollAnimatorNone(MockScrollAnimatorNone::create(m_mockScrollab
leArea.get())) | |
228 { | |
229 } | |
230 | |
231 void SetUp() override | |
232 { | |
233 m_currentPosition = 100; | |
234 m_data = new ScrollAnimator::PerAxisData(&m_currentPosition, 768); | |
235 } | |
236 void TearDown() override | |
237 { | |
238 delete m_data; | |
239 } | |
240 | |
241 void reset(); | |
242 bool updateDataFromParameters(float step, float multiplier, float minScrollP
os, float maxScrollPos, double currentTime, ScrollAnimator::Parameters*); | |
243 bool updateDataFromParameters(float step, float multiplier, float scrollable
Size, double currentTime, ScrollAnimator::Parameters*); | |
244 bool animateScroll(double currentTime); | |
245 | |
246 double attackArea(ScrollAnimator::Curve, double startT, double endT); | |
247 double releaseArea(ScrollAnimator::Curve, double startT, double endT); | |
248 double attackCurve(ScrollAnimator::Curve, double deltaT, double curveT, doub
le startPosition, double attackPosition); | |
249 double releaseCurve(ScrollAnimator::Curve, double deltaT, double curveT, dou
ble releasePosition, double desiredPosition); | |
250 double coastCurve(ScrollAnimator::Curve, double factor); | |
251 | |
252 void curveTestInner(ScrollAnimator::Curve, double step, double time); | |
253 void curveTest(ScrollAnimator::Curve); | |
254 | |
255 void checkDesiredPosition(float expectedPosition); | |
256 void checkSoftLanding(float expectedPosition); | |
257 | |
258 static double kTickTime; | |
259 static double kAnimationTime; | |
260 static double kStartTime; | |
261 static double kEndTime; | |
262 float m_currentPosition; | |
263 OwnPtrWillBePersistent<MockScrollableArea> m_mockScrollableArea; | |
264 OwnPtr<MockScrollAnimatorNone> m_mockScrollAnimatorNone; | |
265 bool m_scrollingDown; | |
266 ScrollAnimator::PerAxisData* m_data; | |
267 }; | |
268 | |
269 double ScrollAnimatorTest::kTickTime = 1 / 60.0; | |
270 double ScrollAnimatorTest::kAnimationTime = 0.01; | |
271 double ScrollAnimatorTest::kStartTime = 10.0; | |
272 double ScrollAnimatorTest::kEndTime = 20.0; | |
273 | |
274 void ScrollAnimatorTest::reset() | |
275 { | |
276 m_data->reset(); | |
277 m_scrollingDown = true; | |
278 } | |
279 | |
280 bool ScrollAnimatorTest::updateDataFromParameters(float step, float multiplier,
float minScrollPos, float maxScrollPos, double currentTime, ScrollAnimator::Para
meters* parameters) | |
281 { | |
282 if (step * multiplier) | |
283 m_scrollingDown = (step * multiplier > 0); | |
284 | |
285 double oldVelocity = m_data->m_currentVelocity; | |
286 double oldDesiredVelocity = m_data->m_desiredVelocity; | |
287 double oldTimeLeft = m_data->m_animationTime - (m_data->m_lastAnimationTime
- m_data->m_startTime); | |
288 bool result = m_data->updateDataFromParameters(step, multiplier, minScrollPo
s, maxScrollPos, currentTime, parameters); | |
289 if (m_scrollingDown) | |
290 EXPECT_LE(oldVelocity, m_data->m_currentVelocity); | |
291 else | |
292 EXPECT_GE(oldVelocity, m_data->m_currentVelocity); | |
293 | |
294 double deltaTime = m_data->m_lastAnimationTime - m_data->m_startTime; | |
295 double timeLeft = m_data->m_animationTime - deltaTime; | |
296 double releaseTimeLeft = std::min(timeLeft, m_data->m_releaseTime); | |
297 double attackTimeLeft = std::max(0., m_data->m_attackTime - deltaTime); | |
298 double sustainTimeLeft = std::max(0., timeLeft - releaseTimeLeft - attackTim
eLeft); | |
299 | |
300 // If we're getting near the finish, the desired velocity can decrease since
the time left gets increased. | |
301 if (step * multiplier) { | |
302 double allowedVelocityDecreaseFactor = 0.99 * oldTimeLeft / timeLeft; | |
303 allowedVelocityDecreaseFactor *= allowedVelocityDecreaseFactor; | |
304 if (m_scrollingDown) | |
305 EXPECT_LE(oldDesiredVelocity * allowedVelocityDecreaseFactor, m_data
->m_desiredVelocity); | |
306 else | |
307 EXPECT_GE(oldDesiredVelocity * allowedVelocityDecreaseFactor, m_data
->m_desiredVelocity); | |
308 | |
309 double startPosition = attackTimeLeft ? m_data->m_attackPosition : m_cur
rentPosition; | |
310 double expectedReleasePosition = startPosition + sustainTimeLeft * m_dat
a->m_desiredVelocity; | |
311 EXPECT_NEAR(expectedReleasePosition, m_data->m_releasePosition, result ?
.0001 : 1); | |
312 } | |
313 | |
314 return result; | |
315 } | |
316 | |
317 bool ScrollAnimatorTest::updateDataFromParameters(float step, float multiplier,
float scrollableSize, double currentTime, ScrollAnimator::Parameters* parameters
) | |
318 { | |
319 return updateDataFromParameters(step, multiplier, 0, scrollableSize, current
Time, parameters); | |
320 } | |
321 | |
322 bool ScrollAnimatorTest::animateScroll(double currentTime) | |
323 { | |
324 double oldPosition = *m_data->m_currentPosition; | |
325 bool testEstimatedMaxVelocity = m_data->m_startTime + m_data->m_animationTim
e - m_data->m_lastAnimationTime > m_data->m_releaseTime; | |
326 | |
327 bool result = m_data->animateScroll(currentTime); | |
328 | |
329 double deltaTime = m_data->m_lastAnimationTime - m_data->m_startTime; | |
330 double timeLeft = m_data->m_animationTime - deltaTime; | |
331 double releaseTimeLeft = std::min(timeLeft, m_data->m_releaseTime); | |
332 double attackTimeLeft = std::max(0., m_data->m_attackTime - deltaTime); | |
333 double sustainTimeLeft = std::max(0., timeLeft - releaseTimeLeft - attackTim
eLeft); | |
334 double distanceLeft = m_data->m_desiredPosition - *m_data->m_currentPosition
; | |
335 | |
336 if (m_scrollingDown) { | |
337 EXPECT_LE(0, m_data->m_currentVelocity); | |
338 EXPECT_LE(oldPosition, *m_data->m_currentPosition); | |
339 } else { | |
340 EXPECT_GE(0, m_data->m_currentVelocity); | |
341 EXPECT_GE(oldPosition, *m_data->m_currentPosition); | |
342 } | |
343 EXPECT_GE(fabs(m_data->m_desiredVelocity) * 2, fabs(m_data->m_currentVelocit
y)); | |
344 if (testEstimatedMaxVelocity) | |
345 EXPECT_GE(fabs(distanceLeft / sustainTimeLeft) * 1.2, fabs(m_data->m_cur
rentVelocity)); | |
346 | |
347 return result; | |
348 } | |
349 | |
350 double ScrollAnimatorTest::attackArea(ScrollAnimator::Curve curve, double startT
, double endT) | |
351 { | |
352 return ScrollAnimator::PerAxisData::attackArea(curve, startT, endT); | |
353 } | |
354 | |
355 double ScrollAnimatorTest::releaseArea(ScrollAnimator::Curve curve, double start
T, double endT) | |
356 { | |
357 return ScrollAnimator::PerAxisData::releaseArea(curve, startT, endT); | |
358 } | |
359 | |
360 double ScrollAnimatorTest::attackCurve(ScrollAnimator::Curve curve, double delta
T, double curveT, double startPosition, double attackPosition) | |
361 { | |
362 return ScrollAnimator::PerAxisData::attackCurve(curve, deltaT, curveT, start
Position, attackPosition); | |
363 } | |
364 | |
365 double ScrollAnimatorTest::releaseCurve(ScrollAnimator::Curve curve, double delt
aT, double curveT, double releasePosition, double desiredPosition) | |
366 { | |
367 return ScrollAnimator::PerAxisData::releaseCurve(curve, deltaT, curveT, rele
asePosition, desiredPosition); | |
368 } | |
369 | |
370 double ScrollAnimatorTest::coastCurve(ScrollAnimator::Curve curve, double factor
) | |
371 { | |
372 return ScrollAnimator::PerAxisData::coastCurve(curve, factor); | |
373 } | |
374 | |
375 void ScrollAnimatorTest::curveTestInner(ScrollAnimator::Curve curve, double step
, double time) | |
376 { | |
377 const double kPosition = 1000; | |
378 | |
379 double oldPos = 0; | |
380 double oldVelocity = 0; | |
381 double accumulate = 0; | |
382 | |
383 for (double t = step ; t <= time ; t += step) { | |
384 double newPos = attackCurve(curve, t, time, 0, kPosition); | |
385 double delta = newPos - oldPos; | |
386 double velocity = delta / step; | |
387 double velocityDelta = velocity - oldVelocity; | |
388 | |
389 accumulate += (oldPos + newPos) / 2 * (step / time); | |
390 oldPos = newPos; | |
391 oldVelocity = velocity; | |
392 if (curve != ScrollAnimator::Bounce) { | |
393 EXPECT_LE(-.0001, velocityDelta); | |
394 EXPECT_LT(0, delta); | |
395 } | |
396 | |
397 double area = attackArea(curve, 0, t / time) * kPosition; | |
398 EXPECT_LE(0, area); | |
399 EXPECT_NEAR(accumulate, area, 1.0); | |
400 } | |
401 | |
402 oldPos = 0; | |
403 oldVelocity *= 2; | |
404 accumulate = releaseArea(curve, 0, 1) * kPosition; | |
405 for (double t = step ; t <= time ; t += step) { | |
406 double newPos = releaseCurve(curve, t, time, 0, kPosition); | |
407 double delta = newPos - oldPos; | |
408 double velocity = delta / step; | |
409 double velocityDelta = velocity - oldVelocity; | |
410 | |
411 accumulate -= (kPosition - (oldPos + newPos) / 2) * (step / time); | |
412 oldPos = newPos; | |
413 oldVelocity = velocity; | |
414 if (curve != ScrollAnimator::Bounce) { | |
415 EXPECT_GE(0.01, velocityDelta); | |
416 EXPECT_LT(0, delta); | |
417 } | |
418 | |
419 double area = releaseArea(curve, t / time, 1) * kPosition; | |
420 EXPECT_LE(0, area); | |
421 EXPECT_NEAR(accumulate, area, 1.0); | |
422 } | |
423 } | |
424 | |
425 void ScrollAnimatorTest::curveTest(ScrollAnimator::Curve curve) | |
426 { | |
427 curveTestInner(curve, 0.01, 0.25); | |
428 curveTestInner(curve, 0.2, 10); | |
429 curveTestInner(curve, 0.025, 10); | |
430 curveTestInner(curve, 0.01, 1); | |
431 curveTestInner(curve, 0.25, 40); | |
432 } | |
433 | |
434 void ScrollAnimatorTest::checkDesiredPosition(float expectedPosition) | |
435 { | |
436 EXPECT_EQ(expectedPosition, m_data->m_desiredPosition); | |
437 } | |
438 | |
439 void ScrollAnimatorTest::checkSoftLanding(float expectedPosition) | |
440 { | |
441 EXPECT_EQ(expectedPosition, m_currentPosition); | |
442 EXPECT_LE(m_data->m_desiredVelocity / 2, m_data->m_currentVelocity); | |
443 } | |
444 | |
445 TEST_F(ScrollAnimatorTest, CurveMathLinear) | |
446 { | |
447 curveTest(ScrollAnimator::Linear); | |
448 } | |
449 | |
450 TEST_F(ScrollAnimatorTest, CurveMathQuadratic) | |
451 { | |
452 curveTest(ScrollAnimator::Quadratic); | |
453 } | |
454 | |
455 TEST_F(ScrollAnimatorTest, CurveMathCubic) | |
456 { | |
457 curveTest(ScrollAnimator::Cubic); | |
458 } | |
459 | |
460 TEST_F(ScrollAnimatorTest, CurveMathQuartic) | |
461 { | |
462 curveTest(ScrollAnimator::Quartic); | |
463 } | |
464 | |
465 TEST_F(ScrollAnimatorTest, CurveMathBounce) | |
466 { | |
467 curveTest(ScrollAnimator::Bounce); | |
468 } | |
469 | |
470 TEST_F(ScrollAnimatorTest, CurveMathCoast) | |
471 { | |
472 for (double t = .25; t < 1; t += .25) { | |
473 EXPECT_EQ(t, coastCurve(ScrollAnimator::Linear, t)); | |
474 EXPECT_LT(t, coastCurve(ScrollAnimator::Quadratic, t)); | |
475 EXPECT_LT(t, coastCurve(ScrollAnimator::Cubic, t)); | |
476 EXPECT_LT(coastCurve(ScrollAnimator::Quadratic, t), coastCurve(ScrollAni
mator::Cubic, t)); | |
477 EXPECT_LT(t, coastCurve(ScrollAnimator::Quartic, t)); | |
478 EXPECT_LT(coastCurve(ScrollAnimator::Cubic, t), coastCurve(ScrollAnimato
r::Quartic, t)); | |
479 } | |
480 } | |
481 | |
482 TEST_F(ScrollAnimatorTest, ScrollOnceLinear) | |
483 { | |
484 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Linear, 3 * kTickTime, ScrollAnimator::Linear, 3 * kTickTime, ScrollAnimator::
Linear, 0); | |
485 | |
486 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
487 bool result = true; | |
488 for (double t = kStartTime; result && t < kEndTime; t += kAnimationTime) | |
489 result = animateScroll(t); | |
490 } | |
491 | |
492 TEST_F(ScrollAnimatorTest, ScrollOnceQuadratic) | |
493 { | |
494 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Quadratic, 3 * kTickTime, ScrollAnimator::Quadratic, 3 * kTickTime, ScrollAnim
ator::Linear, 0); | |
495 | |
496 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
497 bool result = true; | |
498 for (double t = kStartTime; result && t < kEndTime; t += kAnimationTime) | |
499 result = animateScroll(t); | |
500 } | |
501 | |
502 TEST_F(ScrollAnimatorTest, ScrollLongQuadratic) | |
503 { | |
504 ScrollAnimator::Parameters parameters(true, 20 * kTickTime, 0, ScrollAnimato
r::Quadratic, 3 * kTickTime, ScrollAnimator::Quadratic, 3 * kTickTime, ScrollAni
mator::Linear, 0); | |
505 | |
506 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
507 bool result = true; | |
508 for (double t = kStartTime; result && t < kEndTime; t += kAnimationTime) | |
509 result = animateScroll(t); | |
510 } | |
511 | |
512 TEST_F(ScrollAnimatorTest, ScrollQuadraticNoSustain) | |
513 { | |
514 ScrollAnimator::Parameters parameters(true, 8 * kTickTime, 0, ScrollAnimator
::Quadratic, 4 * kTickTime, ScrollAnimator::Quadratic, 4 * kTickTime, ScrollAnim
ator::Linear, 0); | |
515 | |
516 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
517 bool result = true; | |
518 for (double t = kStartTime; result && t < kEndTime; t += kAnimationTime) | |
519 result = animateScroll(t); | |
520 } | |
521 | |
522 TEST_F(ScrollAnimatorTest, ScrollQuadraticSmoothed) | |
523 { | |
524 ScrollAnimator::Parameters parameters(true, 8 * kTickTime, 8 * kTickTime, Sc
rollAnimator::Quadratic, 4 * kTickTime, ScrollAnimator::Quadratic, 4 * kTickTime
, ScrollAnimator::Linear, 0); | |
525 | |
526 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
527 bool result = true; | |
528 for (double t = kStartTime; result && t < kEndTime; t += kAnimationTime) | |
529 result = animateScroll(t); | |
530 } | |
531 | |
532 TEST_F(ScrollAnimatorTest, ScrollOnceCubic) | |
533 { | |
534 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Li
near, 0); | |
535 | |
536 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
537 bool result = true; | |
538 for (double t = kStartTime; result && t < kEndTime; t += kAnimationTime) | |
539 result = animateScroll(t); | |
540 } | |
541 | |
542 TEST_F(ScrollAnimatorTest, ScrollOnceQuartic) | |
543 { | |
544 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Quartic, 3 * kTickTime, ScrollAnimator::Quartic, 3 * kTickTime, ScrollAnimator
::Linear, 0); | |
545 | |
546 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
547 bool result = true; | |
548 for (double t = kStartTime; result && t < kEndTime; t += kAnimationTime) | |
549 result = animateScroll(t); | |
550 } | |
551 | |
552 TEST_F(ScrollAnimatorTest, ScrollOnceShort) | |
553 { | |
554 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Li
near, 0); | |
555 | |
556 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
557 bool result = true; | |
558 for (double t = kStartTime; result && t < kEndTime; t += kTickTime) | |
559 result = animateScroll(t); | |
560 } | |
561 | |
562 TEST_F(ScrollAnimatorTest, ScrollTwiceQuadratic) | |
563 { | |
564 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Quadratic, 3 * kTickTime, ScrollAnimator::Quadratic, 3 * kTickTime, ScrollAnim
ator::Linear, 0); | |
565 | |
566 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
567 bool result = true; | |
568 double t; | |
569 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
570 result = animateScroll(t); | |
571 | |
572 result = result && animateScroll(t); | |
573 double before = m_currentPosition; | |
574 result = result && updateDataFromParameters(1, 40, 1000, t, ¶meters); | |
575 result = result && animateScroll(t); | |
576 double after = m_currentPosition; | |
577 EXPECT_NEAR(before, after, 10); | |
578 | |
579 t += kAnimationTime; | |
580 | |
581 result = result && animateScroll(t); | |
582 before = m_currentPosition; | |
583 result = result && updateDataFromParameters(1, 40, 1000, t, ¶meters); | |
584 result = result && animateScroll(t); | |
585 after = m_currentPosition; | |
586 EXPECT_NEAR(before, after, 10); | |
587 | |
588 t += kAnimationTime; | |
589 for (; result && t < kEndTime; t += kAnimationTime) | |
590 result = animateScroll(t); | |
591 } | |
592 | |
593 TEST_F(ScrollAnimatorTest, ScrollLotsQuadratic) | |
594 { | |
595 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Quadratic, 3 * kTickTime, ScrollAnimator::Quadratic, 3 * kTickTime, ScrollAnim
ator::Linear, 0); | |
596 | |
597 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime, ¶meters))
; | |
598 bool result = true; | |
599 double t; | |
600 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
601 result = animateScroll(t); | |
602 | |
603 for (int i = 0; i < 20; ++i) { | |
604 t += kAnimationTime; | |
605 result = result && animateScroll(t); | |
606 result = result && updateDataFromParameters(3, 40, 10000, t, ¶meters
); | |
607 } | |
608 | |
609 t += kAnimationTime; | |
610 for (; result && t < kEndTime; t += kAnimationTime) | |
611 result = result && animateScroll(t); | |
612 } | |
613 | |
614 TEST_F(ScrollAnimatorTest, ScrollLotsQuadraticSmoothed) | |
615 { | |
616 ScrollAnimator::Parameters parameters(true, 10 * kTickTime, 6 * kTickTime, S
crollAnimator::Quadratic, 3 * kTickTime, ScrollAnimator::Quadratic, 3 * kTickTim
e, ScrollAnimator::Linear, 0); | |
617 | |
618 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime, ¶meters))
; | |
619 bool result = true; | |
620 double t; | |
621 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
622 result = animateScroll(t); | |
623 | |
624 for (int i = 0; i < 20; ++i) { | |
625 t += kAnimationTime; | |
626 result = result && animateScroll(t); | |
627 result = result && updateDataFromParameters(3, 40, 10000, t, ¶meters
); | |
628 } | |
629 | |
630 t += kAnimationTime; | |
631 for (; result && t < kEndTime; t += kAnimationTime) | |
632 result = result && animateScroll(t); | |
633 } | |
634 | |
635 TEST_F(ScrollAnimatorTest, ScrollTwiceCubic) | |
636 { | |
637 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Li
near, 0); | |
638 | |
639 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
640 bool result = true; | |
641 double t; | |
642 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
643 result = animateScroll(t); | |
644 | |
645 result = result && animateScroll(t); | |
646 double before = m_currentPosition; | |
647 result = result && updateDataFromParameters(1, 40, 1000, t, ¶meters); | |
648 result = result && animateScroll(t); | |
649 double after = m_currentPosition; | |
650 EXPECT_NEAR(before, after, 10); | |
651 | |
652 t += kAnimationTime; | |
653 | |
654 result = result && animateScroll(t); | |
655 before = m_currentPosition; | |
656 result = result && updateDataFromParameters(1, 40, 1000, t, ¶meters); | |
657 result = result && animateScroll(t); | |
658 after = m_currentPosition; | |
659 EXPECT_NEAR(before, after, 10); | |
660 | |
661 t += kAnimationTime; | |
662 for (; result && t < kEndTime; t += kAnimationTime) | |
663 result = animateScroll(t); | |
664 } | |
665 | |
666 TEST_F(ScrollAnimatorTest, ScrollLotsCubic) | |
667 { | |
668 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Li
near, 0); | |
669 | |
670 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime, ¶meters))
; | |
671 bool result = true; | |
672 double t; | |
673 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
674 result = animateScroll(t); | |
675 | |
676 for (int i = 0; i < 20; ++i) { | |
677 t += kAnimationTime; | |
678 result = result && animateScroll(t); | |
679 result = result && updateDataFromParameters(3, 40, 10000, t, ¶meters
); | |
680 } | |
681 | |
682 t += kAnimationTime; | |
683 for (; result && t < kEndTime; t += kAnimationTime) | |
684 result = result && animateScroll(t); | |
685 } | |
686 | |
687 TEST_F(ScrollAnimatorTest, ScrollLotsCubicSmoothed) | |
688 { | |
689 ScrollAnimator::Parameters parameters(true, 10 * kTickTime, 6 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 0); | |
690 | |
691 EXPECT_TRUE(updateDataFromParameters(1, 40, 10000, kStartTime, ¶meters))
; | |
692 bool result = true; | |
693 double t; | |
694 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
695 result = animateScroll(t); | |
696 | |
697 for (int i = 0; i < 20; ++i) { | |
698 t += kAnimationTime; | |
699 result = result && animateScroll(t); | |
700 result = result && updateDataFromParameters(3, 40, 10000, t, ¶meters
); | |
701 } | |
702 | |
703 t += kAnimationTime; | |
704 for (; result && t < kEndTime; t += kAnimationTime) | |
705 result = result && animateScroll(t); | |
706 } | |
707 | |
708 TEST_F(ScrollAnimatorTest, ScrollWheelTrace) | |
709 { | |
710 ScrollAnimator::Parameters parameters(true, 11 * kTickTime, 0, ScrollAnimato
r::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::L
inear, 0); | |
711 | |
712 // Constructed from an actual scroll wheel trace that exhibited a glitch. | |
713 bool result = updateDataFromParameters(1, 53.33f, 1000, 100.5781f, ¶mete
rs); | |
714 result = animateScroll(100.5933); | |
715 result = result && animateScroll(100.6085); | |
716 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.6485f, &par
ameters); | |
717 result = result && animateScroll(100.6515); | |
718 result = result && animateScroll(100.6853); | |
719 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.6863f, &par
ameters); | |
720 result = result && animateScroll(100.7005); | |
721 result = result && animateScroll(100.7157); | |
722 result = result && animateScroll(100.7312); | |
723 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.7379f, &par
ameters); | |
724 result = result && animateScroll(100.7464); | |
725 result = result && animateScroll(100.7617); | |
726 result = result && animateScroll(100.7775); | |
727 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.7779f, &par
ameters); | |
728 for (double t = 100.7928; result && t < 200; t += 0.015) | |
729 result = result && animateScroll(t); | |
730 } | |
731 | |
732 TEST_F(ScrollAnimatorTest, ScrollWheelTraceSmoothed) | |
733 { | |
734 ScrollAnimator::Parameters parameters(true, 11 * kTickTime, 7 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 0); | |
735 | |
736 // Constructed from an actual scroll wheel trace that exhibited a glitch. | |
737 bool result = updateDataFromParameters(1, 53.33f, 1000, 100.5781f, ¶mete
rs); | |
738 result = animateScroll(100.5933); | |
739 result = result && animateScroll(100.6085); | |
740 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.6485f, &par
ameters); | |
741 result = result && animateScroll(100.6515); | |
742 result = result && animateScroll(100.6853); | |
743 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.6863f, &par
ameters); | |
744 result = result && animateScroll(100.7005); | |
745 result = result && animateScroll(100.7157); | |
746 result = result && animateScroll(100.7312); | |
747 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.7379f, &par
ameters); | |
748 result = result && animateScroll(100.7464); | |
749 result = result && animateScroll(100.7617); | |
750 result = result && animateScroll(100.7775); | |
751 result = result && updateDataFromParameters(1, 53.33f, 1000, 100.7779f, &par
ameters); | |
752 for (double t = 100.7928; result && t < 200; t += 0.015) | |
753 result = result && animateScroll(t); | |
754 } | |
755 | |
756 TEST_F(ScrollAnimatorTest, LinuxTrackPadTrace) | |
757 { | |
758 ScrollAnimator::Parameters parameters(true, 11 * kTickTime, 0, ScrollAnimato
r::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::L
inear, 0); | |
759 | |
760 bool result = updateDataFromParameters(1.00, 60.00, 1000, 100.6863, ¶met
ers); | |
761 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.6897, &pa
rameters); | |
762 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7001, &pa
rameters); | |
763 result = result && animateScroll(100.7015); | |
764 result = result && animateScroll(100.7169); | |
765 result = result && updateDataFromParameters(1.00, 40.00, 1000, 100.7179, &pa
rameters); | |
766 result = result && animateScroll(100.7322); | |
767 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7332, &pa
rameters); | |
768 result = result && animateScroll(100.7491); | |
769 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7519, &pa
rameters); | |
770 result = result && animateScroll(100.7676); | |
771 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7698, &pa
rameters); | |
772 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7830, &pa
rameters); | |
773 result = result && animateScroll(100.7834); | |
774 result = result && animateScroll(100.7997); | |
775 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8019, &pa
rameters); | |
776 result = result && animateScroll(100.8154); | |
777 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8241, &pa
rameters); | |
778 result = result && animateScroll(100.8335); | |
779 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8465, &pa
rameters); | |
780 result = result && animateScroll(100.8513); | |
781 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8623, &pa
rameters); | |
782 for (double t = 100.8674; result && t < 200; t += 0.015) | |
783 result = result && animateScroll(t); | |
784 } | |
785 | |
786 TEST_F(ScrollAnimatorTest, LinuxTrackPadTraceSmoothed) | |
787 { | |
788 ScrollAnimator::Parameters parameters(true, 11 * kTickTime, 7 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 0); | |
789 | |
790 bool result = updateDataFromParameters(1.00, 60.00, 1000, 100.6863, ¶met
ers); | |
791 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.6897, &pa
rameters); | |
792 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7001, &pa
rameters); | |
793 result = result && animateScroll(100.7015); | |
794 result = result && animateScroll(100.7169); | |
795 result = result && updateDataFromParameters(1.00, 40.00, 1000, 100.7179, &pa
rameters); | |
796 result = result && animateScroll(100.7322); | |
797 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7332, &pa
rameters); | |
798 result = result && animateScroll(100.7491); | |
799 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7519, &pa
rameters); | |
800 result = result && animateScroll(100.7676); | |
801 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7698, &pa
rameters); | |
802 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.7830, &pa
rameters); | |
803 result = result && animateScroll(100.7834); | |
804 result = result && animateScroll(100.7997); | |
805 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8019, &pa
rameters); | |
806 result = result && animateScroll(100.8154); | |
807 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8241, &pa
rameters); | |
808 result = result && animateScroll(100.8335); | |
809 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8465, &pa
rameters); | |
810 result = result && animateScroll(100.8513); | |
811 result = result && updateDataFromParameters(1.00, 20.00, 1000, 100.8623, &pa
rameters); | |
812 for (double t = 100.8674; result && t < 200; t += 0.015) | |
813 result = result && animateScroll(t); | |
814 } | |
815 | |
816 TEST_F(ScrollAnimatorTest, ScrollRightToBumperRTL) | |
817 { | |
818 // Tests that scrolling works for a negative scroll bound. This is the case | |
819 // for RTL pages where the scroll position is always negative. | |
820 m_currentPosition = 0; | |
821 ScrollAnimator::Parameters parameters(true, 10 * kTickTime, 7 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 0); | |
822 | |
823 EXPECT_TRUE(updateDataFromParameters(1, -20, -200, 0, kStartTime, ¶meter
s)); | |
824 bool result = true; | |
825 double t = kStartTime; | |
826 for (int i = 0; i < 10; ++i) { | |
827 t += kAnimationTime; | |
828 result = result && animateScroll(t); | |
829 updateDataFromParameters(1, -20, -200, 0, t, ¶meters); | |
830 } | |
831 checkDesiredPosition(-200); | |
832 | |
833 t += kAnimationTime; | |
834 for (; result && t < kEndTime; t += kAnimationTime) | |
835 result = result && animateScroll(t); | |
836 checkSoftLanding(-200); | |
837 } | |
838 | |
839 TEST_F(ScrollAnimatorTest, ScrollDownToBumper) | |
840 { | |
841 ScrollAnimator::Parameters parameters(true, 10 * kTickTime, 7 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 0); | |
842 | |
843 EXPECT_TRUE(updateDataFromParameters(1, 20, 200, kStartTime, ¶meters)); | |
844 bool result = true; | |
845 double t = kStartTime; | |
846 for (int i = 0; i < 10; ++i) { | |
847 t += kAnimationTime; | |
848 result = result && animateScroll(t); | |
849 updateDataFromParameters(1, 20, 200, t, ¶meters); | |
850 } | |
851 checkDesiredPosition(200); | |
852 | |
853 t += kAnimationTime; | |
854 for (; result && t < kEndTime; t += kAnimationTime) | |
855 result = result && animateScroll(t); | |
856 checkSoftLanding(200); | |
857 } | |
858 | |
859 TEST_F(ScrollAnimatorTest, ScrollUpToBumper) | |
860 { | |
861 ScrollAnimator::Parameters parameters(true, 10 * kTickTime, 7 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 0); | |
862 | |
863 EXPECT_TRUE(updateDataFromParameters(1, -20, 200, kStartTime, ¶meters)); | |
864 bool result = true; | |
865 double t = kStartTime; | |
866 for (int i = 0; i < 10; ++i) { | |
867 t += kAnimationTime; | |
868 result = result && animateScroll(t); | |
869 updateDataFromParameters(1, -20, 200, t, ¶meters); | |
870 } | |
871 checkDesiredPosition(0); | |
872 | |
873 t += kAnimationTime; | |
874 for (; result && t < kEndTime; t += kAnimationTime) | |
875 result = result && animateScroll(t); | |
876 checkSoftLanding(0); | |
877 } | |
878 | |
879 TEST_F(ScrollAnimatorTest, ScrollUpToBumperCoast) | |
880 { | |
881 ScrollAnimator::Parameters parameters(true, 11 * kTickTime, 2 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 1); | |
882 | |
883 m_currentPosition = 40000; | |
884 EXPECT_TRUE(updateDataFromParameters(1, -10000, 50000, kStartTime, ¶mete
rs)); | |
885 bool result = true; | |
886 double t = kStartTime; | |
887 for (int i = 0; i < 10; ++i) { | |
888 t += kAnimationTime; | |
889 result = result && animateScroll(t); | |
890 updateDataFromParameters(1, -10000, 50000, t, ¶meters); | |
891 } | |
892 checkDesiredPosition(0); | |
893 | |
894 t += kAnimationTime; | |
895 for (; result && t < kEndTime; t += kAnimationTime) | |
896 result = result && animateScroll(t); | |
897 checkSoftLanding(0); | |
898 } | |
899 | |
900 TEST_F(ScrollAnimatorTest, ScrollDownToBumperCoast) | |
901 { | |
902 ScrollAnimator::Parameters parameters(true, 11 * kTickTime, 2 * kTickTime, S
crollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, Scrol
lAnimator::Linear, 1); | |
903 | |
904 m_currentPosition = 10000; | |
905 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime, ¶meter
s)); | |
906 bool result = true; | |
907 double t = kStartTime; | |
908 for (int i = 0; i < 10; ++i) { | |
909 t += kAnimationTime; | |
910 result = result && animateScroll(t); | |
911 updateDataFromParameters(1, 10000, 50000, t, ¶meters); | |
912 } | |
913 checkDesiredPosition(50000); | |
914 | |
915 t += kAnimationTime; | |
916 for (; result && t < kEndTime; t += kAnimationTime) | |
917 result = result && animateScroll(t); | |
918 checkSoftLanding(50000); | |
919 } | |
920 | |
921 TEST_F(ScrollAnimatorTest, VaryingInputsEquivalency) | |
922 { | |
923 ScrollAnimator::Parameters parameters(true, 15 * kTickTime, 10 * kTickTime,
ScrollAnimator::Cubic, 5 * kTickTime, ScrollAnimator::Cubic, 5 * kTickTime, Scro
llAnimator::Linear, 0); | |
924 | |
925 reset(); | |
926 EXPECT_TRUE(updateDataFromParameters(1, 300, 50000, kStartTime, ¶meters)
); | |
927 SavePerAxisData dataSingle(*m_data); | |
928 | |
929 reset(); | |
930 EXPECT_TRUE(updateDataFromParameters(1, 150, 50000, kStartTime, ¶meters)
); | |
931 EXPECT_TRUE(updateDataFromParameters(1, 150, 50000, kStartTime, ¶meters)
); | |
932 SavePerAxisData dataDouble(*m_data); | |
933 | |
934 reset(); | |
935 EXPECT_TRUE(updateDataFromParameters(1, 100, 50000, kStartTime, ¶meters)
); | |
936 EXPECT_TRUE(updateDataFromParameters(1, 100, 50000, kStartTime, ¶meters)
); | |
937 EXPECT_TRUE(updateDataFromParameters(1, 100, 50000, kStartTime, ¶meters)
); | |
938 SavePerAxisData dataTriple(*m_data); | |
939 | |
940 reset(); | |
941 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters))
; | |
942 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters))
; | |
943 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters))
; | |
944 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters))
; | |
945 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters))
; | |
946 EXPECT_TRUE(updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters))
; | |
947 SavePerAxisData dataMany(*m_data); | |
948 | |
949 EXPECT_EQ(dataSingle, dataDouble); | |
950 EXPECT_EQ(dataSingle, dataTriple); | |
951 EXPECT_EQ(dataSingle, dataMany); | |
952 } | |
953 | |
954 TEST_F(ScrollAnimatorTest, VaryingInputsEquivalencyCoast) | |
955 { | |
956 ScrollAnimator::Parameters parameters(true, 15 * kTickTime, 10 * kTickTime,
ScrollAnimator::Cubic, 5 * kTickTime, ScrollAnimator::Cubic, 5 * kTickTime, Scro
llAnimator::Linear, 1); | |
957 | |
958 reset(); | |
959 updateDataFromParameters(1, 300, 50000, kStartTime, ¶meters); | |
960 SavePerAxisData dataSingle(*m_data); | |
961 | |
962 reset(); | |
963 updateDataFromParameters(1, 150, 50000, kStartTime, ¶meters); | |
964 updateDataFromParameters(1, 150, 50000, kStartTime, ¶meters); | |
965 SavePerAxisData dataDouble(*m_data); | |
966 | |
967 reset(); | |
968 updateDataFromParameters(1, 100, 50000, kStartTime, ¶meters); | |
969 updateDataFromParameters(1, 100, 50000, kStartTime, ¶meters); | |
970 updateDataFromParameters(1, 100, 50000, kStartTime, ¶meters); | |
971 SavePerAxisData dataTriple(*m_data); | |
972 | |
973 reset(); | |
974 updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters); | |
975 updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters); | |
976 updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters); | |
977 updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters); | |
978 updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters); | |
979 updateDataFromParameters(1, 50, 50000, kStartTime, ¶meters); | |
980 SavePerAxisData dataMany(*m_data); | |
981 | |
982 EXPECT_EQ(dataSingle, dataDouble); | |
983 EXPECT_EQ(dataSingle, dataTriple); | |
984 EXPECT_EQ(dataSingle, dataMany); | |
985 } | |
986 | |
987 TEST_F(ScrollAnimatorTest, VaryingInputsEquivalencyCoastLarge) | |
988 { | |
989 ScrollAnimator::Parameters parameters(true, 15 * kTickTime, 10 * kTickTime,
ScrollAnimator::Cubic, 5 * kTickTime, ScrollAnimator::Cubic, 5 * kTickTime, Scro
llAnimator::Linear, 1); | |
990 | |
991 reset(); | |
992 EXPECT_TRUE(updateDataFromParameters(1, 30000, 50000, kStartTime, ¶meter
s)); | |
993 SavePerAxisData dataSingle(*m_data); | |
994 | |
995 reset(); | |
996 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime, ¶meter
s)); | |
997 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime, ¶meter
s)); | |
998 SavePerAxisData dataDouble(*m_data); | |
999 | |
1000 reset(); | |
1001 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime, ¶meter
s)); | |
1002 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime, ¶meter
s)); | |
1003 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime, ¶meter
s)); | |
1004 SavePerAxisData dataTriple(*m_data); | |
1005 | |
1006 reset(); | |
1007 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime, ¶meters
)); | |
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 SavePerAxisData dataMany(*m_data); | |
1014 | |
1015 EXPECT_EQ(dataSingle, dataDouble); | |
1016 EXPECT_EQ(dataSingle, dataTriple); | |
1017 EXPECT_EQ(dataSingle, dataMany); | |
1018 } | |
1019 | |
1020 TEST_F(ScrollAnimatorTest, VaryingInputsEquivalencyCoastSteep) | |
1021 { | |
1022 ScrollAnimator::Parameters parameters(true, 15 * kTickTime, 10 * kTickTime,
ScrollAnimator::Cubic, 5 * kTickTime, ScrollAnimator::Cubic, 5 * kTickTime, Scro
llAnimator::Quadratic, 1); | |
1023 | |
1024 reset(); | |
1025 EXPECT_TRUE(updateDataFromParameters(1, 30000, 50000, kStartTime, ¶meter
s)); | |
1026 SavePerAxisData dataSingle(*m_data); | |
1027 | |
1028 reset(); | |
1029 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime, ¶meter
s)); | |
1030 EXPECT_TRUE(updateDataFromParameters(1, 15000, 50000, kStartTime, ¶meter
s)); | |
1031 SavePerAxisData dataDouble(*m_data); | |
1032 | |
1033 reset(); | |
1034 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime, ¶meter
s)); | |
1035 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime, ¶meter
s)); | |
1036 EXPECT_TRUE(updateDataFromParameters(1, 10000, 50000, kStartTime, ¶meter
s)); | |
1037 SavePerAxisData dataTriple(*m_data); | |
1038 | |
1039 reset(); | |
1040 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime, ¶meters
)); | |
1041 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime, ¶meters
)); | |
1042 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime, ¶meters
)); | |
1043 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime, ¶meters
)); | |
1044 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime, ¶meters
)); | |
1045 EXPECT_TRUE(updateDataFromParameters(1, 5000, 50000, kStartTime, ¶meters
)); | |
1046 SavePerAxisData dataMany(*m_data); | |
1047 | |
1048 EXPECT_EQ(dataSingle, dataDouble); | |
1049 EXPECT_EQ(dataSingle, dataTriple); | |
1050 EXPECT_EQ(dataSingle, dataMany); | |
1051 } | |
1052 | |
1053 TEST_F(ScrollAnimatorTest, ScrollStopInMiddle) | |
1054 { | |
1055 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Li
near, 0); | |
1056 | |
1057 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
1058 bool result = true; | |
1059 double t; | |
1060 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
1061 result = animateScroll(t); | |
1062 | |
1063 result = result && animateScroll(t); | |
1064 EXPECT_TRUE(result); | |
1065 double before = m_currentPosition; | |
1066 result = result && updateDataFromParameters(0, 0, 1000, t, ¶meters); | |
1067 EXPECT_FALSE(result); | |
1068 result = result && animateScroll(t); | |
1069 double after = m_currentPosition; | |
1070 EXPECT_EQ(before, after); | |
1071 checkDesiredPosition(after); | |
1072 } | |
1073 | |
1074 TEST_F(ScrollAnimatorTest, ReverseInMiddle) | |
1075 { | |
1076 ScrollAnimator::Parameters parameters(true, 7 * kTickTime, 0, ScrollAnimator
::Cubic, 3 * kTickTime, ScrollAnimator::Cubic, 3 * kTickTime, ScrollAnimator::Li
near, 0); | |
1077 | |
1078 EXPECT_TRUE(updateDataFromParameters(1, 40, 1000, kStartTime, ¶meters)); | |
1079 bool result = true; | |
1080 double t; | |
1081 for (t = kStartTime; result && t < kStartTime + 1.5 * kTickTime; t += kAnima
tionTime) | |
1082 result = animateScroll(t); | |
1083 | |
1084 result = result && animateScroll(t); | |
1085 EXPECT_TRUE(result); | |
1086 double before = m_currentPosition; | |
1087 result = result && updateDataFromParameters(1, -10, 1000, t, ¶meters); | |
1088 EXPECT_TRUE(result); | |
1089 result = result && animateScroll(t); | |
1090 double after = m_currentPosition; | |
1091 EXPECT_GE(before, after); | |
1092 | |
1093 t += kAnimationTime; | |
1094 for (; result && t < kEndTime; t += kAnimationTime) | |
1095 result = result && animateScroll(t); | |
1096 EXPECT_GE(before, m_currentPosition); | |
1097 } | |
1098 | |
1099 } // namespace blink | |
OLD | NEW |