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

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: nitsnits 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 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(2);
321 // Called from userScroll, updateCompositorAnimations, then
322 // takeoverCompositorAnimation (to re-register after RunningOnCompositor).
323 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3);
324 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1))
325 .WillRepeatedly(Return(true));
326
327 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService());
328
329 // Smooth scroll.
330 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100 , 0));
331 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService());
332 EXPECT_TRUE(result.didScrollX);
333 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX);
334 EXPECT_TRUE(scrollAnimator->hasRunningAnimation());
335
336 // Update compositor animation.
337 gMockedTime += 0.05;
338 scrollAnimator->setShouldSendToCompositor(true);
339 scrollAnimator->updateCompositorAnimations();
340 EXPECT_EQ(scrollAnimator->m_runState,
341 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor);
342
343 // Takeover.
344 scrollAnimator->takeoverCompositorAnimation();
345 EXPECT_EQ(scrollAnimator->m_runState,
346 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositorButNee dsTakeover);
347
348 // Animation should now be running on the main thread.
349 scrollAnimator->setShouldSendToCompositor(false);
350 scrollAnimator->updateCompositorAnimations();
351 EXPECT_EQ(scrollAnimator->m_runState,
352 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread);
353 scrollAnimator->tickAnimation(getMockedTime());
354 EXPECT_NE(100, scrollAnimator->currentPosition().x());
355 EXPECT_NE(0, scrollAnimator->currentPosition().x());
356 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
357 reset(*scrollAnimator);
358 }
359
279 TEST(ScrollAnimatorTest, Disabled) 360 TEST(ScrollAnimatorTest, Disabled)
280 { 361 {
281 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false); 362 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(false);
282 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime)); 363 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S crollAnimator(scrollableArea.get(), getMockedTime));
283 364
284 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint())); 365 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))); 366 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will Repeatedly(Return(IntPoint(1000, 1000)));
286 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); 367 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8);
287 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); 368 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0);
288 369
(...skipping 12 matching lines...) Expand all
301 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 382 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
302 reset(*scrollAnimator); 383 reset(*scrollAnimator);
303 384
304 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); 385 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0));
305 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); 386 EXPECT_EQ(100, scrollAnimator->currentPosition().x());
306 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); 387 EXPECT_EQ(0, scrollAnimator->currentPosition().y());
307 reset(*scrollAnimator); 388 reset(*scrollAnimator);
308 } 389 }
309 390
310 } // namespace blink 391 } // 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