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

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

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

Powered by Google App Engine
This is Rietveld 408576698