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/gestures/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/point.h"
28 #include "ui/gfx/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 virtual ~GestureEventConsumeDelegate() {}
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 virtual 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 queue_events_(true) {
342 virtual ~QueueTouchEventDelegate() {
343 while(!queue_
.empty()) {
344 delete queue_
.front();
349 virtual void OnTouchEvent(ui::TouchEvent
* event
) OVERRIDE
{
351 queue_
.push(new ui::TouchEvent(*event
, window_
, window_
));
352 event
->StopPropagation();
357 ReceivedAckImpl(false);
360 void ReceivedAckPreventDefaulted() {
361 ReceivedAckImpl(true);
364 void set_window(Window
* w
) { window_
= w
; }
365 void set_queue_events(bool queue
) { queue_events_
= queue
; }
368 void ReceivedAckImpl(bool prevent_defaulted
) {
369 scoped_ptr
<ui::TouchEvent
> event(queue_
.front());
370 dispatcher_
->ProcessedTouchEvent(event
.get(), window_
,
371 prevent_defaulted
? ui::ER_HANDLED
: ui::ER_UNHANDLED
);
375 std::queue
<ui::TouchEvent
*> queue_
;
377 WindowEventDispatcher
* dispatcher_
;
380 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate
);
383 // A delegate that ignores gesture events but keeps track of [synthetic] mouse
385 class GestureEventSynthDelegate
: public TestWindowDelegate
{
387 GestureEventSynthDelegate()
388 : mouse_enter_(false),
391 mouse_release_(false),
393 double_click_(false) {
397 mouse_enter_
= false;
399 mouse_press_
= false;
400 mouse_release_
= false;
402 double_click_
= false;
405 bool mouse_enter() const { return mouse_enter_
; }
406 bool mouse_exit() const { return mouse_exit_
; }
407 bool mouse_press() const { return mouse_press_
; }
408 bool mouse_move() const { return mouse_move_
; }
409 bool mouse_release() const { return mouse_release_
; }
410 bool double_click() const { return double_click_
; }
412 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
{
413 switch (event
->type()) {
414 case ui::ET_MOUSE_PRESSED
:
415 double_click_
= event
->flags() & ui::EF_IS_DOUBLE_CLICK
;
418 case ui::ET_MOUSE_RELEASED
:
419 mouse_release_
= true;
421 case ui::ET_MOUSE_MOVED
:
424 case ui::ET_MOUSE_ENTERED
:
427 case ui::ET_MOUSE_EXITED
:
444 DISALLOW_COPY_AND_ASSIGN(GestureEventSynthDelegate
);
447 class ScopedGestureRecognizerSetter
{
449 // Takes ownership of |new_gr|.
450 explicit ScopedGestureRecognizerSetter(ui::GestureRecognizer
* new_gr
)
452 original_gr_
= ui::GestureRecognizer::Get();
453 ui::SetGestureRecognizerForTesting(new_gr_
.get());
456 virtual ~ScopedGestureRecognizerSetter() {
457 ui::SetGestureRecognizerForTesting(original_gr_
);
461 ui::GestureRecognizer
* original_gr_
;
462 scoped_ptr
<ui::GestureRecognizer
> new_gr_
;
464 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter
);
472 // Use a non-zero start time to pass DCHECKs which ensure events have had a
474 TimedEvents() : simulated_now_(1) {
477 base::TimeDelta
Now() {
478 base::TimeDelta t
= base::TimeDelta::FromMilliseconds(simulated_now_
);
483 base::TimeDelta
LeapForward(int time_in_millis
) {
484 simulated_now_
+= time_in_millis
;
485 return base::TimeDelta::FromMilliseconds(simulated_now_
);
488 base::TimeDelta
InFuture(int time_in_millis
) {
489 return base::TimeDelta::FromMilliseconds(simulated_now_
+ time_in_millis
);
492 void SendScrollEvents(ui::EventProcessor
* dispatcher
,
500 GestureEventConsumeDelegate
* delegate
) {
504 for (int i
= 0; i
< num_steps
; i
++) {
507 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::PointF(x
, y
),
509 base::TimeDelta::FromMilliseconds(simulated_now_
));
510 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(&move
);
511 ASSERT_FALSE(details
.dispatcher_destroyed
);
512 simulated_now_
+= time_step
;
516 void SendScrollEvent(ui::EventProcessor
* dispatcher
,
520 GestureEventConsumeDelegate
* delegate
) {
522 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::PointF(x
, y
),
524 base::TimeDelta::FromMilliseconds(simulated_now_
));
525 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(&move
);
526 ASSERT_FALSE(details
.dispatcher_destroyed
);
531 // An event handler to keep track of events.
532 class TestEventHandler
: public ui::EventHandler
{
535 : touch_released_count_(0),
536 touch_pressed_count_(0),
537 touch_moved_count_(0) {}
539 virtual ~TestEventHandler() {}
541 virtual void OnTouchEvent(ui::TouchEvent
* event
) OVERRIDE
{
542 switch (event
->type()) {
543 case ui::ET_TOUCH_RELEASED
:
544 touch_released_count_
++;
546 case ui::ET_TOUCH_PRESSED
:
547 touch_pressed_count_
++;
549 case ui::ET_TOUCH_MOVED
:
550 touch_moved_count_
++;
552 case ui::ET_TOUCH_CANCELLED
:
553 cancelled_touch_points_
.push_back(event
->location());
561 touch_released_count_
= 0;
562 touch_pressed_count_
= 0;
563 touch_moved_count_
= 0;
564 cancelled_touch_points_
.clear();
567 int touch_released_count() const { return touch_released_count_
; }
568 int touch_pressed_count() const { return touch_pressed_count_
; }
569 int touch_moved_count() const { return touch_moved_count_
; }
570 int touch_cancelled_count() const {
571 return static_cast<int>(cancelled_touch_points_
.size());
573 const std::vector
<gfx::PointF
>& cancelled_touch_points() const {
574 return cancelled_touch_points_
;
578 int touch_released_count_
;
579 int touch_pressed_count_
;
580 int touch_moved_count_
;
581 std::vector
<gfx::PointF
> cancelled_touch_points_
;
583 DISALLOW_COPY_AND_ASSIGN(TestEventHandler
);
586 // Removes the target window from its parent when it receives a touch-cancel
588 class RemoveOnTouchCancelHandler
: public TestEventHandler
{
590 RemoveOnTouchCancelHandler() {}
591 virtual ~RemoveOnTouchCancelHandler() {}
595 virtual void OnTouchEvent(ui::TouchEvent
* event
) OVERRIDE
{
596 TestEventHandler::OnTouchEvent(event
);
597 if (event
->type() == ui::ET_TOUCH_CANCELLED
) {
598 Window
* target
= static_cast<Window
*>(event
->target());
599 // This is tiptoeing around crbug.com/310172. If this event handler isn't
600 // removed, we enter an infinite loop.
601 target
->RemovePreTargetHandler(this);
602 target
->parent()->RemoveChild(target
);
606 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler
);
609 void DelayByLongPressTimeout() {
610 ui::GestureProvider::Config config
;
611 base::RunLoop run_loop
;
612 base::MessageLoop::current()->PostDelayedTask(
614 run_loop
.QuitClosure(),
615 config
.gesture_detector_config
.longpress_timeout
* 2);
619 void DelayByShowPressTimeout() {
620 ui::GestureProvider::Config config
;
621 base::RunLoop run_loop
;
622 base::MessageLoop::current()->PostDelayedTask(
624 run_loop
.QuitClosure(),
625 config
.gesture_detector_config
.showpress_timeout
* 2);
631 class GestureRecognizerTest
: public AuraTestBase
,
632 public ::testing::WithParamInterface
<bool> {
634 GestureRecognizerTest() {}
636 virtual void SetUp() OVERRIDE
{
637 AuraTestBase::SetUp();
638 ui::GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click(
640 ui::GestureConfiguration::set_show_press_delay_in_ms(2);
641 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003);
644 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest
);
647 // Check that appropriate touch events generate tap gesture events.
648 TEST_F(GestureRecognizerTest
, GestureEventTap
) {
649 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
650 new GestureEventConsumeDelegate());
652 const int kWindowWidth
= 123;
653 const int kWindowHeight
= 45;
654 const int kTouchId
= 2;
655 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
656 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
657 delegate
.get(), -1234, bounds
, root_window()));
660 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
661 kTouchId
, tes
.Now());
662 DispatchEventUsingWindowDispatcher(&press
);
663 EXPECT_FALSE(delegate
->tap());
664 EXPECT_FALSE(delegate
->show_press());
665 EXPECT_TRUE(delegate
->tap_down());
666 EXPECT_FALSE(delegate
->tap_cancel());
667 EXPECT_TRUE(delegate
->begin());
668 EXPECT_FALSE(delegate
->scroll_begin());
669 EXPECT_FALSE(delegate
->scroll_update());
670 EXPECT_FALSE(delegate
->scroll_end());
671 EXPECT_FALSE(delegate
->long_press());
674 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
675 EXPECT_TRUE(delegate
->show_press());
676 EXPECT_FALSE(delegate
->tap_down());
678 // Make sure there is enough delay before the touch is released so that it is
679 // recognized as a tap.
681 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
682 kTouchId
, tes
.LeapForward(50));
684 DispatchEventUsingWindowDispatcher(&release
);
685 EXPECT_TRUE(delegate
->tap());
686 EXPECT_FALSE(delegate
->tap_down());
687 EXPECT_FALSE(delegate
->tap_cancel());
688 EXPECT_FALSE(delegate
->begin());
689 EXPECT_TRUE(delegate
->end());
690 EXPECT_FALSE(delegate
->scroll_begin());
691 EXPECT_FALSE(delegate
->scroll_update());
692 EXPECT_FALSE(delegate
->scroll_end());
694 EXPECT_EQ(1, delegate
->tap_count());
697 // Check that appropriate touch events generate tap gesture events
698 // when information about the touch radii are provided.
699 TEST_F(GestureRecognizerTest
, GestureEventTapRegion
) {
700 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
701 new GestureEventConsumeDelegate());
703 const int kWindowWidth
= 800;
704 const int kWindowHeight
= 600;
705 const int kTouchId
= 2;
706 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
707 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
708 delegate
.get(), -1234, bounds
, root_window()));
710 // Test with no ET_TOUCH_MOVED events.
713 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
714 kTouchId
, tes
.Now());
715 press
.set_radius_x(5);
716 press
.set_radius_y(12);
717 DispatchEventUsingWindowDispatcher(&press
);
718 EXPECT_FALSE(delegate
->tap());
719 EXPECT_TRUE(delegate
->tap_down());
720 EXPECT_FALSE(delegate
->tap_cancel());
721 EXPECT_TRUE(delegate
->begin());
722 EXPECT_FALSE(delegate
->scroll_begin());
723 EXPECT_FALSE(delegate
->scroll_update());
724 EXPECT_FALSE(delegate
->scroll_end());
725 EXPECT_FALSE(delegate
->long_press());
727 // Make sure there is enough delay before the touch is released so that it
728 // is recognized as a tap.
730 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
731 kTouchId
, tes
.LeapForward(50));
732 release
.set_radius_x(5);
733 release
.set_radius_y(12);
735 DispatchEventUsingWindowDispatcher(&release
);
736 EXPECT_TRUE(delegate
->tap());
737 EXPECT_FALSE(delegate
->tap_down());
738 EXPECT_FALSE(delegate
->tap_cancel());
739 EXPECT_FALSE(delegate
->begin());
740 EXPECT_TRUE(delegate
->end());
741 EXPECT_FALSE(delegate
->scroll_begin());
742 EXPECT_FALSE(delegate
->scroll_update());
743 EXPECT_FALSE(delegate
->scroll_end());
745 EXPECT_EQ(1, delegate
->tap_count());
746 gfx::Point
actual_point(delegate
->tap_location());
747 EXPECT_EQ(24, delegate
->bounding_box().width());
748 EXPECT_EQ(24, delegate
->bounding_box().height());
749 EXPECT_EQ(101, actual_point
.x());
750 EXPECT_EQ(201, actual_point
.y());
753 // Test with no ET_TOUCH_MOVED events but different touch points and radii.
756 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(365, 290),
757 kTouchId
, tes
.Now());
758 press
.set_radius_x(8);
759 press
.set_radius_y(14);
760 DispatchEventUsingWindowDispatcher(&press
);
761 EXPECT_FALSE(delegate
->tap());
762 EXPECT_TRUE(delegate
->tap_down());
763 EXPECT_FALSE(delegate
->tap_cancel());
764 EXPECT_TRUE(delegate
->begin());
765 EXPECT_FALSE(delegate
->scroll_begin());
766 EXPECT_FALSE(delegate
->scroll_update());
767 EXPECT_FALSE(delegate
->scroll_end());
768 EXPECT_FALSE(delegate
->long_press());
771 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(367, 291),
772 kTouchId
, tes
.LeapForward(50));
773 release
.set_radius_x(20);
774 release
.set_radius_y(13);
776 DispatchEventUsingWindowDispatcher(&release
);
777 EXPECT_TRUE(delegate
->tap());
778 EXPECT_FALSE(delegate
->tap_down());
779 EXPECT_FALSE(delegate
->tap_cancel());
780 EXPECT_FALSE(delegate
->begin());
781 EXPECT_TRUE(delegate
->end());
782 EXPECT_FALSE(delegate
->scroll_begin());
783 EXPECT_FALSE(delegate
->scroll_update());
784 EXPECT_FALSE(delegate
->scroll_end());
786 EXPECT_EQ(1, delegate
->tap_count());
787 gfx::Point
actual_point(delegate
->tap_location());
788 EXPECT_EQ(40, delegate
->bounding_box().width());
789 EXPECT_EQ(40, delegate
->bounding_box().height());
790 EXPECT_EQ(367, actual_point
.x());
791 EXPECT_EQ(291, actual_point
.y());
794 // Test with a single ET_TOUCH_MOVED event.
797 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(46, 205),
798 kTouchId
, tes
.Now());
799 press
.set_radius_x(6);
800 press
.set_radius_y(10);
801 DispatchEventUsingWindowDispatcher(&press
);
802 EXPECT_FALSE(delegate
->tap());
803 EXPECT_TRUE(delegate
->tap_down());
804 EXPECT_FALSE(delegate
->tap_cancel());
805 EXPECT_TRUE(delegate
->begin());
806 EXPECT_FALSE(delegate
->tap_cancel());
807 EXPECT_FALSE(delegate
->scroll_begin());
808 EXPECT_FALSE(delegate
->scroll_update());
809 EXPECT_FALSE(delegate
->scroll_end());
810 EXPECT_FALSE(delegate
->long_press());
813 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(49, 204),
814 kTouchId
, tes
.LeapForward(50));
815 move
.set_radius_x(8);
816 move
.set_radius_y(12);
817 DispatchEventUsingWindowDispatcher(&move
);
818 EXPECT_FALSE(delegate
->tap());
819 EXPECT_FALSE(delegate
->tap_down());
820 EXPECT_FALSE(delegate
->tap_cancel());
821 EXPECT_FALSE(delegate
->begin());
822 EXPECT_FALSE(delegate
->scroll_begin());
823 EXPECT_FALSE(delegate
->scroll_update());
824 EXPECT_FALSE(delegate
->scroll_end());
825 EXPECT_FALSE(delegate
->long_press());
828 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(49, 204),
829 kTouchId
, tes
.LeapForward(50));
830 release
.set_radius_x(4);
831 release
.set_radius_y(8);
833 DispatchEventUsingWindowDispatcher(&release
);
834 EXPECT_TRUE(delegate
->tap());
835 EXPECT_FALSE(delegate
->tap_down());
836 EXPECT_FALSE(delegate
->tap_cancel());
837 EXPECT_FALSE(delegate
->begin());
838 EXPECT_TRUE(delegate
->end());
839 EXPECT_FALSE(delegate
->scroll_begin());
840 EXPECT_FALSE(delegate
->scroll_update());
841 EXPECT_FALSE(delegate
->scroll_end());
843 EXPECT_EQ(1, delegate
->tap_count());
844 gfx::Point
actual_point(delegate
->tap_location());
845 EXPECT_EQ(16, delegate
->bounding_box().width());
846 EXPECT_EQ(16, delegate
->bounding_box().height());
847 EXPECT_EQ(49, actual_point
.x());
848 EXPECT_EQ(204, actual_point
.y());
851 // Test with a few ET_TOUCH_MOVED events.
854 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(400, 150),
855 kTouchId
, tes
.Now());
856 press
.set_radius_x(7);
857 press
.set_radius_y(10);
858 DispatchEventUsingWindowDispatcher(&press
);
859 EXPECT_FALSE(delegate
->tap());
860 EXPECT_TRUE(delegate
->tap_down());
861 EXPECT_FALSE(delegate
->tap_cancel());
862 EXPECT_TRUE(delegate
->begin());
863 EXPECT_FALSE(delegate
->scroll_begin());
864 EXPECT_FALSE(delegate
->scroll_update());
865 EXPECT_FALSE(delegate
->scroll_end());
866 EXPECT_FALSE(delegate
->long_press());
869 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(397, 151),
870 kTouchId
, tes
.LeapForward(50));
871 move
.set_radius_x(13);
872 move
.set_radius_y(12);
873 DispatchEventUsingWindowDispatcher(&move
);
874 EXPECT_FALSE(delegate
->tap());
875 EXPECT_FALSE(delegate
->tap_down());
876 EXPECT_FALSE(delegate
->tap_cancel());
877 EXPECT_FALSE(delegate
->begin());
878 EXPECT_FALSE(delegate
->scroll_begin());
879 EXPECT_FALSE(delegate
->scroll_update());
880 EXPECT_FALSE(delegate
->scroll_end());
881 EXPECT_FALSE(delegate
->long_press());
884 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(397, 149),
885 kTouchId
, tes
.LeapForward(50));
886 move1
.set_radius_x(16);
887 move1
.set_radius_y(16);
888 DispatchEventUsingWindowDispatcher(&move1
);
889 EXPECT_FALSE(delegate
->tap());
890 EXPECT_FALSE(delegate
->tap_down());
891 EXPECT_FALSE(delegate
->tap_cancel());
892 EXPECT_FALSE(delegate
->begin());
893 EXPECT_FALSE(delegate
->scroll_begin());
894 EXPECT_FALSE(delegate
->scroll_update());
895 EXPECT_FALSE(delegate
->scroll_end());
896 EXPECT_FALSE(delegate
->long_press());
899 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(400, 150),
900 kTouchId
, tes
.LeapForward(50));
901 move2
.set_radius_x(14);
902 move2
.set_radius_y(10);
903 DispatchEventUsingWindowDispatcher(&move2
);
904 EXPECT_FALSE(delegate
->tap());
905 EXPECT_FALSE(delegate
->tap_down());
906 EXPECT_FALSE(delegate
->tap_cancel());
907 EXPECT_FALSE(delegate
->begin());
908 EXPECT_FALSE(delegate
->scroll_begin());
909 EXPECT_FALSE(delegate
->scroll_update());
910 EXPECT_FALSE(delegate
->scroll_end());
911 EXPECT_FALSE(delegate
->long_press());
914 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(401, 149),
915 kTouchId
, tes
.LeapForward(50));
916 release
.set_radius_x(8);
917 release
.set_radius_y(9);
919 DispatchEventUsingWindowDispatcher(&release
);
920 EXPECT_TRUE(delegate
->tap());
921 EXPECT_FALSE(delegate
->tap_down());
922 EXPECT_FALSE(delegate
->tap_cancel());
923 EXPECT_FALSE(delegate
->begin());
924 EXPECT_TRUE(delegate
->end());
925 EXPECT_FALSE(delegate
->scroll_begin());
926 EXPECT_FALSE(delegate
->scroll_update());
927 EXPECT_FALSE(delegate
->scroll_end());
929 EXPECT_EQ(1, delegate
->tap_count());
930 gfx::Point
actual_point(delegate
->tap_location());
931 EXPECT_EQ(18, delegate
->bounding_box().width());
932 EXPECT_EQ(18, delegate
->bounding_box().height());
933 EXPECT_EQ(401, actual_point
.x());
934 EXPECT_EQ(149, actual_point
.y());
938 // Check that appropriate touch events generate scroll gesture events.
939 TEST_F(GestureRecognizerTest
, GestureEventScroll
) {
940 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of
941 // that distance to be consumed by the slop, so we set the slop radius to
942 // sqrt(5 * 5 + 5 * 5).
943 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
944 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
945 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
946 new GestureEventConsumeDelegate());
948 const int kWindowWidth
= 123;
949 const int kWindowHeight
= 45;
950 const int kTouchId
= 5;
951 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
952 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
953 delegate
.get(), -1234, bounds
, root_window()));
956 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
957 kTouchId
, tes
.Now());
958 DispatchEventUsingWindowDispatcher(&press
);
959 EXPECT_2_EVENTS(delegate
->events(),
960 ui::ET_GESTURE_BEGIN
,
961 ui::ET_GESTURE_TAP_DOWN
);
963 // Move the touch-point enough so that it is considered as a scroll. This
964 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
965 // The first movement is diagonal, to ensure that we have a free scroll,
966 // and not a rail scroll.
967 tes
.SendScrollEvent(event_processor(), 111.5, 211.5, kTouchId
,
969 EXPECT_3_EVENTS(delegate
->events(),
970 ui::ET_GESTURE_TAP_CANCEL
,
971 ui::ET_GESTURE_SCROLL_BEGIN
,
972 ui::ET_GESTURE_SCROLL_UPDATE
);
973 // The slop consumed 5 dips
974 EXPECT_FLOAT_EQ(5.5, delegate
->scroll_x());
975 EXPECT_FLOAT_EQ(5.5, delegate
->scroll_y());
976 EXPECT_EQ(gfx::Point(1, 1).ToString(),
977 delegate
->scroll_begin_position().ToString());
979 // When scrolling with a single finger, the bounding box of the gesture should
980 // be empty, since it's a single point and the radius for testing is zero.
981 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
983 // Move some more to generate a few more scroll updates. Make sure that we get
984 // out of the snap channel for the unified GR.
985 tes
.SendScrollEvent(event_processor(), 20, 120, kTouchId
, delegate
.get());
986 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
987 EXPECT_FLOAT_EQ(-91.5, delegate
->scroll_x());
988 EXPECT_FLOAT_EQ(-91.5, delegate
->scroll_y());
989 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
991 tes
.SendScrollEvent(event_processor(), 50, 124, kTouchId
, delegate
.get());
992 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
993 EXPECT_EQ(30, delegate
->scroll_x());
994 EXPECT_EQ(4, delegate
->scroll_y());
995 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
997 // Release the touch. This should end the scroll.
999 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1001 tes
.LeapForward(50));
1002 DispatchEventUsingWindowDispatcher(&release
);
1003 EXPECT_2_EVENTS(delegate
->events(),
1004 ui::ET_SCROLL_FLING_START
,
1005 ui::ET_GESTURE_END
);
1006 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1009 // Check that predicted scroll update positions are correct.
1010 TEST_F(GestureRecognizerTest
, GestureEventScrollPrediction
) {
1011 const double prediction_interval
= 0.03;
1012 ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval
);
1013 // We'll start by moving the touch point by (5, 5). We want all of that
1014 // distance to be consumed by the slop, so we set the slop radius to
1015 // sqrt(5 * 5 + 5 * 5).
1016 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1017 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1019 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1020 new GestureEventConsumeDelegate());
1022 const int kWindowWidth
= 123;
1023 const int kWindowHeight
= 45;
1024 const int kTouchId
= 5;
1025 gfx::Rect
bounds(95, 195, kWindowWidth
, kWindowHeight
);
1026 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1027 delegate
.get(), -1234, bounds
, root_window()));
1030 // Tracks the total scroll since we want to verify that the correct position
1031 // will be scrolled to throughout the prediction.
1032 gfx::Vector2dF total_scroll
;
1033 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(96, 196),
1034 kTouchId
, tes
.Now());
1035 DispatchEventUsingWindowDispatcher(&press
);
1036 EXPECT_2_EVENTS(delegate
->events(),
1037 ui::ET_GESTURE_BEGIN
,
1038 ui::ET_GESTURE_TAP_DOWN
);
1041 // Get rid of touch slop.
1042 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(111, 211),
1043 kTouchId
, tes
.Now());
1044 DispatchEventUsingWindowDispatcher(&move
);
1045 EXPECT_3_EVENTS(delegate
->events(),
1046 ui::ET_GESTURE_TAP_CANCEL
,
1047 ui::ET_GESTURE_SCROLL_BEGIN
,
1048 ui::ET_GESTURE_SCROLL_UPDATE
);
1049 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1050 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1052 // Move the touch-point enough so that it is considered as a scroll. This
1053 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1054 // The first movement is diagonal, to ensure that we have a free scroll,
1055 // and not a rail scroll.
1056 tes
.LeapForward(30);
1057 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
1058 EXPECT_1_EVENT(delegate
->events(),
1059 ui::ET_GESTURE_SCROLL_UPDATE
);
1060 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1061 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1063 // Move some more to generate a few more scroll updates.
1064 tes
.LeapForward(30);
1065 tes
.SendScrollEvent(event_processor(), 110, 211, kTouchId
, delegate
.get());
1066 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1067 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1068 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1070 tes
.LeapForward(30);
1071 tes
.SendScrollEvent(event_processor(), 140, 215, kTouchId
, delegate
.get());
1072 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1073 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1074 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1076 // Release the touch. This should end the scroll.
1078 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1080 tes
.LeapForward(50));
1081 DispatchEventUsingWindowDispatcher(&release
);
1084 // Check that the bounding box during a scroll event is correct.
1085 TEST_F(GestureRecognizerTest
, GestureEventScrollBoundingBox
) {
1087 for (int radius
= 1; radius
<= 10; ++radius
) {
1088 ui::GestureConfiguration::set_default_radius(radius
);
1089 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1090 new GestureEventConsumeDelegate());
1091 const int kWindowWidth
= 123;
1092 const int kWindowHeight
= 45;
1093 const int kTouchId
= 5;
1094 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1095 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1096 delegate
.get(), -1234, bounds
, root_window()));
1098 const int kPositionX
= 101;
1099 const int kPositionY
= 201;
1101 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1102 gfx::Point(kPositionX
, kPositionY
),
1105 DispatchEventUsingWindowDispatcher(&press
);
1106 EXPECT_EQ(gfx::Rect(kPositionX
- radius
,
1107 kPositionY
- radius
,
1109 radius
* 2).ToString(),
1110 delegate
->bounding_box().ToString());
1112 const int kScrollAmount
= 50;
1113 tes
.SendScrollEvents(event_processor(), kPositionX
, kPositionY
,
1114 1, 1, kTouchId
, 1, kScrollAmount
, delegate
.get());
1115 EXPECT_EQ(gfx::Point(1, 1).ToString(),
1116 delegate
->scroll_begin_position().ToString());
1117 EXPECT_EQ(gfx::Rect(kPositionX
+ kScrollAmount
- radius
,
1118 kPositionY
+ kScrollAmount
- radius
,
1120 radius
* 2).ToString(),
1121 delegate
->bounding_box().ToString());
1123 // Release the touch. This should end the scroll.
1125 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1126 gfx::Point(kPositionX
+ kScrollAmount
,
1127 kPositionY
+ kScrollAmount
),
1128 kTouchId
, press
.time_stamp() +
1129 base::TimeDelta::FromMilliseconds(50));
1130 DispatchEventUsingWindowDispatcher(&release
);
1131 EXPECT_EQ(gfx::Rect(kPositionX
+ kScrollAmount
- radius
,
1132 kPositionY
+ kScrollAmount
- radius
,
1134 radius
* 2).ToString(),
1135 delegate
->bounding_box().ToString());
1137 ui::GestureConfiguration::set_default_radius(0);
1140 // Check Scroll End Events report correct velocities
1141 // if the user was on a horizontal rail
1142 TEST_F(GestureRecognizerTest
, GestureEventHorizontalRailFling
) {
1143 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1144 new GestureEventConsumeDelegate());
1146 const int kTouchId
= 7;
1147 gfx::Rect
bounds(0, 0, 1000, 1000);
1148 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1149 delegate
.get(), -1234, bounds
, root_window()));
1151 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1152 kTouchId
, tes
.Now());
1153 DispatchEventUsingWindowDispatcher(&press
);
1155 // Get rid of touch slop.
1156 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(10, 0),
1157 kTouchId
, tes
.Now());
1158 DispatchEventUsingWindowDispatcher(&move
);
1162 // Move the touch-point horizontally enough that it is considered a
1163 // horizontal scroll.
1164 tes
.SendScrollEvent(event_processor(), 30, 1, kTouchId
, delegate
.get());
1165 EXPECT_FLOAT_EQ(0, delegate
->scroll_y());
1166 EXPECT_FLOAT_EQ(20, delegate
->scroll_x());
1168 // Get a high x velocity, while still staying on the rail
1169 tes
.SendScrollEvents(event_processor(), 1, 1,
1170 100, 10, kTouchId
, 1,
1171 ui::GestureConfiguration::points_buffered_for_velocity(),
1175 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1176 kTouchId
, tes
.Now());
1177 DispatchEventUsingWindowDispatcher(&release
);
1179 EXPECT_TRUE(delegate
->fling());
1180 EXPECT_FALSE(delegate
->scroll_end());
1181 EXPECT_GT(delegate
->velocity_x(), 0);
1182 EXPECT_EQ(0, delegate
->velocity_y());
1185 // Check Scroll End Events report correct velocities
1186 // if the user was on a vertical rail
1187 TEST_F(GestureRecognizerTest
, GestureEventVerticalRailFling
) {
1188 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1189 new GestureEventConsumeDelegate());
1191 const int kTouchId
= 7;
1192 gfx::Rect
bounds(0, 0, 1000, 1000);
1193 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1194 delegate
.get(), -1234, bounds
, root_window()));
1196 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1197 kTouchId
, tes
.Now());
1198 DispatchEventUsingWindowDispatcher(&press
);
1200 // Get rid of touch slop.
1201 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(0, 10),
1202 kTouchId
, tes
.Now());
1203 DispatchEventUsingWindowDispatcher(&move
);
1206 // Move the touch-point vertically enough that it is considered a
1208 tes
.SendScrollEvent(event_processor(), 1, 30, kTouchId
, delegate
.get());
1209 EXPECT_EQ(20, delegate
->scroll_y());
1210 EXPECT_EQ(0, delegate
->scroll_x());
1211 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1213 // Get a high y velocity, while still staying on the rail
1214 tes
.SendScrollEvents(event_processor(), 1, 6,
1215 10, 100, kTouchId
, 1,
1216 ui::GestureConfiguration::points_buffered_for_velocity(),
1218 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1221 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 206),
1222 kTouchId
, tes
.Now());
1223 DispatchEventUsingWindowDispatcher(&release
);
1225 EXPECT_TRUE(delegate
->fling());
1226 EXPECT_FALSE(delegate
->scroll_end());
1227 EXPECT_EQ(0, delegate
->velocity_x());
1228 EXPECT_GT(delegate
->velocity_y(), 0);
1231 // Check Scroll End Events report non-zero velocities if the user is not on a
1233 TEST_F(GestureRecognizerTest
, GestureEventNonRailFling
) {
1234 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
1235 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1236 new GestureEventConsumeDelegate());
1238 const int kTouchId
= 7;
1239 gfx::Rect
bounds(0, 0, 1000, 1000);
1240 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1241 delegate
.get(), -1234, bounds
, root_window()));
1243 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1244 kTouchId
, tes
.Now());
1245 DispatchEventUsingWindowDispatcher(&press
);
1247 // Move the touch-point such that a non-rail scroll begins, and we're outside
1248 // the snap channel for the unified GR.
1249 tes
.SendScrollEvent(event_processor(), 50, 50, kTouchId
, delegate
.get());
1250 EXPECT_EQ(50, delegate
->scroll_y());
1251 EXPECT_EQ(50, delegate
->scroll_x());
1253 tes
.SendScrollEvents(event_processor(), 1, 1,
1254 10, 100, kTouchId
, 1,
1255 ui::GestureConfiguration::points_buffered_for_velocity(),
1259 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1260 kTouchId
, tes
.Now());
1261 DispatchEventUsingWindowDispatcher(&release
);
1263 EXPECT_TRUE(delegate
->fling());
1264 EXPECT_FALSE(delegate
->scroll_end());
1265 EXPECT_GT(delegate
->velocity_x(), 0);
1266 EXPECT_GT(delegate
->velocity_y(), 0);
1269 // Check that appropriate touch events generate long press events
1270 TEST_F(GestureRecognizerTest
, GestureEventLongPress
) {
1271 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1272 new GestureEventConsumeDelegate());
1273 const int kWindowWidth
= 123;
1274 const int kWindowHeight
= 45;
1275 const int kTouchId
= 2;
1276 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1277 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1278 delegate
.get(), -1234, bounds
, root_window()));
1282 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
1283 gfx::Point(101, 201),
1285 ui::EventTimeForNow());
1286 DispatchEventUsingWindowDispatcher(&press1
);
1287 EXPECT_TRUE(delegate
->tap_down());
1288 EXPECT_TRUE(delegate
->begin());
1289 EXPECT_FALSE(delegate
->tap_cancel());
1291 // We haven't pressed long enough for a long press to occur
1292 EXPECT_FALSE(delegate
->long_press());
1294 // Wait until the timer runs out
1295 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
1296 EXPECT_TRUE(delegate
->long_press());
1297 EXPECT_FALSE(delegate
->tap_cancel());
1300 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
,
1301 gfx::Point(101, 201),
1303 ui::EventTimeForNow());
1304 DispatchEventUsingWindowDispatcher(&release1
);
1305 EXPECT_FALSE(delegate
->long_press());
1307 // Note the tap cancel isn't dispatched until the release
1308 EXPECT_TRUE(delegate
->tap_cancel());
1309 EXPECT_FALSE(delegate
->tap());
1312 // Check that scrolling prevents a long press.
1313 TEST_F(GestureRecognizerTest
, GestureEventLongPressCancelledByScroll
) {
1314 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1315 new GestureEventConsumeDelegate());
1317 const int kWindowWidth
= 123;
1318 const int kWindowHeight
= 45;
1319 const int kTouchId
= 6;
1320 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1321 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1322 delegate
.get(), -1234, bounds
, root_window()));
1326 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1327 kTouchId
, tes
.Now());
1328 DispatchEventUsingWindowDispatcher(&press1
);
1329 EXPECT_TRUE(delegate
->tap_down());
1331 // We haven't pressed long enough for a long press to occur
1332 EXPECT_FALSE(delegate
->long_press());
1333 EXPECT_FALSE(delegate
->tap_cancel());
1335 // Scroll around, to cancel the long press
1336 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
1338 // Wait until a long press event would have fired, if it hadn't been
1340 DelayByLongPressTimeout();
1342 EXPECT_FALSE(delegate
->long_press());
1343 EXPECT_TRUE(delegate
->tap_cancel());
1346 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1347 kTouchId
, tes
.LeapForward(10));
1348 DispatchEventUsingWindowDispatcher(&release1
);
1349 EXPECT_FALSE(delegate
->long_press());
1350 EXPECT_FALSE(delegate
->tap_cancel());
1353 // Check that appropriate touch events generate long tap events
1354 TEST_F(GestureRecognizerTest
, GestureEventLongTap
) {
1355 ui::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click(
1357 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1358 new GestureEventConsumeDelegate());
1359 const int kWindowWidth
= 123;
1360 const int kWindowHeight
= 45;
1361 const int kTouchId
= 2;
1362 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1363 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1364 delegate
.get(), -1234, bounds
, root_window()));
1368 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
1369 gfx::Point(101, 201),
1371 ui::EventTimeForNow());
1372 DispatchEventUsingWindowDispatcher(&press1
);
1373 EXPECT_TRUE(delegate
->tap_down());
1374 EXPECT_TRUE(delegate
->begin());
1375 EXPECT_FALSE(delegate
->tap_cancel());
1377 // We haven't pressed long enough for a long press to occur
1378 EXPECT_FALSE(delegate
->long_press());
1380 // Wait until the timer runs out
1381 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
1382 EXPECT_TRUE(delegate
->long_press());
1383 EXPECT_FALSE(delegate
->tap_cancel());
1386 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
,
1387 gfx::Point(101, 201),
1389 ui::EventTimeForNow());
1390 DispatchEventUsingWindowDispatcher(&release1
);
1391 EXPECT_FALSE(delegate
->long_press());
1392 EXPECT_TRUE(delegate
->long_tap());
1394 // Note the tap cancel isn't dispatched until the release
1395 EXPECT_TRUE(delegate
->tap_cancel());
1396 EXPECT_FALSE(delegate
->tap());
1399 // Check that second tap cancels a long press
1400 TEST_F(GestureRecognizerTest
, GestureEventLongPressCancelledBySecondTap
) {
1401 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1402 new GestureEventConsumeDelegate());
1404 const int kWindowWidth
= 300;
1405 const int kWindowHeight
= 400;
1406 const int kTouchId1
= 8;
1407 const int kTouchId2
= 2;
1408 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
1409 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1410 delegate
.get(), -1234, bounds
, root_window()));
1413 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1414 kTouchId1
, tes
.Now());
1415 DispatchEventUsingWindowDispatcher(&press
);
1416 EXPECT_TRUE(delegate
->tap_down());
1417 EXPECT_TRUE(delegate
->begin());
1419 // We haven't pressed long enough for a long press to occur
1420 EXPECT_FALSE(delegate
->long_press());
1422 // Second tap, to cancel the long press
1424 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1425 kTouchId2
, tes
.Now());
1426 DispatchEventUsingWindowDispatcher(&press2
);
1427 EXPECT_FALSE(delegate
->tap_down()); // no touch down for second tap.
1428 EXPECT_TRUE(delegate
->tap_cancel());
1429 EXPECT_TRUE(delegate
->begin());
1431 // Wait until the timer runs out
1432 DelayByLongPressTimeout();
1434 // No long press occurred
1435 EXPECT_FALSE(delegate
->long_press());
1438 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1439 kTouchId1
, tes
.Now());
1440 DispatchEventUsingWindowDispatcher(&release1
);
1441 EXPECT_FALSE(delegate
->long_press());
1442 EXPECT_TRUE(delegate
->two_finger_tap());
1443 EXPECT_FALSE(delegate
->tap_cancel());
1446 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1447 // Also tests that horizontal rails can be broken.
1448 TEST_F(GestureRecognizerTest
, GestureEventHorizontalRailScroll
) {
1449 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1450 new GestureEventConsumeDelegate());
1452 const int kTouchId
= 7;
1453 gfx::Rect
bounds(0, 0, 1000, 1000);
1454 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1455 delegate
.get(), -1234, bounds
, root_window()));
1457 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1458 kTouchId
, tes
.Now());
1459 DispatchEventUsingWindowDispatcher(&press
);
1461 // Get rid of touch slop.
1462 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(5, 0),
1463 kTouchId
, tes
.Now());
1465 DispatchEventUsingWindowDispatcher(&move
);
1468 // Move the touch-point horizontally enough that it is considered a
1469 // horizontal scroll.
1470 tes
.SendScrollEvent(event_processor(), 25, 0, kTouchId
, delegate
.get());
1471 EXPECT_EQ(0, delegate
->scroll_y());
1472 EXPECT_EQ(20, delegate
->scroll_x());
1474 tes
.SendScrollEvent(event_processor(), 30, 6, kTouchId
, delegate
.get());
1475 EXPECT_TRUE(delegate
->scroll_update());
1476 EXPECT_EQ(5, delegate
->scroll_x());
1477 // y shouldn't change, as we're on a horizontal rail.
1478 EXPECT_EQ(0, delegate
->scroll_y());
1480 // Send enough information that a velocity can be calculated for the gesture,
1481 // and we can break the rail
1482 tes
.SendScrollEvents(event_processor(), 1, 1,
1483 6, 100, kTouchId
, 1,
1484 ui::GestureConfiguration::points_buffered_for_velocity(),
1487 tes
.SendScrollEvent(event_processor(), 5, 0, kTouchId
, delegate
.get());
1488 tes
.SendScrollEvent(event_processor(), 10, 5, kTouchId
, delegate
.get());
1490 // The rail should be broken
1491 EXPECT_TRUE(delegate
->scroll_update());
1492 EXPECT_EQ(5, delegate
->scroll_x());
1493 EXPECT_EQ(5, delegate
->scroll_y());
1496 // Check that vertical scroll gestures cause scrolls on vertical rails.
1497 // Also tests that vertical rails can be broken.
1498 TEST_F(GestureRecognizerTest
, GestureEventVerticalRailScroll
) {
1499 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1500 new GestureEventConsumeDelegate());
1502 const int kTouchId
= 7;
1503 gfx::Rect
bounds(0, 0, 1000, 1000);
1504 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1505 delegate
.get(), -1234, bounds
, root_window()));
1507 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1508 kTouchId
, tes
.Now());
1509 DispatchEventUsingWindowDispatcher(&press
);
1511 // Get rid of touch slop.
1512 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(0, 5),
1513 kTouchId
, tes
.Now());
1514 DispatchEventUsingWindowDispatcher(&move
);
1517 // Move the touch-point vertically enough that it is considered a
1519 tes
.SendScrollEvent(event_processor(), 0, 25, kTouchId
, delegate
.get());
1520 EXPECT_EQ(0, delegate
->scroll_x());
1521 EXPECT_EQ(20, delegate
->scroll_y());
1523 tes
.SendScrollEvent(event_processor(), 6, 30, kTouchId
, delegate
.get());
1524 EXPECT_TRUE(delegate
->scroll_update());
1525 EXPECT_EQ(5, delegate
->scroll_y());
1526 // x shouldn't change, as we're on a vertical rail.
1527 EXPECT_EQ(0, delegate
->scroll_x());
1528 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1530 // Send enough information that a velocity can be calculated for the gesture,
1531 // and we can break the rail
1532 tes
.SendScrollEvents(event_processor(), 1, 6,
1533 100, 1, kTouchId
, 1,
1534 ui::GestureConfiguration::points_buffered_for_velocity(),
1537 tes
.SendScrollEvent(event_processor(), 0, 5, kTouchId
, delegate
.get());
1538 tes
.SendScrollEvent(event_processor(), 5, 10, kTouchId
, delegate
.get());
1540 // The rail should be broken
1541 EXPECT_TRUE(delegate
->scroll_update());
1542 EXPECT_EQ(5, delegate
->scroll_x());
1543 EXPECT_EQ(5, delegate
->scroll_y());
1546 TEST_F(GestureRecognizerTest
, GestureTapFollowedByScroll
) {
1547 // We'll start by moving the touch point by (5, 5). We want all of that
1548 // distance to be consumed by the slop, so we set the slop radius to
1549 // sqrt(5 * 5 + 5 * 5).
1550 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1551 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1553 // First, tap. Then, do a scroll using the same touch-id.
1554 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1555 new GestureEventConsumeDelegate());
1557 const int kWindowWidth
= 123;
1558 const int kWindowHeight
= 45;
1559 const int kTouchId
= 3;
1560 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1561 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1562 delegate
.get(), -1234, bounds
, root_window()));
1565 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1566 kTouchId
, tes
.Now());
1567 DispatchEventUsingWindowDispatcher(&press
);
1568 EXPECT_FALSE(delegate
->tap());
1569 EXPECT_TRUE(delegate
->tap_down());
1570 EXPECT_FALSE(delegate
->tap_cancel());
1571 EXPECT_FALSE(delegate
->scroll_begin());
1572 EXPECT_FALSE(delegate
->scroll_update());
1573 EXPECT_FALSE(delegate
->scroll_end());
1575 // Make sure there is enough delay before the touch is released so that it is
1576 // recognized as a tap.
1578 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1579 kTouchId
, tes
.LeapForward(50));
1580 DispatchEventUsingWindowDispatcher(&release
);
1581 EXPECT_TRUE(delegate
->tap());
1582 EXPECT_FALSE(delegate
->tap_down());
1583 EXPECT_FALSE(delegate
->tap_cancel());
1584 EXPECT_FALSE(delegate
->scroll_begin());
1585 EXPECT_FALSE(delegate
->scroll_update());
1586 EXPECT_FALSE(delegate
->scroll_end());
1588 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger
1591 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1592 kTouchId
, tes
.LeapForward(1000));
1593 DispatchEventUsingWindowDispatcher(&press1
);
1594 EXPECT_FALSE(delegate
->tap());
1595 EXPECT_TRUE(delegate
->tap_down());
1596 EXPECT_FALSE(delegate
->tap_cancel());
1597 EXPECT_FALSE(delegate
->scroll_begin());
1598 EXPECT_FALSE(delegate
->scroll_update());
1599 EXPECT_FALSE(delegate
->scroll_end());
1601 // Get rid of touch slop.
1602 ui::TouchEvent
move_remove_slop(ui::ET_TOUCH_MOVED
, gfx::Point(116, 216),
1603 kTouchId
, tes
.Now());
1604 DispatchEventUsingWindowDispatcher(&move_remove_slop
);
1605 EXPECT_TRUE(delegate
->tap_cancel());
1606 EXPECT_TRUE(delegate
->scroll_begin());
1607 EXPECT_TRUE(delegate
->scroll_update());
1608 EXPECT_EQ(15, delegate
->scroll_x_hint());
1609 EXPECT_EQ(15, delegate
->scroll_y_hint());
1613 // Move the touch-point enough so that it is considered as a scroll. This
1614 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1615 // The first movement is diagonal, to ensure that we have a free scroll,
1616 // and not a rail scroll.
1618 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(135, 235),
1619 kTouchId
, tes
.Now());
1620 DispatchEventUsingWindowDispatcher(&move
);
1621 EXPECT_FALSE(delegate
->tap());
1622 EXPECT_FALSE(delegate
->tap_down());
1623 EXPECT_FALSE(delegate
->tap_cancel());
1624 EXPECT_FALSE(delegate
->scroll_begin());
1625 EXPECT_TRUE(delegate
->scroll_update());
1626 EXPECT_FALSE(delegate
->scroll_end());
1627 EXPECT_EQ(19, delegate
->scroll_x());
1628 EXPECT_EQ(19, delegate
->scroll_y());
1630 // Move some more to generate a few more scroll updates.
1632 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(115, 216),
1633 kTouchId
, tes
.Now());
1634 DispatchEventUsingWindowDispatcher(&move1
);
1635 EXPECT_FALSE(delegate
->tap());
1636 EXPECT_FALSE(delegate
->tap_down());
1637 EXPECT_FALSE(delegate
->tap_cancel());
1638 EXPECT_FALSE(delegate
->scroll_begin());
1639 EXPECT_TRUE(delegate
->scroll_update());
1640 EXPECT_FALSE(delegate
->scroll_end());
1641 EXPECT_EQ(-20, delegate
->scroll_x());
1642 EXPECT_EQ(-19, delegate
->scroll_y());
1643 EXPECT_EQ(0, delegate
->scroll_x_hint());
1644 EXPECT_EQ(0, delegate
->scroll_y_hint());
1647 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(145, 220),
1648 kTouchId
, tes
.Now());
1649 DispatchEventUsingWindowDispatcher(&move2
);
1650 EXPECT_FALSE(delegate
->tap());
1651 EXPECT_FALSE(delegate
->tap_down());
1652 EXPECT_FALSE(delegate
->tap_cancel());
1653 EXPECT_FALSE(delegate
->scroll_begin());
1654 EXPECT_TRUE(delegate
->scroll_update());
1655 EXPECT_FALSE(delegate
->scroll_end());
1656 EXPECT_EQ(30, delegate
->scroll_x());
1657 EXPECT_EQ(4, delegate
->scroll_y());
1659 // Release the touch. This should end the scroll.
1661 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1662 kTouchId
, tes
.Now());
1663 DispatchEventUsingWindowDispatcher(&release1
);
1664 EXPECT_FALSE(delegate
->tap());
1665 EXPECT_FALSE(delegate
->tap_down());
1666 EXPECT_FALSE(delegate
->tap_cancel());
1667 EXPECT_FALSE(delegate
->scroll_begin());
1668 EXPECT_FALSE(delegate
->scroll_update());
1669 EXPECT_FALSE(delegate
->scroll_end());
1670 EXPECT_TRUE(delegate
->fling());
1673 TEST_F(GestureRecognizerTest
, AsynchronousGestureRecognition
) {
1674 scoped_ptr
<QueueTouchEventDelegate
> queued_delegate(
1675 new QueueTouchEventDelegate(host()->dispatcher()));
1677 const int kWindowWidth
= 123;
1678 const int kWindowHeight
= 45;
1679 const int kTouchId1
= 6;
1680 const int kTouchId2
= 4;
1681 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1682 scoped_ptr
<aura::Window
> queue(CreateTestWindowWithDelegate(
1683 queued_delegate
.get(), -1234, bounds
, root_window()));
1685 queued_delegate
->set_window(queue
.get());
1687 // Touch down on the window. This should not generate any gesture event.
1688 queued_delegate
->Reset();
1689 ui::TouchEvent
press(
1690 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
1691 DispatchEventUsingWindowDispatcher(&press
);
1692 EXPECT_FALSE(queued_delegate
->tap());
1693 EXPECT_FALSE(queued_delegate
->tap_down());
1694 EXPECT_FALSE(queued_delegate
->tap_cancel());
1695 EXPECT_FALSE(queued_delegate
->begin());
1696 EXPECT_FALSE(queued_delegate
->scroll_begin());
1697 EXPECT_FALSE(queued_delegate
->scroll_update());
1698 EXPECT_FALSE(queued_delegate
->scroll_end());
1700 // Introduce some delay before the touch is released so that it is recognized
1701 // as a tap. However, this still should not create any gesture events.
1702 queued_delegate
->Reset();
1703 ui::TouchEvent
release(
1704 ui::ET_TOUCH_RELEASED
,
1705 gfx::Point(101, 201),
1707 press
.time_stamp() + base::TimeDelta::FromMilliseconds(50));
1708 DispatchEventUsingWindowDispatcher(&release
);
1709 EXPECT_FALSE(queued_delegate
->tap());
1710 EXPECT_FALSE(queued_delegate
->tap_down());
1711 EXPECT_FALSE(queued_delegate
->tap_cancel());
1712 EXPECT_FALSE(queued_delegate
->begin());
1713 EXPECT_FALSE(queued_delegate
->end());
1714 EXPECT_FALSE(queued_delegate
->scroll_begin());
1715 EXPECT_FALSE(queued_delegate
->scroll_update());
1716 EXPECT_FALSE(queued_delegate
->scroll_end());
1718 // Create another window, and place a touch-down on it. This should create a
1719 // tap-down gesture.
1720 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1721 new GestureEventConsumeDelegate());
1722 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1723 delegate
.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window()));
1725 ui::TouchEvent
press2(
1726 ui::ET_TOUCH_PRESSED
, gfx::Point(10, 20), kTouchId2
, tes
.Now());
1727 DispatchEventUsingWindowDispatcher(&press2
);
1728 EXPECT_FALSE(delegate
->tap());
1729 EXPECT_TRUE(delegate
->tap_down());
1730 EXPECT_FALSE(delegate
->tap_cancel());
1731 EXPECT_FALSE(queued_delegate
->begin());
1732 EXPECT_FALSE(queued_delegate
->end());
1733 EXPECT_FALSE(delegate
->scroll_begin());
1734 EXPECT_FALSE(delegate
->scroll_update());
1735 EXPECT_FALSE(delegate
->scroll_end());
1737 ui::TouchEvent
release2(
1738 ui::ET_TOUCH_RELEASED
, gfx::Point(10, 20), kTouchId2
, tes
.Now());
1739 DispatchEventUsingWindowDispatcher(&release2
);
1741 // Process the first queued event.
1742 queued_delegate
->Reset();
1743 queued_delegate
->ReceivedAck();
1744 EXPECT_FALSE(queued_delegate
->tap());
1745 EXPECT_TRUE(queued_delegate
->tap_down());
1746 EXPECT_TRUE(queued_delegate
->begin());
1747 EXPECT_FALSE(queued_delegate
->tap_cancel());
1748 EXPECT_FALSE(queued_delegate
->end());
1749 EXPECT_FALSE(queued_delegate
->scroll_begin());
1750 EXPECT_FALSE(queued_delegate
->scroll_update());
1751 EXPECT_FALSE(queued_delegate
->scroll_end());
1753 // Now, process the second queued event.
1754 queued_delegate
->Reset();
1755 queued_delegate
->ReceivedAck();
1756 EXPECT_TRUE(queued_delegate
->tap());
1757 EXPECT_FALSE(queued_delegate
->tap_down());
1758 EXPECT_FALSE(queued_delegate
->tap_cancel());
1759 EXPECT_FALSE(queued_delegate
->begin());
1760 EXPECT_TRUE(queued_delegate
->end());
1761 EXPECT_FALSE(queued_delegate
->scroll_begin());
1762 EXPECT_FALSE(queued_delegate
->scroll_update());
1763 EXPECT_FALSE(queued_delegate
->scroll_end());
1765 // Start all over. Press on the first window, then press again on the second
1766 // window. The second press should still go to the first window.
1767 queued_delegate
->Reset();
1768 ui::TouchEvent
press3(
1769 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
1770 DispatchEventUsingWindowDispatcher(&press3
);
1771 EXPECT_FALSE(queued_delegate
->tap());
1772 EXPECT_FALSE(queued_delegate
->tap_down());
1773 EXPECT_FALSE(queued_delegate
->tap_cancel());
1774 EXPECT_FALSE(queued_delegate
->begin());
1775 EXPECT_FALSE(queued_delegate
->end());
1776 EXPECT_FALSE(queued_delegate
->begin());
1777 EXPECT_FALSE(queued_delegate
->end());
1778 EXPECT_FALSE(queued_delegate
->scroll_begin());
1779 EXPECT_FALSE(queued_delegate
->scroll_update());
1780 EXPECT_FALSE(queued_delegate
->scroll_end());
1782 queued_delegate
->Reset();
1784 ui::TouchEvent
press4(
1785 ui::ET_TOUCH_PRESSED
, gfx::Point(103, 203), kTouchId2
, tes
.Now());
1786 DispatchEventUsingWindowDispatcher(&press4
);
1787 EXPECT_FALSE(delegate
->tap());
1788 EXPECT_FALSE(delegate
->tap_down());
1789 EXPECT_FALSE(delegate
->tap_cancel());
1790 EXPECT_FALSE(delegate
->begin());
1791 EXPECT_FALSE(delegate
->end());
1792 EXPECT_FALSE(delegate
->scroll_begin());
1793 EXPECT_FALSE(delegate
->scroll_update());
1794 EXPECT_FALSE(delegate
->scroll_end());
1795 EXPECT_FALSE(queued_delegate
->tap());
1796 EXPECT_FALSE(queued_delegate
->tap_down());
1797 EXPECT_FALSE(queued_delegate
->tap_cancel());
1798 EXPECT_FALSE(queued_delegate
->begin());
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 // Move the second touch-point enough so that it is considered a pinch. This
1805 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures.
1806 queued_delegate
->Reset();
1808 int x_move
= ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
1809 ui::TouchEvent
move(
1810 ui::ET_TOUCH_MOVED
, gfx::Point(203 + x_move
, 303), kTouchId2
, tes
.Now());
1811 DispatchEventUsingWindowDispatcher(&move
);
1812 EXPECT_FALSE(delegate
->tap());
1813 EXPECT_FALSE(delegate
->tap_down());
1814 EXPECT_FALSE(delegate
->tap_cancel());
1815 EXPECT_FALSE(delegate
->begin());
1816 EXPECT_FALSE(delegate
->scroll_begin());
1817 EXPECT_FALSE(delegate
->scroll_update());
1818 EXPECT_FALSE(delegate
->scroll_end());
1819 EXPECT_FALSE(queued_delegate
->tap());
1820 EXPECT_FALSE(queued_delegate
->tap_down());
1821 EXPECT_FALSE(queued_delegate
->tap_cancel());
1822 EXPECT_FALSE(queued_delegate
->begin());
1823 EXPECT_FALSE(queued_delegate
->scroll_begin());
1824 EXPECT_FALSE(queued_delegate
->scroll_update());
1825 EXPECT_FALSE(queued_delegate
->scroll_end());
1827 queued_delegate
->Reset();
1828 queued_delegate
->ReceivedAck();
1829 EXPECT_FALSE(queued_delegate
->tap());
1830 EXPECT_TRUE(queued_delegate
->tap_down());
1831 EXPECT_TRUE(queued_delegate
->begin());
1832 EXPECT_FALSE(queued_delegate
->tap_cancel());
1833 EXPECT_FALSE(queued_delegate
->end());
1834 EXPECT_FALSE(queued_delegate
->scroll_begin());
1835 EXPECT_FALSE(queued_delegate
->scroll_update());
1836 EXPECT_FALSE(queued_delegate
->scroll_end());
1838 queued_delegate
->Reset();
1839 queued_delegate
->ReceivedAck();
1840 EXPECT_FALSE(queued_delegate
->tap());
1841 EXPECT_FALSE(queued_delegate
->tap_down()); // no touch down for second tap.
1842 EXPECT_TRUE(queued_delegate
->tap_cancel());
1843 EXPECT_TRUE(queued_delegate
->begin());
1844 EXPECT_FALSE(queued_delegate
->end());
1845 EXPECT_FALSE(queued_delegate
->scroll_begin());
1846 EXPECT_FALSE(queued_delegate
->scroll_update());
1847 EXPECT_FALSE(queued_delegate
->scroll_end());
1848 EXPECT_FALSE(queued_delegate
->pinch_begin());
1849 EXPECT_FALSE(queued_delegate
->pinch_update());
1850 EXPECT_FALSE(queued_delegate
->pinch_end());
1852 queued_delegate
->Reset();
1853 queued_delegate
->ReceivedAck();
1854 EXPECT_FALSE(queued_delegate
->tap());
1855 EXPECT_FALSE(queued_delegate
->tap_down());
1856 EXPECT_FALSE(queued_delegate
->tap_cancel());
1857 EXPECT_FALSE(queued_delegate
->begin());
1858 EXPECT_FALSE(queued_delegate
->end());
1859 EXPECT_TRUE(queued_delegate
->scroll_begin());
1861 EXPECT_TRUE(queued_delegate
->scroll_update());
1862 EXPECT_FALSE(queued_delegate
->scroll_end());
1863 EXPECT_TRUE(queued_delegate
->pinch_begin());
1864 EXPECT_FALSE(queued_delegate
->pinch_update());
1865 EXPECT_FALSE(queued_delegate
->pinch_end());
1868 // Check that appropriate touch events generate pinch gesture events.
1869 TEST_F(GestureRecognizerTest
, GestureEventPinchFromScroll
) {
1870 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1871 new GestureEventConsumeDelegate());
1873 const int kWindowWidth
= 300;
1874 const int kWindowHeight
= 400;
1875 const int kTouchId1
= 5;
1876 const int kTouchId2
= 3;
1877 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
1878 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1879 delegate
.get(), -1234, bounds
, root_window()));
1882 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1883 kTouchId1
, tes
.Now());
1884 DispatchEventUsingWindowDispatcher(&press
);
1885 EXPECT_2_EVENTS(delegate
->events(),
1886 ui::ET_GESTURE_BEGIN
,
1887 ui::ET_GESTURE_TAP_DOWN
);
1889 // Move the touch-point enough so that it is considered as a scroll. This
1890 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1892 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(130, 301),
1893 kTouchId1
, tes
.Now());
1894 DispatchEventUsingWindowDispatcher(&move
);
1895 EXPECT_3_EVENTS(delegate
->events(),
1896 ui::ET_GESTURE_TAP_CANCEL
,
1897 ui::ET_GESTURE_SCROLL_BEGIN
,
1898 ui::ET_GESTURE_SCROLL_UPDATE
);
1900 // Press the second finger. It should cause pinch-begin. Note that we will not
1901 // transition to two finger tap here because the touch points are far enough.
1903 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1904 kTouchId2
, tes
.Now());
1905 DispatchEventUsingWindowDispatcher(&press2
);
1906 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_BEGIN
);
1907 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(),
1908 delegate
->bounding_box().ToString());
1910 // Move the first finger.
1912 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(95, 201),
1913 kTouchId1
, tes
.Now());
1914 DispatchEventUsingWindowDispatcher(&move3
);
1915 EXPECT_2_EVENTS(delegate
->events(),
1916 ui::ET_GESTURE_SCROLL_UPDATE
,
1917 ui::ET_GESTURE_PINCH_BEGIN
);
1918 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(),
1919 delegate
->bounding_box().ToString());
1921 // Now move the second finger.
1923 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(55, 15),
1924 kTouchId2
, tes
.Now());
1925 DispatchEventUsingWindowDispatcher(&move4
);
1926 EXPECT_2_EVENTS(delegate
->events(),
1927 ui::ET_GESTURE_SCROLL_UPDATE
,
1928 ui::ET_GESTURE_PINCH_UPDATE
);
1929 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(),
1930 delegate
->bounding_box().ToString());
1932 // Release the first finger. This should end pinch.
1934 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1935 kTouchId1
, tes
.Now());
1936 DispatchEventUsingWindowDispatcher(&release
);
1937 EXPECT_2_EVENTS(delegate
->events(),
1938 ui::ET_GESTURE_PINCH_END
,
1939 ui::ET_GESTURE_END
);
1940 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
1941 delegate
->bounding_box().ToString());
1943 // Move the second finger. This should still generate a scroll.
1945 ui::TouchEvent
move5(ui::ET_TOUCH_MOVED
, gfx::Point(25, 10),
1946 kTouchId2
, tes
.Now());
1947 DispatchEventUsingWindowDispatcher(&move5
);
1948 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1949 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1952 TEST_F(GestureRecognizerTest
, GestureEventPinchFromScrollFromPinch
) {
1953 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1954 new GestureEventConsumeDelegate());
1956 const int kWindowWidth
= 300;
1957 const int kWindowHeight
= 400;
1958 const int kTouchId1
= 5;
1959 const int kTouchId2
= 3;
1960 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
1961 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1962 delegate
.get(), -1234, bounds
, root_window()));
1964 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
1965 kTouchId1
, tes
.Now());
1966 DispatchEventUsingWindowDispatcher(&press
);
1968 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1969 kTouchId2
, tes
.Now());
1970 DispatchEventUsingWindowDispatcher(&press2
);
1971 EXPECT_FALSE(delegate
->pinch_begin());
1973 // Touch move triggers pinch begin.
1974 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId1
, delegate
.get());
1975 EXPECT_TRUE(delegate
->pinch_begin());
1976 EXPECT_FALSE(delegate
->pinch_update());
1978 // Touch move triggers pinch update.
1979 tes
.SendScrollEvent(event_processor(), 160, 200, kTouchId1
, delegate
.get());
1980 EXPECT_FALSE(delegate
->pinch_begin());
1981 EXPECT_TRUE(delegate
->pinch_update());
1983 // Pinch has started, now release the second finger
1985 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1986 kTouchId1
, tes
.Now());
1987 DispatchEventUsingWindowDispatcher(&release
);
1988 EXPECT_TRUE(delegate
->pinch_end());
1990 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId2
, delegate
.get());
1991 EXPECT_TRUE(delegate
->scroll_update());
1995 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1996 kTouchId1
, tes
.Now());
1997 DispatchEventUsingWindowDispatcher(&press3
);
1998 // Now the touch points are close. So we will go into two finger tap.
1999 // Move the touch-point enough to break two-finger-tap and enter pinch.
2000 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(101, 50),
2001 kTouchId1
, tes
.Now());
2002 DispatchEventUsingWindowDispatcher(&move2
);
2003 EXPECT_TRUE(delegate
->pinch_begin());
2005 tes
.SendScrollEvent(event_processor(), 350, 350, kTouchId1
, delegate
.get());
2006 EXPECT_TRUE(delegate
->pinch_update());
2009 TEST_F(GestureRecognizerTest
, GestureEventPinchFromTap
) {
2010 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2011 new GestureEventConsumeDelegate());
2013 const int kWindowWidth
= 300;
2014 const int kWindowHeight
= 400;
2015 const int kTouchId1
= 3;
2016 const int kTouchId2
= 5;
2017 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
2018 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2019 delegate
.get(), -1234, bounds
, root_window()));
2022 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
2023 kTouchId1
, tes
.Now());
2024 DispatchEventUsingWindowDispatcher(&press
);
2025 EXPECT_2_EVENTS(delegate
->events(),
2026 ui::ET_GESTURE_BEGIN
,
2027 ui::ET_GESTURE_TAP_DOWN
);
2028 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2030 // Press the second finger far enough to break two finger tap.
2032 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2033 kTouchId2
, tes
.Now());
2034 DispatchEventUsingWindowDispatcher(&press2
);
2035 EXPECT_2_EVENTS(delegate
->events(),
2036 ui::ET_GESTURE_TAP_CANCEL
,
2037 ui::ET_GESTURE_BEGIN
);
2038 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(),
2039 delegate
->bounding_box().ToString());
2041 // Move the first finger.
2043 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
2044 kTouchId1
, tes
.Now());
2045 DispatchEventUsingWindowDispatcher(&move3
);
2046 EXPECT_3_EVENTS(delegate
->events(),
2047 ui::ET_GESTURE_SCROLL_BEGIN
,
2048 ui::ET_GESTURE_SCROLL_UPDATE
,
2049 ui::ET_GESTURE_PINCH_BEGIN
);
2050 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(),
2051 delegate
->bounding_box().ToString());
2053 // Now move the second finger.
2055 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(55, 15),
2056 kTouchId2
, tes
.Now());
2057 DispatchEventUsingWindowDispatcher(&move4
);
2058 EXPECT_2_EVENTS(delegate
->events(),
2059 ui::ET_GESTURE_SCROLL_UPDATE
,
2060 ui::ET_GESTURE_PINCH_UPDATE
);
2061 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(),
2062 delegate
->bounding_box().ToString());
2064 // Release the first finger. This should end pinch.
2066 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2067 kTouchId1
, tes
.LeapForward(10));
2068 DispatchEventUsingWindowDispatcher(&release
);
2069 EXPECT_2_EVENTS(delegate
->events(),
2070 ui::ET_GESTURE_PINCH_END
,
2071 ui::ET_GESTURE_END
);
2072 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
2073 delegate
->bounding_box().ToString());
2075 // Move the second finger. This should still generate a scroll.
2077 ui::TouchEvent
move5(ui::ET_TOUCH_MOVED
, gfx::Point(25, 10),
2078 kTouchId2
, tes
.Now());
2079 DispatchEventUsingWindowDispatcher(&move5
);
2080 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
2081 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2084 TEST_F(GestureRecognizerTest
, GestureEventIgnoresDisconnectedEvents
) {
2085 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2086 new GestureEventConsumeDelegate());
2089 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2091 DispatchEventUsingWindowDispatcher(&release1
);
2092 EXPECT_FALSE(delegate
->tap());
2093 EXPECT_FALSE(delegate
->tap_down());
2096 // Check that a touch is locked to the window of the closest current touch
2097 // within max_separation_for_gesture_touches_in_pixels
2098 TEST_F(GestureRecognizerTest
, GestureEventTouchLockSelectsCorrectWindow
) {
2099 ui::GestureRecognizer
* gesture_recognizer
= new ui::GestureRecognizerImpl();
2101 ScopedGestureRecognizerSetter
gr_setter(gesture_recognizer
);
2103 ui::GestureConsumer
* target
;
2104 const int kNumWindows
= 4;
2106 scoped_ptr
<GestureEventConsumeDelegate
*[]> delegates(
2107 new GestureEventConsumeDelegate
*[kNumWindows
]);
2109 ui::GestureConfiguration::
2110 set_max_separation_for_gesture_touches_in_pixels(499);
2112 scoped_ptr
<gfx::Rect
[]> window_bounds(new gfx::Rect
[kNumWindows
]);
2113 window_bounds
[0] = gfx::Rect(0, 0, 1, 1);
2114 window_bounds
[1] = gfx::Rect(500, 0, 1, 1);
2115 window_bounds
[2] = gfx::Rect(0, 500, 1, 1);
2116 window_bounds
[3] = gfx::Rect(500, 500, 1, 1);
2118 scoped_ptr
<aura::Window
*[]> windows(new aura::Window
*[kNumWindows
]);
2120 // Instantiate windows with |window_bounds| and touch each window at
2122 for (int i
= 0; i
< kNumWindows
; ++i
) {
2123 delegates
[i
] = new GestureEventConsumeDelegate();
2124 windows
[i
] = CreateTestWindowWithDelegate(
2125 delegates
[i
], i
, window_bounds
[i
], root_window());
2126 windows
[i
]->set_id(i
);
2127 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, window_bounds
[i
].origin(),
2129 DispatchEventUsingWindowDispatcher(&press
);
2132 // Touches should now be associated with the closest touch within
2133 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels
2134 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(11, 11), -1);
2135 EXPECT_EQ("0", WindowIDAsString(target
));
2136 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(511, 11), -1);
2137 EXPECT_EQ("1", WindowIDAsString(target
));
2138 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(11, 511), -1);
2139 EXPECT_EQ("2", WindowIDAsString(target
));
2140 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(511, 511), -1);
2141 EXPECT_EQ("3", WindowIDAsString(target
));
2143 // Add a touch in the middle associated with windows[2]
2144 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 500),
2145 kNumWindows
, tes
.Now());
2146 DispatchEventUsingWindowDispatcher(&press
);
2147 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(250, 250),
2148 kNumWindows
, tes
.Now());
2149 DispatchEventUsingWindowDispatcher(&move
);
2151 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(250, 250), -1);
2152 EXPECT_EQ("2", WindowIDAsString(target
));
2154 // Make sure that ties are broken by distance to a current touch
2155 // Closer to the point in the bottom right.
2156 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(380, 380), -1);
2157 EXPECT_EQ("3", WindowIDAsString(target
));
2159 // This touch is closer to the point in the middle
2160 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(300, 300), -1);
2161 EXPECT_EQ("2", WindowIDAsString(target
));
2163 // A touch too far from other touches won't be locked to anything
2164 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2165 EXPECT_TRUE(target
== NULL
);
2167 // Move a touch associated with windows[2] to 1000, 1000
2168 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(1000, 1000),
2169 kNumWindows
, tes
.Now());
2170 DispatchEventUsingWindowDispatcher(&move2
);
2172 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2173 EXPECT_EQ("2", WindowIDAsString(target
));
2175 for (int i
= 0; i
< kNumWindows
; ++i
) {
2176 // Delete windows before deleting delegates.
2178 delete delegates
[i
];
2182 // Check that a touch's target will not be effected by a touch on a different
2184 TEST_F(GestureRecognizerTest
, GestureEventTouchLockIgnoresOtherScreens
) {
2185 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2186 new GestureEventConsumeDelegate());
2187 gfx::Rect
bounds(0, 0, 10, 10);
2188 scoped_ptr
<aura::Window
> window(
2189 CreateTestWindowWithDelegate(delegate
.get(), 0, bounds
, root_window()));
2191 const int kTouchId1
= 8;
2192 const int kTouchId2
= 2;
2195 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(5, 5),
2196 kTouchId1
, tes
.Now());
2197 ui::EventTestApi
test_press1(&press1
);
2198 test_press1
.set_source_device_id(1);
2199 DispatchEventUsingWindowDispatcher(&press1
);
2201 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20),
2202 kTouchId2
, tes
.Now());
2203 ui::EventTestApi
test_press2(&press2
);
2204 test_press2
.set_source_device_id(2);
2205 DispatchEventUsingWindowDispatcher(&press2
);
2207 // The second press should not have been locked to the same target as the
2208 // first, as they occured on different displays.
2210 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
),
2211 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
));
2214 // Check that touch events outside the root window are still handled
2215 // by the root window's gesture sequence.
2216 TEST_F(GestureRecognizerTest
, GestureEventOutsideRootWindowTap
) {
2218 scoped_ptr
<aura::Window
> window(CreateTestWindowWithBounds(
2219 gfx::Rect(-100, -100, 2000, 2000), root_window()));
2221 gfx::Point
pos1(-10, -10);
2222 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, pos1
, 0, tes
.Now());
2223 DispatchEventUsingWindowDispatcher(&press1
);
2225 gfx::Point
pos2(1000, 1000);
2226 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, pos2
, 1, tes
.Now());
2227 DispatchEventUsingWindowDispatcher(&press2
);
2229 // As these presses were outside the root window, they should be
2230 // associated with the root window.
2231 EXPECT_EQ(root_window(),
2232 static_cast<aura::Window
*>(
2233 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
)));
2234 EXPECT_EQ(root_window(),
2235 static_cast<aura::Window
*>(
2236 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
)));
2239 TEST_F(GestureRecognizerTest
, NoTapWithPreventDefaultedRelease
) {
2240 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2241 new QueueTouchEventDelegate(host()->dispatcher()));
2243 const int kTouchId
= 2;
2244 gfx::Rect
bounds(100, 200, 100, 100);
2245 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2246 delegate
.get(), -1234, bounds
, root_window()));
2247 delegate
->set_window(window
.get());
2250 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2251 kTouchId
, tes
.Now());
2252 DispatchEventUsingWindowDispatcher(&press
);
2253 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2254 kTouchId
, tes
.LeapForward(50));
2255 DispatchEventUsingWindowDispatcher(&release
);
2258 delegate
->ReceivedAck();
2259 EXPECT_TRUE(delegate
->tap_down());
2261 delegate
->ReceivedAckPreventDefaulted();
2262 EXPECT_FALSE(delegate
->tap());
2263 EXPECT_TRUE(delegate
->tap_cancel());
2266 TEST_F(GestureRecognizerTest
, PinchScrollWithPreventDefaultedRelease
) {
2267 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2268 new QueueTouchEventDelegate(host()->dispatcher()));
2270 const int kTouchId1
= 7;
2271 const int kTouchId2
= 5;
2272 gfx::Rect
bounds(10, 20, 100, 100);
2273 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2274 delegate
.get(), -1234, bounds
, root_window()));
2275 delegate
->set_window(window
.get());
2279 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(15, 25), kTouchId1
,
2281 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(20, 95), kTouchId1
,
2282 tes
.LeapForward(200));
2283 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(15, 25), kTouchId1
,
2284 tes
.LeapForward(50));
2285 DispatchEventUsingWindowDispatcher(&press
);
2286 DispatchEventUsingWindowDispatcher(&move
);
2287 DispatchEventUsingWindowDispatcher(&release
);
2290 // Ack the press event.
2291 delegate
->ReceivedAck();
2293 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2296 // Ack the move event.
2297 delegate
->ReceivedAck();
2298 EXPECT_3_EVENTS(delegate
->events(),
2299 ui::ET_GESTURE_TAP_CANCEL
,
2300 ui::ET_GESTURE_SCROLL_BEGIN
,
2301 ui::ET_GESTURE_SCROLL_UPDATE
);
2304 // Ack the release event. Although the release event has been processed, it
2305 // should still generate a scroll-end event.
2306 delegate
->ReceivedAckPreventDefaulted();
2308 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2311 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(15, 25), kTouchId1
,
2313 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(20, 95), kTouchId1
,
2314 tes
.LeapForward(200));
2315 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(15, 25), kTouchId1
,
2316 tes
.LeapForward(50));
2317 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(55, 25), kTouchId2
,
2319 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(145, 85), kTouchId2
,
2320 tes
.LeapForward(1000));
2321 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(145, 85), kTouchId2
,
2322 tes
.LeapForward(14));
2325 DispatchEventUsingWindowDispatcher(&press
);
2326 DispatchEventUsingWindowDispatcher(&move
);
2327 DispatchEventUsingWindowDispatcher(&press2
);
2328 DispatchEventUsingWindowDispatcher(&move2
);
2329 DispatchEventUsingWindowDispatcher(&release
);
2330 DispatchEventUsingWindowDispatcher(&release2
);
2332 // Ack the press and move events.
2334 delegate
->ReceivedAck();
2336 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2339 delegate
->ReceivedAck();
2340 EXPECT_3_EVENTS(delegate
->events(),
2341 ui::ET_GESTURE_TAP_CANCEL
,
2342 ui::ET_GESTURE_SCROLL_BEGIN
,
2343 ui::ET_GESTURE_SCROLL_UPDATE
);
2346 delegate
->ReceivedAck();
2347 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_BEGIN
);
2350 delegate
->ReceivedAck();
2351 EXPECT_2_EVENTS(delegate
->events(),
2352 ui::ET_GESTURE_SCROLL_UPDATE
,
2353 ui::ET_GESTURE_PINCH_BEGIN
);
2355 // Ack the first release. Although the release is processed, it should still
2356 // generate a pinch-end event.
2358 delegate
->ReceivedAckPreventDefaulted();
2360 delegate
->events(), ui::ET_GESTURE_PINCH_END
, ui::ET_GESTURE_END
);
2363 delegate
->ReceivedAckPreventDefaulted();
2365 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2368 TEST_F(GestureRecognizerTest
, GestureEndLocation
) {
2369 GestureEventConsumeDelegate delegate
;
2370 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2371 &delegate
, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2372 ui::test::EventGenerator
generator(root_window(), window
.get());
2373 const gfx::Point
begin(20, 20);
2374 const gfx::Point
end(150, 150);
2375 const gfx::Vector2d window_offset
=
2376 window
->bounds().origin().OffsetFromOrigin();
2377 generator
.GestureScrollSequence(begin
, end
,
2378 base::TimeDelta::FromMilliseconds(20),
2380 EXPECT_EQ((begin
- window_offset
).ToString(),
2381 delegate
.scroll_begin_position().ToString());
2382 EXPECT_EQ((end
- window_offset
).ToString(),
2383 delegate
.gesture_end_location().ToString());
2386 TEST_F(GestureRecognizerTest
, CaptureSendsGestureEnd
) {
2387 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2388 new GestureEventConsumeDelegate());
2389 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2390 delegate
.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2391 ui::test::EventGenerator
generator(root_window());
2393 generator
.MoveMouseRelativeTo(window
.get(), gfx::Point(10, 10));
2394 generator
.PressTouch();
2395 RunAllPendingInMessageLoop();
2397 EXPECT_TRUE(delegate
->tap_down());
2399 scoped_ptr
<aura::Window
> capture(CreateTestWindowWithBounds(
2400 gfx::Rect(10, 10, 200, 200), root_window()));
2401 capture
->SetCapture();
2402 RunAllPendingInMessageLoop();
2404 EXPECT_TRUE(delegate
->end());
2405 EXPECT_TRUE(delegate
->tap_cancel());
2408 // Check that previous touch actions that are completely finished (either
2409 // released or cancelled), do not receive extra synthetic cancels upon change of
2411 TEST_F(GestureRecognizerTest
, CaptureDoesNotCancelFinishedTouches
) {
2412 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2413 new GestureEventConsumeDelegate());
2414 scoped_ptr
<TestEventHandler
> handler(new TestEventHandler
);
2415 root_window()->AddPreTargetHandler(handler
.get());
2417 // Create a window and set it as the capture window.
2418 scoped_ptr
<aura::Window
> window1(CreateTestWindowWithDelegate(delegate
.get(),
2419 -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2420 window1
->SetCapture();
2422 ui::test::EventGenerator
generator(root_window());
2425 // Generate two touch-press events on the window.
2426 scoped_ptr
<ui::TouchEvent
> touch0(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
2427 gfx::Point(20, 20), 0,
2429 scoped_ptr
<ui::TouchEvent
> touch1(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
2430 gfx::Point(30, 30), 1,
2432 generator
.Dispatch(touch0
.get());
2433 generator
.Dispatch(touch1
.get());
2434 RunAllPendingInMessageLoop();
2435 EXPECT_EQ(2, handler
->touch_pressed_count());
2438 tes
.LeapForward(1000);
2440 // End the two touches, one by a touch-release and one by a touch-cancel; to
2441 // cover both cases.
2442 touch0
.reset(new ui::TouchEvent(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
2444 touch1
.reset(new ui::TouchEvent(ui::ET_TOUCH_CANCELLED
, gfx::Point(30, 30), 1,
2446 generator
.Dispatch(touch0
.get());
2447 generator
.Dispatch(touch1
.get());
2448 RunAllPendingInMessageLoop();
2449 EXPECT_EQ(1, handler
->touch_released_count());
2450 EXPECT_EQ(1, handler
->touch_cancelled_count());
2452 // Create a new window and set it as the new capture window.
2453 scoped_ptr
<aura::Window
> window2(CreateTestWindowWithBounds(
2454 gfx::Rect(100, 100, 300, 300), root_window()));
2455 window2
->SetCapture();
2456 RunAllPendingInMessageLoop();
2457 // Check that setting capture does not generate any synthetic touch-cancels
2458 // for the two previously finished touch actions.
2459 EXPECT_EQ(1, handler
->touch_cancelled_count());
2461 root_window()->RemovePreTargetHandler(handler
.get());
2464 // Tests that a press with the same touch id as an existing touch is ignored.
2465 TEST_F(GestureRecognizerTest
, PressDoesNotCrash
) {
2466 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2467 new GestureEventConsumeDelegate());
2470 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2471 delegate
.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2473 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(45, 45), 7, tes
.Now());
2474 press
.set_radius_x(40);
2475 DispatchEventUsingWindowDispatcher(&press
);
2476 EXPECT_TRUE(delegate
->tap_down());
2477 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(),
2478 delegate
->bounding_box().ToString());
2481 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(55, 45), 7, tes
.Now());
2482 DispatchEventUsingWindowDispatcher(&press2
);
2484 // This new press should not generate a tap-down.
2485 EXPECT_FALSE(delegate
->begin());
2486 EXPECT_FALSE(delegate
->tap_down());
2487 EXPECT_FALSE(delegate
->tap_cancel());
2488 EXPECT_FALSE(delegate
->scroll_begin());
2491 TEST_F(GestureRecognizerTest
, TwoFingerTap
) {
2492 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2493 new GestureEventConsumeDelegate());
2494 const int kWindowWidth
= 123;
2495 const int kWindowHeight
= 45;
2496 const int kTouchId1
= 2;
2497 const int kTouchId2
= 3;
2498 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2499 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2500 delegate
.get(), -1234, bounds
, root_window()));
2504 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2505 kTouchId1
, tes
.Now());
2506 DispatchEventUsingWindowDispatcher(&press1
);
2508 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2511 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2512 kTouchId2
, tes
.Now());
2513 DispatchEventUsingWindowDispatcher(&press2
);
2515 delegate
->events(), ui::ET_GESTURE_TAP_CANCEL
, ui::ET_GESTURE_BEGIN
);
2517 // Little bit of touch move should not affect our state.
2519 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(102, 202),
2520 kTouchId1
, tes
.Now());
2521 DispatchEventUsingWindowDispatcher(&move1
);
2522 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(131, 202),
2523 kTouchId2
, tes
.Now());
2524 DispatchEventUsingWindowDispatcher(&move2
);
2525 EXPECT_2_EVENTS(delegate
->events(),
2526 ui::ET_GESTURE_SCROLL_BEGIN
,
2527 ui::ET_GESTURE_SCROLL_UPDATE
);
2529 // Make sure there is enough delay before the touch is released so that it is
2530 // recognized as a tap.
2532 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2533 kTouchId1
, tes
.LeapForward(50));
2535 DispatchEventUsingWindowDispatcher(&release1
);
2537 delegate
->events(), ui::ET_GESTURE_TWO_FINGER_TAP
, ui::ET_GESTURE_END
);
2539 // Lift second finger.
2540 // Make sure there is enough delay before the touch is released so that it is
2541 // recognized as a tap.
2543 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
2544 kTouchId2
, tes
.LeapForward(50));
2546 DispatchEventUsingWindowDispatcher(&release2
);
2548 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2551 TEST_F(GestureRecognizerTest
, TwoFingerTapExpired
) {
2552 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2553 new GestureEventConsumeDelegate());
2554 const int kWindowWidth
= 123;
2555 const int kWindowHeight
= 45;
2556 const int kTouchId1
= 2;
2557 const int kTouchId2
= 3;
2558 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2559 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2560 delegate
.get(), -1234, bounds
, root_window()));
2564 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2565 kTouchId1
, tes
.Now());
2566 DispatchEventUsingWindowDispatcher(&press1
);
2569 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2570 kTouchId2
, tes
.Now());
2571 DispatchEventUsingWindowDispatcher(&press2
);
2573 // Send release event after sufficient delay so that two finger time expires.
2575 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2576 kTouchId1
, tes
.LeapForward(1000));
2578 DispatchEventUsingWindowDispatcher(&release1
);
2579 EXPECT_FALSE(delegate
->two_finger_tap());
2581 // Lift second finger.
2582 // Make sure there is enough delay before the touch is released so that it is
2583 // recognized as a tap.
2585 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
2586 kTouchId2
, tes
.LeapForward(50));
2588 DispatchEventUsingWindowDispatcher(&release2
);
2589 EXPECT_FALSE(delegate
->two_finger_tap());
2592 TEST_F(GestureRecognizerTest
, TwoFingerTapChangesToPinch
) {
2593 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2594 new GestureEventConsumeDelegate());
2595 const int kWindowWidth
= 123;
2596 const int kWindowHeight
= 45;
2597 const int kTouchId1
= 2;
2598 const int kTouchId2
= 3;
2601 // Test moving first finger
2603 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2604 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2605 delegate
.get(), -1234, bounds
, root_window()));
2608 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2609 kTouchId1
, tes
.Now());
2610 DispatchEventUsingWindowDispatcher(&press1
);
2613 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2614 kTouchId2
, tes
.Now());
2615 DispatchEventUsingWindowDispatcher(&press2
);
2617 tes
.SendScrollEvent(event_processor(), 230, 330, kTouchId1
, delegate
.get());
2618 EXPECT_FALSE(delegate
->two_finger_tap());
2619 EXPECT_TRUE(delegate
->pinch_begin());
2621 // Make sure there is enough delay before the touch is released so that it
2622 // is recognized as a tap.
2624 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2625 kTouchId2
, tes
.LeapForward(50));
2627 DispatchEventUsingWindowDispatcher(&release
);
2628 EXPECT_FALSE(delegate
->two_finger_tap());
2629 EXPECT_TRUE(delegate
->pinch_end());
2632 // Test moving second finger
2634 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2635 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2636 delegate
.get(), -1234, bounds
, root_window()));
2639 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2640 kTouchId1
, tes
.Now());
2641 DispatchEventUsingWindowDispatcher(&press1
);
2644 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2645 kTouchId2
, tes
.Now());
2646 DispatchEventUsingWindowDispatcher(&press2
);
2648 tes
.SendScrollEvent(event_processor(), 301, 230, kTouchId2
, delegate
.get());
2649 EXPECT_FALSE(delegate
->two_finger_tap());
2650 EXPECT_TRUE(delegate
->pinch_begin());
2652 // Make sure there is enough delay before the touch is released so that it
2653 // is recognized as a tap.
2655 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2656 kTouchId1
, tes
.LeapForward(50));
2658 DispatchEventUsingWindowDispatcher(&release
);
2659 EXPECT_FALSE(delegate
->two_finger_tap());
2660 EXPECT_TRUE(delegate
->pinch_end());
2664 TEST_F(GestureRecognizerTest
, NoTwoFingerTapWhenFirstFingerHasScrolled
) {
2665 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2666 new GestureEventConsumeDelegate());
2667 const int kWindowWidth
= 123;
2668 const int kWindowHeight
= 45;
2669 const int kTouchId1
= 2;
2670 const int kTouchId2
= 3;
2673 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2674 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2675 delegate
.get(), -1234, bounds
, root_window()));
2678 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2679 kTouchId1
, tes
.Now());
2680 DispatchEventUsingWindowDispatcher(&press1
);
2681 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId1
, delegate
.get());
2684 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2685 kTouchId2
, tes
.Now());
2686 DispatchEventUsingWindowDispatcher(&press2
);
2688 EXPECT_FALSE(delegate
->pinch_begin());
2690 // Make sure there is enough delay before the touch is released so that it
2691 // is recognized as a tap.
2693 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2694 kTouchId2
, tes
.LeapForward(50));
2696 DispatchEventUsingWindowDispatcher(&release
);
2697 EXPECT_FALSE(delegate
->two_finger_tap());
2698 EXPECT_FALSE(delegate
->pinch_end());
2701 TEST_F(GestureRecognizerTest
, MultiFingerSwipe
) {
2702 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2703 new GestureEventConsumeDelegate());
2704 const int kWindowWidth
= 123;
2705 const int kWindowHeight
= 45;
2707 gfx::Rect
bounds(5, 10, kWindowWidth
, kWindowHeight
);
2708 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2709 delegate
.get(), -1234, bounds
, root_window()));
2711 const int kSteps
= 15;
2712 const int kTouchPoints
= 4;
2713 gfx::Point points
[kTouchPoints
] = {
2720 ui::test::EventGenerator
generator(root_window(), window
.get());
2722 // The unified gesture recognizer assumes a finger has stopped if it hasn't
2723 // moved for too long. See ui/events/gesture_detection/velocity_tracker.cc's
2724 // kAssumePointerStoppedTimeMs.
2725 for (int count
= 2; count
<= kTouchPoints
; ++count
) {
2726 generator
.GestureMultiFingerScroll(
2727 count
, points
, 10, kSteps
, 0, -11 * kSteps
);
2728 EXPECT_TRUE(delegate
->swipe_up());
2731 generator
.GestureMultiFingerScroll(
2732 count
, points
, 10, kSteps
, 0, 11 * kSteps
);
2733 EXPECT_TRUE(delegate
->swipe_down());
2736 generator
.GestureMultiFingerScroll(
2737 count
, points
, 10, kSteps
, -11 * kSteps
, 0);
2738 EXPECT_TRUE(delegate
->swipe_left());
2741 generator
.GestureMultiFingerScroll(
2742 count
, points
, 10, kSteps
, 11 * kSteps
, 0);
2743 EXPECT_TRUE(delegate
->swipe_right());
2746 generator
.GestureMultiFingerScroll(
2747 count
, points
, 10, kSteps
, 5 * kSteps
, 12 * kSteps
);
2748 EXPECT_FALSE(delegate
->swipe_down());
2751 generator
.GestureMultiFingerScroll(
2752 count
, points
, 10, kSteps
, 4 * kSteps
, 12 * kSteps
);
2753 EXPECT_TRUE(delegate
->swipe_down());
2756 generator
.GestureMultiFingerScroll(
2757 count
, points
, 10, kSteps
, 3 * kSteps
, 12 * kSteps
);
2758 EXPECT_TRUE(delegate
->swipe_down());
2763 TEST_F(GestureRecognizerTest
, TwoFingerTapCancelled
) {
2764 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2765 new GestureEventConsumeDelegate());
2766 const int kWindowWidth
= 123;
2767 const int kWindowHeight
= 45;
2768 const int kTouchId1
= 2;
2769 const int kTouchId2
= 3;
2772 // Test canceling first finger.
2774 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2775 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2776 delegate
.get(), -1234, bounds
, root_window()));
2779 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2780 kTouchId1
, tes
.Now());
2781 DispatchEventUsingWindowDispatcher(&press1
);
2784 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2785 kTouchId2
, tes
.Now());
2786 DispatchEventUsingWindowDispatcher(&press2
);
2789 ui::TouchEvent
cancel(ui::ET_TOUCH_CANCELLED
, gfx::Point(130, 201),
2790 kTouchId1
, tes
.Now());
2791 DispatchEventUsingWindowDispatcher(&cancel
);
2792 EXPECT_FALSE(delegate
->two_finger_tap());
2794 // Make sure there is enough delay before the touch is released so that it
2795 // is recognized as a tap.
2797 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2798 kTouchId2
, tes
.LeapForward(50));
2800 DispatchEventUsingWindowDispatcher(&release
);
2801 EXPECT_FALSE(delegate
->two_finger_tap());
2804 // Test canceling second finger
2806 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2807 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2808 delegate
.get(), -1234, bounds
, root_window()));
2811 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2812 kTouchId1
, tes
.Now());
2813 DispatchEventUsingWindowDispatcher(&press1
);
2816 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2817 kTouchId2
, tes
.Now());
2818 DispatchEventUsingWindowDispatcher(&press2
);
2821 ui::TouchEvent
cancel(ui::ET_TOUCH_CANCELLED
, gfx::Point(130, 201),
2822 kTouchId2
, tes
.Now());
2823 DispatchEventUsingWindowDispatcher(&cancel
);
2824 EXPECT_FALSE(delegate
->two_finger_tap());
2826 // Make sure there is enough delay before the touch is released so that it
2827 // is recognized as a tap.
2829 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2830 kTouchId1
, tes
.LeapForward(50));
2832 DispatchEventUsingWindowDispatcher(&release
);
2833 EXPECT_FALSE(delegate
->two_finger_tap());
2837 TEST_F(GestureRecognizerTest
, VeryWideTwoFingerTouchDownShouldBeAPinch
) {
2838 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2839 new GestureEventConsumeDelegate());
2840 const int kWindowWidth
= 523;
2841 const int kWindowHeight
= 45;
2842 const int kTouchId1
= 2;
2843 const int kTouchId2
= 3;
2844 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2845 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2846 delegate
.get(), -1234, bounds
, root_window()));
2850 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2851 kTouchId1
, tes
.Now());
2852 DispatchEventUsingWindowDispatcher(&press1
);
2853 EXPECT_FALSE(delegate
->tap());
2854 EXPECT_TRUE(delegate
->tap_down());
2855 EXPECT_FALSE(delegate
->tap_cancel());
2856 EXPECT_FALSE(delegate
->scroll_begin());
2857 EXPECT_FALSE(delegate
->scroll_update());
2858 EXPECT_FALSE(delegate
->scroll_end());
2859 EXPECT_FALSE(delegate
->long_press());
2860 EXPECT_FALSE(delegate
->two_finger_tap());
2863 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(430, 201),
2864 kTouchId2
, tes
.Now());
2865 DispatchEventUsingWindowDispatcher(&press2
);
2866 EXPECT_FALSE(delegate
->tap());
2867 EXPECT_FALSE(delegate
->tap_down()); // no touch down for second tap.
2868 EXPECT_TRUE(delegate
->tap_cancel());
2869 EXPECT_FALSE(delegate
->scroll_begin());
2870 EXPECT_FALSE(delegate
->scroll_update());
2871 EXPECT_FALSE(delegate
->scroll_end());
2872 EXPECT_FALSE(delegate
->long_press());
2873 EXPECT_FALSE(delegate
->two_finger_tap());
2874 EXPECT_FALSE(delegate
->pinch_begin());
2877 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(530, 301),
2878 kTouchId2
, tes
.Now());
2879 DispatchEventUsingWindowDispatcher(&move2
);
2880 EXPECT_FALSE(delegate
->tap());
2881 EXPECT_FALSE(delegate
->tap_down());
2882 EXPECT_FALSE(delegate
->tap_cancel());
2883 // Pinch & Scroll only when there is enough movement.
2884 EXPECT_TRUE(delegate
->scroll_begin());
2885 EXPECT_TRUE(delegate
->scroll_update());
2886 EXPECT_FALSE(delegate
->scroll_end());
2887 EXPECT_FALSE(delegate
->long_press());
2888 EXPECT_FALSE(delegate
->two_finger_tap());
2889 EXPECT_TRUE(delegate
->pinch_begin());
2892 // Verifies if a window is the target of multiple touch-ids and we hide the
2893 // window everything is cleaned up correctly.
2894 TEST_F(GestureRecognizerTest
, FlushAllOnHide
) {
2895 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2896 new GestureEventConsumeDelegate());
2897 gfx::Rect
bounds(0, 0, 200, 200);
2898 scoped_ptr
<aura::Window
> window(
2899 CreateTestWindowWithDelegate(delegate
.get(), 0, bounds
, root_window()));
2900 const int kTouchId1
= 8;
2901 const int kTouchId2
= 2;
2904 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2905 kTouchId1
, tes
.Now());
2906 DispatchEventUsingWindowDispatcher(&press1
);
2907 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20),
2908 kTouchId2
, tes
.Now());
2909 DispatchEventUsingWindowDispatcher(&press2
);
2912 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
));
2914 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
));
2917 TEST_F(GestureRecognizerTest
, LongPressTimerStopsOnPreventDefaultedTouchMoves
) {
2918 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2919 new QueueTouchEventDelegate(host()->dispatcher()));
2920 const int kTouchId
= 2;
2921 gfx::Rect
bounds(100, 200, 100, 100);
2922 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2923 delegate
.get(), -1234, bounds
, root_window()));
2924 delegate
->set_window(window
.get());
2928 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2929 kTouchId
, tes
.Now());
2930 DispatchEventUsingWindowDispatcher(&press
);
2931 // Scroll around, to cancel the long press
2932 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
2935 delegate
->ReceivedAck();
2936 EXPECT_TRUE(delegate
->tap_down());
2938 // Wait long enough that long press would have fired if the touchmove hadn't
2940 DelayByLongPressTimeout();
2943 delegate
->ReceivedAckPreventDefaulted();
2944 EXPECT_FALSE(delegate
->long_press());
2947 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events.
2948 class ConsumesTouchMovesDelegate
: public GestureEventConsumeDelegate
{
2950 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {}
2951 virtual ~ConsumesTouchMovesDelegate() {}
2953 void set_consume_touch_move(bool consume
) { consume_touch_move_
= consume
; }
2956 virtual void OnTouchEvent(ui::TouchEvent
* touch
) OVERRIDE
{
2957 if (consume_touch_move_
&& touch
->type() == ui::ET_TOUCH_MOVED
)
2958 touch
->SetHandled();
2960 GestureEventConsumeDelegate::OnTouchEvent(touch
);
2963 bool consume_touch_move_
;
2965 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate
);
2968 // Same as GestureEventScroll, but tests that the behavior is the same
2969 // even if all the touch-move events are consumed.
2970 TEST_F(GestureRecognizerTest
, GestureEventScrollTouchMoveConsumed
) {
2971 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
2972 new ConsumesTouchMovesDelegate());
2973 const int kWindowWidth
= 123;
2974 const int kWindowHeight
= 45;
2975 const int kTouchId
= 5;
2976 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2977 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2978 delegate
.get(), -1234, bounds
, root_window()));
2982 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2983 kTouchId
, tes
.Now());
2984 DispatchEventUsingWindowDispatcher(&press
);
2985 EXPECT_FALSE(delegate
->tap());
2986 EXPECT_TRUE(delegate
->tap_down());
2987 EXPECT_FALSE(delegate
->tap_cancel());
2988 EXPECT_TRUE(delegate
->begin());
2989 EXPECT_FALSE(delegate
->scroll_begin());
2990 EXPECT_FALSE(delegate
->scroll_update());
2991 EXPECT_FALSE(delegate
->scroll_end());
2993 // Move the touch-point enough so that it would normally be considered a
2994 // scroll. But since the touch-moves will be consumed, the scroll should not
2996 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
2997 EXPECT_FALSE(delegate
->tap());
2998 EXPECT_FALSE(delegate
->tap_down());
2999 EXPECT_TRUE(delegate
->tap_cancel());
3000 EXPECT_FALSE(delegate
->begin());
3001 EXPECT_FALSE(delegate
->scroll_update());
3002 EXPECT_FALSE(delegate
->scroll_end());
3004 EXPECT_TRUE(delegate
->scroll_begin());
3006 // Release the touch back at the start point. This should end without causing
3009 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 230),
3010 kTouchId
, tes
.LeapForward(50));
3011 DispatchEventUsingWindowDispatcher(&release
);
3012 EXPECT_FALSE(delegate
->tap());
3013 EXPECT_FALSE(delegate
->tap_down());
3014 EXPECT_FALSE(delegate
->tap_cancel());
3015 EXPECT_FALSE(delegate
->begin());
3016 EXPECT_TRUE(delegate
->end());
3017 EXPECT_FALSE(delegate
->scroll_begin());
3018 EXPECT_FALSE(delegate
->scroll_update());
3020 EXPECT_TRUE(delegate
->scroll_end());
3023 // Tests the behavior of 2F scroll when some of the touch-move events are
3025 TEST_F(GestureRecognizerTest
, GestureEventScrollTwoFingerTouchMoveConsumed
) {
3026 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3027 new ConsumesTouchMovesDelegate());
3028 const int kWindowWidth
= 123;
3029 const int kWindowHeight
= 100;
3030 const int kTouchId1
= 2;
3031 const int kTouchId2
= 3;
3034 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3035 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3036 delegate
.get(), -1234, bounds
, root_window()));
3039 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3040 kTouchId1
, tes
.Now());
3041 DispatchEventUsingWindowDispatcher(&press1
);
3042 tes
.SendScrollEvent(event_processor(), 131, 231, kTouchId1
, delegate
.get());
3044 EXPECT_2_EVENTS(delegate
->events(),
3045 ui::ET_GESTURE_TAP_CANCEL
,
3046 ui::ET_GESTURE_SCROLL_BEGIN
);
3049 // Second finger touches down and moves.
3050 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
3051 kTouchId2
, tes
.LeapForward(50));
3052 DispatchEventUsingWindowDispatcher(&press2
);
3053 tes
.SendScrollEvent(event_processor(), 161, 231, kTouchId2
, delegate
.get());
3054 EXPECT_0_EVENTS(delegate
->events());
3057 // Move first finger again, no PinchUpdate & ScrollUpdate.
3058 tes
.SendScrollEvent(event_processor(), 161, 261, kTouchId1
, delegate
.get());
3059 EXPECT_0_EVENTS(delegate
->events());
3061 // Stops consuming touch-move.
3062 delegate
->set_consume_touch_move(false);
3065 // Making a pinch gesture.
3066 tes
.SendScrollEvent(event_processor(), 161, 260, kTouchId1
, delegate
.get());
3067 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
3070 tes
.SendScrollEvent(event_processor(), 161, 261, kTouchId2
, delegate
.get());
3071 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
3074 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3075 kTouchId1
, tes
.Now());
3076 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
3077 kTouchId2
, tes
.Now());
3078 DispatchEventUsingWindowDispatcher(&release1
);
3079 DispatchEventUsingWindowDispatcher(&release2
);
3081 EXPECT_3_EVENTS(delegate
->events(),
3083 ui::ET_GESTURE_SCROLL_END
,
3084 ui::ET_GESTURE_END
);
3087 // Like as GestureEventTouchMoveConsumed but tests the different behavior
3088 // depending on whether the events were consumed before or after the scroll
3090 TEST_F(GestureRecognizerTest
, GestureEventScrollTouchMovePartialConsumed
) {
3091 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3092 new ConsumesTouchMovesDelegate());
3093 const int kWindowWidth
= 123;
3094 const int kWindowHeight
= 45;
3095 const int kTouchId
= 5;
3096 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3097 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3098 delegate
.get(), -1234, bounds
, root_window()));
3102 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3103 kTouchId
, tes
.Now());
3104 DispatchEventUsingWindowDispatcher(&press
);
3105 EXPECT_FALSE(delegate
->tap());
3106 EXPECT_TRUE(delegate
->tap_down());
3107 EXPECT_FALSE(delegate
->tap_cancel());
3108 EXPECT_TRUE(delegate
->begin());
3109 EXPECT_FALSE(delegate
->scroll_begin());
3110 EXPECT_FALSE(delegate
->scroll_update());
3111 EXPECT_FALSE(delegate
->scroll_end());
3113 // Move the touch-point enough so that it would normally be considered a
3114 // scroll. But since the touch-moves will be consumed, the scroll should not
3116 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3117 EXPECT_FALSE(delegate
->tap());
3118 EXPECT_FALSE(delegate
->tap_down());
3119 EXPECT_TRUE(delegate
->tap_cancel());
3120 EXPECT_FALSE(delegate
->begin());
3121 EXPECT_FALSE(delegate
->scroll_update());
3122 EXPECT_FALSE(delegate
->scroll_end());
3124 // Consuming the first touch move event won't prevent all future scrolling.
3125 EXPECT_TRUE(delegate
->scroll_begin());
3127 // Now, stop consuming touch-move events, and move the touch-point again.
3128 delegate
->set_consume_touch_move(false);
3129 tes
.SendScrollEvent(event_processor(), 159, 259, kTouchId
, delegate
.get());
3130 EXPECT_FALSE(delegate
->tap());
3131 EXPECT_FALSE(delegate
->tap_down());
3132 EXPECT_FALSE(delegate
->tap_cancel());
3133 EXPECT_FALSE(delegate
->begin());
3134 EXPECT_FALSE(delegate
->scroll_begin());
3135 EXPECT_FALSE(delegate
->scroll_end());
3137 // Scroll not prevented by consumed first touch move.
3138 EXPECT_TRUE(delegate
->scroll_update());
3139 EXPECT_EQ(29, delegate
->scroll_x());
3140 EXPECT_EQ(29, delegate
->scroll_y());
3141 EXPECT_EQ(gfx::Point(0, 0).ToString(),
3142 delegate
->scroll_begin_position().ToString());
3144 // Start consuming touch-move events again.
3145 delegate
->set_consume_touch_move(true);
3147 // Move some more to generate a few more scroll updates.
3148 tes
.SendScrollEvent(event_processor(), 110, 211, kTouchId
, delegate
.get());
3149 EXPECT_FALSE(delegate
->tap());
3150 EXPECT_FALSE(delegate
->tap_down());
3151 EXPECT_FALSE(delegate
->tap_cancel());
3152 EXPECT_FALSE(delegate
->begin());
3153 EXPECT_FALSE(delegate
->scroll_begin());
3154 EXPECT_FALSE(delegate
->scroll_update());
3155 EXPECT_FALSE(delegate
->scroll_end());
3156 EXPECT_EQ(0, delegate
->scroll_x());
3157 EXPECT_EQ(0, delegate
->scroll_y());
3159 tes
.SendScrollEvent(event_processor(), 140, 215, kTouchId
, delegate
.get());
3160 EXPECT_FALSE(delegate
->tap());
3161 EXPECT_FALSE(delegate
->tap_down());
3162 EXPECT_FALSE(delegate
->tap_cancel());
3163 EXPECT_FALSE(delegate
->begin());
3164 EXPECT_FALSE(delegate
->scroll_begin());
3165 EXPECT_FALSE(delegate
->scroll_update());
3166 EXPECT_FALSE(delegate
->scroll_end());
3167 EXPECT_EQ(0, delegate
->scroll_x());
3168 EXPECT_EQ(0, delegate
->scroll_y());
3170 // Release the touch.
3172 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3173 kTouchId
, tes
.LeapForward(50));
3174 DispatchEventUsingWindowDispatcher(&release
);
3175 EXPECT_FALSE(delegate
->tap());
3176 EXPECT_FALSE(delegate
->tap_down());
3177 EXPECT_FALSE(delegate
->tap_cancel());
3178 EXPECT_FALSE(delegate
->begin());
3179 EXPECT_TRUE(delegate
->end());
3180 EXPECT_FALSE(delegate
->scroll_begin());
3181 EXPECT_FALSE(delegate
->scroll_update());
3182 EXPECT_FALSE(delegate
->fling());
3184 EXPECT_TRUE(delegate
->scroll_end());
3187 // Check that appropriate touch events generate double tap gesture events.
3188 TEST_F(GestureRecognizerTest
, GestureEventDoubleTap
) {
3189 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3190 new GestureEventConsumeDelegate());
3191 const int kWindowWidth
= 123;
3192 const int kWindowHeight
= 45;
3193 const int kTouchId
= 2;
3194 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3195 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3196 delegate
.get(), -1234, bounds
, root_window()));
3199 // First tap (tested in GestureEventTap)
3200 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(104, 201),
3201 kTouchId
, tes
.Now());
3202 DispatchEventUsingWindowDispatcher(&press1
);
3203 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(104, 201),
3204 kTouchId
, tes
.LeapForward(50));
3205 DispatchEventUsingWindowDispatcher(&release1
);
3209 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 203),
3210 kTouchId
, tes
.LeapForward(200));
3211 DispatchEventUsingWindowDispatcher(&press2
);
3212 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3213 kTouchId
, tes
.LeapForward(50));
3214 DispatchEventUsingWindowDispatcher(&release2
);
3216 EXPECT_TRUE(delegate
->tap());
3217 EXPECT_TRUE(delegate
->tap_down());
3218 EXPECT_FALSE(delegate
->tap_cancel());
3219 EXPECT_TRUE(delegate
->begin());
3220 EXPECT_TRUE(delegate
->end());
3221 EXPECT_FALSE(delegate
->scroll_begin());
3222 EXPECT_FALSE(delegate
->scroll_update());
3223 EXPECT_FALSE(delegate
->scroll_end());
3225 EXPECT_EQ(2, delegate
->tap_count());
3228 // Check that appropriate touch events generate triple tap gesture events.
3229 TEST_F(GestureRecognizerTest
, GestureEventTripleTap
) {
3230 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3231 new GestureEventConsumeDelegate());
3232 const int kWindowWidth
= 123;
3233 const int kWindowHeight
= 45;
3234 const int kTouchId
= 2;
3235 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3236 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3237 delegate
.get(), -1234, bounds
, root_window()));
3240 // First tap (tested in GestureEventTap)
3241 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(104, 201),
3242 kTouchId
, tes
.Now());
3243 DispatchEventUsingWindowDispatcher(&press1
);
3244 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(104, 201),
3245 kTouchId
, tes
.LeapForward(50));
3246 DispatchEventUsingWindowDispatcher(&release1
);
3248 EXPECT_EQ(1, delegate
->tap_count());
3251 // Second tap (tested in GestureEventDoubleTap)
3252 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 203),
3253 kTouchId
, tes
.LeapForward(200));
3254 DispatchEventUsingWindowDispatcher(&press2
);
3255 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3256 kTouchId
, tes
.LeapForward(50));
3257 DispatchEventUsingWindowDispatcher(&release2
);
3259 EXPECT_EQ(2, delegate
->tap_count());
3263 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
, gfx::Point(102, 206),
3264 kTouchId
, tes
.LeapForward(200));
3265 DispatchEventUsingWindowDispatcher(&press3
);
3266 ui::TouchEvent
release3(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3267 kTouchId
, tes
.LeapForward(50));
3268 DispatchEventUsingWindowDispatcher(&release3
);
3270 // Third, Fourth and Fifth Taps. Taps after the third should have their
3271 // |tap_count| wrap around back to 1.
3272 for (int i
= 3; i
< 5; ++i
) {
3273 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
,
3274 gfx::Point(102, 206),
3276 tes
.LeapForward(200));
3277 DispatchEventUsingWindowDispatcher(&press3
);
3278 ui::TouchEvent
release3(ui::ET_TOUCH_RELEASED
,
3279 gfx::Point(102, 206),
3281 tes
.LeapForward(50));
3282 DispatchEventUsingWindowDispatcher(&release3
);
3284 EXPECT_TRUE(delegate
->tap());
3285 EXPECT_TRUE(delegate
->tap_down());
3286 EXPECT_FALSE(delegate
->tap_cancel());
3287 EXPECT_TRUE(delegate
->begin());
3288 EXPECT_TRUE(delegate
->end());
3289 EXPECT_FALSE(delegate
->scroll_begin());
3290 EXPECT_FALSE(delegate
->scroll_update());
3291 EXPECT_FALSE(delegate
->scroll_end());
3292 EXPECT_EQ(1 + (i
% 3), delegate
->tap_count());
3296 // Check that we don't get a double tap when the two taps are far apart.
3297 TEST_F(GestureRecognizerTest
, TwoTapsFarApart
) {
3298 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3299 new GestureEventConsumeDelegate());
3300 const int kWindowWidth
= 123;
3301 const int kWindowHeight
= 45;
3302 const int kTouchId
= 2;
3303 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3304 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3305 delegate
.get(), -1234, bounds
, root_window()));
3308 // First tap (tested in GestureEventTap)
3309 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3310 kTouchId
, tes
.Now());
3311 DispatchEventUsingWindowDispatcher(&press1
);
3312 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3313 kTouchId
, tes
.LeapForward(50));
3314 DispatchEventUsingWindowDispatcher(&release1
);
3317 // Second tap, close in time but far in distance
3318 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(201, 201),
3319 kTouchId
, tes
.LeapForward(200));
3320 DispatchEventUsingWindowDispatcher(&press2
);
3321 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(201, 201),
3322 kTouchId
, tes
.LeapForward(50));
3323 DispatchEventUsingWindowDispatcher(&release2
);
3325 EXPECT_TRUE(delegate
->tap());
3326 EXPECT_TRUE(delegate
->tap_down());
3327 EXPECT_FALSE(delegate
->tap_cancel());
3328 EXPECT_TRUE(delegate
->begin());
3329 EXPECT_TRUE(delegate
->end());
3330 EXPECT_FALSE(delegate
->scroll_begin());
3331 EXPECT_FALSE(delegate
->scroll_update());
3332 EXPECT_FALSE(delegate
->scroll_end());
3334 EXPECT_EQ(1, delegate
->tap_count());
3337 // Check that we don't get a double tap when the two taps have a long enough
3338 // delay in between.
3339 TEST_F(GestureRecognizerTest
, TwoTapsWithDelayBetween
) {
3340 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3341 new GestureEventConsumeDelegate());
3342 const int kWindowWidth
= 123;
3343 const int kWindowHeight
= 45;
3344 const int kTouchId
= 2;
3345 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3346 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3347 delegate
.get(), -1234, bounds
, root_window()));
3350 // First tap (tested in GestureEventTap)
3351 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3352 kTouchId
, tes
.Now());
3353 DispatchEventUsingWindowDispatcher(&press1
);
3354 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3355 kTouchId
, tes
.LeapForward(50));
3356 DispatchEventUsingWindowDispatcher(&release1
);
3359 // Second tap, close in distance but after some delay
3360 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3361 kTouchId
, tes
.LeapForward(2000));
3362 DispatchEventUsingWindowDispatcher(&press2
);
3363 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3364 kTouchId
, tes
.LeapForward(50));
3365 DispatchEventUsingWindowDispatcher(&release2
);
3367 EXPECT_TRUE(delegate
->tap());
3368 EXPECT_TRUE(delegate
->tap_down());
3369 EXPECT_FALSE(delegate
->tap_cancel());
3370 EXPECT_TRUE(delegate
->begin());
3371 EXPECT_TRUE(delegate
->end());
3372 EXPECT_FALSE(delegate
->scroll_begin());
3373 EXPECT_FALSE(delegate
->scroll_update());
3374 EXPECT_FALSE(delegate
->scroll_end());
3376 EXPECT_EQ(1, delegate
->tap_count());
3379 // Checks that if the bounding-box of a gesture changes because of change in
3380 // radius of a touch-point, and not because of change in position, then there
3381 // are not gesture events from that.
3382 TEST_F(GestureRecognizerTest
, BoundingBoxRadiusChange
) {
3383 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3384 new GestureEventConsumeDelegate());
3385 const int kWindowWidth
= 234;
3386 const int kWindowHeight
= 345;
3387 const int kTouchId
= 5, kTouchId2
= 7;
3388 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3389 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3390 delegate
.get(), -1234, bounds
, root_window()));
3393 ui::TouchEvent
press1(
3394 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId
, tes
.Now());
3395 DispatchEventUsingWindowDispatcher(&press1
);
3396 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
3400 ui::TouchEvent
press2(
3401 ui::ET_TOUCH_PRESSED
, gfx::Point(201, 201), kTouchId2
,
3402 tes
.LeapForward(400));
3403 press2
.set_radius_x(5);
3404 DispatchEventUsingWindowDispatcher(&press2
);
3405 EXPECT_FALSE(delegate
->pinch_begin());
3406 EXPECT_EQ(gfx::Rect(101, 196, 105, 10).ToString(),
3407 delegate
->bounding_box().ToString());
3411 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(50, 50), kTouchId
,
3412 tes
.LeapForward(40));
3413 DispatchEventUsingWindowDispatcher(&move1
);
3414 EXPECT_TRUE(delegate
->pinch_begin());
3415 EXPECT_EQ(gfx::Rect(50, 50, 156, 156).ToString(),
3416 delegate
->bounding_box().ToString());
3420 // The position doesn't move, but the radius changes.
3421 ui::TouchEvent
move2(
3422 ui::ET_TOUCH_MOVED
, gfx::Point(50, 50), kTouchId
, tes
.LeapForward(40));
3423 move2
.set_radius_x(50);
3424 move2
.set_radius_y(60);
3425 DispatchEventUsingWindowDispatcher(&move2
);
3426 EXPECT_FALSE(delegate
->tap());
3427 EXPECT_FALSE(delegate
->tap_cancel());
3428 EXPECT_FALSE(delegate
->scroll_update());
3429 EXPECT_FALSE(delegate
->pinch_update());
3434 // Checks that slow scrolls deliver the correct deltas.
3435 // In particular, fix for http;//crbug.com/150573.
3436 TEST_F(GestureRecognizerTest
, NoDriftInScroll
) {
3437 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
3438 ui::GestureConfiguration::set_min_scroll_delta_squared(9);
3439 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3440 new GestureEventConsumeDelegate());
3441 const int kWindowWidth
= 234;
3442 const int kWindowHeight
= 345;
3443 const int kTouchId
= 5;
3445 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3446 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3447 delegate
.get(), -1234, bounds
, root_window()));
3449 ui::TouchEvent
press1(
3450 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 208), kTouchId
, tes
.Now());
3451 DispatchEventUsingWindowDispatcher(&press1
);
3452 EXPECT_TRUE(delegate
->begin());
3456 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(101, 206), kTouchId
,
3457 tes
.LeapForward(40));
3458 DispatchEventUsingWindowDispatcher(&move1
);
3459 EXPECT_FALSE(delegate
->scroll_begin());
3463 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(101, 204), kTouchId
,
3464 tes
.LeapForward(40));
3465 DispatchEventUsingWindowDispatcher(&move2
);
3466 EXPECT_TRUE(delegate
->tap_cancel());
3467 EXPECT_TRUE(delegate
->scroll_begin());
3468 EXPECT_TRUE(delegate
->scroll_update());
3469 // 3 px consumed by touch slop region.
3470 EXPECT_EQ(-1, delegate
->scroll_y());
3471 EXPECT_EQ(-4, delegate
->scroll_y_hint());
3475 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(101, 204), kTouchId
,
3476 tes
.LeapForward(40));
3477 DispatchEventUsingWindowDispatcher(&move3
);
3478 EXPECT_FALSE(delegate
->scroll_update());
3482 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(101, 203), kTouchId
,
3483 tes
.LeapForward(40));
3484 DispatchEventUsingWindowDispatcher(&move4
);
3485 EXPECT_TRUE(delegate
->scroll_update());
3486 EXPECT_EQ(-1, delegate
->scroll_y());
3491 // Ensure that move events which are preventDefaulted will cause a tap
3492 // cancel gesture event to be fired if the move would normally cause a
3493 // scroll. See bug http://crbug.com/146397.
3494 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveCanFireTapCancel
) {
3495 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3496 new ConsumesTouchMovesDelegate());
3497 const int kTouchId
= 5;
3498 gfx::Rect
bounds(100, 200, 123, 45);
3499 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3500 delegate
.get(), -1234, bounds
, root_window()));
3504 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3505 kTouchId
, tes
.Now());
3507 delegate
->set_consume_touch_move(false);
3508 DispatchEventUsingWindowDispatcher(&press
);
3509 delegate
->set_consume_touch_move(true);
3511 // Move the touch-point enough so that it would normally be considered a
3512 // scroll. But since the touch-moves will be consumed, no scrolling should
3514 // With the unified gesture detector, we will receive a scroll begin gesture,
3515 // whereas with the aura gesture recognizer we won't.
3516 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3517 EXPECT_FALSE(delegate
->tap());
3518 EXPECT_FALSE(delegate
->tap_down());
3519 EXPECT_TRUE(delegate
->tap_cancel());
3520 EXPECT_FALSE(delegate
->begin());
3521 EXPECT_FALSE(delegate
->scroll_update());
3522 EXPECT_FALSE(delegate
->scroll_end());
3525 TEST_F(GestureRecognizerTest
,
3526 TransferEventDispatchesTouchCancel
) {
3527 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3528 new GestureEventConsumeDelegate());
3530 const int kWindowWidth
= 800;
3531 const int kWindowHeight
= 600;
3532 const int kTouchId1
= 1;
3533 const int kTouchId2
= 2;
3534 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3535 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3536 delegate
.get(), -1234, bounds
, root_window()));
3537 scoped_ptr
<TestEventHandler
> handler(new TestEventHandler());
3538 window
->AddPreTargetHandler(handler
.get());
3540 // Start a gesture sequence on |window|. Then transfer the events to NULL.
3541 // Make sure |window| receives a touch-cancel event.
3543 ui::TouchEvent
press(
3544 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
3545 DispatchEventUsingWindowDispatcher(&press
);
3547 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
3550 ui::ET_TOUCH_PRESSED
, gfx::Point(50, 50), kTouchId2
, tes
.Now());
3551 DispatchEventUsingWindowDispatcher(&p2
);
3553 delegate
->events(), ui::ET_GESTURE_TAP_CANCEL
, ui::ET_GESTURE_BEGIN
);
3555 ui::TouchEvent
move(
3556 ui::ET_TOUCH_MOVED
, gfx::Point(350, 300), kTouchId2
, tes
.Now());
3557 DispatchEventUsingWindowDispatcher(&move
);
3558 EXPECT_3_EVENTS(delegate
->events(),
3559 ui::ET_GESTURE_SCROLL_BEGIN
,
3560 ui::ET_GESTURE_SCROLL_UPDATE
,
3561 ui::ET_GESTURE_PINCH_BEGIN
);
3562 EXPECT_EQ(2, handler
->touch_pressed_count());
3566 ui::GestureRecognizer
* gesture_recognizer
= ui::GestureRecognizer::Get();
3567 EXPECT_EQ(window
.get(),
3568 gesture_recognizer
->GetTouchLockedTarget(press
));
3569 gesture_recognizer
->TransferEventsTo(window
.get(), NULL
);
3571 gesture_recognizer
->GetTouchLockedTarget(press
));
3572 EXPECT_4_EVENTS(delegate
->events(),
3573 ui::ET_GESTURE_PINCH_END
,
3574 ui::ET_GESTURE_SCROLL_END
,
3576 ui::ET_GESTURE_END
);
3577 const std::vector
<gfx::PointF
>& points
= handler
->cancelled_touch_points();
3578 EXPECT_EQ(2U, points
.size());
3579 EXPECT_EQ(gfx::Point(101, 201), points
[0]);
3580 EXPECT_EQ(gfx::Point(350, 300), points
[1]);
3583 // Check that appropriate touch events generate show press events
3584 TEST_F(GestureRecognizerTest
, GestureEventShowPress
) {
3585 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3586 new GestureEventConsumeDelegate());
3588 const int kWindowWidth
= 123;
3589 const int kWindowHeight
= 45;
3590 const int kTouchId
= 2;
3591 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3592 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3593 delegate
.get(), -1234, bounds
, root_window()));
3597 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3598 kTouchId
, tes
.Now());
3599 DispatchEventUsingWindowDispatcher(&press1
);
3600 EXPECT_TRUE(delegate
->tap_down());
3601 EXPECT_TRUE(delegate
->begin());
3602 EXPECT_FALSE(delegate
->tap_cancel());
3604 // We haven't pressed long enough for a show press to occur
3605 EXPECT_FALSE(delegate
->show_press());
3607 // Wait until the timer runs out
3608 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
3609 EXPECT_TRUE(delegate
->show_press());
3610 EXPECT_FALSE(delegate
->tap_cancel());
3613 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3614 kTouchId
, tes
.Now());
3615 DispatchEventUsingWindowDispatcher(&release1
);
3616 EXPECT_FALSE(delegate
->long_press());
3618 // Note the tap isn't dispatched until the release
3619 EXPECT_FALSE(delegate
->tap_cancel());
3620 EXPECT_TRUE(delegate
->tap());
3623 // Check that scrolling cancels a show press
3624 TEST_F(GestureRecognizerTest
, GestureEventShowPressCancelledByScroll
) {
3625 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3626 new GestureEventConsumeDelegate());
3628 const int kWindowWidth
= 123;
3629 const int kWindowHeight
= 45;
3630 const int kTouchId
= 6;
3631 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3632 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3633 delegate
.get(), -1234, bounds
, root_window()));
3637 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3638 kTouchId
, tes
.Now());
3639 DispatchEventUsingWindowDispatcher(&press1
);
3640 EXPECT_TRUE(delegate
->tap_down());
3642 // We haven't pressed long enough for a show press to occur
3643 EXPECT_FALSE(delegate
->show_press());
3644 EXPECT_FALSE(delegate
->tap_cancel());
3646 // Scroll around, to cancel the show press
3647 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3648 // Wait until the timer runs out
3649 DelayByShowPressTimeout();
3650 EXPECT_FALSE(delegate
->show_press());
3651 EXPECT_TRUE(delegate
->tap_cancel());
3654 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3655 kTouchId
, tes
.LeapForward(10));
3656 DispatchEventUsingWindowDispatcher(&release1
);
3657 EXPECT_FALSE(delegate
->show_press());
3658 EXPECT_FALSE(delegate
->tap_cancel());
3661 // Test that show press events are sent immediately on tap
3662 TEST_F(GestureRecognizerTest
, GestureEventShowPressSentOnTap
) {
3663 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3664 new GestureEventConsumeDelegate());
3666 const int kWindowWidth
= 123;
3667 const int kWindowHeight
= 45;
3668 const int kTouchId
= 6;
3669 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3670 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3671 delegate
.get(), -1234, bounds
, root_window()));
3675 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3676 kTouchId
, tes
.Now());
3677 DispatchEventUsingWindowDispatcher(&press1
);
3678 EXPECT_TRUE(delegate
->tap_down());
3680 // We haven't pressed long enough for a show press to occur
3681 EXPECT_FALSE(delegate
->show_press());
3682 EXPECT_FALSE(delegate
->tap_cancel());
3685 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3686 kTouchId
, tes
.LeapForward(50));
3687 DispatchEventUsingWindowDispatcher(&release1
);
3688 EXPECT_TRUE(delegate
->show_press());
3689 EXPECT_FALSE(delegate
->tap_cancel());
3690 EXPECT_TRUE(delegate
->tap());
3693 // Test that consuming the first move touch event prevents a scroll.
3694 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveScrollTest
) {
3695 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3696 new QueueTouchEventDelegate(host()->dispatcher()));
3698 const int kTouchId
= 7;
3699 gfx::Rect
bounds(0, 0, 1000, 1000);
3700 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3701 delegate
.get(), -1234, bounds
, root_window()));
3702 delegate
->set_window(window
.get());
3704 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3705 kTouchId
, tes
.Now());
3706 DispatchEventUsingWindowDispatcher(&press
);
3707 delegate
->ReceivedAck();
3709 // A touch move within the slop region is never consumed in web contents. The
3710 // unified GR won't prevent scroll if a touch move within the slop region is
3711 // consumed, so make sure this touch move exceeds the slop region.
3712 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(10, 10),
3713 kTouchId
, tes
.Now());
3714 DispatchEventUsingWindowDispatcher(&move1
);
3715 delegate
->ReceivedAckPreventDefaulted();
3717 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20),
3718 kTouchId
, tes
.Now());
3719 DispatchEventUsingWindowDispatcher(&move2
);
3720 delegate
->ReceivedAck();
3722 // With the unified gesture detector, consuming the first touch move event
3723 // won't prevent all future scrolling.
3724 EXPECT_TRUE(delegate
->scroll_begin());
3725 EXPECT_TRUE(delegate
->scroll_update());
3728 // Test that consuming the first move touch doesn't prevent a tap.
3729 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveTapTest
) {
3730 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3731 new QueueTouchEventDelegate(host()->dispatcher()));
3733 const int kTouchId
= 7;
3734 gfx::Rect
bounds(0, 0, 1000, 1000);
3735 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3736 delegate
.get(), -1234, bounds
, root_window()));
3737 delegate
->set_window(window
.get());
3739 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3740 kTouchId
, tes
.Now());
3741 DispatchEventUsingWindowDispatcher(&press
);
3742 delegate
->ReceivedAck();
3744 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(2, 2),
3745 kTouchId
, tes
.Now());
3746 DispatchEventUsingWindowDispatcher(&move
);
3747 delegate
->ReceivedAckPreventDefaulted();
3749 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(2, 2),
3750 kTouchId
, tes
.LeapForward(50));
3751 DispatchEventUsingWindowDispatcher(&release
);
3752 delegate
->ReceivedAck();
3754 EXPECT_TRUE(delegate
->tap());
3757 // Test that consuming the first move touch doesn't prevent a long press.
3758 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveLongPressTest
) {
3759 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3760 new QueueTouchEventDelegate(host()->dispatcher()));
3762 const int kWindowWidth
= 123;
3763 const int kWindowHeight
= 45;
3764 const int kTouchId
= 2;
3765 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3766 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3767 delegate
.get(), -1234, bounds
, root_window()));
3768 delegate
->set_window(window
.get());
3772 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3773 kTouchId
, tes
.Now());
3774 DispatchEventUsingWindowDispatcher(&press1
);
3775 delegate
->ReceivedAck();
3777 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(103, 203),
3778 kTouchId
, tes
.Now());
3779 DispatchEventUsingWindowDispatcher(&move
);
3780 delegate
->ReceivedAckPreventDefaulted();
3782 // Wait until the timer runs out
3783 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
3784 EXPECT_TRUE(delegate
->long_press());
3787 // Tests that the deltas are correct when leaving the slop region very slowly.
3788 TEST_F(GestureRecognizerTest
, TestExceedingSlopSlowly
) {
3789 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
3790 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3791 new GestureEventConsumeDelegate());
3792 const int kWindowWidth
= 234;
3793 const int kWindowHeight
= 345;
3794 const int kTouchId
= 5;
3796 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3797 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3798 delegate
.get(), -1234, bounds
, root_window()));
3800 ui::TouchEvent
press(
3801 ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10), kTouchId
, tes
.Now());
3802 DispatchEventUsingWindowDispatcher(&press
);
3803 EXPECT_FALSE(delegate
->scroll_begin());
3804 EXPECT_FALSE(delegate
->scroll_update());
3807 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(11, 10), kTouchId
,
3808 tes
.LeapForward(40));
3809 DispatchEventUsingWindowDispatcher(&move1
);
3810 EXPECT_FALSE(delegate
->scroll_begin());
3811 EXPECT_FALSE(delegate
->scroll_update());
3812 EXPECT_EQ(0, delegate
->scroll_x());
3813 EXPECT_EQ(0, delegate
->scroll_x_hint());
3816 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(12, 10), kTouchId
,
3817 tes
.LeapForward(40));
3818 DispatchEventUsingWindowDispatcher(&move2
);
3819 EXPECT_FALSE(delegate
->scroll_begin());
3820 EXPECT_FALSE(delegate
->scroll_update());
3821 EXPECT_EQ(0, delegate
->scroll_x());
3822 EXPECT_EQ(0, delegate
->scroll_x_hint());
3826 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::PointF(13.1f
, 10.f
), kTouchId
,
3827 tes
.LeapForward(40));
3828 DispatchEventUsingWindowDispatcher(&move3
);
3829 EXPECT_TRUE(delegate
->scroll_begin());
3830 EXPECT_TRUE(delegate
->scroll_update());
3831 EXPECT_NEAR(0.1, delegate
->scroll_x(), 0.0001);
3832 EXPECT_FLOAT_EQ(3.1f
, delegate
->scroll_x_hint());
3835 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(14, 10), kTouchId
,
3836 tes
.LeapForward(40));
3837 DispatchEventUsingWindowDispatcher(&move4
);
3838 EXPECT_FALSE(delegate
->scroll_begin());
3839 EXPECT_TRUE(delegate
->scroll_update());
3840 EXPECT_NEAR(0.9, delegate
->scroll_x(), 0.0001);
3841 EXPECT_EQ(0.f
, delegate
->scroll_x_hint());
3845 TEST_F(GestureRecognizerTest
, ScrollAlternatelyConsumedTest
) {
3846 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3847 new QueueTouchEventDelegate(host()->dispatcher()));
3849 const int kWindowWidth
= 3000;
3850 const int kWindowHeight
= 3000;
3851 const int kTouchId
= 2;
3852 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3853 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3854 delegate
.get(), -1234, bounds
, root_window()));
3855 delegate
->set_window(window
.get());
3862 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(x
, y
),
3863 kTouchId
, tes
.Now());
3864 DispatchEventUsingWindowDispatcher(&press1
);
3865 delegate
->ReceivedAck();
3866 EXPECT_FALSE(delegate
->scroll_begin());
3867 EXPECT_FALSE(delegate
->scroll_update());
3872 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
),
3873 kTouchId
, tes
.Now());
3874 DispatchEventUsingWindowDispatcher(&move1
);
3875 delegate
->ReceivedAck();
3876 EXPECT_TRUE(delegate
->scroll_begin());
3877 EXPECT_TRUE(delegate
->scroll_update());
3880 for (int i
= 0; i
< 3; ++i
) {
3883 ui::TouchEvent
move2(
3884 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId
, tes
.Now());
3885 DispatchEventUsingWindowDispatcher(&move2
);
3886 delegate
->ReceivedAck();
3887 EXPECT_FALSE(delegate
->scroll_begin());
3888 EXPECT_TRUE(delegate
->scroll_update());
3889 EXPECT_EQ(10, delegate
->scroll_x());
3890 EXPECT_EQ(10, delegate
->scroll_y());
3895 ui::TouchEvent
move3(
3896 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId
, tes
.Now());
3897 DispatchEventUsingWindowDispatcher(&move3
);
3898 delegate
->ReceivedAckPreventDefaulted();
3899 EXPECT_FALSE(delegate
->scroll_begin());
3900 EXPECT_FALSE(delegate
->scroll_update());
3905 TEST_F(GestureRecognizerTest
, PinchAlternatelyConsumedTest
) {
3906 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3907 new QueueTouchEventDelegate(host()->dispatcher()));
3909 const int kWindowWidth
= 3000;
3910 const int kWindowHeight
= 3000;
3911 const int kTouchId1
= 5;
3912 const int kTouchId2
= 7;
3913 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3914 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3915 delegate
.get(), -1234, bounds
, root_window()));
3916 delegate
->set_window(window
.get());
3919 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3920 kTouchId1
, tes
.Now());
3921 DispatchEventUsingWindowDispatcher(&press1
);
3922 delegate
->ReceivedAck();
3923 EXPECT_FALSE(delegate
->scroll_begin());
3924 EXPECT_FALSE(delegate
->scroll_update());
3930 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(x
, y
),
3931 kTouchId2
, tes
.Now());
3932 DispatchEventUsingWindowDispatcher(&press2
);
3933 delegate
->ReceivedAck();
3934 EXPECT_FALSE(delegate
->scroll_begin());
3935 EXPECT_FALSE(delegate
->scroll_update());
3936 EXPECT_FALSE(delegate
->pinch_begin());
3937 EXPECT_FALSE(delegate
->pinch_update());
3943 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
),
3944 kTouchId2
, tes
.Now());
3945 DispatchEventUsingWindowDispatcher(&move1
);
3946 delegate
->ReceivedAck();
3947 EXPECT_TRUE(delegate
->scroll_begin());
3948 EXPECT_TRUE(delegate
->scroll_update());
3949 EXPECT_TRUE(delegate
->pinch_begin());
3950 EXPECT_FALSE(delegate
->pinch_update());
3953 const float expected_scales
[] = {1.5f
, 1.2f
, 1.125f
};
3955 for (int i
= 0; i
< 3; ++i
) {
3958 ui::TouchEvent
move2(
3959 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId2
, tes
.Now());
3960 DispatchEventUsingWindowDispatcher(&move2
);
3961 delegate
->ReceivedAck();
3962 EXPECT_FALSE(delegate
->scroll_begin());
3963 EXPECT_TRUE(delegate
->scroll_update());
3964 EXPECT_FALSE(delegate
->scroll_end());
3965 EXPECT_FALSE(delegate
->pinch_begin());
3966 EXPECT_TRUE(delegate
->pinch_update());
3967 EXPECT_FALSE(delegate
->pinch_end());
3968 EXPECT_EQ(25, delegate
->scroll_x());
3969 EXPECT_EQ(25, delegate
->scroll_y());
3970 EXPECT_FLOAT_EQ(expected_scales
[i
], delegate
->scale());
3975 ui::TouchEvent
move3(
3976 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId2
, tes
.Now());
3977 DispatchEventUsingWindowDispatcher(&move3
);
3978 delegate
->ReceivedAckPreventDefaulted();
3979 EXPECT_FALSE(delegate
->scroll_begin());
3980 EXPECT_FALSE(delegate
->scroll_update());
3981 EXPECT_FALSE(delegate
->scroll_end());
3982 EXPECT_FALSE(delegate
->pinch_begin());
3983 EXPECT_FALSE(delegate
->pinch_update());
3984 EXPECT_FALSE(delegate
->pinch_end());
3989 // Test that touch event flags are passed through to the gesture event.
3990 TEST_F(GestureRecognizerTest
, GestureEventFlagsPassedFromTouchEvent
) {
3991 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3992 new GestureEventConsumeDelegate());
3994 const int kWindowWidth
= 123;
3995 const int kWindowHeight
= 45;
3996 const int kTouchId
= 6;
3997 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3998 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3999 delegate
.get(), -1234, bounds
, root_window()));
4003 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4004 kTouchId
, tes
.Now());
4005 DispatchEventUsingWindowDispatcher(&press1
);
4006 EXPECT_TRUE(delegate
->tap_down());
4008 int default_flags
= delegate
->flags();
4010 ui::TouchEvent
move1(
4011 ui::ET_TOUCH_MOVED
, gfx::Point(397, 149), kTouchId
, tes
.LeapForward(50));
4012 move1
.set_flags(992);
4014 DispatchEventUsingWindowDispatcher(&move1
);
4015 EXPECT_NE(default_flags
, delegate
->flags());
4018 // Test that latency info is passed through to the gesture event.
4019 TEST_F(GestureRecognizerTest
, LatencyPassedFromTouchEvent
) {
4020 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4021 new GestureEventConsumeDelegate());
4023 const int kWindowWidth
= 123;
4024 const int kWindowHeight
= 45;
4025 const int kTouchId
= 6;
4027 const base::TimeTicks time_original
= base::TimeTicks::FromInternalValue(100);
4028 const base::TimeTicks time_ui
= base::TimeTicks::FromInternalValue(200);
4029 const base::TimeTicks time_acked
= base::TimeTicks::FromInternalValue(300);
4031 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
4032 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4033 delegate
.get(), -1234, bounds
, root_window()));
4037 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4038 kTouchId
, tes
.Now());
4040 // Ensure the only components around are the ones we add.
4041 press1
.latency()->Clear();
4043 press1
.latency()->AddLatencyNumberWithTimestamp(
4044 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 0, 0, time_original
, 1);
4046 press1
.latency()->AddLatencyNumberWithTimestamp(
4047 ui::INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, 0, time_ui
, 1);
4049 press1
.latency()->AddLatencyNumberWithTimestamp(
4050 ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT
, 0, 0, time_acked
, 1);
4052 DispatchEventUsingWindowDispatcher(&press1
);
4053 EXPECT_TRUE(delegate
->tap_down());
4055 ui::LatencyInfo::LatencyComponent component
;
4057 EXPECT_EQ(3U, delegate
->latency_info().latency_components
.size());
4058 ASSERT_TRUE(delegate
->latency_info().FindLatency(
4059 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 0, &component
));
4060 EXPECT_EQ(time_original
, component
.event_time
);
4062 ASSERT_TRUE(delegate
->latency_info().FindLatency(
4063 ui::INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
4064 EXPECT_EQ(time_ui
, component
.event_time
);
4066 ASSERT_TRUE(delegate
->latency_info().FindLatency(
4067 ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT
, 0, &component
));
4068 EXPECT_EQ(time_acked
, component
.event_time
);
4070 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
4071 EXPECT_TRUE(delegate
->show_press());
4072 EXPECT_EQ(0U, delegate
->latency_info().latency_components
.size());
4075 // A delegate that deletes a window on long press.
4076 class GestureEventDeleteWindowOnLongPress
: public GestureEventConsumeDelegate
{
4078 GestureEventDeleteWindowOnLongPress()
4081 void set_window(aura::Window
** window
) { window_
= window
; }
4083 virtual void OnGestureEvent(ui::GestureEvent
* gesture
) OVERRIDE
{
4084 GestureEventConsumeDelegate::OnGestureEvent(gesture
);
4085 if (gesture
->type() != ui::ET_GESTURE_LONG_PRESS
)
4087 ui::GestureRecognizer::Get()->CleanupStateForConsumer(*window_
);
4093 aura::Window
** window_
;
4094 DISALLOW_COPY_AND_ASSIGN(GestureEventDeleteWindowOnLongPress
);
4097 // Check that deleting the window in response to a long press gesture doesn't
4099 TEST_F(GestureRecognizerTest
, GestureEventLongPressDeletingWindow
) {
4100 GestureEventDeleteWindowOnLongPress delegate
;
4101 const int kWindowWidth
= 123;
4102 const int kWindowHeight
= 45;
4103 const int kTouchId
= 2;
4104 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
4105 aura::Window
* window(CreateTestWindowWithDelegate(
4106 &delegate
, -1234, bounds
, root_window()));
4107 delegate
.set_window(&window
);
4109 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
4110 gfx::Point(101, 201),
4112 ui::EventTimeForNow());
4113 DispatchEventUsingWindowDispatcher(&press1
);
4114 EXPECT_TRUE(window
!= NULL
);
4116 // Wait until the timer runs out.
4117 delegate
.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
4118 EXPECT_EQ(NULL
, window
);
4121 TEST_F(GestureRecognizerTest
, GestureEventSmallPinchDisabled
) {
4122 CommandLine::ForCurrentProcess()->AppendSwitch(
4123 switches::kCompensateForUnstablePinchZoom
);
4125 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4126 new GestureEventConsumeDelegate());
4128 const int kWindowWidth
= 300;
4129 const int kWindowHeight
= 400;
4130 const int kTouchId1
= 3;
4131 const int kTouchId2
= 5;
4132 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4133 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4134 delegate
.get(), -1234, bounds
, root_window()));
4136 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
4137 kTouchId1
, tes
.Now());
4138 DispatchEventUsingWindowDispatcher(&press1
);
4139 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
4140 kTouchId2
, tes
.Now());
4141 DispatchEventUsingWindowDispatcher(&press2
);
4143 // Move the first finger.
4145 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
4146 kTouchId1
, tes
.Now());
4147 DispatchEventUsingWindowDispatcher(&move1
);
4149 EXPECT_3_EVENTS(delegate
->events(),
4150 ui::ET_GESTURE_SCROLL_BEGIN
,
4151 ui::ET_GESTURE_SCROLL_UPDATE
,
4152 ui::ET_GESTURE_PINCH_BEGIN
);
4154 // No pinch update occurs, as kCompensateForUnstablePinchZoom is on, and this
4155 // is a very small pinch.
4157 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(65, 202),
4158 kTouchId1
, tes
.Now());
4159 DispatchEventUsingWindowDispatcher(&move2
);
4160 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
4163 TEST_F(GestureRecognizerTest
, GestureEventSmallPinchEnabled
) {
4164 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4165 new GestureEventConsumeDelegate());
4167 const int kWindowWidth
= 300;
4168 const int kWindowHeight
= 400;
4169 const int kTouchId1
= 3;
4170 const int kTouchId2
= 5;
4171 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4172 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4173 delegate
.get(), -1234, bounds
, root_window()));
4175 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
4176 kTouchId1
, tes
.Now());
4177 DispatchEventUsingWindowDispatcher(&press1
);
4178 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
4179 kTouchId2
, tes
.Now());
4180 DispatchEventUsingWindowDispatcher(&press2
);
4182 // Move the first finger.
4184 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
4185 kTouchId1
, tes
.Now());
4186 DispatchEventUsingWindowDispatcher(&move1
);
4188 EXPECT_3_EVENTS(delegate
->events(),
4189 ui::ET_GESTURE_SCROLL_BEGIN
,
4190 ui::ET_GESTURE_SCROLL_UPDATE
,
4191 ui::ET_GESTURE_PINCH_BEGIN
);
4194 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(65, 202),
4195 kTouchId1
, tes
.Now());
4196 DispatchEventUsingWindowDispatcher(&move2
);
4197 EXPECT_2_EVENTS(delegate
->events(),
4198 ui::ET_GESTURE_SCROLL_UPDATE
,
4199 ui::ET_GESTURE_PINCH_UPDATE
);
4202 // Tests that delaying the ack of a touch release doesn't trigger a long press
4204 TEST_F(GestureRecognizerTest
, EagerGestureDetection
) {
4205 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4206 new QueueTouchEventDelegate(host()->dispatcher()));
4208 const int kTouchId
= 2;
4209 gfx::Rect
bounds(100, 200, 100, 100);
4210 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4211 delegate
.get(), -1234, bounds
, root_window()));
4212 delegate
->set_window(window
.get());
4215 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4216 kTouchId
, tes
.Now());
4217 DispatchEventUsingWindowDispatcher(&press
);
4218 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
4219 kTouchId
, tes
.LeapForward(50));
4220 DispatchEventUsingWindowDispatcher(&release
);
4223 // Ack the touch press.
4224 delegate
->ReceivedAck();
4225 EXPECT_TRUE(delegate
->tap_down());
4228 // Wait until the long press event would fire (if we weren't eager).
4229 DelayByLongPressTimeout();
4231 // Ack the touch release.
4232 delegate
->ReceivedAck();
4233 EXPECT_TRUE(delegate
->tap());
4234 EXPECT_FALSE(delegate
->long_press());
4237 // This tests crbug.com/405519, in which events which the gesture detector
4238 // ignores cause future events to also be thrown away.
4239 TEST_F(GestureRecognizerTest
, IgnoredEventsDontPreventFutureEvents
) {
4240 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4241 new QueueTouchEventDelegate(host()->dispatcher()));
4243 const int kWindowWidth
= 300;
4244 const int kWindowHeight
= 400;
4245 const int kTouchId1
= 3;
4246 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4247 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4248 delegate
.get(), -1234, bounds
, root_window()));
4249 delegate
->set_window(window
.get());
4251 ui::TouchEvent
press1(
4252 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301), kTouchId1
, tes
.Now());
4253 DispatchEventUsingWindowDispatcher(&press1
);
4254 delegate
->ReceivedAck();
4257 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
4259 // Move the first finger.
4261 ui::TouchEvent
move1(
4262 ui::ET_TOUCH_MOVED
, gfx::Point(65, 201), kTouchId1
, tes
.Now());
4263 DispatchEventUsingWindowDispatcher(&move1
);
4264 delegate
->ReceivedAck();
4266 EXPECT_3_EVENTS(delegate
->events(),
4267 ui::ET_GESTURE_TAP_CANCEL
,
4268 ui::ET_GESTURE_SCROLL_BEGIN
,
4269 ui::ET_GESTURE_SCROLL_UPDATE
);
4272 ui::TouchEvent
move2(
4273 ui::ET_TOUCH_MOVED
, gfx::Point(65, 202), kTouchId1
, tes
.Now());
4274 DispatchEventUsingWindowDispatcher(&move2
);
4276 // Send a touchmove event at the same location as the previous touchmove
4277 // event. This shouldn't do anything.
4278 ui::TouchEvent
move3(
4279 ui::ET_TOUCH_MOVED
, gfx::Point(65, 202), kTouchId1
, tes
.Now());
4280 DispatchEventUsingWindowDispatcher(&move3
);
4282 delegate
->ReceivedAck();
4283 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);