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

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

Issue 1782563002: Takeover MT initiated animations from the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollAnimatorCompositorCoordinator.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF unction)
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 {}
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 EXPECT_TRUE(result.didScroll); 299 EXPECT_TRUE(result.didScroll);
272 gMockedTime += 0.05; 300 gMockedTime += 0.05;
273 scrollAnimator->updateCompositorAnimations(); 301 scrollAnimator->updateCompositorAnimations();
274 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); 302 EXPECT_FALSE(scrollAnimator->hasRunningAnimation());
275 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x()); 303 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x());
276 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 304 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
277 305
278 reset(*scrollAnimator); 306 reset(*scrollAnimator);
279 } 307 }
280 308
309 // Test that a smooth scroll offset animation running on the compositor is
310 // completed on the main thread.
311 TEST(ScrollAnimatorTest, AnimatedScrollTakeover)
312 {
313 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea =
314 MockScrollableArea::create(true);
315 OwnPtrWillBeRawPtr<TestScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(
316 new TestScrollAnimator(scrollableArea.get(), getMockedTime));
317
318 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1))
319 .WillRepeatedly(Return(IntPoint()));
320 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1))
321 .WillRepeatedly(Return(IntPoint(1000, 1000)));
322 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2);
323 // Called from userScroll, updateCompositorAnimations, then
324 // takeoverCompositorAnimation (to re-register after RunningOnCompositor).
325 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
326 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
327 .WillRepeatedly(Return(true));
328
329 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
330
331 // Smooth scroll.
332 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100 , 0));
333 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService());
334 EXPECT_TRUE(result.didScrollX);
335 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX);
336 EXPECT_TRUE(scrollAnimator->hasRunningAnimation());
337
338 // Update compositor animation.
339 gMockedTime += 0.05;
340 scrollAnimator->setShouldSendToCompositor(true);
341 scrollAnimator->updateCompositorAnimations();
342 EXPECT_EQ(scrollAnimator->m_runState,
343 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor);
344
345 // Takeover.
346 scrollAnimator->takeoverCompositorAnimation();
347 EXPECT_EQ(scrollAnimator->m_runState,
348 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositorButNee dsTakeover);
349
350 // Animation should now be running on the main thread.
351 scrollAnimator->setShouldSendToCompositor(false);
352 scrollAnimator->updateCompositorAnimations();
353 EXPECT_EQ(scrollAnimator->m_runState,
354 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread);
355 scrollAnimator->tickAnimation(getMockedTime());
356 EXPECT_NE(100, scrollAnimator->currentPosition().x());
357 EXPECT_NE(0, scrollAnimator->currentPosition().x());
358 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
359 reset(*scrollAnimator);
360 }
361
281 TEST(ScrollAnimatorTest, Disabled) 362 TEST(ScrollAnimatorTest, Disabled)
282 { 363 {
283 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false); 364 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false);
284 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime)); 365 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime));
285 366
286 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 367 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint()));
287 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000))); 368 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
288 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); 369 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8);
289 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); 370 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0);
290 371
(...skipping 12 matching lines...) Expand all
303 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 384 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
304 reset(*scrollAnimator); 385 reset(*scrollAnimator);
305 386
306 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 100, 1); 387 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 100, 1);
307 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 388 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
308 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 389 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
309 reset(*scrollAnimator); 390 reset(*scrollAnimator);
310 } 391 }
311 392
312 } // namespace blink 393 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollAnimatorCompositorCoordinator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698