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

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

Issue 1860903002: Update Source/platform/ to assume Oilpan only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: back out ScrollAnimatorMac() accidental change 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GarbageCollectedFinalized<MockScrollableArea>, public ScrollableArea { 53 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>, public ScrollableArea {
54 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); 54 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea);
55 public: 55 public:
56 static RawPtr<MockScrollableArea> create(bool scrollAnimatorEnabled) 56 static MockScrollableArea* create(bool scrollAnimatorEnabled)
57 { 57 {
58 return 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));
(...skipping 60 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 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true) ; 137 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
138 RawPtr<ScrollAnimator> scrollAnimator = new ScrollAnimator(scrollableArea.ge t(), getMockedTime); 138 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke dTime);
139 139
140 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 140 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
141 .WillRepeatedly(Return(IntPoint())); 141 .WillRepeatedly(Return(IntPoint()));
142 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 142 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
143 .WillRepeatedly(Return(IntPoint(1000, 1000))); 143 .WillRepeatedly(Return(IntPoint(1000, 1000)));
144 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); 144 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2);
145 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); 145 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
146 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 146 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
147 .WillRepeatedly(Return(true)); 147 .WillRepeatedly(Return(true));
148 148
(...skipping 25 matching lines...) Expand all
174 scrollAnimator->updateCompositorAnimations(); 174 scrollAnimator->updateCompositorAnimations();
175 scrollAnimator->tickAnimation(getMockedTime()); 175 scrollAnimator->tickAnimation(getMockedTime());
176 EXPECT_EQ(scrollAnimator->m_runState, 176 EXPECT_EQ(scrollAnimator->m_runState,
177 ScrollAnimatorCompositorCoordinator::RunState::Idle); 177 ScrollAnimatorCompositorCoordinator::RunState::Idle);
178 178
179 reset(*scrollAnimator); 179 reset(*scrollAnimator);
180 } 180 }
181 181
182 TEST(ScrollAnimatorTest, MainThreadEnabled) 182 TEST(ScrollAnimatorTest, MainThreadEnabled)
183 { 183 {
184 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true) ; 184 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
185 RawPtr<ScrollAnimator> scrollAnimator = new ScrollAnimator(scrollableArea.ge t(), getMockedTime); 185 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke dTime);
186 186
187 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 187 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint()));
188 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000))); 188 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
189 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9); 189 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9);
190 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6); 190 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6);
191 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)).WillRepe atedly(Return(true)); 191 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)).WillRepe atedly(Return(true));
192 192
193 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 193 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
194 194
195 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(-10 0, 0)); 195 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(-10 0, 0));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 251 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
252 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 252 EXPECT_NE(0, scrollAnimator->currentPosition().x());
253 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 253 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
254 reset(*scrollAnimator); 254 reset(*scrollAnimator);
255 } 255 }
256 256
257 // Test that a smooth scroll offset animation is aborted when followed by a 257 // Test that a smooth scroll offset animation is aborted when followed by a
258 // non-smooth scroll offset animation. 258 // non-smooth scroll offset animation.
259 TEST(ScrollAnimatorTest, AnimatedScrollAborted) 259 TEST(ScrollAnimatorTest, AnimatedScrollAborted)
260 { 260 {
261 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true) ; 261 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
262 RawPtr<ScrollAnimator> scrollAnimator = new ScrollAnimator(scrollableArea.ge t(), getMockedTime); 262 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke dTime);
263 263
264 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 264 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
265 .WillRepeatedly(Return(IntPoint())); 265 .WillRepeatedly(Return(IntPoint()));
266 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 266 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
267 .WillRepeatedly(Return(IntPoint(1000, 1000))); 267 .WillRepeatedly(Return(IntPoint(1000, 1000)));
268 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); 268 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3);
269 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); 269 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
270 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 270 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
271 .WillRepeatedly(Return(true)); 271 .WillRepeatedly(Return(true));
272 272
(...skipping 25 matching lines...) Expand all
298 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x()); 298 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x());
299 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 299 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
300 300
301 reset(*scrollAnimator); 301 reset(*scrollAnimator);
302 } 302 }
303 303
304 // Test that a smooth scroll offset animation running on the compositor is 304 // Test that a smooth scroll offset animation running on the compositor is
305 // completed on the main thread. 305 // completed on the main thread.
306 TEST(ScrollAnimatorTest, AnimatedScrollTakeover) 306 TEST(ScrollAnimatorTest, AnimatedScrollTakeover)
307 { 307 {
308 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true) ; 308 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
309 RawPtr<TestScrollAnimator> scrollAnimator = new TestScrollAnimator(scrollabl eArea.get(), getMockedTime); 309 TestScrollAnimator* scrollAnimator = new TestScrollAnimator(scrollableArea, getMockedTime);
310 310
311 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 311 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
312 .WillRepeatedly(Return(IntPoint())); 312 .WillRepeatedly(Return(IntPoint()));
313 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 313 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
314 .WillRepeatedly(Return(IntPoint(1000, 1000))); 314 .WillRepeatedly(Return(IntPoint(1000, 1000)));
315 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); 315 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2);
316 // Called from userScroll, updateCompositorAnimations, then 316 // Called from userScroll, updateCompositorAnimations, then
317 // takeoverCompositorAnimation (to re-register after RunningOnCompositor). 317 // takeoverCompositorAnimation (to re-register after RunningOnCompositor).
318 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); 318 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
319 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 319 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
(...skipping 27 matching lines...) Expand all
347 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); 347 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread);
348 scrollAnimator->tickAnimation(getMockedTime()); 348 scrollAnimator->tickAnimation(getMockedTime());
349 EXPECT_NE(100, scrollAnimator->currentPosition().x()); 349 EXPECT_NE(100, scrollAnimator->currentPosition().x());
350 EXPECT_NE(0, scrollAnimator->currentPosition().x()); 350 EXPECT_NE(0, scrollAnimator->currentPosition().x());
351 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 351 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
352 reset(*scrollAnimator); 352 reset(*scrollAnimator);
353 } 353 }
354 354
355 TEST(ScrollAnimatorTest, Disabled) 355 TEST(ScrollAnimatorTest, Disabled)
356 { 356 {
357 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(false ); 357 MockScrollableArea* scrollableArea = MockScrollableArea::create(false);
358 RawPtr<ScrollAnimator> scrollAnimator = new ScrollAnimator(scrollableArea.ge t(), getMockedTime); 358 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke dTime);
359 359
360 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 360 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint()));
361 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000))); 361 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
362 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); 362 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8);
363 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); 363 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0);
364 364
365 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); 365 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0));
366 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 366 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
367 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 367 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
368 reset(*scrollAnimator); 368 reset(*scrollAnimator);
(...skipping 11 matching lines...) Expand all
380 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); 380 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0));
381 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 381 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
382 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 382 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
383 reset(*scrollAnimator); 383 reset(*scrollAnimator);
384 } 384 }
385 385
386 // Test that cancelling an animation resets the animation state. 386 // Test that cancelling an animation resets the animation state.
387 // See crbug.com/598548. 387 // See crbug.com/598548.
388 TEST(ScrollAnimatorTest, CancellingAnimationResetsState) 388 TEST(ScrollAnimatorTest, CancellingAnimationResetsState)
389 { 389 {
390 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true) ; 390 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
391 RawPtr<ScrollAnimator> scrollAnimator = new ScrollAnimator(scrollableArea.ge t(), getMockedTime); 391 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke dTime);
392 392
393 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 393 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
394 .WillRepeatedly(Return(IntPoint())); 394 .WillRepeatedly(Return(IntPoint()));
395 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 395 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
396 .WillRepeatedly(Return(IntPoint(1000, 1000))); 396 .WillRepeatedly(Return(IntPoint(1000, 1000)));
397 // Called from first userScroll, setCurrentPosition, and second userScroll. 397 // Called from first userScroll, setCurrentPosition, and second userScroll.
398 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); 398 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3);
399 // Called from userScroll, updateCompositorAnimations. 399 // Called from userScroll, updateCompositorAnimations.
400 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); 400 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4);
401 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 401 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 441
442 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x()); 442 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x());
443 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 443 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
444 reset(*scrollAnimator); 444 reset(*scrollAnimator);
445 } 445 }
446 446
447 // Test the behavior when in WaitingToCancelOnCompositor and a new user scroll 447 // Test the behavior when in WaitingToCancelOnCompositor and a new user scroll
448 // happens. 448 // happens.
449 TEST(ScrollAnimatorTest, CancellingCompositorAnimation) 449 TEST(ScrollAnimatorTest, CancellingCompositorAnimation)
450 { 450 {
451 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true) ; 451 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
452 RawPtr<TestScrollAnimator> scrollAnimator = new TestScrollAnimator(scrollabl eArea.get(), getMockedTime); 452 TestScrollAnimator* scrollAnimator = new TestScrollAnimator(scrollableArea, getMockedTime);
453 453
454 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) 454 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
455 .WillRepeatedly(Return(IntPoint())); 455 .WillRepeatedly(Return(IntPoint()));
456 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) 456 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
457 .WillRepeatedly(Return(IntPoint(1000, 1000))); 457 .WillRepeatedly(Return(IntPoint(1000, 1000)));
458 // Called when reset, not setting anywhere else. 458 // Called when reset, not setting anywhere else.
459 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(1); 459 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(1);
460 // Called from first and last user scroll, and first update. 460 // Called from first and last user scroll, and first update.
461 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); 461 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
462 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) 462 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor ); 511 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor );
512 EXPECT_EQ(100, scrollAnimator->desiredTargetPosition().x()); 512 EXPECT_EQ(100, scrollAnimator->desiredTargetPosition().x());
513 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y()); 513 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y());
514 reset(*scrollAnimator); 514 reset(*scrollAnimator);
515 515
516 // Forced GC in order to finalize objects depending on the mock object. 516 // Forced GC in order to finalize objects depending on the mock object.
517 Heap::collectAllGarbage(); 517 Heap::collectAllGarbage();
518 } 518 }
519 519
520 } // namespace blink 520 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698