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

Side by Side Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 252833005: Reland "GestureRecognizerTest tests both Aura and Unified Gesture Detectors." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix failing test. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/aura/test/aura_test_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 swipe_down_(false), 89 swipe_down_(false),
90 scroll_x_(0), 90 scroll_x_(0),
91 scroll_y_(0), 91 scroll_y_(0),
92 scroll_velocity_x_(0), 92 scroll_velocity_x_(0),
93 scroll_velocity_y_(0), 93 scroll_velocity_y_(0),
94 velocity_x_(0), 94 velocity_x_(0),
95 velocity_y_(0), 95 velocity_y_(0),
96 scroll_x_hint_(0), 96 scroll_x_hint_(0),
97 scroll_y_hint_(0), 97 scroll_y_hint_(0),
98 tap_count_(0), 98 tap_count_(0),
99 wait_until_event_(ui::ET_UNKNOWN) { 99 flags_(0),
100 } 100 wait_until_event_(ui::ET_UNKNOWN) {}
101 101
102 virtual ~GestureEventConsumeDelegate() {} 102 virtual ~GestureEventConsumeDelegate() {}
103 103
104 void Reset() { 104 void Reset() {
105 events_.clear(); 105 events_.clear();
106 tap_ = false; 106 tap_ = false;
107 tap_down_ = false; 107 tap_down_ = false;
108 tap_cancel_ = false; 108 tap_cancel_ = false;
109 begin_ = false; 109 begin_ = false;
110 end_ = false; 110 end_ = false;
(...skipping 19 matching lines...) Expand all
130 scroll_x_ = 0; 130 scroll_x_ = 0;
131 scroll_y_ = 0; 131 scroll_y_ = 0;
132 scroll_velocity_x_ = 0; 132 scroll_velocity_x_ = 0;
133 scroll_velocity_y_ = 0; 133 scroll_velocity_y_ = 0;
134 velocity_x_ = 0; 134 velocity_x_ = 0;
135 velocity_y_ = 0; 135 velocity_y_ = 0;
136 scroll_x_hint_ = 0; 136 scroll_x_hint_ = 0;
137 scroll_y_hint_ = 0; 137 scroll_y_hint_ = 0;
138 tap_count_ = 0; 138 tap_count_ = 0;
139 scale_ = 0; 139 scale_ = 0;
140 flags_ = 0;
140 } 141 }
141 142
142 const std::vector<ui::EventType>& events() const { return events_; }; 143 const std::vector<ui::EventType>& events() const { return events_; };
143 144
144 bool tap() const { return tap_; } 145 bool tap() const { return tap_; }
145 bool tap_down() const { return tap_down_; } 146 bool tap_down() const { return tap_down_; }
146 bool tap_cancel() const { return tap_cancel_; } 147 bool tap_cancel() const { return tap_cancel_; }
147 bool begin() const { return begin_; } 148 bool begin() const { return begin_; }
148 bool end() const { return end_; } 149 bool end() const { return end_; }
149 bool scroll_begin() const { return scroll_begin_; } 150 bool scroll_begin() const { return scroll_begin_; }
(...skipping 28 matching lines...) Expand all
178 float scroll_y() const { return scroll_y_; } 179 float scroll_y() const { return scroll_y_; }
179 float scroll_velocity_x() const { return scroll_velocity_x_; } 180 float scroll_velocity_x() const { return scroll_velocity_x_; }
180 float scroll_velocity_y() const { return scroll_velocity_y_; } 181 float scroll_velocity_y() const { return scroll_velocity_y_; }
181 float velocity_x() const { return velocity_x_; } 182 float velocity_x() const { return velocity_x_; }
182 float velocity_y() const { return velocity_y_; } 183 float velocity_y() const { return velocity_y_; }
183 float scroll_x_hint() const { return scroll_x_hint_; } 184 float scroll_x_hint() const { return scroll_x_hint_; }
184 float scroll_y_hint() const { return scroll_y_hint_; } 185 float scroll_y_hint() const { return scroll_y_hint_; }
185 float scale() const { return scale_; } 186 float scale() const { return scale_; }
186 const gfx::Rect& bounding_box() const { return bounding_box_; } 187 const gfx::Rect& bounding_box() const { return bounding_box_; }
187 int tap_count() const { return tap_count_; } 188 int tap_count() const { return tap_count_; }
189 int flags() const { return flags_; }
188 190
189 void WaitUntilReceivedGesture(ui::EventType type) { 191 void WaitUntilReceivedGesture(ui::EventType type) {
190 wait_until_event_ = type; 192 wait_until_event_ = type;
191 run_loop_.reset(new base::RunLoop()); 193 run_loop_.reset(new base::RunLoop());
192 run_loop_->Run(); 194 run_loop_->Run();
193 } 195 }
194 196
195 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { 197 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
196 events_.push_back(gesture->type()); 198 events_.push_back(gesture->type());
197 bounding_box_ = gesture->details().bounding_box(); 199 bounding_box_ = gesture->details().bounding_box();
200 flags_ = gesture->flags();
198 switch (gesture->type()) { 201 switch (gesture->type()) {
199 case ui::ET_GESTURE_TAP: 202 case ui::ET_GESTURE_TAP:
200 tap_location_ = gesture->location(); 203 tap_location_ = gesture->location();
201 tap_count_ = gesture->details().tap_count(); 204 tap_count_ = gesture->details().tap_count();
202 tap_ = true; 205 tap_ = true;
203 break; 206 break;
204 case ui::ET_GESTURE_TAP_DOWN: 207 case ui::ET_GESTURE_TAP_DOWN:
205 tap_down_ = true; 208 tap_down_ = true;
206 break; 209 break;
207 case ui::ET_GESTURE_TAP_CANCEL: 210 case ui::ET_GESTURE_TAP_CANCEL:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 break; 261 break;
259 case ui::ET_GESTURE_SHOW_PRESS: 262 case ui::ET_GESTURE_SHOW_PRESS:
260 show_press_ = true; 263 show_press_ = true;
261 break; 264 break;
262 case ui::ET_GESTURE_MULTIFINGER_SWIPE: 265 case ui::ET_GESTURE_MULTIFINGER_SWIPE:
263 swipe_left_ = gesture->details().swipe_left(); 266 swipe_left_ = gesture->details().swipe_left();
264 swipe_right_ = gesture->details().swipe_right(); 267 swipe_right_ = gesture->details().swipe_right();
265 swipe_up_ = gesture->details().swipe_up(); 268 swipe_up_ = gesture->details().swipe_up();
266 swipe_down_ = gesture->details().swipe_down(); 269 swipe_down_ = gesture->details().swipe_down();
267 break; 270 break;
271 case ui::ET_SCROLL_FLING_CANCEL:
272 // Only used in unified gesture detection.
273 break;
268 default: 274 default:
269 NOTREACHED(); 275 NOTREACHED();
270 } 276 }
271 if (wait_until_event_ == gesture->type() && run_loop_) { 277 if (wait_until_event_ == gesture->type() && run_loop_) {
272 run_loop_->Quit(); 278 run_loop_->Quit();
273 wait_until_event_ = ui::ET_UNKNOWN; 279 wait_until_event_ = ui::ET_UNKNOWN;
274 } 280 }
275 gesture->StopPropagation(); 281 gesture->StopPropagation();
276 } 282 }
277 283
(...skipping 30 matching lines...) Expand all
308 float scroll_y_; 314 float scroll_y_;
309 float scroll_velocity_x_; 315 float scroll_velocity_x_;
310 float scroll_velocity_y_; 316 float scroll_velocity_y_;
311 float velocity_x_; 317 float velocity_x_;
312 float velocity_y_; 318 float velocity_y_;
313 float scroll_x_hint_; 319 float scroll_x_hint_;
314 float scroll_y_hint_; 320 float scroll_y_hint_;
315 float scale_; 321 float scale_;
316 gfx::Rect bounding_box_; 322 gfx::Rect bounding_box_;
317 int tap_count_; 323 int tap_count_;
324 int flags_;
318 325
319 ui::EventType wait_until_event_; 326 ui::EventType wait_until_event_;
320 327
321 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 328 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate);
322 }; 329 };
323 330
324 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 331 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
325 public: 332 public:
326 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) 333 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher)
327 : window_(NULL), 334 : window_(NULL),
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 scoped_ptr<ui::GestureRecognizer> new_gr_; 528 scoped_ptr<ui::GestureRecognizer> new_gr_;
522 529
523 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter); 530 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter);
524 }; 531 };
525 532
526 class TimedEvents { 533 class TimedEvents {
527 private: 534 private:
528 int simulated_now_; 535 int simulated_now_;
529 536
530 public: 537 public:
531 TimedEvents() : simulated_now_(0) { 538 // Use a non-zero start time to pass DCHECKs which ensure events have had a
539 // time assigned.
540 TimedEvents() : simulated_now_(1) {
532 } 541 }
533 542
534 base::TimeDelta Now() { 543 base::TimeDelta Now() {
535 base::TimeDelta t = base::TimeDelta::FromMilliseconds(simulated_now_); 544 base::TimeDelta t = base::TimeDelta::FromMilliseconds(simulated_now_);
536 simulated_now_++; 545 simulated_now_++;
537 return t; 546 return t;
538 } 547 }
539 548
540 base::TimeDelta LeapForward(int time_in_millis) { 549 base::TimeDelta LeapForward(int time_in_millis) {
541 simulated_now_ += time_in_millis; 550 simulated_now_ += time_in_millis;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 target->RemovePreTargetHandler(this); 668 target->RemovePreTargetHandler(this);
660 target->parent()->RemoveChild(target); 669 target->parent()->RemoveChild(target);
661 } 670 }
662 } 671 }
663 672
664 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler); 673 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler);
665 }; 674 };
666 675
667 } // namespace 676 } // namespace
668 677
669 class GestureRecognizerTest : public AuraTestBase { 678 class GestureRecognizerTest : public AuraTestBase,
679 public ::testing::WithParamInterface<bool> {
670 public: 680 public:
671 GestureRecognizerTest() {} 681 GestureRecognizerTest() {}
672 682
683 bool UsingUnifiedGR() {
684 return GetParam();
685 }
686
673 virtual void SetUp() OVERRIDE { 687 virtual void SetUp() OVERRIDE {
674 CommandLine::ForCurrentProcess()->AppendSwitch( 688 // TODO(tdresser): Once unified GR has landed, only run these tests once.
675 switches::kEnableScrollPrediction); 689 if (UsingUnifiedGR()) {
690 // TODO(tdresser): use unified GR once it's available.
691 // CommandLine::ForCurrentProcess()->AppendSwitch(
692 // switches::kUseUnifiedGestureDetector);
693 }
694
676 AuraTestBase::SetUp(); 695 AuraTestBase::SetUp();
677 } 696 }
678 697
679 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); 698 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest);
680 }; 699 };
681 700
682 // Check that appropriate touch events generate tap gesture events. 701 // Check that appropriate touch events generate tap gesture events.
683 TEST_F(GestureRecognizerTest, GestureEventTap) { 702 TEST_P(GestureRecognizerTest, GestureEventTap) {
684 scoped_ptr<GestureEventConsumeDelegate> delegate( 703 scoped_ptr<GestureEventConsumeDelegate> delegate(
685 new GestureEventConsumeDelegate()); 704 new GestureEventConsumeDelegate());
686 TimedEvents tes; 705 TimedEvents tes;
687 const int kWindowWidth = 123; 706 const int kWindowWidth = 123;
688 const int kWindowHeight = 45; 707 const int kWindowHeight = 45;
689 const int kTouchId = 2; 708 const int kTouchId = 2;
690 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 709 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
691 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 710 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
692 delegate.get(), -1234, bounds, root_window())); 711 delegate.get(), -1234, bounds, root_window()));
693 712
(...skipping 30 matching lines...) Expand all
724 EXPECT_TRUE(delegate->end()); 743 EXPECT_TRUE(delegate->end());
725 EXPECT_FALSE(delegate->scroll_begin()); 744 EXPECT_FALSE(delegate->scroll_begin());
726 EXPECT_FALSE(delegate->scroll_update()); 745 EXPECT_FALSE(delegate->scroll_update());
727 EXPECT_FALSE(delegate->scroll_end()); 746 EXPECT_FALSE(delegate->scroll_end());
728 747
729 EXPECT_EQ(1, delegate->tap_count()); 748 EXPECT_EQ(1, delegate->tap_count());
730 } 749 }
731 750
732 // Check that appropriate touch events generate tap gesture events 751 // Check that appropriate touch events generate tap gesture events
733 // when information about the touch radii are provided. 752 // when information about the touch radii are provided.
734 TEST_F(GestureRecognizerTest, GestureEventTapRegion) { 753 TEST_P(GestureRecognizerTest, GestureEventTapRegion) {
735 scoped_ptr<GestureEventConsumeDelegate> delegate( 754 scoped_ptr<GestureEventConsumeDelegate> delegate(
736 new GestureEventConsumeDelegate()); 755 new GestureEventConsumeDelegate());
737 TimedEvents tes; 756 TimedEvents tes;
738 const int kWindowWidth = 800; 757 const int kWindowWidth = 800;
739 const int kWindowHeight = 600; 758 const int kWindowHeight = 600;
740 const int kTouchId = 2; 759 const int kTouchId = 2;
741 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 760 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
742 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 761 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
743 delegate.get(), -1234, bounds, root_window())); 762 delegate.get(), -1234, bounds, root_window()));
744 763
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 EXPECT_EQ(1, delegate->tap_count()); 983 EXPECT_EQ(1, delegate->tap_count());
965 gfx::Point actual_point(delegate->tap_location()); 984 gfx::Point actual_point(delegate->tap_location());
966 EXPECT_EQ(33, delegate->bounding_box().width()); 985 EXPECT_EQ(33, delegate->bounding_box().width());
967 EXPECT_EQ(32, delegate->bounding_box().height()); 986 EXPECT_EQ(32, delegate->bounding_box().height());
968 EXPECT_EQ(397, actual_point.x()); 987 EXPECT_EQ(397, actual_point.x());
969 EXPECT_EQ(149, actual_point.y()); 988 EXPECT_EQ(149, actual_point.y());
970 } 989 }
971 } 990 }
972 991
973 // Check that appropriate touch events generate scroll gesture events. 992 // Check that appropriate touch events generate scroll gesture events.
974 TEST_F(GestureRecognizerTest, GestureEventScroll) { 993 TEST_P(GestureRecognizerTest, GestureEventScroll) {
975 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of 994 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of
976 // that distance to be consumed by the slop, so we set the slop radius to 995 // that distance to be consumed by the slop, so we set the slop radius to
977 // sqrt(5 * 5 + 5 * 5). 996 // sqrt(5 * 5 + 5 * 5).
978 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( 997 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
979 sqrt(static_cast<double>(5 * 5 + 5 * 5))); 998 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
980 scoped_ptr<GestureEventConsumeDelegate> delegate( 999 scoped_ptr<GestureEventConsumeDelegate> delegate(
981 new GestureEventConsumeDelegate()); 1000 new GestureEventConsumeDelegate());
982 TimedEvents tes; 1001 TimedEvents tes;
983 const int kWindowWidth = 123; 1002 const int kWindowWidth = 123;
984 const int kWindowHeight = 45; 1003 const int kWindowHeight = 45;
(...skipping 23 matching lines...) Expand all
1008 // The slop consumed 5 dips 1027 // The slop consumed 5 dips
1009 EXPECT_FLOAT_EQ(5.5, delegate->scroll_x()); 1028 EXPECT_FLOAT_EQ(5.5, delegate->scroll_x());
1010 EXPECT_FLOAT_EQ(5.5, delegate->scroll_y()); 1029 EXPECT_FLOAT_EQ(5.5, delegate->scroll_y());
1011 EXPECT_EQ(gfx::Point(1, 1).ToString(), 1030 EXPECT_EQ(gfx::Point(1, 1).ToString(),
1012 delegate->scroll_begin_position().ToString()); 1031 delegate->scroll_begin_position().ToString());
1013 1032
1014 // When scrolling with a single finger, the bounding box of the gesture should 1033 // When scrolling with a single finger, the bounding box of the gesture should
1015 // be empty, since it's a single point and the radius for testing is zero. 1034 // be empty, since it's a single point and the radius for testing is zero.
1016 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1035 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1017 1036
1018 // Move some more to generate a few more scroll updates. 1037 // Move some more to generate a few more scroll updates. Make sure that we get
1019 tes.SendScrollEvent(event_processor(), 91, 192, kTouchId, delegate.get()); 1038 // out of the snap channel for the unified GR.
1039 tes.SendScrollEvent(event_processor(), 20, 120, kTouchId, delegate.get());
1020 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 1040 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
1021 EXPECT_FLOAT_EQ(-20.5, delegate->scroll_x()); 1041 EXPECT_FLOAT_EQ(-91.5, delegate->scroll_x());
1022 EXPECT_FLOAT_EQ(-19.5, delegate->scroll_y()); 1042 EXPECT_FLOAT_EQ(-91.5, delegate->scroll_y());
1023 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1043 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1024 1044
1025 tes.SendScrollEvent(event_processor(), 121, 196, kTouchId, delegate.get()); 1045 tes.SendScrollEvent(event_processor(), 50, 124, kTouchId, delegate.get());
1026 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 1046 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
1027 EXPECT_EQ(30, delegate->scroll_x()); 1047 EXPECT_EQ(30, delegate->scroll_x());
1028 EXPECT_EQ(4, delegate->scroll_y()); 1048 EXPECT_EQ(4, delegate->scroll_y());
1029 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1049 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1030 1050
1031 // Release the touch. This should end the scroll. 1051 // Release the touch. This should end the scroll.
1032 delegate->Reset(); 1052 delegate->Reset();
1033 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1053 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1034 kTouchId, 1054 kTouchId,
1035 tes.LeapForward(50)); 1055 tes.LeapForward(50));
1036 DispatchEventUsingWindowDispatcher(&release); 1056 DispatchEventUsingWindowDispatcher(&release);
1037 EXPECT_2_EVENTS(delegate->events(), 1057 EXPECT_2_EVENTS(delegate->events(),
1038 ui::ET_SCROLL_FLING_START, 1058 ui::ET_SCROLL_FLING_START,
1039 ui::ET_GESTURE_END); 1059 ui::ET_GESTURE_END);
1040 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1060 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1041 } 1061 }
1042 1062
1043 // Check that predicted scroll update positions are correct. 1063 // Check that predicted scroll update positions are correct.
1044 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { 1064 TEST_P(GestureRecognizerTest, GestureEventScrollPrediction) {
1045 const double prediction_interval = 0.03; 1065 const double prediction_interval = 0.03;
1046 ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval); 1066 ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval);
1047 // We'll start by moving the touch point by (5, 5). We want all of that 1067 // We'll start by moving the touch point by (5, 5). We want all of that
1048 // distance to be consumed by the slop, so we set the slop radius to 1068 // distance to be consumed by the slop, so we set the slop radius to
1049 // sqrt(5 * 5 + 5 * 5). 1069 // sqrt(5 * 5 + 5 * 5).
1050 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( 1070 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1051 sqrt(static_cast<double>(5 * 5 + 5 * 5))); 1071 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1052 1072
1053 scoped_ptr<GestureEventConsumeDelegate> delegate( 1073 scoped_ptr<GestureEventConsumeDelegate> delegate(
1054 new GestureEventConsumeDelegate()); 1074 new GestureEventConsumeDelegate());
(...skipping 11 matching lines...) Expand all
1066 gfx::Vector2dF total_scroll; 1086 gfx::Vector2dF total_scroll;
1067 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(96, 196), 1087 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(96, 196),
1068 kTouchId, tes.Now()); 1088 kTouchId, tes.Now());
1069 DispatchEventUsingWindowDispatcher(&press); 1089 DispatchEventUsingWindowDispatcher(&press);
1070 EXPECT_2_EVENTS(delegate->events(), 1090 EXPECT_2_EVENTS(delegate->events(),
1071 ui::ET_GESTURE_BEGIN, 1091 ui::ET_GESTURE_BEGIN,
1072 ui::ET_GESTURE_TAP_DOWN); 1092 ui::ET_GESTURE_TAP_DOWN);
1073 delegate->Reset(); 1093 delegate->Reset();
1074 1094
1075 // Get rid of touch slop. 1095 // Get rid of touch slop.
1076 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), 1096 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(111, 211),
1077 kTouchId, tes.Now()); 1097 kTouchId, tes.Now());
1078 DispatchEventUsingWindowDispatcher(&move); 1098 DispatchEventUsingWindowDispatcher(&move);
1079 EXPECT_3_EVENTS(delegate->events(), 1099 EXPECT_3_EVENTS(delegate->events(),
1080 ui::ET_GESTURE_TAP_CANCEL, 1100 ui::ET_GESTURE_TAP_CANCEL,
1081 ui::ET_GESTURE_SCROLL_BEGIN, 1101 ui::ET_GESTURE_SCROLL_BEGIN,
1082 ui::ET_GESTURE_SCROLL_UPDATE); 1102 ui::ET_GESTURE_SCROLL_UPDATE);
1083 total_scroll.set_x(total_scroll.x() + delegate->scroll_x()); 1103 total_scroll.set_x(total_scroll.x() + delegate->scroll_x());
1084 total_scroll.set_y(total_scroll.y() + delegate->scroll_y()); 1104 total_scroll.set_y(total_scroll.y() + delegate->scroll_y());
1085 1105
1086 // Move the touch-point enough so that it is considered as a scroll. This 1106 // Move the touch-point enough so that it is considered as a scroll. This
(...skipping 22 matching lines...) Expand all
1109 1129
1110 // Release the touch. This should end the scroll. 1130 // Release the touch. This should end the scroll.
1111 delegate->Reset(); 1131 delegate->Reset();
1112 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1132 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1113 kTouchId, 1133 kTouchId,
1114 tes.LeapForward(50)); 1134 tes.LeapForward(50));
1115 DispatchEventUsingWindowDispatcher(&release); 1135 DispatchEventUsingWindowDispatcher(&release);
1116 } 1136 }
1117 1137
1118 // Check that the bounding box during a scroll event is correct. 1138 // Check that the bounding box during a scroll event is correct.
1119 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { 1139 TEST_P(GestureRecognizerTest, GestureEventScrollBoundingBox) {
1120 TimedEvents tes; 1140 TimedEvents tes;
1121 for (int radius = 1; radius <= 10; ++radius) { 1141 for (int radius = 1; radius <= 10; ++radius) {
1122 ui::GestureConfiguration::set_default_radius(radius); 1142 ui::GestureConfiguration::set_default_radius(radius);
1123 scoped_ptr<GestureEventConsumeDelegate> delegate( 1143 scoped_ptr<GestureEventConsumeDelegate> delegate(
1124 new GestureEventConsumeDelegate()); 1144 new GestureEventConsumeDelegate());
1125 const int kWindowWidth = 123; 1145 const int kWindowWidth = 123;
1126 const int kWindowHeight = 45; 1146 const int kWindowHeight = 45;
1127 const int kTouchId = 5; 1147 const int kTouchId = 5;
1128 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1148 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1129 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1149 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 kPositionY + kScrollAmount - radius, 1186 kPositionY + kScrollAmount - radius,
1167 radius * 2, 1187 radius * 2,
1168 radius * 2).ToString(), 1188 radius * 2).ToString(),
1169 delegate->bounding_box().ToString()); 1189 delegate->bounding_box().ToString());
1170 } 1190 }
1171 ui::GestureConfiguration::set_default_radius(0); 1191 ui::GestureConfiguration::set_default_radius(0);
1172 } 1192 }
1173 1193
1174 // Check Scroll End Events report correct velocities 1194 // Check Scroll End Events report correct velocities
1175 // if the user was on a horizontal rail 1195 // if the user was on a horizontal rail
1176 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { 1196 TEST_P(GestureRecognizerTest, GestureEventHorizontalRailFling) {
1177 scoped_ptr<GestureEventConsumeDelegate> delegate( 1197 scoped_ptr<GestureEventConsumeDelegate> delegate(
1178 new GestureEventConsumeDelegate()); 1198 new GestureEventConsumeDelegate());
1179 TimedEvents tes; 1199 TimedEvents tes;
1180 const int kTouchId = 7; 1200 const int kTouchId = 7;
1181 gfx::Rect bounds(0, 0, 1000, 1000); 1201 gfx::Rect bounds(0, 0, 1000, 1000);
1182 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1202 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1183 delegate.get(), -1234, bounds, root_window())); 1203 delegate.get(), -1234, bounds, root_window()));
1184 1204
1185 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1205 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1186 kTouchId, tes.Now()); 1206 kTouchId, tes.Now());
1187 DispatchEventUsingWindowDispatcher(&press); 1207 DispatchEventUsingWindowDispatcher(&press);
1188 1208
1189 // Get rid of touch slop. 1209 // Get rid of touch slop.
1190 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0), 1210 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0),
1191 kTouchId, tes.Now()); 1211 kTouchId, tes.Now());
1192 DispatchEventUsingWindowDispatcher(&move); 1212 DispatchEventUsingWindowDispatcher(&move);
1193 delegate->Reset(); 1213 delegate->Reset();
1194 1214
1195 1215
1196 // Move the touch-point horizontally enough that it is considered a 1216 // Move the touch-point horizontally enough that it is considered a
1197 // horizontal scroll. 1217 // horizontal scroll.
1198 tes.SendScrollEvent(event_processor(), 25, 1, kTouchId, delegate.get()); 1218 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get());
1199 EXPECT_EQ(0, delegate->scroll_y()); 1219 EXPECT_FLOAT_EQ(0, delegate->scroll_y());
1200 EXPECT_EQ(20, delegate->scroll_x()); 1220 EXPECT_FLOAT_EQ(20, delegate->scroll_x());
1201 1221
1202 // Get a high x velocity, while still staying on the rail 1222 // Get a high x velocity, while still staying on the rail
1203 tes.SendScrollEvents(event_processor(), 1, 1, 1223 tes.SendScrollEvents(event_processor(), 1, 1,
1204 100, 10, kTouchId, 1, 1224 100, 10, kTouchId, 1,
1205 ui::GestureConfiguration::points_buffered_for_velocity(), 1225 ui::GestureConfiguration::points_buffered_for_velocity(),
1206 delegate.get()); 1226 delegate.get());
1207 1227
1208 delegate->Reset(); 1228 delegate->Reset();
1209 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1229 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1210 kTouchId, tes.Now()); 1230 kTouchId, tes.Now());
1211 DispatchEventUsingWindowDispatcher(&release); 1231 DispatchEventUsingWindowDispatcher(&release);
1212 1232
1213 EXPECT_TRUE(delegate->fling()); 1233 EXPECT_TRUE(delegate->fling());
1214 EXPECT_FALSE(delegate->scroll_end()); 1234 EXPECT_FALSE(delegate->scroll_end());
1215 EXPECT_GT(delegate->velocity_x(), 0); 1235 EXPECT_GT(delegate->velocity_x(), 0);
1216 EXPECT_EQ(0, delegate->velocity_y()); 1236 EXPECT_EQ(0, delegate->velocity_y());
1217 } 1237 }
1218 1238
1219 // Check Scroll End Events report correct velocities 1239 // Check Scroll End Events report correct velocities
1220 // if the user was on a vertical rail 1240 // if the user was on a vertical rail
1221 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { 1241 TEST_P(GestureRecognizerTest, GestureEventVerticalRailFling) {
1222 scoped_ptr<GestureEventConsumeDelegate> delegate( 1242 scoped_ptr<GestureEventConsumeDelegate> delegate(
1223 new GestureEventConsumeDelegate()); 1243 new GestureEventConsumeDelegate());
1224 TimedEvents tes; 1244 TimedEvents tes;
1225 const int kTouchId = 7; 1245 const int kTouchId = 7;
1226 gfx::Rect bounds(0, 0, 1000, 1000); 1246 gfx::Rect bounds(0, 0, 1000, 1000);
1227 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1247 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1228 delegate.get(), -1234, bounds, root_window())); 1248 delegate.get(), -1234, bounds, root_window()));
1229 1249
1230 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1250 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1231 kTouchId, tes.Now()); 1251 kTouchId, tes.Now());
1232 DispatchEventUsingWindowDispatcher(&press); 1252 DispatchEventUsingWindowDispatcher(&press);
1233 1253
1234 // Get rid of touch slop. 1254 // Get rid of touch slop.
1235 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5), 1255 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 10),
1236 kTouchId, tes.Now()); 1256 kTouchId, tes.Now());
1237 DispatchEventUsingWindowDispatcher(&move); 1257 DispatchEventUsingWindowDispatcher(&move);
1238 delegate->Reset(); 1258 delegate->Reset();
1239 1259
1240 // Move the touch-point vertically enough that it is considered a 1260 // Move the touch-point vertically enough that it is considered a
1241 // vertical scroll. 1261 // vertical scroll.
1242 tes.SendScrollEvent(event_processor(), 1, 25, kTouchId, delegate.get()); 1262 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get());
1243 EXPECT_EQ(20, delegate->scroll_y()); 1263 EXPECT_EQ(20, delegate->scroll_y());
1244 EXPECT_EQ(0, delegate->scroll_x()); 1264 EXPECT_EQ(0, delegate->scroll_x());
1245 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1265 EXPECT_EQ(0, delegate->scroll_velocity_x());
1246 1266
1247 // Get a high y velocity, while still staying on the rail 1267 // Get a high y velocity, while still staying on the rail
1248 tes.SendScrollEvents(event_processor(), 1, 6, 1268 tes.SendScrollEvents(event_processor(), 1, 6,
1249 10, 100, kTouchId, 1, 1269 10, 100, kTouchId, 1,
1250 ui::GestureConfiguration::points_buffered_for_velocity(), 1270 ui::GestureConfiguration::points_buffered_for_velocity(),
1251 delegate.get()); 1271 delegate.get());
1252 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1272 EXPECT_EQ(0, delegate->scroll_velocity_x());
1253 1273
1254 delegate->Reset(); 1274 delegate->Reset();
1255 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206), 1275 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206),
1256 kTouchId, tes.Now()); 1276 kTouchId, tes.Now());
1257 DispatchEventUsingWindowDispatcher(&release); 1277 DispatchEventUsingWindowDispatcher(&release);
1258 1278
1259 EXPECT_TRUE(delegate->fling()); 1279 EXPECT_TRUE(delegate->fling());
1260 EXPECT_FALSE(delegate->scroll_end()); 1280 EXPECT_FALSE(delegate->scroll_end());
1261 EXPECT_EQ(0, delegate->velocity_x()); 1281 EXPECT_EQ(0, delegate->velocity_x());
1262 EXPECT_GT(delegate->velocity_y(), 0); 1282 EXPECT_GT(delegate->velocity_y(), 0);
1263 } 1283 }
1264 1284
1265 // Check Scroll End Events reports zero velocities 1285 // Check Scroll End Events report non-zero velocities if the user is not on a
1266 // if the user is not on a rail 1286 // rail
1267 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { 1287 TEST_P(GestureRecognizerTest, GestureEventNonRailFling) {
1268 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0); 1288 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
1269 scoped_ptr<GestureEventConsumeDelegate> delegate( 1289 scoped_ptr<GestureEventConsumeDelegate> delegate(
1270 new GestureEventConsumeDelegate()); 1290 new GestureEventConsumeDelegate());
1271 TimedEvents tes; 1291 TimedEvents tes;
1272 const int kTouchId = 7; 1292 const int kTouchId = 7;
1273 gfx::Rect bounds(0, 0, 1000, 1000); 1293 gfx::Rect bounds(0, 0, 1000, 1000);
1274 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1294 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1275 delegate.get(), -1234, bounds, root_window())); 1295 delegate.get(), -1234, bounds, root_window()));
1276 1296
1277 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1297 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1278 kTouchId, tes.Now()); 1298 kTouchId, tes.Now());
1279 DispatchEventUsingWindowDispatcher(&press); 1299 DispatchEventUsingWindowDispatcher(&press);
1280 1300
1281 // Move the touch-point such that a non-rail scroll begins 1301 // Move the touch-point such that a non-rail scroll begins, and we're outside
1282 tes.SendScrollEvent(event_processor(), 20, 20, kTouchId, delegate.get()); 1302 // the snap channel for the unified GR.
1283 EXPECT_EQ(20, delegate->scroll_y()); 1303 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get());
1284 EXPECT_EQ(20, delegate->scroll_x()); 1304 EXPECT_EQ(50, delegate->scroll_y());
1305 EXPECT_EQ(50, delegate->scroll_x());
1285 1306
1286 tes.SendScrollEvents(event_processor(), 1, 1, 1307 tes.SendScrollEvents(event_processor(), 1, 1,
1287 10, 100, kTouchId, 1, 1308 10, 100, kTouchId, 1,
1288 ui::GestureConfiguration::points_buffered_for_velocity(), 1309 ui::GestureConfiguration::points_buffered_for_velocity(),
1289 delegate.get()); 1310 delegate.get());
1290 1311
1291 delegate->Reset(); 1312 delegate->Reset();
1292 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1313 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1293 kTouchId, tes.Now()); 1314 kTouchId, tes.Now());
1294 DispatchEventUsingWindowDispatcher(&release); 1315 DispatchEventUsingWindowDispatcher(&release);
1295 1316
1296 EXPECT_TRUE(delegate->fling()); 1317 EXPECT_TRUE(delegate->fling());
1297 EXPECT_FALSE(delegate->scroll_end()); 1318 EXPECT_FALSE(delegate->scroll_end());
1298 EXPECT_GT(delegate->velocity_x(), 0); 1319 EXPECT_GT(delegate->velocity_x(), 0);
1299 EXPECT_GT(delegate->velocity_y(), 0); 1320 EXPECT_GT(delegate->velocity_y(), 0);
1300 } 1321 }
1301 1322
1302 // Check that appropriate touch events generate long press events 1323 // Check that appropriate touch events generate long press events
1303 TEST_F(GestureRecognizerTest, GestureEventLongPress) { 1324 TEST_P(GestureRecognizerTest, GestureEventLongPress) {
1304 scoped_ptr<GestureEventConsumeDelegate> delegate( 1325 scoped_ptr<GestureEventConsumeDelegate> delegate(
1305 new GestureEventConsumeDelegate()); 1326 new GestureEventConsumeDelegate());
1306 TimedEvents tes;
1307 const int kWindowWidth = 123; 1327 const int kWindowWidth = 123;
1308 const int kWindowHeight = 45; 1328 const int kWindowHeight = 45;
1309 const int kTouchId = 2; 1329 const int kTouchId = 2;
1310 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1330 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1311 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1331 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1312 delegate.get(), -1234, bounds, root_window())); 1332 delegate.get(), -1234, bounds, root_window()));
1313 1333
1314 delegate->Reset(); 1334 delegate->Reset();
1315 1335
1316 TimerTestGestureRecognizer* gesture_recognizer = 1336 TimerTestGestureRecognizer* gesture_recognizer =
1317 new TimerTestGestureRecognizer(); 1337 new TimerTestGestureRecognizer();
1318 1338
1319 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 1339 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
1320 1340
1321 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1341 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED,
1322 kTouchId, tes.Now()); 1342 gfx::Point(101, 201),
1343 kTouchId,
1344 ui::EventTimeForNow());
1323 DispatchEventUsingWindowDispatcher(&press1); 1345 DispatchEventUsingWindowDispatcher(&press1);
1324 EXPECT_TRUE(delegate->tap_down()); 1346 EXPECT_TRUE(delegate->tap_down());
1325 EXPECT_TRUE(delegate->begin()); 1347 EXPECT_TRUE(delegate->begin());
1326 EXPECT_FALSE(delegate->tap_cancel()); 1348 EXPECT_FALSE(delegate->tap_cancel());
1327 1349
1328 // We haven't pressed long enough for a long press to occur 1350 // We haven't pressed long enough for a long press to occur
1329 EXPECT_FALSE(delegate->long_press()); 1351 EXPECT_FALSE(delegate->long_press());
1330 1352
1331 // Wait until the timer runs out 1353 // Wait until the timer runs out
1332 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 1354 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
1333 EXPECT_TRUE(delegate->long_press()); 1355 EXPECT_TRUE(delegate->long_press());
1334 EXPECT_FALSE(delegate->tap_cancel()); 1356 EXPECT_FALSE(delegate->tap_cancel());
1335 1357
1336 delegate->Reset(); 1358 delegate->Reset();
1337 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1359 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED,
1338 kTouchId, tes.Now()); 1360 gfx::Point(101, 201),
1361 kTouchId,
1362 ui::EventTimeForNow());
1339 DispatchEventUsingWindowDispatcher(&release1); 1363 DispatchEventUsingWindowDispatcher(&release1);
1340 EXPECT_FALSE(delegate->long_press()); 1364 EXPECT_FALSE(delegate->long_press());
1341 1365
1342 // Note the tap down isn't cancelled until the release 1366 // Note the tap cancel isn't dispatched until the release
1343 EXPECT_TRUE(delegate->tap_cancel()); 1367 EXPECT_TRUE(delegate->tap_cancel());
1368 EXPECT_FALSE(delegate->tap());
1344 } 1369 }
1345 1370
1346 // Check that scrolling cancels a long press 1371 // Check that scrolling cancels a long press
1347 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { 1372 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
1348 scoped_ptr<GestureEventConsumeDelegate> delegate( 1373 scoped_ptr<GestureEventConsumeDelegate> delegate(
1349 new GestureEventConsumeDelegate()); 1374 new GestureEventConsumeDelegate());
1350 TimedEvents tes; 1375 TimedEvents tes;
1351 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); 1376 ui::GestureConfiguration::set_long_press_time_in_seconds(.01);
1352 const int kWindowWidth = 123; 1377 const int kWindowWidth = 123;
1353 const int kWindowHeight = 45; 1378 const int kWindowHeight = 45;
1354 const int kTouchId = 6; 1379 const int kTouchId = 6;
1355 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1380 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1356 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1381 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1357 delegate.get(), -1234, bounds, root_window())); 1382 delegate.get(), -1234, bounds, root_window()));
(...skipping 26 matching lines...) Expand all
1384 1409
1385 delegate->Reset(); 1410 delegate->Reset();
1386 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1411 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1387 kTouchId, tes.LeapForward(10)); 1412 kTouchId, tes.LeapForward(10));
1388 DispatchEventUsingWindowDispatcher(&release1); 1413 DispatchEventUsingWindowDispatcher(&release1);
1389 EXPECT_FALSE(delegate->long_press()); 1414 EXPECT_FALSE(delegate->long_press());
1390 EXPECT_FALSE(delegate->tap_cancel()); 1415 EXPECT_FALSE(delegate->tap_cancel());
1391 } 1416 }
1392 1417
1393 // Check that appropriate touch events generate long tap events 1418 // Check that appropriate touch events generate long tap events
1394 TEST_F(GestureRecognizerTest, GestureEventLongTap) { 1419 TEST_P(GestureRecognizerTest, GestureEventLongTap) {
1395 scoped_ptr<GestureEventConsumeDelegate> delegate( 1420 scoped_ptr<GestureEventConsumeDelegate> delegate(
1396 new GestureEventConsumeDelegate()); 1421 new GestureEventConsumeDelegate());
1397 TimedEvents tes;
1398 const int kWindowWidth = 123; 1422 const int kWindowWidth = 123;
1399 const int kWindowHeight = 45; 1423 const int kWindowHeight = 45;
1400 const int kTouchId = 2; 1424 const int kTouchId = 2;
1401 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1425 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1402 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1426 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1403 delegate.get(), -1234, bounds, root_window())); 1427 delegate.get(), -1234, bounds, root_window()));
1404 1428
1405 delegate->Reset(); 1429 delegate->Reset();
1406 1430
1407 TimerTestGestureRecognizer* gesture_recognizer = 1431 TimerTestGestureRecognizer* gesture_recognizer =
1408 new TimerTestGestureRecognizer(); 1432 new TimerTestGestureRecognizer();
1409 1433
1410 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 1434 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
1411 1435
1412 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1436 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED,
1413 kTouchId, tes.Now()); 1437 gfx::Point(101, 201),
1438 kTouchId,
1439 ui::EventTimeForNow());
1414 DispatchEventUsingWindowDispatcher(&press1); 1440 DispatchEventUsingWindowDispatcher(&press1);
1415 EXPECT_TRUE(delegate->tap_down()); 1441 EXPECT_TRUE(delegate->tap_down());
1416 EXPECT_TRUE(delegate->begin()); 1442 EXPECT_TRUE(delegate->begin());
1417 EXPECT_FALSE(delegate->tap_cancel()); 1443 EXPECT_FALSE(delegate->tap_cancel());
1418 1444
1419 // We haven't pressed long enough for a long press to occur 1445 // We haven't pressed long enough for a long press to occur
1420 EXPECT_FALSE(delegate->long_press()); 1446 EXPECT_FALSE(delegate->long_press());
1421 1447
1422 // Wait until the timer runs out 1448 // Wait until the timer runs out
1423 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 1449 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
1424 EXPECT_TRUE(delegate->long_press()); 1450 EXPECT_TRUE(delegate->long_press());
1425 EXPECT_FALSE(delegate->tap_cancel()); 1451 EXPECT_FALSE(delegate->tap_cancel());
1426 1452
1427 delegate->Reset(); 1453 delegate->Reset();
1428 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1454 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED,
1429 kTouchId, tes.Now()); 1455 gfx::Point(101, 201),
1456 kTouchId,
1457 ui::EventTimeForNow());
1430 DispatchEventUsingWindowDispatcher(&release1); 1458 DispatchEventUsingWindowDispatcher(&release1);
1431 EXPECT_FALSE(delegate->long_press()); 1459 EXPECT_FALSE(delegate->long_press());
1432 EXPECT_TRUE(delegate->long_tap()); 1460 EXPECT_TRUE(delegate->long_tap());
1433 1461
1434 // Note the tap down isn't cancelled until the release 1462 // Note the tap cancel isn't dispatched until the release
1435 EXPECT_TRUE(delegate->tap_cancel()); 1463 EXPECT_TRUE(delegate->tap_cancel());
1464 EXPECT_FALSE(delegate->tap());
1436 } 1465 }
1437 1466
1438 // Check that second tap cancels a long press 1467 // Check that second tap cancels a long press
1439 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { 1468 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
1469 // TODO(tdresser): enable this test with unified GR once two finger tap is
1470 // supported. See crbug.com/354396.
1471 if (UsingUnifiedGR())
1472 return;
1473
1440 scoped_ptr<GestureEventConsumeDelegate> delegate( 1474 scoped_ptr<GestureEventConsumeDelegate> delegate(
1441 new GestureEventConsumeDelegate()); 1475 new GestureEventConsumeDelegate());
1442 TimedEvents tes; 1476 TimedEvents tes;
1443 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); 1477 ui::GestureConfiguration::set_long_press_time_in_seconds(.01);
1444 const int kWindowWidth = 300; 1478 const int kWindowWidth = 300;
1445 const int kWindowHeight = 400; 1479 const int kWindowHeight = 400;
1446 const int kTouchId1 = 8; 1480 const int kTouchId1 = 8;
1447 const int kTouchId2 = 2; 1481 const int kTouchId2 = 2;
1448 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1482 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1449 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1483 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1520 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1487 kTouchId1, tes.Now()); 1521 kTouchId1, tes.Now());
1488 DispatchEventUsingWindowDispatcher(&release1); 1522 DispatchEventUsingWindowDispatcher(&release1);
1489 EXPECT_FALSE(delegate->long_press()); 1523 EXPECT_FALSE(delegate->long_press());
1490 EXPECT_TRUE(delegate->two_finger_tap()); 1524 EXPECT_TRUE(delegate->two_finger_tap());
1491 EXPECT_FALSE(delegate->tap_cancel()); 1525 EXPECT_FALSE(delegate->tap_cancel());
1492 } 1526 }
1493 1527
1494 // Check that horizontal scroll gestures cause scrolls on horizontal rails. 1528 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1495 // Also tests that horizontal rails can be broken. 1529 // Also tests that horizontal rails can be broken.
1496 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { 1530 TEST_P(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
1497 scoped_ptr<GestureEventConsumeDelegate> delegate( 1531 scoped_ptr<GestureEventConsumeDelegate> delegate(
1498 new GestureEventConsumeDelegate()); 1532 new GestureEventConsumeDelegate());
1499 TimedEvents tes; 1533 TimedEvents tes;
1500 const int kTouchId = 7; 1534 const int kTouchId = 7;
1501 gfx::Rect bounds(0, 0, 1000, 1000); 1535 gfx::Rect bounds(0, 0, 1000, 1000);
1502 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1536 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1503 delegate.get(), -1234, bounds, root_window())); 1537 delegate.get(), -1234, bounds, root_window()));
1504 1538
1505 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1539 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1506 kTouchId, tes.Now()); 1540 kTouchId, tes.Now());
1507 DispatchEventUsingWindowDispatcher(&press); 1541 DispatchEventUsingWindowDispatcher(&press);
1508 1542
1509 // Get rid of touch slop. 1543 // Get rid of touch slop.
1510 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0), 1544 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0),
1511 kTouchId, tes.Now()); 1545 kTouchId, tes.Now());
1512 1546
1513 DispatchEventUsingWindowDispatcher(&move); 1547 DispatchEventUsingWindowDispatcher(&move);
1514 delegate->Reset(); 1548 delegate->Reset();
1515 1549
1516 // Move the touch-point horizontally enough that it is considered a 1550 // Move the touch-point horizontally enough that it is considered a
1517 // horizontal scroll. 1551 // horizontal scroll.
1518 tes.SendScrollEvent(event_processor(), 25, 1, kTouchId, delegate.get()); 1552 tes.SendScrollEvent(event_processor(), 25, 0, kTouchId, delegate.get());
1519 EXPECT_EQ(0, delegate->scroll_y()); 1553 EXPECT_EQ(0, delegate->scroll_y());
1520 EXPECT_EQ(20, delegate->scroll_x()); 1554 EXPECT_EQ(20, delegate->scroll_x());
1521 1555
1522 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get()); 1556 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get());
1523 EXPECT_TRUE(delegate->scroll_update()); 1557 EXPECT_TRUE(delegate->scroll_update());
1524 EXPECT_EQ(5, delegate->scroll_x()); 1558 EXPECT_EQ(5, delegate->scroll_x());
1525 // y shouldn't change, as we're on a horizontal rail. 1559 // y shouldn't change, as we're on a horizontal rail.
1526 EXPECT_EQ(0, delegate->scroll_y()); 1560 EXPECT_EQ(0, delegate->scroll_y());
1527 1561
1528 // Send enough information that a velocity can be calculated for the gesture, 1562 // Send enough information that a velocity can be calculated for the gesture,
1529 // and we can break the rail 1563 // and we can break the rail
1530 tes.SendScrollEvents(event_processor(), 1, 1, 1564 tes.SendScrollEvents(event_processor(), 1, 1,
1531 6, 100, kTouchId, 1, 1565 6, 100, kTouchId, 1,
1532 ui::GestureConfiguration::points_buffered_for_velocity(), 1566 ui::GestureConfiguration::points_buffered_for_velocity(),
1533 delegate.get()); 1567 delegate.get());
1534 1568
1535 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get()); 1569 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get());
1536 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get()); 1570 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get());
1537 1571
1538 // The rail should be broken 1572 // The rail should be broken
1539 EXPECT_TRUE(delegate->scroll_update()); 1573 EXPECT_TRUE(delegate->scroll_update());
1540 EXPECT_EQ(5, delegate->scroll_x()); 1574 EXPECT_EQ(5, delegate->scroll_x());
1541 EXPECT_EQ(5, delegate->scroll_y()); 1575 EXPECT_EQ(5, delegate->scroll_y());
1542 } 1576 }
1543 1577
1544 // Check that vertical scroll gestures cause scrolls on vertical rails. 1578 // Check that vertical scroll gestures cause scrolls on vertical rails.
1545 // Also tests that vertical rails can be broken. 1579 // Also tests that vertical rails can be broken.
1546 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { 1580 TEST_P(GestureRecognizerTest, GestureEventVerticalRailScroll) {
1547 scoped_ptr<GestureEventConsumeDelegate> delegate( 1581 scoped_ptr<GestureEventConsumeDelegate> delegate(
1548 new GestureEventConsumeDelegate()); 1582 new GestureEventConsumeDelegate());
1549 TimedEvents tes; 1583 TimedEvents tes;
1550 const int kTouchId = 7; 1584 const int kTouchId = 7;
1551 gfx::Rect bounds(0, 0, 1000, 1000); 1585 gfx::Rect bounds(0, 0, 1000, 1000);
1552 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1586 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1553 delegate.get(), -1234, bounds, root_window())); 1587 delegate.get(), -1234, bounds, root_window()));
1554 1588
1555 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1589 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1556 kTouchId, tes.Now()); 1590 kTouchId, tes.Now());
1557 DispatchEventUsingWindowDispatcher(&press); 1591 DispatchEventUsingWindowDispatcher(&press);
1558 1592
1559 // Get rid of touch slop. 1593 // Get rid of touch slop.
1560 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5), 1594 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5),
1561 kTouchId, tes.Now()); 1595 kTouchId, tes.Now());
1562 DispatchEventUsingWindowDispatcher(&move); 1596 DispatchEventUsingWindowDispatcher(&move);
1563 delegate->Reset(); 1597 delegate->Reset();
1564 1598
1565 // Move the touch-point vertically enough that it is considered a 1599 // Move the touch-point vertically enough that it is considered a
1566 // vertical scroll. 1600 // vertical scroll.
1567 tes.SendScrollEvent(event_processor(), 1, 25, kTouchId, delegate.get()); 1601 tes.SendScrollEvent(event_processor(), 0, 25, kTouchId, delegate.get());
1568 EXPECT_EQ(0, delegate->scroll_x()); 1602 EXPECT_EQ(0, delegate->scroll_x());
1569 EXPECT_EQ(20, delegate->scroll_y()); 1603 EXPECT_EQ(20, delegate->scroll_y());
1570 1604
1571 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get()); 1605 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get());
1572 EXPECT_TRUE(delegate->scroll_update()); 1606 EXPECT_TRUE(delegate->scroll_update());
1573 EXPECT_EQ(5, delegate->scroll_y()); 1607 EXPECT_EQ(5, delegate->scroll_y());
1574 // x shouldn't change, as we're on a vertical rail. 1608 // x shouldn't change, as we're on a vertical rail.
1575 EXPECT_EQ(0, delegate->scroll_x()); 1609 EXPECT_EQ(0, delegate->scroll_x());
1576 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1610 EXPECT_EQ(0, delegate->scroll_velocity_x());
1577 1611
1578 // Send enough information that a velocity can be calculated for the gesture, 1612 // Send enough information that a velocity can be calculated for the gesture,
1579 // and we can break the rail 1613 // and we can break the rail
1580 tes.SendScrollEvents(event_processor(), 1, 6, 1614 tes.SendScrollEvents(event_processor(), 1, 6,
1581 100, 1, kTouchId, 1, 1615 100, 1, kTouchId, 1,
1582 ui::GestureConfiguration::points_buffered_for_velocity(), 1616 ui::GestureConfiguration::points_buffered_for_velocity(),
1583 delegate.get()); 1617 delegate.get());
1584 1618
1585 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get()); 1619 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get());
1586 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get()); 1620 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get());
1587 1621
1588 // The rail should be broken 1622 // The rail should be broken
1589 EXPECT_TRUE(delegate->scroll_update()); 1623 EXPECT_TRUE(delegate->scroll_update());
1590 EXPECT_EQ(5, delegate->scroll_x()); 1624 EXPECT_EQ(5, delegate->scroll_x());
1591 EXPECT_EQ(5, delegate->scroll_y()); 1625 EXPECT_EQ(5, delegate->scroll_y());
1592 } 1626 }
1593 1627
1594 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { 1628 TEST_P(GestureRecognizerTest, GestureTapFollowedByScroll) {
1595 // We'll start by moving the touch point by (5, 5). We want all of that 1629 // 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 1630 // distance to be consumed by the slop, so we set the slop radius to
1597 // sqrt(5 * 5 + 5 * 5). 1631 // sqrt(5 * 5 + 5 * 5).
1598 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( 1632 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1599 sqrt(static_cast<double>(5 * 5 + 5 * 5))); 1633 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1600 1634
1601 // First, tap. Then, do a scroll using the same touch-id. 1635 // First, tap. Then, do a scroll using the same touch-id.
1602 scoped_ptr<GestureEventConsumeDelegate> delegate( 1636 scoped_ptr<GestureEventConsumeDelegate> delegate(
1603 new GestureEventConsumeDelegate()); 1637 new GestureEventConsumeDelegate());
1604 TimedEvents tes; 1638 TimedEvents tes;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 kTouchId, tes.LeapForward(1000)); 1674 kTouchId, tes.LeapForward(1000));
1641 DispatchEventUsingWindowDispatcher(&press1); 1675 DispatchEventUsingWindowDispatcher(&press1);
1642 EXPECT_FALSE(delegate->tap()); 1676 EXPECT_FALSE(delegate->tap());
1643 EXPECT_TRUE(delegate->tap_down()); 1677 EXPECT_TRUE(delegate->tap_down());
1644 EXPECT_FALSE(delegate->tap_cancel()); 1678 EXPECT_FALSE(delegate->tap_cancel());
1645 EXPECT_FALSE(delegate->scroll_begin()); 1679 EXPECT_FALSE(delegate->scroll_begin());
1646 EXPECT_FALSE(delegate->scroll_update()); 1680 EXPECT_FALSE(delegate->scroll_update());
1647 EXPECT_FALSE(delegate->scroll_end()); 1681 EXPECT_FALSE(delegate->scroll_end());
1648 1682
1649 // Get rid of touch slop. 1683 // Get rid of touch slop.
1650 ui::TouchEvent move_remove_slop(ui::ET_TOUCH_MOVED, gfx::Point(106, 206), 1684 ui::TouchEvent move_remove_slop(ui::ET_TOUCH_MOVED, gfx::Point(116, 216),
1651 kTouchId, tes.Now()); 1685 kTouchId, tes.Now());
1652 DispatchEventUsingWindowDispatcher(&move_remove_slop); 1686 DispatchEventUsingWindowDispatcher(&move_remove_slop);
1653 EXPECT_TRUE(delegate->tap_cancel()); 1687 EXPECT_TRUE(delegate->tap_cancel());
1654 EXPECT_TRUE(delegate->scroll_begin()); 1688 EXPECT_TRUE(delegate->scroll_begin());
1655 EXPECT_FALSE(delegate->scroll_update()); 1689 EXPECT_TRUE(delegate->scroll_update());
1656 EXPECT_EQ(5, delegate->scroll_x_hint()); 1690 EXPECT_EQ(15, delegate->scroll_x_hint());
1657 EXPECT_EQ(5, delegate->scroll_y_hint()); 1691 EXPECT_EQ(15, delegate->scroll_y_hint());
1658 1692
1659 delegate->Reset(); 1693 delegate->Reset();
1660 1694
1661 // Move the touch-point enough so that it is considered as a scroll. This 1695 // Move the touch-point enough so that it is considered as a scroll. This
1662 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1696 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1663 // The first movement is diagonal, to ensure that we have a free scroll, 1697 // The first movement is diagonal, to ensure that we have a free scroll,
1664 // and not a rail scroll. 1698 // and not a rail scroll.
1665 delegate->Reset(); 1699 delegate->Reset();
1666 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(135, 235), 1700 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(135, 235),
1667 kTouchId, tes.Now()); 1701 kTouchId, tes.Now());
1668 DispatchEventUsingWindowDispatcher(&move); 1702 DispatchEventUsingWindowDispatcher(&move);
1669 EXPECT_FALSE(delegate->tap()); 1703 EXPECT_FALSE(delegate->tap());
1670 EXPECT_FALSE(delegate->tap_down()); 1704 EXPECT_FALSE(delegate->tap_down());
1671 EXPECT_FALSE(delegate->tap_cancel()); 1705 EXPECT_FALSE(delegate->tap_cancel());
1672 EXPECT_FALSE(delegate->scroll_begin()); 1706 EXPECT_FALSE(delegate->scroll_begin());
1673 EXPECT_TRUE(delegate->scroll_update()); 1707 EXPECT_TRUE(delegate->scroll_update());
1674 EXPECT_FALSE(delegate->scroll_end()); 1708 EXPECT_FALSE(delegate->scroll_end());
1675 EXPECT_EQ(29, delegate->scroll_x()); 1709 EXPECT_EQ(19, delegate->scroll_x());
1676 EXPECT_EQ(29, delegate->scroll_y()); 1710 EXPECT_EQ(19, delegate->scroll_y());
1677 1711
1678 // Move some more to generate a few more scroll updates. 1712 // Move some more to generate a few more scroll updates.
1679 delegate->Reset(); 1713 delegate->Reset();
1680 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(115, 216), 1714 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(115, 216),
1681 kTouchId, tes.Now()); 1715 kTouchId, tes.Now());
1682 DispatchEventUsingWindowDispatcher(&move1); 1716 DispatchEventUsingWindowDispatcher(&move1);
1683 EXPECT_FALSE(delegate->tap()); 1717 EXPECT_FALSE(delegate->tap());
1684 EXPECT_FALSE(delegate->tap_down()); 1718 EXPECT_FALSE(delegate->tap_down());
1685 EXPECT_FALSE(delegate->tap_cancel()); 1719 EXPECT_FALSE(delegate->tap_cancel());
1686 EXPECT_FALSE(delegate->scroll_begin()); 1720 EXPECT_FALSE(delegate->scroll_begin());
(...skipping 24 matching lines...) Expand all
1711 DispatchEventUsingWindowDispatcher(&release1); 1745 DispatchEventUsingWindowDispatcher(&release1);
1712 EXPECT_FALSE(delegate->tap()); 1746 EXPECT_FALSE(delegate->tap());
1713 EXPECT_FALSE(delegate->tap_down()); 1747 EXPECT_FALSE(delegate->tap_down());
1714 EXPECT_FALSE(delegate->tap_cancel()); 1748 EXPECT_FALSE(delegate->tap_cancel());
1715 EXPECT_FALSE(delegate->scroll_begin()); 1749 EXPECT_FALSE(delegate->scroll_begin());
1716 EXPECT_FALSE(delegate->scroll_update()); 1750 EXPECT_FALSE(delegate->scroll_update());
1717 EXPECT_FALSE(delegate->scroll_end()); 1751 EXPECT_FALSE(delegate->scroll_end());
1718 EXPECT_TRUE(delegate->fling()); 1752 EXPECT_TRUE(delegate->fling());
1719 } 1753 }
1720 1754
1721 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { 1755 TEST_P(GestureRecognizerTest, AsynchronousGestureRecognition) {
1756 // TODO(tdresser): enable this test with unified GR once two finger tap is
1757 // supported. See crbug.com/354396.
1758 if (UsingUnifiedGR())
1759 return;
1722 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 1760 scoped_ptr<QueueTouchEventDelegate> queued_delegate(
1723 new QueueTouchEventDelegate(host()->dispatcher())); 1761 new QueueTouchEventDelegate(host()->dispatcher()));
1724 const int kWindowWidth = 123; 1762 const int kWindowWidth = 123;
1725 const int kWindowHeight = 45; 1763 const int kWindowHeight = 45;
1726 const int kTouchId1 = 6; 1764 const int kTouchId1 = 6;
1727 const int kTouchId2 = 4; 1765 const int kTouchId2 = 4;
1728 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1766 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1729 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 1767 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
1730 queued_delegate.get(), -1234, bounds, root_window())); 1768 queued_delegate.get(), -1234, bounds, root_window()));
1731 1769
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 EXPECT_FALSE(queued_delegate->end()); 1941 EXPECT_FALSE(queued_delegate->end());
1904 EXPECT_TRUE(queued_delegate->scroll_begin()); 1942 EXPECT_TRUE(queued_delegate->scroll_begin());
1905 EXPECT_FALSE(queued_delegate->scroll_update()); 1943 EXPECT_FALSE(queued_delegate->scroll_update());
1906 EXPECT_FALSE(queued_delegate->scroll_end()); 1944 EXPECT_FALSE(queued_delegate->scroll_end());
1907 EXPECT_TRUE(queued_delegate->pinch_begin()); 1945 EXPECT_TRUE(queued_delegate->pinch_begin());
1908 EXPECT_FALSE(queued_delegate->pinch_update()); 1946 EXPECT_FALSE(queued_delegate->pinch_update());
1909 EXPECT_FALSE(queued_delegate->pinch_end()); 1947 EXPECT_FALSE(queued_delegate->pinch_end());
1910 } 1948 }
1911 1949
1912 // Check that appropriate touch events generate pinch gesture events. 1950 // Check that appropriate touch events generate pinch gesture events.
1913 TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) { 1951 TEST_P(GestureRecognizerTest, GestureEventPinchFromScroll) {
1952 // Disabled for unified GR due to differences in when pinch begin is sent. The
1953 // Aura GR sends it earlier than is necessary.
1954 if (UsingUnifiedGR())
1955 return;
1956
1914 scoped_ptr<GestureEventConsumeDelegate> delegate( 1957 scoped_ptr<GestureEventConsumeDelegate> delegate(
1915 new GestureEventConsumeDelegate()); 1958 new GestureEventConsumeDelegate());
1916 TimedEvents tes; 1959 TimedEvents tes;
1917 const int kWindowWidth = 300; 1960 const int kWindowWidth = 300;
1918 const int kWindowHeight = 400; 1961 const int kWindowHeight = 400;
1919 const int kTouchId1 = 5; 1962 const int kTouchId1 = 5;
1920 const int kTouchId2 = 3; 1963 const int kTouchId2 = 3;
1921 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1964 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1922 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1965 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1923 delegate.get(), -1234, bounds, root_window())); 1966 delegate.get(), -1234, bounds, root_window()));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 2031
1989 // Move the second finger. This should still generate a scroll. 2032 // Move the second finger. This should still generate a scroll.
1990 delegate->Reset(); 2033 delegate->Reset();
1991 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 2034 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
1992 kTouchId2, tes.Now()); 2035 kTouchId2, tes.Now());
1993 DispatchEventUsingWindowDispatcher(&move5); 2036 DispatchEventUsingWindowDispatcher(&move5);
1994 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 2037 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
1995 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2038 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1996 } 2039 }
1997 2040
1998 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { 2041 TEST_P(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
1999 scoped_ptr<GestureEventConsumeDelegate> delegate( 2042 scoped_ptr<GestureEventConsumeDelegate> delegate(
2000 new GestureEventConsumeDelegate()); 2043 new GestureEventConsumeDelegate());
2001 TimedEvents tes; 2044 TimedEvents tes;
2002 const int kWindowWidth = 300; 2045 const int kWindowWidth = 300;
2003 const int kWindowHeight = 400; 2046 const int kWindowHeight = 400;
2004 const int kTouchId1 = 5; 2047 const int kTouchId1 = 5;
2005 const int kTouchId2 = 3; 2048 const int kTouchId2 = 3;
2006 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 2049 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
2007 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2050 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2008 delegate.get(), -1234, bounds, root_window())); 2051 delegate.get(), -1234, bounds, root_window()));
(...skipping 27 matching lines...) Expand all
2036 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId2, delegate.get()); 2079 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId2, delegate.get());
2037 EXPECT_TRUE(delegate->scroll_update()); 2080 EXPECT_TRUE(delegate->scroll_update());
2038 2081
2039 // Pinch again 2082 // Pinch again
2040 delegate->Reset(); 2083 delegate->Reset();
2041 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2084 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
2042 kTouchId1, tes.Now()); 2085 kTouchId1, tes.Now());
2043 DispatchEventUsingWindowDispatcher(&press3); 2086 DispatchEventUsingWindowDispatcher(&press3);
2044 // Now the touch points are close. So we will go into two finger tap. 2087 // Now the touch points are close. So we will go into two finger tap.
2045 // Move the touch-point enough to break two-finger-tap and enter pinch. 2088 // Move the touch-point enough to break two-finger-tap and enter pinch.
2046 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202), 2089 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50),
2047 kTouchId1, tes.Now()); 2090 kTouchId1, tes.Now());
2048 DispatchEventUsingWindowDispatcher(&move2); 2091 DispatchEventUsingWindowDispatcher(&move2);
2049 EXPECT_TRUE(delegate->pinch_begin()); 2092 EXPECT_TRUE(delegate->pinch_begin());
2050 2093
2051 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId1, delegate.get()); 2094 tes.SendScrollEvent(event_processor(), 350, 350, kTouchId1, delegate.get());
2052 EXPECT_TRUE(delegate->pinch_update()); 2095 EXPECT_TRUE(delegate->pinch_update());
2053 } 2096 }
2054 2097
2055 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { 2098 TEST_P(GestureRecognizerTest, GestureEventPinchFromTap) {
2099 // TODO(tdresser): enable this test with unified GR once two finger tap.
2100 if (UsingUnifiedGR())
2101 return;
2102
2056 scoped_ptr<GestureEventConsumeDelegate> delegate( 2103 scoped_ptr<GestureEventConsumeDelegate> delegate(
2057 new GestureEventConsumeDelegate()); 2104 new GestureEventConsumeDelegate());
2058 TimedEvents tes; 2105 TimedEvents tes;
2059 const int kWindowWidth = 300; 2106 const int kWindowWidth = 300;
2060 const int kWindowHeight = 400; 2107 const int kWindowHeight = 400;
2061 const int kTouchId1 = 3; 2108 const int kTouchId1 = 3;
2062 const int kTouchId2 = 5; 2109 const int kTouchId2 = 5;
2063 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 2110 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
2064 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2111 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2065 delegate.get(), -1234, bounds, root_window())); 2112 delegate.get(), -1234, bounds, root_window()));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 2166
2120 // Move the second finger. This should still generate a scroll. 2167 // Move the second finger. This should still generate a scroll.
2121 delegate->Reset(); 2168 delegate->Reset();
2122 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 2169 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
2123 kTouchId2, tes.Now()); 2170 kTouchId2, tes.Now());
2124 DispatchEventUsingWindowDispatcher(&move5); 2171 DispatchEventUsingWindowDispatcher(&move5);
2125 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 2172 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
2126 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2173 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
2127 } 2174 }
2128 2175
2129 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { 2176 TEST_P(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
2130 scoped_ptr<GestureEventConsumeDelegate> delegate( 2177 scoped_ptr<GestureEventConsumeDelegate> delegate(
2131 new GestureEventConsumeDelegate()); 2178 new GestureEventConsumeDelegate());
2132 TimedEvents tes; 2179 TimedEvents tes;
2133 2180
2134 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2181 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2135 6, tes.Now()); 2182 6, tes.Now());
2136 DispatchEventUsingWindowDispatcher(&release1); 2183 DispatchEventUsingWindowDispatcher(&release1);
2137 EXPECT_FALSE(delegate->tap()); 2184 EXPECT_FALSE(delegate->tap());
2138 EXPECT_FALSE(delegate->tap_down()); 2185 EXPECT_FALSE(delegate->tap_down());
2139 } 2186 }
2140 2187
2141 // Check that a touch is locked to the window of the closest current touch 2188 // Check that a touch is locked to the window of the closest current touch
2142 // within max_separation_for_gesture_touches_in_pixels 2189 // within max_separation_for_gesture_touches_in_pixels
2143 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { 2190 TEST_P(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
2144 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl(); 2191 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl();
2145 TimedEvents tes; 2192 TimedEvents tes;
2146 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2193 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2147 2194
2148 ui::GestureConsumer* target; 2195 ui::GestureConsumer* target;
2149 const int kNumWindows = 4; 2196 const int kNumWindows = 4;
2150 2197
2151 scoped_ptr<GestureEventConsumeDelegate*[]> delegates( 2198 scoped_ptr<GestureEventConsumeDelegate*[]> delegates(
2152 new GestureEventConsumeDelegate*[kNumWindows]); 2199 new GestureEventConsumeDelegate*[kNumWindows]);
2153 2200
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2219 2266
2220 for (int i = 0; i < kNumWindows; ++i) { 2267 for (int i = 0; i < kNumWindows; ++i) {
2221 // Delete windows before deleting delegates. 2268 // Delete windows before deleting delegates.
2222 delete windows[i]; 2269 delete windows[i];
2223 delete delegates[i]; 2270 delete delegates[i];
2224 } 2271 }
2225 } 2272 }
2226 2273
2227 // Check that a touch's target will not be effected by a touch on a different 2274 // Check that a touch's target will not be effected by a touch on a different
2228 // screen. 2275 // screen.
2229 TEST_F(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) { 2276 TEST_P(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) {
2230 scoped_ptr<GestureEventConsumeDelegate> delegate( 2277 scoped_ptr<GestureEventConsumeDelegate> delegate(
2231 new GestureEventConsumeDelegate()); 2278 new GestureEventConsumeDelegate());
2232 gfx::Rect bounds(0, 0, 10, 10); 2279 gfx::Rect bounds(0, 0, 10, 10);
2233 scoped_ptr<aura::Window> window( 2280 scoped_ptr<aura::Window> window(
2234 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); 2281 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
2235 2282
2236 const int kTouchId1 = 8; 2283 const int kTouchId1 = 8;
2237 const int kTouchId2 = 2; 2284 const int kTouchId2 = 2;
2238 TimedEvents tes; 2285 TimedEvents tes;
2239 2286
2240 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5), 2287 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5),
2241 kTouchId1, tes.Now()); 2288 kTouchId1, tes.Now());
2242 press1.set_source_device_id(1); 2289 press1.set_source_device_id(1);
2243 DispatchEventUsingWindowDispatcher(&press1); 2290 DispatchEventUsingWindowDispatcher(&press1);
2244 2291
2245 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2292 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2246 kTouchId2, tes.Now()); 2293 kTouchId2, tes.Now());
2247 press2.set_source_device_id(2); 2294 press2.set_source_device_id(2);
2248 DispatchEventUsingWindowDispatcher(&press2); 2295 DispatchEventUsingWindowDispatcher(&press2);
2249 2296
2250 // The second press should not have been locked to the same target as the 2297 // The second press should not have been locked to the same target as the
2251 // first, as they occured on different displays. 2298 // first, as they occured on different displays.
2252 EXPECT_NE( 2299 EXPECT_NE(
2253 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1), 2300 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1),
2254 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)); 2301 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
2255 } 2302 }
2256 2303
2257 // Check that touch events outside the root window are still handled 2304 // Check that touch events outside the root window are still handled
2258 // by the root window's gesture sequence. 2305 // by the root window's gesture sequence.
2259 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { 2306 TEST_P(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
2307 // TODO(tdresser): write a version of this test for the unified GR.
2308 if (UsingUnifiedGR())
2309 return;
2310
2260 TestGestureRecognizer* gesture_recognizer = 2311 TestGestureRecognizer* gesture_recognizer =
2261 new TestGestureRecognizer(); 2312 new TestGestureRecognizer();
2262 TimedEvents tes; 2313 TimedEvents tes;
2263 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2314 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2264 2315
2265 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( 2316 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds(
2266 gfx::Rect(-100, -100, 2000, 2000), root_window())); 2317 gfx::Rect(-100, -100, 2000, 2000), root_window()));
2267 2318
2268 ui::GestureSequence* window_gesture_sequence = 2319 ui::GestureSequence* window_gesture_sequence =
2269 gesture_recognizer->GetGestureSequenceForTesting(window.get()); 2320 gesture_recognizer->GetGestureSequenceForTesting(window.get());
2270 2321
2271 ui::GestureSequence* root_window_gesture_sequence = 2322 ui::GestureSequence* root_window_gesture_sequence =
2272 gesture_recognizer->GetGestureSequenceForTesting(root_window()); 2323 gesture_recognizer->GetGestureSequenceForTesting(root_window());
2273 2324
2274 gfx::Point pos1(-10, -10); 2325 gfx::Point pos1(-10, -10);
2275 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now()); 2326 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now());
2276 DispatchEventUsingWindowDispatcher(&press1); 2327 DispatchEventUsingWindowDispatcher(&press1);
2277 2328
2278 gfx::Point pos2(1000, 1000); 2329 gfx::Point pos2(1000, 1000);
2279 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, tes.Now()); 2330 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, tes.Now());
2280 DispatchEventUsingWindowDispatcher(&press2); 2331 DispatchEventUsingWindowDispatcher(&press2);
2281 2332
2282 // As these presses were outside the root window, they should be 2333 // As these presses were outside the root window, they should be
2283 // associated with the root window. 2334 // associated with the root window.
2284 EXPECT_EQ(0, window_gesture_sequence->point_count()); 2335 EXPECT_EQ(0, window_gesture_sequence->point_count());
2285 EXPECT_EQ(2, root_window_gesture_sequence->point_count()); 2336 EXPECT_EQ(2, root_window_gesture_sequence->point_count());
2286 } 2337 }
2287 2338
2288 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { 2339 TEST_P(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
2289 scoped_ptr<QueueTouchEventDelegate> delegate( 2340 scoped_ptr<QueueTouchEventDelegate> delegate(
2290 new QueueTouchEventDelegate(host()->dispatcher())); 2341 new QueueTouchEventDelegate(host()->dispatcher()));
2291 TimedEvents tes; 2342 TimedEvents tes;
2292 const int kTouchId = 2; 2343 const int kTouchId = 2;
2293 gfx::Rect bounds(100, 200, 100, 100); 2344 gfx::Rect bounds(100, 200, 100, 100);
2294 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2345 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2295 delegate.get(), -1234, bounds, root_window())); 2346 delegate.get(), -1234, bounds, root_window()));
2296 delegate->set_window(window.get()); 2347 delegate->set_window(window.get());
2297 2348
2298 delegate->Reset(); 2349 delegate->Reset();
2299 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2350 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2300 kTouchId, tes.Now()); 2351 kTouchId, tes.Now());
2301 DispatchEventUsingWindowDispatcher(&press); 2352 DispatchEventUsingWindowDispatcher(&press);
2302 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2353 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2303 kTouchId, tes.LeapForward(50)); 2354 kTouchId, tes.LeapForward(50));
2304 DispatchEventUsingWindowDispatcher(&release); 2355 DispatchEventUsingWindowDispatcher(&release);
2305 2356
2306 delegate->Reset(); 2357 delegate->Reset();
2307 delegate->ReceivedAck(); 2358 delegate->ReceivedAck();
2308 EXPECT_TRUE(delegate->tap_down()); 2359 EXPECT_TRUE(delegate->tap_down());
2309 delegate->Reset(); 2360 delegate->Reset();
2310 delegate->ReceivedAckPreventDefaulted(); 2361 delegate->ReceivedAckPreventDefaulted();
2311 EXPECT_FALSE(delegate->tap()); 2362 EXPECT_FALSE(delegate->tap());
2312 EXPECT_TRUE(delegate->tap_cancel()); 2363 EXPECT_TRUE(delegate->tap_cancel());
2313 } 2364 }
2314 2365
2315 TEST_F(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) { 2366 TEST_P(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) {
2367 // Disabled for unified GR due to differences in when pinch begin is sent. The
2368 // Aura GR sends it earlier than is necessary.
2369 if (UsingUnifiedGR())
2370 return;
2371
2316 scoped_ptr<QueueTouchEventDelegate> delegate( 2372 scoped_ptr<QueueTouchEventDelegate> delegate(
2317 new QueueTouchEventDelegate(host()->dispatcher())); 2373 new QueueTouchEventDelegate(host()->dispatcher()));
2318 TimedEvents tes; 2374 TimedEvents tes;
2319 const int kTouchId1 = 7; 2375 const int kTouchId1 = 7;
2320 const int kTouchId2 = 5; 2376 const int kTouchId2 = 5;
2321 gfx::Rect bounds(10, 20, 100, 100); 2377 gfx::Rect bounds(10, 20, 100, 100);
2322 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2378 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2323 delegate.get(), -1234, bounds, root_window())); 2379 delegate.get(), -1234, bounds, root_window()));
2324 delegate->set_window(window.get()); 2380 delegate->set_window(window.get());
2325 2381
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 delegate->ReceivedAckPreventDefaulted(); 2455 delegate->ReceivedAckPreventDefaulted();
2400 EXPECT_TRUE(delegate->pinch_end()); 2456 EXPECT_TRUE(delegate->pinch_end());
2401 EXPECT_TRUE(delegate->end()); 2457 EXPECT_TRUE(delegate->end());
2402 2458
2403 delegate->Reset(); 2459 delegate->Reset();
2404 delegate->ReceivedAckPreventDefaulted(); 2460 delegate->ReceivedAckPreventDefaulted();
2405 EXPECT_TRUE(delegate->scroll_end()); 2461 EXPECT_TRUE(delegate->scroll_end());
2406 EXPECT_TRUE(delegate->end()); 2462 EXPECT_TRUE(delegate->end());
2407 } 2463 }
2408 2464
2409 TEST_F(GestureRecognizerTest, GestureEndLocation) { 2465 TEST_P(GestureRecognizerTest, GestureEndLocation) {
2410 GestureEventConsumeDelegate delegate; 2466 GestureEventConsumeDelegate delegate;
2411 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2467 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2412 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2468 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2413 EventGenerator generator(root_window(), window.get()); 2469 EventGenerator generator(root_window(), window.get());
2414 const gfx::Point begin(20, 20); 2470 const gfx::Point begin(20, 20);
2415 const gfx::Point end(150, 150); 2471 const gfx::Point end(150, 150);
2416 const gfx::Vector2d window_offset = 2472 const gfx::Vector2d window_offset =
2417 window->bounds().origin().OffsetFromOrigin(); 2473 window->bounds().origin().OffsetFromOrigin();
2418 generator.GestureScrollSequence(begin, end, 2474 generator.GestureScrollSequence(begin, end,
2419 base::TimeDelta::FromMilliseconds(20), 2475 base::TimeDelta::FromMilliseconds(20),
2420 10); 2476 10);
2421 EXPECT_EQ((begin - window_offset).ToString(), 2477 EXPECT_EQ((begin - window_offset).ToString(),
2422 delegate.scroll_begin_position().ToString()); 2478 delegate.scroll_begin_position().ToString());
2423 EXPECT_EQ((end - window_offset).ToString(), 2479 EXPECT_EQ((end - window_offset).ToString(),
2424 delegate.gesture_end_location().ToString()); 2480 delegate.gesture_end_location().ToString());
2425 } 2481 }
2426 2482
2427 TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) { 2483 TEST_P(GestureRecognizerTest, CaptureSendsGestureEnd) {
2428 scoped_ptr<GestureEventConsumeDelegate> delegate( 2484 scoped_ptr<GestureEventConsumeDelegate> delegate(
2429 new GestureEventConsumeDelegate()); 2485 new GestureEventConsumeDelegate());
2430 TestGestureRecognizer* gesture_recognizer = 2486 TestGestureRecognizer* gesture_recognizer =
2431 new TestGestureRecognizer(); 2487 new TestGestureRecognizer();
2432 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2488 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2433 2489
2434 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2490 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2435 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2491 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2436 EventGenerator generator(root_window()); 2492 EventGenerator generator(root_window());
2437 2493
2438 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10)); 2494 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10));
2439 generator.PressTouch(); 2495 generator.PressTouch();
2440 RunAllPendingInMessageLoop(); 2496 RunAllPendingInMessageLoop();
2441 2497
2442 EXPECT_TRUE(delegate->tap_down()); 2498 EXPECT_TRUE(delegate->tap_down());
2443 2499
2444 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds( 2500 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds(
2445 gfx::Rect(10, 10, 200, 200), root_window())); 2501 gfx::Rect(10, 10, 200, 200), root_window()));
2446 capture->SetCapture(); 2502 capture->SetCapture();
2447 RunAllPendingInMessageLoop(); 2503 RunAllPendingInMessageLoop();
2448 2504
2449 EXPECT_TRUE(delegate->end()); 2505 EXPECT_TRUE(delegate->end());
2450 EXPECT_TRUE(delegate->tap_cancel()); 2506 EXPECT_TRUE(delegate->tap_cancel());
2451 } 2507 }
2452 2508
2453 // Check that previous touch actions that are completely finished (either 2509 // Check that previous touch actions that are completely finished (either
2454 // released or cancelled), do not receive extra synthetic cancels upon change of 2510 // released or cancelled), do not receive extra synthetic cancels upon change of
2455 // capture. 2511 // capture.
2456 TEST_F(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) { 2512 TEST_P(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) {
2457 scoped_ptr<GestureEventConsumeDelegate> delegate( 2513 scoped_ptr<GestureEventConsumeDelegate> delegate(
2458 new GestureEventConsumeDelegate()); 2514 new GestureEventConsumeDelegate());
2459 scoped_ptr<TestEventHandler> handler(new TestEventHandler); 2515 scoped_ptr<TestEventHandler> handler(new TestEventHandler);
2460 root_window()->AddPreTargetHandler(handler.get()); 2516 root_window()->AddPreTargetHandler(handler.get());
2461 2517
2462 // Create a window and set it as the capture window. 2518 // Create a window and set it as the capture window.
2463 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(delegate.get(), 2519 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(delegate.get(),
2464 -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2520 -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2465 window1->SetCapture(); 2521 window1->SetCapture();
2466 2522
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 gfx::Rect(100, 100, 300, 300), root_window())); 2555 gfx::Rect(100, 100, 300, 300), root_window()));
2500 window2->SetCapture(); 2556 window2->SetCapture();
2501 RunAllPendingInMessageLoop(); 2557 RunAllPendingInMessageLoop();
2502 // Check that setting capture does not generate any synthetic touch-cancels 2558 // Check that setting capture does not generate any synthetic touch-cancels
2503 // for the two previously finished touch actions. 2559 // for the two previously finished touch actions.
2504 EXPECT_EQ(1, handler->touch_cancelled_count()); 2560 EXPECT_EQ(1, handler->touch_cancelled_count());
2505 2561
2506 root_window()->RemovePreTargetHandler(handler.get()); 2562 root_window()->RemovePreTargetHandler(handler.get());
2507 } 2563 }
2508 2564
2509 TEST_F(GestureRecognizerTest, PressDoesNotCrash) { 2565 // Tests that a press with the same touch id as an existing touch is ignored.
2566 TEST_P(GestureRecognizerTest, PressDoesNotCrash) {
2510 scoped_ptr<GestureEventConsumeDelegate> delegate( 2567 scoped_ptr<GestureEventConsumeDelegate> delegate(
2511 new GestureEventConsumeDelegate()); 2568 new GestureEventConsumeDelegate());
2512 TestGestureRecognizer* gesture_recognizer = 2569 TestGestureRecognizer* gesture_recognizer =
2513 new TestGestureRecognizer(); 2570 new TestGestureRecognizer();
2514 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2571 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2515 TimedEvents tes; 2572 TimedEvents tes;
2516 2573
2517 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2574 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2518 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2575 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2519 2576
2520 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, tes.Now()); 2577 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, tes.Now());
2521 press.set_radius_x(40); 2578 press.set_radius_x(40);
2522 DispatchEventUsingWindowDispatcher(&press); 2579 DispatchEventUsingWindowDispatcher(&press);
2523 EXPECT_TRUE(delegate->tap_down()); 2580 EXPECT_TRUE(delegate->tap_down());
2524 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(), 2581 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(),
2525 delegate->bounding_box().ToString()); 2582 delegate->bounding_box().ToString());
2526 delegate->Reset(); 2583 delegate->Reset();
2527 2584
2528 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, tes.Now()); 2585 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, tes.Now());
2529 DispatchEventUsingWindowDispatcher(&press2); 2586 DispatchEventUsingWindowDispatcher(&press2);
2530 2587
2531 // This new press should not generate a tap-down. 2588 // This new press should not generate a tap-down.
2532 EXPECT_FALSE(delegate->begin()); 2589 EXPECT_FALSE(delegate->begin());
2533 EXPECT_FALSE(delegate->tap_down()); 2590 EXPECT_FALSE(delegate->tap_down());
2534 EXPECT_FALSE(delegate->tap_cancel()); 2591 EXPECT_FALSE(delegate->tap_cancel());
2535 EXPECT_FALSE(delegate->scroll_begin()); 2592 EXPECT_FALSE(delegate->scroll_begin());
2536 } 2593 }
2537 2594
2538 TEST_F(GestureRecognizerTest, TwoFingerTap) { 2595 TEST_P(GestureRecognizerTest, TwoFingerTap) {
2596 // TODO(tdresser): enable this test with unified GR once two finger tap is
2597 // supported. See crbug.com/354396.
2598 if (UsingUnifiedGR())
2599 return;
2600
2539 scoped_ptr<GestureEventConsumeDelegate> delegate( 2601 scoped_ptr<GestureEventConsumeDelegate> delegate(
2540 new GestureEventConsumeDelegate()); 2602 new GestureEventConsumeDelegate());
2541 const int kWindowWidth = 123; 2603 const int kWindowWidth = 123;
2542 const int kWindowHeight = 45; 2604 const int kWindowHeight = 45;
2543 const int kTouchId1 = 2; 2605 const int kTouchId1 = 2;
2544 const int kTouchId2 = 3; 2606 const int kTouchId2 = 3;
2545 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2607 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2546 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2608 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2547 delegate.get(), -1234, bounds, root_window())); 2609 delegate.get(), -1234, bounds, root_window()));
2548 TimedEvents tes; 2610 TimedEvents tes;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2616 EXPECT_FALSE(delegate->tap()); 2678 EXPECT_FALSE(delegate->tap());
2617 EXPECT_FALSE(delegate->tap_down()); 2679 EXPECT_FALSE(delegate->tap_down());
2618 EXPECT_FALSE(delegate->tap_cancel()); 2680 EXPECT_FALSE(delegate->tap_cancel());
2619 EXPECT_FALSE(delegate->scroll_begin()); 2681 EXPECT_FALSE(delegate->scroll_begin());
2620 EXPECT_FALSE(delegate->scroll_update()); 2682 EXPECT_FALSE(delegate->scroll_update());
2621 EXPECT_FALSE(delegate->scroll_end()); 2683 EXPECT_FALSE(delegate->scroll_end());
2622 EXPECT_TRUE(delegate->fling()); 2684 EXPECT_TRUE(delegate->fling());
2623 EXPECT_FALSE(delegate->two_finger_tap()); 2685 EXPECT_FALSE(delegate->two_finger_tap());
2624 } 2686 }
2625 2687
2626 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) { 2688 TEST_P(GestureRecognizerTest, TwoFingerTapExpired) {
2627 scoped_ptr<GestureEventConsumeDelegate> delegate( 2689 scoped_ptr<GestureEventConsumeDelegate> delegate(
2628 new GestureEventConsumeDelegate()); 2690 new GestureEventConsumeDelegate());
2629 const int kWindowWidth = 123; 2691 const int kWindowWidth = 123;
2630 const int kWindowHeight = 45; 2692 const int kWindowHeight = 45;
2631 const int kTouchId1 = 2; 2693 const int kTouchId1 = 2;
2632 const int kTouchId2 = 3; 2694 const int kTouchId2 = 3;
2633 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2695 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2634 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2696 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2635 delegate.get(), -1234, bounds, root_window())); 2697 delegate.get(), -1234, bounds, root_window()));
2636 TimedEvents tes; 2698 TimedEvents tes;
(...skipping 20 matching lines...) Expand all
2657 // Make sure there is enough delay before the touch is released so that it is 2719 // Make sure there is enough delay before the touch is released so that it is
2658 // recognized as a tap. 2720 // recognized as a tap.
2659 delegate->Reset(); 2721 delegate->Reset();
2660 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2722 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
2661 kTouchId2, tes.LeapForward(50)); 2723 kTouchId2, tes.LeapForward(50));
2662 2724
2663 DispatchEventUsingWindowDispatcher(&release2); 2725 DispatchEventUsingWindowDispatcher(&release2);
2664 EXPECT_FALSE(delegate->two_finger_tap()); 2726 EXPECT_FALSE(delegate->two_finger_tap());
2665 } 2727 }
2666 2728
2667 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) { 2729 TEST_P(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
2730 // TODO(tdresser): enable this test with unified GR once two finger tap is
2731 // supported. See crbug.com/354396.
2732 if (UsingUnifiedGR())
2733 return;
2734
2668 scoped_ptr<GestureEventConsumeDelegate> delegate( 2735 scoped_ptr<GestureEventConsumeDelegate> delegate(
2669 new GestureEventConsumeDelegate()); 2736 new GestureEventConsumeDelegate());
2670 const int kWindowWidth = 123; 2737 const int kWindowWidth = 123;
2671 const int kWindowHeight = 45; 2738 const int kWindowHeight = 45;
2672 const int kTouchId1 = 2; 2739 const int kTouchId1 = 2;
2673 const int kTouchId2 = 3; 2740 const int kTouchId2 = 3;
2674 TimedEvents tes; 2741 TimedEvents tes;
2675 2742
2676 // Test moving first finger 2743 // Test moving first finger
2677 { 2744 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 delegate->Reset(); 2796 delegate->Reset();
2730 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2797 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2731 kTouchId1, tes.LeapForward(50)); 2798 kTouchId1, tes.LeapForward(50));
2732 2799
2733 DispatchEventUsingWindowDispatcher(&release); 2800 DispatchEventUsingWindowDispatcher(&release);
2734 EXPECT_FALSE(delegate->two_finger_tap()); 2801 EXPECT_FALSE(delegate->two_finger_tap());
2735 EXPECT_TRUE(delegate->pinch_end()); 2802 EXPECT_TRUE(delegate->pinch_end());
2736 } 2803 }
2737 } 2804 }
2738 2805
2739 TEST_F(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) { 2806 TEST_P(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) {
2807 // Disabled for unified GR due to differences in when pinch begin is sent. The
2808 // Aura GR sends it earlier than is necessary.
2809 if (UsingUnifiedGR())
2810 return;
2811
2740 scoped_ptr<GestureEventConsumeDelegate> delegate( 2812 scoped_ptr<GestureEventConsumeDelegate> delegate(
2741 new GestureEventConsumeDelegate()); 2813 new GestureEventConsumeDelegate());
2742 const int kWindowWidth = 123; 2814 const int kWindowWidth = 123;
2743 const int kWindowHeight = 45; 2815 const int kWindowHeight = 45;
2744 const int kTouchId1 = 2; 2816 const int kTouchId1 = 2;
2745 const int kTouchId2 = 3; 2817 const int kTouchId2 = 3;
2746 TimedEvents tes; 2818 TimedEvents tes;
2747 2819
2748 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2820 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2749 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2821 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 16 matching lines...) Expand all
2766 // is recognized as a tap. 2838 // is recognized as a tap.
2767 delegate->Reset(); 2839 delegate->Reset();
2768 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2840 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2769 kTouchId2, tes.LeapForward(50)); 2841 kTouchId2, tes.LeapForward(50));
2770 2842
2771 DispatchEventUsingWindowDispatcher(&release); 2843 DispatchEventUsingWindowDispatcher(&release);
2772 EXPECT_FALSE(delegate->two_finger_tap()); 2844 EXPECT_FALSE(delegate->two_finger_tap());
2773 EXPECT_TRUE(delegate->pinch_end()); 2845 EXPECT_TRUE(delegate->pinch_end());
2774 } 2846 }
2775 2847
2776 TEST_F(GestureRecognizerTest, MultiFingerSwipe) { 2848 TEST_P(GestureRecognizerTest, MultiFingerSwipe) {
2777 scoped_ptr<GestureEventConsumeDelegate> delegate( 2849 scoped_ptr<GestureEventConsumeDelegate> delegate(
2778 new GestureEventConsumeDelegate()); 2850 new GestureEventConsumeDelegate());
2779 const int kWindowWidth = 123; 2851 const int kWindowWidth = 123;
2780 const int kWindowHeight = 45; 2852 const int kWindowHeight = 45;
2781 2853
2782 gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight); 2854 gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight);
2783 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2855 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2784 delegate.get(), -1234, bounds, root_window())); 2856 delegate.get(), -1234, bounds, root_window()));
2785 2857
2786 const int kSteps = 15; 2858 const int kSteps = 15;
2787 const int kTouchPoints = 4; 2859 const int kTouchPoints = 4;
2788 gfx::Point points[kTouchPoints] = { 2860 gfx::Point points[kTouchPoints] = {
2789 gfx::Point(10, 30), 2861 gfx::Point(10, 30),
2790 gfx::Point(30, 20), 2862 gfx::Point(30, 20),
2791 gfx::Point(50, 30), 2863 gfx::Point(50, 30),
2792 gfx::Point(80, 50) 2864 gfx::Point(80, 50)
2793 }; 2865 };
2794 2866
2795 aura::test::EventGenerator generator(root_window(), window.get()); 2867 aura::test::EventGenerator generator(root_window(), window.get());
2796 2868
2869 // The unified gesture recognizer assumes a finger has stopped if it hasn't
2870 // moved for too long. See ui/events/gesture_detection/velocity_tracker.cc's
2871 // kAssumePointerStoppedTimeMs.
2797 for (int count = 2; count <= kTouchPoints; ++count) { 2872 for (int count = 2; count <= kTouchPoints; ++count) {
2798 generator.GestureMultiFingerScroll( 2873 generator.GestureMultiFingerScroll(
2799 count, points, 1000, kSteps, 0, -11 * kSteps); 2874 count, points, 10, kSteps, 0, -11 * kSteps);
2800 EXPECT_TRUE(delegate->swipe_up()); 2875 EXPECT_TRUE(delegate->swipe_up());
2801 delegate->Reset(); 2876 delegate->Reset();
2802 2877
2803 generator.GestureMultiFingerScroll( 2878 generator.GestureMultiFingerScroll(
2804 count, points, 1000, kSteps, 0, 11 * kSteps); 2879 count, points, 10, kSteps, 0, 11 * kSteps);
2805 EXPECT_TRUE(delegate->swipe_down()); 2880 EXPECT_TRUE(delegate->swipe_down());
2806 delegate->Reset(); 2881 delegate->Reset();
2807 2882
2808 generator.GestureMultiFingerScroll( 2883 generator.GestureMultiFingerScroll(
2809 count, points, 1000, kSteps, -11 * kSteps, 0); 2884 count, points, 10, kSteps, -11 * kSteps, 0);
2810 EXPECT_TRUE(delegate->swipe_left()); 2885 EXPECT_TRUE(delegate->swipe_left());
2811 delegate->Reset(); 2886 delegate->Reset();
2812 2887
2813 generator.GestureMultiFingerScroll( 2888 generator.GestureMultiFingerScroll(
2814 count, points, 1000, kSteps, 11 * kSteps, 0); 2889 count, points, 10, kSteps, 11 * kSteps, 0);
2815 EXPECT_TRUE(delegate->swipe_right()); 2890 EXPECT_TRUE(delegate->swipe_right());
2816 delegate->Reset(); 2891 delegate->Reset();
2817 } 2892 }
2818 } 2893 }
2819 2894
2820 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) { 2895 TEST_P(GestureRecognizerTest, TwoFingerTapCancelled) {
2821 scoped_ptr<GestureEventConsumeDelegate> delegate( 2896 scoped_ptr<GestureEventConsumeDelegate> delegate(
2822 new GestureEventConsumeDelegate()); 2897 new GestureEventConsumeDelegate());
2823 const int kWindowWidth = 123; 2898 const int kWindowWidth = 123;
2824 const int kWindowHeight = 45; 2899 const int kWindowHeight = 45;
2825 const int kTouchId1 = 2; 2900 const int kTouchId1 = 2;
2826 const int kTouchId2 = 3; 2901 const int kTouchId2 = 3;
2827 TimedEvents tes; 2902 TimedEvents tes;
2828 2903
2829 // Test canceling first finger. 2904 // Test canceling first finger.
2830 { 2905 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 // is recognized as a tap. 2959 // is recognized as a tap.
2885 delegate->Reset(); 2960 delegate->Reset();
2886 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2961 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2887 kTouchId1, tes.LeapForward(50)); 2962 kTouchId1, tes.LeapForward(50));
2888 2963
2889 DispatchEventUsingWindowDispatcher(&release); 2964 DispatchEventUsingWindowDispatcher(&release);
2890 EXPECT_FALSE(delegate->two_finger_tap()); 2965 EXPECT_FALSE(delegate->two_finger_tap());
2891 } 2966 }
2892 } 2967 }
2893 2968
2894 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { 2969 TEST_P(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
2970 // Disabled for unified GR due to differences in when scroll update is
2971 // sent. The Aura GR will never send a ScrollUpdate with a ScrollBegin, but
2972 // the unified GR will.
2973 if (UsingUnifiedGR())
2974 return;
2975
2895 scoped_ptr<GestureEventConsumeDelegate> delegate( 2976 scoped_ptr<GestureEventConsumeDelegate> delegate(
2896 new GestureEventConsumeDelegate()); 2977 new GestureEventConsumeDelegate());
2897 const int kWindowWidth = 523; 2978 const int kWindowWidth = 523;
2898 const int kWindowHeight = 45; 2979 const int kWindowHeight = 45;
2899 const int kTouchId1 = 2; 2980 const int kTouchId1 = 2;
2900 const int kTouchId2 = 3; 2981 const int kTouchId2 = 3;
2901 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2982 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2902 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2983 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2903 delegate.get(), -1234, bounds, root_window())); 2984 delegate.get(), -1234, bounds, root_window()));
2904 TimedEvents tes; 2985 TimedEvents tes;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 EXPECT_TRUE(delegate->scroll_begin()); 3022 EXPECT_TRUE(delegate->scroll_begin());
2942 EXPECT_FALSE(delegate->scroll_update()); 3023 EXPECT_FALSE(delegate->scroll_update());
2943 EXPECT_FALSE(delegate->scroll_end()); 3024 EXPECT_FALSE(delegate->scroll_end());
2944 EXPECT_FALSE(delegate->long_press()); 3025 EXPECT_FALSE(delegate->long_press());
2945 EXPECT_FALSE(delegate->two_finger_tap()); 3026 EXPECT_FALSE(delegate->two_finger_tap());
2946 EXPECT_TRUE(delegate->pinch_begin()); 3027 EXPECT_TRUE(delegate->pinch_begin());
2947 } 3028 }
2948 3029
2949 // Verifies if a window is the target of multiple touch-ids and we hide the 3030 // Verifies if a window is the target of multiple touch-ids and we hide the
2950 // window everything is cleaned up correctly. 3031 // window everything is cleaned up correctly.
2951 TEST_F(GestureRecognizerTest, FlushAllOnHide) { 3032 TEST_P(GestureRecognizerTest, FlushAllOnHide) {
2952 scoped_ptr<GestureEventConsumeDelegate> delegate( 3033 scoped_ptr<GestureEventConsumeDelegate> delegate(
2953 new GestureEventConsumeDelegate()); 3034 new GestureEventConsumeDelegate());
2954 gfx::Rect bounds(0, 0, 200, 200); 3035 gfx::Rect bounds(0, 0, 200, 200);
2955 scoped_ptr<aura::Window> window( 3036 scoped_ptr<aura::Window> window(
2956 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); 3037 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
2957 const int kTouchId1 = 8; 3038 const int kTouchId1 = 8;
2958 const int kTouchId2 = 2; 3039 const int kTouchId2 = 2;
2959 TimedEvents tes; 3040 TimedEvents tes;
2960 3041
2961 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 3042 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
2962 kTouchId1, tes.Now()); 3043 kTouchId1, tes.Now());
2963 DispatchEventUsingWindowDispatcher(&press1); 3044 DispatchEventUsingWindowDispatcher(&press1);
2964 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 3045 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2965 kTouchId2, tes.Now()); 3046 kTouchId2, tes.Now());
2966 DispatchEventUsingWindowDispatcher(&press2); 3047 DispatchEventUsingWindowDispatcher(&press2);
2967 window->Hide(); 3048 window->Hide();
2968 EXPECT_EQ(NULL, 3049 EXPECT_EQ(NULL,
2969 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1)); 3050 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1));
2970 EXPECT_EQ(NULL, 3051 EXPECT_EQ(NULL,
2971 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)); 3052 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
2972 } 3053 }
2973 3054
2974 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { 3055 TEST_P(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
3056 // TODO(tdresser): write a version of this test for the unified GR.
3057 if (UsingUnifiedGR())
3058 return;
3059
2975 scoped_ptr<QueueTouchEventDelegate> delegate( 3060 scoped_ptr<QueueTouchEventDelegate> delegate(
2976 new QueueTouchEventDelegate(host()->dispatcher())); 3061 new QueueTouchEventDelegate(host()->dispatcher()));
2977 const int kTouchId = 2; 3062 const int kTouchId = 2;
2978 gfx::Rect bounds(100, 200, 100, 100); 3063 gfx::Rect bounds(100, 200, 100, 100);
2979 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3064 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2980 delegate.get(), -1234, bounds, root_window())); 3065 delegate.get(), -1234, bounds, root_window()));
2981 delegate->set_window(window.get()); 3066 delegate->set_window(window.get());
2982 TimedEvents tes; 3067 TimedEvents tes;
2983 3068
2984 TimerTestGestureRecognizer* gesture_recognizer = 3069 TimerTestGestureRecognizer* gesture_recognizer =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 GestureEventConsumeDelegate::OnTouchEvent(touch); 3109 GestureEventConsumeDelegate::OnTouchEvent(touch);
3025 } 3110 }
3026 3111
3027 bool consume_touch_move_; 3112 bool consume_touch_move_;
3028 3113
3029 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); 3114 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate);
3030 }; 3115 };
3031 3116
3032 // Same as GestureEventScroll, but tests that the behavior is the same 3117 // Same as GestureEventScroll, but tests that the behavior is the same
3033 // even if all the touch-move events are consumed. 3118 // even if all the touch-move events are consumed.
3034 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) { 3119 TEST_P(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
3035 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3120 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3036 new ConsumesTouchMovesDelegate()); 3121 new ConsumesTouchMovesDelegate());
3037 const int kWindowWidth = 123; 3122 const int kWindowWidth = 123;
3038 const int kWindowHeight = 45; 3123 const int kWindowHeight = 45;
3039 const int kTouchId = 5; 3124 const int kTouchId = 5;
3040 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3125 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3041 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3126 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3042 delegate.get(), -1234, bounds, root_window())); 3127 delegate.get(), -1234, bounds, root_window()));
3043 TimedEvents tes; 3128 TimedEvents tes;
3044 3129
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 EXPECT_FALSE(delegate->tap_down()); 3161 EXPECT_FALSE(delegate->tap_down());
3077 EXPECT_FALSE(delegate->tap_cancel()); 3162 EXPECT_FALSE(delegate->tap_cancel());
3078 EXPECT_FALSE(delegate->begin()); 3163 EXPECT_FALSE(delegate->begin());
3079 EXPECT_TRUE(delegate->end()); 3164 EXPECT_TRUE(delegate->end());
3080 EXPECT_FALSE(delegate->scroll_begin()); 3165 EXPECT_FALSE(delegate->scroll_begin());
3081 EXPECT_FALSE(delegate->scroll_update()); 3166 EXPECT_FALSE(delegate->scroll_update());
3082 EXPECT_FALSE(delegate->scroll_end()); 3167 EXPECT_FALSE(delegate->scroll_end());
3083 } 3168 }
3084 3169
3085 // Tests the behavior of 2F scroll when all the touch-move events are consumed. 3170 // Tests the behavior of 2F scroll when all the touch-move events are consumed.
3086 TEST_F(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) { 3171 TEST_P(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) {
3172 // TODO(tdresser): enable this test with unified GR once two finger tap is
3173 // supported. See crbug.com/354396.
3174 if (UsingUnifiedGR())
3175 return;
3176
3087 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3177 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3088 new ConsumesTouchMovesDelegate()); 3178 new ConsumesTouchMovesDelegate());
3089 const int kWindowWidth = 123; 3179 const int kWindowWidth = 123;
3090 const int kWindowHeight = 100; 3180 const int kWindowHeight = 100;
3091 const int kTouchId1 = 2; 3181 const int kTouchId1 = 2;
3092 const int kTouchId2 = 3; 3182 const int kTouchId2 = 3;
3093 TimedEvents tes; 3183 TimedEvents tes;
3094 3184
3095 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3185 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3096 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3186 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3183 EXPECT_TRUE(delegate->fling()); 3273 EXPECT_TRUE(delegate->fling());
3184 3274
3185 EXPECT_FALSE(delegate->pinch_begin()); 3275 EXPECT_FALSE(delegate->pinch_begin());
3186 EXPECT_FALSE(delegate->pinch_update()); 3276 EXPECT_FALSE(delegate->pinch_update());
3187 EXPECT_FALSE(delegate->pinch_end()); 3277 EXPECT_FALSE(delegate->pinch_end());
3188 } 3278 }
3189 3279
3190 // Like as GestureEventTouchMoveConsumed but tests the different behavior 3280 // Like as GestureEventTouchMoveConsumed but tests the different behavior
3191 // depending on whether the events were consumed before or after the scroll 3281 // depending on whether the events were consumed before or after the scroll
3192 // started. 3282 // started.
3193 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) { 3283 TEST_P(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) {
3194 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3284 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3195 new ConsumesTouchMovesDelegate()); 3285 new ConsumesTouchMovesDelegate());
3196 const int kWindowWidth = 123; 3286 const int kWindowWidth = 123;
3197 const int kWindowHeight = 45; 3287 const int kWindowHeight = 45;
3198 const int kTouchId = 5; 3288 const int kTouchId = 5;
3199 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3289 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3200 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3290 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3201 delegate.get(), -1234, bounds, root_window())); 3291 delegate.get(), -1234, bounds, root_window()));
3202 TimedEvents tes; 3292 TimedEvents tes;
3203 3293
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3277 EXPECT_FALSE(delegate->tap_cancel()); 3367 EXPECT_FALSE(delegate->tap_cancel());
3278 EXPECT_FALSE(delegate->begin()); 3368 EXPECT_FALSE(delegate->begin());
3279 EXPECT_TRUE(delegate->end()); 3369 EXPECT_TRUE(delegate->end());
3280 EXPECT_FALSE(delegate->scroll_begin()); 3370 EXPECT_FALSE(delegate->scroll_begin());
3281 EXPECT_FALSE(delegate->scroll_update()); 3371 EXPECT_FALSE(delegate->scroll_update());
3282 EXPECT_FALSE(delegate->scroll_end()); 3372 EXPECT_FALSE(delegate->scroll_end());
3283 EXPECT_FALSE(delegate->fling()); 3373 EXPECT_FALSE(delegate->fling());
3284 } 3374 }
3285 3375
3286 // Check that appropriate touch events generate double tap gesture events. 3376 // Check that appropriate touch events generate double tap gesture events.
3287 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) { 3377 TEST_P(GestureRecognizerTest, GestureEventDoubleTap) {
3378 // TODO(tdresser): enable this test with unified GR once double / triple tap
3379 // gestures work. See crbug.com/357270.
3380 if (UsingUnifiedGR())
3381 return;
3382
3288 scoped_ptr<GestureEventConsumeDelegate> delegate( 3383 scoped_ptr<GestureEventConsumeDelegate> delegate(
3289 new GestureEventConsumeDelegate()); 3384 new GestureEventConsumeDelegate());
3290 const int kWindowWidth = 123; 3385 const int kWindowWidth = 123;
3291 const int kWindowHeight = 45; 3386 const int kWindowHeight = 45;
3292 const int kTouchId = 2; 3387 const int kTouchId = 2;
3293 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3388 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3294 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3389 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3295 delegate.get(), -1234, bounds, root_window())); 3390 delegate.get(), -1234, bounds, root_window()));
3296 TimedEvents tes; 3391 TimedEvents tes;
3297 3392
(...skipping 20 matching lines...) Expand all
3318 EXPECT_TRUE(delegate->begin()); 3413 EXPECT_TRUE(delegate->begin());
3319 EXPECT_TRUE(delegate->end()); 3414 EXPECT_TRUE(delegate->end());
3320 EXPECT_FALSE(delegate->scroll_begin()); 3415 EXPECT_FALSE(delegate->scroll_begin());
3321 EXPECT_FALSE(delegate->scroll_update()); 3416 EXPECT_FALSE(delegate->scroll_update());
3322 EXPECT_FALSE(delegate->scroll_end()); 3417 EXPECT_FALSE(delegate->scroll_end());
3323 3418
3324 EXPECT_EQ(2, delegate->tap_count()); 3419 EXPECT_EQ(2, delegate->tap_count());
3325 } 3420 }
3326 3421
3327 // Check that appropriate touch events generate triple tap gesture events. 3422 // Check that appropriate touch events generate triple tap gesture events.
3328 TEST_F(GestureRecognizerTest, GestureEventTripleTap) { 3423 TEST_P(GestureRecognizerTest, GestureEventTripleTap) {
3424 // TODO(tdresser): enable this test with unified GR once double / triple tap
3425 // gestures work. See crbug.com/357270.
3426 if (UsingUnifiedGR())
3427 return;
3428
3329 scoped_ptr<GestureEventConsumeDelegate> delegate( 3429 scoped_ptr<GestureEventConsumeDelegate> delegate(
3330 new GestureEventConsumeDelegate()); 3430 new GestureEventConsumeDelegate());
3331 const int kWindowWidth = 123; 3431 const int kWindowWidth = 123;
3332 const int kWindowHeight = 45; 3432 const int kWindowHeight = 45;
3333 const int kTouchId = 2; 3433 const int kTouchId = 2;
3334 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3434 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3335 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3435 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3336 delegate.get(), -1234, bounds, root_window())); 3436 delegate.get(), -1234, bounds, root_window()));
3337 TimedEvents tes; 3437 TimedEvents tes;
3338 3438
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3373 EXPECT_TRUE(delegate->begin()); 3473 EXPECT_TRUE(delegate->begin());
3374 EXPECT_TRUE(delegate->end()); 3474 EXPECT_TRUE(delegate->end());
3375 EXPECT_FALSE(delegate->scroll_begin()); 3475 EXPECT_FALSE(delegate->scroll_begin());
3376 EXPECT_FALSE(delegate->scroll_update()); 3476 EXPECT_FALSE(delegate->scroll_update());
3377 EXPECT_FALSE(delegate->scroll_end()); 3477 EXPECT_FALSE(delegate->scroll_end());
3378 3478
3379 EXPECT_EQ(3, delegate->tap_count()); 3479 EXPECT_EQ(3, delegate->tap_count());
3380 } 3480 }
3381 3481
3382 // Check that we don't get a double tap when the two taps are far apart. 3482 // Check that we don't get a double tap when the two taps are far apart.
3383 TEST_F(GestureRecognizerTest, TwoTapsFarApart) { 3483 TEST_P(GestureRecognizerTest, TwoTapsFarApart) {
3384 scoped_ptr<GestureEventConsumeDelegate> delegate( 3484 scoped_ptr<GestureEventConsumeDelegate> delegate(
3385 new GestureEventConsumeDelegate()); 3485 new GestureEventConsumeDelegate());
3386 const int kWindowWidth = 123; 3486 const int kWindowWidth = 123;
3387 const int kWindowHeight = 45; 3487 const int kWindowHeight = 45;
3388 const int kTouchId = 2; 3488 const int kTouchId = 2;
3389 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3489 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3390 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3490 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3391 delegate.get(), -1234, bounds, root_window())); 3491 delegate.get(), -1234, bounds, root_window()));
3392 TimedEvents tes; 3492 TimedEvents tes;
3393 3493
(...skipping 21 matching lines...) Expand all
3415 EXPECT_TRUE(delegate->end()); 3515 EXPECT_TRUE(delegate->end());
3416 EXPECT_FALSE(delegate->scroll_begin()); 3516 EXPECT_FALSE(delegate->scroll_begin());
3417 EXPECT_FALSE(delegate->scroll_update()); 3517 EXPECT_FALSE(delegate->scroll_update());
3418 EXPECT_FALSE(delegate->scroll_end()); 3518 EXPECT_FALSE(delegate->scroll_end());
3419 3519
3420 EXPECT_EQ(1, delegate->tap_count()); 3520 EXPECT_EQ(1, delegate->tap_count());
3421 } 3521 }
3422 3522
3423 // Check that we don't get a double tap when the two taps have a long enough 3523 // Check that we don't get a double tap when the two taps have a long enough
3424 // delay in between. 3524 // delay in between.
3425 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) { 3525 TEST_P(GestureRecognizerTest, TwoTapsWithDelayBetween) {
3426 scoped_ptr<GestureEventConsumeDelegate> delegate( 3526 scoped_ptr<GestureEventConsumeDelegate> delegate(
3427 new GestureEventConsumeDelegate()); 3527 new GestureEventConsumeDelegate());
3428 const int kWindowWidth = 123; 3528 const int kWindowWidth = 123;
3429 const int kWindowHeight = 45; 3529 const int kWindowHeight = 45;
3430 const int kTouchId = 2; 3530 const int kTouchId = 2;
3431 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3531 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3432 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3532 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3433 delegate.get(), -1234, bounds, root_window())); 3533 delegate.get(), -1234, bounds, root_window()));
3434 TimedEvents tes; 3534 TimedEvents tes;
3435 3535
(...skipping 22 matching lines...) Expand all
3458 EXPECT_FALSE(delegate->scroll_begin()); 3558 EXPECT_FALSE(delegate->scroll_begin());
3459 EXPECT_FALSE(delegate->scroll_update()); 3559 EXPECT_FALSE(delegate->scroll_update());
3460 EXPECT_FALSE(delegate->scroll_end()); 3560 EXPECT_FALSE(delegate->scroll_end());
3461 3561
3462 EXPECT_EQ(1, delegate->tap_count()); 3562 EXPECT_EQ(1, delegate->tap_count());
3463 } 3563 }
3464 3564
3465 // Checks that if the bounding-box of a gesture changes because of change in 3565 // Checks that if the bounding-box of a gesture changes because of change in
3466 // radius of a touch-point, and not because of change in position, then there 3566 // radius of a touch-point, and not because of change in position, then there
3467 // are not gesture events from that. 3567 // are not gesture events from that.
3468 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) { 3568 TEST_P(GestureRecognizerTest, BoundingBoxRadiusChange) {
3569 // TODO(tdresser): enable this test with unified GR when (if?) bounding box
3570 // behavior is unified.
3571 if (UsingUnifiedGR())
3572 return;
3573
3469 scoped_ptr<GestureEventConsumeDelegate> delegate( 3574 scoped_ptr<GestureEventConsumeDelegate> delegate(
3470 new GestureEventConsumeDelegate()); 3575 new GestureEventConsumeDelegate());
3471 const int kWindowWidth = 234; 3576 const int kWindowWidth = 234;
3472 const int kWindowHeight = 345; 3577 const int kWindowHeight = 345;
3473 const int kTouchId = 5, kTouchId2 = 7; 3578 const int kTouchId = 5, kTouchId2 = 7;
3474 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3579 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3475 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3580 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3476 delegate.get(), -1234, bounds, root_window())); 3581 delegate.get(), -1234, bounds, root_window()));
3477 TimedEvents tes; 3582 TimedEvents tes;
3478 3583
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3512 EXPECT_FALSE(delegate->tap()); 3617 EXPECT_FALSE(delegate->tap());
3513 EXPECT_FALSE(delegate->tap_cancel()); 3618 EXPECT_FALSE(delegate->tap_cancel());
3514 EXPECT_FALSE(delegate->scroll_update()); 3619 EXPECT_FALSE(delegate->scroll_update());
3515 EXPECT_FALSE(delegate->pinch_update()); 3620 EXPECT_FALSE(delegate->pinch_update());
3516 3621
3517 delegate->Reset(); 3622 delegate->Reset();
3518 } 3623 }
3519 3624
3520 // Checks that slow scrolls deliver the correct deltas. 3625 // Checks that slow scrolls deliver the correct deltas.
3521 // In particular, fix for http;//crbug.com/150573. 3626 // In particular, fix for http;//crbug.com/150573.
3522 TEST_F(GestureRecognizerTest, NoDriftInScroll) { 3627 TEST_P(GestureRecognizerTest, NoDriftInScroll) {
3523 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); 3628 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
3524 ui::GestureConfiguration::set_min_scroll_delta_squared(9); 3629 ui::GestureConfiguration::set_min_scroll_delta_squared(9);
3525 scoped_ptr<GestureEventConsumeDelegate> delegate( 3630 scoped_ptr<GestureEventConsumeDelegate> delegate(
3526 new GestureEventConsumeDelegate()); 3631 new GestureEventConsumeDelegate());
3527 const int kWindowWidth = 234; 3632 const int kWindowWidth = 234;
3528 const int kWindowHeight = 345; 3633 const int kWindowHeight = 345;
3529 const int kTouchId = 5; 3634 const int kTouchId = 5;
3530 TimedEvents tes; 3635 TimedEvents tes;
3531 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3636 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3532 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3637 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3570 DispatchEventUsingWindowDispatcher(&move4); 3675 DispatchEventUsingWindowDispatcher(&move4);
3571 EXPECT_TRUE(delegate->scroll_update()); 3676 EXPECT_TRUE(delegate->scroll_update());
3572 EXPECT_EQ(-1, delegate->scroll_y()); 3677 EXPECT_EQ(-1, delegate->scroll_y());
3573 3678
3574 delegate->Reset(); 3679 delegate->Reset();
3575 } 3680 }
3576 3681
3577 // Ensure that move events which are preventDefaulted will cause a tap 3682 // Ensure that move events which are preventDefaulted will cause a tap
3578 // cancel gesture event to be fired if the move would normally cause a 3683 // cancel gesture event to be fired if the move would normally cause a
3579 // scroll. See bug http://crbug.com/146397. 3684 // scroll. See bug http://crbug.com/146397.
3580 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) { 3685 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) {
3581 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3686 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3582 new ConsumesTouchMovesDelegate()); 3687 new ConsumesTouchMovesDelegate());
3583 const int kTouchId = 5; 3688 const int kTouchId = 5;
3584 gfx::Rect bounds(100, 200, 123, 45); 3689 gfx::Rect bounds(100, 200, 123, 45);
3585 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3690 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3586 delegate.get(), -1234, bounds, root_window())); 3691 delegate.get(), -1234, bounds, root_window()));
3587 TimedEvents tes; 3692 TimedEvents tes;
3588 3693
3589 delegate->Reset(); 3694 delegate->Reset();
3590 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3695 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3591 kTouchId, tes.Now()); 3696 kTouchId, tes.Now());
3592 3697
3593 delegate->set_consume_touch_move(false); 3698 delegate->set_consume_touch_move(false);
3594 DispatchEventUsingWindowDispatcher(&press); 3699 DispatchEventUsingWindowDispatcher(&press);
3595 delegate->set_consume_touch_move(true); 3700 delegate->set_consume_touch_move(true);
3596 delegate->Reset(); 3701 delegate->Reset();
3597 // Move the touch-point enough so that it would normally be considered a 3702 // Move the touch-point enough so that it would normally be considered a
3598 // scroll. But since the touch-moves will be consumed, the scroll should not 3703 // scroll. But since the touch-moves will be consumed, the scroll should not
3599 // start. 3704 // start.
3600 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); 3705 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
3601 EXPECT_FALSE(delegate->tap()); 3706 EXPECT_FALSE(delegate->tap());
3602 EXPECT_FALSE(delegate->tap_down()); 3707 EXPECT_FALSE(delegate->tap_down());
3603 EXPECT_TRUE(delegate->tap_cancel()); 3708 EXPECT_TRUE(delegate->tap_cancel());
3604 EXPECT_FALSE(delegate->begin()); 3709 EXPECT_FALSE(delegate->begin());
3605 EXPECT_FALSE(delegate->scroll_begin()); 3710 EXPECT_FALSE(delegate->scroll_begin());
3606 EXPECT_FALSE(delegate->scroll_update()); 3711 EXPECT_FALSE(delegate->scroll_update());
3607 EXPECT_FALSE(delegate->scroll_end()); 3712 EXPECT_FALSE(delegate->scroll_end());
3608 } 3713 }
3609 3714
3610 TEST_F(GestureRecognizerTest, 3715 TEST_P(GestureRecognizerTest,
3611 TransferEventDispatchesTouchCancel) { 3716 TransferEventDispatchesTouchCancel) {
3612 scoped_ptr<GestureEventConsumeDelegate> delegate( 3717 scoped_ptr<GestureEventConsumeDelegate> delegate(
3613 new GestureEventConsumeDelegate()); 3718 new GestureEventConsumeDelegate());
3614 TimedEvents tes; 3719 TimedEvents tes;
3615 const int kWindowWidth = 800; 3720 const int kWindowWidth = 800;
3616 const int kWindowHeight = 600; 3721 const int kWindowHeight = 600;
3617 const int kTouchId = 2; 3722 const int kTouchId = 2;
3618 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3723 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3619 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3724 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3620 delegate.get(), -1234, bounds, root_window())); 3725 delegate.get(), -1234, bounds, root_window()));
(...skipping 22 matching lines...) Expand all
3643 gesture_recognizer->GetTouchLockedTarget(press)); 3748 gesture_recognizer->GetTouchLockedTarget(press));
3644 gesture_recognizer->TransferEventsTo(window.get(), NULL); 3749 gesture_recognizer->TransferEventsTo(window.get(), NULL);
3645 EXPECT_EQ(NULL, 3750 EXPECT_EQ(NULL,
3646 gesture_recognizer->GetTouchLockedTarget(press)); 3751 gesture_recognizer->GetTouchLockedTarget(press));
3647 // The event-handler removes |window| from its parent on the first 3752 // The event-handler removes |window| from its parent on the first
3648 // touch-cancel event, so it won't receive the second touch-cancel event. 3753 // touch-cancel event, so it won't receive the second touch-cancel event.
3649 EXPECT_EQ(1, handler->touch_cancelled_count()); 3754 EXPECT_EQ(1, handler->touch_cancelled_count());
3650 } 3755 }
3651 3756
3652 // Check that appropriate touch events generate show press events 3757 // Check that appropriate touch events generate show press events
3653 TEST_F(GestureRecognizerTest, GestureEventShowPress) { 3758 TEST_P(GestureRecognizerTest, GestureEventShowPress) {
3654 scoped_ptr<GestureEventConsumeDelegate> delegate( 3759 scoped_ptr<GestureEventConsumeDelegate> delegate(
3655 new GestureEventConsumeDelegate()); 3760 new GestureEventConsumeDelegate());
3656 TimedEvents tes; 3761 TimedEvents tes;
3657 const int kWindowWidth = 123; 3762 const int kWindowWidth = 123;
3658 const int kWindowHeight = 45; 3763 const int kWindowHeight = 45;
3659 const int kTouchId = 2; 3764 const int kTouchId = 2;
3660 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3765 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3661 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3766 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3662 delegate.get(), -1234, bounds, root_window())); 3767 delegate.get(), -1234, bounds, root_window()));
3663 3768
(...skipping 18 matching lines...) Expand all
3682 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS); 3787 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS);
3683 EXPECT_TRUE(delegate->show_press()); 3788 EXPECT_TRUE(delegate->show_press());
3684 EXPECT_FALSE(delegate->tap_cancel()); 3789 EXPECT_FALSE(delegate->tap_cancel());
3685 3790
3686 delegate->Reset(); 3791 delegate->Reset();
3687 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3792 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3688 kTouchId, tes.Now()); 3793 kTouchId, tes.Now());
3689 DispatchEventUsingWindowDispatcher(&release1); 3794 DispatchEventUsingWindowDispatcher(&release1);
3690 EXPECT_FALSE(delegate->long_press()); 3795 EXPECT_FALSE(delegate->long_press());
3691 3796
3692 // Note the tap down isn't cancelled until the release 3797 // Note the tap isn't dispatched until the release
3693 EXPECT_TRUE(delegate->tap_cancel()); 3798 EXPECT_FALSE(delegate->tap_cancel());
3799 EXPECT_TRUE(delegate->tap());
3694 } 3800 }
3695 3801
3696 // Check that scrolling cancels a show press 3802 // Check that scrolling cancels a show press
3697 TEST_F(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) { 3803 TEST_P(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) {
3698 scoped_ptr<GestureEventConsumeDelegate> delegate( 3804 scoped_ptr<GestureEventConsumeDelegate> delegate(
3699 new GestureEventConsumeDelegate()); 3805 new GestureEventConsumeDelegate());
3700 TimedEvents tes; 3806 TimedEvents tes;
3701 const int kWindowWidth = 123; 3807 const int kWindowWidth = 123;
3702 const int kWindowHeight = 45; 3808 const int kWindowHeight = 45;
3703 const int kTouchId = 6; 3809 const int kTouchId = 6;
3704 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3810 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3705 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3811 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3706 delegate.get(), -1234, bounds, root_window())); 3812 delegate.get(), -1234, bounds, root_window()));
3707 3813
(...skipping 26 matching lines...) Expand all
3734 3840
3735 delegate->Reset(); 3841 delegate->Reset();
3736 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3842 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3737 kTouchId, tes.LeapForward(10)); 3843 kTouchId, tes.LeapForward(10));
3738 DispatchEventUsingWindowDispatcher(&release1); 3844 DispatchEventUsingWindowDispatcher(&release1);
3739 EXPECT_FALSE(delegate->show_press()); 3845 EXPECT_FALSE(delegate->show_press());
3740 EXPECT_FALSE(delegate->tap_cancel()); 3846 EXPECT_FALSE(delegate->tap_cancel());
3741 } 3847 }
3742 3848
3743 // Test that show press events are sent immediately on tap 3849 // Test that show press events are sent immediately on tap
3744 TEST_F(GestureRecognizerTest, GestureEventShowPressSentOnTap) { 3850 TEST_P(GestureRecognizerTest, GestureEventShowPressSentOnTap) {
3745 scoped_ptr<GestureEventConsumeDelegate> delegate( 3851 scoped_ptr<GestureEventConsumeDelegate> delegate(
3746 new GestureEventConsumeDelegate()); 3852 new GestureEventConsumeDelegate());
3747 TimedEvents tes; 3853 TimedEvents tes;
3748 const int kWindowWidth = 123; 3854 const int kWindowWidth = 123;
3749 const int kWindowHeight = 45; 3855 const int kWindowHeight = 45;
3750 const int kTouchId = 6; 3856 const int kTouchId = 6;
3751 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3857 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3752 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3858 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3753 delegate.get(), -1234, bounds, root_window())); 3859 delegate.get(), -1234, bounds, root_window()));
3754 3860
(...skipping 11 matching lines...) Expand all
3766 delegate->Reset(); 3872 delegate->Reset();
3767 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3873 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3768 kTouchId, tes.LeapForward(50)); 3874 kTouchId, tes.LeapForward(50));
3769 DispatchEventUsingWindowDispatcher(&release1); 3875 DispatchEventUsingWindowDispatcher(&release1);
3770 EXPECT_TRUE(delegate->show_press()); 3876 EXPECT_TRUE(delegate->show_press());
3771 EXPECT_FALSE(delegate->tap_cancel()); 3877 EXPECT_FALSE(delegate->tap_cancel());
3772 EXPECT_TRUE(delegate->tap()); 3878 EXPECT_TRUE(delegate->tap());
3773 } 3879 }
3774 3880
3775 // Test that consuming the first move touch event prevents a scroll. 3881 // Test that consuming the first move touch event prevents a scroll.
3776 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) { 3882 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) {
3777 scoped_ptr<QueueTouchEventDelegate> delegate( 3883 scoped_ptr<QueueTouchEventDelegate> delegate(
3778 new QueueTouchEventDelegate(host()->dispatcher())); 3884 new QueueTouchEventDelegate(host()->dispatcher()));
3779 TimedEvents tes; 3885 TimedEvents tes;
3780 const int kTouchId = 7; 3886 const int kTouchId = 7;
3781 gfx::Rect bounds(0, 0, 1000, 1000); 3887 gfx::Rect bounds(0, 0, 1000, 1000);
3782 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3888 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3783 delegate.get(), -1234, bounds, root_window())); 3889 delegate.get(), -1234, bounds, root_window()));
3784 3890
3785 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3891 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3786 kTouchId, tes.Now()); 3892 kTouchId, tes.Now());
3787 DispatchEventUsingWindowDispatcher(&press); 3893 DispatchEventUsingWindowDispatcher(&press);
3788 delegate->ReceivedAck(); 3894 delegate->ReceivedAck();
3789 3895
3790 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(2, 2), 3896 // A touch move within the slop region is never consumed in web contents. The
3897 // unified GR won't prevent scroll if a touch move within the slop region is
3898 // consumed, so make sure this touch move exceeds the slop region.
3899 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10),
3791 kTouchId, tes.Now()); 3900 kTouchId, tes.Now());
3792 DispatchEventUsingWindowDispatcher(&move1); 3901 DispatchEventUsingWindowDispatcher(&move1);
3793 delegate->ReceivedAckPreventDefaulted(); 3902 delegate->ReceivedAckPreventDefaulted();
3794 3903
3795 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 3904 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
3796 kTouchId, tes.Now()); 3905 kTouchId, tes.Now());
3797 DispatchEventUsingWindowDispatcher(&move2); 3906 DispatchEventUsingWindowDispatcher(&move2);
3798 delegate->ReceivedAck(); 3907 delegate->ReceivedAck();
3799 3908
3800 EXPECT_FALSE(delegate->scroll_begin()); 3909 EXPECT_FALSE(delegate->scroll_begin());
3801 EXPECT_FALSE(delegate->scroll_update()); 3910 EXPECT_FALSE(delegate->scroll_update());
3802 } 3911 }
3803 3912
3804 // Test that consuming the first touch move event of a touch point doesn't 3913 // Test that consuming the first touch move event of a touch point doesn't
3805 // prevent pinching once an additional touch has been pressed. 3914 // prevent pinching once an additional touch has been pressed.
3806 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) { 3915 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) {
3916 // Consuming moves within the touch slop and the the disposition handling of
3917 // pinch events behave differently between the Unified GR and the Aura GR.
3918 if (UsingUnifiedGR())
3919 return;
3920
3807 scoped_ptr<QueueTouchEventDelegate> delegate( 3921 scoped_ptr<QueueTouchEventDelegate> delegate(
3808 new QueueTouchEventDelegate(host()->dispatcher())); 3922 new QueueTouchEventDelegate(host()->dispatcher()));
3809 TimedEvents tes; 3923 TimedEvents tes;
3810 const int kTouchId1 = 7; 3924 const int kTouchId1 = 7;
3811 const int kTouchId2 = 4; 3925 const int kTouchId2 = 4;
3812 gfx::Rect bounds(0, 0, 1000, 1000); 3926 gfx::Rect bounds(0, 0, 1000, 1000);
3813 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3927 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3814 delegate.get(), -1234, bounds, root_window())); 3928 delegate.get(), -1234, bounds, root_window()));
3815 3929
3816 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3930 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3853 kTouchId2, tes.Now()); 3967 kTouchId2, tes.Now());
3854 DispatchEventUsingWindowDispatcher(&move4); 3968 DispatchEventUsingWindowDispatcher(&move4);
3855 delegate->ReceivedAck(); 3969 delegate->ReceivedAck();
3856 3970
3857 EXPECT_TRUE(delegate->pinch_update()); 3971 EXPECT_TRUE(delegate->pinch_update());
3858 EXPECT_EQ(10, delegate->scroll_x()); 3972 EXPECT_EQ(10, delegate->scroll_x());
3859 EXPECT_EQ(10, delegate->scroll_y()); 3973 EXPECT_EQ(10, delegate->scroll_y());
3860 } 3974 }
3861 3975
3862 // Test that consuming the first move touch doesn't prevent a tap. 3976 // Test that consuming the first move touch doesn't prevent a tap.
3863 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) { 3977 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) {
3864 scoped_ptr<QueueTouchEventDelegate> delegate( 3978 scoped_ptr<QueueTouchEventDelegate> delegate(
3865 new QueueTouchEventDelegate(host()->dispatcher())); 3979 new QueueTouchEventDelegate(host()->dispatcher()));
3866 TimedEvents tes; 3980 TimedEvents tes;
3867 const int kTouchId = 7; 3981 const int kTouchId = 7;
3868 gfx::Rect bounds(0, 0, 1000, 1000); 3982 gfx::Rect bounds(0, 0, 1000, 1000);
3869 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3983 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3870 delegate.get(), -1234, bounds, root_window())); 3984 delegate.get(), -1234, bounds, root_window()));
3871 3985
3872 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3986 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3873 kTouchId, tes.Now()); 3987 kTouchId, tes.Now());
3874 DispatchEventUsingWindowDispatcher(&press); 3988 DispatchEventUsingWindowDispatcher(&press);
3875 delegate->ReceivedAck(); 3989 delegate->ReceivedAck();
3876 3990
3877 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2), 3991 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
3878 kTouchId, tes.Now()); 3992 kTouchId, tes.Now());
3879 DispatchEventUsingWindowDispatcher(&move); 3993 DispatchEventUsingWindowDispatcher(&move);
3880 delegate->ReceivedAckPreventDefaulted(); 3994 delegate->ReceivedAckPreventDefaulted();
3881 3995
3882 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(2, 2), 3996 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(2, 2),
3883 kTouchId, tes.LeapForward(50)); 3997 kTouchId, tes.LeapForward(50));
3884 DispatchEventUsingWindowDispatcher(&release); 3998 DispatchEventUsingWindowDispatcher(&release);
3885 delegate->ReceivedAck(); 3999 delegate->ReceivedAck();
3886 4000
3887 EXPECT_TRUE(delegate->tap()); 4001 EXPECT_TRUE(delegate->tap());
3888 } 4002 }
3889 4003
3890 // Test that consuming the first move touch doesn't prevent a long press. 4004 // Test that consuming the first move touch doesn't prevent a long press.
3891 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) { 4005 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) {
3892 scoped_ptr<QueueTouchEventDelegate> delegate( 4006 scoped_ptr<QueueTouchEventDelegate> delegate(
3893 new QueueTouchEventDelegate(host()->dispatcher())); 4007 new QueueTouchEventDelegate(host()->dispatcher()));
3894 TimedEvents tes; 4008 TimedEvents tes;
3895 const int kWindowWidth = 123; 4009 const int kWindowWidth = 123;
3896 const int kWindowHeight = 45; 4010 const int kWindowHeight = 45;
3897 const int kTouchId = 2; 4011 const int kTouchId = 2;
3898 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 4012 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3899 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4013 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3900 delegate.get(), -1234, bounds, root_window())); 4014 delegate.get(), -1234, bounds, root_window()));
3901 4015
(...skipping 13 matching lines...) Expand all
3915 kTouchId, tes.Now()); 4029 kTouchId, tes.Now());
3916 DispatchEventUsingWindowDispatcher(&move); 4030 DispatchEventUsingWindowDispatcher(&move);
3917 delegate->ReceivedAckPreventDefaulted(); 4031 delegate->ReceivedAckPreventDefaulted();
3918 4032
3919 // Wait until the timer runs out 4033 // Wait until the timer runs out
3920 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 4034 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
3921 EXPECT_TRUE(delegate->long_press()); 4035 EXPECT_TRUE(delegate->long_press());
3922 } 4036 }
3923 4037
3924 // Tests that the deltas are correct when leaving the slop region very slowly. 4038 // Tests that the deltas are correct when leaving the slop region very slowly.
3925 TEST_F(GestureRecognizerTest, TestExceedingSlopSlowly) { 4039 TEST_P(GestureRecognizerTest, TestExceedingSlopSlowly) {
4040 // Disabled for unified GR due to subtle differences in touch slop handling.
4041 if (UsingUnifiedGR())
4042 return;
4043
3926 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); 4044 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
3927 scoped_ptr<GestureEventConsumeDelegate> delegate( 4045 scoped_ptr<GestureEventConsumeDelegate> delegate(
3928 new GestureEventConsumeDelegate()); 4046 new GestureEventConsumeDelegate());
3929 const int kWindowWidth = 234; 4047 const int kWindowWidth = 234;
3930 const int kWindowHeight = 345; 4048 const int kWindowHeight = 345;
3931 const int kTouchId = 5; 4049 const int kTouchId = 5;
3932 TimedEvents tes; 4050 TimedEvents tes;
3933 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 4051 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3934 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4052 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3935 delegate.get(), -1234, bounds, root_window())); 4053 delegate.get(), -1234, bounds, root_window()));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3973 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(14, 10), kTouchId, 4091 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(14, 10), kTouchId,
3974 tes.LeapForward(40)); 4092 tes.LeapForward(40));
3975 DispatchEventUsingWindowDispatcher(&move4); 4093 DispatchEventUsingWindowDispatcher(&move4);
3976 EXPECT_FALSE(delegate->scroll_begin()); 4094 EXPECT_FALSE(delegate->scroll_begin());
3977 EXPECT_TRUE(delegate->scroll_update()); 4095 EXPECT_TRUE(delegate->scroll_update());
3978 EXPECT_EQ(1, delegate->scroll_x()); 4096 EXPECT_EQ(1, delegate->scroll_x());
3979 EXPECT_EQ(0, delegate->scroll_x_hint()); 4097 EXPECT_EQ(0, delegate->scroll_x_hint());
3980 delegate->Reset(); 4098 delegate->Reset();
3981 } 4099 }
3982 4100
3983 TEST_F(GestureRecognizerTest, ScrollAlternatelyConsumedTest) { 4101 TEST_P(GestureRecognizerTest, ScrollAlternatelyConsumedTest) {
3984 scoped_ptr<QueueTouchEventDelegate> delegate( 4102 scoped_ptr<QueueTouchEventDelegate> delegate(
3985 new QueueTouchEventDelegate(host()->dispatcher())); 4103 new QueueTouchEventDelegate(host()->dispatcher()));
3986 TimedEvents tes; 4104 TimedEvents tes;
3987 const int kWindowWidth = 3000; 4105 const int kWindowWidth = 3000;
3988 const int kWindowHeight = 3000; 4106 const int kWindowHeight = 3000;
3989 const int kTouchId = 2; 4107 const int kTouchId = 2;
3990 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 4108 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3991 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4109 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3992 delegate.get(), -1234, bounds, root_window())); 4110 delegate.get(), -1234, bounds, root_window()));
3993 4111
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4032 ui::TouchEvent move3( 4150 ui::TouchEvent move3(
4033 ui::ET_TOUCH_MOVED, gfx::Point(x, y), kTouchId, tes.Now()); 4151 ui::ET_TOUCH_MOVED, gfx::Point(x, y), kTouchId, tes.Now());
4034 DispatchEventUsingWindowDispatcher(&move3); 4152 DispatchEventUsingWindowDispatcher(&move3);
4035 delegate->ReceivedAckPreventDefaulted(); 4153 delegate->ReceivedAckPreventDefaulted();
4036 EXPECT_FALSE(delegate->scroll_begin()); 4154 EXPECT_FALSE(delegate->scroll_begin());
4037 EXPECT_FALSE(delegate->scroll_update()); 4155 EXPECT_FALSE(delegate->scroll_update());
4038 delegate->Reset(); 4156 delegate->Reset();
4039 } 4157 }
4040 } 4158 }
4041 4159
4042 TEST_F(GestureRecognizerTest, PinchAlternatelyConsumedTest) { 4160 TEST_P(GestureRecognizerTest, PinchAlternatelyConsumedTest) {
4161 // Disabled for unified GR due to differences in when scroll update is
4162 // sent. The Aura GR will never send a ScrollUpdate with a ScrollBegin, but
4163 // the unified GR will.
4164 if (UsingUnifiedGR())
4165 return;
4166
4043 scoped_ptr<QueueTouchEventDelegate> delegate( 4167 scoped_ptr<QueueTouchEventDelegate> delegate(
4044 new QueueTouchEventDelegate(host()->dispatcher())); 4168 new QueueTouchEventDelegate(host()->dispatcher()));
4045 TimedEvents tes; 4169 TimedEvents tes;
4046 const int kWindowWidth = 3000; 4170 const int kWindowWidth = 3000;
4047 const int kWindowHeight = 3000; 4171 const int kWindowHeight = 3000;
4048 const int kTouchId1 = 5; 4172 const int kTouchId1 = 5;
4049 const int kTouchId2 = 7; 4173 const int kTouchId2 = 7;
4050 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 4174 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
4051 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4175 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4052 delegate.get(), -1234, bounds, root_window())); 4176 delegate.get(), -1234, bounds, root_window()));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4116 EXPECT_FALSE(delegate->scroll_begin()); 4240 EXPECT_FALSE(delegate->scroll_begin());
4117 EXPECT_FALSE(delegate->scroll_update()); 4241 EXPECT_FALSE(delegate->scroll_update());
4118 EXPECT_FALSE(delegate->scroll_end()); 4242 EXPECT_FALSE(delegate->scroll_end());
4119 EXPECT_FALSE(delegate->pinch_begin()); 4243 EXPECT_FALSE(delegate->pinch_begin());
4120 EXPECT_FALSE(delegate->pinch_update()); 4244 EXPECT_FALSE(delegate->pinch_update());
4121 EXPECT_FALSE(delegate->pinch_end()); 4245 EXPECT_FALSE(delegate->pinch_end());
4122 delegate->Reset(); 4246 delegate->Reset();
4123 } 4247 }
4124 } 4248 }
4125 4249
4250 // Test that touch event flags are passed through to the gesture event.
4251 TEST_P(GestureRecognizerTest, GestureEventFlagsPassedFromTouchEvent) {
4252 scoped_ptr<GestureEventConsumeDelegate> delegate(
4253 new GestureEventConsumeDelegate());
4254 TimedEvents tes;
4255 const int kWindowWidth = 123;
4256 const int kWindowHeight = 45;
4257 const int kTouchId = 6;
4258 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
4259 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4260 delegate.get(), -1234, bounds, root_window()));
4261
4262 delegate->Reset();
4263
4264 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
4265 kTouchId, tes.Now());
4266 DispatchEventUsingWindowDispatcher(&press1);
4267 EXPECT_TRUE(delegate->tap_down());
4268
4269 int default_flags = delegate->flags();
4270
4271 ui::TouchEvent move1(
4272 ui::ET_TOUCH_MOVED, gfx::Point(397, 149), kTouchId, tes.LeapForward(50));
4273 move1.set_flags(992);
4274
4275 DispatchEventUsingWindowDispatcher(&move1);
4276 EXPECT_NE(default_flags, delegate->flags());
4277 }
4278
4279 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4280 GestureRecognizerTest,
4281 ::testing::Bool());
4282
4126 } // namespace test 4283 } // namespace test
4127 } // namespace aura 4284 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/aura/test/aura_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698