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.
7 #include "base/command_line.h"
8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/timer/timer.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/aura/env.h"
13 #include "ui/aura/test/aura_test_base.h"
14 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/test/test_windows.h"
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/base/hit_test.h"
19 #include "ui/base/ui_base_switches.h"
20 #include "ui/events/event.h"
21 #include "ui/events/event_switches.h"
22 #include "ui/events/event_utils.h"
23 #include "ui/events/gesture_detection/gesture_configuration.h"
24 #include "ui/events/gestures/gesture_recognizer_impl.h"
25 #include "ui/events/gestures/gesture_types.h"
26 #include "ui/events/test/event_generator.h"
27 #include "ui/events/test/events_test_utils.h"
28 #include "ui/gfx/geometry/point.h"
29 #include "ui/gfx/geometry/rect.h"
36 std::string
WindowIDAsString(ui::GestureConsumer
* consumer
) {
38 base::IntToString(static_cast<Window
*>(consumer
)->id()) : "?";
41 #define EXPECT_0_EVENTS(events) \
42 EXPECT_EQ(0u, events.size())
44 #define EXPECT_1_EVENT(events, e0) \
45 EXPECT_EQ(1u, events.size()); \
46 EXPECT_EQ(e0, events[0])
48 #define EXPECT_2_EVENTS(events, e0, e1) \
49 EXPECT_EQ(2u, events.size()); \
50 EXPECT_EQ(e0, events[0]); \
51 EXPECT_EQ(e1, events[1])
53 #define EXPECT_3_EVENTS(events, e0, e1, e2) \
54 EXPECT_EQ(3u, events.size()); \
55 EXPECT_EQ(e0, events[0]); \
56 EXPECT_EQ(e1, events[1]); \
57 EXPECT_EQ(e2, events[2])
59 #define EXPECT_4_EVENTS(events, e0, e1, e2, e3) \
60 EXPECT_EQ(4u, events.size()); \
61 EXPECT_EQ(e0, events[0]); \
62 EXPECT_EQ(e1, events[1]); \
63 EXPECT_EQ(e2, events[2]); \
64 EXPECT_EQ(e3, events[3])
66 // A delegate that keeps track of gesture events.
67 class GestureEventConsumeDelegate
: public TestWindowDelegate
{
69 GestureEventConsumeDelegate()
76 scroll_update_(false),
83 two_finger_tap_(false),
91 scroll_velocity_x_(0),
92 scroll_velocity_y_(0),
99 wait_until_event_(ui::ET_UNKNOWN
) {}
101 ~GestureEventConsumeDelegate() override
{}
110 scroll_begin_
= false;
111 scroll_update_
= false;
113 pinch_begin_
= false;
114 pinch_update_
= false;
118 two_finger_tap_
= false;
121 swipe_right_
= false;
125 scroll_begin_position_
.SetPoint(0, 0);
126 tap_location_
.SetPoint(0, 0);
127 gesture_end_location_
.SetPoint(0, 0);
131 scroll_velocity_x_
= 0;
132 scroll_velocity_y_
= 0;
142 const std::vector
<ui::EventType
>& events() const { return events_
; };
144 bool tap() const { return tap_
; }
145 bool tap_down() const { return tap_down_
; }
146 bool tap_cancel() const { return tap_cancel_
; }
147 bool begin() const { return begin_
; }
148 bool end() const { return end_
; }
149 bool scroll_begin() const { return scroll_begin_
; }
150 bool scroll_update() const { return scroll_update_
; }
151 bool scroll_end() const { return scroll_end_
; }
152 bool pinch_begin() const { return pinch_begin_
; }
153 bool pinch_update() const { return pinch_update_
; }
154 bool pinch_end() const { return pinch_end_
; }
155 bool long_press() const { return long_press_
; }
156 bool long_tap() const { return long_tap_
; }
157 bool fling() const { return fling_
; }
158 bool two_finger_tap() const { return two_finger_tap_
; }
159 bool show_press() const { return show_press_
; }
160 bool swipe_left() const { return swipe_left_
; }
161 bool swipe_right() const { return swipe_right_
; }
162 bool swipe_up() const { return swipe_up_
; }
163 bool swipe_down() const { return swipe_down_
; }
165 const gfx::Point
& scroll_begin_position() const {
166 return scroll_begin_position_
;
169 const gfx::Point
& tap_location() const {
170 return tap_location_
;
173 const gfx::Point
& gesture_end_location() const {
174 return gesture_end_location_
;
177 float scroll_x() const { return scroll_x_
; }
178 float scroll_y() const { return scroll_y_
; }
179 float scroll_velocity_x() const { return scroll_velocity_x_
; }
180 float scroll_velocity_y() const { return scroll_velocity_y_
; }
181 float velocity_x() const { return velocity_x_
; }
182 float velocity_y() const { return velocity_y_
; }
183 float scroll_x_hint() const { return scroll_x_hint_
; }
184 float scroll_y_hint() const { return scroll_y_hint_
; }
185 float scale() const { return scale_
; }
186 const gfx::Rect
& bounding_box() const { return bounding_box_
; }
187 int tap_count() const { return tap_count_
; }
188 int flags() const { return flags_
; }
190 void WaitUntilReceivedGesture(ui::EventType type
) {
191 wait_until_event_
= type
;
192 run_loop_
.reset(new base::RunLoop());
196 void OnGestureEvent(ui::GestureEvent
* gesture
) override
{
197 events_
.push_back(gesture
->type());
198 bounding_box_
= gesture
->details().bounding_box();
199 flags_
= gesture
->flags();
200 switch (gesture
->type()) {
201 case ui::ET_GESTURE_TAP
:
202 tap_location_
= gesture
->location();
203 tap_count_
= gesture
->details().tap_count();
206 case ui::ET_GESTURE_TAP_DOWN
:
209 case ui::ET_GESTURE_TAP_CANCEL
:
212 case ui::ET_GESTURE_BEGIN
:
215 case ui::ET_GESTURE_END
:
217 gesture_end_location_
= gesture
->location();
219 case ui::ET_GESTURE_SCROLL_BEGIN
:
220 scroll_begin_
= true;
221 scroll_begin_position_
= gesture
->location();
222 scroll_x_hint_
= gesture
->details().scroll_x_hint();
223 scroll_y_hint_
= gesture
->details().scroll_y_hint();
225 case ui::ET_GESTURE_SCROLL_UPDATE
:
226 scroll_update_
= true;
227 scroll_x_
+= gesture
->details().scroll_x();
228 scroll_y_
+= gesture
->details().scroll_y();
230 case ui::ET_GESTURE_SCROLL_END
:
231 EXPECT_TRUE(velocity_x_
== 0 && velocity_y_
== 0);
234 case ui::ET_GESTURE_PINCH_BEGIN
:
237 case ui::ET_GESTURE_PINCH_UPDATE
:
238 pinch_update_
= true;
239 scale_
= gesture
->details().scale();
241 case ui::ET_GESTURE_PINCH_END
:
244 case ui::ET_GESTURE_LONG_PRESS
:
247 case ui::ET_GESTURE_LONG_TAP
:
250 case ui::ET_SCROLL_FLING_START
:
251 EXPECT_TRUE(gesture
->details().velocity_x() != 0 ||
252 gesture
->details().velocity_y() != 0);
253 EXPECT_FALSE(scroll_end_
);
255 velocity_x_
= gesture
->details().velocity_x();
256 velocity_y_
= gesture
->details().velocity_y();
258 case ui::ET_GESTURE_TWO_FINGER_TAP
:
259 two_finger_tap_
= true;
261 case ui::ET_GESTURE_SHOW_PRESS
:
264 case ui::ET_GESTURE_SWIPE
:
265 swipe_left_
= gesture
->details().swipe_left();
266 swipe_right_
= gesture
->details().swipe_right();
267 swipe_up_
= gesture
->details().swipe_up();
268 swipe_down_
= gesture
->details().swipe_down();
270 case ui::ET_SCROLL_FLING_CANCEL
:
271 // Only used in unified gesture detection.
276 if (wait_until_event_
== gesture
->type() && run_loop_
) {
278 wait_until_event_
= ui::ET_UNKNOWN
;
280 gesture
->StopPropagation();
284 scoped_ptr
<base::RunLoop
> run_loop_
;
285 std::vector
<ui::EventType
> events_
;
301 bool two_finger_tap_
;
308 gfx::Point scroll_begin_position_
;
309 gfx::Point tap_location_
;
310 gfx::Point gesture_end_location_
;
314 float scroll_velocity_x_
;
315 float scroll_velocity_y_
;
318 float scroll_x_hint_
;
319 float scroll_y_hint_
;
321 gfx::Rect bounding_box_
;
325 ui::EventType wait_until_event_
;
327 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate
);
330 class QueueTouchEventDelegate
: public GestureEventConsumeDelegate
{
332 explicit QueueTouchEventDelegate(WindowEventDispatcher
* dispatcher
)
334 dispatcher_(dispatcher
),
335 synchronous_ack_for_next_event_(AckState::PENDING
) {}
337 ~QueueTouchEventDelegate() override
{}
339 void OnTouchEvent(ui::TouchEvent
* event
) override
{
340 event
->DisableSynchronousHandling();
341 if (synchronous_ack_for_next_event_
!= AckState::PENDING
) {
342 ui::GestureRecognizer::Get()->AckTouchEvent(
343 event
->unique_event_id(),
344 synchronous_ack_for_next_event_
== AckState::CONSUMED
348 synchronous_ack_for_next_event_
= AckState::PENDING
;
350 sent_events_ids_
.push_back(event
->unique_event_id());
355 ReceivedAckImpl(false);
358 void ReceivedAckPreventDefaulted() {
359 ReceivedAckImpl(true);
362 void set_window(Window
* w
) { window_
= w
; }
363 void set_synchronous_ack_for_next_event(bool consumed
) {
364 DCHECK(synchronous_ack_for_next_event_
== AckState::PENDING
);
365 synchronous_ack_for_next_event_
=
366 consumed
? AckState::CONSUMED
: AckState::UNCONSUMED
;
370 enum class AckState
{
376 void ReceivedAckImpl(bool prevent_defaulted
) {
377 DCHECK(!sent_events_ids_
.empty());
378 if (sent_events_ids_
.empty())
380 uint32 sent_event_id
= sent_events_ids_
.front();
381 sent_events_ids_
.pop_front();
382 dispatcher_
->ProcessedTouchEvent(
383 sent_event_id
, window_
,
384 prevent_defaulted
? ui::ER_HANDLED
: ui::ER_UNHANDLED
);
388 WindowEventDispatcher
* dispatcher_
;
389 AckState synchronous_ack_for_next_event_
;
390 std::list
<uint32
> sent_events_ids_
;
392 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate
);
395 // A delegate that ignores gesture events but keeps track of [synthetic] mouse
397 class GestureEventSynthDelegate
: public TestWindowDelegate
{
399 GestureEventSynthDelegate()
400 : mouse_enter_(false),
403 mouse_release_(false),
405 double_click_(false) {
409 mouse_enter_
= false;
411 mouse_press_
= false;
412 mouse_release_
= false;
414 double_click_
= false;
417 bool mouse_enter() const { return mouse_enter_
; }
418 bool mouse_exit() const { return mouse_exit_
; }
419 bool mouse_press() const { return mouse_press_
; }
420 bool mouse_move() const { return mouse_move_
; }
421 bool mouse_release() const { return mouse_release_
; }
422 bool double_click() const { return double_click_
; }
424 void OnMouseEvent(ui::MouseEvent
* event
) override
{
425 switch (event
->type()) {
426 case ui::ET_MOUSE_PRESSED
:
427 double_click_
= event
->flags() & ui::EF_IS_DOUBLE_CLICK
;
430 case ui::ET_MOUSE_RELEASED
:
431 mouse_release_
= true;
433 case ui::ET_MOUSE_MOVED
:
436 case ui::ET_MOUSE_ENTERED
:
439 case ui::ET_MOUSE_EXITED
:
456 DISALLOW_COPY_AND_ASSIGN(GestureEventSynthDelegate
);
459 class ScopedGestureRecognizerSetter
{
461 // Takes ownership of |new_gr|.
462 explicit ScopedGestureRecognizerSetter(ui::GestureRecognizer
* new_gr
)
464 original_gr_
= ui::GestureRecognizer::Get();
465 ui::SetGestureRecognizerForTesting(new_gr_
.get());
468 virtual ~ScopedGestureRecognizerSetter() {
469 ui::SetGestureRecognizerForTesting(original_gr_
);
473 ui::GestureRecognizer
* original_gr_
;
474 scoped_ptr
<ui::GestureRecognizer
> new_gr_
;
476 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter
);
484 // Use a non-zero start time to pass DCHECKs which ensure events have had a
486 TimedEvents() : simulated_now_(1) {
489 base::TimeDelta
Now() {
490 base::TimeDelta t
= base::TimeDelta::FromMilliseconds(simulated_now_
);
495 base::TimeDelta
LeapForward(int time_in_millis
) {
496 simulated_now_
+= time_in_millis
;
497 return base::TimeDelta::FromMilliseconds(simulated_now_
);
500 base::TimeDelta
InFuture(int time_in_millis
) {
501 return base::TimeDelta::FromMilliseconds(simulated_now_
+ time_in_millis
);
504 void SendScrollEvents(ui::EventProcessor
* dispatcher
,
512 GestureEventConsumeDelegate
* delegate
) {
516 for (int i
= 0; i
< num_steps
; i
++) {
519 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::PointF(x
, y
),
521 base::TimeDelta::FromMilliseconds(simulated_now_
));
522 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(&move
);
523 ASSERT_FALSE(details
.dispatcher_destroyed
);
524 simulated_now_
+= time_step
;
528 void SendScrollEvent(ui::EventProcessor
* dispatcher
,
532 GestureEventConsumeDelegate
* delegate
) {
534 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::PointF(x
, y
),
536 base::TimeDelta::FromMilliseconds(simulated_now_
));
537 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(&move
);
538 ASSERT_FALSE(details
.dispatcher_destroyed
);
543 // An event handler to keep track of events.
544 class TestEventHandler
: public ui::EventHandler
{
547 : touch_released_count_(0),
548 touch_pressed_count_(0),
549 touch_moved_count_(0) {}
551 ~TestEventHandler() override
{}
553 void OnTouchEvent(ui::TouchEvent
* event
) override
{
554 switch (event
->type()) {
555 case ui::ET_TOUCH_RELEASED
:
556 touch_released_count_
++;
558 case ui::ET_TOUCH_PRESSED
:
559 touch_pressed_count_
++;
561 case ui::ET_TOUCH_MOVED
:
562 touch_moved_count_
++;
564 case ui::ET_TOUCH_CANCELLED
:
565 cancelled_touch_points_
.push_back(event
->location());
573 touch_released_count_
= 0;
574 touch_pressed_count_
= 0;
575 touch_moved_count_
= 0;
576 cancelled_touch_points_
.clear();
579 int touch_released_count() const { return touch_released_count_
; }
580 int touch_pressed_count() const { return touch_pressed_count_
; }
581 int touch_moved_count() const { return touch_moved_count_
; }
582 int touch_cancelled_count() const {
583 return static_cast<int>(cancelled_touch_points_
.size());
585 const std::vector
<gfx::PointF
>& cancelled_touch_points() const {
586 return cancelled_touch_points_
;
590 int touch_released_count_
;
591 int touch_pressed_count_
;
592 int touch_moved_count_
;
593 std::vector
<gfx::PointF
> cancelled_touch_points_
;
595 DISALLOW_COPY_AND_ASSIGN(TestEventHandler
);
598 // Removes the target window from its parent when it receives a touch-cancel
600 class RemoveOnTouchCancelHandler
: public TestEventHandler
{
602 RemoveOnTouchCancelHandler() {}
603 ~RemoveOnTouchCancelHandler() override
{}
607 void OnTouchEvent(ui::TouchEvent
* event
) override
{
608 TestEventHandler::OnTouchEvent(event
);
609 if (event
->type() == ui::ET_TOUCH_CANCELLED
) {
610 Window
* target
= static_cast<Window
*>(event
->target());
611 target
->parent()->RemoveChild(target
);
615 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler
);
618 void DelayByLongPressTimeout() {
619 ui::GestureProvider::Config config
;
620 base::RunLoop run_loop
;
621 base::MessageLoop::current()->PostDelayedTask(
623 run_loop
.QuitClosure(),
624 config
.gesture_detector_config
.longpress_timeout
* 2);
628 void DelayByShowPressTimeout() {
629 ui::GestureProvider::Config config
;
630 base::RunLoop run_loop
;
631 base::MessageLoop::current()->PostDelayedTask(
633 run_loop
.QuitClosure(),
634 config
.gesture_detector_config
.showpress_timeout
* 2);
640 class GestureRecognizerTest
: public AuraTestBase
,
641 public ::testing::WithParamInterface
<bool> {
643 GestureRecognizerTest() {}
645 void SetUp() override
{
646 AuraTestBase::SetUp();
647 ui::GestureConfiguration::GetInstance()->set_show_press_delay_in_ms(2);
648 ui::GestureConfiguration::GetInstance()->set_long_press_time_in_ms(3);
652 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest
);
655 class GestureRecognizerWithSwitchTest
: public GestureRecognizerTest
{
657 GestureRecognizerWithSwitchTest() {}
659 void SetUp() override
{
660 GestureRecognizerTest::SetUp();
661 base::CommandLine::ForCurrentProcess()->AppendSwitch(
662 switches::kCompensateForUnstablePinchZoom
);
663 ui::GestureConfiguration::GetInstance()->set_min_pinch_update_span_delta(5);
667 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerWithSwitchTest
);
670 // Check that appropriate touch events generate tap gesture events.
671 TEST_F(GestureRecognizerTest
, GestureEventTap
) {
672 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
673 new GestureEventConsumeDelegate());
675 const int kWindowWidth
= 123;
676 const int kWindowHeight
= 45;
677 const int kTouchId
= 2;
678 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
679 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
680 delegate
.get(), -1234, bounds
, root_window()));
683 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
684 kTouchId
, tes
.Now());
685 DispatchEventUsingWindowDispatcher(&press
);
686 EXPECT_FALSE(delegate
->tap());
687 EXPECT_FALSE(delegate
->show_press());
688 EXPECT_TRUE(delegate
->tap_down());
689 EXPECT_FALSE(delegate
->tap_cancel());
690 EXPECT_TRUE(delegate
->begin());
691 EXPECT_FALSE(delegate
->scroll_begin());
692 EXPECT_FALSE(delegate
->scroll_update());
693 EXPECT_FALSE(delegate
->scroll_end());
694 EXPECT_FALSE(delegate
->long_press());
697 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
698 EXPECT_TRUE(delegate
->show_press());
699 EXPECT_FALSE(delegate
->tap_down());
701 // Make sure there is enough delay before the touch is released so that it is
702 // recognized as a tap.
704 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
705 kTouchId
, tes
.LeapForward(50));
707 DispatchEventUsingWindowDispatcher(&release
);
708 EXPECT_TRUE(delegate
->tap());
709 EXPECT_FALSE(delegate
->tap_down());
710 EXPECT_FALSE(delegate
->tap_cancel());
711 EXPECT_FALSE(delegate
->begin());
712 EXPECT_TRUE(delegate
->end());
713 EXPECT_FALSE(delegate
->scroll_begin());
714 EXPECT_FALSE(delegate
->scroll_update());
715 EXPECT_FALSE(delegate
->scroll_end());
717 EXPECT_EQ(1, delegate
->tap_count());
720 // Check that appropriate touch events generate tap gesture events
721 // when information about the touch radii are provided.
722 TEST_F(GestureRecognizerTest
, GestureEventTapRegion
) {
723 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
724 new GestureEventConsumeDelegate());
726 const int kWindowWidth
= 800;
727 const int kWindowHeight
= 600;
728 const int kTouchId
= 2;
729 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
730 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
731 delegate
.get(), -1234, bounds
, root_window()));
733 // Test with no ET_TOUCH_MOVED events.
736 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
737 kTouchId
, tes
.Now());
738 press
.set_radius_x(5);
739 press
.set_radius_y(12);
740 DispatchEventUsingWindowDispatcher(&press
);
741 EXPECT_FALSE(delegate
->tap());
742 EXPECT_TRUE(delegate
->tap_down());
743 EXPECT_FALSE(delegate
->tap_cancel());
744 EXPECT_TRUE(delegate
->begin());
745 EXPECT_FALSE(delegate
->scroll_begin());
746 EXPECT_FALSE(delegate
->scroll_update());
747 EXPECT_FALSE(delegate
->scroll_end());
748 EXPECT_FALSE(delegate
->long_press());
750 // Make sure there is enough delay before the touch is released so that it
751 // is recognized as a tap.
753 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
754 kTouchId
, tes
.LeapForward(50));
755 release
.set_radius_x(5);
756 release
.set_radius_y(12);
758 DispatchEventUsingWindowDispatcher(&release
);
759 EXPECT_TRUE(delegate
->tap());
760 EXPECT_FALSE(delegate
->tap_down());
761 EXPECT_FALSE(delegate
->tap_cancel());
762 EXPECT_FALSE(delegate
->begin());
763 EXPECT_TRUE(delegate
->end());
764 EXPECT_FALSE(delegate
->scroll_begin());
765 EXPECT_FALSE(delegate
->scroll_update());
766 EXPECT_FALSE(delegate
->scroll_end());
768 EXPECT_EQ(1, delegate
->tap_count());
769 gfx::Point
actual_point(delegate
->tap_location());
770 EXPECT_EQ(24, delegate
->bounding_box().width());
771 EXPECT_EQ(24, delegate
->bounding_box().height());
772 EXPECT_EQ(101, actual_point
.x());
773 EXPECT_EQ(201, actual_point
.y());
776 // Test with no ET_TOUCH_MOVED events but different touch points and radii.
779 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(365, 290),
780 kTouchId
, tes
.Now());
781 press
.set_radius_x(8);
782 press
.set_radius_y(14);
783 DispatchEventUsingWindowDispatcher(&press
);
784 EXPECT_FALSE(delegate
->tap());
785 EXPECT_TRUE(delegate
->tap_down());
786 EXPECT_FALSE(delegate
->tap_cancel());
787 EXPECT_TRUE(delegate
->begin());
788 EXPECT_FALSE(delegate
->scroll_begin());
789 EXPECT_FALSE(delegate
->scroll_update());
790 EXPECT_FALSE(delegate
->scroll_end());
791 EXPECT_FALSE(delegate
->long_press());
794 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(367, 291),
795 kTouchId
, tes
.LeapForward(50));
796 release
.set_radius_x(20);
797 release
.set_radius_y(13);
799 DispatchEventUsingWindowDispatcher(&release
);
800 EXPECT_TRUE(delegate
->tap());
801 EXPECT_FALSE(delegate
->tap_down());
802 EXPECT_FALSE(delegate
->tap_cancel());
803 EXPECT_FALSE(delegate
->begin());
804 EXPECT_TRUE(delegate
->end());
805 EXPECT_FALSE(delegate
->scroll_begin());
806 EXPECT_FALSE(delegate
->scroll_update());
807 EXPECT_FALSE(delegate
->scroll_end());
809 EXPECT_EQ(1, delegate
->tap_count());
810 gfx::Point
actual_point(delegate
->tap_location());
811 EXPECT_EQ(40, delegate
->bounding_box().width());
812 EXPECT_EQ(40, delegate
->bounding_box().height());
813 EXPECT_EQ(367, actual_point
.x());
814 EXPECT_EQ(291, actual_point
.y());
817 // Test with a single ET_TOUCH_MOVED event.
820 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(46, 205),
821 kTouchId
, tes
.Now());
822 press
.set_radius_x(6);
823 press
.set_radius_y(10);
824 DispatchEventUsingWindowDispatcher(&press
);
825 EXPECT_FALSE(delegate
->tap());
826 EXPECT_TRUE(delegate
->tap_down());
827 EXPECT_FALSE(delegate
->tap_cancel());
828 EXPECT_TRUE(delegate
->begin());
829 EXPECT_FALSE(delegate
->tap_cancel());
830 EXPECT_FALSE(delegate
->scroll_begin());
831 EXPECT_FALSE(delegate
->scroll_update());
832 EXPECT_FALSE(delegate
->scroll_end());
833 EXPECT_FALSE(delegate
->long_press());
836 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(49, 204),
837 kTouchId
, tes
.LeapForward(50));
838 move
.set_radius_x(8);
839 move
.set_radius_y(12);
840 DispatchEventUsingWindowDispatcher(&move
);
841 EXPECT_FALSE(delegate
->tap());
842 EXPECT_FALSE(delegate
->tap_down());
843 EXPECT_FALSE(delegate
->tap_cancel());
844 EXPECT_FALSE(delegate
->begin());
845 EXPECT_FALSE(delegate
->scroll_begin());
846 EXPECT_FALSE(delegate
->scroll_update());
847 EXPECT_FALSE(delegate
->scroll_end());
848 EXPECT_FALSE(delegate
->long_press());
851 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(49, 204),
852 kTouchId
, tes
.LeapForward(50));
853 release
.set_radius_x(4);
854 release
.set_radius_y(8);
856 DispatchEventUsingWindowDispatcher(&release
);
857 EXPECT_TRUE(delegate
->tap());
858 EXPECT_FALSE(delegate
->tap_down());
859 EXPECT_FALSE(delegate
->tap_cancel());
860 EXPECT_FALSE(delegate
->begin());
861 EXPECT_TRUE(delegate
->end());
862 EXPECT_FALSE(delegate
->scroll_begin());
863 EXPECT_FALSE(delegate
->scroll_update());
864 EXPECT_FALSE(delegate
->scroll_end());
866 EXPECT_EQ(1, delegate
->tap_count());
867 gfx::Point
actual_point(delegate
->tap_location());
868 EXPECT_EQ(16, delegate
->bounding_box().width());
869 EXPECT_EQ(16, delegate
->bounding_box().height());
870 EXPECT_EQ(49, actual_point
.x());
871 EXPECT_EQ(204, actual_point
.y());
874 // Test with a few ET_TOUCH_MOVED events.
877 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(400, 150),
878 kTouchId
, tes
.Now());
879 press
.set_radius_x(7);
880 press
.set_radius_y(10);
881 DispatchEventUsingWindowDispatcher(&press
);
882 EXPECT_FALSE(delegate
->tap());
883 EXPECT_TRUE(delegate
->tap_down());
884 EXPECT_FALSE(delegate
->tap_cancel());
885 EXPECT_TRUE(delegate
->begin());
886 EXPECT_FALSE(delegate
->scroll_begin());
887 EXPECT_FALSE(delegate
->scroll_update());
888 EXPECT_FALSE(delegate
->scroll_end());
889 EXPECT_FALSE(delegate
->long_press());
892 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(397, 151),
893 kTouchId
, tes
.LeapForward(50));
894 move
.set_radius_x(13);
895 move
.set_radius_y(12);
896 DispatchEventUsingWindowDispatcher(&move
);
897 EXPECT_FALSE(delegate
->tap());
898 EXPECT_FALSE(delegate
->tap_down());
899 EXPECT_FALSE(delegate
->tap_cancel());
900 EXPECT_FALSE(delegate
->begin());
901 EXPECT_FALSE(delegate
->scroll_begin());
902 EXPECT_FALSE(delegate
->scroll_update());
903 EXPECT_FALSE(delegate
->scroll_end());
904 EXPECT_FALSE(delegate
->long_press());
907 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(397, 149),
908 kTouchId
, tes
.LeapForward(50));
909 move1
.set_radius_x(16);
910 move1
.set_radius_y(16);
911 DispatchEventUsingWindowDispatcher(&move1
);
912 EXPECT_FALSE(delegate
->tap());
913 EXPECT_FALSE(delegate
->tap_down());
914 EXPECT_FALSE(delegate
->tap_cancel());
915 EXPECT_FALSE(delegate
->begin());
916 EXPECT_FALSE(delegate
->scroll_begin());
917 EXPECT_FALSE(delegate
->scroll_update());
918 EXPECT_FALSE(delegate
->scroll_end());
919 EXPECT_FALSE(delegate
->long_press());
922 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(400, 150),
923 kTouchId
, tes
.LeapForward(50));
924 move2
.set_radius_x(14);
925 move2
.set_radius_y(10);
926 DispatchEventUsingWindowDispatcher(&move2
);
927 EXPECT_FALSE(delegate
->tap());
928 EXPECT_FALSE(delegate
->tap_down());
929 EXPECT_FALSE(delegate
->tap_cancel());
930 EXPECT_FALSE(delegate
->begin());
931 EXPECT_FALSE(delegate
->scroll_begin());
932 EXPECT_FALSE(delegate
->scroll_update());
933 EXPECT_FALSE(delegate
->scroll_end());
934 EXPECT_FALSE(delegate
->long_press());
937 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(401, 149),
938 kTouchId
, tes
.LeapForward(50));
939 release
.set_radius_x(8);
940 release
.set_radius_y(9);
942 DispatchEventUsingWindowDispatcher(&release
);
943 EXPECT_TRUE(delegate
->tap());
944 EXPECT_FALSE(delegate
->tap_down());
945 EXPECT_FALSE(delegate
->tap_cancel());
946 EXPECT_FALSE(delegate
->begin());
947 EXPECT_TRUE(delegate
->end());
948 EXPECT_FALSE(delegate
->scroll_begin());
949 EXPECT_FALSE(delegate
->scroll_update());
950 EXPECT_FALSE(delegate
->scroll_end());
952 EXPECT_EQ(1, delegate
->tap_count());
953 gfx::Point
actual_point(delegate
->tap_location());
954 EXPECT_EQ(18, delegate
->bounding_box().width());
955 EXPECT_EQ(18, delegate
->bounding_box().height());
956 EXPECT_EQ(401, actual_point
.x());
957 EXPECT_EQ(149, actual_point
.y());
961 // Check that appropriate touch events generate scroll gesture events.
962 TEST_F(GestureRecognizerTest
, GestureEventScroll
) {
963 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of
964 // that distance to be consumed by the slop, so we set the slop radius to
965 // sqrt(5 * 5 + 5 * 5).
966 ui::GestureConfiguration::GetInstance()
967 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f
* 5 + 5 * 5));
968 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
969 new GestureEventConsumeDelegate());
971 const int kWindowWidth
= 123;
972 const int kWindowHeight
= 45;
973 const int kTouchId
= 5;
974 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
975 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
976 delegate
.get(), -1234, bounds
, root_window()));
979 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
980 kTouchId
, tes
.Now());
981 DispatchEventUsingWindowDispatcher(&press
);
982 EXPECT_2_EVENTS(delegate
->events(),
983 ui::ET_GESTURE_BEGIN
,
984 ui::ET_GESTURE_TAP_DOWN
);
986 // Move the touch-point enough so that it is considered as a scroll. This
987 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
988 // The first movement is diagonal, to ensure that we have a free scroll,
989 // and not a rail scroll.
990 tes
.SendScrollEvent(event_processor(), 111.5, 211.5, kTouchId
,
992 EXPECT_3_EVENTS(delegate
->events(),
993 ui::ET_GESTURE_TAP_CANCEL
,
994 ui::ET_GESTURE_SCROLL_BEGIN
,
995 ui::ET_GESTURE_SCROLL_UPDATE
);
996 // The slop consumed 5 dips
997 EXPECT_FLOAT_EQ(5.5, delegate
->scroll_x());
998 EXPECT_FLOAT_EQ(5.5, delegate
->scroll_y());
999 EXPECT_EQ(gfx::Point(1, 1).ToString(),
1000 delegate
->scroll_begin_position().ToString());
1002 // When scrolling with a single finger, the bounding box of the gesture should
1003 // be empty, since it's a single point and the radius for testing is zero.
1004 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1006 // Move some more to generate a few more scroll updates. Make sure that we get
1007 // out of the snap channel for the unified GR.
1008 tes
.SendScrollEvent(event_processor(), 20, 120, kTouchId
, delegate
.get());
1009 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1010 EXPECT_FLOAT_EQ(-91.5, delegate
->scroll_x());
1011 EXPECT_FLOAT_EQ(-91.5, delegate
->scroll_y());
1012 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1014 tes
.SendScrollEvent(event_processor(), 50, 124, kTouchId
, delegate
.get());
1015 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1016 EXPECT_EQ(30, delegate
->scroll_x());
1017 EXPECT_EQ(4, delegate
->scroll_y());
1018 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1020 // Release the touch. This should end the scroll.
1022 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1024 tes
.LeapForward(50));
1025 DispatchEventUsingWindowDispatcher(&release
);
1026 EXPECT_2_EVENTS(delegate
->events(),
1027 ui::ET_SCROLL_FLING_START
,
1028 ui::ET_GESTURE_END
);
1029 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
1032 // Check that predicted scroll update positions are correct.
1033 TEST_F(GestureRecognizerTest
, GestureEventScrollPrediction
) {
1034 // We'll start by moving the touch point by (5, 5). We want all of that
1035 // distance to be consumed by the slop, so we set the slop radius to
1036 // sqrt(5 * 5 + 5 * 5).
1037 ui::GestureConfiguration::GetInstance()
1038 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f
* 5 + 5 * 5));
1040 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1041 new GestureEventConsumeDelegate());
1043 const int kWindowWidth
= 123;
1044 const int kWindowHeight
= 45;
1045 const int kTouchId
= 5;
1046 gfx::Rect
bounds(95, 195, kWindowWidth
, kWindowHeight
);
1047 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1048 delegate
.get(), -1234, bounds
, root_window()));
1051 // Tracks the total scroll since we want to verify that the correct position
1052 // will be scrolled to throughout the prediction.
1053 gfx::Vector2dF total_scroll
;
1054 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(96, 196),
1055 kTouchId
, tes
.Now());
1056 DispatchEventUsingWindowDispatcher(&press
);
1057 EXPECT_2_EVENTS(delegate
->events(),
1058 ui::ET_GESTURE_BEGIN
,
1059 ui::ET_GESTURE_TAP_DOWN
);
1062 // Get rid of touch slop.
1063 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(111, 211),
1064 kTouchId
, tes
.Now());
1065 DispatchEventUsingWindowDispatcher(&move
);
1066 EXPECT_3_EVENTS(delegate
->events(),
1067 ui::ET_GESTURE_TAP_CANCEL
,
1068 ui::ET_GESTURE_SCROLL_BEGIN
,
1069 ui::ET_GESTURE_SCROLL_UPDATE
);
1070 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1071 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1073 // Move the touch-point enough so that it is considered as a scroll. This
1074 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1075 // The first movement is diagonal, to ensure that we have a free scroll,
1076 // and not a rail scroll.
1077 tes
.LeapForward(30);
1078 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
1079 EXPECT_1_EVENT(delegate
->events(),
1080 ui::ET_GESTURE_SCROLL_UPDATE
);
1081 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1082 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1084 // Move some more to generate a few more scroll updates.
1085 tes
.LeapForward(30);
1086 tes
.SendScrollEvent(event_processor(), 110, 211, kTouchId
, delegate
.get());
1087 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1088 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1089 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1091 tes
.LeapForward(30);
1092 tes
.SendScrollEvent(event_processor(), 140, 215, kTouchId
, delegate
.get());
1093 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
1094 total_scroll
.set_x(total_scroll
.x() + delegate
->scroll_x());
1095 total_scroll
.set_y(total_scroll
.y() + delegate
->scroll_y());
1097 // Release the touch. This should end the scroll.
1099 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1101 tes
.LeapForward(50));
1102 DispatchEventUsingWindowDispatcher(&release
);
1105 // Check that the bounding box during a scroll event is correct.
1106 TEST_F(GestureRecognizerTest
, GestureEventScrollBoundingBox
) {
1108 for (int radius
= 1; radius
<= 10; ++radius
) {
1109 ui::GestureConfiguration::GetInstance()->set_default_radius(radius
);
1110 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1111 new GestureEventConsumeDelegate());
1112 const int kWindowWidth
= 123;
1113 const int kWindowHeight
= 45;
1114 const int kTouchId
= 5;
1115 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1116 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1117 delegate
.get(), -1234, bounds
, root_window()));
1119 const float kPositionX
= 101;
1120 const float kPositionY
= 201;
1122 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1123 gfx::PointF(kPositionX
, kPositionY
),
1126 DispatchEventUsingWindowDispatcher(&press
);
1127 EXPECT_EQ(gfx::Rect(kPositionX
- radius
, kPositionY
- radius
, radius
* 2,
1129 delegate
->bounding_box());
1131 const int kScrollAmount
= 50;
1132 tes
.SendScrollEvents(event_processor(), kPositionX
, kPositionY
,
1133 1, 1, kTouchId
, 1, kScrollAmount
, delegate
.get());
1134 EXPECT_EQ(gfx::Point(1, 1).ToString(),
1135 delegate
->scroll_begin_position().ToString());
1137 gfx::Rect(kPositionX
+ kScrollAmount
- radius
,
1138 kPositionY
+ kScrollAmount
- radius
, radius
* 2, radius
* 2),
1139 delegate
->bounding_box());
1141 // Release the touch. This should end the scroll.
1143 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1144 gfx::PointF(kPositionX
+ kScrollAmount
,
1145 kPositionY
+ kScrollAmount
),
1146 kTouchId
, press
.time_stamp() +
1147 base::TimeDelta::FromMilliseconds(50));
1148 DispatchEventUsingWindowDispatcher(&release
);
1150 gfx::Rect(kPositionX
+ kScrollAmount
- radius
,
1151 kPositionY
+ kScrollAmount
- radius
, radius
* 2, radius
* 2),
1152 delegate
->bounding_box());
1154 ui::GestureConfiguration::GetInstance()->set_default_radius(0);
1157 // Check Scroll End Events report correct velocities
1158 // if the user was on a horizontal rail
1159 TEST_F(GestureRecognizerTest
, GestureEventHorizontalRailFling
) {
1160 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1161 new GestureEventConsumeDelegate());
1163 const int kTouchId
= 7;
1164 gfx::Rect
bounds(0, 0, 1000, 1000);
1165 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1166 delegate
.get(), -1234, bounds
, root_window()));
1168 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1169 kTouchId
, tes
.Now());
1170 DispatchEventUsingWindowDispatcher(&press
);
1172 // Get rid of touch slop.
1173 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(10, 0),
1174 kTouchId
, tes
.Now());
1175 DispatchEventUsingWindowDispatcher(&move
);
1179 // Move the touch-point horizontally enough that it is considered a
1180 // horizontal scroll.
1181 tes
.SendScrollEvent(event_processor(), 30, 1, kTouchId
, delegate
.get());
1182 EXPECT_FLOAT_EQ(0, delegate
->scroll_y());
1183 EXPECT_FLOAT_EQ(20, delegate
->scroll_x());
1185 // Get a high x velocity, while still staying on the rail
1186 const int kScrollAmount
= 8;
1187 tes
.SendScrollEvents(event_processor(),
1198 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1199 kTouchId
, tes
.Now());
1200 DispatchEventUsingWindowDispatcher(&release
);
1202 EXPECT_TRUE(delegate
->fling());
1203 EXPECT_FALSE(delegate
->scroll_end());
1204 EXPECT_GT(delegate
->velocity_x(), 0);
1205 EXPECT_EQ(0, delegate
->velocity_y());
1208 // Check Scroll End Events report correct velocities
1209 // if the user was on a vertical rail
1210 TEST_F(GestureRecognizerTest
, GestureEventVerticalRailFling
) {
1211 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1212 new GestureEventConsumeDelegate());
1214 const int kTouchId
= 7;
1215 gfx::Rect
bounds(0, 0, 1000, 1000);
1216 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1217 delegate
.get(), -1234, bounds
, root_window()));
1219 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1220 kTouchId
, tes
.Now());
1221 DispatchEventUsingWindowDispatcher(&press
);
1223 // Get rid of touch slop.
1224 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(0, 10),
1225 kTouchId
, tes
.Now());
1226 DispatchEventUsingWindowDispatcher(&move
);
1229 // Move the touch-point vertically enough that it is considered a
1231 tes
.SendScrollEvent(event_processor(), 1, 30, kTouchId
, delegate
.get());
1232 EXPECT_EQ(20, delegate
->scroll_y());
1233 EXPECT_EQ(0, delegate
->scroll_x());
1234 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1236 // Get a high y velocity, while still staying on the rail
1237 const int kScrollAmount
= 8;
1238 tes
.SendScrollEvents(event_processor(),
1247 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1250 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 206),
1251 kTouchId
, tes
.Now());
1252 DispatchEventUsingWindowDispatcher(&release
);
1254 EXPECT_TRUE(delegate
->fling());
1255 EXPECT_FALSE(delegate
->scroll_end());
1256 EXPECT_EQ(0, delegate
->velocity_x());
1257 EXPECT_GT(delegate
->velocity_y(), 0);
1260 // Check Scroll End Events report non-zero velocities if the user is not on a
1262 TEST_F(GestureRecognizerTest
, GestureEventNonRailFling
) {
1263 ui::GestureConfiguration::GetInstance()
1264 ->set_max_touch_move_in_pixels_for_click(0);
1265 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1266 new GestureEventConsumeDelegate());
1268 const int kTouchId
= 7;
1269 gfx::Rect
bounds(0, 0, 1000, 1000);
1270 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1271 delegate
.get(), -1234, bounds
, root_window()));
1273 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1274 kTouchId
, tes
.Now());
1275 DispatchEventUsingWindowDispatcher(&press
);
1277 // Move the touch-point such that a non-rail scroll begins, and we're outside
1278 // the snap channel for the unified GR.
1279 tes
.SendScrollEvent(event_processor(), 50, 50, kTouchId
, delegate
.get());
1280 EXPECT_EQ(50, delegate
->scroll_y());
1281 EXPECT_EQ(50, delegate
->scroll_x());
1283 const int kScrollAmount
= 8;
1284 tes
.SendScrollEvents(event_processor(),
1295 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1296 kTouchId
, tes
.Now());
1297 DispatchEventUsingWindowDispatcher(&release
);
1299 EXPECT_TRUE(delegate
->fling());
1300 EXPECT_FALSE(delegate
->scroll_end());
1301 EXPECT_GT(delegate
->velocity_x(), 0);
1302 EXPECT_GT(delegate
->velocity_y(), 0);
1305 // Check that appropriate touch events generate long press events
1306 TEST_F(GestureRecognizerTest
, GestureEventLongPress
) {
1307 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1308 new GestureEventConsumeDelegate());
1309 const int kWindowWidth
= 123;
1310 const int kWindowHeight
= 45;
1311 const int kTouchId
= 2;
1312 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1313 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1314 delegate
.get(), -1234, bounds
, root_window()));
1318 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
1319 gfx::Point(101, 201),
1321 ui::EventTimeForNow());
1322 DispatchEventUsingWindowDispatcher(&press1
);
1323 EXPECT_TRUE(delegate
->tap_down());
1324 EXPECT_TRUE(delegate
->begin());
1325 EXPECT_FALSE(delegate
->tap_cancel());
1327 // We haven't pressed long enough for a long press to occur
1328 EXPECT_FALSE(delegate
->long_press());
1330 // Wait until the timer runs out
1331 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
1332 EXPECT_TRUE(delegate
->long_press());
1333 EXPECT_FALSE(delegate
->tap_cancel());
1336 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
,
1337 gfx::Point(101, 201),
1339 ui::EventTimeForNow());
1340 DispatchEventUsingWindowDispatcher(&release1
);
1341 EXPECT_FALSE(delegate
->long_press());
1343 // Note the tap cancel isn't dispatched until the release
1344 EXPECT_TRUE(delegate
->tap_cancel());
1345 EXPECT_FALSE(delegate
->tap());
1348 // Check that scrolling prevents a long press.
1349 TEST_F(GestureRecognizerTest
, GestureEventLongPressCancelledByScroll
) {
1350 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1351 new GestureEventConsumeDelegate());
1353 const int kWindowWidth
= 123;
1354 const int kWindowHeight
= 45;
1355 const int kTouchId
= 6;
1356 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1357 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1358 delegate
.get(), -1234, bounds
, root_window()));
1362 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1363 kTouchId
, tes
.Now());
1364 DispatchEventUsingWindowDispatcher(&press1
);
1365 EXPECT_TRUE(delegate
->tap_down());
1367 // We haven't pressed long enough for a long press to occur
1368 EXPECT_FALSE(delegate
->long_press());
1369 EXPECT_FALSE(delegate
->tap_cancel());
1371 // Scroll around, to cancel the long press
1372 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
1374 // Wait until a long press event would have fired, if it hadn't been
1376 DelayByLongPressTimeout();
1378 EXPECT_FALSE(delegate
->long_press());
1379 EXPECT_TRUE(delegate
->tap_cancel());
1382 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1383 kTouchId
, tes
.LeapForward(10));
1384 DispatchEventUsingWindowDispatcher(&release1
);
1385 EXPECT_FALSE(delegate
->long_press());
1386 EXPECT_FALSE(delegate
->tap_cancel());
1389 // Check that appropriate touch events generate long tap events
1390 TEST_F(GestureRecognizerTest
, GestureEventLongTap
) {
1391 ui::GestureConfiguration::GetInstance()
1392 ->set_max_touch_down_duration_for_click_in_ms(3);
1393 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1394 new GestureEventConsumeDelegate());
1395 const int kWindowWidth
= 123;
1396 const int kWindowHeight
= 45;
1397 const int kTouchId
= 2;
1398 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1399 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1400 delegate
.get(), -1234, bounds
, root_window()));
1404 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
1405 gfx::Point(101, 201),
1407 ui::EventTimeForNow());
1408 DispatchEventUsingWindowDispatcher(&press1
);
1409 EXPECT_TRUE(delegate
->tap_down());
1410 EXPECT_TRUE(delegate
->begin());
1411 EXPECT_FALSE(delegate
->tap_cancel());
1413 // We haven't pressed long enough for a long press to occur
1414 EXPECT_FALSE(delegate
->long_press());
1416 // Wait until the timer runs out
1417 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
1418 EXPECT_TRUE(delegate
->long_press());
1419 EXPECT_FALSE(delegate
->tap_cancel());
1422 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
,
1423 gfx::Point(101, 201),
1425 ui::EventTimeForNow());
1426 DispatchEventUsingWindowDispatcher(&release1
);
1427 EXPECT_FALSE(delegate
->long_press());
1428 EXPECT_TRUE(delegate
->long_tap());
1430 // Note the tap cancel isn't dispatched until the release
1431 EXPECT_TRUE(delegate
->tap_cancel());
1432 EXPECT_FALSE(delegate
->tap());
1435 // Check that second tap cancels a long press
1436 TEST_F(GestureRecognizerTest
, GestureEventLongPressCancelledBySecondTap
) {
1437 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1438 new GestureEventConsumeDelegate());
1440 const int kWindowWidth
= 300;
1441 const int kWindowHeight
= 400;
1442 const int kTouchId1
= 8;
1443 const int kTouchId2
= 2;
1444 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
1445 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1446 delegate
.get(), -1234, bounds
, root_window()));
1449 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1450 kTouchId1
, tes
.Now());
1451 DispatchEventUsingWindowDispatcher(&press
);
1452 EXPECT_TRUE(delegate
->tap_down());
1453 EXPECT_TRUE(delegate
->begin());
1455 // We haven't pressed long enough for a long press to occur
1456 EXPECT_FALSE(delegate
->long_press());
1458 // Second tap, to cancel the long press
1460 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1461 kTouchId2
, tes
.Now());
1462 DispatchEventUsingWindowDispatcher(&press2
);
1463 EXPECT_FALSE(delegate
->tap_down()); // no touch down for second tap.
1464 EXPECT_TRUE(delegate
->tap_cancel());
1465 EXPECT_TRUE(delegate
->begin());
1467 // Wait until the timer runs out
1468 DelayByLongPressTimeout();
1470 // No long press occurred
1471 EXPECT_FALSE(delegate
->long_press());
1474 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1475 kTouchId1
, tes
.Now());
1476 DispatchEventUsingWindowDispatcher(&release1
);
1477 EXPECT_FALSE(delegate
->long_press());
1478 EXPECT_TRUE(delegate
->two_finger_tap());
1479 EXPECT_FALSE(delegate
->tap_cancel());
1482 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1483 // Also tests that horizontal rails can be broken.
1484 TEST_F(GestureRecognizerTest
, GestureEventHorizontalRailScroll
) {
1485 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1486 new GestureEventConsumeDelegate());
1488 const int kTouchId
= 7;
1489 gfx::Rect
bounds(0, 0, 1000, 1000);
1490 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1491 delegate
.get(), -1234, bounds
, root_window()));
1493 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1494 kTouchId
, tes
.Now());
1495 DispatchEventUsingWindowDispatcher(&press
);
1497 // Get rid of touch slop.
1498 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(5, 0),
1499 kTouchId
, tes
.Now());
1501 DispatchEventUsingWindowDispatcher(&move
);
1504 // Move the touch-point horizontally enough that it is considered a
1505 // horizontal scroll.
1506 tes
.SendScrollEvent(event_processor(), 25, 0, kTouchId
, delegate
.get());
1507 EXPECT_EQ(0, delegate
->scroll_y());
1508 EXPECT_EQ(20, delegate
->scroll_x());
1510 tes
.SendScrollEvent(event_processor(), 30, 6, kTouchId
, delegate
.get());
1511 EXPECT_TRUE(delegate
->scroll_update());
1512 EXPECT_EQ(5, delegate
->scroll_x());
1513 // y shouldn't change, as we're on a horizontal rail.
1514 EXPECT_EQ(0, delegate
->scroll_y());
1516 // Send enough information that a velocity can be calculated for the gesture,
1517 // and we can break the rail
1518 const int kScrollAmount
= 8;
1519 tes
.SendScrollEvents(event_processor(),
1529 tes
.SendScrollEvent(event_processor(), 5, 0, kTouchId
, delegate
.get());
1530 tes
.SendScrollEvent(event_processor(), 10, 5, kTouchId
, delegate
.get());
1532 // The rail should be broken
1533 EXPECT_TRUE(delegate
->scroll_update());
1534 EXPECT_EQ(5, delegate
->scroll_x());
1535 EXPECT_EQ(5, delegate
->scroll_y());
1538 // Check that vertical scroll gestures cause scrolls on vertical rails.
1539 // Also tests that vertical rails can be broken.
1540 TEST_F(GestureRecognizerTest
, GestureEventVerticalRailScroll
) {
1541 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1542 new GestureEventConsumeDelegate());
1544 const int kTouchId
= 7;
1545 gfx::Rect
bounds(0, 0, 1000, 1000);
1546 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1547 delegate
.get(), -1234, bounds
, root_window()));
1549 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
1550 kTouchId
, tes
.Now());
1551 DispatchEventUsingWindowDispatcher(&press
);
1553 // Get rid of touch slop.
1554 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(0, 5),
1555 kTouchId
, tes
.Now());
1556 DispatchEventUsingWindowDispatcher(&move
);
1559 // Move the touch-point vertically enough that it is considered a
1561 tes
.SendScrollEvent(event_processor(), 0, 25, kTouchId
, delegate
.get());
1562 EXPECT_EQ(0, delegate
->scroll_x());
1563 EXPECT_EQ(20, delegate
->scroll_y());
1565 tes
.SendScrollEvent(event_processor(), 6, 30, kTouchId
, delegate
.get());
1566 EXPECT_TRUE(delegate
->scroll_update());
1567 EXPECT_EQ(5, delegate
->scroll_y());
1568 // x shouldn't change, as we're on a vertical rail.
1569 EXPECT_EQ(0, delegate
->scroll_x());
1570 EXPECT_EQ(0, delegate
->scroll_velocity_x());
1572 // Send enough information that a velocity can be calculated for the gesture,
1573 // and we can break the rail
1574 const int kScrollAmount
= 8;
1575 tes
.SendScrollEvents(event_processor(),
1585 tes
.SendScrollEvent(event_processor(), 0, 5, kTouchId
, delegate
.get());
1586 tes
.SendScrollEvent(event_processor(), 5, 10, kTouchId
, delegate
.get());
1588 // The rail should be broken
1589 EXPECT_TRUE(delegate
->scroll_update());
1590 EXPECT_EQ(5, delegate
->scroll_x());
1591 EXPECT_EQ(5, delegate
->scroll_y());
1594 TEST_F(GestureRecognizerTest
, GestureTapFollowedByScroll
) {
1595 // We'll start by moving the touch point by (5, 5). We want all of that
1596 // distance to be consumed by the slop, so we set the slop radius to
1597 // sqrt(5 * 5 + 5 * 5).
1598 ui::GestureConfiguration::GetInstance()
1599 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f
* 5 + 5 * 5));
1601 // First, tap. Then, do a scroll using the same touch-id.
1602 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1603 new GestureEventConsumeDelegate());
1605 const int kWindowWidth
= 123;
1606 const int kWindowHeight
= 45;
1607 const int kTouchId
= 3;
1608 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1609 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1610 delegate
.get(), -1234, bounds
, root_window()));
1613 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1614 kTouchId
, tes
.Now());
1615 DispatchEventUsingWindowDispatcher(&press
);
1616 EXPECT_FALSE(delegate
->tap());
1617 EXPECT_TRUE(delegate
->tap_down());
1618 EXPECT_FALSE(delegate
->tap_cancel());
1619 EXPECT_FALSE(delegate
->scroll_begin());
1620 EXPECT_FALSE(delegate
->scroll_update());
1621 EXPECT_FALSE(delegate
->scroll_end());
1623 // Make sure there is enough delay before the touch is released so that it is
1624 // recognized as a tap.
1626 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1627 kTouchId
, tes
.LeapForward(50));
1628 DispatchEventUsingWindowDispatcher(&release
);
1629 EXPECT_TRUE(delegate
->tap());
1630 EXPECT_FALSE(delegate
->tap_down());
1631 EXPECT_FALSE(delegate
->tap_cancel());
1632 EXPECT_FALSE(delegate
->scroll_begin());
1633 EXPECT_FALSE(delegate
->scroll_update());
1634 EXPECT_FALSE(delegate
->scroll_end());
1636 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger
1639 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1640 kTouchId
, tes
.LeapForward(1000));
1641 DispatchEventUsingWindowDispatcher(&press1
);
1642 EXPECT_FALSE(delegate
->tap());
1643 EXPECT_TRUE(delegate
->tap_down());
1644 EXPECT_FALSE(delegate
->tap_cancel());
1645 EXPECT_FALSE(delegate
->scroll_begin());
1646 EXPECT_FALSE(delegate
->scroll_update());
1647 EXPECT_FALSE(delegate
->scroll_end());
1649 // Get rid of touch slop.
1650 ui::TouchEvent
move_remove_slop(ui::ET_TOUCH_MOVED
, gfx::Point(116, 216),
1651 kTouchId
, tes
.Now());
1652 DispatchEventUsingWindowDispatcher(&move_remove_slop
);
1653 EXPECT_TRUE(delegate
->tap_cancel());
1654 EXPECT_TRUE(delegate
->scroll_begin());
1655 EXPECT_TRUE(delegate
->scroll_update());
1656 EXPECT_EQ(15, delegate
->scroll_x_hint());
1657 EXPECT_EQ(15, delegate
->scroll_y_hint());
1661 // Move the touch-point enough so that it is considered as a scroll. This
1662 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1663 // The first movement is diagonal, to ensure that we have a free scroll,
1664 // and not a rail scroll.
1666 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(135, 235),
1667 kTouchId
, tes
.Now());
1668 DispatchEventUsingWindowDispatcher(&move
);
1669 EXPECT_FALSE(delegate
->tap());
1670 EXPECT_FALSE(delegate
->tap_down());
1671 EXPECT_FALSE(delegate
->tap_cancel());
1672 EXPECT_FALSE(delegate
->scroll_begin());
1673 EXPECT_TRUE(delegate
->scroll_update());
1674 EXPECT_FALSE(delegate
->scroll_end());
1675 EXPECT_EQ(19, delegate
->scroll_x());
1676 EXPECT_EQ(19, delegate
->scroll_y());
1678 // Move some more to generate a few more scroll updates.
1680 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(115, 216),
1681 kTouchId
, tes
.Now());
1682 DispatchEventUsingWindowDispatcher(&move1
);
1683 EXPECT_FALSE(delegate
->tap());
1684 EXPECT_FALSE(delegate
->tap_down());
1685 EXPECT_FALSE(delegate
->tap_cancel());
1686 EXPECT_FALSE(delegate
->scroll_begin());
1687 EXPECT_TRUE(delegate
->scroll_update());
1688 EXPECT_FALSE(delegate
->scroll_end());
1689 EXPECT_EQ(-20, delegate
->scroll_x());
1690 EXPECT_EQ(-19, delegate
->scroll_y());
1691 EXPECT_EQ(0, delegate
->scroll_x_hint());
1692 EXPECT_EQ(0, delegate
->scroll_y_hint());
1695 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(145, 220),
1696 kTouchId
, tes
.Now());
1697 DispatchEventUsingWindowDispatcher(&move2
);
1698 EXPECT_FALSE(delegate
->tap());
1699 EXPECT_FALSE(delegate
->tap_down());
1700 EXPECT_FALSE(delegate
->tap_cancel());
1701 EXPECT_FALSE(delegate
->scroll_begin());
1702 EXPECT_TRUE(delegate
->scroll_update());
1703 EXPECT_FALSE(delegate
->scroll_end());
1704 EXPECT_EQ(30, delegate
->scroll_x());
1705 EXPECT_EQ(4, delegate
->scroll_y());
1707 // Release the touch. This should end the scroll.
1709 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1710 kTouchId
, tes
.Now());
1711 DispatchEventUsingWindowDispatcher(&release1
);
1712 EXPECT_FALSE(delegate
->tap());
1713 EXPECT_FALSE(delegate
->tap_down());
1714 EXPECT_FALSE(delegate
->tap_cancel());
1715 EXPECT_FALSE(delegate
->scroll_begin());
1716 EXPECT_FALSE(delegate
->scroll_update());
1717 EXPECT_FALSE(delegate
->scroll_end());
1718 EXPECT_TRUE(delegate
->fling());
1721 TEST_F(GestureRecognizerTest
, AsynchronousGestureRecognition
) {
1722 scoped_ptr
<QueueTouchEventDelegate
> queued_delegate(
1723 new QueueTouchEventDelegate(host()->dispatcher()));
1725 const int kWindowWidth
= 123;
1726 const int kWindowHeight
= 45;
1727 const int kTouchId1
= 6;
1728 const int kTouchId2
= 4;
1729 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
1730 scoped_ptr
<aura::Window
> queue(CreateTestWindowWithDelegate(
1731 queued_delegate
.get(), -1234, bounds
, root_window()));
1733 queued_delegate
->set_window(queue
.get());
1735 // Touch down on the window. This should not generate any gesture event.
1736 queued_delegate
->Reset();
1737 ui::TouchEvent
press(
1738 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
1739 DispatchEventUsingWindowDispatcher(&press
);
1740 EXPECT_FALSE(queued_delegate
->tap());
1741 EXPECT_FALSE(queued_delegate
->tap_down());
1742 EXPECT_FALSE(queued_delegate
->tap_cancel());
1743 EXPECT_FALSE(queued_delegate
->begin());
1744 EXPECT_FALSE(queued_delegate
->scroll_begin());
1745 EXPECT_FALSE(queued_delegate
->scroll_update());
1746 EXPECT_FALSE(queued_delegate
->scroll_end());
1748 // Introduce some delay before the touch is released so that it is recognized
1749 // as a tap. However, this still should not create any gesture events.
1750 queued_delegate
->Reset();
1751 ui::TouchEvent
release(
1752 ui::ET_TOUCH_RELEASED
,
1753 gfx::Point(101, 201),
1755 press
.time_stamp() + base::TimeDelta::FromMilliseconds(50));
1756 DispatchEventUsingWindowDispatcher(&release
);
1757 EXPECT_FALSE(queued_delegate
->tap());
1758 EXPECT_FALSE(queued_delegate
->tap_down());
1759 EXPECT_FALSE(queued_delegate
->tap_cancel());
1760 EXPECT_FALSE(queued_delegate
->begin());
1761 EXPECT_FALSE(queued_delegate
->end());
1762 EXPECT_FALSE(queued_delegate
->scroll_begin());
1763 EXPECT_FALSE(queued_delegate
->scroll_update());
1764 EXPECT_FALSE(queued_delegate
->scroll_end());
1766 // Create another window, and place a touch-down on it. This should create a
1767 // tap-down gesture.
1768 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1769 new GestureEventConsumeDelegate());
1770 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1771 delegate
.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window()));
1773 ui::TouchEvent
press2(
1774 ui::ET_TOUCH_PRESSED
, gfx::Point(10, 20), kTouchId2
, tes
.Now());
1775 DispatchEventUsingWindowDispatcher(&press2
);
1776 EXPECT_FALSE(delegate
->tap());
1777 EXPECT_TRUE(delegate
->tap_down());
1778 EXPECT_FALSE(delegate
->tap_cancel());
1779 EXPECT_FALSE(queued_delegate
->begin());
1780 EXPECT_FALSE(queued_delegate
->end());
1781 EXPECT_FALSE(delegate
->scroll_begin());
1782 EXPECT_FALSE(delegate
->scroll_update());
1783 EXPECT_FALSE(delegate
->scroll_end());
1785 ui::TouchEvent
release2(
1786 ui::ET_TOUCH_RELEASED
, gfx::Point(10, 20), kTouchId2
, tes
.Now());
1787 DispatchEventUsingWindowDispatcher(&release2
);
1789 // Process the first queued event.
1790 queued_delegate
->Reset();
1791 queued_delegate
->ReceivedAck();
1792 EXPECT_FALSE(queued_delegate
->tap());
1793 EXPECT_TRUE(queued_delegate
->tap_down());
1794 EXPECT_TRUE(queued_delegate
->begin());
1795 EXPECT_FALSE(queued_delegate
->tap_cancel());
1796 EXPECT_FALSE(queued_delegate
->end());
1797 EXPECT_FALSE(queued_delegate
->scroll_begin());
1798 EXPECT_FALSE(queued_delegate
->scroll_update());
1799 EXPECT_FALSE(queued_delegate
->scroll_end());
1801 // Now, process the second queued event.
1802 queued_delegate
->Reset();
1803 queued_delegate
->ReceivedAck();
1804 EXPECT_TRUE(queued_delegate
->tap());
1805 EXPECT_FALSE(queued_delegate
->tap_down());
1806 EXPECT_FALSE(queued_delegate
->tap_cancel());
1807 EXPECT_FALSE(queued_delegate
->begin());
1808 EXPECT_TRUE(queued_delegate
->end());
1809 EXPECT_FALSE(queued_delegate
->scroll_begin());
1810 EXPECT_FALSE(queued_delegate
->scroll_update());
1811 EXPECT_FALSE(queued_delegate
->scroll_end());
1813 // Start all over. Press on the first window, then press again on the second
1814 // window. The second press should still go to the first window.
1815 queued_delegate
->Reset();
1816 ui::TouchEvent
press3(
1817 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
1818 DispatchEventUsingWindowDispatcher(&press3
);
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
->end());
1824 EXPECT_FALSE(queued_delegate
->begin());
1825 EXPECT_FALSE(queued_delegate
->end());
1826 EXPECT_FALSE(queued_delegate
->scroll_begin());
1827 EXPECT_FALSE(queued_delegate
->scroll_update());
1828 EXPECT_FALSE(queued_delegate
->scroll_end());
1830 queued_delegate
->Reset();
1832 ui::TouchEvent
press4(
1833 ui::ET_TOUCH_PRESSED
, gfx::Point(103, 203), kTouchId2
, tes
.Now());
1834 DispatchEventUsingWindowDispatcher(&press4
);
1835 EXPECT_FALSE(delegate
->tap());
1836 EXPECT_FALSE(delegate
->tap_down());
1837 EXPECT_FALSE(delegate
->tap_cancel());
1838 EXPECT_FALSE(delegate
->begin());
1839 EXPECT_FALSE(delegate
->end());
1840 EXPECT_FALSE(delegate
->scroll_begin());
1841 EXPECT_FALSE(delegate
->scroll_update());
1842 EXPECT_FALSE(delegate
->scroll_end());
1843 EXPECT_FALSE(queued_delegate
->tap());
1844 EXPECT_FALSE(queued_delegate
->tap_down());
1845 EXPECT_FALSE(queued_delegate
->tap_cancel());
1846 EXPECT_FALSE(queued_delegate
->begin());
1847 EXPECT_FALSE(queued_delegate
->end());
1848 EXPECT_FALSE(queued_delegate
->scroll_begin());
1849 EXPECT_FALSE(queued_delegate
->scroll_update());
1850 EXPECT_FALSE(queued_delegate
->scroll_end());
1852 // Move the second touch-point enough so that it is considered a pinch. This
1853 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures.
1854 queued_delegate
->Reset();
1856 ui::TouchEvent
move(
1859 ui::GestureConfiguration::GetInstance()
1860 ->max_touch_move_in_pixels_for_click(),
1864 DispatchEventUsingWindowDispatcher(&move
);
1865 EXPECT_FALSE(delegate
->tap());
1866 EXPECT_FALSE(delegate
->tap_down());
1867 EXPECT_FALSE(delegate
->tap_cancel());
1868 EXPECT_FALSE(delegate
->begin());
1869 EXPECT_FALSE(delegate
->scroll_begin());
1870 EXPECT_FALSE(delegate
->scroll_update());
1871 EXPECT_FALSE(delegate
->scroll_end());
1872 EXPECT_FALSE(queued_delegate
->tap());
1873 EXPECT_FALSE(queued_delegate
->tap_down());
1874 EXPECT_FALSE(queued_delegate
->tap_cancel());
1875 EXPECT_FALSE(queued_delegate
->begin());
1876 EXPECT_FALSE(queued_delegate
->scroll_begin());
1877 EXPECT_FALSE(queued_delegate
->scroll_update());
1878 EXPECT_FALSE(queued_delegate
->scroll_end());
1880 queued_delegate
->Reset();
1881 queued_delegate
->ReceivedAck();
1882 EXPECT_FALSE(queued_delegate
->tap());
1883 EXPECT_TRUE(queued_delegate
->tap_down());
1884 EXPECT_TRUE(queued_delegate
->begin());
1885 EXPECT_FALSE(queued_delegate
->tap_cancel());
1886 EXPECT_FALSE(queued_delegate
->end());
1887 EXPECT_FALSE(queued_delegate
->scroll_begin());
1888 EXPECT_FALSE(queued_delegate
->scroll_update());
1889 EXPECT_FALSE(queued_delegate
->scroll_end());
1891 queued_delegate
->Reset();
1892 queued_delegate
->ReceivedAck();
1893 EXPECT_FALSE(queued_delegate
->tap());
1894 EXPECT_FALSE(queued_delegate
->tap_down()); // no touch down for second tap.
1895 EXPECT_TRUE(queued_delegate
->tap_cancel());
1896 EXPECT_TRUE(queued_delegate
->begin());
1897 EXPECT_FALSE(queued_delegate
->end());
1898 EXPECT_FALSE(queued_delegate
->scroll_begin());
1899 EXPECT_FALSE(queued_delegate
->scroll_update());
1900 EXPECT_FALSE(queued_delegate
->scroll_end());
1901 EXPECT_FALSE(queued_delegate
->pinch_begin());
1902 EXPECT_FALSE(queued_delegate
->pinch_update());
1903 EXPECT_FALSE(queued_delegate
->pinch_end());
1905 queued_delegate
->Reset();
1906 queued_delegate
->ReceivedAck();
1907 EXPECT_FALSE(queued_delegate
->tap());
1908 EXPECT_FALSE(queued_delegate
->tap_down());
1909 EXPECT_FALSE(queued_delegate
->tap_cancel());
1910 EXPECT_FALSE(queued_delegate
->begin());
1911 EXPECT_FALSE(queued_delegate
->end());
1912 EXPECT_TRUE(queued_delegate
->scroll_begin());
1914 EXPECT_TRUE(queued_delegate
->scroll_update());
1915 EXPECT_FALSE(queued_delegate
->scroll_end());
1916 EXPECT_TRUE(queued_delegate
->pinch_begin());
1917 EXPECT_FALSE(queued_delegate
->pinch_update());
1918 EXPECT_FALSE(queued_delegate
->pinch_end());
1921 // Check that appropriate touch events generate pinch gesture events.
1922 TEST_F(GestureRecognizerTest
, GestureEventPinchFromScroll
) {
1923 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
1924 new GestureEventConsumeDelegate());
1926 const int kWindowWidth
= 300;
1927 const int kWindowHeight
= 400;
1928 const int kTouchId1
= 5;
1929 const int kTouchId2
= 3;
1930 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
1931 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
1932 delegate
.get(), -1234, bounds
, root_window()));
1935 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
1936 kTouchId1
, tes
.Now());
1937 DispatchEventUsingWindowDispatcher(&press
);
1938 EXPECT_2_EVENTS(delegate
->events(),
1939 ui::ET_GESTURE_BEGIN
,
1940 ui::ET_GESTURE_TAP_DOWN
);
1942 // Move the touch-point enough so that it is considered as a scroll. This
1943 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1945 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(130, 301),
1946 kTouchId1
, tes
.Now());
1947 DispatchEventUsingWindowDispatcher(&move
);
1948 EXPECT_3_EVENTS(delegate
->events(),
1949 ui::ET_GESTURE_TAP_CANCEL
,
1950 ui::ET_GESTURE_SCROLL_BEGIN
,
1951 ui::ET_GESTURE_SCROLL_UPDATE
);
1953 // Press the second finger. It should cause pinch-begin. Note that we will not
1954 // transition to two finger tap here because the touch points are far enough.
1956 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
1957 kTouchId2
, tes
.Now());
1958 DispatchEventUsingWindowDispatcher(&press2
);
1959 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_BEGIN
);
1960 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(),
1961 delegate
->bounding_box().ToString());
1963 // Move the first finger.
1965 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(95, 201),
1966 kTouchId1
, tes
.Now());
1967 DispatchEventUsingWindowDispatcher(&move3
);
1968 EXPECT_2_EVENTS(delegate
->events(),
1969 ui::ET_GESTURE_SCROLL_UPDATE
,
1970 ui::ET_GESTURE_PINCH_BEGIN
);
1971 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(),
1972 delegate
->bounding_box().ToString());
1974 // Now move the second finger.
1976 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(55, 15),
1977 kTouchId2
, tes
.Now());
1978 DispatchEventUsingWindowDispatcher(&move4
);
1979 EXPECT_2_EVENTS(delegate
->events(),
1980 ui::ET_GESTURE_SCROLL_UPDATE
,
1981 ui::ET_GESTURE_PINCH_UPDATE
);
1982 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(),
1983 delegate
->bounding_box().ToString());
1985 // Release the first finger. This should end pinch.
1987 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
1988 kTouchId1
, tes
.Now());
1989 DispatchEventUsingWindowDispatcher(&release
);
1990 EXPECT_2_EVENTS(delegate
->events(),
1991 ui::ET_GESTURE_PINCH_END
,
1992 ui::ET_GESTURE_END
);
1993 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
1994 delegate
->bounding_box().ToString());
1996 // Move the second finger. This should still generate a scroll.
1998 ui::TouchEvent
move5(ui::ET_TOUCH_MOVED
, gfx::Point(25, 10),
1999 kTouchId2
, tes
.Now());
2000 DispatchEventUsingWindowDispatcher(&move5
);
2001 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
2002 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2005 TEST_F(GestureRecognizerTest
, GestureEventPinchFromScrollFromPinch
) {
2006 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2007 new GestureEventConsumeDelegate());
2009 const int kWindowWidth
= 300;
2010 const int kWindowHeight
= 400;
2011 const int kTouchId1
= 5;
2012 const int kTouchId2
= 3;
2013 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
2014 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2015 delegate
.get(), -1234, bounds
, root_window()));
2017 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
2018 kTouchId1
, tes
.Now());
2019 DispatchEventUsingWindowDispatcher(&press
);
2021 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2022 kTouchId2
, tes
.Now());
2023 DispatchEventUsingWindowDispatcher(&press2
);
2024 EXPECT_FALSE(delegate
->pinch_begin());
2026 // Touch move triggers pinch begin.
2027 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId1
, delegate
.get());
2028 EXPECT_TRUE(delegate
->pinch_begin());
2029 EXPECT_FALSE(delegate
->pinch_update());
2031 // Touch move triggers pinch update.
2032 tes
.SendScrollEvent(event_processor(), 160, 200, kTouchId1
, delegate
.get());
2033 EXPECT_FALSE(delegate
->pinch_begin());
2034 EXPECT_TRUE(delegate
->pinch_update());
2036 // Pinch has started, now release the second finger
2038 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2039 kTouchId1
, tes
.Now());
2040 DispatchEventUsingWindowDispatcher(&release
);
2041 EXPECT_TRUE(delegate
->pinch_end());
2043 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId2
, delegate
.get());
2044 EXPECT_TRUE(delegate
->scroll_update());
2048 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2049 kTouchId1
, tes
.Now());
2050 DispatchEventUsingWindowDispatcher(&press3
);
2051 // Now the touch points are close. So we will go into two finger tap.
2052 // Move the touch-point enough to break two-finger-tap and enter pinch.
2053 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(101, 50),
2054 kTouchId1
, tes
.Now());
2055 DispatchEventUsingWindowDispatcher(&move2
);
2056 EXPECT_TRUE(delegate
->pinch_begin());
2058 tes
.SendScrollEvent(event_processor(), 350, 350, kTouchId1
, delegate
.get());
2059 EXPECT_TRUE(delegate
->pinch_update());
2062 TEST_F(GestureRecognizerTest
, GestureEventPinchFromTap
) {
2063 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2064 new GestureEventConsumeDelegate());
2066 const int kWindowWidth
= 300;
2067 const int kWindowHeight
= 400;
2068 const int kTouchId1
= 3;
2069 const int kTouchId2
= 5;
2070 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
2071 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2072 delegate
.get(), -1234, bounds
, root_window()));
2075 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
2076 kTouchId1
, tes
.Now());
2077 DispatchEventUsingWindowDispatcher(&press
);
2078 EXPECT_2_EVENTS(delegate
->events(),
2079 ui::ET_GESTURE_BEGIN
,
2080 ui::ET_GESTURE_TAP_DOWN
);
2081 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2083 // Press the second finger far enough to break two finger tap.
2085 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2086 kTouchId2
, tes
.Now());
2087 DispatchEventUsingWindowDispatcher(&press2
);
2088 EXPECT_2_EVENTS(delegate
->events(),
2089 ui::ET_GESTURE_TAP_CANCEL
,
2090 ui::ET_GESTURE_BEGIN
);
2091 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(),
2092 delegate
->bounding_box().ToString());
2094 // Move the first finger.
2096 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
2097 kTouchId1
, tes
.Now());
2098 DispatchEventUsingWindowDispatcher(&move3
);
2099 EXPECT_3_EVENTS(delegate
->events(),
2100 ui::ET_GESTURE_SCROLL_BEGIN
,
2101 ui::ET_GESTURE_SCROLL_UPDATE
,
2102 ui::ET_GESTURE_PINCH_BEGIN
);
2103 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(),
2104 delegate
->bounding_box().ToString());
2106 // Now move the second finger.
2108 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(55, 15),
2109 kTouchId2
, tes
.Now());
2110 DispatchEventUsingWindowDispatcher(&move4
);
2111 EXPECT_2_EVENTS(delegate
->events(),
2112 ui::ET_GESTURE_SCROLL_UPDATE
,
2113 ui::ET_GESTURE_PINCH_UPDATE
);
2114 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(),
2115 delegate
->bounding_box().ToString());
2117 // Release the first finger. This should end pinch.
2119 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2120 kTouchId1
, tes
.LeapForward(10));
2121 DispatchEventUsingWindowDispatcher(&release
);
2122 EXPECT_2_EVENTS(delegate
->events(),
2123 ui::ET_GESTURE_PINCH_END
,
2124 ui::ET_GESTURE_END
);
2125 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
2126 delegate
->bounding_box().ToString());
2128 // Move the second finger. This should still generate a scroll.
2130 ui::TouchEvent
move5(ui::ET_TOUCH_MOVED
, gfx::Point(25, 10),
2131 kTouchId2
, tes
.Now());
2132 DispatchEventUsingWindowDispatcher(&move5
);
2133 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
2134 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
2137 TEST_F(GestureRecognizerTest
, GestureEventIgnoresDisconnectedEvents
) {
2138 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2139 new GestureEventConsumeDelegate());
2142 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2144 DispatchEventUsingWindowDispatcher(&release1
);
2145 EXPECT_FALSE(delegate
->tap());
2146 EXPECT_FALSE(delegate
->tap_down());
2149 // Check that a touch is locked to the window of the closest current touch
2150 // within max_separation_for_gesture_touches_in_pixels
2151 TEST_F(GestureRecognizerTest
, GestureEventTouchLockSelectsCorrectWindow
) {
2152 ui::GestureRecognizer
* gesture_recognizer
= new ui::GestureRecognizerImpl();
2154 ScopedGestureRecognizerSetter
gr_setter(gesture_recognizer
);
2156 ui::GestureConsumer
* target
;
2157 const int kNumWindows
= 4;
2159 scoped_ptr
<GestureEventConsumeDelegate
*[]> delegates(
2160 new GestureEventConsumeDelegate
*[kNumWindows
]);
2162 ui::GestureConfiguration::GetInstance()
2163 ->set_max_separation_for_gesture_touches_in_pixels(499);
2165 scoped_ptr
<gfx::Rect
[]> window_bounds(new gfx::Rect
[kNumWindows
]);
2166 window_bounds
[0] = gfx::Rect(0, 0, 1, 1);
2167 window_bounds
[1] = gfx::Rect(500, 0, 1, 1);
2168 window_bounds
[2] = gfx::Rect(0, 500, 1, 1);
2169 window_bounds
[3] = gfx::Rect(500, 500, 1, 1);
2171 scoped_ptr
<aura::Window
*[]> windows(new aura::Window
*[kNumWindows
]);
2173 // Instantiate windows with |window_bounds| and touch each window at
2175 for (int i
= 0; i
< kNumWindows
; ++i
) {
2176 delegates
[i
] = new GestureEventConsumeDelegate();
2177 windows
[i
] = CreateTestWindowWithDelegate(
2178 delegates
[i
], i
, window_bounds
[i
], root_window());
2179 windows
[i
]->set_id(i
);
2180 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, window_bounds
[i
].origin(),
2182 DispatchEventUsingWindowDispatcher(&press
);
2185 // Touches should now be associated with the closest touch within
2186 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels
2187 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(11, 11), -1);
2188 EXPECT_EQ("0", WindowIDAsString(target
));
2189 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(511, 11), -1);
2190 EXPECT_EQ("1", WindowIDAsString(target
));
2191 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(11, 511), -1);
2192 EXPECT_EQ("2", WindowIDAsString(target
));
2193 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(511, 511), -1);
2194 EXPECT_EQ("3", WindowIDAsString(target
));
2196 // Add a touch in the middle associated with windows[2]
2197 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 500),
2198 kNumWindows
, tes
.Now());
2199 DispatchEventUsingWindowDispatcher(&press
);
2200 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(250, 250),
2201 kNumWindows
, tes
.Now());
2202 DispatchEventUsingWindowDispatcher(&move
);
2204 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(250, 250), -1);
2205 EXPECT_EQ("2", WindowIDAsString(target
));
2207 // Make sure that ties are broken by distance to a current touch
2208 // Closer to the point in the bottom right.
2209 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(380, 380), -1);
2210 EXPECT_EQ("3", WindowIDAsString(target
));
2212 // This touch is closer to the point in the middle
2213 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(300, 300), -1);
2214 EXPECT_EQ("2", WindowIDAsString(target
));
2216 // A touch too far from other touches won't be locked to anything
2217 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2218 EXPECT_TRUE(target
== NULL
);
2220 // Move a touch associated with windows[2] to 1000, 1000
2221 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(1000, 1000),
2222 kNumWindows
, tes
.Now());
2223 DispatchEventUsingWindowDispatcher(&move2
);
2225 target
= gesture_recognizer
->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2226 EXPECT_EQ("2", WindowIDAsString(target
));
2228 for (int i
= 0; i
< kNumWindows
; ++i
) {
2229 // Delete windows before deleting delegates.
2231 delete delegates
[i
];
2235 // Check that a touch's target will not be effected by a touch on a different
2237 TEST_F(GestureRecognizerTest
, GestureEventTouchLockIgnoresOtherScreens
) {
2238 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2239 new GestureEventConsumeDelegate());
2240 gfx::Rect
bounds(0, 0, 10, 10);
2241 scoped_ptr
<aura::Window
> window(
2242 CreateTestWindowWithDelegate(delegate
.get(), 0, bounds
, root_window()));
2244 const int kTouchId1
= 8;
2245 const int kTouchId2
= 2;
2248 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(5, 5),
2249 kTouchId1
, tes
.Now());
2250 ui::EventTestApi
test_press1(&press1
);
2251 test_press1
.set_source_device_id(1);
2252 DispatchEventUsingWindowDispatcher(&press1
);
2254 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20),
2255 kTouchId2
, tes
.Now());
2256 ui::EventTestApi
test_press2(&press2
);
2257 test_press2
.set_source_device_id(2);
2258 DispatchEventUsingWindowDispatcher(&press2
);
2260 // The second press should not have been locked to the same target as the
2261 // first, as they occured on different displays.
2263 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
),
2264 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
));
2267 // Check that touch events outside the root window are still handled
2268 // by the root window's gesture sequence.
2269 TEST_F(GestureRecognizerTest
, GestureEventOutsideRootWindowTap
) {
2271 scoped_ptr
<aura::Window
> window(CreateTestWindowWithBounds(
2272 gfx::Rect(-100, -100, 2000, 2000), root_window()));
2274 gfx::Point
pos1(-10, -10);
2275 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, pos1
, 0, tes
.Now());
2276 DispatchEventUsingWindowDispatcher(&press1
);
2278 gfx::Point
pos2(1000, 1000);
2279 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, pos2
, 1, tes
.Now());
2280 DispatchEventUsingWindowDispatcher(&press2
);
2282 // As these presses were outside the root window, they should be
2283 // associated with the root window.
2284 EXPECT_EQ(root_window(),
2285 static_cast<aura::Window
*>(
2286 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
)));
2287 EXPECT_EQ(root_window(),
2288 static_cast<aura::Window
*>(
2289 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
)));
2292 TEST_F(GestureRecognizerTest
, NoTapWithPreventDefaultedRelease
) {
2293 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2294 new QueueTouchEventDelegate(host()->dispatcher()));
2296 const int kTouchId
= 2;
2297 gfx::Rect
bounds(100, 200, 100, 100);
2298 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2299 delegate
.get(), -1234, bounds
, root_window()));
2300 delegate
->set_window(window
.get());
2303 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2304 kTouchId
, tes
.Now());
2305 DispatchEventUsingWindowDispatcher(&press
);
2306 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2307 kTouchId
, tes
.LeapForward(50));
2308 DispatchEventUsingWindowDispatcher(&release
);
2311 delegate
->ReceivedAck();
2312 EXPECT_TRUE(delegate
->tap_down());
2314 delegate
->ReceivedAckPreventDefaulted();
2315 EXPECT_FALSE(delegate
->tap());
2316 EXPECT_TRUE(delegate
->tap_cancel());
2319 TEST_F(GestureRecognizerTest
, PinchScrollWithPreventDefaultedRelease
) {
2320 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2321 new QueueTouchEventDelegate(host()->dispatcher()));
2323 const int kTouchId1
= 7;
2324 const int kTouchId2
= 5;
2325 gfx::Rect
bounds(10, 20, 100, 100);
2326 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2327 delegate
.get(), -1234, bounds
, root_window()));
2328 delegate
->set_window(window
.get());
2332 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(15, 25), kTouchId1
,
2334 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(20, 95), kTouchId1
,
2335 tes
.LeapForward(200));
2336 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(15, 25), kTouchId1
,
2337 tes
.LeapForward(50));
2338 DispatchEventUsingWindowDispatcher(&press
);
2339 DispatchEventUsingWindowDispatcher(&move
);
2340 DispatchEventUsingWindowDispatcher(&release
);
2343 // Ack the press event.
2344 delegate
->ReceivedAck();
2346 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2349 // Ack the move event.
2350 delegate
->ReceivedAck();
2351 EXPECT_3_EVENTS(delegate
->events(),
2352 ui::ET_GESTURE_TAP_CANCEL
,
2353 ui::ET_GESTURE_SCROLL_BEGIN
,
2354 ui::ET_GESTURE_SCROLL_UPDATE
);
2357 // Ack the release event. Although the release event has been processed, it
2358 // should still generate a scroll-end event.
2359 delegate
->ReceivedAckPreventDefaulted();
2361 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2364 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(15, 25), kTouchId1
,
2366 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(20, 95), kTouchId1
,
2367 tes
.LeapForward(200));
2368 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(15, 25), kTouchId1
,
2369 tes
.LeapForward(50));
2370 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(55, 25), kTouchId2
,
2372 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(145, 85), kTouchId2
,
2373 tes
.LeapForward(1000));
2374 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(145, 85), kTouchId2
,
2375 tes
.LeapForward(14));
2378 DispatchEventUsingWindowDispatcher(&press
);
2379 DispatchEventUsingWindowDispatcher(&move
);
2380 DispatchEventUsingWindowDispatcher(&press2
);
2381 DispatchEventUsingWindowDispatcher(&move2
);
2382 DispatchEventUsingWindowDispatcher(&release
);
2383 DispatchEventUsingWindowDispatcher(&release2
);
2385 // Ack the press and move events.
2387 delegate
->ReceivedAck();
2389 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2392 delegate
->ReceivedAck();
2393 EXPECT_3_EVENTS(delegate
->events(),
2394 ui::ET_GESTURE_TAP_CANCEL
,
2395 ui::ET_GESTURE_SCROLL_BEGIN
,
2396 ui::ET_GESTURE_SCROLL_UPDATE
);
2399 delegate
->ReceivedAck();
2400 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_BEGIN
);
2403 delegate
->ReceivedAck();
2404 EXPECT_2_EVENTS(delegate
->events(),
2405 ui::ET_GESTURE_SCROLL_UPDATE
,
2406 ui::ET_GESTURE_PINCH_BEGIN
);
2408 // Ack the first release. Although the release is processed, it should still
2409 // generate a pinch-end event.
2411 delegate
->ReceivedAckPreventDefaulted();
2413 delegate
->events(), ui::ET_GESTURE_PINCH_END
, ui::ET_GESTURE_END
);
2416 delegate
->ReceivedAckPreventDefaulted();
2418 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2421 TEST_F(GestureRecognizerTest
, GestureEndLocation
) {
2422 GestureEventConsumeDelegate delegate
;
2423 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2424 &delegate
, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2425 ui::test::EventGenerator
generator(root_window(), window
.get());
2426 const gfx::Point
begin(20, 20);
2427 const gfx::Point
end(150, 150);
2428 const gfx::Vector2d window_offset
=
2429 window
->bounds().origin().OffsetFromOrigin();
2430 generator
.GestureScrollSequence(begin
, end
,
2431 base::TimeDelta::FromMilliseconds(20),
2433 EXPECT_EQ((begin
- window_offset
).ToString(),
2434 delegate
.scroll_begin_position().ToString());
2435 EXPECT_EQ((end
- window_offset
).ToString(),
2436 delegate
.gesture_end_location().ToString());
2439 TEST_F(GestureRecognizerTest
, CaptureSendsGestureEnd
) {
2440 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2441 new GestureEventConsumeDelegate());
2442 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2443 delegate
.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2444 ui::test::EventGenerator
generator(root_window());
2446 generator
.MoveMouseRelativeTo(window
.get(), gfx::Point(10, 10));
2447 generator
.PressTouch();
2448 RunAllPendingInMessageLoop();
2450 EXPECT_TRUE(delegate
->tap_down());
2452 scoped_ptr
<aura::Window
> capture(CreateTestWindowWithBounds(
2453 gfx::Rect(10, 10, 200, 200), root_window()));
2454 capture
->SetCapture();
2455 RunAllPendingInMessageLoop();
2457 EXPECT_TRUE(delegate
->end());
2458 EXPECT_TRUE(delegate
->tap_cancel());
2461 // Check that previous touch actions that are completely finished (either
2462 // released or cancelled), do not receive extra synthetic cancels upon change of
2464 TEST_F(GestureRecognizerTest
, CaptureDoesNotCancelFinishedTouches
) {
2465 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2466 new GestureEventConsumeDelegate());
2467 scoped_ptr
<TestEventHandler
> handler(new TestEventHandler
);
2468 root_window()->AddPreTargetHandler(handler
.get());
2470 // Create a window and set it as the capture window.
2471 scoped_ptr
<aura::Window
> window1(CreateTestWindowWithDelegate(delegate
.get(),
2472 -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2473 window1
->SetCapture();
2475 ui::test::EventGenerator
generator(root_window());
2478 // Generate two touch-press events on the window.
2479 scoped_ptr
<ui::TouchEvent
> touch0(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
2480 gfx::Point(20, 20), 0,
2482 scoped_ptr
<ui::TouchEvent
> touch1(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
2483 gfx::Point(30, 30), 1,
2485 generator
.Dispatch(touch0
.get());
2486 generator
.Dispatch(touch1
.get());
2487 RunAllPendingInMessageLoop();
2488 EXPECT_EQ(2, handler
->touch_pressed_count());
2491 tes
.LeapForward(1000);
2493 // End the two touches, one by a touch-release and one by a touch-cancel; to
2494 // cover both cases.
2495 touch0
.reset(new ui::TouchEvent(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
2497 touch1
.reset(new ui::TouchEvent(ui::ET_TOUCH_CANCELLED
, gfx::Point(30, 30), 1,
2499 generator
.Dispatch(touch0
.get());
2500 generator
.Dispatch(touch1
.get());
2501 RunAllPendingInMessageLoop();
2502 EXPECT_EQ(1, handler
->touch_released_count());
2503 EXPECT_EQ(1, handler
->touch_cancelled_count());
2505 // Create a new window and set it as the new capture window.
2506 scoped_ptr
<aura::Window
> window2(CreateTestWindowWithBounds(
2507 gfx::Rect(100, 100, 300, 300), root_window()));
2508 window2
->SetCapture();
2509 RunAllPendingInMessageLoop();
2510 // Check that setting capture does not generate any synthetic touch-cancels
2511 // for the two previously finished touch actions.
2512 EXPECT_EQ(1, handler
->touch_cancelled_count());
2514 root_window()->RemovePreTargetHandler(handler
.get());
2517 // Tests that a press with the same touch id as an existing touch is ignored.
2518 TEST_F(GestureRecognizerTest
, PressDoesNotCrash
) {
2519 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2520 new GestureEventConsumeDelegate());
2523 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2524 delegate
.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2526 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(45, 45), 7, tes
.Now());
2527 press
.set_radius_x(40);
2528 DispatchEventUsingWindowDispatcher(&press
);
2529 EXPECT_TRUE(delegate
->tap_down());
2530 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(),
2531 delegate
->bounding_box().ToString());
2534 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(55, 45), 7, tes
.Now());
2535 DispatchEventUsingWindowDispatcher(&press2
);
2537 // FIXME(tdresser): this should not generate a tap down; however,
2538 // there is at least one case where we need to allow a touch press
2539 // from a currently used touch id. See crbug.com/373125 for details.
2540 EXPECT_TRUE(delegate
->begin());
2541 EXPECT_TRUE(delegate
->tap_down());
2542 EXPECT_TRUE(delegate
->tap_cancel());
2543 EXPECT_FALSE(delegate
->scroll_begin());
2546 TEST_F(GestureRecognizerTest
, TwoFingerTap
) {
2547 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2548 new GestureEventConsumeDelegate());
2549 const int kWindowWidth
= 123;
2550 const int kWindowHeight
= 45;
2551 const int kTouchId1
= 2;
2552 const int kTouchId2
= 3;
2553 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2554 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2555 delegate
.get(), -1234, bounds
, root_window()));
2559 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2560 kTouchId1
, tes
.Now());
2561 DispatchEventUsingWindowDispatcher(&press1
);
2563 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
2566 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2567 kTouchId2
, tes
.Now());
2568 DispatchEventUsingWindowDispatcher(&press2
);
2570 delegate
->events(), ui::ET_GESTURE_TAP_CANCEL
, ui::ET_GESTURE_BEGIN
);
2572 // Little bit of touch move should not affect our state.
2574 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(102, 202),
2575 kTouchId1
, tes
.Now());
2576 DispatchEventUsingWindowDispatcher(&move1
);
2577 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(131, 202),
2578 kTouchId2
, tes
.Now());
2579 DispatchEventUsingWindowDispatcher(&move2
);
2580 EXPECT_3_EVENTS(delegate
->events(), ui::ET_GESTURE_SCROLL_BEGIN
,
2581 ui::ET_GESTURE_SCROLL_UPDATE
, ui::ET_GESTURE_SCROLL_UPDATE
);
2583 // Make sure there is enough delay before the touch is released so that it is
2584 // recognized as a tap.
2586 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2587 kTouchId1
, tes
.LeapForward(50));
2589 DispatchEventUsingWindowDispatcher(&release1
);
2591 delegate
->events(), ui::ET_GESTURE_TWO_FINGER_TAP
, ui::ET_GESTURE_END
);
2593 // Lift second finger.
2594 // Make sure there is enough delay before the touch is released so that it is
2595 // recognized as a tap.
2597 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
2598 kTouchId2
, tes
.LeapForward(50));
2600 DispatchEventUsingWindowDispatcher(&release2
);
2602 delegate
->events(), ui::ET_GESTURE_SCROLL_END
, ui::ET_GESTURE_END
);
2605 TEST_F(GestureRecognizerTest
, TwoFingerTapExpired
) {
2606 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2607 new GestureEventConsumeDelegate());
2608 const int kWindowWidth
= 123;
2609 const int kWindowHeight
= 45;
2610 const int kTouchId1
= 2;
2611 const int kTouchId2
= 3;
2612 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2613 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2614 delegate
.get(), -1234, bounds
, root_window()));
2618 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2619 kTouchId1
, tes
.Now());
2620 DispatchEventUsingWindowDispatcher(&press1
);
2623 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2624 kTouchId2
, tes
.Now());
2625 DispatchEventUsingWindowDispatcher(&press2
);
2627 // Send release event after sufficient delay so that two finger time expires.
2629 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2630 kTouchId1
, tes
.LeapForward(1000));
2632 DispatchEventUsingWindowDispatcher(&release1
);
2633 EXPECT_FALSE(delegate
->two_finger_tap());
2635 // Lift second finger.
2636 // Make sure there is enough delay before the touch is released so that it is
2637 // recognized as a tap.
2639 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
2640 kTouchId2
, tes
.LeapForward(50));
2642 DispatchEventUsingWindowDispatcher(&release2
);
2643 EXPECT_FALSE(delegate
->two_finger_tap());
2646 TEST_F(GestureRecognizerTest
, TwoFingerTapChangesToPinch
) {
2647 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2648 new GestureEventConsumeDelegate());
2649 const int kWindowWidth
= 123;
2650 const int kWindowHeight
= 45;
2651 const int kTouchId1
= 2;
2652 const int kTouchId2
= 3;
2655 // Test moving first finger
2657 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2658 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2659 delegate
.get(), -1234, bounds
, root_window()));
2662 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2663 kTouchId1
, tes
.Now());
2664 DispatchEventUsingWindowDispatcher(&press1
);
2667 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2668 kTouchId2
, tes
.Now());
2669 DispatchEventUsingWindowDispatcher(&press2
);
2671 tes
.SendScrollEvent(event_processor(), 230, 330, kTouchId1
, delegate
.get());
2672 EXPECT_FALSE(delegate
->two_finger_tap());
2673 EXPECT_TRUE(delegate
->pinch_begin());
2675 // Make sure there is enough delay before the touch is released so that it
2676 // is recognized as a tap.
2678 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2679 kTouchId2
, tes
.LeapForward(50));
2681 DispatchEventUsingWindowDispatcher(&release
);
2682 EXPECT_FALSE(delegate
->two_finger_tap());
2683 EXPECT_TRUE(delegate
->pinch_end());
2686 // Test moving second finger
2688 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2689 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2690 delegate
.get(), -1234, bounds
, root_window()));
2693 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2694 kTouchId1
, tes
.Now());
2695 DispatchEventUsingWindowDispatcher(&press1
);
2698 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2699 kTouchId2
, tes
.Now());
2700 DispatchEventUsingWindowDispatcher(&press2
);
2702 tes
.SendScrollEvent(event_processor(), 301, 230, kTouchId2
, delegate
.get());
2703 EXPECT_FALSE(delegate
->two_finger_tap());
2704 EXPECT_TRUE(delegate
->pinch_begin());
2706 // Make sure there is enough delay before the touch is released so that it
2707 // is recognized as a tap.
2709 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2710 kTouchId1
, tes
.LeapForward(50));
2712 DispatchEventUsingWindowDispatcher(&release
);
2713 EXPECT_FALSE(delegate
->two_finger_tap());
2714 EXPECT_TRUE(delegate
->pinch_end());
2718 TEST_F(GestureRecognizerTest
, NoTwoFingerTapWhenFirstFingerHasScrolled
) {
2719 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2720 new GestureEventConsumeDelegate());
2721 const int kWindowWidth
= 123;
2722 const int kWindowHeight
= 45;
2723 const int kTouchId1
= 2;
2724 const int kTouchId2
= 3;
2727 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2728 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2729 delegate
.get(), -1234, bounds
, root_window()));
2732 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2733 kTouchId1
, tes
.Now());
2734 DispatchEventUsingWindowDispatcher(&press1
);
2735 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId1
, delegate
.get());
2738 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2739 kTouchId2
, tes
.Now());
2740 DispatchEventUsingWindowDispatcher(&press2
);
2742 EXPECT_FALSE(delegate
->pinch_begin());
2744 // Make sure there is enough delay before the touch is released so that it
2745 // is recognized as a tap.
2747 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2748 kTouchId2
, tes
.LeapForward(50));
2750 DispatchEventUsingWindowDispatcher(&release
);
2751 EXPECT_FALSE(delegate
->two_finger_tap());
2752 EXPECT_FALSE(delegate
->pinch_end());
2755 TEST_F(GestureRecognizerTest
, MultiFingerSwipe
) {
2756 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2757 new GestureEventConsumeDelegate());
2758 const int kWindowWidth
= 123;
2759 const int kWindowHeight
= 45;
2761 gfx::Rect
bounds(5, 10, kWindowWidth
, kWindowHeight
);
2762 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2763 delegate
.get(), -1234, bounds
, root_window()));
2765 const int kSteps
= 15;
2766 const int kTouchPoints
= 4;
2767 gfx::Point points
[kTouchPoints
] = {
2774 ui::test::EventGenerator
generator(root_window(), window
.get());
2776 // The unified gesture recognizer assumes a finger has stopped if it hasn't
2777 // moved for too long. See ui/events/gesture_detection/velocity_tracker.cc's
2778 // kAssumePointerStoppedTimeMs.
2779 for (int count
= 2; count
<= kTouchPoints
; ++count
) {
2780 generator
.GestureMultiFingerScroll(
2781 count
, points
, 10, kSteps
, 0, -11 * kSteps
);
2782 EXPECT_TRUE(delegate
->swipe_up());
2785 generator
.GestureMultiFingerScroll(
2786 count
, points
, 10, kSteps
, 0, 11 * kSteps
);
2787 EXPECT_TRUE(delegate
->swipe_down());
2790 generator
.GestureMultiFingerScroll(
2791 count
, points
, 10, kSteps
, -11 * kSteps
, 0);
2792 EXPECT_TRUE(delegate
->swipe_left());
2795 generator
.GestureMultiFingerScroll(
2796 count
, points
, 10, kSteps
, 11 * kSteps
, 0);
2797 EXPECT_TRUE(delegate
->swipe_right());
2800 generator
.GestureMultiFingerScroll(
2801 count
, points
, 10, kSteps
, 5 * kSteps
, 12 * kSteps
);
2802 EXPECT_FALSE(delegate
->swipe_down());
2805 generator
.GestureMultiFingerScroll(
2806 count
, points
, 10, kSteps
, 4 * kSteps
, 12 * kSteps
);
2807 EXPECT_TRUE(delegate
->swipe_down());
2810 generator
.GestureMultiFingerScroll(
2811 count
, points
, 10, kSteps
, 3 * kSteps
, 12 * kSteps
);
2812 EXPECT_TRUE(delegate
->swipe_down());
2817 TEST_F(GestureRecognizerTest
, TwoFingerTapCancelled
) {
2818 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2819 new GestureEventConsumeDelegate());
2820 const int kWindowWidth
= 123;
2821 const int kWindowHeight
= 45;
2822 const int kTouchId1
= 2;
2823 const int kTouchId2
= 3;
2826 // Test canceling first finger.
2828 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2829 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2830 delegate
.get(), -1234, bounds
, root_window()));
2833 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2834 kTouchId1
, tes
.Now());
2835 DispatchEventUsingWindowDispatcher(&press1
);
2838 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2839 kTouchId2
, tes
.Now());
2840 DispatchEventUsingWindowDispatcher(&press2
);
2843 ui::TouchEvent
cancel(ui::ET_TOUCH_CANCELLED
, gfx::Point(130, 201),
2844 kTouchId1
, tes
.Now());
2845 DispatchEventUsingWindowDispatcher(&cancel
);
2846 EXPECT_FALSE(delegate
->two_finger_tap());
2848 // Make sure there is enough delay before the touch is released so that it
2849 // is recognized as a tap.
2851 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2852 kTouchId2
, tes
.LeapForward(50));
2854 DispatchEventUsingWindowDispatcher(&release
);
2855 EXPECT_FALSE(delegate
->two_finger_tap());
2858 // Test canceling second finger
2860 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2861 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2862 delegate
.get(), -1234, bounds
, root_window()));
2865 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2866 kTouchId1
, tes
.Now());
2867 DispatchEventUsingWindowDispatcher(&press1
);
2870 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
2871 kTouchId2
, tes
.Now());
2872 DispatchEventUsingWindowDispatcher(&press2
);
2875 ui::TouchEvent
cancel(ui::ET_TOUCH_CANCELLED
, gfx::Point(130, 201),
2876 kTouchId2
, tes
.Now());
2877 DispatchEventUsingWindowDispatcher(&cancel
);
2878 EXPECT_FALSE(delegate
->two_finger_tap());
2880 // Make sure there is enough delay before the touch is released so that it
2881 // is recognized as a tap.
2883 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
2884 kTouchId1
, tes
.LeapForward(50));
2886 DispatchEventUsingWindowDispatcher(&release
);
2887 EXPECT_FALSE(delegate
->two_finger_tap());
2891 TEST_F(GestureRecognizerTest
, VeryWideTwoFingerTouchDownShouldBeAPinch
) {
2892 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2893 new GestureEventConsumeDelegate());
2894 const int kWindowWidth
= 523;
2895 const int kWindowHeight
= 45;
2896 const int kTouchId1
= 2;
2897 const int kTouchId2
= 3;
2898 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
2899 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2900 delegate
.get(), -1234, bounds
, root_window()));
2904 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2905 kTouchId1
, tes
.Now());
2906 DispatchEventUsingWindowDispatcher(&press1
);
2907 EXPECT_FALSE(delegate
->tap());
2908 EXPECT_TRUE(delegate
->tap_down());
2909 EXPECT_FALSE(delegate
->tap_cancel());
2910 EXPECT_FALSE(delegate
->scroll_begin());
2911 EXPECT_FALSE(delegate
->scroll_update());
2912 EXPECT_FALSE(delegate
->scroll_end());
2913 EXPECT_FALSE(delegate
->long_press());
2914 EXPECT_FALSE(delegate
->two_finger_tap());
2917 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(430, 201),
2918 kTouchId2
, tes
.Now());
2919 DispatchEventUsingWindowDispatcher(&press2
);
2920 EXPECT_FALSE(delegate
->tap());
2921 EXPECT_FALSE(delegate
->tap_down()); // no touch down for second tap.
2922 EXPECT_TRUE(delegate
->tap_cancel());
2923 EXPECT_FALSE(delegate
->scroll_begin());
2924 EXPECT_FALSE(delegate
->scroll_update());
2925 EXPECT_FALSE(delegate
->scroll_end());
2926 EXPECT_FALSE(delegate
->long_press());
2927 EXPECT_FALSE(delegate
->two_finger_tap());
2928 EXPECT_FALSE(delegate
->pinch_begin());
2931 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(530, 301),
2932 kTouchId2
, tes
.Now());
2933 DispatchEventUsingWindowDispatcher(&move2
);
2934 EXPECT_FALSE(delegate
->tap());
2935 EXPECT_FALSE(delegate
->tap_down());
2936 EXPECT_FALSE(delegate
->tap_cancel());
2937 // Pinch & Scroll only when there is enough movement.
2938 EXPECT_TRUE(delegate
->scroll_begin());
2939 EXPECT_TRUE(delegate
->scroll_update());
2940 EXPECT_FALSE(delegate
->scroll_end());
2941 EXPECT_FALSE(delegate
->long_press());
2942 EXPECT_FALSE(delegate
->two_finger_tap());
2943 EXPECT_TRUE(delegate
->pinch_begin());
2946 // Verifies if a window is the target of multiple touch-ids and we hide the
2947 // window everything is cleaned up correctly.
2948 TEST_F(GestureRecognizerTest
, FlushAllOnHide
) {
2949 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
2950 new GestureEventConsumeDelegate());
2951 gfx::Rect
bounds(0, 0, 200, 200);
2952 scoped_ptr
<aura::Window
> window(
2953 CreateTestWindowWithDelegate(delegate
.get(), 0, bounds
, root_window()));
2954 const int kTouchId1
= 8;
2955 const int kTouchId2
= 2;
2958 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
2959 kTouchId1
, tes
.Now());
2960 DispatchEventUsingWindowDispatcher(&press1
);
2961 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20),
2962 kTouchId2
, tes
.Now());
2963 DispatchEventUsingWindowDispatcher(&press2
);
2966 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1
));
2968 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2
));
2971 TEST_F(GestureRecognizerTest
, LongPressTimerStopsOnPreventDefaultedTouchMoves
) {
2972 scoped_ptr
<QueueTouchEventDelegate
> delegate(
2973 new QueueTouchEventDelegate(host()->dispatcher()));
2974 const int kTouchId
= 2;
2975 gfx::Rect
bounds(100, 200, 100, 100);
2976 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
2977 delegate
.get(), -1234, bounds
, root_window()));
2978 delegate
->set_window(window
.get());
2982 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
2983 kTouchId
, tes
.Now());
2984 DispatchEventUsingWindowDispatcher(&press
);
2985 // Scroll around, to cancel the long press
2986 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
2989 delegate
->ReceivedAck();
2990 EXPECT_TRUE(delegate
->tap_down());
2992 // Wait long enough that long press would have fired if the touchmove hadn't
2994 DelayByLongPressTimeout();
2997 delegate
->ReceivedAckPreventDefaulted();
2998 EXPECT_FALSE(delegate
->long_press());
3001 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events.
3002 class ConsumesTouchMovesDelegate
: public GestureEventConsumeDelegate
{
3004 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {}
3005 ~ConsumesTouchMovesDelegate() override
{}
3007 void set_consume_touch_move(bool consume
) { consume_touch_move_
= consume
; }
3010 void OnTouchEvent(ui::TouchEvent
* touch
) override
{
3011 if (consume_touch_move_
&& touch
->type() == ui::ET_TOUCH_MOVED
)
3012 touch
->SetHandled();
3014 GestureEventConsumeDelegate::OnTouchEvent(touch
);
3017 bool consume_touch_move_
;
3019 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate
);
3022 // Same as GestureEventScroll, but tests that the behavior is the same
3023 // even if all the touch-move events are consumed.
3024 TEST_F(GestureRecognizerTest
, GestureEventScrollTouchMoveConsumed
) {
3025 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3026 new ConsumesTouchMovesDelegate());
3027 const int kWindowWidth
= 123;
3028 const int kWindowHeight
= 45;
3029 const int kTouchId
= 5;
3030 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3031 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3032 delegate
.get(), -1234, bounds
, root_window()));
3036 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3037 kTouchId
, tes
.Now());
3038 DispatchEventUsingWindowDispatcher(&press
);
3039 EXPECT_FALSE(delegate
->tap());
3040 EXPECT_TRUE(delegate
->tap_down());
3041 EXPECT_FALSE(delegate
->tap_cancel());
3042 EXPECT_TRUE(delegate
->begin());
3043 EXPECT_FALSE(delegate
->scroll_begin());
3044 EXPECT_FALSE(delegate
->scroll_update());
3045 EXPECT_FALSE(delegate
->scroll_end());
3047 // Move the touch-point enough so that it would normally be considered a
3048 // scroll. But since the touch-moves will be consumed, the scroll should not
3050 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3051 EXPECT_FALSE(delegate
->tap());
3052 EXPECT_FALSE(delegate
->tap_down());
3053 EXPECT_TRUE(delegate
->tap_cancel());
3054 EXPECT_FALSE(delegate
->begin());
3055 EXPECT_FALSE(delegate
->scroll_update());
3056 EXPECT_FALSE(delegate
->scroll_end());
3058 EXPECT_TRUE(delegate
->scroll_begin());
3060 // Release the touch back at the start point. This should end without causing
3063 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 230),
3064 kTouchId
, tes
.LeapForward(50));
3065 DispatchEventUsingWindowDispatcher(&release
);
3066 EXPECT_FALSE(delegate
->tap());
3067 EXPECT_FALSE(delegate
->tap_down());
3068 EXPECT_FALSE(delegate
->tap_cancel());
3069 EXPECT_FALSE(delegate
->begin());
3070 EXPECT_TRUE(delegate
->end());
3071 EXPECT_FALSE(delegate
->scroll_begin());
3072 EXPECT_FALSE(delegate
->scroll_update());
3074 EXPECT_TRUE(delegate
->scroll_end());
3077 // Tests the behavior of 2F scroll when some of the touch-move events are
3079 TEST_F(GestureRecognizerTest
, GestureEventScrollTwoFingerTouchMoveConsumed
) {
3080 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3081 new ConsumesTouchMovesDelegate());
3082 const int kWindowWidth
= 123;
3083 const int kWindowHeight
= 100;
3084 const int kTouchId1
= 2;
3085 const int kTouchId2
= 3;
3088 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3089 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3090 delegate
.get(), -1234, bounds
, root_window()));
3093 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3094 kTouchId1
, tes
.Now());
3095 DispatchEventUsingWindowDispatcher(&press1
);
3096 tes
.SendScrollEvent(event_processor(), 131, 231, kTouchId1
, delegate
.get());
3098 EXPECT_2_EVENTS(delegate
->events(),
3099 ui::ET_GESTURE_TAP_CANCEL
,
3100 ui::ET_GESTURE_SCROLL_BEGIN
);
3103 // Second finger touches down and moves.
3104 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(130, 201),
3105 kTouchId2
, tes
.LeapForward(50));
3106 DispatchEventUsingWindowDispatcher(&press2
);
3107 tes
.SendScrollEvent(event_processor(), 161, 231, kTouchId2
, delegate
.get());
3108 EXPECT_0_EVENTS(delegate
->events());
3111 // Move first finger again, no PinchUpdate & ScrollUpdate.
3112 tes
.SendScrollEvent(event_processor(), 161, 261, kTouchId1
, delegate
.get());
3113 EXPECT_0_EVENTS(delegate
->events());
3115 // Stops consuming touch-move.
3116 delegate
->set_consume_touch_move(false);
3119 // Making a pinch gesture.
3120 tes
.SendScrollEvent(event_processor(), 161, 260, kTouchId1
, delegate
.get());
3121 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
3124 tes
.SendScrollEvent(event_processor(), 161, 261, kTouchId2
, delegate
.get());
3125 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
3128 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3129 kTouchId1
, tes
.Now());
3130 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(130, 201),
3131 kTouchId2
, tes
.Now());
3132 DispatchEventUsingWindowDispatcher(&release1
);
3133 DispatchEventUsingWindowDispatcher(&release2
);
3135 EXPECT_3_EVENTS(delegate
->events(),
3137 ui::ET_SCROLL_FLING_START
,
3138 ui::ET_GESTURE_END
);
3141 // Like as GestureEventTouchMoveConsumed but tests the different behavior
3142 // depending on whether the events were consumed before or after the scroll
3144 TEST_F(GestureRecognizerTest
, GestureEventScrollTouchMovePartialConsumed
) {
3145 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3146 new ConsumesTouchMovesDelegate());
3147 const int kWindowWidth
= 123;
3148 const int kWindowHeight
= 45;
3149 const int kTouchId
= 5;
3150 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3151 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3152 delegate
.get(), -1234, bounds
, root_window()));
3156 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3157 kTouchId
, tes
.Now());
3158 DispatchEventUsingWindowDispatcher(&press
);
3159 EXPECT_FALSE(delegate
->tap());
3160 EXPECT_TRUE(delegate
->tap_down());
3161 EXPECT_FALSE(delegate
->tap_cancel());
3162 EXPECT_TRUE(delegate
->begin());
3163 EXPECT_FALSE(delegate
->scroll_begin());
3164 EXPECT_FALSE(delegate
->scroll_update());
3165 EXPECT_FALSE(delegate
->scroll_end());
3167 // Move the touch-point enough so that it would normally be considered a
3168 // scroll. But since the touch-moves will be consumed, the scroll should not
3170 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3171 EXPECT_FALSE(delegate
->tap());
3172 EXPECT_FALSE(delegate
->tap_down());
3173 EXPECT_TRUE(delegate
->tap_cancel());
3174 EXPECT_FALSE(delegate
->begin());
3175 EXPECT_FALSE(delegate
->scroll_update());
3176 EXPECT_FALSE(delegate
->scroll_end());
3178 // Consuming the first touch move event won't prevent all future scrolling.
3179 EXPECT_TRUE(delegate
->scroll_begin());
3181 // Now, stop consuming touch-move events, and move the touch-point again.
3182 delegate
->set_consume_touch_move(false);
3183 tes
.SendScrollEvent(event_processor(), 159, 259, kTouchId
, delegate
.get());
3184 EXPECT_FALSE(delegate
->tap());
3185 EXPECT_FALSE(delegate
->tap_down());
3186 EXPECT_FALSE(delegate
->tap_cancel());
3187 EXPECT_FALSE(delegate
->begin());
3188 EXPECT_FALSE(delegate
->scroll_begin());
3189 EXPECT_FALSE(delegate
->scroll_end());
3191 // Scroll not prevented by consumed first touch move.
3192 EXPECT_TRUE(delegate
->scroll_update());
3193 EXPECT_EQ(29, delegate
->scroll_x());
3194 EXPECT_EQ(29, delegate
->scroll_y());
3195 EXPECT_EQ(gfx::Point(0, 0).ToString(),
3196 delegate
->scroll_begin_position().ToString());
3198 // Start consuming touch-move events again.
3199 delegate
->set_consume_touch_move(true);
3201 // Move some more to generate a few more scroll updates.
3202 tes
.SendScrollEvent(event_processor(), 110, 211, kTouchId
, delegate
.get());
3203 EXPECT_FALSE(delegate
->tap());
3204 EXPECT_FALSE(delegate
->tap_down());
3205 EXPECT_FALSE(delegate
->tap_cancel());
3206 EXPECT_FALSE(delegate
->begin());
3207 EXPECT_FALSE(delegate
->scroll_begin());
3208 EXPECT_FALSE(delegate
->scroll_update());
3209 EXPECT_FALSE(delegate
->scroll_end());
3210 EXPECT_EQ(0, delegate
->scroll_x());
3211 EXPECT_EQ(0, delegate
->scroll_y());
3213 tes
.SendScrollEvent(event_processor(), 140, 215, kTouchId
, delegate
.get());
3214 EXPECT_FALSE(delegate
->tap());
3215 EXPECT_FALSE(delegate
->tap_down());
3216 EXPECT_FALSE(delegate
->tap_cancel());
3217 EXPECT_FALSE(delegate
->begin());
3218 EXPECT_FALSE(delegate
->scroll_begin());
3219 EXPECT_FALSE(delegate
->scroll_update());
3220 EXPECT_FALSE(delegate
->scroll_end());
3221 EXPECT_EQ(0, delegate
->scroll_x());
3222 EXPECT_EQ(0, delegate
->scroll_y());
3224 // Release the touch.
3226 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3227 kTouchId
, tes
.LeapForward(50));
3228 DispatchEventUsingWindowDispatcher(&release
);
3229 EXPECT_FALSE(delegate
->tap());
3230 EXPECT_FALSE(delegate
->tap_down());
3231 EXPECT_FALSE(delegate
->tap_cancel());
3232 EXPECT_FALSE(delegate
->begin());
3233 EXPECT_TRUE(delegate
->end());
3234 EXPECT_FALSE(delegate
->scroll_begin());
3235 EXPECT_FALSE(delegate
->scroll_update());
3236 EXPECT_FALSE(delegate
->fling());
3238 EXPECT_TRUE(delegate
->scroll_end());
3241 // Check that appropriate touch events generate double tap gesture events.
3242 TEST_F(GestureRecognizerTest
, GestureEventDoubleTap
) {
3243 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3244 new GestureEventConsumeDelegate());
3245 const int kWindowWidth
= 123;
3246 const int kWindowHeight
= 45;
3247 const int kTouchId
= 2;
3248 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3249 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3250 delegate
.get(), -1234, bounds
, root_window()));
3253 // First tap (tested in GestureEventTap)
3254 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(104, 201),
3255 kTouchId
, tes
.Now());
3256 DispatchEventUsingWindowDispatcher(&press1
);
3257 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(104, 201),
3258 kTouchId
, tes
.LeapForward(50));
3259 DispatchEventUsingWindowDispatcher(&release1
);
3263 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 203),
3264 kTouchId
, tes
.LeapForward(200));
3265 DispatchEventUsingWindowDispatcher(&press2
);
3266 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3267 kTouchId
, tes
.LeapForward(50));
3268 DispatchEventUsingWindowDispatcher(&release2
);
3270 EXPECT_TRUE(delegate
->tap());
3271 EXPECT_TRUE(delegate
->tap_down());
3272 EXPECT_FALSE(delegate
->tap_cancel());
3273 EXPECT_TRUE(delegate
->begin());
3274 EXPECT_TRUE(delegate
->end());
3275 EXPECT_FALSE(delegate
->scroll_begin());
3276 EXPECT_FALSE(delegate
->scroll_update());
3277 EXPECT_FALSE(delegate
->scroll_end());
3279 EXPECT_EQ(2, delegate
->tap_count());
3282 // Check that appropriate touch events generate triple tap gesture events.
3283 TEST_F(GestureRecognizerTest
, GestureEventTripleTap
) {
3284 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3285 new GestureEventConsumeDelegate());
3286 const int kWindowWidth
= 123;
3287 const int kWindowHeight
= 45;
3288 const int kTouchId
= 2;
3289 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3290 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3291 delegate
.get(), -1234, bounds
, root_window()));
3294 // First tap (tested in GestureEventTap)
3295 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(104, 201),
3296 kTouchId
, tes
.Now());
3297 DispatchEventUsingWindowDispatcher(&press1
);
3298 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(104, 201),
3299 kTouchId
, tes
.LeapForward(50));
3300 DispatchEventUsingWindowDispatcher(&release1
);
3302 EXPECT_EQ(1, delegate
->tap_count());
3305 // Second tap (tested in GestureEventDoubleTap)
3306 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 203),
3307 kTouchId
, tes
.LeapForward(200));
3308 DispatchEventUsingWindowDispatcher(&press2
);
3309 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3310 kTouchId
, tes
.LeapForward(50));
3311 DispatchEventUsingWindowDispatcher(&release2
);
3313 EXPECT_EQ(2, delegate
->tap_count());
3317 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
, gfx::Point(102, 206),
3318 kTouchId
, tes
.LeapForward(200));
3319 DispatchEventUsingWindowDispatcher(&press3
);
3320 ui::TouchEvent
release3(ui::ET_TOUCH_RELEASED
, gfx::Point(102, 206),
3321 kTouchId
, tes
.LeapForward(50));
3322 DispatchEventUsingWindowDispatcher(&release3
);
3324 // Third, Fourth and Fifth Taps. Taps after the third should have their
3325 // |tap_count| wrap around back to 1.
3326 for (int i
= 3; i
< 5; ++i
) {
3327 ui::TouchEvent
press3(ui::ET_TOUCH_PRESSED
,
3328 gfx::Point(102, 206),
3330 tes
.LeapForward(200));
3331 DispatchEventUsingWindowDispatcher(&press3
);
3332 ui::TouchEvent
release3(ui::ET_TOUCH_RELEASED
,
3333 gfx::Point(102, 206),
3335 tes
.LeapForward(50));
3336 DispatchEventUsingWindowDispatcher(&release3
);
3338 EXPECT_TRUE(delegate
->tap());
3339 EXPECT_TRUE(delegate
->tap_down());
3340 EXPECT_FALSE(delegate
->tap_cancel());
3341 EXPECT_TRUE(delegate
->begin());
3342 EXPECT_TRUE(delegate
->end());
3343 EXPECT_FALSE(delegate
->scroll_begin());
3344 EXPECT_FALSE(delegate
->scroll_update());
3345 EXPECT_FALSE(delegate
->scroll_end());
3346 EXPECT_EQ(1 + (i
% 3), delegate
->tap_count());
3350 // Check that we don't get a double tap when the two taps are far apart.
3351 TEST_F(GestureRecognizerTest
, TwoTapsFarApart
) {
3352 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3353 new GestureEventConsumeDelegate());
3354 const int kWindowWidth
= 123;
3355 const int kWindowHeight
= 45;
3356 const int kTouchId
= 2;
3357 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3358 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3359 delegate
.get(), -1234, bounds
, root_window()));
3362 // First tap (tested in GestureEventTap)
3363 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3364 kTouchId
, tes
.Now());
3365 DispatchEventUsingWindowDispatcher(&press1
);
3366 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3367 kTouchId
, tes
.LeapForward(50));
3368 DispatchEventUsingWindowDispatcher(&release1
);
3371 // Second tap, close in time but far in distance
3372 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(201, 201),
3373 kTouchId
, tes
.LeapForward(200));
3374 DispatchEventUsingWindowDispatcher(&press2
);
3375 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(201, 201),
3376 kTouchId
, tes
.LeapForward(50));
3377 DispatchEventUsingWindowDispatcher(&release2
);
3379 EXPECT_TRUE(delegate
->tap());
3380 EXPECT_TRUE(delegate
->tap_down());
3381 EXPECT_FALSE(delegate
->tap_cancel());
3382 EXPECT_TRUE(delegate
->begin());
3383 EXPECT_TRUE(delegate
->end());
3384 EXPECT_FALSE(delegate
->scroll_begin());
3385 EXPECT_FALSE(delegate
->scroll_update());
3386 EXPECT_FALSE(delegate
->scroll_end());
3388 EXPECT_EQ(1, delegate
->tap_count());
3391 // Check that we don't get a double tap when the two taps have a long enough
3392 // delay in between.
3393 TEST_F(GestureRecognizerTest
, TwoTapsWithDelayBetween
) {
3394 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3395 new GestureEventConsumeDelegate());
3396 const int kWindowWidth
= 123;
3397 const int kWindowHeight
= 45;
3398 const int kTouchId
= 2;
3399 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3400 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3401 delegate
.get(), -1234, bounds
, root_window()));
3404 // First tap (tested in GestureEventTap)
3405 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3406 kTouchId
, tes
.Now());
3407 DispatchEventUsingWindowDispatcher(&press1
);
3408 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3409 kTouchId
, tes
.LeapForward(50));
3410 DispatchEventUsingWindowDispatcher(&release1
);
3413 // Second tap, close in distance but after some delay
3414 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3415 kTouchId
, tes
.LeapForward(2000));
3416 DispatchEventUsingWindowDispatcher(&press2
);
3417 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3418 kTouchId
, tes
.LeapForward(50));
3419 DispatchEventUsingWindowDispatcher(&release2
);
3421 EXPECT_TRUE(delegate
->tap());
3422 EXPECT_TRUE(delegate
->tap_down());
3423 EXPECT_FALSE(delegate
->tap_cancel());
3424 EXPECT_TRUE(delegate
->begin());
3425 EXPECT_TRUE(delegate
->end());
3426 EXPECT_FALSE(delegate
->scroll_begin());
3427 EXPECT_FALSE(delegate
->scroll_update());
3428 EXPECT_FALSE(delegate
->scroll_end());
3430 EXPECT_EQ(1, delegate
->tap_count());
3433 // Checks that if the bounding-box of a gesture changes because of change in
3434 // radius of a touch-point, and not because of change in position, then there
3435 // are not gesture events from that.
3436 TEST_F(GestureRecognizerTest
, BoundingBoxRadiusChange
) {
3437 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3438 new GestureEventConsumeDelegate());
3439 const int kWindowWidth
= 234;
3440 const int kWindowHeight
= 345;
3441 const int kTouchId
= 5, kTouchId2
= 7;
3442 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3443 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3444 delegate
.get(), -1234, bounds
, root_window()));
3447 ui::TouchEvent
press1(
3448 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId
, tes
.Now());
3449 DispatchEventUsingWindowDispatcher(&press1
);
3450 EXPECT_TRUE(delegate
->bounding_box().IsEmpty());
3454 ui::TouchEvent
press2(
3455 ui::ET_TOUCH_PRESSED
, gfx::Point(201, 201), kTouchId2
,
3456 tes
.LeapForward(400));
3457 press2
.set_radius_x(5);
3458 DispatchEventUsingWindowDispatcher(&press2
);
3459 EXPECT_FALSE(delegate
->pinch_begin());
3460 EXPECT_EQ(gfx::Rect(101, 196, 105, 10).ToString(),
3461 delegate
->bounding_box().ToString());
3465 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(50, 50), kTouchId
,
3466 tes
.LeapForward(40));
3467 DispatchEventUsingWindowDispatcher(&move1
);
3468 EXPECT_TRUE(delegate
->pinch_begin());
3469 EXPECT_EQ(gfx::Rect(50, 50, 156, 156).ToString(),
3470 delegate
->bounding_box().ToString());
3474 // The position doesn't move, but the radius changes.
3475 ui::TouchEvent
move2(
3476 ui::ET_TOUCH_MOVED
, gfx::Point(50, 50), kTouchId
, tes
.LeapForward(40));
3477 move2
.set_radius_x(50);
3478 move2
.set_radius_y(60);
3479 DispatchEventUsingWindowDispatcher(&move2
);
3480 EXPECT_FALSE(delegate
->tap());
3481 EXPECT_FALSE(delegate
->tap_cancel());
3482 EXPECT_FALSE(delegate
->scroll_update());
3483 EXPECT_FALSE(delegate
->pinch_update());
3488 // Checks that slow scrolls deliver the correct deltas.
3489 // In particular, fix for http;//crbug.com/150573.
3490 TEST_F(GestureRecognizerTest
, NoDriftInScroll
) {
3491 ui::GestureConfiguration::GetInstance()
3492 ->set_max_touch_move_in_pixels_for_click(3);
3493 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3494 new GestureEventConsumeDelegate());
3495 const int kWindowWidth
= 234;
3496 const int kWindowHeight
= 345;
3497 const int kTouchId
= 5;
3499 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3500 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3501 delegate
.get(), -1234, bounds
, root_window()));
3503 ui::TouchEvent
press1(
3504 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 208), kTouchId
, tes
.Now());
3505 DispatchEventUsingWindowDispatcher(&press1
);
3506 EXPECT_TRUE(delegate
->begin());
3510 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(101, 206), kTouchId
,
3511 tes
.LeapForward(40));
3512 DispatchEventUsingWindowDispatcher(&move1
);
3513 EXPECT_FALSE(delegate
->scroll_begin());
3517 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(101, 204), kTouchId
,
3518 tes
.LeapForward(40));
3519 DispatchEventUsingWindowDispatcher(&move2
);
3520 EXPECT_TRUE(delegate
->tap_cancel());
3521 EXPECT_TRUE(delegate
->scroll_begin());
3522 EXPECT_TRUE(delegate
->scroll_update());
3523 // 3 px consumed by touch slop region.
3524 EXPECT_EQ(-1, delegate
->scroll_y());
3525 EXPECT_EQ(-4, delegate
->scroll_y_hint());
3529 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(101, 204), kTouchId
,
3530 tes
.LeapForward(40));
3531 DispatchEventUsingWindowDispatcher(&move3
);
3532 EXPECT_FALSE(delegate
->scroll_update());
3536 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(101, 203), kTouchId
,
3537 tes
.LeapForward(40));
3538 DispatchEventUsingWindowDispatcher(&move4
);
3539 EXPECT_TRUE(delegate
->scroll_update());
3540 EXPECT_EQ(-1, delegate
->scroll_y());
3545 // Ensure that move events which are preventDefaulted will cause a tap
3546 // cancel gesture event to be fired if the move would normally cause a
3547 // scroll. See bug http://crbug.com/146397.
3548 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveCanFireTapCancel
) {
3549 scoped_ptr
<ConsumesTouchMovesDelegate
> delegate(
3550 new ConsumesTouchMovesDelegate());
3551 const int kTouchId
= 5;
3552 gfx::Rect
bounds(100, 200, 123, 45);
3553 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3554 delegate
.get(), -1234, bounds
, root_window()));
3558 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3559 kTouchId
, tes
.Now());
3561 delegate
->set_consume_touch_move(false);
3562 DispatchEventUsingWindowDispatcher(&press
);
3563 delegate
->set_consume_touch_move(true);
3565 // Move the touch-point enough so that it would normally be considered a
3566 // scroll. But since the touch-moves will be consumed, no scrolling should
3568 // With the unified gesture detector, we will receive a scroll begin gesture,
3569 // whereas with the aura gesture recognizer we won't.
3570 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3571 EXPECT_FALSE(delegate
->tap());
3572 EXPECT_FALSE(delegate
->tap_down());
3573 EXPECT_TRUE(delegate
->tap_cancel());
3574 EXPECT_FALSE(delegate
->begin());
3575 EXPECT_FALSE(delegate
->scroll_update());
3576 EXPECT_FALSE(delegate
->scroll_end());
3579 TEST_F(GestureRecognizerTest
, CancelAllActiveTouches
) {
3580 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3581 new GestureEventConsumeDelegate());
3583 const int kWindowWidth
= 800;
3584 const int kWindowHeight
= 600;
3585 const int kTouchId1
= 1;
3586 const int kTouchId2
= 2;
3587 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3588 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3589 delegate
.get(), -1234, bounds
, root_window()));
3590 scoped_ptr
<TestEventHandler
> handler(new TestEventHandler());
3591 window
->AddPreTargetHandler(handler
.get());
3593 // Start a gesture sequence on |window|. Then cancel all touches.
3594 // Make sure |window| receives a touch-cancel event.
3596 ui::TouchEvent
press(
3597 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201), kTouchId1
, tes
.Now());
3598 DispatchEventUsingWindowDispatcher(&press
);
3600 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
3603 ui::ET_TOUCH_PRESSED
, gfx::Point(50, 50), kTouchId2
, tes
.Now());
3604 DispatchEventUsingWindowDispatcher(&p2
);
3606 delegate
->events(), ui::ET_GESTURE_TAP_CANCEL
, ui::ET_GESTURE_BEGIN
);
3608 ui::TouchEvent
move(
3609 ui::ET_TOUCH_MOVED
, gfx::Point(350, 300), kTouchId2
, tes
.Now());
3610 DispatchEventUsingWindowDispatcher(&move
);
3611 EXPECT_3_EVENTS(delegate
->events(),
3612 ui::ET_GESTURE_SCROLL_BEGIN
,
3613 ui::ET_GESTURE_SCROLL_UPDATE
,
3614 ui::ET_GESTURE_PINCH_BEGIN
);
3615 EXPECT_EQ(2, handler
->touch_pressed_count());
3619 ui::GestureRecognizer
* gesture_recognizer
= ui::GestureRecognizer::Get();
3620 EXPECT_EQ(window
.get(),
3621 gesture_recognizer
->GetTouchLockedTarget(press
));
3623 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
3625 EXPECT_EQ(NULL
, gesture_recognizer
->GetTouchLockedTarget(press
));
3626 EXPECT_4_EVENTS(delegate
->events(),
3627 ui::ET_GESTURE_PINCH_END
,
3628 ui::ET_GESTURE_SCROLL_END
,
3630 ui::ET_GESTURE_END
);
3631 const std::vector
<gfx::PointF
>& points
= handler
->cancelled_touch_points();
3632 EXPECT_EQ(2U, points
.size());
3633 EXPECT_EQ(gfx::Point(101, 201), points
[0]);
3634 EXPECT_EQ(gfx::Point(350, 300), points
[1]);
3637 // Check that appropriate touch events generate show press events
3638 TEST_F(GestureRecognizerTest
, GestureEventShowPress
) {
3639 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3640 new GestureEventConsumeDelegate());
3642 const int kWindowWidth
= 123;
3643 const int kWindowHeight
= 45;
3644 const int kTouchId
= 2;
3645 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3646 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3647 delegate
.get(), -1234, bounds
, root_window()));
3651 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3652 kTouchId
, tes
.Now());
3653 DispatchEventUsingWindowDispatcher(&press1
);
3654 EXPECT_TRUE(delegate
->tap_down());
3655 EXPECT_TRUE(delegate
->begin());
3656 EXPECT_FALSE(delegate
->tap_cancel());
3658 // We haven't pressed long enough for a show press to occur
3659 EXPECT_FALSE(delegate
->show_press());
3661 // Wait until the timer runs out
3662 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS
);
3663 EXPECT_TRUE(delegate
->show_press());
3664 EXPECT_FALSE(delegate
->tap_cancel());
3667 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3668 kTouchId
, tes
.Now());
3669 DispatchEventUsingWindowDispatcher(&release1
);
3670 EXPECT_FALSE(delegate
->long_press());
3672 // Note the tap isn't dispatched until the release
3673 EXPECT_FALSE(delegate
->tap_cancel());
3674 EXPECT_TRUE(delegate
->tap());
3677 // Check that scrolling cancels a show press
3678 TEST_F(GestureRecognizerTest
, GestureEventShowPressCancelledByScroll
) {
3679 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3680 new GestureEventConsumeDelegate());
3682 const int kWindowWidth
= 123;
3683 const int kWindowHeight
= 45;
3684 const int kTouchId
= 6;
3685 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3686 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3687 delegate
.get(), -1234, bounds
, root_window()));
3691 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3692 kTouchId
, tes
.Now());
3693 DispatchEventUsingWindowDispatcher(&press1
);
3694 EXPECT_TRUE(delegate
->tap_down());
3696 // We haven't pressed long enough for a show press to occur
3697 EXPECT_FALSE(delegate
->show_press());
3698 EXPECT_FALSE(delegate
->tap_cancel());
3700 // Scroll around, to cancel the show press
3701 tes
.SendScrollEvent(event_processor(), 130, 230, kTouchId
, delegate
.get());
3702 // Wait until the timer runs out
3703 DelayByShowPressTimeout();
3704 EXPECT_FALSE(delegate
->show_press());
3705 EXPECT_TRUE(delegate
->tap_cancel());
3708 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3709 kTouchId
, tes
.LeapForward(10));
3710 DispatchEventUsingWindowDispatcher(&release1
);
3711 EXPECT_FALSE(delegate
->show_press());
3712 EXPECT_FALSE(delegate
->tap_cancel());
3715 // Test that show press events are sent immediately on tap
3716 TEST_F(GestureRecognizerTest
, GestureEventShowPressSentOnTap
) {
3717 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3718 new GestureEventConsumeDelegate());
3720 const int kWindowWidth
= 123;
3721 const int kWindowHeight
= 45;
3722 const int kTouchId
= 6;
3723 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3724 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3725 delegate
.get(), -1234, bounds
, root_window()));
3729 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3730 kTouchId
, tes
.Now());
3731 DispatchEventUsingWindowDispatcher(&press1
);
3732 EXPECT_TRUE(delegate
->tap_down());
3734 // We haven't pressed long enough for a show press to occur
3735 EXPECT_FALSE(delegate
->show_press());
3736 EXPECT_FALSE(delegate
->tap_cancel());
3739 ui::TouchEvent
release1(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
3740 kTouchId
, tes
.LeapForward(50));
3741 DispatchEventUsingWindowDispatcher(&release1
);
3742 EXPECT_TRUE(delegate
->show_press());
3743 EXPECT_FALSE(delegate
->tap_cancel());
3744 EXPECT_TRUE(delegate
->tap());
3747 // Test that consuming the first move touch event prevents a scroll.
3748 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveScrollTest
) {
3749 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3750 new QueueTouchEventDelegate(host()->dispatcher()));
3752 const int kTouchId
= 7;
3753 gfx::Rect
bounds(0, 0, 1000, 1000);
3754 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3755 delegate
.get(), -1234, bounds
, root_window()));
3756 delegate
->set_window(window
.get());
3758 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3759 kTouchId
, tes
.Now());
3760 DispatchEventUsingWindowDispatcher(&press
);
3761 delegate
->ReceivedAck();
3763 // A touch move within the slop region is never consumed in web contents. The
3764 // unified GR won't prevent scroll if a touch move within the slop region is
3765 // consumed, so make sure this touch move exceeds the slop region.
3766 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(10, 10),
3767 kTouchId
, tes
.Now());
3768 DispatchEventUsingWindowDispatcher(&move1
);
3769 delegate
->ReceivedAckPreventDefaulted();
3771 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20),
3772 kTouchId
, tes
.Now());
3773 DispatchEventUsingWindowDispatcher(&move2
);
3774 delegate
->ReceivedAck();
3776 // With the unified gesture detector, consuming the first touch move event
3777 // won't prevent all future scrolling.
3778 EXPECT_TRUE(delegate
->scroll_begin());
3779 EXPECT_TRUE(delegate
->scroll_update());
3782 // Test that consuming the first move touch doesn't prevent a tap.
3783 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveTapTest
) {
3784 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3785 new QueueTouchEventDelegate(host()->dispatcher()));
3787 const int kTouchId
= 7;
3788 gfx::Rect
bounds(0, 0, 1000, 1000);
3789 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3790 delegate
.get(), -1234, bounds
, root_window()));
3791 delegate
->set_window(window
.get());
3793 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3794 kTouchId
, tes
.Now());
3795 DispatchEventUsingWindowDispatcher(&press
);
3796 delegate
->ReceivedAck();
3798 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(2, 2),
3799 kTouchId
, tes
.Now());
3800 DispatchEventUsingWindowDispatcher(&move
);
3801 delegate
->ReceivedAckPreventDefaulted();
3803 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(2, 2),
3804 kTouchId
, tes
.LeapForward(50));
3805 DispatchEventUsingWindowDispatcher(&release
);
3806 delegate
->ReceivedAck();
3808 EXPECT_TRUE(delegate
->tap());
3811 // Test that consuming the first move touch doesn't prevent a long press.
3812 TEST_F(GestureRecognizerTest
, GestureEventConsumedTouchMoveLongPressTest
) {
3813 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3814 new QueueTouchEventDelegate(host()->dispatcher()));
3816 const int kWindowWidth
= 123;
3817 const int kWindowHeight
= 45;
3818 const int kTouchId
= 2;
3819 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
3820 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3821 delegate
.get(), -1234, bounds
, root_window()));
3822 delegate
->set_window(window
.get());
3826 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
3827 kTouchId
, tes
.Now());
3828 DispatchEventUsingWindowDispatcher(&press1
);
3829 delegate
->ReceivedAck();
3831 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
, gfx::Point(103, 203),
3832 kTouchId
, tes
.Now());
3833 DispatchEventUsingWindowDispatcher(&move
);
3834 delegate
->ReceivedAckPreventDefaulted();
3836 // Wait until the timer runs out
3837 delegate
->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
3838 EXPECT_TRUE(delegate
->long_press());
3841 // Tests that the deltas are correct when leaving the slop region very slowly.
3842 TEST_F(GestureRecognizerTest
, TestExceedingSlopSlowly
) {
3843 ui::GestureConfiguration::GetInstance()
3844 ->set_max_touch_move_in_pixels_for_click(3);
3845 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
3846 new GestureEventConsumeDelegate());
3847 const int kWindowWidth
= 234;
3848 const int kWindowHeight
= 345;
3849 const int kTouchId
= 5;
3851 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3852 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3853 delegate
.get(), -1234, bounds
, root_window()));
3855 ui::TouchEvent
press(
3856 ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10), kTouchId
, tes
.Now());
3857 DispatchEventUsingWindowDispatcher(&press
);
3858 EXPECT_FALSE(delegate
->scroll_begin());
3859 EXPECT_FALSE(delegate
->scroll_update());
3862 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(11, 10), kTouchId
,
3863 tes
.LeapForward(40));
3864 DispatchEventUsingWindowDispatcher(&move1
);
3865 EXPECT_FALSE(delegate
->scroll_begin());
3866 EXPECT_FALSE(delegate
->scroll_update());
3867 EXPECT_EQ(0, delegate
->scroll_x());
3868 EXPECT_EQ(0, delegate
->scroll_x_hint());
3871 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(12, 10), kTouchId
,
3872 tes
.LeapForward(40));
3873 DispatchEventUsingWindowDispatcher(&move2
);
3874 EXPECT_FALSE(delegate
->scroll_begin());
3875 EXPECT_FALSE(delegate
->scroll_update());
3876 EXPECT_EQ(0, delegate
->scroll_x());
3877 EXPECT_EQ(0, delegate
->scroll_x_hint());
3881 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::PointF(13.1f
, 10.f
), kTouchId
,
3882 tes
.LeapForward(40));
3883 DispatchEventUsingWindowDispatcher(&move3
);
3884 EXPECT_TRUE(delegate
->scroll_begin());
3885 EXPECT_TRUE(delegate
->scroll_update());
3886 EXPECT_NEAR(0.1, delegate
->scroll_x(), 0.0001);
3887 EXPECT_FLOAT_EQ(3.1f
, delegate
->scroll_x_hint());
3890 ui::TouchEvent
move4(ui::ET_TOUCH_MOVED
, gfx::Point(14, 10), kTouchId
,
3891 tes
.LeapForward(40));
3892 DispatchEventUsingWindowDispatcher(&move4
);
3893 EXPECT_FALSE(delegate
->scroll_begin());
3894 EXPECT_TRUE(delegate
->scroll_update());
3895 EXPECT_NEAR(0.9, delegate
->scroll_x(), 0.0001);
3896 EXPECT_EQ(0.f
, delegate
->scroll_x_hint());
3900 TEST_F(GestureRecognizerTest
, ScrollAlternatelyConsumedTest
) {
3901 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3902 new QueueTouchEventDelegate(host()->dispatcher()));
3904 const int kWindowWidth
= 3000;
3905 const int kWindowHeight
= 3000;
3906 const int kTouchId
= 2;
3907 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3908 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3909 delegate
.get(), -1234, bounds
, root_window()));
3910 delegate
->set_window(window
.get());
3917 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(x
, y
),
3918 kTouchId
, tes
.Now());
3919 DispatchEventUsingWindowDispatcher(&press1
);
3920 delegate
->ReceivedAck();
3921 EXPECT_FALSE(delegate
->scroll_begin());
3922 EXPECT_FALSE(delegate
->scroll_update());
3927 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
),
3928 kTouchId
, tes
.Now());
3929 DispatchEventUsingWindowDispatcher(&move1
);
3930 delegate
->ReceivedAck();
3931 EXPECT_TRUE(delegate
->scroll_begin());
3932 EXPECT_TRUE(delegate
->scroll_update());
3935 for (int i
= 0; i
< 3; ++i
) {
3938 ui::TouchEvent
move2(
3939 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId
, tes
.Now());
3940 DispatchEventUsingWindowDispatcher(&move2
);
3941 delegate
->ReceivedAck();
3942 EXPECT_FALSE(delegate
->scroll_begin());
3943 EXPECT_TRUE(delegate
->scroll_update());
3944 EXPECT_EQ(10, delegate
->scroll_x());
3945 EXPECT_EQ(10, delegate
->scroll_y());
3950 ui::TouchEvent
move3(
3951 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId
, tes
.Now());
3952 DispatchEventUsingWindowDispatcher(&move3
);
3953 delegate
->ReceivedAckPreventDefaulted();
3954 EXPECT_FALSE(delegate
->scroll_begin());
3955 EXPECT_FALSE(delegate
->scroll_update());
3960 TEST_F(GestureRecognizerTest
, PinchAlternatelyConsumedTest
) {
3961 scoped_ptr
<QueueTouchEventDelegate
> delegate(
3962 new QueueTouchEventDelegate(host()->dispatcher()));
3964 const int kWindowWidth
= 3000;
3965 const int kWindowHeight
= 3000;
3966 const int kTouchId1
= 5;
3967 const int kTouchId2
= 7;
3968 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
3969 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
3970 delegate
.get(), -1234, bounds
, root_window()));
3971 delegate
->set_window(window
.get());
3974 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0),
3975 kTouchId1
, tes
.Now());
3976 DispatchEventUsingWindowDispatcher(&press1
);
3977 delegate
->ReceivedAck();
3978 EXPECT_FALSE(delegate
->scroll_begin());
3979 EXPECT_FALSE(delegate
->scroll_update());
3985 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(x
, y
),
3986 kTouchId2
, tes
.Now());
3987 DispatchEventUsingWindowDispatcher(&press2
);
3988 delegate
->ReceivedAck();
3989 EXPECT_FALSE(delegate
->scroll_begin());
3990 EXPECT_FALSE(delegate
->scroll_update());
3991 EXPECT_FALSE(delegate
->pinch_begin());
3992 EXPECT_FALSE(delegate
->pinch_update());
3998 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
),
3999 kTouchId2
, tes
.Now());
4000 DispatchEventUsingWindowDispatcher(&move1
);
4001 delegate
->ReceivedAck();
4002 EXPECT_TRUE(delegate
->scroll_begin());
4003 EXPECT_TRUE(delegate
->scroll_update());
4004 EXPECT_TRUE(delegate
->pinch_begin());
4005 EXPECT_FALSE(delegate
->pinch_update());
4008 const float expected_scales
[] = {1.5f
, 1.2f
, 1.125f
};
4010 for (int i
= 0; i
< 3; ++i
) {
4013 ui::TouchEvent
move2(
4014 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId2
, tes
.Now());
4015 DispatchEventUsingWindowDispatcher(&move2
);
4016 delegate
->ReceivedAck();
4017 EXPECT_FALSE(delegate
->scroll_begin());
4018 EXPECT_TRUE(delegate
->scroll_update());
4019 EXPECT_FALSE(delegate
->scroll_end());
4020 EXPECT_FALSE(delegate
->pinch_begin());
4021 EXPECT_TRUE(delegate
->pinch_update());
4022 EXPECT_FALSE(delegate
->pinch_end());
4023 EXPECT_EQ(25, delegate
->scroll_x());
4024 EXPECT_EQ(25, delegate
->scroll_y());
4025 EXPECT_FLOAT_EQ(expected_scales
[i
], delegate
->scale());
4030 ui::TouchEvent
move3(
4031 ui::ET_TOUCH_MOVED
, gfx::Point(x
, y
), kTouchId2
, tes
.Now());
4032 DispatchEventUsingWindowDispatcher(&move3
);
4033 delegate
->ReceivedAckPreventDefaulted();
4034 EXPECT_FALSE(delegate
->scroll_begin());
4035 EXPECT_FALSE(delegate
->scroll_update());
4036 EXPECT_FALSE(delegate
->scroll_end());
4037 EXPECT_FALSE(delegate
->pinch_begin());
4038 EXPECT_FALSE(delegate
->pinch_update());
4039 EXPECT_FALSE(delegate
->pinch_end());
4044 // Test that touch event flags are passed through to the gesture event.
4045 TEST_F(GestureRecognizerTest
, GestureEventFlagsPassedFromTouchEvent
) {
4046 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4047 new GestureEventConsumeDelegate());
4049 const int kWindowWidth
= 123;
4050 const int kWindowHeight
= 45;
4051 const int kTouchId
= 6;
4052 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
4053 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4054 delegate
.get(), -1234, bounds
, root_window()));
4058 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4059 kTouchId
, tes
.Now());
4060 DispatchEventUsingWindowDispatcher(&press1
);
4061 EXPECT_TRUE(delegate
->tap_down());
4063 int default_flags
= delegate
->flags();
4065 ui::TouchEvent
move1(
4066 ui::ET_TOUCH_MOVED
, gfx::Point(397, 149), kTouchId
, tes
.LeapForward(50));
4067 move1
.set_flags(992);
4069 DispatchEventUsingWindowDispatcher(&move1
);
4070 EXPECT_NE(default_flags
, delegate
->flags());
4073 // A delegate that deletes a window on long press.
4074 class GestureEventDeleteWindowOnLongPress
: public GestureEventConsumeDelegate
{
4076 GestureEventDeleteWindowOnLongPress()
4079 void set_window(aura::Window
** window
) { window_
= window
; }
4081 void OnGestureEvent(ui::GestureEvent
* gesture
) override
{
4082 GestureEventConsumeDelegate::OnGestureEvent(gesture
);
4083 if (gesture
->type() != ui::ET_GESTURE_LONG_PRESS
)
4085 ui::GestureRecognizer::Get()->CleanupStateForConsumer(*window_
);
4091 aura::Window
** window_
;
4092 DISALLOW_COPY_AND_ASSIGN(GestureEventDeleteWindowOnLongPress
);
4095 // Check that deleting the window in response to a long press gesture doesn't
4097 TEST_F(GestureRecognizerTest
, GestureEventLongPressDeletingWindow
) {
4098 GestureEventDeleteWindowOnLongPress delegate
;
4099 const int kWindowWidth
= 123;
4100 const int kWindowHeight
= 45;
4101 const int kTouchId
= 2;
4102 gfx::Rect
bounds(100, 200, kWindowWidth
, kWindowHeight
);
4103 aura::Window
* window(CreateTestWindowWithDelegate(
4104 &delegate
, -1234, bounds
, root_window()));
4105 delegate
.set_window(&window
);
4107 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
,
4108 gfx::Point(101, 201),
4110 ui::EventTimeForNow());
4111 DispatchEventUsingWindowDispatcher(&press1
);
4112 EXPECT_TRUE(window
!= NULL
);
4114 // Wait until the timer runs out.
4115 delegate
.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS
);
4116 EXPECT_EQ(NULL
, window
);
4119 TEST_F(GestureRecognizerWithSwitchTest
, GestureEventSmallPinchDisabled
) {
4120 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4121 new GestureEventConsumeDelegate());
4123 const int kWindowWidth
= 300;
4124 const int kWindowHeight
= 400;
4125 const int kTouchId1
= 3;
4126 const int kTouchId2
= 5;
4127 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4128 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4129 delegate
.get(), -1234, bounds
, root_window()));
4131 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
4132 kTouchId1
, tes
.Now());
4133 DispatchEventUsingWindowDispatcher(&press1
);
4134 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
4135 kTouchId2
, tes
.Now());
4136 DispatchEventUsingWindowDispatcher(&press2
);
4138 // Move the first finger.
4140 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
4141 kTouchId1
, tes
.Now());
4142 DispatchEventUsingWindowDispatcher(&move1
);
4144 EXPECT_3_EVENTS(delegate
->events(),
4145 ui::ET_GESTURE_SCROLL_BEGIN
,
4146 ui::ET_GESTURE_SCROLL_UPDATE
,
4147 ui::ET_GESTURE_PINCH_BEGIN
);
4149 // No pinch update occurs, as kCompensateForUnstablePinchZoom is on and
4150 // |min_pinch_update_span_delta| was nonzero, and this is a very small pinch.
4152 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(65, 202),
4153 kTouchId1
, tes
.Now());
4154 DispatchEventUsingWindowDispatcher(&move2
);
4155 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
4158 TEST_F(GestureRecognizerTest
, GestureEventSmallPinchEnabled
) {
4159 scoped_ptr
<GestureEventConsumeDelegate
> delegate(
4160 new GestureEventConsumeDelegate());
4162 const int kWindowWidth
= 300;
4163 const int kWindowHeight
= 400;
4164 const int kTouchId1
= 3;
4165 const int kTouchId2
= 5;
4166 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4167 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4168 delegate
.get(), -1234, bounds
, root_window()));
4170 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301),
4171 kTouchId1
, tes
.Now());
4172 DispatchEventUsingWindowDispatcher(&press1
);
4173 ui::TouchEvent
press2(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10),
4174 kTouchId2
, tes
.Now());
4175 DispatchEventUsingWindowDispatcher(&press2
);
4177 // Move the first finger.
4179 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(65, 201),
4180 kTouchId1
, tes
.Now());
4181 DispatchEventUsingWindowDispatcher(&move1
);
4183 EXPECT_3_EVENTS(delegate
->events(),
4184 ui::ET_GESTURE_SCROLL_BEGIN
,
4185 ui::ET_GESTURE_SCROLL_UPDATE
,
4186 ui::ET_GESTURE_PINCH_BEGIN
);
4189 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(65, 202),
4190 kTouchId1
, tes
.Now());
4191 DispatchEventUsingWindowDispatcher(&move2
);
4192 EXPECT_2_EVENTS(delegate
->events(),
4193 ui::ET_GESTURE_SCROLL_UPDATE
,
4194 ui::ET_GESTURE_PINCH_UPDATE
);
4197 // Tests that delaying the ack of a touch release doesn't trigger a long press
4199 TEST_F(GestureRecognizerTest
, EagerGestureDetection
) {
4200 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4201 new QueueTouchEventDelegate(host()->dispatcher()));
4203 const int kTouchId
= 2;
4204 gfx::Rect
bounds(100, 200, 100, 100);
4205 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4206 delegate
.get(), -1234, bounds
, root_window()));
4207 delegate
->set_window(window
.get());
4210 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(101, 201),
4211 kTouchId
, tes
.Now());
4212 DispatchEventUsingWindowDispatcher(&press
);
4213 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
, gfx::Point(101, 201),
4214 kTouchId
, tes
.LeapForward(50));
4215 DispatchEventUsingWindowDispatcher(&release
);
4218 // Ack the touch press.
4219 delegate
->ReceivedAck();
4220 EXPECT_TRUE(delegate
->tap_down());
4223 // Wait until the long press event would fire (if we weren't eager).
4224 DelayByLongPressTimeout();
4226 // Ack the touch release.
4227 delegate
->ReceivedAck();
4228 EXPECT_TRUE(delegate
->tap());
4229 EXPECT_FALSE(delegate
->long_press());
4232 // This tests crbug.com/405519, in which touch events which the gesture detector
4233 // ignores interfere with gesture recognition.
4234 TEST_F(GestureRecognizerTest
, IgnoredEventsDontBreakGestureRecognition
) {
4235 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4236 new QueueTouchEventDelegate(host()->dispatcher()));
4238 const int kWindowWidth
= 300;
4239 const int kWindowHeight
= 400;
4240 const int kTouchId1
= 3;
4241 gfx::Rect
bounds(5, 5, kWindowWidth
, kWindowHeight
);
4242 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4243 delegate
.get(), -1234, bounds
, root_window()));
4244 delegate
->set_window(window
.get());
4246 ui::TouchEvent
press1(
4247 ui::ET_TOUCH_PRESSED
, gfx::Point(101, 301), kTouchId1
, tes
.Now());
4248 DispatchEventUsingWindowDispatcher(&press1
);
4249 delegate
->ReceivedAck();
4252 delegate
->events(), ui::ET_GESTURE_BEGIN
, ui::ET_GESTURE_TAP_DOWN
);
4254 // Move the first finger.
4256 ui::TouchEvent
move1(
4257 ui::ET_TOUCH_MOVED
, gfx::Point(65, 201), kTouchId1
, tes
.Now());
4258 DispatchEventUsingWindowDispatcher(&move1
);
4259 delegate
->ReceivedAck();
4261 EXPECT_3_EVENTS(delegate
->events(),
4262 ui::ET_GESTURE_TAP_CANCEL
,
4263 ui::ET_GESTURE_SCROLL_BEGIN
,
4264 ui::ET_GESTURE_SCROLL_UPDATE
);
4268 // Send a valid event, but don't ack it.
4269 ui::TouchEvent
move2(
4270 ui::ET_TOUCH_MOVED
, gfx::Point(65, 202), kTouchId1
, tes
.Now());
4271 DispatchEventUsingWindowDispatcher(&move2
);
4272 EXPECT_0_EVENTS(delegate
->events());
4274 // Send a touchmove event at the same location as the previous touchmove
4275 // event. This shouldn't do anything.
4276 ui::TouchEvent
move3(
4277 ui::ET_TOUCH_MOVED
, gfx::Point(65, 202), kTouchId1
, tes
.Now());
4278 DispatchEventUsingWindowDispatcher(&move3
);
4280 // Ack the previous valid event. The intermediary invalid event shouldn't
4282 delegate
->ReceivedAck();
4283 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
4286 // Tests that an event stream can have a mix of sync and async acks.
4287 TEST_F(GestureRecognizerTest
,
4288 MixedSyncAndAsyncAcksDontCauseOutOfOrderDispatch
) {
4289 scoped_ptr
<QueueTouchEventDelegate
> delegate(
4290 new QueueTouchEventDelegate(host()->dispatcher()));
4292 const int kWindowWidth
= 300;
4293 const int kWindowHeight
= 400;
4294 const int kTouchId1
= 3;
4295 gfx::Rect
bounds(0, 0, kWindowWidth
, kWindowHeight
);
4296 scoped_ptr
<aura::Window
> window(CreateTestWindowWithDelegate(
4297 delegate
.get(), -1234, bounds
, root_window()));
4298 delegate
->set_window(window
.get());
4300 // Start a scroll gesture.
4301 ui::TouchEvent
press1(
4302 ui::ET_TOUCH_PRESSED
, gfx::Point(0, 0), kTouchId1
, tes
.Now());
4303 DispatchEventUsingWindowDispatcher(&press1
);
4304 delegate
->ReceivedAck();
4306 ui::TouchEvent
move1(
4307 ui::ET_TOUCH_MOVED
, gfx::Point(100, 100), kTouchId1
, tes
.Now());
4308 DispatchEventUsingWindowDispatcher(&move1
);
4309 delegate
->ReceivedAck();
4312 // Dispatch a synchronously consumed touch move, which should be ignored.
4313 delegate
->set_synchronous_ack_for_next_event(true);
4314 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(200, 200), kTouchId1
,
4316 DispatchEventUsingWindowDispatcher(&move2
);
4317 EXPECT_0_EVENTS(delegate
->events());
4319 // Dispatch a touch move, but don't ack it.
4320 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
, gfx::Point(300, 300), kTouchId1
,
4322 DispatchEventUsingWindowDispatcher(&move3
);
4324 // Dispatch two synchronously consumed touch moves, which should be ignored.
4325 delegate
->set_synchronous_ack_for_next_event(true);
4326 ui::TouchEvent
move4(
4327 ui::ET_TOUCH_MOVED
, gfx::Point(400, 400), kTouchId1
, tes
.Now());
4328 DispatchEventUsingWindowDispatcher(&move4
);
4330 delegate
->set_synchronous_ack_for_next_event(true);
4331 ui::TouchEvent
move5(
4332 ui::ET_TOUCH_MOVED
, gfx::Point(500, 500), kTouchId1
, tes
.Now());
4333 DispatchEventUsingWindowDispatcher(&move5
);
4335 EXPECT_0_EVENTS(delegate
->events());
4336 EXPECT_EQ(100, delegate
->bounding_box().x());
4337 // Ack the pending touch move, and ensure the most recent gesture event
4338 // used its co-ordinates.
4339 delegate
->ReceivedAck();
4340 EXPECT_EQ(300, delegate
->bounding_box().x());
4341 EXPECT_1_EVENT(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
);
4343 // Dispatch a touch move, but don't ack it.
4345 ui::TouchEvent
move6(ui::ET_TOUCH_MOVED
, gfx::Point(600, 600), kTouchId1
,
4347 DispatchEventUsingWindowDispatcher(&move6
);
4349 // Dispatch a synchronously unconsumed touch move.
4350 delegate
->set_synchronous_ack_for_next_event(false);
4351 ui::TouchEvent
move7(
4352 ui::ET_TOUCH_MOVED
, gfx::Point(700, 700), kTouchId1
, tes
.Now());
4353 DispatchEventUsingWindowDispatcher(&move7
);
4355 // The synchronous ack is stuck behind the pending touch move.
4356 EXPECT_0_EVENTS(delegate
->events());
4358 delegate
->ReceivedAck();
4359 EXPECT_2_EVENTS(delegate
->events(), ui::ET_GESTURE_SCROLL_UPDATE
,
4360 ui::ET_GESTURE_SCROLL_UPDATE
);