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

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

Issue 2383113003: Refactor ScrollableArea::setScrollPosition. (Closed)
Patch Set: Created 4 years, 2 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 public: 55 public:
56 static MockScrollableArea* create(bool scrollAnimatorEnabled) { 56 static MockScrollableArea* create(bool scrollAnimatorEnabled) {
57 return new MockScrollableArea(scrollAnimatorEnabled); 57 return new MockScrollableArea(scrollAnimatorEnabled);
58 } 58 }
59 59
60 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect()); 60 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect());
61 MOCK_CONST_METHOD0(isActive, bool()); 61 MOCK_CONST_METHOD0(isActive, bool());
62 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); 62 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation));
63 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); 63 MOCK_CONST_METHOD0(isScrollCornerVisible, bool());
64 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); 64 MOCK_CONST_METHOD0(scrollCornerRect, IntRect());
65 MOCK_METHOD2(setScrollOffset, void(const DoublePoint&, ScrollType)); 65 MOCK_METHOD2(updateScrollPosition, void(const DoublePoint&, ScrollType));
66 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); 66 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void());
67 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); 67 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*());
68 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); 68 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint());
69 MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint()); 69 MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint());
70 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); 70 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect));
71 MOCK_CONST_METHOD0(contentsSize, IntSize()); 71 MOCK_CONST_METHOD0(contentsSize, IntSize());
72 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); 72 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool());
73 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); 73 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect());
74 MOCK_METHOD0(registerForAnimation, void()); 74 MOCK_METHOD0(registerForAnimation, void());
75 MOCK_METHOD0(scheduleAnimation, bool()); 75 MOCK_METHOD0(scheduleAnimation, bool());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); 153 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
154 ScrollAnimator* scrollAnimator = 154 ScrollAnimator* scrollAnimator =
155 new ScrollAnimator(scrollableArea, getMockedTime); 155 new ScrollAnimator(scrollableArea, getMockedTime);
156 156
157 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 157 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
158 .Times(AtLeast(1)) 158 .Times(AtLeast(1))
159 .WillRepeatedly(Return(IntPoint())); 159 .WillRepeatedly(Return(IntPoint()));
160 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 160 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
161 .Times(AtLeast(1)) 161 .Times(AtLeast(1))
162 .WillRepeatedly(Return(IntPoint(1000, 1000))); 162 .WillRepeatedly(Return(IntPoint(1000, 1000)));
163 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); 163 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(2);
164 // Once from userScroll, once from updateCompositorAnimations. 164 // Once from userScroll, once from updateCompositorAnimations.
165 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); 165 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
166 EXPECT_CALL(*scrollableArea, scheduleAnimation()) 166 EXPECT_CALL(*scrollableArea, scheduleAnimation())
167 .Times(AtLeast(1)) 167 .Times(AtLeast(1))
168 .WillRepeatedly(Return(true)); 168 .WillRepeatedly(Return(true));
169 169
170 // Idle 170 // Idle
171 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 171 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
172 EXPECT_EQ(scrollAnimator->m_runState, 172 EXPECT_EQ(scrollAnimator->m_runState,
173 ScrollAnimatorCompositorCoordinator::RunState::Idle); 173 ScrollAnimatorCompositorCoordinator::RunState::Idle);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); 209 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
210 ScrollAnimator* scrollAnimator = 210 ScrollAnimator* scrollAnimator =
211 new ScrollAnimator(scrollableArea, getMockedTime); 211 new ScrollAnimator(scrollableArea, getMockedTime);
212 212
213 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 213 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
214 .Times(AtLeast(1)) 214 .Times(AtLeast(1))
215 .WillRepeatedly(Return(IntPoint())); 215 .WillRepeatedly(Return(IntPoint()));
216 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 216 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
217 .Times(AtLeast(1)) 217 .Times(AtLeast(1))
218 .WillRepeatedly(Return(IntPoint(1000, 1000))); 218 .WillRepeatedly(Return(IntPoint(1000, 1000)));
219 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9); 219 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(9);
220 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6); 220 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6);
221 EXPECT_CALL(*scrollableArea, scheduleAnimation()) 221 EXPECT_CALL(*scrollableArea, scheduleAnimation())
222 .Times(AtLeast(1)) 222 .Times(AtLeast(1))
223 .WillRepeatedly(Return(true)); 223 .WillRepeatedly(Return(true));
224 224
225 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 225 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
226 226
227 ScrollResult result = 227 ScrollResult result =
228 scrollAnimator->userScroll(ScrollByLine, FloatSize(-100, 0)); 228 scrollAnimator->userScroll(ScrollByLine, FloatSize(-100, 0));
229 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 229 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); 293 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
294 ScrollAnimator* scrollAnimator = 294 ScrollAnimator* scrollAnimator =
295 new ScrollAnimator(scrollableArea, getMockedTime); 295 new ScrollAnimator(scrollableArea, getMockedTime);
296 296
297 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 297 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
298 .Times(AtLeast(1)) 298 .Times(AtLeast(1))
299 .WillRepeatedly(Return(IntPoint())); 299 .WillRepeatedly(Return(IntPoint()));
300 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 300 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
301 .Times(AtLeast(1)) 301 .Times(AtLeast(1))
302 .WillRepeatedly(Return(IntPoint(1000, 1000))); 302 .WillRepeatedly(Return(IntPoint(1000, 1000)));
303 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); 303 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(3);
304 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); 304 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
305 EXPECT_CALL(*scrollableArea, scheduleAnimation()) 305 EXPECT_CALL(*scrollableArea, scheduleAnimation())
306 .Times(AtLeast(1)) 306 .Times(AtLeast(1))
307 .WillRepeatedly(Return(true)); 307 .WillRepeatedly(Return(true));
308 308
309 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 309 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
310 310
311 // Smooth scroll. 311 // Smooth scroll.
312 ScrollResult result = 312 ScrollResult result =
313 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); 313 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0));
(...skipping 30 matching lines...) Expand all
344 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); 344 MockScrollableArea* scrollableArea = MockScrollableArea::create(true);
345 TestScrollAnimator* scrollAnimator = 345 TestScrollAnimator* scrollAnimator =
346 new TestScrollAnimator(scrollableArea, getMockedTime); 346 new TestScrollAnimator(scrollableArea, getMockedTime);
347 347
348 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 348 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
349 .Times(AtLeast(1)) 349 .Times(AtLeast(1))
350 .WillRepeatedly(Return(IntPoint())); 350 .WillRepeatedly(Return(IntPoint()));
351 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 351 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
352 .Times(AtLeast(1)) 352 .Times(AtLeast(1))
353 .WillRepeatedly(Return(IntPoint(1000, 1000))); 353 .WillRepeatedly(Return(IntPoint(1000, 1000)));
354 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); 354 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(2);
355 // Called from userScroll, updateCompositorAnimations, then 355 // Called from userScroll, updateCompositorAnimations, then
356 // takeOverCompositorAnimation (to re-register after RunningOnCompositor). 356 // takeOverCompositorAnimation (to re-register after RunningOnCompositor).
357 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); 357 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
358 EXPECT_CALL(*scrollableArea, scheduleAnimation()) 358 EXPECT_CALL(*scrollableArea, scheduleAnimation())
359 .Times(AtLeast(1)) 359 .Times(AtLeast(1))
360 .WillRepeatedly(Return(true)); 360 .WillRepeatedly(Return(true));
361 361
362 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 362 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
363 363
364 // Smooth scroll. 364 // Smooth scroll.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 MockScrollableArea* scrollableArea = MockScrollableArea::create(false); 398 MockScrollableArea* scrollableArea = MockScrollableArea::create(false);
399 ScrollAnimator* scrollAnimator = 399 ScrollAnimator* scrollAnimator =
400 new ScrollAnimator(scrollableArea, getMockedTime); 400 new ScrollAnimator(scrollableArea, getMockedTime);
401 401
402 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 402 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
403 .Times(AtLeast(1)) 403 .Times(AtLeast(1))
404 .WillRepeatedly(Return(IntPoint())); 404 .WillRepeatedly(Return(IntPoint()));
405 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 405 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
406 .Times(AtLeast(1)) 406 .Times(AtLeast(1))
407 .WillRepeatedly(Return(IntPoint(1000, 1000))); 407 .WillRepeatedly(Return(IntPoint(1000, 1000)));
408 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); 408 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(8);
409 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); 409 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0);
410 410
411 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); 411 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0));
412 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 412 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
413 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 413 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
414 reset(*scrollAnimator); 414 reset(*scrollAnimator);
415 415
416 scrollAnimator->userScroll(ScrollByPage, FloatSize(100, 0)); 416 scrollAnimator->userScroll(ScrollByPage, FloatSize(100, 0));
417 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 417 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
418 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 418 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
(...skipping 17 matching lines...) Expand all
436 ScrollAnimator* scrollAnimator = 436 ScrollAnimator* scrollAnimator =
437 new ScrollAnimator(scrollableArea, getMockedTime); 437 new ScrollAnimator(scrollableArea, getMockedTime);
438 438
439 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 439 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
440 .Times(AtLeast(1)) 440 .Times(AtLeast(1))
441 .WillRepeatedly(Return(IntPoint())); 441 .WillRepeatedly(Return(IntPoint()));
442 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 442 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
443 .Times(AtLeast(1)) 443 .Times(AtLeast(1))
444 .WillRepeatedly(Return(IntPoint(1000, 1000))); 444 .WillRepeatedly(Return(IntPoint(1000, 1000)));
445 // Called from first userScroll, setCurrentPosition, and second userScroll. 445 // Called from first userScroll, setCurrentPosition, and second userScroll.
446 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); 446 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(3);
447 // Called from userScroll, updateCompositorAnimations. 447 // Called from userScroll, updateCompositorAnimations.
448 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); 448 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4);
449 EXPECT_CALL(*scrollableArea, scheduleAnimation()) 449 EXPECT_CALL(*scrollableArea, scheduleAnimation())
450 .Times(AtLeast(1)) 450 .Times(AtLeast(1))
451 .WillRepeatedly(Return(true)); 451 .WillRepeatedly(Return(true));
452 452
453 EXPECT_EQ(0, scrollAnimator->currentPosition().x()); 453 EXPECT_EQ(0, scrollAnimator->currentPosition().x());
454 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 454 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
455 455
456 // WaitingToSendToCompositor 456 // WaitingToSendToCompositor
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 TestScrollAnimator* scrollAnimator = 504 TestScrollAnimator* scrollAnimator =
505 new TestScrollAnimator(scrollableArea, getMockedTime); 505 new TestScrollAnimator(scrollableArea, getMockedTime);
506 506
507 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 507 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
508 .Times(AtLeast(1)) 508 .Times(AtLeast(1))
509 .WillRepeatedly(Return(IntPoint())); 509 .WillRepeatedly(Return(IntPoint()));
510 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 510 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
511 .Times(AtLeast(1)) 511 .Times(AtLeast(1))
512 .WillRepeatedly(Return(IntPoint(1000, 1000))); 512 .WillRepeatedly(Return(IntPoint(1000, 1000)));
513 // Called when reset, not setting anywhere else. 513 // Called when reset, not setting anywhere else.
514 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(1); 514 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(1);
515 // Called from userScroll, and first update. 515 // Called from userScroll, and first update.
516 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); 516 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4);
517 EXPECT_CALL(*scrollableArea, scheduleAnimation()) 517 EXPECT_CALL(*scrollableArea, scheduleAnimation())
518 .Times(AtLeast(1)) 518 .Times(AtLeast(1))
519 .WillRepeatedly(Return(true)); 519 .WillRepeatedly(Return(true));
520 520
521 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); 521 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
522 522
523 // First user scroll. 523 // First user scroll.
524 ScrollResult result = 524 ScrollResult result =
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 scrollableArea->setScrollAnimator(animator); 623 scrollableArea->setScrollAnimator(animator);
624 624
625 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) 625 EXPECT_CALL(*scrollableArea, minimumScrollPosition())
626 .Times(AtLeast(1)) 626 .Times(AtLeast(1))
627 .WillRepeatedly(Return(IntPoint(-100, -100))); 627 .WillRepeatedly(Return(IntPoint(-100, -100)));
628 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) 628 EXPECT_CALL(*scrollableArea, maximumScrollPosition())
629 .Times(AtLeast(1)) 629 .Times(AtLeast(1))
630 .WillRepeatedly(Return(IntPoint(1000, 1000))); 630 .WillRepeatedly(Return(IntPoint(1000, 1000)));
631 // Twice from tickAnimation, once from reset, and twice from 631 // Twice from tickAnimation, once from reset, and twice from
632 // adjustAnimationAndSetScrollPosition. 632 // adjustAnimationAndSetScrollPosition.
633 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(5); 633 EXPECT_CALL(*scrollableArea, updateScrollPosition(_, _)).Times(5);
634 // One from call to userScroll and one from updateCompositorAnimations. 634 // One from call to userScroll and one from updateCompositorAnimations.
635 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); 635 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2);
636 EXPECT_CALL(*scrollableArea, scheduleAnimation()) 636 EXPECT_CALL(*scrollableArea, scheduleAnimation())
637 .Times(AtLeast(1)) 637 .Times(AtLeast(1))
638 .WillRepeatedly(Return(true)); 638 .WillRepeatedly(Return(true));
639 639
640 // Idle 640 // Idle
641 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); 641 EXPECT_FALSE(animator->hasAnimationThatRequiresService());
642 EXPECT_EQ(FloatPoint(), animator->currentPosition()); 642 EXPECT_EQ(FloatPoint(), animator->currentPosition());
643 643
(...skipping 28 matching lines...) Expand all
672 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); 672 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup);
673 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition()); 673 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition());
674 674
675 reset(*animator); 675 reset(*animator);
676 676
677 // Forced GC in order to finalize objects depending on the mock object. 677 // Forced GC in order to finalize objects depending on the mock object.
678 ThreadState::current()->collectAllGarbage(); 678 ThreadState::current()->collectAllGarbage();
679 } 679 }
680 680
681 } // namespace blink 681 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698