OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/input/single_scrollbar_animation_controller_thinning.h" | 5 #include "cc/input/single_scrollbar_animation_controller_thinning.h" |
6 | 6 |
7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
8 #include "cc/test/fake_impl_task_runner_provider.h" | 8 #include "cc/test/fake_impl_task_runner_provider.h" |
9 #include "cc/test/fake_layer_tree_host_impl.h" | 9 #include "cc/test/fake_layer_tree_host_impl.h" |
10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
11 #include "cc/test/test_task_graph_runner.h" | 11 #include "cc/test/test_task_graph_runner.h" |
12 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using testing::AtLeast; | 16 using testing::AtLeast; |
17 using testing::Mock; | 17 using testing::Mock; |
18 using testing::NiceMock; | 18 using testing::NiceMock; |
19 using testing::_; | 19 using testing::_; |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 namespace { | 22 namespace { |
23 | 23 |
24 const float kIdleThicknessScale = | 24 const float kIdleThicknessScale = |
25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; | 25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; |
26 const float kDefaultMouseMoveDistanceToTriggerAnimation = | 26 const float kMouseMoveDistanceToTriggerExpand = |
27 SingleScrollbarAnimationControllerThinning:: | 27 SingleScrollbarAnimationControllerThinning:: |
28 kDefaultMouseMoveDistanceToTriggerAnimation; | 28 kMouseMoveDistanceToTriggerExpand; |
| 29 const float kMouseMoveDistanceToTriggerFadeIn = |
| 30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn; |
29 | 31 |
30 class MockSingleScrollbarAnimationControllerClient | 32 class MockSingleScrollbarAnimationControllerClient |
31 : public ScrollbarAnimationControllerClient { | 33 : public ScrollbarAnimationControllerClient { |
32 public: | 34 public: |
33 explicit MockSingleScrollbarAnimationControllerClient( | 35 explicit MockSingleScrollbarAnimationControllerClient( |
34 LayerTreeHostImpl* host_impl) | 36 LayerTreeHostImpl* host_impl) |
35 : host_impl_(host_impl) {} | 37 : host_impl_(host_impl) {} |
36 virtual ~MockSingleScrollbarAnimationControllerClient() {} | 38 virtual ~MockSingleScrollbarAnimationControllerClient() {} |
37 | 39 |
38 ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override { | 40 ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override { |
(...skipping 28 matching lines...) Expand all Loading... |
67 LayerImpl::Create(host_impl_.active_tree(), 3); | 69 LayerImpl::Create(host_impl_.active_tree(), 3); |
68 scroll_layer->SetElementId( | 70 scroll_layer->SetElementId( |
69 LayerIdToElementIdForTesting(scroll_layer->id())); | 71 LayerIdToElementIdForTesting(scroll_layer->id())); |
70 clip_layer_ = clip.get(); | 72 clip_layer_ = clip.get(); |
71 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 73 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
72 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 74 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
73 | 75 |
74 const int kId = 2; | 76 const int kId = 2; |
75 const int kThumbThickness = 10; | 77 const int kThumbThickness = 10; |
76 const int kTrackStart = 0; | 78 const int kTrackStart = 0; |
| 79 const int kTrackLength = 100; |
77 const bool kIsLeftSideVerticalScrollbar = false; | 80 const bool kIsLeftSideVerticalScrollbar = false; |
78 const bool kIsOverlayScrollbar = true; | 81 const bool kIsOverlayScrollbar = true; |
79 | 82 |
80 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 83 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
81 SolidColorScrollbarLayerImpl::Create( | 84 SolidColorScrollbarLayerImpl::Create( |
82 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, | 85 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
83 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 86 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
84 scrollbar_layer_ = scrollbar.get(); | 87 scrollbar_layer_ = scrollbar.get(); |
85 | 88 |
86 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 89 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
87 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 90 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
88 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 91 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
89 | 92 |
| 93 scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength)); |
| 94 scrollbar_layer_->SetPosition(gfx::PointF(90, 0)); |
90 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 95 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
91 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 96 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
92 clip_layer_->SetBounds(gfx::Size(100, 100)); | 97 clip_layer_->SetBounds(gfx::Size(100, 100)); |
93 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 98 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
94 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 99 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
95 | 100 |
96 scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 101 scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
97 scroll_layer_ptr->element_id(), HORIZONTAL, &client_, | 102 scroll_layer_ptr->element_id(), HORIZONTAL, &client_, |
98 kThinningDuration); | 103 kThinningDuration); |
99 } | 104 } |
100 | 105 |
101 FakeImplTaskRunnerProvider task_runner_provider_; | 106 FakeImplTaskRunnerProvider task_runner_provider_; |
102 TestTaskGraphRunner task_graph_runner_; | 107 TestTaskGraphRunner task_graph_runner_; |
103 FakeLayerTreeHostImpl host_impl_; | 108 FakeLayerTreeHostImpl host_impl_; |
104 std::unique_ptr<SingleScrollbarAnimationControllerThinning> | 109 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
105 scrollbar_controller_; | 110 scrollbar_controller_; |
106 LayerImpl* clip_layer_; | 111 LayerImpl* clip_layer_; |
107 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 112 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
108 NiceMock<MockSingleScrollbarAnimationControllerClient> client_; | 113 NiceMock<MockSingleScrollbarAnimationControllerClient> client_; |
109 }; | 114 }; |
110 | 115 |
| 116 gfx::PointF NearScrollbar(float offset_x, float offset_y) { |
| 117 gfx::PointF p(90, 0); |
| 118 p.Offset(offset_x, offset_y); |
| 119 return p; |
| 120 } |
| 121 |
111 // Check initialization of scrollbar. Should start thin. | 122 // Check initialization of scrollbar. Should start thin. |
112 TEST_F(SingleScrollbarAnimationControllerThinningTest, Idle) { | 123 TEST_F(SingleScrollbarAnimationControllerThinningTest, Idle) { |
113 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 124 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
114 scrollbar_layer_->thumb_thickness_scale_factor()); | 125 scrollbar_layer_->thumb_thickness_scale_factor()); |
115 } | 126 } |
116 | 127 |
117 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when | 128 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when |
118 // moved away. | 129 // moved away. |
119 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) { | 130 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) { |
120 base::TimeTicks time; | 131 base::TimeTicks time; |
121 time += base::TimeDelta::FromSeconds(1); | 132 time += base::TimeDelta::FromSeconds(1); |
122 | 133 |
123 scrollbar_controller_->DidMouseMoveNear(1); | 134 scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0)); |
124 scrollbar_controller_->Animate(time); | 135 scrollbar_controller_->Animate(time); |
125 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 136 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
126 scrollbar_layer_->thumb_thickness_scale_factor()); | 137 scrollbar_layer_->thumb_thickness_scale_factor()); |
127 | 138 |
128 // Should animate to thickened. | 139 // Should animate to thickened. |
129 time += kThinningDuration; | 140 time += kThinningDuration; |
130 scrollbar_controller_->Animate(time); | 141 scrollbar_controller_->Animate(time); |
131 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 142 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
132 | 143 |
133 // Subsequent moves within the nearness threshold should not change anything. | 144 // Subsequent moves within the nearness threshold should not change anything. |
134 scrollbar_controller_->DidMouseMoveNear(2); | 145 scrollbar_controller_->DidMouseMove(NearScrollbar(-2, 0)); |
135 scrollbar_controller_->Animate(time); | 146 scrollbar_controller_->Animate(time); |
136 time += base::TimeDelta::FromSeconds(10); | 147 time += base::TimeDelta::FromSeconds(10); |
137 scrollbar_controller_->Animate(time); | 148 scrollbar_controller_->Animate(time); |
138 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 149 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
139 | 150 |
140 // Now move away from bar. | 151 // Now move away from thumb. |
141 scrollbar_controller_->DidMouseMoveNear( | 152 scrollbar_controller_->DidMouseMove( |
142 kDefaultMouseMoveDistanceToTriggerAnimation); | 153 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
143 scrollbar_controller_->Animate(time); | 154 scrollbar_controller_->Animate(time); |
144 time += kThinningDuration; | 155 time += kThinningDuration; |
145 scrollbar_controller_->Animate(time); | 156 scrollbar_controller_->Animate(time); |
| 157 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 158 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 159 |
| 160 // Move away from track. |
| 161 scrollbar_controller_->DidMouseMove( |
| 162 NearScrollbar(-kMouseMoveDistanceToTriggerFadeIn, 0)); |
| 163 scrollbar_controller_->Animate(time); |
| 164 time += kThinningDuration; |
| 165 scrollbar_controller_->Animate(time); |
146 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 166 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
147 scrollbar_layer_->thumb_thickness_scale_factor()); | 167 scrollbar_layer_->thumb_thickness_scale_factor()); |
148 } | 168 } |
149 | 169 |
150 // Move the pointer over the scrollbar. Make sure it gets thick that it gets | 170 // Move the pointer over the scrollbar. Make sure it gets thick that it gets |
151 // thin when moved away. | 171 // thin when moved away. |
152 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) { | 172 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) { |
153 base::TimeTicks time; | 173 base::TimeTicks time; |
154 time += base::TimeDelta::FromSeconds(1); | 174 time += base::TimeDelta::FromSeconds(1); |
155 | 175 |
156 scrollbar_controller_->DidMouseMoveNear(0); | 176 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
157 scrollbar_controller_->Animate(time); | 177 scrollbar_controller_->Animate(time); |
158 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 178 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
159 scrollbar_layer_->thumb_thickness_scale_factor()); | 179 scrollbar_layer_->thumb_thickness_scale_factor()); |
160 | 180 |
161 // Should animate to thickened. | 181 // Should animate to thickened. |
162 time += kThinningDuration; | 182 time += kThinningDuration; |
163 scrollbar_controller_->Animate(time); | 183 scrollbar_controller_->Animate(time); |
164 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 184 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
165 | 185 |
166 // Subsequent moves should not change anything. | 186 // Subsequent moves should not change anything. |
167 scrollbar_controller_->DidMouseMoveNear(0); | 187 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
168 scrollbar_controller_->Animate(time); | 188 scrollbar_controller_->Animate(time); |
169 time += base::TimeDelta::FromSeconds(10); | 189 time += base::TimeDelta::FromSeconds(10); |
170 scrollbar_controller_->Animate(time); | 190 scrollbar_controller_->Animate(time); |
171 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 191 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
172 | 192 |
173 // Moving off the scrollbar but still withing the "near" threshold should do | 193 // Moving off the scrollbar but still withing the "near" threshold should do |
174 // nothing. | 194 // nothing. |
175 scrollbar_controller_->DidMouseMoveNear( | 195 scrollbar_controller_->DidMouseMove( |
176 kDefaultMouseMoveDistanceToTriggerAnimation - 1.f); | 196 NearScrollbar(-kMouseMoveDistanceToTriggerExpand + 1, 0)); |
177 scrollbar_controller_->Animate(time); | 197 scrollbar_controller_->Animate(time); |
178 time += base::TimeDelta::FromSeconds(10); | 198 time += base::TimeDelta::FromSeconds(10); |
179 scrollbar_controller_->Animate(time); | 199 scrollbar_controller_->Animate(time); |
180 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 200 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
181 | 201 |
182 // Now move away from bar. | 202 // Now move away from thumb. |
183 scrollbar_controller_->DidMouseMoveNear( | 203 scrollbar_controller_->DidMouseMove( |
184 kDefaultMouseMoveDistanceToTriggerAnimation); | 204 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
185 scrollbar_controller_->Animate(time); | 205 scrollbar_controller_->Animate(time); |
186 time += kThinningDuration; | 206 time += kThinningDuration; |
187 scrollbar_controller_->Animate(time); | 207 scrollbar_controller_->Animate(time); |
188 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 208 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
189 scrollbar_layer_->thumb_thickness_scale_factor()); | 209 scrollbar_layer_->thumb_thickness_scale_factor()); |
190 } | 210 } |
191 | 211 |
192 // First move the pointer over the scrollbar off of it. Make sure the thinning | 212 // First move the pointer over the scrollbar off of it. Make sure the thinning |
193 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the | 213 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the |
194 // thickening animation in the DidMouseMoveNear call. | 214 // thickening animation in the DidMouseMove call. |
195 TEST_F(SingleScrollbarAnimationControllerThinningTest, | 215 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
196 MouseNearThenAwayWhileAnimating) { | 216 MouseNearThenAwayWhileAnimating) { |
197 base::TimeTicks time; | 217 base::TimeTicks time; |
198 time += base::TimeDelta::FromSeconds(1); | 218 time += base::TimeDelta::FromSeconds(1); |
199 | 219 |
200 scrollbar_controller_->DidMouseMoveNear(0); | 220 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
201 scrollbar_controller_->Animate(time); | 221 scrollbar_controller_->Animate(time); |
202 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 222 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
203 scrollbar_layer_->thumb_thickness_scale_factor()); | 223 scrollbar_layer_->thumb_thickness_scale_factor()); |
204 | 224 |
205 // Should animate to thickened. | 225 // Should animate to thickened. |
206 time += kThinningDuration; | 226 time += kThinningDuration; |
207 scrollbar_controller_->Animate(time); | 227 scrollbar_controller_->Animate(time); |
208 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 228 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
209 | 229 |
210 // This is tricky. The DidMouseLeave() is sent before the | 230 // This is tricky. The DidMouseLeave() is sent before the |
211 // subsequent DidMouseMoveNear(), if the mouse moves in that direction. | 231 // subsequent DidMouseMove(), if the mouse moves in that direction. |
212 // This results in the thumb thinning. We want to make sure that when the | 232 // This results in the thumb thinning. We want to make sure that when the |
213 // thumb starts expanding it doesn't first narrow to the idle thinness. | 233 // thumb starts expanding it doesn't first narrow to the idle thinness. |
214 time += base::TimeDelta::FromSeconds(1); | 234 time += base::TimeDelta::FromSeconds(1); |
215 scrollbar_controller_->DidMouseLeave(); | 235 scrollbar_controller_->DidMouseLeave(); |
216 scrollbar_controller_->Animate(time); | 236 scrollbar_controller_->Animate(time); |
217 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 237 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
218 | 238 |
219 // Let the animation run half of the way through the thinning animation. | 239 // Let the animation run half of the way through the thinning animation. |
220 time += kThinningDuration / 2; | 240 time += kThinningDuration / 2; |
221 scrollbar_controller_->Animate(time); | 241 scrollbar_controller_->Animate(time); |
222 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 242 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
223 scrollbar_layer_->thumb_thickness_scale_factor()); | 243 scrollbar_layer_->thumb_thickness_scale_factor()); |
224 | 244 |
225 // Now we get a notification for the mouse moving over the scroller. The | 245 // Now we get a notification for the mouse moving over the scroller. The |
226 // animation is reset to the thickening direction but we won't start | 246 // animation is reset to the thickening direction but we won't start |
227 // thickening until the new animation catches up to the current thickness. | 247 // thickening until the new animation catches up to the current thickness. |
228 scrollbar_controller_->DidMouseMoveNear(1); | 248 scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0)); |
229 scrollbar_controller_->Animate(time); | 249 scrollbar_controller_->Animate(time); |
230 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 250 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
231 scrollbar_layer_->thumb_thickness_scale_factor()); | 251 scrollbar_layer_->thumb_thickness_scale_factor()); |
232 | 252 |
233 // Until we reach the half way point, the animation will have no effect. | 253 // Until we reach the half way point, the animation will have no effect. |
234 time += kThinningDuration / 4; | 254 time += kThinningDuration / 4; |
235 scrollbar_controller_->Animate(time); | 255 scrollbar_controller_->Animate(time); |
236 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 256 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
237 scrollbar_layer_->thumb_thickness_scale_factor()); | 257 scrollbar_layer_->thumb_thickness_scale_factor()); |
238 | 258 |
(...skipping 17 matching lines...) Expand all Loading... |
256 | 276 |
257 // First move the pointer on the scrollbar, then press it, then away. | 277 // First move the pointer on the scrollbar, then press it, then away. |
258 // Confirm that the bar gets thick. Then mouse up. Confirm that | 278 // Confirm that the bar gets thick. Then mouse up. Confirm that |
259 // the bar gets thin. | 279 // the bar gets thin. |
260 TEST_F(SingleScrollbarAnimationControllerThinningTest, | 280 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
261 MouseCaptureAndReleaseOutOfBar) { | 281 MouseCaptureAndReleaseOutOfBar) { |
262 base::TimeTicks time; | 282 base::TimeTicks time; |
263 time += base::TimeDelta::FromSeconds(1); | 283 time += base::TimeDelta::FromSeconds(1); |
264 | 284 |
265 // Move over the scrollbar. | 285 // Move over the scrollbar. |
266 scrollbar_controller_->DidMouseMoveNear(0); | 286 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
267 scrollbar_controller_->Animate(time); | 287 scrollbar_controller_->Animate(time); |
268 time += kThinningDuration; | 288 time += kThinningDuration; |
269 scrollbar_controller_->Animate(time); | 289 scrollbar_controller_->Animate(time); |
270 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 290 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
271 | 291 |
272 // Capture | 292 // Capture |
273 scrollbar_controller_->DidMouseDown(); | 293 scrollbar_controller_->DidMouseDown(); |
274 time += base::TimeDelta::FromSeconds(1); | 294 time += base::TimeDelta::FromSeconds(1); |
275 scrollbar_controller_->Animate(time); | 295 scrollbar_controller_->Animate(time); |
276 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 296 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
277 | 297 |
278 // Should stay thick for a while. | 298 // Should stay thick for a while. |
279 time += base::TimeDelta::FromSeconds(10); | 299 time += base::TimeDelta::FromSeconds(10); |
280 scrollbar_controller_->Animate(time); | 300 scrollbar_controller_->Animate(time); |
281 | 301 |
282 // Move outside the "near" threshold. Because the scrollbar is captured it | 302 // Move outside the "near" threshold. Because the scrollbar is captured it |
283 // should remain thick. | 303 // should remain thick. |
284 scrollbar_controller_->DidMouseMoveNear( | 304 scrollbar_controller_->DidMouseMove( |
285 kDefaultMouseMoveDistanceToTriggerAnimation); | 305 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
286 time += kThinningDuration; | 306 time += kThinningDuration; |
287 scrollbar_controller_->Animate(time); | 307 scrollbar_controller_->Animate(time); |
288 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 308 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
289 | 309 |
290 // Release. | 310 // Release. |
291 scrollbar_controller_->DidMouseUp(); | 311 scrollbar_controller_->DidMouseUp(); |
292 | 312 |
293 // Should become thin. | 313 // Should become thin. |
294 time += base::TimeDelta::FromSeconds(1); | 314 time += base::TimeDelta::FromSeconds(1); |
295 scrollbar_controller_->Animate(time); | 315 scrollbar_controller_->Animate(time); |
296 time += kThinningDuration; | 316 time += kThinningDuration; |
297 scrollbar_controller_->Animate(time); | 317 scrollbar_controller_->Animate(time); |
298 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 318 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
299 scrollbar_layer_->thumb_thickness_scale_factor()); | 319 scrollbar_layer_->thumb_thickness_scale_factor()); |
300 } | 320 } |
301 | 321 |
302 // First move the pointer on the scrollbar, then press it, then away. Confirm | 322 // First move the pointer on the scrollbar, then press it, then away. Confirm |
303 // that the bar gets thick. Then move point on the scrollbar and mouse up. | 323 // that the bar gets thick. Then move point on the scrollbar and mouse up. |
304 // Confirm that the bar stays thick. | 324 // Confirm that the bar stays thick. |
305 TEST_F(SingleScrollbarAnimationControllerThinningTest, | 325 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
306 MouseCaptureAndReleaseOnBar) { | 326 MouseCaptureAndReleaseOnBar) { |
307 base::TimeTicks time; | 327 base::TimeTicks time; |
308 time += base::TimeDelta::FromSeconds(1); | 328 time += base::TimeDelta::FromSeconds(1); |
309 | 329 |
310 // Move over scrollbar. | 330 // Move over scrollbar. |
311 scrollbar_controller_->DidMouseMoveNear(0); | 331 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
312 scrollbar_controller_->Animate(time); | 332 scrollbar_controller_->Animate(time); |
313 time += kThinningDuration; | 333 time += kThinningDuration; |
314 scrollbar_controller_->Animate(time); | 334 scrollbar_controller_->Animate(time); |
315 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 335 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
316 | 336 |
317 // Capture. Nothing should change. | 337 // Capture. Nothing should change. |
318 scrollbar_controller_->DidMouseDown(); | 338 scrollbar_controller_->DidMouseDown(); |
319 time += base::TimeDelta::FromSeconds(1); | 339 time += base::TimeDelta::FromSeconds(1); |
320 scrollbar_controller_->Animate(time); | 340 scrollbar_controller_->Animate(time); |
321 time += base::TimeDelta::FromSeconds(10); | 341 time += base::TimeDelta::FromSeconds(10); |
322 scrollbar_controller_->Animate(time); | 342 scrollbar_controller_->Animate(time); |
323 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 343 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
324 | 344 |
325 // Move away from scrollbar. Nothing should change. | 345 // Move away from scrollbar. Nothing should change. |
326 scrollbar_controller_->DidMouseMoveNear( | 346 scrollbar_controller_->DidMouseMove( |
327 kDefaultMouseMoveDistanceToTriggerAnimation); | 347 NearScrollbar(kMouseMoveDistanceToTriggerExpand, 0)); |
328 time += base::TimeDelta::FromSeconds(1); | 348 time += base::TimeDelta::FromSeconds(1); |
329 scrollbar_controller_->Animate(time); | 349 scrollbar_controller_->Animate(time); |
330 time += base::TimeDelta::FromSeconds(10); | 350 time += base::TimeDelta::FromSeconds(10); |
331 scrollbar_controller_->Animate(time); | 351 scrollbar_controller_->Animate(time); |
332 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 352 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
333 | 353 |
334 // Move over scrollbar and release. Since we're near the scrollbar, it should | 354 // Move over scrollbar and release. Since we're near the scrollbar, it should |
335 // remain thick. | 355 // remain thick. |
336 scrollbar_controller_->DidMouseMoveNear(0); | 356 scrollbar_controller_->DidMouseMove( |
| 357 NearScrollbar(-kMouseMoveDistanceToTriggerExpand + 1, 0)); |
337 scrollbar_controller_->DidMouseUp(); | 358 scrollbar_controller_->DidMouseUp(); |
338 time += base::TimeDelta::FromSeconds(1); | 359 time += base::TimeDelta::FromSeconds(1); |
339 scrollbar_controller_->Animate(time); | 360 scrollbar_controller_->Animate(time); |
340 time += base::TimeDelta::FromSeconds(10); | 361 time += base::TimeDelta::FromSeconds(10); |
341 scrollbar_controller_->Animate(time); | 362 scrollbar_controller_->Animate(time); |
342 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 363 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
343 } | 364 } |
344 | 365 |
345 // Tests that the thickening/thinning effects are animated. | 366 // Tests that the thickening/thinning effects are animated. |
346 TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) { | 367 TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) { |
347 base::TimeTicks time; | 368 base::TimeTicks time; |
348 time += base::TimeDelta::FromSeconds(1); | 369 time += base::TimeDelta::FromSeconds(1); |
349 | 370 |
350 // Move mouse near scrollbar. Test that at half the duration time, the | 371 // Move mouse near scrollbar. Test that at half the duration time, the |
351 // thickness is half way through its animation. | 372 // thickness is half way through its animation. |
352 scrollbar_controller_->DidMouseMoveNear(1); | 373 scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0)); |
353 scrollbar_controller_->Animate(time); | 374 scrollbar_controller_->Animate(time); |
354 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 375 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
355 scrollbar_layer_->thumb_thickness_scale_factor()); | 376 scrollbar_layer_->thumb_thickness_scale_factor()); |
356 | 377 |
357 time += kThinningDuration / 2; | 378 time += kThinningDuration / 2; |
358 scrollbar_controller_->Animate(time); | 379 scrollbar_controller_->Animate(time); |
359 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, | 380 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, |
360 scrollbar_layer_->thumb_thickness_scale_factor()); | 381 scrollbar_layer_->thumb_thickness_scale_factor()); |
361 | 382 |
362 time += kThinningDuration / 2; | 383 time += kThinningDuration / 2; |
363 scrollbar_controller_->Animate(time); | 384 scrollbar_controller_->Animate(time); |
364 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 385 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
365 | 386 |
366 // Move mouse away from scrollbar. Same check. | 387 // Move mouse away from scrollbar. Same check. |
367 time += base::TimeDelta::FromSeconds(1); | 388 time += base::TimeDelta::FromSeconds(1); |
368 scrollbar_controller_->DidMouseMoveNear( | 389 scrollbar_controller_->DidMouseMove( |
369 kDefaultMouseMoveDistanceToTriggerAnimation); | 390 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
370 scrollbar_controller_->Animate(time); | 391 scrollbar_controller_->Animate(time); |
371 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 392 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
372 | 393 |
373 time += kThinningDuration / 2; | 394 time += kThinningDuration / 2; |
374 scrollbar_controller_->Animate(time); | 395 scrollbar_controller_->Animate(time); |
375 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 396 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
376 scrollbar_layer_->thumb_thickness_scale_factor()); | 397 scrollbar_layer_->thumb_thickness_scale_factor()); |
377 | 398 |
378 time += kThinningDuration / 2; | 399 time += kThinningDuration / 2; |
379 scrollbar_controller_->Animate(time); | 400 scrollbar_controller_->Animate(time); |
380 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 401 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
381 scrollbar_layer_->thumb_thickness_scale_factor()); | 402 scrollbar_layer_->thumb_thickness_scale_factor()); |
382 } | 403 } |
383 | 404 |
384 } // namespace | 405 } // namespace |
385 } // namespace cc | 406 } // namespace cc |
OLD | NEW |