OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/blink/input_scroll_elasticity_controller.h" | 5 #include "ui/events/blink/input_scroll_elasticity_controller.h" |
6 | 6 |
7 #include "cc/input/input_handler.h" | 7 #include "cc/input/input_handler.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/WebKit/public/web/WebInputEvent.h" | 9 #include "third_party/WebKit/public/web/WebInputEvent.h" |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 event.timeStampSeconds = (current_time_ - base::TimeTicks()).InSecondsF(); | 92 event.timeStampSeconds = (current_time_ - base::TimeTicks()).InSecondsF(); |
93 | 93 |
94 cc::InputHandlerScrollResult scroll_result; | 94 cc::InputHandlerScrollResult scroll_result; |
95 scroll_result.did_overscroll_root = !overscroll_delta.IsZero(); | 95 scroll_result.did_overscroll_root = !overscroll_delta.IsZero(); |
96 scroll_result.unused_scroll_delta = overscroll_delta; | 96 scroll_result.unused_scroll_delta = overscroll_delta; |
97 | 97 |
98 controller_.ObserveWheelEventAndResult(event, scroll_result); | 98 controller_.ObserveWheelEventAndResult(event, scroll_result); |
99 input_event_count_ += 1; | 99 input_event_count_ += 1; |
100 } | 100 } |
101 | 101 |
| 102 void SendGestureScrollBegin(bool inertial) { |
| 103 blink::WebGestureEvent event; |
| 104 event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 105 event.type = blink::WebInputEvent::GestureScrollBegin; |
| 106 event.data.scrollBegin.inertial = inertial; |
| 107 TickCurrentTime(); |
| 108 event.timeStampSeconds = (current_time_ - base::TimeTicks()).InSecondsF(); |
| 109 |
| 110 controller_.ObserveGestureEventAndResult(event, |
| 111 cc::InputHandlerScrollResult()); |
| 112 input_event_count_ += 1; |
| 113 } |
| 114 |
| 115 void SendGestureScrollUpdate( |
| 116 bool inertial, |
| 117 const gfx::Vector2dF& event_delta = gfx::Vector2dF(), |
| 118 const gfx::Vector2dF& overscroll_delta = gfx::Vector2dF()) { |
| 119 blink::WebGestureEvent event; |
| 120 event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 121 event.type = blink::WebInputEvent::GestureScrollUpdate; |
| 122 event.data.scrollUpdate.inertial = inertial; |
| 123 event.data.scrollUpdate.deltaX = -event_delta.x(); |
| 124 event.data.scrollUpdate.deltaY = -event_delta.y(); |
| 125 TickCurrentTime(); |
| 126 event.timeStampSeconds = (current_time_ - base::TimeTicks()).InSecondsF(); |
| 127 |
| 128 cc::InputHandlerScrollResult scroll_result; |
| 129 scroll_result.did_overscroll_root = !overscroll_delta.IsZero(); |
| 130 scroll_result.unused_scroll_delta = overscroll_delta; |
| 131 |
| 132 controller_.ObserveGestureEventAndResult(event, scroll_result); |
| 133 input_event_count_ += 1; |
| 134 } |
| 135 |
| 136 void SendGestureScrollEnd() { |
| 137 blink::WebGestureEvent event; |
| 138 event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 139 event.type = blink::WebInputEvent::GestureScrollEnd; |
| 140 |
| 141 TickCurrentTime(); |
| 142 event.timeStampSeconds = (current_time_ - base::TimeTicks()).InSecondsF(); |
| 143 |
| 144 controller_.ObserveGestureEventAndResult(event, |
| 145 cc::InputHandlerScrollResult()); |
| 146 input_event_count_ += 1; |
| 147 } |
| 148 |
102 const base::TimeTicks& TickCurrentTime() { | 149 const base::TimeTicks& TickCurrentTime() { |
103 current_time_ += base::TimeDelta::FromSecondsD(1 / 60.f); | 150 current_time_ += base::TimeDelta::FromSecondsD(1 / 60.f); |
104 return current_time_; | 151 return current_time_; |
105 } | 152 } |
106 void TickCurrentTimeAndAnimate() { | 153 void TickCurrentTimeAndAnimate() { |
107 TickCurrentTime(); | 154 TickCurrentTime(); |
108 controller_.Animate(current_time_); | 155 controller_.Animate(current_time_); |
109 } | 156 } |
110 | 157 |
111 MockScrollElasticityHelper helper_; | 158 MockScrollElasticityHelper helper_; |
(...skipping 29 matching lines...) Expand all Loading... |
141 gfx::Vector2dF(-25, 40)); | 188 gfx::Vector2dF(-25, 40)); |
142 EXPECT_EQ(3, helper_.set_stretch_amount_count()); | 189 EXPECT_EQ(3, helper_.set_stretch_amount_count()); |
143 EXPECT_GT(0.f, helper_.StretchAmount().x()); | 190 EXPECT_GT(0.f, helper_.StretchAmount().x()); |
144 EXPECT_EQ(0.f, helper_.StretchAmount().y()); | 191 EXPECT_EQ(0.f, helper_.StretchAmount().y()); |
145 helper_.SetStretchAmount(gfx::Vector2dF()); | 192 helper_.SetStretchAmount(gfx::Vector2dF()); |
146 EXPECT_EQ(4, helper_.set_stretch_amount_count()); | 193 EXPECT_EQ(4, helper_.set_stretch_amount_count()); |
147 SendMouseWheelEvent(PhaseEnded, PhaseNone); | 194 SendMouseWheelEvent(PhaseEnded, PhaseNone); |
148 EXPECT_EQ(0, helper_.request_begin_frame_count()); | 195 EXPECT_EQ(0, helper_.request_begin_frame_count()); |
149 } | 196 } |
150 | 197 |
| 198 // Verify that stretching only occurs in one axis at a time, and that it |
| 199 // is biased to the Y axis. |
| 200 TEST_F(ScrollElasticityControllerTest, GestureBased_Axis) { |
| 201 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0), |
| 202 gfx::ScrollOffset(0, 0)); |
| 203 |
| 204 // If we push equally in the X and Y directions, we should see a stretch only |
| 205 // in the Y direction. |
| 206 SendGestureScrollBegin(false); |
| 207 SendGestureScrollUpdate(false, gfx::Vector2dF(10, 10), |
| 208 gfx::Vector2dF(10, 10)); |
| 209 EXPECT_EQ(1, helper_.set_stretch_amount_count()); |
| 210 EXPECT_EQ(0.f, helper_.StretchAmount().x()); |
| 211 EXPECT_LT(0.f, helper_.StretchAmount().y()); |
| 212 helper_.SetStretchAmount(gfx::Vector2dF()); |
| 213 EXPECT_EQ(2, helper_.set_stretch_amount_count()); |
| 214 SendGestureScrollEnd(); |
| 215 EXPECT_EQ(0, helper_.request_begin_frame_count()); |
| 216 |
| 217 // If we push more in the X direction than the Y direction, we should see a |
| 218 // stretch only in the X direction. This decision should be based on the |
| 219 // input delta, not the actual overscroll delta. |
| 220 SendGestureScrollBegin(false); |
| 221 SendGestureScrollUpdate(false, gfx::Vector2dF(-25, 10), |
| 222 gfx::Vector2dF(-25, 40)); |
| 223 EXPECT_EQ(3, helper_.set_stretch_amount_count()); |
| 224 EXPECT_GT(0.f, helper_.StretchAmount().x()); |
| 225 EXPECT_EQ(0.f, helper_.StretchAmount().y()); |
| 226 helper_.SetStretchAmount(gfx::Vector2dF()); |
| 227 EXPECT_EQ(4, helper_.set_stretch_amount_count()); |
| 228 SendGestureScrollEnd(); |
| 229 EXPECT_EQ(0, helper_.request_begin_frame_count()); |
| 230 } |
| 231 |
151 // Verify that we need a total overscroll delta of at least 10 in a pinned | 232 // Verify that we need a total overscroll delta of at least 10 in a pinned |
152 // direction before we start stretching. | 233 // direction before we start stretching. |
153 TEST_F(ScrollElasticityControllerTest, MinimumDeltaBeforeStretch) { | 234 TEST_F(ScrollElasticityControllerTest, MinimumDeltaBeforeStretch) { |
154 // We should not start stretching while we are not pinned in the direction | 235 // We should not start stretching while we are not pinned in the direction |
155 // of the scroll (even if there is an overscroll delta). We have to wait for | 236 // of the scroll (even if there is an overscroll delta). We have to wait for |
156 // the regular scroll to eat all of the events. | 237 // the regular scroll to eat all of the events. |
157 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), | 238 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), |
158 gfx::ScrollOffset(10, 10)); | 239 gfx::ScrollOffset(10, 10)); |
159 SendMouseWheelEvent(PhaseMayBegin, PhaseNone); | 240 SendMouseWheelEvent(PhaseMayBegin, PhaseNone); |
160 SendMouseWheelEvent(PhaseBegan, PhaseNone); | 241 SendMouseWheelEvent(PhaseBegan, PhaseNone); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 EXPECT_EQ(0.f, helper_.StretchAmount().x()); | 275 EXPECT_EQ(0.f, helper_.StretchAmount().x()); |
195 EXPECT_LT(0.f, helper_.StretchAmount().y()); | 276 EXPECT_LT(0.f, helper_.StretchAmount().y()); |
196 | 277 |
197 // End the gesture. Because there is a non-zero stretch, we should be in the | 278 // End the gesture. Because there is a non-zero stretch, we should be in the |
198 // animated state, and should have had a frame requested. | 279 // animated state, and should have had a frame requested. |
199 EXPECT_EQ(0, helper_.request_begin_frame_count()); | 280 EXPECT_EQ(0, helper_.request_begin_frame_count()); |
200 SendMouseWheelEvent(PhaseEnded, PhaseNone); | 281 SendMouseWheelEvent(PhaseEnded, PhaseNone); |
201 EXPECT_EQ(1, helper_.request_begin_frame_count()); | 282 EXPECT_EQ(1, helper_.request_begin_frame_count()); |
202 } | 283 } |
203 | 284 |
204 // Verify that an stretch caused by a momentum scroll will switch to the | 285 // Verify that we need a total overscroll delta of at least 10 in a pinned |
| 286 // direction before we start stretching. |
| 287 TEST_F(ScrollElasticityControllerTest, GestureBased_MinimumDeltaBeforeStretch) { |
| 288 // We should not start stretching while we are not pinned in the direction |
| 289 // of the scroll (even if there is an overscroll delta). We have to wait for |
| 290 // the regular scroll to eat all of the events. |
| 291 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), |
| 292 gfx::ScrollOffset(10, 10)); |
| 293 SendGestureScrollBegin(false); |
| 294 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 10)); |
| 295 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 10)); |
| 296 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 297 |
| 298 // Now pin the -X and +Y direction. The first event will not generate a |
| 299 // stretch |
| 300 // because it is below the delta threshold of 10. |
| 301 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 10), |
| 302 gfx::ScrollOffset(10, 10)); |
| 303 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 8)); |
| 304 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 305 |
| 306 // Make the next scroll be in the -X direction more than the +Y direction, |
| 307 // which will erase the memory of the previous unused delta of 8. |
| 308 SendGestureScrollUpdate(false, gfx::Vector2dF(-10, 5), |
| 309 gfx::Vector2dF(-8, 10)); |
| 310 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 311 |
| 312 // Now push against the pinned +Y direction again by 8. We reset the |
| 313 // previous delta, so this will not generate a stretch. |
| 314 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 8)); |
| 315 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 316 |
| 317 // Push against +Y by another 8. This gets us above the delta threshold of |
| 318 // 10, so we should now have had the stretch set, and it should be in the |
| 319 // +Y direction. The scroll in the -X direction should have been forgotten. |
| 320 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 8)); |
| 321 EXPECT_EQ(1, helper_.set_stretch_amount_count()); |
| 322 EXPECT_EQ(0.f, helper_.StretchAmount().x()); |
| 323 EXPECT_LT(0.f, helper_.StretchAmount().y()); |
| 324 |
| 325 // End the gesture. Because there is a non-zero stretch, we should be in the |
| 326 // animated state, and should have had a frame requested. |
| 327 EXPECT_EQ(0, helper_.request_begin_frame_count()); |
| 328 SendGestureScrollEnd(); |
| 329 EXPECT_EQ(1, helper_.request_begin_frame_count()); |
| 330 } |
| 331 |
| 332 // Verify that a stretch caused by a momentum scroll will switch to the |
205 // animating mode, where input events are ignored, and the stretch is updated | 333 // animating mode, where input events are ignored, and the stretch is updated |
206 // while animating. | 334 // while animating. |
207 TEST_F(ScrollElasticityControllerTest, MomentumAnimate) { | 335 TEST_F(ScrollElasticityControllerTest, MomentumAnimate) { |
208 // Do an active scroll, then switch to the momentum phase and scroll for a | 336 // Do an active scroll, then switch to the momentum phase and scroll for a |
209 // bit. | 337 // bit. |
210 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), | 338 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), |
211 gfx::ScrollOffset(10, 10)); | 339 gfx::ScrollOffset(10, 10)); |
212 SendMouseWheelEvent(PhaseBegan, PhaseNone); | 340 SendMouseWheelEvent(PhaseBegan, PhaseNone); |
213 SendMouseWheelEvent(PhaseChanged, PhaseNone, gfx::Vector2dF(0, -80), | 341 SendMouseWheelEvent(PhaseChanged, PhaseNone, gfx::Vector2dF(0, -80), |
214 gfx::Vector2dF(0, 0)); | 342 gfx::Vector2dF(0, 0)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); | 418 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); |
291 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); | 419 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); |
292 } | 420 } |
293 | 421 |
294 // After coming to rest, no subsequent animate calls change anything. | 422 // After coming to rest, no subsequent animate calls change anything. |
295 TickCurrentTimeAndAnimate(); | 423 TickCurrentTimeAndAnimate(); |
296 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); | 424 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); |
297 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); | 425 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); |
298 } | 426 } |
299 | 427 |
300 // Verify that an stretch opposing a scroll is correctly resolved. | 428 // Verify that a stretch caused by a momentum scroll will switch to the |
| 429 // animating mode, where input events are ignored, and the stretch is updated |
| 430 // while animating. |
| 431 TEST_F(ScrollElasticityControllerTest, GestureBased_MomentumAnimate) { |
| 432 // Do an active scroll, then switch to the momentum phase and scroll for a |
| 433 // bit. |
| 434 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), |
| 435 gfx::ScrollOffset(10, 10)); |
| 436 SendGestureScrollBegin(false); |
| 437 SendGestureScrollUpdate(false, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0)); |
| 438 SendGestureScrollUpdate(false, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0)); |
| 439 SendGestureScrollUpdate(false, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0)); |
| 440 SendGestureScrollEnd(); |
| 441 SendGestureScrollBegin(true); |
| 442 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0)); |
| 443 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0)); |
| 444 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0)); |
| 445 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 446 |
| 447 // Hit the -Y edge and overscroll slightly, but not enough to go over the |
| 448 // threshold to cause a stretch. |
| 449 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 0), |
| 450 gfx::ScrollOffset(10, 10)); |
| 451 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -8)); |
| 452 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 453 EXPECT_EQ(0, helper_.request_begin_frame_count()); |
| 454 |
| 455 // Take another step, this time going over the threshold. This should update |
| 456 // the stretch amount, and then switch to the animating mode. |
| 457 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80)); |
| 458 EXPECT_EQ(1, helper_.set_stretch_amount_count()); |
| 459 EXPECT_EQ(1, helper_.request_begin_frame_count()); |
| 460 EXPECT_GT(-1.f, helper_.StretchAmount().y()); |
| 461 |
| 462 // Subsequent momentum events should do nothing. |
| 463 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80)); |
| 464 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80)); |
| 465 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80)); |
| 466 SendGestureScrollEnd(); |
| 467 EXPECT_EQ(1, helper_.set_stretch_amount_count()); |
| 468 EXPECT_EQ(1, helper_.request_begin_frame_count()); |
| 469 |
| 470 // Subsequent animate events should update the stretch amount and request |
| 471 // another frame. |
| 472 TickCurrentTimeAndAnimate(); |
| 473 EXPECT_EQ(2, helper_.set_stretch_amount_count()); |
| 474 EXPECT_EQ(2, helper_.request_begin_frame_count()); |
| 475 EXPECT_GT(-1.f, helper_.StretchAmount().y()); |
| 476 |
| 477 // Touching the trackpad (a PhaseMayBegin event) should disable animation. |
| 478 SendGestureScrollBegin(false); |
| 479 TickCurrentTimeAndAnimate(); |
| 480 EXPECT_EQ(2, helper_.set_stretch_amount_count()); |
| 481 EXPECT_EQ(2, helper_.request_begin_frame_count()); |
| 482 |
| 483 // Releasing the trackpad should re-enable animation. |
| 484 SendGestureScrollEnd(); |
| 485 EXPECT_EQ(2, helper_.set_stretch_amount_count()); |
| 486 EXPECT_EQ(3, helper_.request_begin_frame_count()); |
| 487 TickCurrentTimeAndAnimate(); |
| 488 EXPECT_EQ(3, helper_.set_stretch_amount_count()); |
| 489 EXPECT_EQ(4, helper_.request_begin_frame_count()); |
| 490 |
| 491 // Keep animating frames until the stretch returns to rest. |
| 492 int stretch_count = 3; |
| 493 int begin_frame_count = 4; |
| 494 while (1) { |
| 495 TickCurrentTimeAndAnimate(); |
| 496 if (helper_.StretchAmount().IsZero()) { |
| 497 stretch_count += 1; |
| 498 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); |
| 499 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); |
| 500 break; |
| 501 } |
| 502 stretch_count += 1; |
| 503 begin_frame_count += 1; |
| 504 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); |
| 505 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); |
| 506 } |
| 507 |
| 508 // After coming to rest, no subsequent animate calls change anything. |
| 509 TickCurrentTimeAndAnimate(); |
| 510 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); |
| 511 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); |
| 512 } |
| 513 |
| 514 // Verify that a stretch opposing a scroll is correctly resolved. |
301 TEST_F(ScrollElasticityControllerTest, ReconcileStretchAndScroll) { | 515 TEST_F(ScrollElasticityControllerTest, ReconcileStretchAndScroll) { |
302 SendMouseWheelEvent(PhaseBegan, PhaseNone); | 516 SendMouseWheelEvent(PhaseBegan, PhaseNone); |
303 | 517 |
304 // Verify completely knocking out the scroll in the -Y direction. | 518 // Verify completely knocking out the scroll in the -Y direction. |
305 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), | 519 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), |
306 gfx::ScrollOffset(10, 10)); | 520 gfx::ScrollOffset(10, 10)); |
307 helper_.SetStretchAmount(gfx::Vector2dF(0, -10)); | 521 helper_.SetStretchAmount(gfx::Vector2dF(0, -10)); |
308 controller_.ReconcileStretchAndScroll(); | 522 controller_.ReconcileStretchAndScroll(); |
309 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, -5)); | 523 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, -5)); |
310 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(5, 0)); | 524 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(5, 0)); |
(...skipping 16 matching lines...) Expand all Loading... |
327 | 541 |
328 // Verify partially knocking out the scroll in the +X and +Y directions. | 542 // Verify partially knocking out the scroll in the +X and +Y directions. |
329 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(2, 3), | 543 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(2, 3), |
330 gfx::ScrollOffset(10, 10)); | 544 gfx::ScrollOffset(10, 10)); |
331 helper_.SetStretchAmount(gfx::Vector2dF(5, 5)); | 545 helper_.SetStretchAmount(gfx::Vector2dF(5, 5)); |
332 controller_.ReconcileStretchAndScroll(); | 546 controller_.ReconcileStretchAndScroll(); |
333 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); | 547 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
334 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(7, 8)); | 548 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(7, 8)); |
335 } | 549 } |
336 | 550 |
| 551 // Verify that a stretch opposing a scroll is correctly resolved. |
| 552 TEST_F(ScrollElasticityControllerTest, GestureBased_ReconcileStretchAndScroll) { |
| 553 SendGestureScrollBegin(false); |
| 554 |
| 555 // Verify completely knocking out the scroll in the -Y direction. |
| 556 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), |
| 557 gfx::ScrollOffset(10, 10)); |
| 558 helper_.SetStretchAmount(gfx::Vector2dF(0, -10)); |
| 559 controller_.ReconcileStretchAndScroll(); |
| 560 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, -5)); |
| 561 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(5, 0)); |
| 562 |
| 563 // Verify partially knocking out the scroll in the -Y direction. |
| 564 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 8), |
| 565 gfx::ScrollOffset(10, 10)); |
| 566 helper_.SetStretchAmount(gfx::Vector2dF(0, -5)); |
| 567 controller_.ReconcileStretchAndScroll(); |
| 568 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
| 569 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(5, 3)); |
| 570 |
| 571 // Verify completely knocking out the scroll in the +X direction. |
| 572 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), |
| 573 gfx::ScrollOffset(10, 10)); |
| 574 helper_.SetStretchAmount(gfx::Vector2dF(10, 0)); |
| 575 controller_.ReconcileStretchAndScroll(); |
| 576 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(5, 0)); |
| 577 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(10, 5)); |
| 578 |
| 579 // Verify partially knocking out the scroll in the +X and +Y directions. |
| 580 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(2, 3), |
| 581 gfx::ScrollOffset(10, 10)); |
| 582 helper_.SetStretchAmount(gfx::Vector2dF(5, 5)); |
| 583 controller_.ReconcileStretchAndScroll(); |
| 584 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
| 585 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(7, 8)); |
| 586 } |
| 587 |
337 // Verify that stretching only happens when the area is user scrollable. | 588 // Verify that stretching only happens when the area is user scrollable. |
338 TEST_F(ScrollElasticityControllerTest, UserScrollableRequiredForStretch) { | 589 TEST_F(ScrollElasticityControllerTest, UserScrollableRequiredForStretch) { |
339 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0), | 590 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0), |
340 gfx::ScrollOffset(10, 10)); | 591 gfx::ScrollOffset(10, 10)); |
341 gfx::Vector2dF delta(0, -15); | 592 gfx::Vector2dF delta(0, -15); |
342 | 593 |
343 // Do an active scroll, and ensure that the stretch amount doesn't change, | 594 // Do an active scroll, and ensure that the stretch amount doesn't change. |
344 // and also that the stretch amount isn't even ever changed. | |
345 helper_.SetUserScrollable(false); | 595 helper_.SetUserScrollable(false); |
346 SendMouseWheelEvent(PhaseBegan, PhaseNone); | 596 SendMouseWheelEvent(PhaseBegan, PhaseNone); |
347 SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta); | 597 SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta); |
348 SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta); | 598 SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta); |
349 SendMouseWheelEvent(PhaseEnded, PhaseNone); | 599 SendMouseWheelEvent(PhaseEnded, PhaseNone); |
350 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); | 600 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
351 EXPECT_EQ(0, helper_.set_stretch_amount_count()); | 601 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
352 SendMouseWheelEvent(PhaseNone, PhaseBegan); | 602 SendMouseWheelEvent(PhaseNone, PhaseBegan); |
353 SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta); | 603 SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta); |
354 SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta); | 604 SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta); |
(...skipping 22 matching lines...) Expand all Loading... |
377 int ticks_to_zero = 0; | 627 int ticks_to_zero = 0; |
378 while (1) { | 628 while (1) { |
379 TickCurrentTimeAndAnimate(); | 629 TickCurrentTimeAndAnimate(); |
380 if (helper_.StretchAmount().IsZero()) | 630 if (helper_.StretchAmount().IsZero()) |
381 break; | 631 break; |
382 ticks_to_zero += 1; | 632 ticks_to_zero += 1; |
383 } | 633 } |
384 EXPECT_GT(ticks_to_zero, 3); | 634 EXPECT_GT(ticks_to_zero, 3); |
385 } | 635 } |
386 | 636 |
| 637 // Verify that stretching only happens when the area is user scrollable. |
| 638 TEST_F(ScrollElasticityControllerTest, |
| 639 GestureBased_UserScrollableRequiredForStretch) { |
| 640 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0), |
| 641 gfx::ScrollOffset(10, 10)); |
| 642 gfx::Vector2dF delta(0, -15); |
| 643 |
| 644 // Do an active scroll, and ensure that the stretch amount doesn't change. |
| 645 helper_.SetUserScrollable(false); |
| 646 SendGestureScrollBegin(false); |
| 647 SendGestureScrollUpdate(false, delta, delta); |
| 648 SendGestureScrollUpdate(false, delta, delta); |
| 649 SendGestureScrollEnd(); |
| 650 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
| 651 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 652 SendGestureScrollBegin(true); |
| 653 SendGestureScrollUpdate(true, delta, delta); |
| 654 SendGestureScrollUpdate(true, delta, delta); |
| 655 SendGestureScrollEnd(); |
| 656 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
| 657 EXPECT_EQ(0, helper_.set_stretch_amount_count()); |
| 658 |
| 659 // Re-enable user scrolling and ensure that stretching is re-enabled. |
| 660 helper_.SetUserScrollable(true); |
| 661 SendGestureScrollBegin(false); |
| 662 SendGestureScrollUpdate(false, delta, delta); |
| 663 SendGestureScrollUpdate(false, delta, delta); |
| 664 SendGestureScrollEnd(); |
| 665 EXPECT_NE(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
| 666 EXPECT_GT(helper_.set_stretch_amount_count(), 0); |
| 667 SendGestureScrollBegin(true); |
| 668 SendGestureScrollUpdate(true, delta, delta); |
| 669 SendGestureScrollUpdate(true, delta, delta); |
| 670 SendGestureScrollEnd(); |
| 671 EXPECT_NE(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); |
| 672 EXPECT_GT(helper_.set_stretch_amount_count(), 0); |
| 673 |
| 674 // Disable user scrolling and tick the timer until the stretch goes back |
| 675 // to zero. Ensure that the return to zero doesn't happen immediately. |
| 676 helper_.SetUserScrollable(false); |
| 677 int ticks_to_zero = 0; |
| 678 while (1) { |
| 679 TickCurrentTimeAndAnimate(); |
| 680 if (helper_.StretchAmount().IsZero()) |
| 681 break; |
| 682 ticks_to_zero += 1; |
| 683 } |
| 684 EXPECT_GT(ticks_to_zero, 3); |
| 685 } |
| 686 |
387 } // namespace | 687 } // namespace |
388 } // namespace ui | 688 } // namespace ui |
OLD | NEW |