OLD | NEW |
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 int visibleHeight() const override { return 768; } | 80 int visibleHeight() const override { return 768; } |
81 int visibleWidth() const override { return 1024; } | 81 int visibleWidth() const override { return 1024; } |
82 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled
; } | 82 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled
; } |
83 int pageStep(ScrollbarOrientation) const override { return 0; } | 83 int pageStep(ScrollbarOrientation) const override { return 0; } |
84 | 84 |
85 void setScrollAnimator(ScrollAnimator* scrollAnimator) | 85 void setScrollAnimator(ScrollAnimator* scrollAnimator) |
86 { | 86 { |
87 animator = scrollAnimator; | 87 animator = scrollAnimator; |
88 } | 88 } |
89 | 89 |
90 bool shouldScrollOnMainThread() const override | |
91 { | |
92 return m_scrollOnMainThread; | |
93 } | |
94 | |
95 void setScrollOnMainThread(bool scrollOnMainThread) | |
96 { | |
97 m_scrollOnMainThread = scrollOnMainThread; | |
98 } | |
99 | |
100 DoublePoint scrollPositionDouble() const override | 90 DoublePoint scrollPositionDouble() const override |
101 { | 91 { |
102 if (animator) | 92 if (animator) |
103 return animator->currentPosition(); | 93 return animator->currentPosition(); |
104 return ScrollableArea::scrollPositionDouble(); | 94 return ScrollableArea::scrollPositionDouble(); |
105 } | 95 } |
106 | 96 |
107 void setScrollPosition(const DoublePoint& position, ScrollType type, | 97 void setScrollPosition(const DoublePoint& position, ScrollType type, |
108 ScrollBehavior behavior = ScrollBehaviorInstant) | 98 ScrollBehavior behavior = ScrollBehaviorInstant) |
109 { | 99 { |
110 if (animator) | 100 if (animator) |
111 animator->setCurrentPosition(toFloatPoint(position)); | 101 animator->setCurrentPosition(toFloatPoint(position)); |
112 ScrollableArea::setScrollPosition(position, type, behavior); | 102 ScrollableArea::setScrollPosition(position, type, behavior); |
113 } | 103 } |
114 | 104 |
115 DEFINE_INLINE_VIRTUAL_TRACE() | 105 DEFINE_INLINE_VIRTUAL_TRACE() |
116 { | 106 { |
117 visitor->trace(animator); | 107 visitor->trace(animator); |
118 ScrollableArea::trace(visitor); | 108 ScrollableArea::trace(visitor); |
119 } | 109 } |
120 | 110 |
121 private: | 111 private: |
122 explicit MockScrollableArea(bool scrollAnimatorEnabled) | 112 explicit MockScrollableArea(bool scrollAnimatorEnabled) |
123 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } | 113 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } |
124 | 114 |
125 bool m_scrollAnimatorEnabled; | 115 bool m_scrollAnimatorEnabled; |
126 bool m_scrollOnMainThread = false; | |
127 Member<ScrollAnimator> animator; | 116 Member<ScrollAnimator> animator; |
128 }; | 117 }; |
129 | 118 |
130 class TestScrollAnimator : public ScrollAnimator { | 119 class TestScrollAnimator : public ScrollAnimator { |
131 public: | 120 public: |
132 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF
unction) | 121 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF
unction) |
133 : ScrollAnimator(scrollableArea, timingFunction) {}; | 122 : ScrollAnimator(scrollableArea, timingFunction) {}; |
134 ~TestScrollAnimator() override {}; | 123 ~TestScrollAnimator() override {}; |
135 | 124 |
136 void setShouldSendToCompositor(bool send) | 125 void setShouldSendToCompositor(bool send) |
(...skipping 23 matching lines...) Expand all Loading... |
160 static void reset(ScrollAnimator& scrollAnimator) | 149 static void reset(ScrollAnimator& scrollAnimator) |
161 { | 150 { |
162 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); | 151 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); |
163 } | 152 } |
164 | 153 |
165 // TODO(skobes): Add unit tests for composited scrolling paths. | 154 // TODO(skobes): Add unit tests for composited scrolling paths. |
166 | 155 |
167 TEST(ScrollAnimatorTest, MainThreadStates) | 156 TEST(ScrollAnimatorTest, MainThreadStates) |
168 { | 157 { |
169 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 158 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); |
170 scrollableArea->setScrollOnMainThread(true); | |
171 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke
dTime); | 159 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke
dTime); |
172 | 160 |
173 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) | 161 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) |
174 .WillRepeatedly(Return(IntPoint())); | 162 .WillRepeatedly(Return(IntPoint())); |
175 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) | 163 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) |
176 .WillRepeatedly(Return(IntPoint(1000, 1000))); | 164 .WillRepeatedly(Return(IntPoint(1000, 1000))); |
177 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); | 165 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); |
178 // Once from userScroll. | 166 // Once from userScroll, once from updateCompositorAnimations. |
179 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(1); | 167 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); |
180 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) | 168 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) |
181 .WillRepeatedly(Return(true)); | 169 .WillRepeatedly(Return(true)); |
182 | 170 |
183 // Idle | 171 // Idle |
184 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 172 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
185 EXPECT_EQ(scrollAnimator->m_runState, | 173 EXPECT_EQ(scrollAnimator->m_runState, |
186 ScrollAnimatorCompositorCoordinator::RunState::Idle); | 174 ScrollAnimatorCompositorCoordinator::RunState::Idle); |
187 | 175 |
188 // WaitingToSendToCompositor | 176 // WaitingToSendToCompositor |
189 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); | 177 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); |
190 EXPECT_EQ(scrollAnimator->m_runState, | 178 EXPECT_EQ(scrollAnimator->m_runState, |
191 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 179 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor
); |
192 | 180 |
193 // RunningOnMainThread | 181 // RunningOnMainThread |
194 gMockedTime += 0.05; | 182 gMockedTime += 0.05; |
195 scrollAnimator->updateCompositorAnimations(); | 183 scrollAnimator->updateCompositorAnimations(); |
196 EXPECT_EQ(scrollAnimator->m_runState, | 184 EXPECT_EQ(scrollAnimator->m_runState, |
197 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 185 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
198 scrollAnimator->tickAnimation(getMockedTime()); | 186 scrollAnimator->tickAnimation(getMockedTime()); |
199 EXPECT_EQ(scrollAnimator->m_runState, | 187 EXPECT_EQ(scrollAnimator->m_runState, |
200 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 188 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
201 | 189 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 animator->updateCompositorAnimations(); | 623 animator->updateCompositorAnimations(); |
636 animator->tickAnimation(getMockedTime()); | 624 animator->tickAnimation(getMockedTime()); |
637 EXPECT_EQ(FloatPoint(110, 90), animator->currentPosition()); | 625 EXPECT_EQ(FloatPoint(110, 90), animator->currentPosition()); |
638 reset(*animator); | 626 reset(*animator); |
639 | 627 |
640 // Forced GC in order to finalize objects depending on the mock object. | 628 // Forced GC in order to finalize objects depending on the mock object. |
641 ThreadState::current()-> collectAllGarbage(); | 629 ThreadState::current()-> collectAllGarbage(); |
642 } | 630 } |
643 | 631 |
644 } // namespace blink | 632 } // namespace blink |
OLD | NEW |