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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 static double gMockedTime = 0.0; 44 static double gMockedTime = 0.0;
45 45
46 static double getMockedTime() 46 static double getMockedTime()
47 { 47 {
48 return gMockedTime; 48 return gMockedTime;
49 } 49 }
50 50
51 namespace { 51 namespace {
52 52
53 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro llableArea>, public ScrollableArea { 53 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>, public ScrollableArea {
54 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); 54 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea);
55 public: 55 public:
56 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(bool scrollAnimator Enabled) 56 static RawPtr<MockScrollableArea> create(bool scrollAnimatorEnabled)
57 { 57 {
58 return adoptPtrWillBeNoop(new MockScrollableArea(scrollAnimatorEnabled)) ; 58 return new MockScrollableArea(scrollAnimatorEnabled);
59 } 59 }
60 60
61 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect()); 61 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect());
62 MOCK_CONST_METHOD0(isActive, bool()); 62 MOCK_CONST_METHOD0(isActive, bool());
63 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); 63 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation));
64 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); 64 MOCK_CONST_METHOD0(isScrollCornerVisible, bool());
65 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); 65 MOCK_CONST_METHOD0(scrollCornerRect, IntRect());
66 MOCK_METHOD2(setScrollOffset, void(const DoublePoint&, ScrollType)); 66 MOCK_METHOD2(setScrollOffset, void(const DoublePoint&, ScrollType));
67 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); 67 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void());
68 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); 68 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 static void reset(ScrollAnimator& scrollAnimator) 128 static void reset(ScrollAnimator& scrollAnimator)
129 { 129 {
130 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); 130 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint());
131 } 131 }
132 132
133 // TODO(skobes): Add unit tests for composited scrolling paths. 133 // TODO(skobes): Add unit tests for composited scrolling paths.
134 134
135 TEST(ScrollAnimatorTest, MainThreadStates) 135 TEST(ScrollAnimatorTest, MainThreadStates)
136 { 136 {
137 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = 137 RawPtr<MockScrollableArea> scrollableArea =
138 MockScrollableArea::create(true); 138 MockScrollableArea::create(true);
139 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop( 139 RawPtr<ScrollAnimator> scrollAnimator =
140 new ScrollAnimator(scrollableArea.get(), getMockedTime)); 140 new ScrollAnimator(scrollableArea.get(), getMockedTime);
141 141
142 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 142 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
143 .WillRepeatedly(Return(IntPoint())); 143 .WillRepeatedly(Return(IntPoint()));
144 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 144 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
145 .WillRepeatedly(Return(IntPoint(1000, 1000))); 145 .WillRepeatedly(Return(IntPoint(1000, 1000)));
146 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); 146 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2);
147 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); 147 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
148 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 148 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
149 .WillRepeatedly(Return(true)); 149 .WillRepeatedly(Return(true));
150 150
(...skipping 25 matching lines...) Expand all
176 scrollAnimator->updateCompositorAnimations(); 176 scrollAnimator->updateCompositorAnimations();
177 scrollAnimator->tickAnimation(getMockedTime()); 177 scrollAnimator->tickAnimation(getMockedTime());
178 EXPECT_EQ(scrollAnimator->m_runState, 178 EXPECT_EQ(scrollAnimator->m_runState,
179 ScrollAnimatorCompositorCoordinator::RunState::Idle); 179 ScrollAnimatorCompositorCoordinator::RunState::Idle);
180 180
181 reset(*scrollAnimator); 181 reset(*scrollAnimator);
182 } 182 }
183 183
184 TEST(ScrollAnimatorTest, MainThreadEnabled) 184 TEST(ScrollAnimatorTest, MainThreadEnabled)
185 { 185 {
186 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(true); 186 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true) ;
187 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime)); 187 RawPtr<ScrollAnimator> scrollAnimator = new ScrollAnimator(scrollableArea.ge t(), getMockedTime);
188 188
189 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 189 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint()));
190 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000))); 190 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
191 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9); 191 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9);
192 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6); 192 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6);
193 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)).WillRepe atedly(Return(true)); 193 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)).WillRepe atedly(Return(true));
194 194
195 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 195 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
196 196
197 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(-10 0, 0)); 197 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(-10 0, 0));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 253 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
254 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 254 EXPECT_NE(0, scrollAnimator->currentPosition().x());
255 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 255 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
256 reset(*scrollAnimator); 256 reset(*scrollAnimator);
257 } 257 }
258 258
259 // Test that a smooth scroll offset animation is aborted when followed by a 259 // Test that a smooth scroll offset animation is aborted when followed by a
260 // non-smooth scroll offset animation. 260 // non-smooth scroll offset animation.
261 TEST(ScrollAnimatorTest, AnimatedScrollAborted) 261 TEST(ScrollAnimatorTest, AnimatedScrollAborted)
262 { 262 {
263 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = 263 RawPtr<MockScrollableArea> scrollableArea =
264 MockScrollableArea::create(true); 264 MockScrollableArea::create(true);
265 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop( 265 RawPtr<ScrollAnimator> scrollAnimator =
266 new ScrollAnimator(scrollableArea.get(), getMockedTime)); 266 new ScrollAnimator(scrollableArea.get(), getMockedTime);
267 267
268 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 268 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
269 .WillRepeatedly(Return(IntPoint())); 269 .WillRepeatedly(Return(IntPoint()));
270 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 270 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
271 .WillRepeatedly(Return(IntPoint(1000, 1000))); 271 .WillRepeatedly(Return(IntPoint(1000, 1000)));
272 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); 272 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3);
273 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); 273 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
274 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 274 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
275 .WillRepeatedly(Return(true)); 275 .WillRepeatedly(Return(true));
276 276
(...skipping 25 matching lines...) Expand all
302 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x()); 302 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x());
303 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 303 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
304 304
305 reset(*scrollAnimator); 305 reset(*scrollAnimator);
306 } 306 }
307 307
308 // Test that a smooth scroll offset animation running on the compositor is 308 // Test that a smooth scroll offset animation running on the compositor is
309 // completed on the main thread. 309 // completed on the main thread.
310 TEST(ScrollAnimatorTest, AnimatedScrollTakeover) 310 TEST(ScrollAnimatorTest, AnimatedScrollTakeover)
311 { 311 {
312 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = 312 RawPtr<MockScrollableArea> scrollableArea =
313 MockScrollableArea::create(true); 313 MockScrollableArea::create(true);
314 OwnPtrWillBeRawPtr<TestScrollAnimator> scrollAnimator = adoptPtrWillBeNoop( 314 RawPtr<TestScrollAnimator> scrollAnimator =
315 new TestScrollAnimator(scrollableArea.get(), getMockedTime)); 315 new TestScrollAnimator(scrollableArea.get(), getMockedTime);
316 316
317 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 317 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
318 .WillRepeatedly(Return(IntPoint())); 318 .WillRepeatedly(Return(IntPoint()));
319 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 319 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
320 .WillRepeatedly(Return(IntPoint(1000, 1000))); 320 .WillRepeatedly(Return(IntPoint(1000, 1000)));
321 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); 321 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2);
322 // Called from userScroll, updateCompositorAnimations, then 322 // Called from userScroll, updateCompositorAnimations, then
323 // takeoverCompositorAnimation (to re-register after RunningOnCompositor). 323 // takeoverCompositorAnimation (to re-register after RunningOnCompositor).
324 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); 324 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
325 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 325 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
(...skipping 27 matching lines...) Expand all
353 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); 353 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread);
354 scrollAnimator->tickAnimation(getMockedTime()); 354 scrollAnimator->tickAnimation(getMockedTime());
355 EXPECT_NE(100, scrollAnimator->currentPosition().x()); 355 EXPECT_NE(100, scrollAnimator->currentPosition().x());
356 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 356 EXPECT_NE(0, scrollAnimator->currentPosition().x());
357 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 357 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
358 reset(*scrollAnimator); 358 reset(*scrollAnimator);
359 } 359 }
360 360
361 TEST(ScrollAnimatorTest, Disabled) 361 TEST(ScrollAnimatorTest, Disabled)
362 { 362 {
363 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false); 363 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(false );
364 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime)); 364 RawPtr<ScrollAnimator> scrollAnimator = new ScrollAnimator(scrollableArea.ge t(), getMockedTime);
365 365
366 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 366 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint()));
367 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000))); 367 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
368 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); 368 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8);
369 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); 369 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0);
370 370
371 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); 371 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0));
372 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 372 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
373 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 373 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
374 reset(*scrollAnimator); 374 reset(*scrollAnimator);
(...skipping 11 matching lines...) Expand all
386 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); 386 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0));
387 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 387 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
388 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 388 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
389 reset(*scrollAnimator); 389 reset(*scrollAnimator);
390 } 390 }
391 391
392 // Test that cancelling an animation resets the animation state. 392 // Test that cancelling an animation resets the animation state.
393 // See crbug.com/598548. 393 // See crbug.com/598548.
394 TEST(ScrollAnimatorTest, CancellingAnimationResetsState) 394 TEST(ScrollAnimatorTest, CancellingAnimationResetsState)
395 { 395 {
396 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = 396 RawPtr<MockScrollableArea> scrollableArea =
397 MockScrollableArea::create(true); 397 MockScrollableArea::create(true);
398 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop( 398 RawPtr<ScrollAnimator> scrollAnimator =
399 new ScrollAnimator(scrollableArea.get(), getMockedTime)); 399 new ScrollAnimator(scrollableArea.get(), getMockedTime);
400 400
401 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 401 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
402 .WillRepeatedly(Return(IntPoint())); 402 .WillRepeatedly(Return(IntPoint()));
403 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 403 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
404 .WillRepeatedly(Return(IntPoint(1000, 1000))); 404 .WillRepeatedly(Return(IntPoint(1000, 1000)));
405 // Called from first userScroll, setCurrentPosition, and second userScroll. 405 // Called from first userScroll, setCurrentPosition, and second userScroll.
406 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); 406 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3);
407 // Called from userScroll, updateCompositorAnimations. 407 // Called from userScroll, updateCompositorAnimations.
408 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); 408 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4);
409 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 409 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 scrollAnimator->tickAnimation(getMockedTime()); 446 scrollAnimator->tickAnimation(getMockedTime());
447 EXPECT_EQ(scrollAnimator->m_runState, 447 EXPECT_EQ(scrollAnimator->m_runState,
448 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); 448 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup);
449 449
450 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x()); 450 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x());
451 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 451 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
452 reset(*scrollAnimator); 452 reset(*scrollAnimator);
453 } 453 }
454 454
455 } // namespace blink 455 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698