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

Side by Side Diff: ui/events/blink/input_scroll_elasticity_controller_unittest.cc

Issue 1749343004: Implement Wheel Gesture Scrolling on OSX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix non mac builds 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
OLDNEW
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
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 }
tdresser 2016/03/02 18:26:53 nit: newline
dtapuska 2016/03/07 18:03:59 Done.
135 void SendGestureScrollEnd() {
136 blink::WebGestureEvent event;
137 event.sourceDevice = blink::WebGestureDeviceTouchpad;
138 event.type = blink::WebInputEvent::GestureScrollEnd;
139
140 TickCurrentTime();
141 event.timeStampSeconds = (current_time_ - base::TimeTicks()).InSecondsF();
142
143 controller_.ObserveGestureEventAndResult(event,
144 cc::InputHandlerScrollResult());
145 input_event_count_ += 1;
146 }
147
102 const base::TimeTicks& TickCurrentTime() { 148 const base::TimeTicks& TickCurrentTime() {
103 current_time_ += base::TimeDelta::FromSecondsD(1 / 60.f); 149 current_time_ += base::TimeDelta::FromSecondsD(1 / 60.f);
104 return current_time_; 150 return current_time_;
105 } 151 }
106 void TickCurrentTimeAndAnimate() { 152 void TickCurrentTimeAndAnimate() {
107 TickCurrentTime(); 153 TickCurrentTime();
108 controller_.Animate(current_time_); 154 controller_.Animate(current_time_);
109 } 155 }
110 156
111 MockScrollElasticityHelper helper_; 157 MockScrollElasticityHelper helper_;
(...skipping 29 matching lines...) Expand all
141 gfx::Vector2dF(-25, 40)); 187 gfx::Vector2dF(-25, 40));
142 EXPECT_EQ(3, helper_.set_stretch_amount_count()); 188 EXPECT_EQ(3, helper_.set_stretch_amount_count());
143 EXPECT_GT(0.f, helper_.StretchAmount().x()); 189 EXPECT_GT(0.f, helper_.StretchAmount().x());
144 EXPECT_EQ(0.f, helper_.StretchAmount().y()); 190 EXPECT_EQ(0.f, helper_.StretchAmount().y());
145 helper_.SetStretchAmount(gfx::Vector2dF()); 191 helper_.SetStretchAmount(gfx::Vector2dF());
146 EXPECT_EQ(4, helper_.set_stretch_amount_count()); 192 EXPECT_EQ(4, helper_.set_stretch_amount_count());
147 SendMouseWheelEvent(PhaseEnded, PhaseNone); 193 SendMouseWheelEvent(PhaseEnded, PhaseNone);
148 EXPECT_EQ(0, helper_.request_begin_frame_count()); 194 EXPECT_EQ(0, helper_.request_begin_frame_count());
149 } 195 }
150 196
197 // Verify that stretching only occurs in one axis at a time, and that it
198 // is biased to the Y axis.
199 TEST_F(ScrollElasticityControllerTest, GestureBased_Axis) {
200 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0),
201 gfx::ScrollOffset(0, 0));
202
203 // If we push equally in the X and Y directions, we should see a stretch only
204 // in the Y direction.
205 SendGestureScrollBegin(false);
206 SendGestureScrollUpdate(false, gfx::Vector2dF(10, 10),
207 gfx::Vector2dF(10, 10));
208 EXPECT_EQ(1, helper_.set_stretch_amount_count());
209 EXPECT_EQ(0.f, helper_.StretchAmount().x());
210 EXPECT_LT(0.f, helper_.StretchAmount().y());
211 helper_.SetStretchAmount(gfx::Vector2dF());
212 EXPECT_EQ(2, helper_.set_stretch_amount_count());
213 SendGestureScrollEnd();
214 EXPECT_EQ(0, helper_.request_begin_frame_count());
215
216 // If we push more in the X direction than the Y direction, we should see a
217 // stretch only in the X direction. This decision should be based on the
218 // input delta, not the actual overscroll delta.
219 SendGestureScrollBegin(false);
220 SendGestureScrollUpdate(false, gfx::Vector2dF(-25, 10),
221 gfx::Vector2dF(-25, 40));
222 EXPECT_EQ(3, helper_.set_stretch_amount_count());
223 EXPECT_GT(0.f, helper_.StretchAmount().x());
224 EXPECT_EQ(0.f, helper_.StretchAmount().y());
225 helper_.SetStretchAmount(gfx::Vector2dF());
226 EXPECT_EQ(4, helper_.set_stretch_amount_count());
227 SendGestureScrollEnd();
228 EXPECT_EQ(0, helper_.request_begin_frame_count());
229 }
230
151 // Verify that we need a total overscroll delta of at least 10 in a pinned 231 // Verify that we need a total overscroll delta of at least 10 in a pinned
152 // direction before we start stretching. 232 // direction before we start stretching.
153 TEST_F(ScrollElasticityControllerTest, MinimumDeltaBeforeStretch) { 233 TEST_F(ScrollElasticityControllerTest, MinimumDeltaBeforeStretch) {
154 // We should not start stretching while we are not pinned in the direction 234 // 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 235 // 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. 236 // the regular scroll to eat all of the events.
157 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), 237 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5),
158 gfx::ScrollOffset(10, 10)); 238 gfx::ScrollOffset(10, 10));
159 SendMouseWheelEvent(PhaseMayBegin, PhaseNone); 239 SendMouseWheelEvent(PhaseMayBegin, PhaseNone);
160 SendMouseWheelEvent(PhaseBegan, PhaseNone); 240 SendMouseWheelEvent(PhaseBegan, PhaseNone);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_EQ(0.f, helper_.StretchAmount().x()); 274 EXPECT_EQ(0.f, helper_.StretchAmount().x());
195 EXPECT_LT(0.f, helper_.StretchAmount().y()); 275 EXPECT_LT(0.f, helper_.StretchAmount().y());
196 276
197 // End the gesture. Because there is a non-zero stretch, we should be in the 277 // 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. 278 // animated state, and should have had a frame requested.
199 EXPECT_EQ(0, helper_.request_begin_frame_count()); 279 EXPECT_EQ(0, helper_.request_begin_frame_count());
200 SendMouseWheelEvent(PhaseEnded, PhaseNone); 280 SendMouseWheelEvent(PhaseEnded, PhaseNone);
201 EXPECT_EQ(1, helper_.request_begin_frame_count()); 281 EXPECT_EQ(1, helper_.request_begin_frame_count());
202 } 282 }
203 283
284 // Verify that we need a total overscroll delta of at least 10 in a pinned
285 // direction before we start stretching.
286 TEST_F(ScrollElasticityControllerTest, GestureBased_MinimumDeltaBeforeStretch) {
287 // We should not start stretching while we are not pinned in the direction
288 // of the scroll (even if there is an overscroll delta). We have to wait for
289 // the regular scroll to eat all of the events.
290 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5),
291 gfx::ScrollOffset(10, 10));
292 SendGestureScrollBegin(false);
293 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 10));
294 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 10));
295 EXPECT_EQ(0, helper_.set_stretch_amount_count());
296
297 // Now pin the -X and +Y direction. The first event will not generate a
298 // stretch
299 // because it is below the delta threshold of 10.
300 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 10),
301 gfx::ScrollOffset(10, 10));
302 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 8));
303 EXPECT_EQ(0, helper_.set_stretch_amount_count());
304
305 // Make the next scroll be in the -X direction more than the +Y direction,
306 // which will erase the memory of the previous unused delta of 8.
307 SendGestureScrollUpdate(false, gfx::Vector2dF(-10, 5),
308 gfx::Vector2dF(-8, 10));
309 EXPECT_EQ(0, helper_.set_stretch_amount_count());
310
311 // Now push against the pinned +Y direction again by 8. We reset the
312 // previous delta, so this will not generate a stretch.
313 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 8));
314 EXPECT_EQ(0, helper_.set_stretch_amount_count());
315
316 // Push against +Y by another 8. This gets us above the delta threshold of
317 // 10, so we should now have had the stretch set, and it should be in the
318 // +Y direction. The scroll in the -X direction should have been forgotten.
319 SendGestureScrollUpdate(false, gfx::Vector2dF(0, 10), gfx::Vector2dF(0, 8));
320 EXPECT_EQ(1, helper_.set_stretch_amount_count());
321 EXPECT_EQ(0.f, helper_.StretchAmount().x());
322 EXPECT_LT(0.f, helper_.StretchAmount().y());
323
324 // End the gesture. Because there is a non-zero stretch, we should be in the
325 // animated state, and should have had a frame requested.
326 EXPECT_EQ(0, helper_.request_begin_frame_count());
327 SendGestureScrollEnd();
328 EXPECT_EQ(1, helper_.request_begin_frame_count());
329 }
330
204 // Verify that an stretch caused by a momentum scroll will switch to the 331 // Verify that an stretch caused by a momentum scroll will switch to the
205 // animating mode, where input events are ignored, and the stretch is updated 332 // animating mode, where input events are ignored, and the stretch is updated
206 // while animating. 333 // while animating.
207 TEST_F(ScrollElasticityControllerTest, MomentumAnimate) { 334 TEST_F(ScrollElasticityControllerTest, MomentumAnimate) {
208 // Do an active scroll, then switch to the momentum phase and scroll for a 335 // Do an active scroll, then switch to the momentum phase and scroll for a
209 // bit. 336 // bit.
210 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), 337 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5),
211 gfx::ScrollOffset(10, 10)); 338 gfx::ScrollOffset(10, 10));
212 SendMouseWheelEvent(PhaseBegan, PhaseNone); 339 SendMouseWheelEvent(PhaseBegan, PhaseNone);
213 SendMouseWheelEvent(PhaseChanged, PhaseNone, gfx::Vector2dF(0, -80), 340 SendMouseWheelEvent(PhaseChanged, PhaseNone, gfx::Vector2dF(0, -80),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); 417 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count());
291 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); 418 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count());
292 } 419 }
293 420
294 // After coming to rest, no subsequent animate calls change anything. 421 // After coming to rest, no subsequent animate calls change anything.
295 TickCurrentTimeAndAnimate(); 422 TickCurrentTimeAndAnimate();
296 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count()); 423 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count());
297 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count()); 424 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count());
298 } 425 }
299 426
427 // Verify that an stretch caused by a momentum scroll will switch to the
428 // animating mode, where input events are ignored, and the stretch is updated
429 // while animating.
430 TEST_F(ScrollElasticityControllerTest, GestureBased_MomentumAnimate) {
431 // Do an active scroll, then switch to the momentum phase and scroll for a
432 // bit.
433 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5),
434 gfx::ScrollOffset(10, 10));
435 SendGestureScrollBegin(false);
436 SendGestureScrollUpdate(false, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0));
437 SendGestureScrollUpdate(false, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0));
438 SendGestureScrollUpdate(false, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0));
439 SendGestureScrollEnd();
440 SendGestureScrollBegin(true);
441 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0));
442 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0));
443 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, 0));
444 EXPECT_EQ(0, helper_.set_stretch_amount_count());
445
446 // Hit the -Y edge and overscroll slightly, but not enough to go over the
447 // threshold to cause a stretch.
448 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 0),
449 gfx::ScrollOffset(10, 10));
450 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -8));
451 EXPECT_EQ(0, helper_.set_stretch_amount_count());
452 EXPECT_EQ(0, helper_.request_begin_frame_count());
453
454 // Take another step, this time going over the threshold. This should update
455 // the stretch amount, and then switch to the animating mode.
456 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80));
457 EXPECT_EQ(1, helper_.set_stretch_amount_count());
458 EXPECT_EQ(1, helper_.request_begin_frame_count());
459 EXPECT_GT(-1.f, helper_.StretchAmount().y());
460
461 // Subsequent momentum events should do nothing.
462 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80));
463 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80));
464 SendGestureScrollUpdate(true, gfx::Vector2dF(0, -80), gfx::Vector2dF(0, -80));
465 SendGestureScrollEnd();
466 EXPECT_EQ(1, helper_.set_stretch_amount_count());
467 EXPECT_EQ(1, helper_.request_begin_frame_count());
468
469 // Subsequent animate events should update the stretch amount and request
470 // another frame.
471 TickCurrentTimeAndAnimate();
472 EXPECT_EQ(2, helper_.set_stretch_amount_count());
473 EXPECT_EQ(2, helper_.request_begin_frame_count());
474 EXPECT_GT(-1.f, helper_.StretchAmount().y());
475
476 // Touching the trackpad (a PhaseMayBegin event) should disable animation.
477 SendGestureScrollBegin(false);
478 TickCurrentTimeAndAnimate();
479 EXPECT_EQ(2, helper_.set_stretch_amount_count());
480 EXPECT_EQ(2, helper_.request_begin_frame_count());
481
482 // Releasing the trackpad should re-enable animation.
483 SendGestureScrollEnd();
484 EXPECT_EQ(2, helper_.set_stretch_amount_count());
485 EXPECT_EQ(3, helper_.request_begin_frame_count());
486 TickCurrentTimeAndAnimate();
487 EXPECT_EQ(3, helper_.set_stretch_amount_count());
488 EXPECT_EQ(4, helper_.request_begin_frame_count());
489
490 // Keep animating frames until the stretch returns to rest.
491 int stretch_count = 3;
492 int begin_frame_count = 4;
493 while (1) {
494 TickCurrentTimeAndAnimate();
495 if (helper_.StretchAmount().IsZero()) {
496 stretch_count += 1;
497 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count());
498 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count());
499 break;
500 }
501 stretch_count += 1;
502 begin_frame_count += 1;
503 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count());
504 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count());
505 }
506
507 // After coming to rest, no subsequent animate calls change anything.
508 TickCurrentTimeAndAnimate();
509 EXPECT_EQ(stretch_count, helper_.set_stretch_amount_count());
510 EXPECT_EQ(begin_frame_count, helper_.request_begin_frame_count());
511 }
512
300 // Verify that an stretch opposing a scroll is correctly resolved. 513 // Verify that an stretch opposing a scroll is correctly resolved.
301 TEST_F(ScrollElasticityControllerTest, ReconcileStretchAndScroll) { 514 TEST_F(ScrollElasticityControllerTest, ReconcileStretchAndScroll) {
302 SendMouseWheelEvent(PhaseBegan, PhaseNone); 515 SendMouseWheelEvent(PhaseBegan, PhaseNone);
303 516
304 // Verify completely knocking out the scroll in the -Y direction. 517 // Verify completely knocking out the scroll in the -Y direction.
305 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5), 518 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5),
306 gfx::ScrollOffset(10, 10)); 519 gfx::ScrollOffset(10, 10));
307 helper_.SetStretchAmount(gfx::Vector2dF(0, -10)); 520 helper_.SetStretchAmount(gfx::Vector2dF(0, -10));
308 controller_.ReconcileStretchAndScroll(); 521 controller_.ReconcileStretchAndScroll();
309 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, -5)); 522 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, -5));
(...skipping 17 matching lines...) Expand all
327 540
328 // Verify partially knocking out the scroll in the +X and +Y directions. 541 // Verify partially knocking out the scroll in the +X and +Y directions.
329 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(2, 3), 542 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(2, 3),
330 gfx::ScrollOffset(10, 10)); 543 gfx::ScrollOffset(10, 10));
331 helper_.SetStretchAmount(gfx::Vector2dF(5, 5)); 544 helper_.SetStretchAmount(gfx::Vector2dF(5, 5));
332 controller_.ReconcileStretchAndScroll(); 545 controller_.ReconcileStretchAndScroll();
333 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0)); 546 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
334 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(7, 8)); 547 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(7, 8));
335 } 548 }
336 549
550 // Verify that an stretch opposing a scroll is correctly resolved.
551 TEST_F(ScrollElasticityControllerTest, GestureBased_ReconcileStretchAndScroll) {
552 SendGestureScrollBegin(false);
553
554 // Verify completely knocking out the scroll in the -Y direction.
555 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5),
556 gfx::ScrollOffset(10, 10));
557 helper_.SetStretchAmount(gfx::Vector2dF(0, -10));
558 controller_.ReconcileStretchAndScroll();
559 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, -5));
560 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(5, 0));
561
562 // Verify partially knocking out the scroll in the -Y direction.
563 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 8),
564 gfx::ScrollOffset(10, 10));
565 helper_.SetStretchAmount(gfx::Vector2dF(0, -5));
566 controller_.ReconcileStretchAndScroll();
567 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
568 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(5, 3));
569
570 // Verify completely knocking out the scroll in the +X direction.
571 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(5, 5),
572 gfx::ScrollOffset(10, 10));
573 helper_.SetStretchAmount(gfx::Vector2dF(10, 0));
574 controller_.ReconcileStretchAndScroll();
575 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(5, 0));
576 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(10, 5));
577
578 // Verify partially knocking out the scroll in the +X and +Y directions.
579 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(2, 3),
580 gfx::ScrollOffset(10, 10));
581 helper_.SetStretchAmount(gfx::Vector2dF(5, 5));
582 controller_.ReconcileStretchAndScroll();
583 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
584 EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(7, 8));
585 }
586
337 // Verify that stretching only happens when the area is user scrollable. 587 // Verify that stretching only happens when the area is user scrollable.
338 TEST_F(ScrollElasticityControllerTest, UserScrollableRequiredForStretch) { 588 TEST_F(ScrollElasticityControllerTest, UserScrollableRequiredForStretch) {
339 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0), 589 helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0),
340 gfx::ScrollOffset(10, 10)); 590 gfx::ScrollOffset(10, 10));
341 gfx::Vector2dF delta(0, -15); 591 gfx::Vector2dF delta(0, -15);
342 592
343 // Do an active scroll, and ensure that the stretch amount doesn't change, 593 // 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. 594 // 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);
(...skipping 30 matching lines...) Expand all
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 // and also that the stretch amount isn't even ever changed.
646 helper_.SetUserScrollable(false);
647 SendGestureScrollBegin(false);
648 SendGestureScrollUpdate(false, delta, delta);
649 SendGestureScrollUpdate(false, delta, delta);
650 SendGestureScrollEnd();
651 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
652 EXPECT_EQ(0, helper_.set_stretch_amount_count());
653 SendGestureScrollBegin(true);
654 SendGestureScrollUpdate(true, delta, delta);
655 SendGestureScrollUpdate(true, delta, delta);
656 SendGestureScrollEnd();
657 EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
658 EXPECT_EQ(0, helper_.set_stretch_amount_count());
659
660 // Re-enable user scrolling and ensure that stretching is re-enabled.
661 helper_.SetUserScrollable(true);
662 SendGestureScrollBegin(false);
663 SendGestureScrollUpdate(false, delta, delta);
664 SendGestureScrollUpdate(false, delta, delta);
665 SendGestureScrollEnd();
666 EXPECT_NE(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
667 EXPECT_GT(helper_.set_stretch_amount_count(), 0);
668 SendGestureScrollBegin(true);
669 SendGestureScrollUpdate(true, delta, delta);
670 SendGestureScrollUpdate(true, delta, delta);
671 SendGestureScrollEnd();
672 EXPECT_NE(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
673 EXPECT_GT(helper_.set_stretch_amount_count(), 0);
674
675 // Disable user scrolling and tick the timer until the stretch goes back
676 // to zero. Ensure that the return to zero doesn't happen immediately.
677 helper_.SetUserScrollable(false);
678 int ticks_to_zero = 0;
679 while (1) {
680 TickCurrentTimeAndAnimate();
681 if (helper_.StretchAmount().IsZero())
682 break;
683 ticks_to_zero += 1;
684 }
685 EXPECT_GT(ticks_to_zero, 3);
686 }
687
387 } // namespace 688 } // namespace
388 } // namespace ui 689 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698