1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/memory/scoped_vector.h"
7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/timer/timer.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/test/aura_test_base.h"
13 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/base/hit_test.h"
18 #include "ui/base/ui_base_switches.h"
19 #include "ui/events/event.h"
20 #include "ui/events/event_switches.h"
21 #include "ui/events/event_utils.h"
22 #include "ui/events/gesture_detection/gesture_configuration.h"
23 #include "ui/events/gestures/gesture_recognizer_impl.h"
24 #include "ui/events/gestures/gesture_types.h"
25 #include "ui/events/test/event_generator.h"
26 #include "ui/events/test/events_test_utils.h"
27 #include "ui/gfx/geometry/point.h"
28 #include "ui/gfx/geometry/rect.h"
37 std::string
WindowIDAsString(ui::GestureConsumer
* consumer
) {
39 base::IntToString(static_cast<Window
*>(consumer
)->id()) : "?";
42 #define EXPECT_0_EVENTS(events) \
43 EXPECT_EQ(0u, events.size())
45 #define EXPECT_1_EVENT(events, e0) \
46 EXPECT_EQ(1u, events.size()); \
47 EXPECT_EQ(e0, events[0])
49 #define EXPECT_2_EVENTS(events, e0, e1) \
50 EXPECT_EQ(2u, events.size()); \
51 EXPECT_EQ(e0, events[0]); \
52 EXPECT_EQ(e1, events[1])
54 #define EXPECT_3_EVENTS(events, e0, e1, e2) \
55 EXPECT_EQ(3u, events.size()); \
56 EXPECT_EQ(e0, events[0]); \
57 EXPECT_EQ(e1, events[1]); \
58 EXPECT_EQ(e2, events[2])
60 #define EXPECT_4_EVENTS(events, e0, e1, e2, e3) \
61 EXPECT_EQ(4u, events.size()); \
62 EXPECT_EQ(e0, events[0]); \
63 EXPECT_EQ(e1, events[1]); \
64 EXPECT_EQ(e2, events[2]); \
65 EXPECT_EQ(e3, events[3])
67 // A delegate that keeps track of gesture events.
68 class GestureEventConsumeDelegate
: public TestWindowDelegate
{
70 GestureEventConsumeDelegate()
77 scroll_update_(false),
84 two_finger_tap_(false),
92 scroll_velocity_x_(0),
93 scroll_velocity_y_(0),
100 wait_until_event_(ui::ET_UNKNOWN
) {}
102 ~GestureEventConsumeDelegate() override
{}
111 scroll_begin_
= false;
112 scroll_update_
= false;
114 pinch_begin_
= false;
115 pinch_update_
= false;
119 two_finger_tap_
= false;
122 swipe_right_
= false;
126 scroll_begin_position_
.SetPoint(0, 0);
127 tap_location_
.SetPoint(0, 0);
128 gesture_end_location_
.SetPoint(0, 0);
132 scroll_velocity_x_
= 0;
133 scroll_velocity_y_
= 0;
141 latency_info_
.Clear();
144 const std::vector
<ui::EventType
>& events() const { return events_
; };
146 bool tap() const { return tap_
; }
147 bool tap_down() const { return tap_down_
; }
148 bool tap_cancel() const { return tap_cancel_
; }
149 bool begin() const { return begin_
; }
150 bool end() const { return end_
; }
151 bool scroll_begin() const { return scroll_begin_
; }
152 bool scroll_update() const { return scroll_update_
; }
153 bool scroll_end() const { return scroll_end_
; }
154 bool pinch_begin() const { return pinch_begin_
; }
155 bool pinch_update() const { return pinch_update_
; }
156 bool pinch_end() const { return pinch_end_
; }
157 bool long_press() const { return long_press_
; }
158 bool long_tap() const { return long_tap_
; }
159 bool fling() const { return fling_
; }
160 bool two_finger_tap() const { return two_finger_tap_
; }
161 bool show_press() const { return show_press_
; }
162 bool swipe_left() const { return swipe_left_
; }
163 bool swipe_right() const { return swipe_right_
; }
164 bool swipe_up() const { return swipe_up_
; }
165 bool swipe_down() const { return swipe_down_
; }
167 const gfx::Point
& scroll_begin_position() const {
168 return scroll_begin_position_
;
171 const gfx::Point
& tap_location() const {
172 return tap_location_
;
175 const gfx::Point
& gesture_end_location() const {
176 return gesture_end_location_
;
179 float scroll_x() const { return scroll_x_
; }
180 float scroll_y() const { return scroll_y_
; }
181 float scroll_velocity_x() const { return scroll_velocity_x_
; }
182 float scroll_velocity_y() const { return scroll_velocity_y_
; }
183 float velocity_x() const { return velocity_x_
; }
184 float velocity_y() const { return velocity_y_
; }
185 float scroll_x_hint() const { return scroll_x_hint_
; }
186 float scroll_y_hint() const { return scroll_y_hint_
; }
187 float scale() const { return scale_
; }
188 const gfx::Rect
& bounding_box() const { return bounding_box_
; }
189 int tap_count() const { return tap_count_
; }
190 int flags() const { return flags_
; }
191 const ui::LatencyInfo
& latency_info() const { return latency_info_
; }
193 void WaitUntilReceivedGesture(ui::EventType type
) {
194 wait_until_event_
= type
;
195 run_loop_
.reset(new base::RunLoop());
199 void OnGestureEvent(ui::GestureEvent
* gesture
) override
{
200 events_
.push_back(gesture
->type());
201 bounding_box_
= gesture
->details().bounding_box();
202 flags_
= gesture
->flags();
203 latency_info_
= *gesture
->latency();
204 switch (gesture
->type()) {
205 case ui::ET_GESTURE_TAP
:
206 tap_location_
= gesture
->location();
207 tap_count_
= gesture
->details().tap_count();
210 case ui::ET_GESTURE_TAP_DOWN
:
213 case ui::ET_GESTURE_TAP_CANCEL
:
216 case ui::ET_GESTURE_BEGIN
:
219 case ui::ET_GESTURE_END
:
221 gesture_end_location_
= gesture
->location();
223 case ui::ET_GESTURE_SCROLL_BEGIN
:
224 scroll_begin_
= true;
225 scroll_begin_position_
= gesture
->location();
226 scroll_x_hint_
= gesture
->details().scroll_x_hint();
227 scroll_y_hint_
= gesture
->details().scroll_y_hint();
229 case ui::ET_GESTURE_SCROLL_UPDATE
:
230 scroll_update_
= true;
231 scroll_x_
+= gesture
->details().scroll_x();
232 scroll_y_
+= gesture
->details().scroll_y();
234 case ui::ET_GESTURE_SCROLL_END
:
235 EXPECT_TRUE(velocity_x_
== 0 && velocity_y_
== 0);
238 case ui::ET_GESTURE_PINCH_BEGIN
:
241 case ui::ET_GESTURE_PINCH_UPDATE
:
242 pinch_update_
= true;
243 scale_
= gesture
->details().scale();
245 case ui::ET_GESTURE_PINCH_END
:
248 case ui::ET_GESTURE_LONG_PRESS
:
251 case ui::ET_GESTURE_LONG_TAP
:
254 case ui::ET_SCROLL_FLING_START
:
255 EXPECT_TRUE(gesture
->details().velocity_x() != 0 ||
256 gesture
->details().velocity_y() != 0);
257 EXPECT_FALSE(scroll_end_
);
259 velocity_x_
= gesture
->details().velocity_x();
260 velocity_y_
= gesture
->details().velocity_y();
262 case ui::ET_GESTURE_TWO_FINGER_TAP
:
263 two_finger_tap_
= true;
265 case ui::ET_GESTURE_SHOW_PRESS
:
268 case ui::ET_GESTURE_SWIPE
:
269 swipe_left_
= gesture
->details().swipe_left();
270 swipe_right_
= gesture
->details().swipe_right();
271 swipe_up_
= gesture
->details().swipe_up();
272 swipe_down_
= gesture
->details().swipe_down();
274 case ui::ET_SCROLL_FLING_CANCEL
:
275 // Only used in unified gesture detection.
280 if (wait_until_event_
== gesture
->type() && run_loop_
) {
282 wait_until_event_
= ui::ET_UNKNOWN
;
284 gesture
->StopPropagation();
288 scoped_ptr
<base::RunLoop
> run_loop_
;
289 std::vector
<ui::EventType
> events_
;
305 bool two_finger_tap_
;
312 gfx::Point scroll_begin_position_
;
313 gfx::Point tap_location_
;
314 gfx::Point gesture_end_location_
;
318 float scroll_velocity_x_
;
319 float scroll_velocity_y_
;
322 float scroll_x_hint_
;
323 float scroll_y_hint_
;
325 gfx::Rect bounding_box_
;
328 ui::LatencyInfo latency_info_
;
330 ui::EventType wait_until_event_
;
332 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate
);
335 class QueueTouchEventDelegate
: public GestureEventConsumeDelegate
{
337 explicit QueueTouchEventDelegate(WindowEventDispatcher
* dispatcher
)
339 dispatcher_(dispatcher
),
340 synchronous_ack_for_next_event_(AckState::PENDING
) {}
342 ~QueueTouchEventDelegate() override
{}
344 void OnTouchEvent(ui::TouchEvent
* event
) override
{
345 event
->DisableSynchronousHandling();
346 if (synchronous_ack_for_next_event_
!= AckState::PENDING
) {
347 ui::GestureRecognizer::Get()->AckSyncTouchEvent(
348 event
->unique_event_id(),
349 synchronous_ack_for_next_event_
== AckState::CONSUMED
353 synchronous_ack_for_next_event_
= AckState::PENDING
;
358 ReceivedAckImpl(false);
361 void ReceivedAckPreventDefaulted() {
362 ReceivedAckImpl(true);
365 void set_window(Window
* w
) { window_
= w
; }
366 void set_synchronous_ack_for_next_event(bool consumed
) {
367 DCHECK(synchronous_ack_for_next_event_
== AckState::PENDING
);
368 synchronous_ack_for_next_event_
=
369 consumed
? AckState::CONSUMED
: AckState::UNCONSUMED
;
373 enum class AckState
{
379 void ReceivedAckImpl(bool prevent_defaulted
) {
380 dispatcher_
->ProcessedTouchEvent(
381 window_
, prevent_defaulted
? ui::ER_HANDLED
: ui::ER_UNHANDLED
);
385 WindowEventDispatcher
* dispatcher_
;
386 AckState synchronous_ack_for_next_event_
;
388 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate
);
391 // A delegate that ignores gesture events but keeps track of [synthetic] mouse
393 class GestureEventSynthDelegate
: public TestWindowDelegate
{
395 GestureEventSynthDelegate()
396 : mouse_enter_(false),
399 mouse_release_(false),
401 double_click_(false) {
405 mouse_enter_
= false;
407 mouse_press_
= false;
408 mouse_release_
= false;
410 double_click_
= false;
413 bool mouse_enter() const { return mouse_enter_
; }
414 bool mouse_exit() const { return mouse_exit_
; }
415 bool mouse_press() const { return mouse_press_
; }
416 bool mouse_move() const { return mouse_move_
; }
417 bool mouse_release() const { return mouse_release_
; }
418 bool double_click() const { return double_click_
; }
420 void OnMouseEvent(ui::MouseEvent
* event
) override
{
421 switch (event
->type()) {
422 case ui::ET_MOUSE_PRESSED
:
423 double_click_
= event
->flags() & ui::EF_IS_DOUBLE_CLICK
;
426 case ui::ET_MOUSE_RELEASED
:
427 mouse_release_
= true;
429 case ui::ET_MOUSE_MOVED
:
432 case ui::ET_MOUSE_ENTERED
:
435 case ui::ET_MOUSE_EXITED
:
452 DISALLOW_COPY_AND_ASSIGN(GestureEventSynthDelegate
);
455 class ScopedGestureRecognizerSetter
{
457 // Takes ownership of |new_gr|.
458 explicit ScopedGestureRecognizerSetter(ui::GestureRecognizer
* new_gr
)
460 original_gr_
= ui::GestureRecognizer::Get();
461 ui::SetGestureRecognizerForTesting(new_gr_
.get());
464 virtual ~ScopedGestureRecognizerSetter() {
465 ui::SetGestureRecognizerForTesting(original_gr_
);
469 ui::GestureRecognizer
* original_gr_
;
470 scoped_ptr
<ui::GestureRecognizer
> new_gr_
;
472 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter
);
480 // Use a non-zero start time to pass DCHECKs which ensure events have had a
482 TimedEvents() : simulated_now_(1) {
485 base::TimeDelta
Now() {
486 base::TimeDelta t
= base::TimeDelta::FromMilliseconds(simulated_now_
);
491 base::TimeDelta
LeapForward(int time_in_millis
) {
492 simulated_now_
+= time_in_millis
;
493 return base::TimeDelta::FromMilliseconds(simulated_now_
);
496 base::TimeDelta
InFuture(int time_in_millis
) {
497 return base::TimeDelta::FromMilliseconds(simulated_now_
+ time_in_millis
);
500 void SendScrollEvents(ui::EventProcessor
* dispatcher
,
508 GestureEventConsumeDelegate
* delegate
) {
512 for (int i
= 0; i
< num_steps
; i
++) {
515 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::PointF(x
, y
),
517 base::TimeDelta::FromMilliseconds(simulated_now_
));
518 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(&move
);
519 ASSERT_FALSE(details
.dispatcher_destroyed
);
520 simulated_now_
+= time_step
;
524 void SendScrollEvent(ui::EventProcessor
* dispatcher
,
528 GestureEventConsumeDelegate
* delegate
) {
530 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::PointF(x
, y
),
532 base::TimeDelta::FromMilliseconds(simulated_now_
));
533 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(&move
);
534 ASSERT_FALSE(details
.dispatcher_destroyed
);
539 // An event handler to keep track of events.
540 class TestEventHandler
: public ui::EventHandler
{
543 : touch_released_count_(0),
544 touch_pressed_count_(0),
545 touch_moved_count_(0) {}
547 ~TestEventHandler() override
{}
549 void OnTouchEvent(ui::TouchEvent
* event
) override
{
550 switch (event
->type()) {
551 case ui::ET_TOUCH_RELEASED
:
552 touch_released_count_
++;
554 case ui::ET_TOUCH_PRESSED
:
555 touch_pressed_count_
++;
557 case ui::ET_TOUCH_MOVED
:
558 touch_moved_count_
++;
560 case ui::ET_TOUCH_CANCELLED
:
561 cancelled_touch_points_
.push_back(event
->location());
569 touch_released_count_
= 0;
570 touch_pressed_count_
= 0;
571 touch_moved_count_
= 0;
572 cancelled_touch_points_
.clear();
575 int touch_released_count() const { return touch_released_count_
; }
576 int touch_pressed_count() const { return touch_pressed_count_
; }
577 int touch_moved_count() const { return touch_moved_count_
; }
578 int touch_cancelled_count() const {
579 return static_cast<int>(cancelled_touch_points_
.size());
581 const std::vector
<gfx::PointF
>& cancelled_touch_points() const {
582 return cancelled_touch_points_
;
586 int touch_released_count_
;
587 int touch_pressed_count_
;
588 int touch_moved_count_
;
589 std::vector
<gfx::PointF
> cancelled_touch_points_
;
591 DISALLOW_COPY_AND_ASSIGN(TestEventHandler
);
594 // Removes the target window from its parent when it receives a touch-cancel
596 class RemoveOnTouchCancelHandler
: public TestEventHandler
{
598 RemoveOnTouchCancelHandler() {}
599 ~RemoveOnTouchCancelHandler() override
{}
603 void OnTouchEvent(ui::TouchEvent
* event
) override
{
604 TestEventHandler::OnTouchEvent(event
);
605 if (event
->type() == ui::ET_TOUCH_CANCELLED
) {
606 Window
* target
= static_cast<Window
*>(event
->target());
607 // This is tiptoeing around crbug.com/310172. If this event handler isn't
608 // removed, we enter an infinite loop.
609 target
->RemovePreTargetHandler(this);
610 target
->parent()->RemoveChild(target
);
614 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler
);
617 void DelayByLongPressTimeout() {
618 ui::GestureProvider::Config config
;
619 base::RunLoop run_loop
;
620 base::MessageLoop::current()->PostDelayedTask(
622 run_loop
.QuitClosure(),
623 config
.gesture_detector_config
.longpress_timeout
* 2);
627 void DelayByShowPressTimeout() {
628 ui::GestureProvider::Config config
;
629 base::RunLoop run_loop
;
630 base::MessageLoop::current()->PostDelayedTask(
632 run_loop
.QuitClosure(),
633 config
.gesture_detector_config
.showpress_timeout
* 2);
639 class GestureRecognizerTest
: public AuraTestBase
,
640 public ::testing::WithParamInterface
<bool> {
642 GestureRecognizerTest() {}
644 void SetUp() override
{
645 AuraTestBase::SetUp();
646 ui::GestureConfiguration::GetInstance()->set_show_press_delay_in_ms(2);
647 ui::GestureConfiguration::GetInstance()->set_long_press_time_in_ms(3);
651 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest
);
654 class GestureRecognizerWithSwitchTest
: public GestureRecognizerTest
{
656 GestureRecognizerWithSwitchTest() {}
658 void SetUp() override
{
659 GestureRecognizerTest::SetUp();
660 base::CommandLine::ForCurrentProcess()->AppendSwitch(
661 switches::kCompensateForUnstablePinchZoom
);
662 ui::GestureConfiguration::GetInstance()->set_min_pinch_update_span_delta(5);
666 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerWithSwitchTest
);
669 // Check that appropriate touch events generate tap gesture events.
670 TEST_F(GestureRecognizerTest
, GestureEventTap
) {
671 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
672 new GestureEventConsumeDelegate());
674 const int kWindowWidth
= 123;
675 const int kWindowHeight
= 45;
676 const int kTouchId
= 2;
677 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
678 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
679 delegate
.get(), -1234, bounds
, root_window()));
682 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
683 kTouchId
, tes
.Now());
684 DispatchEventUsingWindowDispatcher(&press
);
685 EXPECT_FALSE(delegate
->tap());
686 EXPECT_FALSE(delegate
->show_press());
687 EXPECT_TRUE(delegate
->tap_down());
688 EXPECT_FALSE(delegate
->tap_cancel());
689 EXPECT_TRUE(delegate
->begin());
690 EXPECT_FALSE(delegate
->scroll_begin());
691 EXPECT_FALSE(delegate
->scroll_update());
692 EXPECT_FALSE(delegate
->scroll_end());
693 EXPECT_FALSE(delegate
->long_press());
696 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
697 EXPECT_TRUE(delegate
->show_press());
698 EXPECT_FALSE(delegate
->tap_down());
700 // Make sure there is enough delay before the touch is released so that it is
701 // recognized as a tap.
703 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
704 kTouchId
, tes
.LeapForward(50));
706 DispatchEventUsingWindowDispatcher(&release
);
707 EXPECT_TRUE(delegate
->tap());
708 EXPECT_FALSE(delegate
->tap_down());
709 EXPECT_FALSE(delegate
->tap_cancel());
710 EXPECT_FALSE(delegate
->begin());
711 EXPECT_TRUE(delegate
->end());
712 EXPECT_FALSE(delegate
->scroll_begin());
713 EXPECT_FALSE(delegate
->scroll_update());
714 EXPECT_FALSE(delegate
->scroll_end());
716 EXPECT_EQ(1, delegate
->tap_count());
719 // Check that appropriate touch events generate tap gesture events
720 // when information about the touch radii are provided.
721 TEST_F(GestureRecognizerTest
, GestureEventTapRegion
) {
722 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
723 new GestureEventConsumeDelegate());
725 const int kWindowWidth
= 800;
726 const int kWindowHeight
= 600;
727 const int kTouchId
= 2;
728 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
729 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
730 delegate
.get(), -1234, bounds
, root_window()));
732 // Test with no ET_TOUCH_MOVED events.
735 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
736 kTouchId
, tes
.Now());
737 press
.set_radius_x(5);
738 press
.set_radius_y(12);
739 DispatchEventUsingWindowDispatcher(&press
);
740 EXPECT_FALSE(delegate
->tap());
741 EXPECT_TRUE(delegate
->tap_down());
742 EXPECT_FALSE(delegate
->tap_cancel());
743 EXPECT_TRUE(delegate
->begin());
744 EXPECT_FALSE(delegate
->scroll_begin());
745 EXPECT_FALSE(delegate
->scroll_update());
746 EXPECT_FALSE(delegate
->scroll_end());
747 EXPECT_FALSE(delegate
->long_press());
749 // Make sure there is enough delay before the touch is released so that it
750 // is recognized as a tap.
752 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
753 kTouchId
, tes
.LeapForward(50));
754 release
.set_radius_x(5);
755 release
.set_radius_y(12);
757 DispatchEventUsingWindowDispatcher(&release
);
758 EXPECT_TRUE(delegate
->tap());
759 EXPECT_FALSE(delegate
->tap_down());
760 EXPECT_FALSE(delegate
->tap_cancel());
761 EXPECT_FALSE(delegate
->begin());
762 EXPECT_TRUE(delegate
->end());
763 EXPECT_FALSE(delegate
->scroll_begin());
764 EXPECT_FALSE(delegate
->scroll_update());
765 EXPECT_FALSE(delegate
->scroll_end());
767 EXPECT_EQ(1, delegate
->tap_count());
768 gfx::Point
actual_point(delegate
->tap_location());
769 EXPECT_EQ(24, delegate
->bounding_box().width());
770 EXPECT_EQ(24, delegate
->bounding_box().height());
771 EXPECT_EQ(101, actual_point
.x());
772 EXPECT_EQ(201, actual_point
.y());
775 // Test with no ET_TOUCH_MOVED events but different touch points and radii.
778 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(365, 290),
779 kTouchId
, tes
.Now());
780 press
.set_radius_x(8);
781 press
.set_radius_y(14);
782 DispatchEventUsingWindowDispatcher(&press
);
783 EXPECT_FALSE(delegate
->tap());
784 EXPECT_TRUE(delegate
->tap_down());
785 EXPECT_FALSE(delegate
->tap_cancel());
786 EXPECT_TRUE(delegate
->begin());
787 EXPECT_FALSE(delegate
->scroll_begin());
788 EXPECT_FALSE(delegate
->scroll_update());
789 EXPECT_FALSE(delegate
->scroll_end());
790 EXPECT_FALSE(delegate
->long_press());
793 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(367, 291),
794 kTouchId
, tes
.LeapForward(50));
795 release
.set_radius_x(20);
796 release
.set_radius_y(13);
798 DispatchEventUsingWindowDispatcher(&release
);
799 EXPECT_TRUE(delegate
->tap());
800 EXPECT_FALSE(delegate
->tap_down());
801 EXPECT_FALSE(delegate
->tap_cancel());
802 EXPECT_FALSE(delegate
->begin());
803 EXPECT_TRUE(delegate
->end());
804 EXPECT_FALSE(delegate
->scroll_begin());
805 EXPECT_FALSE(delegate
->scroll_update());
806 EXPECT_FALSE(delegate
->scroll_end());
808 EXPECT_EQ(1, delegate
->tap_count());
809 gfx::Point
actual_point(delegate
->tap_location());
810 EXPECT_EQ(40, delegate
->bounding_box().width());
811 EXPECT_EQ(40, delegate
->bounding_box().height());
812 EXPECT_EQ(367, actual_point
.x());
813 EXPECT_EQ(291, actual_point
.y());
816 // Test with a single ET_TOUCH_MOVED event.
819 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(46, 205),
820 kTouchId
, tes
.Now());
821 press
.set_radius_x(6);
822 press
.set_radius_y(10);
823 DispatchEventUsingWindowDispatcher(&press
);
824 EXPECT_FALSE(delegate
->tap());
825 EXPECT_TRUE(delegate
->tap_down());
826 EXPECT_FALSE(delegate
->tap_cancel());
827 EXPECT_TRUE(delegate
->begin());
828 EXPECT_FALSE(delegate
->tap_cancel());
829 EXPECT_FALSE(delegate
->scroll_begin());
830 EXPECT_FALSE(delegate
->scroll_update());
831 EXPECT_FALSE(delegate
->scroll_end());
832 EXPECT_FALSE(delegate
->long_press());
835 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(49, 204),
836 kTouchId
, tes
.LeapForward(50));
837 move
.set_radius_x(8);
838 move
.set_radius_y(12);
839 DispatchEventUsingWindowDispatcher(&move
);
840 EXPECT_FALSE(delegate
->tap());
841 EXPECT_FALSE(delegate
->tap_down());
842 EXPECT_FALSE(delegate
->tap_cancel());
843 EXPECT_FALSE(delegate
->begin());
844 EXPECT_FALSE(delegate
->scroll_begin());
845 EXPECT_FALSE(delegate
->scroll_update());
846 EXPECT_FALSE(delegate
->scroll_end());
847 EXPECT_FALSE(delegate
->long_press());
850 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(49, 204),
851 kTouchId
, tes
.LeapForward(50));
852 release
.set_radius_x(4);
853 release
.set_radius_y(8);
855 DispatchEventUsingWindowDispatcher(&release
);
856 EXPECT_TRUE(delegate
->tap());
857 EXPECT_FALSE(delegate
->tap_down());
858 EXPECT_FALSE(delegate
->tap_cancel());
859 EXPECT_FALSE(delegate
->begin());
860 EXPECT_TRUE(delegate
->end());
861 EXPECT_FALSE(delegate
->scroll_begin());
862 EXPECT_FALSE(delegate
->scroll_update());
863 EXPECT_FALSE(delegate
->scroll_end());
865 EXPECT_EQ(1, delegate
->tap_count());
866 gfx::Point
actual_point(delegate
->tap_location());
867 EXPECT_EQ(16, delegate
->bounding_box().width());
868 EXPECT_EQ(16, delegate
->bounding_box().height());
869 EXPECT_EQ(49, actual_point
.x());
870 EXPECT_EQ(204, actual_point
.y());
873 // Test with a few ET_TOUCH_MOVED events.
876 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(400, 150),
877 kTouchId
, tes
.Now());
878 press
.set_radius_x(7);
879 press
.set_radius_y(10);
880 DispatchEventUsingWindowDispatcher(&press
);
881 EXPECT_FALSE(delegate
->tap());
882 EXPECT_TRUE(delegate
->tap_down());
883 EXPECT_FALSE(delegate
->tap_cancel());
884 EXPECT_TRUE(delegate
->begin());
885 EXPECT_FALSE(delegate
->scroll_begin());
886 EXPECT_FALSE(delegate
->scroll_update());
887 EXPECT_FALSE(delegate
->scroll_end());
888 EXPECT_FALSE(delegate
->long_press());
891 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(397, 151),
892 kTouchId
, tes
.LeapForward(50));
893 move
.set_radius_x(13);
894 move
.set_radius_y(12);
895 DispatchEventUsingWindowDispatcher(&move
);
896 EXPECT_FALSE(delegate
->tap());
897 EXPECT_FALSE(delegate
->tap_down());
898 EXPECT_FALSE(delegate
->tap_cancel());
899 EXPECT_FALSE(delegate
->begin());
900 EXPECT_FALSE(delegate
->scroll_begin());
901 EXPECT_FALSE(delegate
->scroll_update());
902 EXPECT_FALSE(delegate
->scroll_end());
903 EXPECT_FALSE(delegate
->long_press());
906 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(397, 149),
907 kTouchId
, tes
.LeapForward(50));
908 move1
.set_radius_x(16);
909 move1
.set_radius_y(16);
910 DispatchEventUsingWindowDispatcher(&move1
);
911 EXPECT_FALSE(delegate
->tap());
912 EXPECT_FALSE(delegate
->tap_down());
913 EXPECT_FALSE(delegate
->tap_cancel());
914 EXPECT_FALSE(delegate
->begin());
915 EXPECT_FALSE(delegate
->scroll_begin());
916 EXPECT_FALSE(delegate
->scroll_update());
917 EXPECT_FALSE(delegate
->scroll_end());
918 EXPECT_FALSE(delegate
->long_press());
921 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(400, 150),
922 kTouchId
, tes
.LeapForward(50));
923 move2
.set_radius_x(14);
924 move2
.set_radius_y(10);
925 DispatchEventUsingWindowDispatcher(&move2
);
926 EXPECT_FALSE(delegate
->tap());
927 EXPECT_FALSE(delegate
->tap_down());
928 EXPECT_FALSE(delegate
->tap_cancel());
929 EXPECT_FALSE(delegate
->begin());
930 EXPECT_FALSE(delegate
->scroll_begin());
931 EXPECT_FALSE(delegate
->scroll_update());
932 EXPECT_FALSE(delegate
->scroll_end());
933 EXPECT_FALSE(delegate
->long_press());
936 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(401, 149),
937 kTouchId
, tes
.LeapForward(50));
938 release
.set_radius_x(8);
939 release
.set_radius_y(9);
941 DispatchEventUsingWindowDispatcher(&release
);
942 EXPECT_TRUE(delegate
->tap());
943 EXPECT_FALSE(delegate
->tap_down());
944 EXPECT_FALSE(delegate
->tap_cancel());
945 EXPECT_FALSE(delegate
->begin());
946 EXPECT_TRUE(delegate
->end());
947 EXPECT_FALSE(delegate
->scroll_begin());
948 EXPECT_FALSE(delegate
->scroll_update());
949 EXPECT_FALSE(delegate
->scroll_end());
951 EXPECT_EQ(1, delegate
->tap_count());
952 gfx::Point
actual_point(delegate
->tap_location());
953 EXPECT_EQ(18, delegate
->bounding_box().width());
954 EXPECT_EQ(18, delegate
->bounding_box().height());
955 EXPECT_EQ(401, actual_point
.x());
956 EXPECT_EQ(149, actual_point
.y());
960 // Check that appropriate touch events generate scroll gesture events.
961 TEST_F(GestureRecognizerTest
, GestureEventScroll
) {
962 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of
963 // that distance to be consumed by the slop, so we set the slop radius to
964 // sqrt(5 * 5 + 5 * 5).
965 ui::GestureConfiguration::GetInstance()
966 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f
* 5 + 5 * 5));
967 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
968 new GestureEventConsumeDelegate());
970 const int kWindowWidth
= 123;
971 const int kWindowHeight
= 45;
972 const int kTouchId
= 5;
973 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
974 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
975 delegate
.get(), -1234, bounds
, root_window()));
978 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
979 kTouchId
, tes
.Now());
980 DispatchEventUsingWindowDispatcher(&press
);
981 EXPECT_2_EVENTS(delegate
->events(),
982 ui::ET_GESTURE_BEGIN
,
983 ui::ET_GESTURE_TAP_DOWN
);
985 // Move the touch-point enough so that it is considered as a scroll. This
986 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
987 // The first movement is diagonal, to ensure that we have a free scroll,
988 // and not a rail scroll.
989 tes
.SendScrollEvent(event_processor(), 111.5, 211.5, kTouchId
,
991 EXPECT_3_EVENTS(delegate
->events(),
992 ui::ET_GESTURE_TAP_CANCEL
,
993 ui::ET_GESTURE_SCROLL_BEGIN
,
994 ui::ET_GESTURE_SCROLL_UPDATE
);
995 // The slop consumed 5 dips
996 EXPECT_FLOAT_EQ(5.5, delegate
->scroll_x());
997 EXPECT_FLOAT_EQ(5.5, delegate
->scroll_y());
998 EXPECT_EQ(gfx::Point(1, 1).ToString(),
999 delegate
->scroll_begin_position().ToString());
1001 // When scrolling with a single finger, the bounding box of the gesture should
1002 // be empty, since it's a single point and the radius for testing is zero.
1003 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1005 // Move some more to generate a few more scroll updates. Make sure that we get
1006 // out of the snap channel for the unified GR.
1007 tes
.SendScrollEvent(event_processor(), 20, 120, kTouchId
, delegate
.get());
1008 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1009 EXPECT_FLOAT_EQ(-91.5, delegate
->scroll_x());
1010 EXPECT_FLOAT_EQ(-91.5, delegate
->scroll_y());
1011 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1013 tes
.SendScrollEvent(event_processor(), 50, 124, kTouchId
, delegate
.get());
1014 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1015 EXPECT_EQ(30, delegate
->scroll_x());
1016 EXPECT_EQ(4, delegate
->scroll_y());
1017 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1019 // Release the touch. This should end the scroll.
1021 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1023 tes
.LeapForward(50));
1024 DispatchEventUsingWindowDispatcher(&release
);
1025 EXPECT_2_EVENTS(delegate
->events(),
1026 ui::ET_SCROLL_FLING_START
,
1027 ui::ET_GESTURE_END
);
1028 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1031 // Check that predicted scroll update positions are correct.
1032 TEST_F(GestureRecognizerTest
, GestureEventScrollPrediction
) {
1033 // We'll start by moving the touch point by (5, 5). We want all of that
1034 // distance to be consumed by the slop, so we set the slop radius to
1035 // sqrt(5 * 5 + 5 * 5).
1036 ui::GestureConfiguration::GetInstance()
1037 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f
* 5 + 5 * 5));
1039 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1040 new GestureEventConsumeDelegate());
1042 const int kWindowWidth
= 123;
1043 const int kWindowHeight
= 45;
1044 const int kTouchId
= 5;
1045 gfx::Rect
bounds(95, 195, kWindowWidth
, kWindowHeight
);
1046 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1047 delegate
.get(), -1234, bounds
, root_window()));
1050 // Tracks the total scroll since we want to verify that the correct position
1051 // will be scrolled to throughout the prediction.
1052 gfx::Vector2dF total_scroll
;
1053 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(96, 196),
1054 kTouchId
, tes
.Now());
1055 DispatchEventUsingWindowDispatcher(&press
);
1056 EXPECT_2_EVENTS(delegate
->events(),
1057 ui::ET_GESTURE_BEGIN
,
1058 ui::ET_GESTURE_TAP_DOWN
);
1061 // Get rid of touch slop.
1062 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(111, 211),
1063 kTouchId
, tes
.Now());
1064 DispatchEventUsingWindowDispatcher(&move
);
1065 EXPECT_3_EVENTS(delegate
->events(),
1066 ui::ET_GESTURE_TAP_CANCEL
,
1067 ui::ET_GESTURE_SCROLL_BEGIN
,
1068 ui::ET_GESTURE_SCROLL_UPDATE
);
1069 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1070 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1072 // Move the touch-point enough so that it is considered as a scroll. This
1073 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1074 // The first movement is diagonal, to ensure that we have a free scroll,
1075 // and not a rail scroll.
1076 tes
.LeapForward(30);
1077 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
1078 EXPECT_1_EVENT(delegate
->events(),
1079 ui::ET_GESTURE_SCROLL_UPDATE
);
1080 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1081 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1083 // Move some more to generate a few more scroll updates.
1084 tes
.LeapForward(30);
1085 tes
.SendScrollEvent(event_processor(), 110, 211, kTouchId
, delegate
.get());
1086 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1087 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1088 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1090 tes
.LeapForward(30);
1091 tes
.SendScrollEvent(event_processor(), 140, 215, kTouchId
, delegate
.get());
1092 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1093 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1094 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1096 // Release the touch. This should end the scroll.
1098 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1100 tes
.LeapForward(50));
1101 DispatchEventUsingWindowDispatcher(&release
);
1104 // Check that the bounding box during a scroll event is correct.
1105 TEST_F(GestureRecognizerTest
, GestureEventScrollBoundingBox
) {
1107 for (float radius
= 1; radius
<= 10; ++radius
) {
1108 ui::GestureConfiguration::GetInstance()->set_default_radius(radius
);
1109 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1110 new GestureEventConsumeDelegate());
1111 const int kWindowWidth
= 123;
1112 const int kWindowHeight
= 45;
1113 const int kTouchId
= 5;
1114 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1115 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1116 delegate
.get(), -1234, bounds
, root_window()));
1118 const float kPositionX
= 101;
1119 const float kPositionY
= 201;
1121 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1122 gfx::PointF(kPositionX
, kPositionY
),
1125 DispatchEventUsingWindowDispatcher(&press
);
1126 EXPECT_EQ(gfx::RectF(kPositionX
- radius
,
1127 kPositionY
- radius
,
1130 delegate
->bounding_box());
1132 const int kScrollAmount
= 50;
1133 tes
.SendScrollEvents(event_processor(), kPositionX
, kPositionY
,
1134 1, 1, kTouchId
, 1, kScrollAmount
, delegate
.get());
1135 EXPECT_EQ(gfx::Point(1, 1).ToString(),
1136 delegate
->scroll_begin_position().ToString());
1137 EXPECT_EQ(gfx::RectF(kPositionX
+ kScrollAmount
- radius
,
1138 kPositionY
+ kScrollAmount
- radius
,
1141 delegate
->bounding_box());
1143 // Release the touch. This should end the scroll.
1145 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1146 gfx::PointF(kPositionX
+ kScrollAmount
,
1147 kPositionY
+ kScrollAmount
),
1148 kTouchId
, press
.time_stamp() +
1149 base::TimeDelta::FromMilliseconds(50));
1150 DispatchEventUsingWindowDispatcher(&release
);
1151 EXPECT_EQ(gfx::RectF(kPositionX
+ kScrollAmount
- radius
,
1152 kPositionY
+ kScrollAmount
- radius
,
1155 delegate
->bounding_box());
1157 ui::GestureConfiguration::GetInstance()->set_default_radius(0);
1160 // Check Scroll End Events report correct velocities
1161 // if the user was on a horizontal rail
1162 TEST_F(GestureRecognizerTest
, GestureEventHorizontalRailFling
) {
1163 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1164 new GestureEventConsumeDelegate());
1166 const int kTouchId
= 7;
1167 gfx::Rect
bounds(0, 0, 1000, 1000);
1168 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1169 delegate
.get(), -1234, bounds
, root_window()));
1171 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1172 kTouchId
, tes
.Now());
1173 DispatchEventUsingWindowDispatcher(&press
);
1175 // Get rid of touch slop.
1176 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(10, 0),
1177 kTouchId
, tes
.Now());
1178 DispatchEventUsingWindowDispatcher(&move
);
1182 // Move the touch-point horizontally enough that it is considered a
1183 // horizontal scroll.
1184 tes
.SendScrollEvent(event_processor(), 30, 1, kTouchId
, delegate
.get());
1185 EXPECT_FLOAT_EQ(0, delegate
->scroll_y());
1186 EXPECT_FLOAT_EQ(20, delegate
->scroll_x());
1188 // Get a high x velocity, while still staying on the rail
1189 const int kScrollAmount
= 8;
1190 tes
.SendScrollEvents(event_processor(),
1201 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1202 kTouchId
, tes
.Now());
1203 DispatchEventUsingWindowDispatcher(&release
);
1205 EXPECT_TRUE(delegate
->fling());
1206 EXPECT_FALSE(delegate
->scroll_end());
1207 EXPECT_GT(delegate
->velocity_x(), 0);
1208 EXPECT_EQ(0, delegate
->velocity_y());
1211 // Check Scroll End Events report correct velocities
1212 // if the user was on a vertical rail
1213 TEST_F(GestureRecognizerTest
, GestureEventVerticalRailFling
) {
1214 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1215 new GestureEventConsumeDelegate());
1217 const int kTouchId
= 7;
1218 gfx::Rect
bounds(0, 0, 1000, 1000);
1219 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1220 delegate
.get(), -1234, bounds
, root_window()));
1222 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1223 kTouchId
, tes
.Now());
1224 DispatchEventUsingWindowDispatcher(&press
);
1226 // Get rid of touch slop.
1227 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(0, 10),
1228 kTouchId
, tes
.Now());
1229 DispatchEventUsingWindowDispatcher(&move
);
1232 // Move the touch-point vertically enough that it is considered a
1234 tes
.SendScrollEvent(event_processor(), 1, 30, kTouchId
, delegate
.get());
1235 EXPECT_EQ(20, delegate
->scroll_y());
1236 EXPECT_EQ(0, delegate
->scroll_x());
1237 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1239 // Get a high y velocity, while still staying on the rail
1240 const int kScrollAmount
= 8;
1241 tes
.SendScrollEvents(event_processor(),
1250 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1253 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 206),
1254 kTouchId
, tes
.Now());
1255 DispatchEventUsingWindowDispatcher(&release
);
1257 EXPECT_TRUE(delegate
->fling());
1258 EXPECT_FALSE(delegate
->scroll_end());
1259 EXPECT_EQ(0, delegate
->velocity_x());
1260 EXPECT_GT(delegate
->velocity_y(), 0);
1263 // Check Scroll End Events report non-zero velocities if the user is not on a
1265 TEST_F(GestureRecognizerTest
, GestureEventNonRailFling
) {
1266 ui::GestureConfiguration::GetInstance()
1267 ->set_max_touch_move_in_pixels_for_click(0);
1268 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1269 new GestureEventConsumeDelegate());
1271 const int kTouchId
= 7;
1272 gfx::Rect
bounds(0, 0, 1000, 1000);
1273 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1274 delegate
.get(), -1234, bounds
, root_window()));
1276 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1277 kTouchId
, tes
.Now());
1278 DispatchEventUsingWindowDispatcher(&press
);
1280 // Move the touch-point such that a non-rail scroll begins, and we're outside
1281 // the snap channel for the unified GR.
1282 tes
.SendScrollEvent(event_processor(), 50, 50, kTouchId
, delegate
.get());
1283 EXPECT_EQ(50, delegate
->scroll_y());
1284 EXPECT_EQ(50, delegate
->scroll_x());
1286 const int kScrollAmount
= 8;
1287 tes
.SendScrollEvents(event_processor(),
1298 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1299 kTouchId
, tes
.Now());
1300 DispatchEventUsingWindowDispatcher(&release
);
1302 EXPECT_TRUE(delegate
->fling());
1303 EXPECT_FALSE(delegate
->scroll_end());
1304 EXPECT_GT(delegate
->velocity_x(), 0);
1305 EXPECT_GT(delegate
->velocity_y(), 0);
1308 // Check that appropriate touch events generate long press events
1309 TEST_F(GestureRecognizerTest
, GestureEventLongPress
) {
1310 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1311 new GestureEventConsumeDelegate());
1312 const int kWindowWidth
= 123;
1313 const int kWindowHeight
= 45;
1314 const int kTouchId
= 2;
1315 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1316 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1317 delegate
.get(), -1234, bounds
, root_window()));
1321 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
1322 gfx::Point(101, 201),
1324 ui::EventTimeForNow());
1325 DispatchEventUsingWindowDispatcher(&press1
);
1326 EXPECT_TRUE(delegate
->tap_down());
1327 EXPECT_TRUE(delegate
->begin());
1328 EXPECT_FALSE(delegate
->tap_cancel());
1330 // We haven't pressed long enough for a long press to occur
1331 EXPECT_FALSE(delegate
->long_press());
1333 // Wait until the timer runs out
1334 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
1335 EXPECT_TRUE(delegate
->long_press());
1336 EXPECT_FALSE(delegate
->tap_cancel());
1339 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
,
1340 gfx::Point(101, 201),
1342 ui::EventTimeForNow());
1343 DispatchEventUsingWindowDispatcher(&release1
);
1344 EXPECT_FALSE(delegate
->long_press());
1346 // Note the tap cancel isn't dispatched until the release
1347 EXPECT_TRUE(delegate
->tap_cancel());
1348 EXPECT_FALSE(delegate
->tap());
1351 // Check that scrolling prevents a long press.
1352 TEST_F(GestureRecognizerTest
, GestureEventLongPressCancelledByScroll
) {
1353 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1354 new GestureEventConsumeDelegate());
1356 const int kWindowWidth
= 123;
1357 const int kWindowHeight
= 45;
1358 const int kTouchId
= 6;
1359 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1360 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1361 delegate
.get(), -1234, bounds
, root_window()));
1365 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1366 kTouchId
, tes
.Now());
1367 DispatchEventUsingWindowDispatcher(&press1
);
1368 EXPECT_TRUE(delegate
->tap_down());
1370 // We haven't pressed long enough for a long press to occur
1371 EXPECT_FALSE(delegate
->long_press());
1372 EXPECT_FALSE(delegate
->tap_cancel());
1374 // Scroll around, to cancel the long press
1375 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
1377 // Wait until a long press event would have fired, if it hadn't been
1379 DelayByLongPressTimeout();
1381 EXPECT_FALSE(delegate
->long_press());
1382 EXPECT_TRUE(delegate
->tap_cancel());
1385 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1386 kTouchId
, tes
.LeapForward(10));
1387 DispatchEventUsingWindowDispatcher(&release1
);
1388 EXPECT_FALSE(delegate
->long_press());
1389 EXPECT_FALSE(delegate
->tap_cancel());
1392 // Check that appropriate touch events generate long tap events
1393 TEST_F(GestureRecognizerTest
, GestureEventLongTap
) {
1394 ui::GestureConfiguration::GetInstance()
1395 ->set_max_touch_down_duration_for_click_in_ms(3);
1396 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1397 new GestureEventConsumeDelegate());
1398 const int kWindowWidth
= 123;
1399 const int kWindowHeight
= 45;
1400 const int kTouchId
= 2;
1401 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1402 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1403 delegate
.get(), -1234, bounds
, root_window()));
1407 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
1408 gfx::Point(101, 201),
1410 ui::EventTimeForNow());
1411 DispatchEventUsingWindowDispatcher(&press1
);
1412 EXPECT_TRUE(delegate
->tap_down());
1413 EXPECT_TRUE(delegate
->begin());
1414 EXPECT_FALSE(delegate
->tap_cancel());
1416 // We haven't pressed long enough for a long press to occur
1417 EXPECT_FALSE(delegate
->long_press());
1419 // Wait until the timer runs out
1420 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
1421 EXPECT_TRUE(delegate
->long_press());
1422 EXPECT_FALSE(delegate
->tap_cancel());
1425 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
,
1426 gfx::Point(101, 201),
1428 ui::EventTimeForNow());
1429 DispatchEventUsingWindowDispatcher(&release1
);
1430 EXPECT_FALSE(delegate
->long_press());
1431 EXPECT_TRUE(delegate
->long_tap());
1433 // Note the tap cancel isn't dispatched until the release
1434 EXPECT_TRUE(delegate
->tap_cancel());
1435 EXPECT_FALSE(delegate
->tap());
1438 // Check that second tap cancels a long press
1439 TEST_F(GestureRecognizerTest
, GestureEventLongPressCancelledBySecondTap
) {
1440 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1441 new GestureEventConsumeDelegate());
1443 const int kWindowWidth
= 300;
1444 const int kWindowHeight
= 400;
1445 const int kTouchId1
= 8;
1446 const int kTouchId2
= 2;
1447 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
1448 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1449 delegate
.get(), -1234, bounds
, root_window()));
1452 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1453 kTouchId1
, tes
.Now());
1454 DispatchEventUsingWindowDispatcher(&press
);
1455 EXPECT_TRUE(delegate
->tap_down());
1456 EXPECT_TRUE(delegate
->begin());
1458 // We haven't pressed long enough for a long press to occur
1459 EXPECT_FALSE(delegate
->long_press());
1461 // Second tap, to cancel the long press
1463 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1464 kTouchId2
, tes
.Now());
1465 DispatchEventUsingWindowDispatcher(&press2
);
1466 EXPECT_FALSE(delegate
->tap_down()); // no touch down for second tap.
1467 EXPECT_TRUE(delegate
->tap_cancel());
1468 EXPECT_TRUE(delegate
->begin());
1470 // Wait until the timer runs out
1471 DelayByLongPressTimeout();
1473 // No long press occurred
1474 EXPECT_FALSE(delegate
->long_press());
1477 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1478 kTouchId1
, tes
.Now());
1479 DispatchEventUsingWindowDispatcher(&release1
);
1480 EXPECT_FALSE(delegate
->long_press());
1481 EXPECT_TRUE(delegate
->two_finger_tap());
1482 EXPECT_FALSE(delegate
->tap_cancel());
1485 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1486 // Also tests that horizontal rails can be broken.
1487 TEST_F(GestureRecognizerTest
, GestureEventHorizontalRailScroll
) {
1488 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1489 new GestureEventConsumeDelegate());
1491 const int kTouchId
= 7;
1492 gfx::Rect
bounds(0, 0, 1000, 1000);
1493 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1494 delegate
.get(), -1234, bounds
, root_window()));
1496 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1497 kTouchId
, tes
.Now());
1498 DispatchEventUsingWindowDispatcher(&press
);
1500 // Get rid of touch slop.
1501 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(5, 0),
1502 kTouchId
, tes
.Now());
1504 DispatchEventUsingWindowDispatcher(&move
);
1507 // Move the touch-point horizontally enough that it is considered a
1508 // horizontal scroll.
1509 tes
.SendScrollEvent(event_processor(), 25, 0, kTouchId
, delegate
.get());
1510 EXPECT_EQ(0, delegate
->scroll_y());
1511 EXPECT_EQ(20, delegate
->scroll_x());
1513 tes
.SendScrollEvent(event_processor(), 30, 6, kTouchId
, delegate
.get());
1514 EXPECT_TRUE(delegate
->scroll_update());
1515 EXPECT_EQ(5, delegate
->scroll_x());
1516 // y shouldn't change, as we're on a horizontal rail.
1517 EXPECT_EQ(0, delegate
->scroll_y());
1519 // Send enough information that a velocity can be calculated for the gesture,
1520 // and we can break the rail
1521 const int kScrollAmount
= 8;
1522 tes
.SendScrollEvents(event_processor(),
1532 tes
.SendScrollEvent(event_processor(), 5, 0, kTouchId
, delegate
.get());
1533 tes
.SendScrollEvent(event_processor(), 10, 5, kTouchId
, delegate
.get());
1535 // The rail should be broken
1536 EXPECT_TRUE(delegate
->scroll_update());
1537 EXPECT_EQ(5, delegate
->scroll_x());
1538 EXPECT_EQ(5, delegate
->scroll_y());
1541 // Check that vertical scroll gestures cause scrolls on vertical rails.
1542 // Also tests that vertical rails can be broken.
1543 TEST_F(GestureRecognizerTest
, GestureEventVerticalRailScroll
) {
1544 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1545 new GestureEventConsumeDelegate());
1547 const int kTouchId
= 7;
1548 gfx::Rect
bounds(0, 0, 1000, 1000);
1549 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1550 delegate
.get(), -1234, bounds
, root_window()));
1552 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1553 kTouchId
, tes
.Now());
1554 DispatchEventUsingWindowDispatcher(&press
);
1556 // Get rid of touch slop.
1557 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(0, 5),
1558 kTouchId
, tes
.Now());
1559 DispatchEventUsingWindowDispatcher(&move
);
1562 // Move the touch-point vertically enough that it is considered a
1564 tes
.SendScrollEvent(event_processor(), 0, 25, kTouchId
, delegate
.get());
1565 EXPECT_EQ(0, delegate
->scroll_x());
1566 EXPECT_EQ(20, delegate
->scroll_y());
1568 tes
.SendScrollEvent(event_processor(), 6, 30, kTouchId
, delegate
.get());
1569 EXPECT_TRUE(delegate
->scroll_update());
1570 EXPECT_EQ(5, delegate
->scroll_y());
1571 // x shouldn't change, as we're on a vertical rail.
1572 EXPECT_EQ(0, delegate
->scroll_x());
1573 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1575 // Send enough information that a velocity can be calculated for the gesture,
1576 // and we can break the rail
1577 const int kScrollAmount
= 8;
1578 tes
.SendScrollEvents(event_processor(),
1588 tes
.SendScrollEvent(event_processor(), 0, 5, kTouchId
, delegate
.get());
1589 tes
.SendScrollEvent(event_processor(), 5, 10, kTouchId
, delegate
.get());
1591 // The rail should be broken
1592 EXPECT_TRUE(delegate
->scroll_update());
1593 EXPECT_EQ(5, delegate
->scroll_x());
1594 EXPECT_EQ(5, delegate
->scroll_y());
1597 TEST_F(GestureRecognizerTest
, GestureTapFollowedByScroll
) {
1598 // We'll start by moving the touch point by (5, 5). We want all of that
1599 // distance to be consumed by the slop, so we set the slop radius to
1600 // sqrt(5 * 5 + 5 * 5).
1601 ui::GestureConfiguration::GetInstance()
1602 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f
* 5 + 5 * 5));
1604 // First, tap. Then, do a scroll using the same touch-id.
1605 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1606 new GestureEventConsumeDelegate());
1608 const int kWindowWidth
= 123;
1609 const int kWindowHeight
= 45;
1610 const int kTouchId
= 3;
1611 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1612 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1613 delegate
.get(), -1234, bounds
, root_window()));
1616 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1617 kTouchId
, tes
.Now());
1618 DispatchEventUsingWindowDispatcher(&press
);
1619 EXPECT_FALSE(delegate
->tap());
1620 EXPECT_TRUE(delegate
->tap_down());
1621 EXPECT_FALSE(delegate
->tap_cancel());
1622 EXPECT_FALSE(delegate
->scroll_begin());
1623 EXPECT_FALSE(delegate
->scroll_update());
1624 EXPECT_FALSE(delegate
->scroll_end());
1626 // Make sure there is enough delay before the touch is released so that it is
1627 // recognized as a tap.
1629 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1630 kTouchId
, tes
.LeapForward(50));
1631 DispatchEventUsingWindowDispatcher(&release
);
1632 EXPECT_TRUE(delegate
->tap());
1633 EXPECT_FALSE(delegate
->tap_down());
1634 EXPECT_FALSE(delegate
->tap_cancel());
1635 EXPECT_FALSE(delegate
->scroll_begin());
1636 EXPECT_FALSE(delegate
->scroll_update());
1637 EXPECT_FALSE(delegate
->scroll_end());
1639 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger
1642 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1643 kTouchId
, tes
.LeapForward(1000));
1644 DispatchEventUsingWindowDispatcher(&press1
);
1645 EXPECT_FALSE(delegate
->tap());
1646 EXPECT_TRUE(delegate
->tap_down());
1647 EXPECT_FALSE(delegate
->tap_cancel());
1648 EXPECT_FALSE(delegate
->scroll_begin());
1649 EXPECT_FALSE(delegate
->scroll_update());
1650 EXPECT_FALSE(delegate
->scroll_end());
1652 // Get rid of touch slop.
1653 ui::TouchEvent
move_remove_slop(ui::ET_TOUCH_MOVED
, gfx::Point(116, 216),
1654 kTouchId
, tes
.Now());
1655 DispatchEventUsingWindowDispatcher(&move_remove_slop
);
1656 EXPECT_TRUE(delegate
->tap_cancel());
1657 EXPECT_TRUE(delegate
->scroll_begin());
1658 EXPECT_TRUE(delegate
->scroll_update());
1659 EXPECT_EQ(15, delegate
->scroll_x_hint());
1660 EXPECT_EQ(15, delegate
->scroll_y_hint());
1664 // Move the touch-point enough so that it is considered as a scroll. This
1665 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1666 // The first movement is diagonal, to ensure that we have a free scroll,
1667 // and not a rail scroll.
1669 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(135, 235),
1670 kTouchId
, tes
.Now());
1671 DispatchEventUsingWindowDispatcher(&move
);
1672 EXPECT_FALSE(delegate
->tap());
1673 EXPECT_FALSE(delegate
->tap_down());
1674 EXPECT_FALSE(delegate
->tap_cancel());
1675 EXPECT_FALSE(delegate
->scroll_begin());
1676 EXPECT_TRUE(delegate
->scroll_update());
1677 EXPECT_FALSE(delegate
->scroll_end());
1678 EXPECT_EQ(19, delegate
->scroll_x());
1679 EXPECT_EQ(19, delegate
->scroll_y());
1681 // Move some more to generate a few more scroll updates.
1683 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(115, 216),
1684 kTouchId
, tes
.Now());
1685 DispatchEventUsingWindowDispatcher(&move1
);
1686 EXPECT_FALSE(delegate
->tap());
1687 EXPECT_FALSE(delegate
->tap_down());
1688 EXPECT_FALSE(delegate
->tap_cancel());
1689 EXPECT_FALSE(delegate
->scroll_begin());
1690 EXPECT_TRUE(delegate
->scroll_update());
1691 EXPECT_FALSE(delegate
->scroll_end());
1692 EXPECT_EQ(-20, delegate
->scroll_x());
1693 EXPECT_EQ(-19, delegate
->scroll_y());
1694 EXPECT_EQ(0, delegate
->scroll_x_hint());
1695 EXPECT_EQ(0, delegate
->scroll_y_hint());
1698 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(145, 220),
1699 kTouchId
, tes
.Now());
1700 DispatchEventUsingWindowDispatcher(&move2
);
1701 EXPECT_FALSE(delegate
->tap());
1702 EXPECT_FALSE(delegate
->tap_down());
1703 EXPECT_FALSE(delegate
->tap_cancel());
1704 EXPECT_FALSE(delegate
->scroll_begin());
1705 EXPECT_TRUE(delegate
->scroll_update());
1706 EXPECT_FALSE(delegate
->scroll_end());
1707 EXPECT_EQ(30, delegate
->scroll_x());
1708 EXPECT_EQ(4, delegate
->scroll_y());
1710 // Release the touch. This should end the scroll.
1712 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1713 kTouchId
, tes
.Now());
1714 DispatchEventUsingWindowDispatcher(&release1
);
1715 EXPECT_FALSE(delegate
->tap());
1716 EXPECT_FALSE(delegate
->tap_down());
1717 EXPECT_FALSE(delegate
->tap_cancel());
1718 EXPECT_FALSE(delegate
->scroll_begin());
1719 EXPECT_FALSE(delegate
->scroll_update());
1720 EXPECT_FALSE(delegate
->scroll_end());
1721 EXPECT_TRUE(delegate
->fling());
1724 TEST_F(GestureRecognizerTest
, AsynchronousGestureRecognition
) {
1725 scoped_ptr
<QueueTouchEventDelegate
> queued_delegate(
1726 new QueueTouchEventDelegate(host()->dispatcher()));
1728 const int kWindowWidth
= 123;
1729 const int kWindowHeight
= 45;
1730 const int kTouchId1
= 6;
1731 const int kTouchId2
= 4;
1732 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1733 scoped_ptr
<aura::Window
> queue(CreateTestWindowWithDelegate(
1734 queued_delegate
.get(), -1234, bounds
, root_window()));
1736 queued_delegate
->set_window(queue
.get());
1738 // Touch down on the window. This should not generate any gesture event.
1739 queued_delegate
->Reset();
1740 ui::TouchEvent
press(
1741 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
1742 DispatchEventUsingWindowDispatcher(&press
);
1743 EXPECT_FALSE(queued_delegate
->tap());
1744 EXPECT_FALSE(queued_delegate
->tap_down());
1745 EXPECT_FALSE(queued_delegate
->tap_cancel());
1746 EXPECT_FALSE(queued_delegate
->begin());
1747 EXPECT_FALSE(queued_delegate
->scroll_begin());
1748 EXPECT_FALSE(queued_delegate
->scroll_update());
1749 EXPECT_FALSE(queued_delegate
->scroll_end());
1751 // Introduce some delay before the touch is released so that it is recognized
1752 // as a tap. However, this still should not create any gesture events.
1753 queued_delegate
->Reset();
1754 ui::TouchEvent
release(
1755 ui::ET_TOUCH_RELEASED
,
1756 gfx::Point(101, 201),
1758 press
.time_stamp() + base::TimeDelta::FromMilliseconds(50));
1759 DispatchEventUsingWindowDispatcher(&release
);
1760 EXPECT_FALSE(queued_delegate
->tap());
1761 EXPECT_FALSE(queued_delegate
->tap_down());
1762 EXPECT_FALSE(queued_delegate
->tap_cancel());
1763 EXPECT_FALSE(queued_delegate
->begin());
1764 EXPECT_FALSE(queued_delegate
->end());
1765 EXPECT_FALSE(queued_delegate
->scroll_begin());
1766 EXPECT_FALSE(queued_delegate
->scroll_update());
1767 EXPECT_FALSE(queued_delegate
->scroll_end());
1769 // Create another window, and place a touch-down on it. This should create a
1770 // tap-down gesture.
1771 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1772 new GestureEventConsumeDelegate());
1773 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1774 delegate
.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window()));
1776 ui::TouchEvent
press2(
1777 ui::ET_TOUCH_PRESSED
, gfx::Point(10, 20), kTouchId2
, tes
.Now());
1778 DispatchEventUsingWindowDispatcher(&press2
);
1779 EXPECT_FALSE(delegate
->tap());
1780 EXPECT_TRUE(delegate
->tap_down());
1781 EXPECT_FALSE(delegate
->tap_cancel());
1782 EXPECT_FALSE(queued_delegate
->begin());
1783 EXPECT_FALSE(queued_delegate
->end());
1784 EXPECT_FALSE(delegate
->scroll_begin());
1785 EXPECT_FALSE(delegate
->scroll_update());
1786 EXPECT_FALSE(delegate
->scroll_end());
1788 ui::TouchEvent
release2(
1789 ui::ET_TOUCH_RELEASED
, gfx::Point(10, 20), kTouchId2
, tes
.Now());
1790 DispatchEventUsingWindowDispatcher(&release2
);
1792 // Process the first queued event.
1793 queued_delegate
->Reset();
1794 queued_delegate
->ReceivedAck();
1795 EXPECT_FALSE(queued_delegate
->tap());
1796 EXPECT_TRUE(queued_delegate
->tap_down());
1797 EXPECT_TRUE(queued_delegate
->begin());
1798 EXPECT_FALSE(queued_delegate
->tap_cancel());
1799 EXPECT_FALSE(queued_delegate
->end());
1800 EXPECT_FALSE(queued_delegate
->scroll_begin());
1801 EXPECT_FALSE(queued_delegate
->scroll_update());
1802 EXPECT_FALSE(queued_delegate
->scroll_end());
1804 // Now, process the second queued event.
1805 queued_delegate
->Reset();
1806 queued_delegate
->ReceivedAck();
1807 EXPECT_TRUE(queued_delegate
->tap());
1808 EXPECT_FALSE(queued_delegate
->tap_down());
1809 EXPECT_FALSE(queued_delegate
->tap_cancel());
1810 EXPECT_FALSE(queued_delegate
->begin());
1811 EXPECT_TRUE(queued_delegate
->end());
1812 EXPECT_FALSE(queued_delegate
->scroll_begin());
1813 EXPECT_FALSE(queued_delegate
->scroll_update());
1814 EXPECT_FALSE(queued_delegate
->scroll_end());
1816 // Start all over. Press on the first window, then press again on the second
1817 // window. The second press should still go to the first window.
1818 queued_delegate
->Reset();
1819 ui::TouchEvent
press3(
1820 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
1821 DispatchEventUsingWindowDispatcher(&press3
);
1822 EXPECT_FALSE(queued_delegate
->tap());
1823 EXPECT_FALSE(queued_delegate
->tap_down());
1824 EXPECT_FALSE(queued_delegate
->tap_cancel());
1825 EXPECT_FALSE(queued_delegate
->begin());
1826 EXPECT_FALSE(queued_delegate
->end());
1827 EXPECT_FALSE(queued_delegate
->begin());
1828 EXPECT_FALSE(queued_delegate
->end());
1829 EXPECT_FALSE(queued_delegate
->scroll_begin());
1830 EXPECT_FALSE(queued_delegate
->scroll_update());
1831 EXPECT_FALSE(queued_delegate
->scroll_end());
1833 queued_delegate
->Reset();
1835 ui::TouchEvent
press4(
1836 ui::ET_TOUCH_PRESSED
, gfx::Point(103, 203), kTouchId2
, tes
.Now());
1837 DispatchEventUsingWindowDispatcher(&press4
);
1838 EXPECT_FALSE(delegate
->tap());
1839 EXPECT_FALSE(delegate
->tap_down());
1840 EXPECT_FALSE(delegate
->tap_cancel());
1841 EXPECT_FALSE(delegate
->begin());
1842 EXPECT_FALSE(delegate
->end());
1843 EXPECT_FALSE(delegate
->scroll_begin());
1844 EXPECT_FALSE(delegate
->scroll_update());
1845 EXPECT_FALSE(delegate
->scroll_end());
1846 EXPECT_FALSE(queued_delegate
->tap());
1847 EXPECT_FALSE(queued_delegate
->tap_down());
1848 EXPECT_FALSE(queued_delegate
->tap_cancel());
1849 EXPECT_FALSE(queued_delegate
->begin());
1850 EXPECT_FALSE(queued_delegate
->end());
1851 EXPECT_FALSE(queued_delegate
->scroll_begin());
1852 EXPECT_FALSE(queued_delegate
->scroll_update());
1853 EXPECT_FALSE(queued_delegate
->scroll_end());
1855 // Move the second touch-point enough so that it is considered a pinch. This
1856 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures.
1857 queued_delegate
->Reset();
1859 ui::TouchEvent
move(
1862 ui::GestureConfiguration::GetInstance()
1863 ->max_touch_move_in_pixels_for_click(),
1867 DispatchEventUsingWindowDispatcher(&move
);
1868 EXPECT_FALSE(delegate
->tap());
1869 EXPECT_FALSE(delegate
->tap_down());
1870 EXPECT_FALSE(delegate
->tap_cancel());
1871 EXPECT_FALSE(delegate
->begin());
1872 EXPECT_FALSE(delegate
->scroll_begin());
1873 EXPECT_FALSE(delegate
->scroll_update());
1874 EXPECT_FALSE(delegate
->scroll_end());
1875 EXPECT_FALSE(queued_delegate
->tap());
1876 EXPECT_FALSE(queued_delegate
->tap_down());
1877 EXPECT_FALSE(queued_delegate
->tap_cancel());
1878 EXPECT_FALSE(queued_delegate
->begin());
1879 EXPECT_FALSE(queued_delegate
->scroll_begin());
1880 EXPECT_FALSE(queued_delegate
->scroll_update());
1881 EXPECT_FALSE(queued_delegate
->scroll_end());
1883 queued_delegate
->Reset();
1884 queued_delegate
->ReceivedAck();
1885 EXPECT_FALSE(queued_delegate
->tap());
1886 EXPECT_TRUE(queued_delegate
->tap_down());
1887 EXPECT_TRUE(queued_delegate
->begin());
1888 EXPECT_FALSE(queued_delegate
->tap_cancel());
1889 EXPECT_FALSE(queued_delegate
->end());
1890 EXPECT_FALSE(queued_delegate
->scroll_begin());
1891 EXPECT_FALSE(queued_delegate
->scroll_update());
1892 EXPECT_FALSE(queued_delegate
->scroll_end());
1894 queued_delegate
->Reset();
1895 queued_delegate
->ReceivedAck();
1896 EXPECT_FALSE(queued_delegate
->tap());
1897 EXPECT_FALSE(queued_delegate
->tap_down()); // no touch down for second tap.
1898 EXPECT_TRUE(queued_delegate
->tap_cancel());
1899 EXPECT_TRUE(queued_delegate
->begin());
1900 EXPECT_FALSE(queued_delegate
->end());
1901 EXPECT_FALSE(queued_delegate
->scroll_begin());
1902 EXPECT_FALSE(queued_delegate
->scroll_update());
1903 EXPECT_FALSE(queued_delegate
->scroll_end());
1904 EXPECT_FALSE(queued_delegate
->pinch_begin());
1905 EXPECT_FALSE(queued_delegate
->pinch_update());
1906 EXPECT_FALSE(queued_delegate
->pinch_end());
1908 queued_delegate
->Reset();
1909 queued_delegate
->ReceivedAck();
1910 EXPECT_FALSE(queued_delegate
->tap());
1911 EXPECT_FALSE(queued_delegate
->tap_down());
1912 EXPECT_FALSE(queued_delegate
->tap_cancel());
1913 EXPECT_FALSE(queued_delegate
->begin());
1914 EXPECT_FALSE(queued_delegate
->end());
1915 EXPECT_TRUE(queued_delegate
->scroll_begin());
1917 EXPECT_TRUE(queued_delegate
->scroll_update());
1918 EXPECT_FALSE(queued_delegate
->scroll_end());
1919 EXPECT_TRUE(queued_delegate
->pinch_begin());
1920 EXPECT_FALSE(queued_delegate
->pinch_update());
1921 EXPECT_FALSE(queued_delegate
->pinch_end());
1924 // Check that appropriate touch events generate pinch gesture events.
1925 TEST_F(GestureRecognizerTest
, GestureEventPinchFromScroll
) {
1926 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1927 new GestureEventConsumeDelegate());
1929 const int kWindowWidth
= 300;
1930 const int kWindowHeight
= 400;
1931 const int kTouchId1
= 5;
1932 const int kTouchId2
= 3;
1933 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
1934 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1935 delegate
.get(), -1234, bounds
, root_window()));
1938 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1939 kTouchId1
, tes
.Now());
1940 DispatchEventUsingWindowDispatcher(&press
);
1941 EXPECT_2_EVENTS(delegate
->events(),
1942 ui::ET_GESTURE_BEGIN
,
1943 ui::ET_GESTURE_TAP_DOWN
);
1945 // Move the touch-point enough so that it is considered as a scroll. This
1946 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1948 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(130, 301),
1949 kTouchId1
, tes
.Now());
1950 DispatchEventUsingWindowDispatcher(&move
);
1951 EXPECT_3_EVENTS(delegate
->events(),
1952 ui::ET_GESTURE_TAP_CANCEL
,
1953 ui::ET_GESTURE_SCROLL_BEGIN
,
1954 ui::ET_GESTURE_SCROLL_UPDATE
);
1956 // Press the second finger. It should cause pinch-begin. Note that we will not
1957 // transition to two finger tap here because the touch points are far enough.
1959 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1960 kTouchId2
, tes
.Now());
1961 DispatchEventUsingWindowDispatcher(&press2
);
1962 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_BEGIN
);
1963 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(),
1964 delegate
->bounding_box().ToString());
1966 // Move the first finger.
1968 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(95, 201),
1969 kTouchId1
, tes
.Now());
1970 DispatchEventUsingWindowDispatcher(&move3
);
1971 EXPECT_2_EVENTS(delegate
->events(),
1972 ui::ET_GESTURE_SCROLL_UPDATE
,
1973 ui::ET_GESTURE_PINCH_BEGIN
);
1974 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(),
1975 delegate
->bounding_box().ToString());
1977 // Now move the second finger.
1979 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(55, 15),
1980 kTouchId2
, tes
.Now());
1981 DispatchEventUsingWindowDispatcher(&move4
);
1982 EXPECT_2_EVENTS(delegate
->events(),
1983 ui::ET_GESTURE_SCROLL_UPDATE
,
1984 ui::ET_GESTURE_PINCH_UPDATE
);
1985 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(),
1986 delegate
->bounding_box().ToString());
1988 // Release the first finger. This should end pinch.
1990 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1991 kTouchId1
, tes
.Now());
1992 DispatchEventUsingWindowDispatcher(&release
);
1993 EXPECT_2_EVENTS(delegate
->events(),
1994 ui::ET_GESTURE_PINCH_END
,
1995 ui::ET_GESTURE_END
);
1996 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
1997 delegate
->bounding_box().ToString());
1999 // Move the second finger. This should still generate a scroll.
2001 ui::TouchEvent
move5(ui::ET_TOUCH_MOVED
, gfx::Point(25, 10),
2002 kTouchId2
, tes
.Now());
2003 DispatchEventUsingWindowDispatcher(&move5
);
2004 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
2005 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2008 TEST_F(GestureRecognizerTest
, GestureEventPinchFromScrollFromPinch
) {
2009 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2010 new GestureEventConsumeDelegate());
2012 const int kWindowWidth
= 300;
2013 const int kWindowHeight
= 400;
2014 const int kTouchId1
= 5;
2015 const int kTouchId2
= 3;
2016 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
2017 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2018 delegate
.get(), -1234, bounds
, root_window()));
2020 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
2021 kTouchId1
, tes
.Now());
2022 DispatchEventUsingWindowDispatcher(&press
);
2024 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2025 kTouchId2
, tes
.Now());
2026 DispatchEventUsingWindowDispatcher(&press2
);
2027 EXPECT_FALSE(delegate
->pinch_begin());
2029 // Touch move triggers pinch begin.
2030 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId1
, delegate
.get());
2031 EXPECT_TRUE(delegate
->pinch_begin());
2032 EXPECT_FALSE(delegate
->pinch_update());
2034 // Touch move triggers pinch update.
2035 tes
.SendScrollEvent(event_processor(), 160, 200, kTouchId1
, delegate
.get());
2036 EXPECT_FALSE(delegate
->pinch_begin());
2037 EXPECT_TRUE(delegate
->pinch_update());
2039 // Pinch has started, now release the second finger
2041 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2042 kTouchId1
, tes
.Now());
2043 DispatchEventUsingWindowDispatcher(&release
);
2044 EXPECT_TRUE(delegate
->pinch_end());
2046 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId2
, delegate
.get());
2047 EXPECT_TRUE(delegate
->scroll_update());
2051 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2052 kTouchId1
, tes
.Now());
2053 DispatchEventUsingWindowDispatcher(&press3
);
2054 // Now the touch points are close. So we will go into two finger tap.
2055 // Move the touch-point enough to break two-finger-tap and enter pinch.
2056 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(101, 50),
2057 kTouchId1
, tes
.Now());
2058 DispatchEventUsingWindowDispatcher(&move2
);
2059 EXPECT_TRUE(delegate
->pinch_begin());
2061 tes
.SendScrollEvent(event_processor(), 350, 350, kTouchId1
, delegate
.get());
2062 EXPECT_TRUE(delegate
->pinch_update());
2065 TEST_F(GestureRecognizerTest
, GestureEventPinchFromTap
) {
2066 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2067 new GestureEventConsumeDelegate());
2069 const int kWindowWidth
= 300;
2070 const int kWindowHeight
= 400;
2071 const int kTouchId1
= 3;
2072 const int kTouchId2
= 5;
2073 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
2074 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2075 delegate
.get(), -1234, bounds
, root_window()));
2078 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
2079 kTouchId1
, tes
.Now());
2080 DispatchEventUsingWindowDispatcher(&press
);
2081 EXPECT_2_EVENTS(delegate
->events(),
2082 ui::ET_GESTURE_BEGIN
,
2083 ui::ET_GESTURE_TAP_DOWN
);
2084 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2086 // Press the second finger far enough to break two finger tap.
2088 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2089 kTouchId2
, tes
.Now());
2090 DispatchEventUsingWindowDispatcher(&press2
);
2091 EXPECT_2_EVENTS(delegate
->events(),
2092 ui::ET_GESTURE_TAP_CANCEL
,
2093 ui::ET_GESTURE_BEGIN
);
2094 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(),
2095 delegate
->bounding_box().ToString());
2097 // Move the first finger.
2099 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
2100 kTouchId1
, tes
.Now());
2101 DispatchEventUsingWindowDispatcher(&move3
);
2102 EXPECT_3_EVENTS(delegate
->events(),
2103 ui::ET_GESTURE_SCROLL_BEGIN
,
2104 ui::ET_GESTURE_SCROLL_UPDATE
,
2105 ui::ET_GESTURE_PINCH_BEGIN
);
2106 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(),
2107 delegate
->bounding_box().ToString());
2109 // Now move the second finger.
2111 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(55, 15),
2112 kTouchId2
, tes
.Now());
2113 DispatchEventUsingWindowDispatcher(&move4
);
2114 EXPECT_2_EVENTS(delegate
->events(),
2115 ui::ET_GESTURE_SCROLL_UPDATE
,
2116 ui::ET_GESTURE_PINCH_UPDATE
);
2117 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(),
2118 delegate
->bounding_box().ToString());
2120 // Release the first finger. This should end pinch.
2122 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2123 kTouchId1
, tes
.LeapForward(10));
2124 DispatchEventUsingWindowDispatcher(&release
);
2125 EXPECT_2_EVENTS(delegate
->events(),
2126 ui::ET_GESTURE_PINCH_END
,
2127 ui::ET_GESTURE_END
);
2128 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
2129 delegate
->bounding_box().ToString());
2131 // Move the second finger. This should still generate a scroll.
2133 ui::TouchEvent
move5(ui::ET_TOUCH_MOVED
, gfx::Point(25, 10),
2134 kTouchId2
, tes
.Now());
2135 DispatchEventUsingWindowDispatcher(&move5
);
2136 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
2137 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2140 TEST_F(GestureRecognizerTest
, GestureEventIgnoresDisconnectedEvents
) {
2141 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2142 new GestureEventConsumeDelegate());
2145 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2147 DispatchEventUsingWindowDispatcher(&release1
);
2148 EXPECT_FALSE(delegate
->tap());
2149 EXPECT_FALSE(delegate
->tap_down());
2152 // Check that a touch is locked to the window of the closest current touch
2153 // within max_separation_for_gesture_touches_in_pixels
2154 TEST_F(GestureRecognizerTest
, GestureEventTouchLockSelectsCorrectWindow
) {
2155 ui::GestureRecognizer
* gesture_recognizer
= new ui::GestureRecognizerImpl();
2157 ScopedGestureRecognizerSetter
gr_setter(gesture_recognizer
);
2159 ui::GestureConsumer
* target
;
2160 const int kNumWindows
= 4;
2162 scoped_ptr
<GestureEventConsumeDelegate
*[]> delegates(
2163 new GestureEventConsumeDelegate
*[kNumWindows
]);
2165 ui::GestureConfiguration::GetInstance()
2166 ->set_max_separation_for_gesture_touches_in_pixels(499);
2168 scoped_ptr
<gfx::Rect
[]> window_bounds(new gfx::Rect
[kNumWindows
]);
2169 window_bounds
[0] = gfx::Rect(0, 0, 1, 1);
2170 window_bounds
[1] = gfx::Rect(500, 0, 1, 1);
2171 window_bounds
[2] = gfx::Rect(0, 500, 1, 1);
2172 window_bounds
[3] = gfx::Rect(500, 500, 1, 1);
2174 scoped_ptr
<aura::Window
*[]> windows(new aura::Window
*[kNumWindows
]);
2176 // Instantiate windows with |window_bounds| and touch each window at
2178 for (int i
= 0; i
< kNumWindows
; ++i
) {
2179 delegates
[i
] = new GestureEventConsumeDelegate();
2180 windows
[i
] = CreateTestWindowWithDelegate(
2181 delegates
[i
], i
, window_bounds
[i
], root_window());
2182 windows
[i
]->set_id(i
);
2183 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, window_bounds
[i
].origin(),
2185 DispatchEventUsingWindowDispatcher(&press
);
2188 // Touches should now be associated with the closest touch within
2189 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels
2190 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(11, 11), -1);
2191 EXPECT_EQ("0", WindowIDAsString(target
));
2192 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(511, 11), -1);
2193 EXPECT_EQ("1", WindowIDAsString(target
));
2194 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(11, 511), -1);
2195 EXPECT_EQ("2", WindowIDAsString(target
));
2196 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(511, 511), -1);
2197 EXPECT_EQ("3", WindowIDAsString(target
));
2199 // Add a touch in the middle associated with windows[2]
2200 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 500),
2201 kNumWindows
, tes
.Now());
2202 DispatchEventUsingWindowDispatcher(&press
);
2203 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(250, 250),
2204 kNumWindows
, tes
.Now());
2205 DispatchEventUsingWindowDispatcher(&move
);
2207 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(250, 250), -1);
2208 EXPECT_EQ("2", WindowIDAsString(target
));
2210 // Make sure that ties are broken by distance to a current touch
2211 // Closer to the point in the bottom right.
2212 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(380, 380), -1);
2213 EXPECT_EQ("3", WindowIDAsString(target
));
2215 // This touch is closer to the point in the middle
2216 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(300, 300), -1);
2217 EXPECT_EQ("2", WindowIDAsString(target
));
2219 // A touch too far from other touches won't be locked to anything
2220 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2221 EXPECT_TRUE(target
== NULL
);
2223 // Move a touch associated with windows[2] to 1000, 1000
2224 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(1000, 1000),
2225 kNumWindows
, tes
.Now());
2226 DispatchEventUsingWindowDispatcher(&move2
);
2228 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2229 EXPECT_EQ("2", WindowIDAsString(target
));
2231 for (int i
= 0; i
< kNumWindows
; ++i
) {
2232 // Delete windows before deleting delegates.
2234 delete delegates
[i
];
2238 // Check that a touch's target will not be effected by a touch on a different
2240 TEST_F(GestureRecognizerTest
, GestureEventTouchLockIgnoresOtherScreens
) {
2241 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2242 new GestureEventConsumeDelegate());
2243 gfx::Rect
bounds(0, 0, 10, 10);
2244 scoped_ptr
<aura::Window
> window(
2245 CreateTestWindowWithDelegate(delegate
.get(), 0, bounds
, root_window()));
2247 const int kTouchId1
= 8;
2248 const int kTouchId2
= 2;
2251 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(5, 5),
2252 kTouchId1
, tes
.Now());
2253 ui::EventTestApi
test_press1(&press1
);
2254 test_press1
.set_source_device_id(1);
2255 DispatchEventUsingWindowDispatcher(&press1
);
2257 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20),
2258 kTouchId2
, tes
.Now());
2259 ui::EventTestApi
test_press2(&press2
);
2260 test_press2
.set_source_device_id(2);
2261 DispatchEventUsingWindowDispatcher(&press2
);
2263 // The second press should not have been locked to the same target as the
2264 // first, as they occured on different displays.
2266 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
),
2267 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
));
2270 // Check that touch events outside the root window are still handled
2271 // by the root window's gesture sequence.
2272 TEST_F(GestureRecognizerTest
, GestureEventOutsideRootWindowTap
) {
2274 scoped_ptr
<aura::Window
> window(CreateTestWindowWithBounds(
2275 gfx::Rect(-100, -100, 2000, 2000), root_window()));
2277 gfx::Point
pos1(-10, -10);
2278 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, pos1
, 0, tes
.Now());
2279 DispatchEventUsingWindowDispatcher(&press1
);
2281 gfx::Point
pos2(1000, 1000);
2282 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, pos2
, 1, tes
.Now());
2283 DispatchEventUsingWindowDispatcher(&press2
);
2285 // As these presses were outside the root window, they should be
2286 // associated with the root window.
2287 EXPECT_EQ(root_window(),
2288 static_cast<aura::Window
*>(
2289 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
)));
2290 EXPECT_EQ(root_window(),
2291 static_cast<aura::Window
*>(
2292 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
)));
2295 TEST_F(GestureRecognizerTest
, NoTapWithPreventDefaultedRelease
) {
2296 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2297 new QueueTouchEventDelegate(host()->dispatcher()));
2299 const int kTouchId
= 2;
2300 gfx::Rect
bounds(100, 200, 100, 100);
2301 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2302 delegate
.get(), -1234, bounds
, root_window()));
2303 delegate
->set_window(window
.get());
2306 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2307 kTouchId
, tes
.Now());
2308 DispatchEventUsingWindowDispatcher(&press
);
2309 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2310 kTouchId
, tes
.LeapForward(50));
2311 DispatchEventUsingWindowDispatcher(&release
);
2314 delegate
->ReceivedAck();
2315 EXPECT_TRUE(delegate
->tap_down());
2317 delegate
->ReceivedAckPreventDefaulted();
2318 EXPECT_FALSE(delegate
->tap());
2319 EXPECT_TRUE(delegate
->tap_cancel());
2322 TEST_F(GestureRecognizerTest
, PinchScrollWithPreventDefaultedRelease
) {
2323 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2324 new QueueTouchEventDelegate(host()->dispatcher()));
2326 const int kTouchId1
= 7;
2327 const int kTouchId2
= 5;
2328 gfx::Rect
bounds(10, 20, 100, 100);
2329 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2330 delegate
.get(), -1234, bounds
, root_window()));
2331 delegate
->set_window(window
.get());
2335 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(15, 25), kTouchId1
,
2337 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(20, 95), kTouchId1
,
2338 tes
.LeapForward(200));
2339 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(15, 25), kTouchId1
,
2340 tes
.LeapForward(50));
2341 DispatchEventUsingWindowDispatcher(&press
);
2342 DispatchEventUsingWindowDispatcher(&move
);
2343 DispatchEventUsingWindowDispatcher(&release
);
2346 // Ack the press event.
2347 delegate
->ReceivedAck();
2349 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2352 // Ack the move event.
2353 delegate
->ReceivedAck();
2354 EXPECT_3_EVENTS(delegate
->events(),
2355 ui::ET_GESTURE_TAP_CANCEL
,
2356 ui::ET_GESTURE_SCROLL_BEGIN
,
2357 ui::ET_GESTURE_SCROLL_UPDATE
);
2360 // Ack the release event. Although the release event has been processed, it
2361 // should still generate a scroll-end event.
2362 delegate
->ReceivedAckPreventDefaulted();
2364 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2367 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(15, 25), kTouchId1
,
2369 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(20, 95), kTouchId1
,
2370 tes
.LeapForward(200));
2371 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(15, 25), kTouchId1
,
2372 tes
.LeapForward(50));
2373 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(55, 25), kTouchId2
,
2375 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(145, 85), kTouchId2
,
2376 tes
.LeapForward(1000));
2377 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(145, 85), kTouchId2
,
2378 tes
.LeapForward(14));
2381 DispatchEventUsingWindowDispatcher(&press
);
2382 DispatchEventUsingWindowDispatcher(&move
);
2383 DispatchEventUsingWindowDispatcher(&press2
);
2384 DispatchEventUsingWindowDispatcher(&move2
);
2385 DispatchEventUsingWindowDispatcher(&release
);
2386 DispatchEventUsingWindowDispatcher(&release2
);
2388 // Ack the press and move events.
2390 delegate
->ReceivedAck();
2392 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2395 delegate
->ReceivedAck();
2396 EXPECT_3_EVENTS(delegate
->events(),
2397 ui::ET_GESTURE_TAP_CANCEL
,
2398 ui::ET_GESTURE_SCROLL_BEGIN
,
2399 ui::ET_GESTURE_SCROLL_UPDATE
);
2402 delegate
->ReceivedAck();
2403 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_BEGIN
);
2406 delegate
->ReceivedAck();
2407 EXPECT_2_EVENTS(delegate
->events(),
2408 ui::ET_GESTURE_SCROLL_UPDATE
,
2409 ui::ET_GESTURE_PINCH_BEGIN
);
2411 // Ack the first release. Although the release is processed, it should still
2412 // generate a pinch-end event.
2414 delegate
->ReceivedAckPreventDefaulted();
2416 delegate
->events(), ui::ET_GESTURE_PINCH_END
, ui::ET_GESTURE_END
);
2419 delegate
->ReceivedAckPreventDefaulted();
2421 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2424 TEST_F(GestureRecognizerTest
, GestureEndLocation
) {
2425 GestureEventConsumeDelegate delegate
;
2426 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2427 &delegate
, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2428 ui::test::EventGenerator
generator(root_window(), window
.get());
2429 const gfx::Point
begin(20, 20);
2430 const gfx::Point
end(150, 150);
2431 const gfx::Vector2d window_offset
=
2432 window
->bounds().origin().OffsetFromOrigin();
2433 generator
.GestureScrollSequence(begin
, end
,
2434 base::TimeDelta::FromMilliseconds(20),
2436 EXPECT_EQ((begin
- window_offset
).ToString(),
2437 delegate
.scroll_begin_position().ToString());
2438 EXPECT_EQ((end
- window_offset
).ToString(),
2439 delegate
.gesture_end_location().ToString());
2442 TEST_F(GestureRecognizerTest
, CaptureSendsGestureEnd
) {
2443 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2444 new GestureEventConsumeDelegate());
2445 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2446 delegate
.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2447 ui::test::EventGenerator
generator(root_window());
2449 generator
.MoveMouseRelativeTo(window
.get(), gfx::Point(10, 10));
2450 generator
.PressTouch();
2451 RunAllPendingInMessageLoop();
2453 EXPECT_TRUE(delegate
->tap_down());
2455 scoped_ptr
<aura::Window
> capture(CreateTestWindowWithBounds(
2456 gfx::Rect(10, 10, 200, 200), root_window()));
2457 capture
->SetCapture();
2458 RunAllPendingInMessageLoop();
2460 EXPECT_TRUE(delegate
->end());
2461 EXPECT_TRUE(delegate
->tap_cancel());
2464 // Check that previous touch actions that are completely finished (either
2465 // released or cancelled), do not receive extra synthetic cancels upon change of
2467 TEST_F(GestureRecognizerTest
, CaptureDoesNotCancelFinishedTouches
) {
2468 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2469 new GestureEventConsumeDelegate());
2470 scoped_ptr
<TestEventHandler
> handler(new TestEventHandler
);
2471 root_window()->AddPreTargetHandler(handler
.get());
2473 // Create a window and set it as the capture window.
2474 scoped_ptr
<aura::Window
> window1(CreateTestWindowWithDelegate(delegate
.get(),
2475 -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2476 window1
->SetCapture();
2478 ui::test::EventGenerator
generator(root_window());
2481 // Generate two touch-press events on the window.
2482 scoped_ptr
<ui::TouchEvent
> touch0(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
2483 gfx::Point(20, 20), 0,
2485 scoped_ptr
<ui::TouchEvent
> touch1(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
2486 gfx::Point(30, 30), 1,
2488 generator
.Dispatch(touch0
.get());
2489 generator
.Dispatch(touch1
.get());
2490 RunAllPendingInMessageLoop();
2491 EXPECT_EQ(2, handler
->touch_pressed_count());
2494 tes
.LeapForward(1000);
2496 // End the two touches, one by a touch-release and one by a touch-cancel; to
2497 // cover both cases.
2498 touch0
.reset(new ui::TouchEvent(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
2500 touch1
.reset(new ui::TouchEvent(ui::ET_TOUCH_CANCELLED
, gfx::Point(30, 30), 1,
2502 generator
.Dispatch(touch0
.get());
2503 generator
.Dispatch(touch1
.get());
2504 RunAllPendingInMessageLoop();
2505 EXPECT_EQ(1, handler
->touch_released_count());
2506 EXPECT_EQ(1, handler
->touch_cancelled_count());
2508 // Create a new window and set it as the new capture window.
2509 scoped_ptr
<aura::Window
> window2(CreateTestWindowWithBounds(
2510 gfx::Rect(100, 100, 300, 300), root_window()));
2511 window2
->SetCapture();
2512 RunAllPendingInMessageLoop();
2513 // Check that setting capture does not generate any synthetic touch-cancels
2514 // for the two previously finished touch actions.
2515 EXPECT_EQ(1, handler
->touch_cancelled_count());
2517 root_window()->RemovePreTargetHandler(handler
.get());
2520 // Tests that a press with the same touch id as an existing touch is ignored.
2521 TEST_F(GestureRecognizerTest
, PressDoesNotCrash
) {
2522 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2523 new GestureEventConsumeDelegate());
2526 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2527 delegate
.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2529 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(45, 45), 7, tes
.Now());
2530 press
.set_radius_x(40);
2531 DispatchEventUsingWindowDispatcher(&press
);
2532 EXPECT_TRUE(delegate
->tap_down());
2533 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(),
2534 delegate
->bounding_box().ToString());
2537 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(55, 45), 7, tes
.Now());
2538 DispatchEventUsingWindowDispatcher(&press2
);
2540 // FIXME(tdresser): this should not generate a tap down; however,
2541 // there is at least one case where we need to allow a touch press
2542 // from a currently used touch id. See crbug.com/373125 for details.
2543 EXPECT_TRUE(delegate
->begin());
2544 EXPECT_TRUE(delegate
->tap_down());
2545 EXPECT_TRUE(delegate
->tap_cancel());
2546 EXPECT_FALSE(delegate
->scroll_begin());
2549 TEST_F(GestureRecognizerTest
, TwoFingerTap
) {
2550 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2551 new GestureEventConsumeDelegate());
2552 const int kWindowWidth
= 123;
2553 const int kWindowHeight
= 45;
2554 const int kTouchId1
= 2;
2555 const int kTouchId2
= 3;
2556 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2557 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2558 delegate
.get(), -1234, bounds
, root_window()));
2562 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2563 kTouchId1
, tes
.Now());
2564 DispatchEventUsingWindowDispatcher(&press1
);
2566 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2569 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2570 kTouchId2
, tes
.Now());
2571 DispatchEventUsingWindowDispatcher(&press2
);
2573 delegate
->events(), ui::ET_GESTURE_TAP_CANCEL
, ui::ET_GESTURE_BEGIN
);
2575 // Little bit of touch move should not affect our state.
2577 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(102, 202),
2578 kTouchId1
, tes
.Now());
2579 DispatchEventUsingWindowDispatcher(&move1
);
2580 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(131, 202),
2581 kTouchId2
, tes
.Now());
2582 DispatchEventUsingWindowDispatcher(&move2
);
2583 EXPECT_2_EVENTS(delegate
->events(),
2584 ui::ET_GESTURE_SCROLL_BEGIN
,
2585 ui::ET_GESTURE_SCROLL_UPDATE
);
2587 // Make sure there is enough delay before the touch is released so that it is
2588 // recognized as a tap.
2590 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2591 kTouchId1
, tes
.LeapForward(50));
2593 DispatchEventUsingWindowDispatcher(&release1
);
2595 delegate
->events(), ui::ET_GESTURE_TWO_FINGER_TAP
, ui::ET_GESTURE_END
);
2597 // Lift second finger.
2598 // Make sure there is enough delay before the touch is released so that it is
2599 // recognized as a tap.
2601 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
2602 kTouchId2
, tes
.LeapForward(50));
2604 DispatchEventUsingWindowDispatcher(&release2
);
2606 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2609 TEST_F(GestureRecognizerTest
, TwoFingerTapExpired
) {
2610 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2611 new GestureEventConsumeDelegate());
2612 const int kWindowWidth
= 123;
2613 const int kWindowHeight
= 45;
2614 const int kTouchId1
= 2;
2615 const int kTouchId2
= 3;
2616 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2617 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2618 delegate
.get(), -1234, bounds
, root_window()));
2622 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2623 kTouchId1
, tes
.Now());
2624 DispatchEventUsingWindowDispatcher(&press1
);
2627 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2628 kTouchId2
, tes
.Now());
2629 DispatchEventUsingWindowDispatcher(&press2
);
2631 // Send release event after sufficient delay so that two finger time expires.
2633 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2634 kTouchId1
, tes
.LeapForward(1000));
2636 DispatchEventUsingWindowDispatcher(&release1
);
2637 EXPECT_FALSE(delegate
->two_finger_tap());
2639 // Lift second finger.
2640 // Make sure there is enough delay before the touch is released so that it is
2641 // recognized as a tap.
2643 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
2644 kTouchId2
, tes
.LeapForward(50));
2646 DispatchEventUsingWindowDispatcher(&release2
);
2647 EXPECT_FALSE(delegate
->two_finger_tap());
2650 TEST_F(GestureRecognizerTest
, TwoFingerTapChangesToPinch
) {
2651 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2652 new GestureEventConsumeDelegate());
2653 const int kWindowWidth
= 123;
2654 const int kWindowHeight
= 45;
2655 const int kTouchId1
= 2;
2656 const int kTouchId2
= 3;
2659 // Test moving first finger
2661 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2662 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2663 delegate
.get(), -1234, bounds
, root_window()));
2666 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2667 kTouchId1
, tes
.Now());
2668 DispatchEventUsingWindowDispatcher(&press1
);
2671 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2672 kTouchId2
, tes
.Now());
2673 DispatchEventUsingWindowDispatcher(&press2
);
2675 tes
.SendScrollEvent(event_processor(), 230, 330, kTouchId1
, delegate
.get());
2676 EXPECT_FALSE(delegate
->two_finger_tap());
2677 EXPECT_TRUE(delegate
->pinch_begin());
2679 // Make sure there is enough delay before the touch is released so that it
2680 // is recognized as a tap.
2682 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2683 kTouchId2
, tes
.LeapForward(50));
2685 DispatchEventUsingWindowDispatcher(&release
);
2686 EXPECT_FALSE(delegate
->two_finger_tap());
2687 EXPECT_TRUE(delegate
->pinch_end());
2690 // Test moving second finger
2692 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2693 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2694 delegate
.get(), -1234, bounds
, root_window()));
2697 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2698 kTouchId1
, tes
.Now());
2699 DispatchEventUsingWindowDispatcher(&press1
);
2702 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2703 kTouchId2
, tes
.Now());
2704 DispatchEventUsingWindowDispatcher(&press2
);
2706 tes
.SendScrollEvent(event_processor(), 301, 230, kTouchId2
, delegate
.get());
2707 EXPECT_FALSE(delegate
->two_finger_tap());
2708 EXPECT_TRUE(delegate
->pinch_begin());
2710 // Make sure there is enough delay before the touch is released so that it
2711 // is recognized as a tap.
2713 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2714 kTouchId1
, tes
.LeapForward(50));
2716 DispatchEventUsingWindowDispatcher(&release
);
2717 EXPECT_FALSE(delegate
->two_finger_tap());
2718 EXPECT_TRUE(delegate
->pinch_end());
2722 TEST_F(GestureRecognizerTest
, NoTwoFingerTapWhenFirstFingerHasScrolled
) {
2723 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2724 new GestureEventConsumeDelegate());
2725 const int kWindowWidth
= 123;
2726 const int kWindowHeight
= 45;
2727 const int kTouchId1
= 2;
2728 const int kTouchId2
= 3;
2731 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2732 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2733 delegate
.get(), -1234, bounds
, root_window()));
2736 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2737 kTouchId1
, tes
.Now());
2738 DispatchEventUsingWindowDispatcher(&press1
);
2739 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId1
, delegate
.get());
2742 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2743 kTouchId2
, tes
.Now());
2744 DispatchEventUsingWindowDispatcher(&press2
);
2746 EXPECT_FALSE(delegate
->pinch_begin());
2748 // Make sure there is enough delay before the touch is released so that it
2749 // is recognized as a tap.
2751 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2752 kTouchId2
, tes
.LeapForward(50));
2754 DispatchEventUsingWindowDispatcher(&release
);
2755 EXPECT_FALSE(delegate
->two_finger_tap());
2756 EXPECT_FALSE(delegate
->pinch_end());
2759 TEST_F(GestureRecognizerTest
, MultiFingerSwipe
) {
2760 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2761 new GestureEventConsumeDelegate());
2762 const int kWindowWidth
= 123;
2763 const int kWindowHeight
= 45;
2765 gfx::Rect
bounds(5, 10, kWindowWidth
, kWindowHeight
);
2766 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2767 delegate
.get(), -1234, bounds
, root_window()));
2769 const int kSteps
= 15;
2770 const int kTouchPoints
= 4;
2771 gfx::Point points
[kTouchPoints
] = {
2778 ui::test::EventGenerator
generator(root_window(), window
.get());
2780 // The unified gesture recognizer assumes a finger has stopped if it hasn't
2781 // moved for too long. See ui/events/gesture_detection/velocity_tracker.cc's
2782 // kAssumePointerStoppedTimeMs.
2783 for (int count
= 2; count
<= kTouchPoints
; ++count
) {
2784 generator
.GestureMultiFingerScroll(
2785 count
, points
, 10, kSteps
, 0, -11 * kSteps
);
2786 EXPECT_TRUE(delegate
->swipe_up());
2789 generator
.GestureMultiFingerScroll(
2790 count
, points
, 10, kSteps
, 0, 11 * kSteps
);
2791 EXPECT_TRUE(delegate
->swipe_down());
2794 generator
.GestureMultiFingerScroll(
2795 count
, points
, 10, kSteps
, -11 * kSteps
, 0);
2796 EXPECT_TRUE(delegate
->swipe_left());
2799 generator
.GestureMultiFingerScroll(
2800 count
, points
, 10, kSteps
, 11 * kSteps
, 0);
2801 EXPECT_TRUE(delegate
->swipe_right());
2804 generator
.GestureMultiFingerScroll(
2805 count
, points
, 10, kSteps
, 5 * kSteps
, 12 * kSteps
);
2806 EXPECT_FALSE(delegate
->swipe_down());
2809 generator
.GestureMultiFingerScroll(
2810 count
, points
, 10, kSteps
, 4 * kSteps
, 12 * kSteps
);
2811 EXPECT_TRUE(delegate
->swipe_down());
2814 generator
.GestureMultiFingerScroll(
2815 count
, points
, 10, kSteps
, 3 * kSteps
, 12 * kSteps
);
2816 EXPECT_TRUE(delegate
->swipe_down());
2821 TEST_F(GestureRecognizerTest
, TwoFingerTapCancelled
) {
2822 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2823 new GestureEventConsumeDelegate());
2824 const int kWindowWidth
= 123;
2825 const int kWindowHeight
= 45;
2826 const int kTouchId1
= 2;
2827 const int kTouchId2
= 3;
2830 // Test canceling first finger.
2832 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2833 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2834 delegate
.get(), -1234, bounds
, root_window()));
2837 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2838 kTouchId1
, tes
.Now());
2839 DispatchEventUsingWindowDispatcher(&press1
);
2842 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2843 kTouchId2
, tes
.Now());
2844 DispatchEventUsingWindowDispatcher(&press2
);
2847 ui::TouchEvent
cancel(ui::ET_TOUCH_CANCELLED
, gfx::Point(130, 201),
2848 kTouchId1
, tes
.Now());
2849 DispatchEventUsingWindowDispatcher(&cancel
);
2850 EXPECT_FALSE(delegate
->two_finger_tap());
2852 // Make sure there is enough delay before the touch is released so that it
2853 // is recognized as a tap.
2855 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2856 kTouchId2
, tes
.LeapForward(50));
2858 DispatchEventUsingWindowDispatcher(&release
);
2859 EXPECT_FALSE(delegate
->two_finger_tap());
2862 // Test canceling second finger
2864 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2865 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2866 delegate
.get(), -1234, bounds
, root_window()));
2869 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2870 kTouchId1
, tes
.Now());
2871 DispatchEventUsingWindowDispatcher(&press1
);
2874 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2875 kTouchId2
, tes
.Now());
2876 DispatchEventUsingWindowDispatcher(&press2
);
2879 ui::TouchEvent
cancel(ui::ET_TOUCH_CANCELLED
, gfx::Point(130, 201),
2880 kTouchId2
, tes
.Now());
2881 DispatchEventUsingWindowDispatcher(&cancel
);
2882 EXPECT_FALSE(delegate
->two_finger_tap());
2884 // Make sure there is enough delay before the touch is released so that it
2885 // is recognized as a tap.
2887 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2888 kTouchId1
, tes
.LeapForward(50));
2890 DispatchEventUsingWindowDispatcher(&release
);
2891 EXPECT_FALSE(delegate
->two_finger_tap());
2895 TEST_F(GestureRecognizerTest
, VeryWideTwoFingerTouchDownShouldBeAPinch
) {
2896 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2897 new GestureEventConsumeDelegate());
2898 const int kWindowWidth
= 523;
2899 const int kWindowHeight
= 45;
2900 const int kTouchId1
= 2;
2901 const int kTouchId2
= 3;
2902 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2903 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2904 delegate
.get(), -1234, bounds
, root_window()));
2908 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2909 kTouchId1
, tes
.Now());
2910 DispatchEventUsingWindowDispatcher(&press1
);
2911 EXPECT_FALSE(delegate
->tap());
2912 EXPECT_TRUE(delegate
->tap_down());
2913 EXPECT_FALSE(delegate
->tap_cancel());
2914 EXPECT_FALSE(delegate
->scroll_begin());
2915 EXPECT_FALSE(delegate
->scroll_update());
2916 EXPECT_FALSE(delegate
->scroll_end());
2917 EXPECT_FALSE(delegate
->long_press());
2918 EXPECT_FALSE(delegate
->two_finger_tap());
2921 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(430, 201),
2922 kTouchId2
, tes
.Now());
2923 DispatchEventUsingWindowDispatcher(&press2
);
2924 EXPECT_FALSE(delegate
->tap());
2925 EXPECT_FALSE(delegate
->tap_down()); // no touch down for second tap.
2926 EXPECT_TRUE(delegate
->tap_cancel());
2927 EXPECT_FALSE(delegate
->scroll_begin());
2928 EXPECT_FALSE(delegate
->scroll_update());
2929 EXPECT_FALSE(delegate
->scroll_end());
2930 EXPECT_FALSE(delegate
->long_press());
2931 EXPECT_FALSE(delegate
->two_finger_tap());
2932 EXPECT_FALSE(delegate
->pinch_begin());
2935 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(530, 301),
2936 kTouchId2
, tes
.Now());
2937 DispatchEventUsingWindowDispatcher(&move2
);
2938 EXPECT_FALSE(delegate
->tap());
2939 EXPECT_FALSE(delegate
->tap_down());
2940 EXPECT_FALSE(delegate
->tap_cancel());
2941 // Pinch & Scroll only when there is enough movement.
2942 EXPECT_TRUE(delegate
->scroll_begin());
2943 EXPECT_TRUE(delegate
->scroll_update());
2944 EXPECT_FALSE(delegate
->scroll_end());
2945 EXPECT_FALSE(delegate
->long_press());
2946 EXPECT_FALSE(delegate
->two_finger_tap());
2947 EXPECT_TRUE(delegate
->pinch_begin());
2950 // Verifies if a window is the target of multiple touch-ids and we hide the
2951 // window everything is cleaned up correctly.
2952 TEST_F(GestureRecognizerTest
, FlushAllOnHide
) {
2953 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2954 new GestureEventConsumeDelegate());
2955 gfx::Rect
bounds(0, 0, 200, 200);
2956 scoped_ptr
<aura::Window
> window(
2957 CreateTestWindowWithDelegate(delegate
.get(), 0, bounds
, root_window()));
2958 const int kTouchId1
= 8;
2959 const int kTouchId2
= 2;
2962 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2963 kTouchId1
, tes
.Now());
2964 DispatchEventUsingWindowDispatcher(&press1
);
2965 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20),
2966 kTouchId2
, tes
.Now());
2967 DispatchEventUsingWindowDispatcher(&press2
);
2970 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
));
2972 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
));
2975 TEST_F(GestureRecognizerTest
, LongPressTimerStopsOnPreventDefaultedTouchMoves
) {
2976 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2977 new QueueTouchEventDelegate(host()->dispatcher()));
2978 const int kTouchId
= 2;
2979 gfx::Rect
bounds(100, 200, 100, 100);
2980 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2981 delegate
.get(), -1234, bounds
, root_window()));
2982 delegate
->set_window(window
.get());
2986 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2987 kTouchId
, tes
.Now());
2988 DispatchEventUsingWindowDispatcher(&press
);
2989 // Scroll around, to cancel the long press
2990 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
2993 delegate
->ReceivedAck();
2994 EXPECT_TRUE(delegate
->tap_down());
2996 // Wait long enough that long press would have fired if the touchmove hadn't
2998 DelayByLongPressTimeout();
3001 delegate
->ReceivedAckPreventDefaulted();
3002 EXPECT_FALSE(delegate
->long_press());
3005 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events.
3006 class ConsumesTouchMovesDelegate
: public GestureEventConsumeDelegate
{
3008 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {}
3009 ~ConsumesTouchMovesDelegate() override
{}
3011 void set_consume_touch_move(bool consume
) { consume_touch_move_
= consume
; }
3014 void OnTouchEvent(ui::TouchEvent
* touch
) override
{
3015 if (consume_touch_move_
&& touch
->type() == ui::ET_TOUCH_MOVED
)
3016 touch
->SetHandled();
3018 GestureEventConsumeDelegate::OnTouchEvent(touch
);
3021 bool consume_touch_move_
;
3023 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate
);
3026 // Same as GestureEventScroll, but tests that the behavior is the same
3027 // even if all the touch-move events are consumed.
3028 TEST_F(GestureRecognizerTest
, GestureEventScrollTouchMoveConsumed
) {
3029 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3030 new ConsumesTouchMovesDelegate());
3031 const int kWindowWidth
= 123;
3032 const int kWindowHeight
= 45;
3033 const int kTouchId
= 5;
3034 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3035 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3036 delegate
.get(), -1234, bounds
, root_window()));
3040 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3041 kTouchId
, tes
.Now());
3042 DispatchEventUsingWindowDispatcher(&press
);
3043 EXPECT_FALSE(delegate
->tap());
3044 EXPECT_TRUE(delegate
->tap_down());
3045 EXPECT_FALSE(delegate
->tap_cancel());
3046 EXPECT_TRUE(delegate
->begin());
3047 EXPECT_FALSE(delegate
->scroll_begin());
3048 EXPECT_FALSE(delegate
->scroll_update());
3049 EXPECT_FALSE(delegate
->scroll_end());
3051 // Move the touch-point enough so that it would normally be considered a
3052 // scroll. But since the touch-moves will be consumed, the scroll should not
3054 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3055 EXPECT_FALSE(delegate
->tap());
3056 EXPECT_FALSE(delegate
->tap_down());
3057 EXPECT_TRUE(delegate
->tap_cancel());
3058 EXPECT_FALSE(delegate
->begin());
3059 EXPECT_FALSE(delegate
->scroll_update());
3060 EXPECT_FALSE(delegate
->scroll_end());
3062 EXPECT_TRUE(delegate
->scroll_begin());
3064 // Release the touch back at the start point. This should end without causing
3067 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 230),
3068 kTouchId
, tes
.LeapForward(50));
3069 DispatchEventUsingWindowDispatcher(&release
);
3070 EXPECT_FALSE(delegate
->tap());
3071 EXPECT_FALSE(delegate
->tap_down());
3072 EXPECT_FALSE(delegate
->tap_cancel());
3073 EXPECT_FALSE(delegate
->begin());
3074 EXPECT_TRUE(delegate
->end());
3075 EXPECT_FALSE(delegate
->scroll_begin());
3076 EXPECT_FALSE(delegate
->scroll_update());
3078 EXPECT_TRUE(delegate
->scroll_end());
3081 // Tests the behavior of 2F scroll when some of the touch-move events are
3083 TEST_F(GestureRecognizerTest
, GestureEventScrollTwoFingerTouchMoveConsumed
) {
3084 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3085 new ConsumesTouchMovesDelegate());
3086 const int kWindowWidth
= 123;
3087 const int kWindowHeight
= 100;
3088 const int kTouchId1
= 2;
3089 const int kTouchId2
= 3;
3092 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3093 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3094 delegate
.get(), -1234, bounds
, root_window()));
3097 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3098 kTouchId1
, tes
.Now());
3099 DispatchEventUsingWindowDispatcher(&press1
);
3100 tes
.SendScrollEvent(event_processor(), 131, 231, kTouchId1
, delegate
.get());
3102 EXPECT_2_EVENTS(delegate
->events(),
3103 ui::ET_GESTURE_TAP_CANCEL
,
3104 ui::ET_GESTURE_SCROLL_BEGIN
);
3107 // Second finger touches down and moves.
3108 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
3109 kTouchId2
, tes
.LeapForward(50));
3110 DispatchEventUsingWindowDispatcher(&press2
);
3111 tes
.SendScrollEvent(event_processor(), 161, 231, kTouchId2
, delegate
.get());
3112 EXPECT_0_EVENTS(delegate
->events());
3115 // Move first finger again, no PinchUpdate & ScrollUpdate.
3116 tes
.SendScrollEvent(event_processor(), 161, 261, kTouchId1
, delegate
.get());
3117 EXPECT_0_EVENTS(delegate
->events());
3119 // Stops consuming touch-move.
3120 delegate
->set_consume_touch_move(false);
3123 // Making a pinch gesture.
3124 tes
.SendScrollEvent(event_processor(), 161, 260, kTouchId1
, delegate
.get());
3125 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
3128 tes
.SendScrollEvent(event_processor(), 161, 261, kTouchId2
, delegate
.get());
3129 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
3132 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3133 kTouchId1
, tes
.Now());
3134 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
3135 kTouchId2
, tes
.Now());
3136 DispatchEventUsingWindowDispatcher(&release1
);
3137 DispatchEventUsingWindowDispatcher(&release2
);
3139 EXPECT_3_EVENTS(delegate
->events(),
3141 ui::ET_SCROLL_FLING_START
,
3142 ui::ET_GESTURE_END
);
3145 // Like as GestureEventTouchMoveConsumed but tests the different behavior
3146 // depending on whether the events were consumed before or after the scroll
3148 TEST_F(GestureRecognizerTest
, GestureEventScrollTouchMovePartialConsumed
) {
3149 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3150 new ConsumesTouchMovesDelegate());
3151 const int kWindowWidth
= 123;
3152 const int kWindowHeight
= 45;
3153 const int kTouchId
= 5;
3154 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3155 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3156 delegate
.get(), -1234, bounds
, root_window()));
3160 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3161 kTouchId
, tes
.Now());
3162 DispatchEventUsingWindowDispatcher(&press
);
3163 EXPECT_FALSE(delegate
->tap());
3164 EXPECT_TRUE(delegate
->tap_down());
3165 EXPECT_FALSE(delegate
->tap_cancel());
3166 EXPECT_TRUE(delegate
->begin());
3167 EXPECT_FALSE(delegate
->scroll_begin());
3168 EXPECT_FALSE(delegate
->scroll_update());
3169 EXPECT_FALSE(delegate
->scroll_end());
3171 // Move the touch-point enough so that it would normally be considered a
3172 // scroll. But since the touch-moves will be consumed, the scroll should not
3174 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3175 EXPECT_FALSE(delegate
->tap());
3176 EXPECT_FALSE(delegate
->tap_down());
3177 EXPECT_TRUE(delegate
->tap_cancel());
3178 EXPECT_FALSE(delegate
->begin());
3179 EXPECT_FALSE(delegate
->scroll_update());
3180 EXPECT_FALSE(delegate
->scroll_end());
3182 // Consuming the first touch move event won't prevent all future scrolling.
3183 EXPECT_TRUE(delegate
->scroll_begin());
3185 // Now, stop consuming touch-move events, and move the touch-point again.
3186 delegate
->set_consume_touch_move(false);
3187 tes
.SendScrollEvent(event_processor(), 159, 259, kTouchId
, delegate
.get());
3188 EXPECT_FALSE(delegate
->tap());
3189 EXPECT_FALSE(delegate
->tap_down());
3190 EXPECT_FALSE(delegate
->tap_cancel());
3191 EXPECT_FALSE(delegate
->begin());
3192 EXPECT_FALSE(delegate
->scroll_begin());
3193 EXPECT_FALSE(delegate
->scroll_end());
3195 // Scroll not prevented by consumed first touch move.
3196 EXPECT_TRUE(delegate
->scroll_update());
3197 EXPECT_EQ(29, delegate
->scroll_x());
3198 EXPECT_EQ(29, delegate
->scroll_y());
3199 EXPECT_EQ(gfx::Point(0, 0).ToString(),
3200 delegate
->scroll_begin_position().ToString());
3202 // Start consuming touch-move events again.
3203 delegate
->set_consume_touch_move(true);
3205 // Move some more to generate a few more scroll updates.
3206 tes
.SendScrollEvent(event_processor(), 110, 211, kTouchId
, delegate
.get());
3207 EXPECT_FALSE(delegate
->tap());
3208 EXPECT_FALSE(delegate
->tap_down());
3209 EXPECT_FALSE(delegate
->tap_cancel());
3210 EXPECT_FALSE(delegate
->begin());
3211 EXPECT_FALSE(delegate
->scroll_begin());
3212 EXPECT_FALSE(delegate
->scroll_update());
3213 EXPECT_FALSE(delegate
->scroll_end());
3214 EXPECT_EQ(0, delegate
->scroll_x());
3215 EXPECT_EQ(0, delegate
->scroll_y());
3217 tes
.SendScrollEvent(event_processor(), 140, 215, kTouchId
, delegate
.get());
3218 EXPECT_FALSE(delegate
->tap());
3219 EXPECT_FALSE(delegate
->tap_down());
3220 EXPECT_FALSE(delegate
->tap_cancel());
3221 EXPECT_FALSE(delegate
->begin());
3222 EXPECT_FALSE(delegate
->scroll_begin());
3223 EXPECT_FALSE(delegate
->scroll_update());
3224 EXPECT_FALSE(delegate
->scroll_end());
3225 EXPECT_EQ(0, delegate
->scroll_x());
3226 EXPECT_EQ(0, delegate
->scroll_y());
3228 // Release the touch.
3230 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3231 kTouchId
, tes
.LeapForward(50));
3232 DispatchEventUsingWindowDispatcher(&release
);
3233 EXPECT_FALSE(delegate
->tap());
3234 EXPECT_FALSE(delegate
->tap_down());
3235 EXPECT_FALSE(delegate
->tap_cancel());
3236 EXPECT_FALSE(delegate
->begin());
3237 EXPECT_TRUE(delegate
->end());
3238 EXPECT_FALSE(delegate
->scroll_begin());
3239 EXPECT_FALSE(delegate
->scroll_update());
3240 EXPECT_FALSE(delegate
->fling());
3242 EXPECT_TRUE(delegate
->scroll_end());
3245 // Check that appropriate touch events generate double tap gesture events.
3246 TEST_F(GestureRecognizerTest
, GestureEventDoubleTap
) {
3247 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3248 new GestureEventConsumeDelegate());
3249 const int kWindowWidth
= 123;
3250 const int kWindowHeight
= 45;
3251 const int kTouchId
= 2;
3252 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3253 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3254 delegate
.get(), -1234, bounds
, root_window()));
3257 // First tap (tested in GestureEventTap)
3258 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(104, 201),
3259 kTouchId
, tes
.Now());
3260 DispatchEventUsingWindowDispatcher(&press1
);
3261 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(104, 201),
3262 kTouchId
, tes
.LeapForward(50));
3263 DispatchEventUsingWindowDispatcher(&release1
);
3267 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 203),
3268 kTouchId
, tes
.LeapForward(200));
3269 DispatchEventUsingWindowDispatcher(&press2
);
3270 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3271 kTouchId
, tes
.LeapForward(50));
3272 DispatchEventUsingWindowDispatcher(&release2
);
3274 EXPECT_TRUE(delegate
->tap());
3275 EXPECT_TRUE(delegate
->tap_down());
3276 EXPECT_FALSE(delegate
->tap_cancel());
3277 EXPECT_TRUE(delegate
->begin());
3278 EXPECT_TRUE(delegate
->end());
3279 EXPECT_FALSE(delegate
->scroll_begin());
3280 EXPECT_FALSE(delegate
->scroll_update());
3281 EXPECT_FALSE(delegate
->scroll_end());
3283 EXPECT_EQ(2, delegate
->tap_count());
3286 // Check that appropriate touch events generate triple tap gesture events.
3287 TEST_F(GestureRecognizerTest
, GestureEventTripleTap
) {
3288 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3289 new GestureEventConsumeDelegate());
3290 const int kWindowWidth
= 123;
3291 const int kWindowHeight
= 45;
3292 const int kTouchId
= 2;
3293 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3294 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3295 delegate
.get(), -1234, bounds
, root_window()));
3298 // First tap (tested in GestureEventTap)
3299 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(104, 201),
3300 kTouchId
, tes
.Now());
3301 DispatchEventUsingWindowDispatcher(&press1
);
3302 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(104, 201),
3303 kTouchId
, tes
.LeapForward(50));
3304 DispatchEventUsingWindowDispatcher(&release1
);
3306 EXPECT_EQ(1, delegate
->tap_count());
3309 // Second tap (tested in GestureEventDoubleTap)
3310 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 203),
3311 kTouchId
, tes
.LeapForward(200));
3312 DispatchEventUsingWindowDispatcher(&press2
);
3313 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3314 kTouchId
, tes
.LeapForward(50));
3315 DispatchEventUsingWindowDispatcher(&release2
);
3317 EXPECT_EQ(2, delegate
->tap_count());
3321 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
, gfx::Point(102, 206),
3322 kTouchId
, tes
.LeapForward(200));
3323 DispatchEventUsingWindowDispatcher(&press3
);
3324 ui::TouchEvent
release3(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3325 kTouchId
, tes
.LeapForward(50));
3326 DispatchEventUsingWindowDispatcher(&release3
);
3328 // Third, Fourth and Fifth Taps. Taps after the third should have their
3329 // |tap_count| wrap around back to 1.
3330 for (int i
= 3; i
< 5; ++i
) {
3331 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
,
3332 gfx::Point(102, 206),
3334 tes
.LeapForward(200));
3335 DispatchEventUsingWindowDispatcher(&press3
);
3336 ui::TouchEvent
release3(ui::ET_TOUCH_RELEASED
,
3337 gfx::Point(102, 206),
3339 tes
.LeapForward(50));
3340 DispatchEventUsingWindowDispatcher(&release3
);
3342 EXPECT_TRUE(delegate
->tap());
3343 EXPECT_TRUE(delegate
->tap_down());
3344 EXPECT_FALSE(delegate
->tap_cancel());
3345 EXPECT_TRUE(delegate
->begin());
3346 EXPECT_TRUE(delegate
->end());
3347 EXPECT_FALSE(delegate
->scroll_begin());
3348 EXPECT_FALSE(delegate
->scroll_update());
3349 EXPECT_FALSE(delegate
->scroll_end());
3350 EXPECT_EQ(1 + (i
% 3), delegate
->tap_count());
3354 // Check that we don't get a double tap when the two taps are far apart.
3355 TEST_F(GestureRecognizerTest
, TwoTapsFarApart
) {
3356 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3357 new GestureEventConsumeDelegate());
3358 const int kWindowWidth
= 123;
3359 const int kWindowHeight
= 45;
3360 const int kTouchId
= 2;
3361 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3362 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3363 delegate
.get(), -1234, bounds
, root_window()));
3366 // First tap (tested in GestureEventTap)
3367 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3368 kTouchId
, tes
.Now());
3369 DispatchEventUsingWindowDispatcher(&press1
);
3370 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3371 kTouchId
, tes
.LeapForward(50));
3372 DispatchEventUsingWindowDispatcher(&release1
);
3375 // Second tap, close in time but far in distance
3376 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(201, 201),
3377 kTouchId
, tes
.LeapForward(200));
3378 DispatchEventUsingWindowDispatcher(&press2
);
3379 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(201, 201),
3380 kTouchId
, tes
.LeapForward(50));
3381 DispatchEventUsingWindowDispatcher(&release2
);
3383 EXPECT_TRUE(delegate
->tap());
3384 EXPECT_TRUE(delegate
->tap_down());
3385 EXPECT_FALSE(delegate
->tap_cancel());
3386 EXPECT_TRUE(delegate
->begin());
3387 EXPECT_TRUE(delegate
->end());
3388 EXPECT_FALSE(delegate
->scroll_begin());
3389 EXPECT_FALSE(delegate
->scroll_update());
3390 EXPECT_FALSE(delegate
->scroll_end());
3392 EXPECT_EQ(1, delegate
->tap_count());
3395 // Check that we don't get a double tap when the two taps have a long enough
3396 // delay in between.
3397 TEST_F(GestureRecognizerTest
, TwoTapsWithDelayBetween
) {
3398 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3399 new GestureEventConsumeDelegate());
3400 const int kWindowWidth
= 123;
3401 const int kWindowHeight
= 45;
3402 const int kTouchId
= 2;
3403 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3404 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3405 delegate
.get(), -1234, bounds
, root_window()));
3408 // First tap (tested in GestureEventTap)
3409 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3410 kTouchId
, tes
.Now());
3411 DispatchEventUsingWindowDispatcher(&press1
);
3412 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3413 kTouchId
, tes
.LeapForward(50));
3414 DispatchEventUsingWindowDispatcher(&release1
);
3417 // Second tap, close in distance but after some delay
3418 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3419 kTouchId
, tes
.LeapForward(2000));
3420 DispatchEventUsingWindowDispatcher(&press2
);
3421 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3422 kTouchId
, tes
.LeapForward(50));
3423 DispatchEventUsingWindowDispatcher(&release2
);
3425 EXPECT_TRUE(delegate
->tap());
3426 EXPECT_TRUE(delegate
->tap_down());
3427 EXPECT_FALSE(delegate
->tap_cancel());
3428 EXPECT_TRUE(delegate
->begin());
3429 EXPECT_TRUE(delegate
->end());
3430 EXPECT_FALSE(delegate
->scroll_begin());
3431 EXPECT_FALSE(delegate
->scroll_update());
3432 EXPECT_FALSE(delegate
->scroll_end());
3434 EXPECT_EQ(1, delegate
->tap_count());
3437 // Checks that if the bounding-box of a gesture changes because of change in
3438 // radius of a touch-point, and not because of change in position, then there
3439 // are not gesture events from that.
3440 TEST_F(GestureRecognizerTest
, BoundingBoxRadiusChange
) {
3441 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3442 new GestureEventConsumeDelegate());
3443 const int kWindowWidth
= 234;
3444 const int kWindowHeight
= 345;
3445 const int kTouchId
= 5, kTouchId2
= 7;
3446 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3447 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3448 delegate
.get(), -1234, bounds
, root_window()));
3451 ui::TouchEvent
press1(
3452 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId
, tes
.Now());
3453 DispatchEventUsingWindowDispatcher(&press1
);
3454 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
3458 ui::TouchEvent
press2(
3459 ui::ET_TOUCH_PRESSED
, gfx::Point(201, 201), kTouchId2
,
3460 tes
.LeapForward(400));
3461 press2
.set_radius_x(5);
3462 DispatchEventUsingWindowDispatcher(&press2
);
3463 EXPECT_FALSE(delegate
->pinch_begin());
3464 EXPECT_EQ(gfx::Rect(101, 196, 105, 10).ToString(),
3465 delegate
->bounding_box().ToString());
3469 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(50, 50), kTouchId
,
3470 tes
.LeapForward(40));
3471 DispatchEventUsingWindowDispatcher(&move1
);
3472 EXPECT_TRUE(delegate
->pinch_begin());
3473 EXPECT_EQ(gfx::Rect(50, 50, 156, 156).ToString(),
3474 delegate
->bounding_box().ToString());
3478 // The position doesn't move, but the radius changes.
3479 ui::TouchEvent
move2(
3480 ui::ET_TOUCH_MOVED
, gfx::Point(50, 50), kTouchId
, tes
.LeapForward(40));
3481 move2
.set_radius_x(50);
3482 move2
.set_radius_y(60);
3483 DispatchEventUsingWindowDispatcher(&move2
);
3484 EXPECT_FALSE(delegate
->tap());
3485 EXPECT_FALSE(delegate
->tap_cancel());
3486 EXPECT_FALSE(delegate
->scroll_update());
3487 EXPECT_FALSE(delegate
->pinch_update());
3492 // Checks that slow scrolls deliver the correct deltas.
3493 // In particular, fix for http;//crbug.com/150573.
3494 TEST_F(GestureRecognizerTest
, NoDriftInScroll
) {
3495 ui::GestureConfiguration::GetInstance()
3496 ->set_max_touch_move_in_pixels_for_click(3);
3497 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3498 new GestureEventConsumeDelegate());
3499 const int kWindowWidth
= 234;
3500 const int kWindowHeight
= 345;
3501 const int kTouchId
= 5;
3503 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3504 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3505 delegate
.get(), -1234, bounds
, root_window()));
3507 ui::TouchEvent
press1(
3508 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 208), kTouchId
, tes
.Now());
3509 DispatchEventUsingWindowDispatcher(&press1
);
3510 EXPECT_TRUE(delegate
->begin());
3514 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(101, 206), kTouchId
,
3515 tes
.LeapForward(40));
3516 DispatchEventUsingWindowDispatcher(&move1
);
3517 EXPECT_FALSE(delegate
->scroll_begin());
3521 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(101, 204), kTouchId
,
3522 tes
.LeapForward(40));
3523 DispatchEventUsingWindowDispatcher(&move2
);
3524 EXPECT_TRUE(delegate
->tap_cancel());
3525 EXPECT_TRUE(delegate
->scroll_begin());
3526 EXPECT_TRUE(delegate
->scroll_update());
3527 // 3 px consumed by touch slop region.
3528 EXPECT_EQ(-1, delegate
->scroll_y());
3529 EXPECT_EQ(-4, delegate
->scroll_y_hint());
3533 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(101, 204), kTouchId
,
3534 tes
.LeapForward(40));
3535 DispatchEventUsingWindowDispatcher(&move3
);
3536 EXPECT_FALSE(delegate
->scroll_update());
3540 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(101, 203), kTouchId
,
3541 tes
.LeapForward(40));
3542 DispatchEventUsingWindowDispatcher(&move4
);
3543 EXPECT_TRUE(delegate
->scroll_update());
3544 EXPECT_EQ(-1, delegate
->scroll_y());
3549 // Ensure that move events which are preventDefaulted will cause a tap
3550 // cancel gesture event to be fired if the move would normally cause a
3551 // scroll. See bug http://crbug.com/146397.
3552 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveCanFireTapCancel
) {
3553 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3554 new ConsumesTouchMovesDelegate());
3555 const int kTouchId
= 5;
3556 gfx::Rect
bounds(100, 200, 123, 45);
3557 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3558 delegate
.get(), -1234, bounds
, root_window()));
3562 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3563 kTouchId
, tes
.Now());
3565 delegate
->set_consume_touch_move(false);
3566 DispatchEventUsingWindowDispatcher(&press
);
3567 delegate
->set_consume_touch_move(true);
3569 // Move the touch-point enough so that it would normally be considered a
3570 // scroll. But since the touch-moves will be consumed, no scrolling should
3572 // With the unified gesture detector, we will receive a scroll begin gesture,
3573 // whereas with the aura gesture recognizer we won't.
3574 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3575 EXPECT_FALSE(delegate
->tap());
3576 EXPECT_FALSE(delegate
->tap_down());
3577 EXPECT_TRUE(delegate
->tap_cancel());
3578 EXPECT_FALSE(delegate
->begin());
3579 EXPECT_FALSE(delegate
->scroll_update());
3580 EXPECT_FALSE(delegate
->scroll_end());
3583 TEST_F(GestureRecognizerTest
, CancelAllActiveTouches
) {
3584 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3585 new GestureEventConsumeDelegate());
3587 const int kWindowWidth
= 800;
3588 const int kWindowHeight
= 600;
3589 const int kTouchId1
= 1;
3590 const int kTouchId2
= 2;
3591 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3592 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3593 delegate
.get(), -1234, bounds
, root_window()));
3594 scoped_ptr
<TestEventHandler
> handler(new TestEventHandler());
3595 window
->AddPreTargetHandler(handler
.get());
3597 // Start a gesture sequence on |window|. Then cancel all touches.
3598 // Make sure |window| receives a touch-cancel event.
3600 ui::TouchEvent
press(
3601 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
3602 DispatchEventUsingWindowDispatcher(&press
);
3604 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
3607 ui::ET_TOUCH_PRESSED
, gfx::Point(50, 50), kTouchId2
, tes
.Now());
3608 DispatchEventUsingWindowDispatcher(&p2
);
3610 delegate
->events(), ui::ET_GESTURE_TAP_CANCEL
, ui::ET_GESTURE_BEGIN
);
3612 ui::TouchEvent
move(
3613 ui::ET_TOUCH_MOVED
, gfx::Point(350, 300), kTouchId2
, tes
.Now());
3614 DispatchEventUsingWindowDispatcher(&move
);
3615 EXPECT_3_EVENTS(delegate
->events(),
3616 ui::ET_GESTURE_SCROLL_BEGIN
,
3617 ui::ET_GESTURE_SCROLL_UPDATE
,
3618 ui::ET_GESTURE_PINCH_BEGIN
);
3619 EXPECT_EQ(2, handler
->touch_pressed_count());
3623 ui::GestureRecognizer
* gesture_recognizer
= ui::GestureRecognizer::Get();
3624 EXPECT_EQ(window
.get(),
3625 gesture_recognizer
->GetTouchLockedTarget(press
));
3627 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
3629 EXPECT_EQ(NULL
, gesture_recognizer
->GetTouchLockedTarget(press
));
3630 EXPECT_4_EVENTS(delegate
->events(),
3631 ui::ET_GESTURE_PINCH_END
,
3632 ui::ET_GESTURE_SCROLL_END
,
3634 ui::ET_GESTURE_END
);
3635 const std::vector
<gfx::PointF
>& points
= handler
->cancelled_touch_points();
3636 EXPECT_EQ(2U, points
.size());
3637 EXPECT_EQ(gfx::Point(101, 201), points
[0]);
3638 EXPECT_EQ(gfx::Point(350, 300), points
[1]);
3641 // Check that appropriate touch events generate show press events
3642 TEST_F(GestureRecognizerTest
, GestureEventShowPress
) {
3643 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3644 new GestureEventConsumeDelegate());
3646 const int kWindowWidth
= 123;
3647 const int kWindowHeight
= 45;
3648 const int kTouchId
= 2;
3649 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3650 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3651 delegate
.get(), -1234, bounds
, root_window()));
3655 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3656 kTouchId
, tes
.Now());
3657 DispatchEventUsingWindowDispatcher(&press1
);
3658 EXPECT_TRUE(delegate
->tap_down());
3659 EXPECT_TRUE(delegate
->begin());
3660 EXPECT_FALSE(delegate
->tap_cancel());
3662 // We haven't pressed long enough for a show press to occur
3663 EXPECT_FALSE(delegate
->show_press());
3665 // Wait until the timer runs out
3666 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
3667 EXPECT_TRUE(delegate
->show_press());
3668 EXPECT_FALSE(delegate
->tap_cancel());
3671 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3672 kTouchId
, tes
.Now());
3673 DispatchEventUsingWindowDispatcher(&release1
);
3674 EXPECT_FALSE(delegate
->long_press());
3676 // Note the tap isn't dispatched until the release
3677 EXPECT_FALSE(delegate
->tap_cancel());
3678 EXPECT_TRUE(delegate
->tap());
3681 // Check that scrolling cancels a show press
3682 TEST_F(GestureRecognizerTest
, GestureEventShowPressCancelledByScroll
) {
3683 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3684 new GestureEventConsumeDelegate());
3686 const int kWindowWidth
= 123;
3687 const int kWindowHeight
= 45;
3688 const int kTouchId
= 6;
3689 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3690 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3691 delegate
.get(), -1234, bounds
, root_window()));
3695 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3696 kTouchId
, tes
.Now());
3697 DispatchEventUsingWindowDispatcher(&press1
);
3698 EXPECT_TRUE(delegate
->tap_down());
3700 // We haven't pressed long enough for a show press to occur
3701 EXPECT_FALSE(delegate
->show_press());
3702 EXPECT_FALSE(delegate
->tap_cancel());
3704 // Scroll around, to cancel the show press
3705 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3706 // Wait until the timer runs out
3707 DelayByShowPressTimeout();
3708 EXPECT_FALSE(delegate
->show_press());
3709 EXPECT_TRUE(delegate
->tap_cancel());
3712 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3713 kTouchId
, tes
.LeapForward(10));
3714 DispatchEventUsingWindowDispatcher(&release1
);
3715 EXPECT_FALSE(delegate
->show_press());
3716 EXPECT_FALSE(delegate
->tap_cancel());
3719 // Test that show press events are sent immediately on tap
3720 TEST_F(GestureRecognizerTest
, GestureEventShowPressSentOnTap
) {
3721 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3722 new GestureEventConsumeDelegate());
3724 const int kWindowWidth
= 123;
3725 const int kWindowHeight
= 45;
3726 const int kTouchId
= 6;
3727 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3728 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3729 delegate
.get(), -1234, bounds
, root_window()));
3733 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3734 kTouchId
, tes
.Now());
3735 DispatchEventUsingWindowDispatcher(&press1
);
3736 EXPECT_TRUE(delegate
->tap_down());
3738 // We haven't pressed long enough for a show press to occur
3739 EXPECT_FALSE(delegate
->show_press());
3740 EXPECT_FALSE(delegate
->tap_cancel());
3743 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3744 kTouchId
, tes
.LeapForward(50));
3745 DispatchEventUsingWindowDispatcher(&release1
);
3746 EXPECT_TRUE(delegate
->show_press());
3747 EXPECT_FALSE(delegate
->tap_cancel());
3748 EXPECT_TRUE(delegate
->tap());
3751 // Test that consuming the first move touch event prevents a scroll.
3752 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveScrollTest
) {
3753 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3754 new QueueTouchEventDelegate(host()->dispatcher()));
3756 const int kTouchId
= 7;
3757 gfx::Rect
bounds(0, 0, 1000, 1000);
3758 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3759 delegate
.get(), -1234, bounds
, root_window()));
3760 delegate
->set_window(window
.get());
3762 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3763 kTouchId
, tes
.Now());
3764 DispatchEventUsingWindowDispatcher(&press
);
3765 delegate
->ReceivedAck();
3767 // A touch move within the slop region is never consumed in web contents. The
3768 // unified GR won't prevent scroll if a touch move within the slop region is
3769 // consumed, so make sure this touch move exceeds the slop region.
3770 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(10, 10),
3771 kTouchId
, tes
.Now());
3772 DispatchEventUsingWindowDispatcher(&move1
);
3773 delegate
->ReceivedAckPreventDefaulted();
3775 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20),
3776 kTouchId
, tes
.Now());
3777 DispatchEventUsingWindowDispatcher(&move2
);
3778 delegate
->ReceivedAck();
3780 // With the unified gesture detector, consuming the first touch move event
3781 // won't prevent all future scrolling.
3782 EXPECT_TRUE(delegate
->scroll_begin());
3783 EXPECT_TRUE(delegate
->scroll_update());
3786 // Test that consuming the first move touch doesn't prevent a tap.
3787 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveTapTest
) {
3788 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3789 new QueueTouchEventDelegate(host()->dispatcher()));
3791 const int kTouchId
= 7;
3792 gfx::Rect
bounds(0, 0, 1000, 1000);
3793 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3794 delegate
.get(), -1234, bounds
, root_window()));
3795 delegate
->set_window(window
.get());
3797 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3798 kTouchId
, tes
.Now());
3799 DispatchEventUsingWindowDispatcher(&press
);
3800 delegate
->ReceivedAck();
3802 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(2, 2),
3803 kTouchId
, tes
.Now());
3804 DispatchEventUsingWindowDispatcher(&move
);
3805 delegate
->ReceivedAckPreventDefaulted();
3807 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(2, 2),
3808 kTouchId
, tes
.LeapForward(50));
3809 DispatchEventUsingWindowDispatcher(&release
);
3810 delegate
->ReceivedAck();
3812 EXPECT_TRUE(delegate
->tap());
3815 // Test that consuming the first move touch doesn't prevent a long press.
3816 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveLongPressTest
) {
3817 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3818 new QueueTouchEventDelegate(host()->dispatcher()));
3820 const int kWindowWidth
= 123;
3821 const int kWindowHeight
= 45;
3822 const int kTouchId
= 2;
3823 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3824 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3825 delegate
.get(), -1234, bounds
, root_window()));
3826 delegate
->set_window(window
.get());
3830 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3831 kTouchId
, tes
.Now());
3832 DispatchEventUsingWindowDispatcher(&press1
);
3833 delegate
->ReceivedAck();
3835 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(103, 203),
3836 kTouchId
, tes
.Now());
3837 DispatchEventUsingWindowDispatcher(&move
);
3838 delegate
->ReceivedAckPreventDefaulted();
3840 // Wait until the timer runs out
3841 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
3842 EXPECT_TRUE(delegate
->long_press());
3845 // Tests that the deltas are correct when leaving the slop region very slowly.
3846 TEST_F(GestureRecognizerTest
, TestExceedingSlopSlowly
) {
3847 ui::GestureConfiguration::GetInstance()
3848 ->set_max_touch_move_in_pixels_for_click(3);
3849 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3850 new GestureEventConsumeDelegate());
3851 const int kWindowWidth
= 234;
3852 const int kWindowHeight
= 345;
3853 const int kTouchId
= 5;
3855 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3856 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3857 delegate
.get(), -1234, bounds
, root_window()));
3859 ui::TouchEvent
press(
3860 ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10), kTouchId
, tes
.Now());
3861 DispatchEventUsingWindowDispatcher(&press
);
3862 EXPECT_FALSE(delegate
->scroll_begin());
3863 EXPECT_FALSE(delegate
->scroll_update());
3866 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(11, 10), kTouchId
,
3867 tes
.LeapForward(40));
3868 DispatchEventUsingWindowDispatcher(&move1
);
3869 EXPECT_FALSE(delegate
->scroll_begin());
3870 EXPECT_FALSE(delegate
->scroll_update());
3871 EXPECT_EQ(0, delegate
->scroll_x());
3872 EXPECT_EQ(0, delegate
->scroll_x_hint());
3875 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(12, 10), kTouchId
,
3876 tes
.LeapForward(40));
3877 DispatchEventUsingWindowDispatcher(&move2
);
3878 EXPECT_FALSE(delegate
->scroll_begin());
3879 EXPECT_FALSE(delegate
->scroll_update());
3880 EXPECT_EQ(0, delegate
->scroll_x());
3881 EXPECT_EQ(0, delegate
->scroll_x_hint());
3885 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::PointF(13.1f
, 10.f
), kTouchId
,
3886 tes
.LeapForward(40));
3887 DispatchEventUsingWindowDispatcher(&move3
);
3888 EXPECT_TRUE(delegate
->scroll_begin());
3889 EXPECT_TRUE(delegate
->scroll_update());
3890 EXPECT_NEAR(0.1, delegate
->scroll_x(), 0.0001);
3891 EXPECT_FLOAT_EQ(3.1f
, delegate
->scroll_x_hint());
3894 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(14, 10), kTouchId
,
3895 tes
.LeapForward(40));
3896 DispatchEventUsingWindowDispatcher(&move4
);
3897 EXPECT_FALSE(delegate
->scroll_begin());
3898 EXPECT_TRUE(delegate
->scroll_update());
3899 EXPECT_NEAR(0.9, delegate
->scroll_x(), 0.0001);
3900 EXPECT_EQ(0.f
, delegate
->scroll_x_hint());
3904 TEST_F(GestureRecognizerTest
, ScrollAlternatelyConsumedTest
) {
3905 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3906 new QueueTouchEventDelegate(host()->dispatcher()));
3908 const int kWindowWidth
= 3000;
3909 const int kWindowHeight
= 3000;
3910 const int kTouchId
= 2;
3911 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3912 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3913 delegate
.get(), -1234, bounds
, root_window()));
3914 delegate
->set_window(window
.get());
3921 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(x
, y
),
3922 kTouchId
, tes
.Now());
3923 DispatchEventUsingWindowDispatcher(&press1
);
3924 delegate
->ReceivedAck();
3925 EXPECT_FALSE(delegate
->scroll_begin());
3926 EXPECT_FALSE(delegate
->scroll_update());
3931 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
),
3932 kTouchId
, tes
.Now());
3933 DispatchEventUsingWindowDispatcher(&move1
);
3934 delegate
->ReceivedAck();
3935 EXPECT_TRUE(delegate
->scroll_begin());
3936 EXPECT_TRUE(delegate
->scroll_update());
3939 for (int i
= 0; i
< 3; ++i
) {
3942 ui::TouchEvent
move2(
3943 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId
, tes
.Now());
3944 DispatchEventUsingWindowDispatcher(&move2
);
3945 delegate
->ReceivedAck();
3946 EXPECT_FALSE(delegate
->scroll_begin());
3947 EXPECT_TRUE(delegate
->scroll_update());
3948 EXPECT_EQ(10, delegate
->scroll_x());
3949 EXPECT_EQ(10, delegate
->scroll_y());
3954 ui::TouchEvent
move3(
3955 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId
, tes
.Now());
3956 DispatchEventUsingWindowDispatcher(&move3
);
3957 delegate
->ReceivedAckPreventDefaulted();
3958 EXPECT_FALSE(delegate
->scroll_begin());
3959 EXPECT_FALSE(delegate
->scroll_update());
3964 TEST_F(GestureRecognizerTest
, PinchAlternatelyConsumedTest
) {
3965 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3966 new QueueTouchEventDelegate(host()->dispatcher()));
3968 const int kWindowWidth
= 3000;
3969 const int kWindowHeight
= 3000;
3970 const int kTouchId1
= 5;
3971 const int kTouchId2
= 7;
3972 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3973 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3974 delegate
.get(), -1234, bounds
, root_window()));
3975 delegate
->set_window(window
.get());
3978 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3979 kTouchId1
, tes
.Now());
3980 DispatchEventUsingWindowDispatcher(&press1
);
3981 delegate
->ReceivedAck();
3982 EXPECT_FALSE(delegate
->scroll_begin());
3983 EXPECT_FALSE(delegate
->scroll_update());
3989 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(x
, y
),
3990 kTouchId2
, tes
.Now());
3991 DispatchEventUsingWindowDispatcher(&press2
);
3992 delegate
->ReceivedAck();
3993 EXPECT_FALSE(delegate
->scroll_begin());
3994 EXPECT_FALSE(delegate
->scroll_update());
3995 EXPECT_FALSE(delegate
->pinch_begin());
3996 EXPECT_FALSE(delegate
->pinch_update());
4002 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
),
4003 kTouchId2
, tes
.Now());
4004 DispatchEventUsingWindowDispatcher(&move1
);
4005 delegate
->ReceivedAck();
4006 EXPECT_TRUE(delegate
->scroll_begin());
4007 EXPECT_TRUE(delegate
->scroll_update());
4008 EXPECT_TRUE(delegate
->pinch_begin());
4009 EXPECT_FALSE(delegate
->pinch_update());
4012 const float expected_scales
[] = {1.5f
, 1.2f
, 1.125f
};
4014 for (int i
= 0; i
< 3; ++i
) {
4017 ui::TouchEvent
move2(
4018 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId2
, tes
.Now());
4019 DispatchEventUsingWindowDispatcher(&move2
);
4020 delegate
->ReceivedAck();
4021 EXPECT_FALSE(delegate
->scroll_begin());
4022 EXPECT_TRUE(delegate
->scroll_update());
4023 EXPECT_FALSE(delegate
->scroll_end());
4024 EXPECT_FALSE(delegate
->pinch_begin());
4025 EXPECT_TRUE(delegate
->pinch_update());
4026 EXPECT_FALSE(delegate
->pinch_end());
4027 EXPECT_EQ(25, delegate
->scroll_x());
4028 EXPECT_EQ(25, delegate
->scroll_y());
4029 EXPECT_FLOAT_EQ(expected_scales
[i
], delegate
->scale());
4034 ui::TouchEvent
move3(
4035 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId2
, tes
.Now());
4036 DispatchEventUsingWindowDispatcher(&move3
);
4037 delegate
->ReceivedAckPreventDefaulted();
4038 EXPECT_FALSE(delegate
->scroll_begin());
4039 EXPECT_FALSE(delegate
->scroll_update());
4040 EXPECT_FALSE(delegate
->scroll_end());
4041 EXPECT_FALSE(delegate
->pinch_begin());
4042 EXPECT_FALSE(delegate
->pinch_update());
4043 EXPECT_FALSE(delegate
->pinch_end());
4048 // Test that touch event flags are passed through to the gesture event.
4049 TEST_F(GestureRecognizerTest
, GestureEventFlagsPassedFromTouchEvent
) {
4050 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4051 new GestureEventConsumeDelegate());
4053 const int kWindowWidth
= 123;
4054 const int kWindowHeight
= 45;
4055 const int kTouchId
= 6;
4056 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
4057 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4058 delegate
.get(), -1234, bounds
, root_window()));
4062 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4063 kTouchId
, tes
.Now());
4064 DispatchEventUsingWindowDispatcher(&press1
);
4065 EXPECT_TRUE(delegate
->tap_down());
4067 int default_flags
= delegate
->flags();
4069 ui::TouchEvent
move1(
4070 ui::ET_TOUCH_MOVED
, gfx::Point(397, 149), kTouchId
, tes
.LeapForward(50));
4071 move1
.set_flags(992);
4073 DispatchEventUsingWindowDispatcher(&move1
);
4074 EXPECT_NE(default_flags
, delegate
->flags());
4077 // Test that latency info is passed through to the gesture event.
4078 TEST_F(GestureRecognizerTest
, LatencyPassedFromTouchEvent
) {
4079 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4080 new GestureEventConsumeDelegate());
4082 const int kWindowWidth
= 123;
4083 const int kWindowHeight
= 45;
4084 const int kTouchId
= 6;
4086 const base::TimeTicks time_original
= base::TimeTicks::FromInternalValue(100);
4087 const base::TimeTicks time_ui
= base::TimeTicks::FromInternalValue(200);
4088 const base::TimeTicks time_acked
= base::TimeTicks::FromInternalValue(300);
4090 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
4091 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4092 delegate
.get(), -1234, bounds
, root_window()));
4096 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4097 kTouchId
, tes
.Now());
4099 // Ensure the only components around are the ones we add.
4100 press1
.latency()->Clear();
4102 press1
.latency()->AddLatencyNumberWithTimestamp(
4103 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 0, 0, time_original
, 1);
4105 press1
.latency()->AddLatencyNumberWithTimestamp(
4106 ui::INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, 0, time_ui
, 1);
4108 press1
.latency()->AddLatencyNumberWithTimestamp(
4109 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT
, 0, 0, time_acked
, 1);
4111 DispatchEventUsingWindowDispatcher(&press1
);
4112 EXPECT_TRUE(delegate
->tap_down());
4114 ui::LatencyInfo::LatencyComponent component
;
4116 EXPECT_EQ(3U, delegate
->latency_info().latency_components
.size());
4117 ASSERT_TRUE(delegate
->latency_info().FindLatency(
4118 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 0, &component
));
4119 EXPECT_EQ(time_original
, component
.event_time
);
4121 ASSERT_TRUE(delegate
->latency_info().FindLatency(
4122 ui::INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
4123 EXPECT_EQ(time_ui
, component
.event_time
);
4125 ASSERT_TRUE(delegate
->latency_info().FindLatency(
4126 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT
, 0, &component
));
4127 EXPECT_EQ(time_acked
, component
.event_time
);
4129 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
4130 EXPECT_TRUE(delegate
->show_press());
4131 EXPECT_EQ(0U, delegate
->latency_info().latency_components
.size());
4134 // A delegate that deletes a window on long press.
4135 class GestureEventDeleteWindowOnLongPress
: public GestureEventConsumeDelegate
{
4137 GestureEventDeleteWindowOnLongPress()
4140 void set_window(aura::Window
** window
) { window_
= window
; }
4142 void OnGestureEvent(ui::GestureEvent
* gesture
) override
{
4143 GestureEventConsumeDelegate::OnGestureEvent(gesture
);
4144 if (gesture
->type() != ui::ET_GESTURE_LONG_PRESS
)
4146 ui::GestureRecognizer::Get()->CleanupStateForConsumer(*window_
);
4152 aura::Window
** window_
;
4153 DISALLOW_COPY_AND_ASSIGN(GestureEventDeleteWindowOnLongPress
);
4156 // Check that deleting the window in response to a long press gesture doesn't
4158 TEST_F(GestureRecognizerTest
, GestureEventLongPressDeletingWindow
) {
4159 GestureEventDeleteWindowOnLongPress delegate
;
4160 const int kWindowWidth
= 123;
4161 const int kWindowHeight
= 45;
4162 const int kTouchId
= 2;
4163 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
4164 aura::Window
* window(CreateTestWindowWithDelegate(
4165 &delegate
, -1234, bounds
, root_window()));
4166 delegate
.set_window(&window
);
4168 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
4169 gfx::Point(101, 201),
4171 ui::EventTimeForNow());
4172 DispatchEventUsingWindowDispatcher(&press1
);
4173 EXPECT_TRUE(window
!= NULL
);
4175 // Wait until the timer runs out.
4176 delegate
.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
4177 EXPECT_EQ(NULL
, window
);
4180 TEST_F(GestureRecognizerWithSwitchTest
, GestureEventSmallPinchDisabled
) {
4181 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4182 new GestureEventConsumeDelegate());
4184 const int kWindowWidth
= 300;
4185 const int kWindowHeight
= 400;
4186 const int kTouchId1
= 3;
4187 const int kTouchId2
= 5;
4188 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4189 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4190 delegate
.get(), -1234, bounds
, root_window()));
4192 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
4193 kTouchId1
, tes
.Now());
4194 DispatchEventUsingWindowDispatcher(&press1
);
4195 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
4196 kTouchId2
, tes
.Now());
4197 DispatchEventUsingWindowDispatcher(&press2
);
4199 // Move the first finger.
4201 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
4202 kTouchId1
, tes
.Now());
4203 DispatchEventUsingWindowDispatcher(&move1
);
4205 EXPECT_3_EVENTS(delegate
->events(),
4206 ui::ET_GESTURE_SCROLL_BEGIN
,
4207 ui::ET_GESTURE_SCROLL_UPDATE
,
4208 ui::ET_GESTURE_PINCH_BEGIN
);
4210 // No pinch update occurs, as kCompensateForUnstablePinchZoom is on and
4211 // |min_pinch_update_span_delta| was nonzero, and this is a very small pinch.
4213 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(65, 202),
4214 kTouchId1
, tes
.Now());
4215 DispatchEventUsingWindowDispatcher(&move2
);
4216 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
4219 TEST_F(GestureRecognizerTest
, GestureEventSmallPinchEnabled
) {
4220 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4221 new GestureEventConsumeDelegate());
4223 const int kWindowWidth
= 300;
4224 const int kWindowHeight
= 400;
4225 const int kTouchId1
= 3;
4226 const int kTouchId2
= 5;
4227 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4228 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4229 delegate
.get(), -1234, bounds
, root_window()));
4231 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
4232 kTouchId1
, tes
.Now());
4233 DispatchEventUsingWindowDispatcher(&press1
);
4234 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
4235 kTouchId2
, tes
.Now());
4236 DispatchEventUsingWindowDispatcher(&press2
);
4238 // Move the first finger.
4240 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
4241 kTouchId1
, tes
.Now());
4242 DispatchEventUsingWindowDispatcher(&move1
);
4244 EXPECT_3_EVENTS(delegate
->events(),
4245 ui::ET_GESTURE_SCROLL_BEGIN
,
4246 ui::ET_GESTURE_SCROLL_UPDATE
,
4247 ui::ET_GESTURE_PINCH_BEGIN
);
4250 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(65, 202),
4251 kTouchId1
, tes
.Now());
4252 DispatchEventUsingWindowDispatcher(&move2
);
4253 EXPECT_2_EVENTS(delegate
->events(),
4254 ui::ET_GESTURE_SCROLL_UPDATE
,
4255 ui::ET_GESTURE_PINCH_UPDATE
);
4258 // Tests that delaying the ack of a touch release doesn't trigger a long press
4260 TEST_F(GestureRecognizerTest
, EagerGestureDetection
) {
4261 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4262 new QueueTouchEventDelegate(host()->dispatcher()));
4264 const int kTouchId
= 2;
4265 gfx::Rect
bounds(100, 200, 100, 100);
4266 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4267 delegate
.get(), -1234, bounds
, root_window()));
4268 delegate
->set_window(window
.get());
4271 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4272 kTouchId
, tes
.Now());
4273 DispatchEventUsingWindowDispatcher(&press
);
4274 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
4275 kTouchId
, tes
.LeapForward(50));
4276 DispatchEventUsingWindowDispatcher(&release
);
4279 // Ack the touch press.
4280 delegate
->ReceivedAck();
4281 EXPECT_TRUE(delegate
->tap_down());
4284 // Wait until the long press event would fire (if we weren't eager).
4285 DelayByLongPressTimeout();
4287 // Ack the touch release.
4288 delegate
->ReceivedAck();
4289 EXPECT_TRUE(delegate
->tap());
4290 EXPECT_FALSE(delegate
->long_press());
4293 // This tests crbug.com/405519, in which touch events which the gesture detector
4294 // ignores interfere with gesture recognition.
4295 TEST_F(GestureRecognizerTest
, IgnoredEventsDontBreakGestureRecognition
) {
4296 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4297 new QueueTouchEventDelegate(host()->dispatcher()));
4299 const int kWindowWidth
= 300;
4300 const int kWindowHeight
= 400;
4301 const int kTouchId1
= 3;
4302 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4303 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4304 delegate
.get(), -1234, bounds
, root_window()));
4305 delegate
->set_window(window
.get());
4307 ui::TouchEvent
press1(
4308 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301), kTouchId1
, tes
.Now());
4309 DispatchEventUsingWindowDispatcher(&press1
);
4310 delegate
->ReceivedAck();
4313 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
4315 // Move the first finger.
4317 ui::TouchEvent
move1(
4318 ui::ET_TOUCH_MOVED
, gfx::Point(65, 201), kTouchId1
, tes
.Now());
4319 DispatchEventUsingWindowDispatcher(&move1
);
4320 delegate
->ReceivedAck();
4322 EXPECT_3_EVENTS(delegate
->events(),
4323 ui::ET_GESTURE_TAP_CANCEL
,
4324 ui::ET_GESTURE_SCROLL_BEGIN
,
4325 ui::ET_GESTURE_SCROLL_UPDATE
);
4329 // Send a valid event, but don't ack it.
4330 ui::TouchEvent
move2(
4331 ui::ET_TOUCH_MOVED
, gfx::Point(65, 202), kTouchId1
, tes
.Now());
4332 DispatchEventUsingWindowDispatcher(&move2
);
4333 EXPECT_0_EVENTS(delegate
->events());
4335 // Send a touchmove event at the same location as the previous touchmove
4336 // event. This shouldn't do anything.
4337 ui::TouchEvent
move3(
4338 ui::ET_TOUCH_MOVED
, gfx::Point(65, 202), kTouchId1
, tes
.Now());
4339 DispatchEventUsingWindowDispatcher(&move3
);
4341 // Ack the previous valid event. The intermediary invalid event shouldn't
4343 delegate
->ReceivedAck();
4344 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
4347 // Tests that an event stream can have a mix of sync and async acks.
4348 TEST_F(GestureRecognizerTest
,
4349 MixedSyncAndAsyncAcksDontCauseOutOfOrderDispatch
) {
4350 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4351 new QueueTouchEventDelegate(host()->dispatcher()));
4353 const int kWindowWidth
= 300;
4354 const int kWindowHeight
= 400;
4355 const int kTouchId1
= 3;
4356 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
4357 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4358 delegate
.get(), -1234, bounds
, root_window()));
4359 delegate
->set_window(window
.get());
4361 // Start a scroll gesture.
4362 ui::TouchEvent
press1(
4363 ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0), kTouchId1
, tes
.Now());
4364 DispatchEventUsingWindowDispatcher(&press1
);
4365 delegate
->ReceivedAck();
4367 ui::TouchEvent
move1(
4368 ui::ET_TOUCH_MOVED
, gfx::Point(100, 100), kTouchId1
, tes
.Now());
4369 DispatchEventUsingWindowDispatcher(&move1
);
4370 delegate
->ReceivedAck();
4373 // Dispatch a synchronously consumed touch move, which should be ignored.
4374 delegate
->set_synchronous_ack_for_next_event(true);
4375 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(200, 200), kTouchId1
,
4377 DispatchEventUsingWindowDispatcher(&move2
);
4378 EXPECT_0_EVENTS(delegate
->events());
4380 // Dispatch a touch move, but don't ack it.
4381 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(300, 300), kTouchId1
,
4383 DispatchEventUsingWindowDispatcher(&move3
);
4385 // Dispatch two synchronously consumed touch moves, which should be ignored.
4386 delegate
->set_synchronous_ack_for_next_event(true);
4387 ui::TouchEvent
move4(
4388 ui::ET_TOUCH_MOVED
, gfx::Point(400, 400), kTouchId1
, tes
.Now());
4389 DispatchEventUsingWindowDispatcher(&move4
);
4391 delegate
->set_synchronous_ack_for_next_event(true);
4392 ui::TouchEvent
move5(
4393 ui::ET_TOUCH_MOVED
, gfx::Point(500, 500), kTouchId1
, tes
.Now());
4394 DispatchEventUsingWindowDispatcher(&move5
);
4396 EXPECT_0_EVENTS(delegate
->events());
4397 EXPECT_EQ(100, delegate
->bounding_box().x());
4398 // Ack the pending touch move, and ensure the most recent gesture event
4399 // used its co-ordinates.
4400 delegate
->ReceivedAck();
4401 EXPECT_EQ(300, delegate
->bounding_box().x());
4402 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
4404 // Dispatch a touch move, but don't ack it.
4406 ui::TouchEvent
move6(ui::ET_TOUCH_MOVED
, gfx::Point(600, 600), kTouchId1
,
4408 DispatchEventUsingWindowDispatcher(&move6
);
4410 // Dispatch a synchronously unconsumed touch move.
4411 delegate
->set_synchronous_ack_for_next_event(false);
4412 ui::TouchEvent
move7(
4413 ui::ET_TOUCH_MOVED
, gfx::Point(700, 700), kTouchId1
, tes
.Now());
4414 DispatchEventUsingWindowDispatcher(&move7
);
4416 // The synchronous ack is stuck behind the pending touch move.
4417 EXPECT_0_EVENTS(delegate
->events());
4419 delegate
->ReceivedAck();
4420 EXPECT_2_EVENTS(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
,
4421 ui::ET_GESTURE_SCROLL_UPDATE
);