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