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

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

Issue 2015113003: Correctly update scroll offset animations in response to scroll anchoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollAnimatorCompositorCoordinator.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 MOCK_METHOD0(scheduleAnimation, bool()); 76 MOCK_METHOD0(scheduleAnimation, bool());
77 77
78 bool userInputScrollable(ScrollbarOrientation) const override { return true; } 78 bool userInputScrollable(ScrollbarOrientation) const override { return true; }
79 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } 79 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; }
80 IntPoint scrollPosition() const override { return IntPoint(); } 80 IntPoint scrollPosition() const override { return IntPoint(); }
81 int visibleHeight() const override { return 768; } 81 int visibleHeight() const override { return 768; }
82 int visibleWidth() const override { return 1024; } 82 int visibleWidth() const override { return 1024; }
83 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled ; } 83 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled ; }
84 int pageStep(ScrollbarOrientation) const override { return 0; } 84 int pageStep(ScrollbarOrientation) const override { return 0; }
85 85
86 void setScrollAnimator(ScrollAnimator* scrollAnimator)
87 {
88 animator = scrollAnimator;
89 }
90
91 DoublePoint scrollPositionDouble() const override
92 {
93 if (animator)
94 return animator->currentPosition();
95 return ScrollableArea::scrollPositionDouble();
96 }
97
98 void setScrollPosition(const DoublePoint& position, ScrollType type,
99 ScrollBehavior behavior = ScrollBehaviorInstant)
100 {
101 if (animator)
102 animator->setCurrentPosition(toFloatPoint(position));
103 ScrollableArea::setScrollPosition(position, type, behavior);
104 }
105
86 DEFINE_INLINE_VIRTUAL_TRACE() 106 DEFINE_INLINE_VIRTUAL_TRACE()
87 { 107 {
108 visitor->trace(animator);
88 ScrollableArea::trace(visitor); 109 ScrollableArea::trace(visitor);
89 } 110 }
90 111
91 private: 112 private:
92 explicit MockScrollableArea(bool scrollAnimatorEnabled) 113 explicit MockScrollableArea(bool scrollAnimatorEnabled)
93 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } 114 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { }
94 115
95 bool m_scrollAnimatorEnabled; 116 bool m_scrollAnimatorEnabled;
117 Member<ScrollAnimator> animator;
96 }; 118 };
97 119
98 class TestScrollAnimator : public ScrollAnimator { 120 class TestScrollAnimator : public ScrollAnimator {
99 public: 121 public:
100 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF unction) 122 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF unction)
101 : ScrollAnimator(scrollableArea, timingFunction) {}; 123 : ScrollAnimator(scrollableArea, timingFunction) {};
102 ~TestScrollAnimator() override {}; 124 ~TestScrollAnimator() override {};
103 125
104 void setShouldSendToCompositor(bool send) 126 void setShouldSendToCompositor(bool send)
105 { 127 {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 TestScrollAnimator* animator = new TestScrollAnimator(scrollableArea, getMoc kedTime); 549 TestScrollAnimator* animator = new TestScrollAnimator(scrollableArea, getMoc kedTime);
528 550
529 // From calls to adjust/takeoverImplOnlyScrollOffsetAnimation. 551 // From calls to adjust/takeoverImplOnlyScrollOffsetAnimation.
530 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); 552 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
531 553
532 // Verify that the adjustment update is cleared. 554 // Verify that the adjustment update is cleared.
533 EXPECT_EQ(animator->m_runState, ScrollAnimatorCompositorCoordinator::RunStat e::Idle); 555 EXPECT_EQ(animator->m_runState, ScrollAnimatorCompositorCoordinator::RunStat e::Idle);
534 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); 556 EXPECT_FALSE(animator->hasAnimationThatRequiresService());
535 EXPECT_TRUE(animator->implOnlyAnimationAdjustmentForTesting().isZero()); 557 EXPECT_TRUE(animator->implOnlyAnimationAdjustmentForTesting().isZero());
536 558
537 animator->adjustImplOnlyScrollOffsetAnimation(FloatSize(100.f, 100.f)); 559 animator->adjustImplOnlyScrollOffsetAnimation(IntSize(100, 100));
538 animator->adjustImplOnlyScrollOffsetAnimation(FloatSize(10.f, -10.f)); 560 animator->adjustImplOnlyScrollOffsetAnimation(IntSize(10, -10));
539 561
540 EXPECT_TRUE(animator->hasAnimationThatRequiresService()); 562 EXPECT_TRUE(animator->hasAnimationThatRequiresService());
541 EXPECT_EQ(FloatSize(110.f, 90.f), animator->implOnlyAnimationAdjustmentForTe sting()); 563 EXPECT_EQ(FloatSize(110, 90), animator->implOnlyAnimationAdjustmentForTestin g());
542 564
543 animator->updateCompositorAnimations(); 565 animator->updateCompositorAnimations();
544 566
545 EXPECT_EQ(animator->m_runState, ScrollAnimatorCompositorCoordinator::RunStat e::Idle); 567 EXPECT_EQ(animator->m_runState, ScrollAnimatorCompositorCoordinator::RunStat e::Idle);
546 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); 568 EXPECT_FALSE(animator->hasAnimationThatRequiresService());
547 EXPECT_TRUE(animator->implOnlyAnimationAdjustmentForTesting().isZero()); 569 EXPECT_TRUE(animator->implOnlyAnimationAdjustmentForTesting().isZero());
548 570
549 // Verify that the takeover update is cleared. 571 // Verify that the takeover update is cleared.
550 animator->takeOverImplOnlyScrollOffsetAnimation(); 572 animator->takeOverImplOnlyScrollOffsetAnimation();
551 EXPECT_TRUE(animator->hasAnimationThatRequiresService()); 573 EXPECT_TRUE(animator->hasAnimationThatRequiresService());
552 animator->updateCompositorAnimations(); 574 animator->updateCompositorAnimations();
553 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); 575 EXPECT_FALSE(animator->hasAnimationThatRequiresService());
554 576
555 // Forced GC in order to finalize objects depending on the mock object. 577 // Forced GC in order to finalize objects depending on the mock object.
556 ThreadHeap::collectAllGarbage(); 578 ThreadHeap::collectAllGarbage();
557 } 579 }
558 580
581 TEST(ScrollAnimatorTest, MainThreadAnimationTargetAdjustment)
582 {
583 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
584 ScrollAnimator* animator = new ScrollAnimator(scrollableArea, getMockedTime) ;
585 scrollableArea->setScrollAnimator(animator);
586
587 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
588 .WillRepeatedly(Return(IntPoint(-100, -100)));
589 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
590 .WillRepeatedly(Return(IntPoint(1000, 1000)));
591 // Twice from tickAnimation, once from reset, and once from
592 // adjustAnimationAndSetScrollPosition.
593 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(4);
594 // One from call to userScroll and one from updateCompositorAnimations.
595 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
596 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
597 .WillRepeatedly(Return(true));
598
599 // Idle
600 EXPECT_FALSE(animator->hasAnimationThatRequiresService());
601 EXPECT_EQ(FloatPoint(), animator->currentPosition());
602
603 // WaitingToSendToCompositor
604 animator->userScroll(ScrollByLine, FloatSize(100, 100));
605
606 // RunningOnMainThread
607 gMockedTime += 0.05;
608 animator->updateCompositorAnimations();
609 animator->tickAnimation(getMockedTime());
610 FloatPoint pos = animator->currentPosition();
611 EXPECT_EQ(FloatPoint(100, 100), animator->desiredTargetPosition());
612 EXPECT_GT(pos.x(), 0);
613 EXPECT_GT(pos.y(), 0);
614
615 // Adjustment
616 IntSize adjustment = IntSize(10, -10);
617 animator->adjustAnimationAndSetScrollPosition(adjustment, AnchoringScroll);
618 EXPECT_EQ(pos + FloatSize(adjustment), animator->currentPosition());
619 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition());
620
621 // Animation finished
622 gMockedTime += 1.0;
623 animator->updateCompositorAnimations();
624 animator->tickAnimation(getMockedTime());
625 EXPECT_EQ(FloatPoint(110, 90), animator->currentPosition());
626 reset(*animator);
627
628 // Forced GC in order to finalize objects depending on the mock object.
629 ThreadHeap::collectAllGarbage();
630 }
631
559 } // namespace blink 632 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollAnimatorCompositorCoordinator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698