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

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

Issue 1770443002: Takeover MT initiated animations from the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits fix failing bots Created 4 years, 9 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 ScrollableArea::trace(visitor); 87 ScrollableArea::trace(visitor);
88 } 88 }
89 89
90 private: 90 private:
91 explicit MockScrollableArea(bool scrollAnimatorEnabled) 91 explicit MockScrollableArea(bool scrollAnimatorEnabled)
92 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } 92 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { }
93 93
94 bool m_scrollAnimatorEnabled; 94 bool m_scrollAnimatorEnabled;
95 }; 95 };
96 96
97 class TestScrollAnimator : public ScrollAnimator {
98 public:
99 explicit TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunctio n timingFunction = WTF::monotonicallyIncreasingTime)
jbroman 2016/03/07 18:38:41 This is never constructed with the default argumen
ymalik 2016/03/07 21:26:07 Done.
100 : ScrollAnimator(scrollableArea, timingFunction) {};
101 ~TestScrollAnimator() override {};
102
103 void setShouldSendToCompositor(bool send)
104 {
105 m_shouldSendToCompositor = send;
106 }
107
108 bool sendAnimationToCompositor() override
109 {
110 if (m_shouldSendToCompositor) {
111 m_runState = ScrollAnimatorCompositorCoordinator::RunState::RunningO nCompositor;
112 m_compositorAnimationId = 1;
113 return true;
114 }
115 return false;
116 }
117
118 protected:
119 void abortAnimation() override {};
jbroman 2016/03/07 18:38:41 nit: superfluous semicolon
120
121 private:
122 bool m_shouldSendToCompositor = false;
123 };
124
97 } // namespace 125 } // namespace
98 126
99 static void reset(ScrollAnimator& scrollAnimator) 127 static void reset(ScrollAnimator& scrollAnimator)
100 { 128 {
101 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); 129 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint());
102 } 130 }
103 131
104 // TODO(skobes): Add unit tests for composited scrolling paths. 132 // TODO(skobes): Add unit tests for composited scrolling paths.
105 133
106 TEST(ScrollAnimatorTest, MainThreadStates) 134 TEST(ScrollAnimatorTest, MainThreadStates)
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 EXPECT_TRUE(result.didScrollX); 297 EXPECT_TRUE(result.didScrollX);
270 gMockedTime += 0.05; 298 gMockedTime += 0.05;
271 scrollAnimator->updateCompositorAnimations(); 299 scrollAnimator->updateCompositorAnimations();
272 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); 300 EXPECT_FALSE(scrollAnimator->hasRunningAnimation());
273 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x()); 301 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x());
274 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 302 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
275 303
276 reset(*scrollAnimator); 304 reset(*scrollAnimator);
277 } 305 }
278 306
307 // Test that a smooth scroll offset animation running on the compositor is
308 // completed on the main thread.
309 TEST(ScrollAnimatorTest, AnimatedScrollTakeover)
310 {
311 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea =
312 MockScrollableArea::create(true);
313 OwnPtrWillBeRawPtr<TestScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(
314 new TestScrollAnimator(scrollableArea.get(), getMockedTime));
315
316 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
317 .WillRepeatedly(Return(IntPoint()));
318 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
319 .WillRepeatedly(Return(IntPoint(1000, 1000)));
320 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3);
jbroman 2016/03/07 18:38:41 It's not entirely obvious to me why we should expe
ymalik 2016/03/07 21:26:07 Actually setScrollOffset is called 2 times, and re
jbroman 2016/03/07 21:33:17 Yeah, you'll have to make sure your mock object is
321 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4);
322 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
323 .WillRepeatedly(Return(true));
324
325 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
326
327 // Smooth scroll.
328 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100 , 0));
329 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService());
330 EXPECT_TRUE(result.didScrollX);
331 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX);
332 EXPECT_TRUE(scrollAnimator->hasRunningAnimation());
333
334 // Update compositor animation.
335 gMockedTime += 0.05;
336 scrollAnimator->setShouldSendToCompositor(true);
337 scrollAnimator->updateCompositorAnimations();
338 EXPECT_EQ(scrollAnimator->m_runState,
339 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor);
340
341 // Takeover.
342 scrollAnimator->takeoverCompositorAnimation();
343 EXPECT_EQ(scrollAnimator->m_runState,
344 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositorButNee dsTakeover);
345
346 // Animation should now be running on the main thread.
347 scrollAnimator->setShouldSendToCompositor(false);
348 scrollAnimator->updateCompositorAnimations();
349 EXPECT_EQ(scrollAnimator->m_runState,
350 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread);
351 scrollAnimator->tickAnimation(getMockedTime());
352 EXPECT_NE(100, scrollAnimator->currentPosition().x());
353 EXPECT_NE(0, scrollAnimator->currentPosition().x());
354 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
355 reset(*scrollAnimator);
356 }
357
279 TEST(ScrollAnimatorTest, Disabled) 358 TEST(ScrollAnimatorTest, Disabled)
280 { 359 {
281 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false); 360 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false);
282 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime)); 361 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime));
283 362
284 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 363 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint()));
285 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000))); 364 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
286 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); 365 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8);
287 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); 366 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0);
288 367
(...skipping 12 matching lines...) Expand all
301 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 380 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
302 reset(*scrollAnimator); 381 reset(*scrollAnimator);
303 382
304 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); 383 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0));
305 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 384 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
306 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 385 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
307 reset(*scrollAnimator); 386 reset(*scrollAnimator);
308 } 387 }
309 388
310 } // namespace blink 389 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698