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

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

Issue 254963003: Revert of GestureRecognizerTest tests both Aura and Unified Gesture Detectors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 velocity_y_(0), 95 velocity_y_(0),
96 scroll_x_ordinal_(0), 96 scroll_x_ordinal_(0),
97 scroll_y_ordinal_(0), 97 scroll_y_ordinal_(0),
98 scroll_velocity_x_ordinal_(0), 98 scroll_velocity_x_ordinal_(0),
99 scroll_velocity_y_ordinal_(0), 99 scroll_velocity_y_ordinal_(0),
100 velocity_x_ordinal_(0), 100 velocity_x_ordinal_(0),
101 velocity_y_ordinal_(0), 101 velocity_y_ordinal_(0),
102 scroll_x_hint_(0), 102 scroll_x_hint_(0),
103 scroll_y_hint_(0), 103 scroll_y_hint_(0),
104 tap_count_(0), 104 tap_count_(0),
105 wait_until_event_(ui::ET_UNKNOWN), 105 wait_until_event_(ui::ET_UNKNOWN) {
106 flags_(0) {} 106 }
107 107
108 virtual ~GestureEventConsumeDelegate() {} 108 virtual ~GestureEventConsumeDelegate() {}
109 109
110 void Reset() { 110 void Reset() {
111 events_.clear(); 111 events_.clear();
112 tap_ = false; 112 tap_ = false;
113 tap_down_ = false; 113 tap_down_ = false;
114 tap_cancel_ = false; 114 tap_cancel_ = false;
115 begin_ = false; 115 begin_ = false;
116 end_ = false; 116 end_ = false;
(...skipping 25 matching lines...) Expand all
142 scroll_x_ordinal_ = 0; 142 scroll_x_ordinal_ = 0;
143 scroll_y_ordinal_ = 0; 143 scroll_y_ordinal_ = 0;
144 scroll_velocity_x_ordinal_ = 0; 144 scroll_velocity_x_ordinal_ = 0;
145 scroll_velocity_y_ordinal_ = 0; 145 scroll_velocity_y_ordinal_ = 0;
146 velocity_x_ordinal_ = 0; 146 velocity_x_ordinal_ = 0;
147 velocity_y_ordinal_ = 0; 147 velocity_y_ordinal_ = 0;
148 scroll_x_hint_ = 0; 148 scroll_x_hint_ = 0;
149 scroll_y_hint_ = 0; 149 scroll_y_hint_ = 0;
150 tap_count_ = 0; 150 tap_count_ = 0;
151 scale_ = 0; 151 scale_ = 0;
152 flags_ = 0;
153 } 152 }
154 153
155 const std::vector<ui::EventType>& events() const { return events_; }; 154 const std::vector<ui::EventType>& events() const { return events_; };
156 155
157 bool tap() const { return tap_; } 156 bool tap() const { return tap_; }
158 bool tap_down() const { return tap_down_; } 157 bool tap_down() const { return tap_down_; }
159 bool tap_cancel() const { return tap_cancel_; } 158 bool tap_cancel() const { return tap_cancel_; }
160 bool begin() const { return begin_; } 159 bool begin() const { return begin_; }
161 bool end() const { return end_; } 160 bool end() const { return end_; }
162 bool scroll_begin() const { return scroll_begin_; } 161 bool scroll_begin() const { return scroll_begin_; }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 float scroll_y_ordinal() const { return scroll_y_ordinal_; } 196 float scroll_y_ordinal() const { return scroll_y_ordinal_; }
198 float scroll_velocity_x_ordinal() const { return scroll_velocity_x_ordinal_; } 197 float scroll_velocity_x_ordinal() const { return scroll_velocity_x_ordinal_; }
199 float scroll_velocity_y_ordinal() const { return scroll_velocity_y_ordinal_; } 198 float scroll_velocity_y_ordinal() const { return scroll_velocity_y_ordinal_; }
200 float velocity_x_ordinal() const { return velocity_x_ordinal_; } 199 float velocity_x_ordinal() const { return velocity_x_ordinal_; }
201 float velocity_y_ordinal() const { return velocity_y_ordinal_; } 200 float velocity_y_ordinal() const { return velocity_y_ordinal_; }
202 float scroll_x_hint() const { return scroll_x_hint_; } 201 float scroll_x_hint() const { return scroll_x_hint_; }
203 float scroll_y_hint() const { return scroll_y_hint_; } 202 float scroll_y_hint() const { return scroll_y_hint_; }
204 float scale() const { return scale_; } 203 float scale() const { return scale_; }
205 const gfx::Rect& bounding_box() const { return bounding_box_; } 204 const gfx::Rect& bounding_box() const { return bounding_box_; }
206 int tap_count() const { return tap_count_; } 205 int tap_count() const { return tap_count_; }
207 int flags() const { return flags_; }
208 206
209 void WaitUntilReceivedGesture(ui::EventType type) { 207 void WaitUntilReceivedGesture(ui::EventType type) {
210 wait_until_event_ = type; 208 wait_until_event_ = type;
211 run_loop_.reset(new base::RunLoop()); 209 run_loop_.reset(new base::RunLoop());
212 run_loop_->Run(); 210 run_loop_->Run();
213 } 211 }
214 212
215 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { 213 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
216 events_.push_back(gesture->type()); 214 events_.push_back(gesture->type());
217 bounding_box_ = gesture->details().bounding_box(); 215 bounding_box_ = gesture->details().bounding_box();
218 flags_ = gesture->flags();
219 switch (gesture->type()) { 216 switch (gesture->type()) {
220 case ui::ET_GESTURE_TAP: 217 case ui::ET_GESTURE_TAP:
221 tap_location_ = gesture->location(); 218 tap_location_ = gesture->location();
222 tap_count_ = gesture->details().tap_count(); 219 tap_count_ = gesture->details().tap_count();
223 tap_ = true; 220 tap_ = true;
224 break; 221 break;
225 case ui::ET_GESTURE_TAP_DOWN: 222 case ui::ET_GESTURE_TAP_DOWN:
226 tap_down_ = true; 223 tap_down_ = true;
227 break; 224 break;
228 case ui::ET_GESTURE_TAP_CANCEL: 225 case ui::ET_GESTURE_TAP_CANCEL:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 break; 280 break;
284 case ui::ET_GESTURE_SHOW_PRESS: 281 case ui::ET_GESTURE_SHOW_PRESS:
285 show_press_ = true; 282 show_press_ = true;
286 break; 283 break;
287 case ui::ET_GESTURE_MULTIFINGER_SWIPE: 284 case ui::ET_GESTURE_MULTIFINGER_SWIPE:
288 swipe_left_ = gesture->details().swipe_left(); 285 swipe_left_ = gesture->details().swipe_left();
289 swipe_right_ = gesture->details().swipe_right(); 286 swipe_right_ = gesture->details().swipe_right();
290 swipe_up_ = gesture->details().swipe_up(); 287 swipe_up_ = gesture->details().swipe_up();
291 swipe_down_ = gesture->details().swipe_down(); 288 swipe_down_ = gesture->details().swipe_down();
292 break; 289 break;
293 case ui::ET_SCROLL_FLING_CANCEL:
294 // Only used in unified gesture detection.
295 break;
296 default: 290 default:
297 NOTREACHED(); 291 NOTREACHED();
298 } 292 }
299 if (wait_until_event_ == gesture->type() && run_loop_) { 293 if (wait_until_event_ == gesture->type() && run_loop_) {
300 run_loop_->Quit(); 294 run_loop_->Quit();
301 wait_until_event_ = ui::ET_UNKNOWN; 295 wait_until_event_ = ui::ET_UNKNOWN;
302 } 296 }
303 gesture->StopPropagation(); 297 gesture->StopPropagation();
304 } 298 }
305 299
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 float scroll_y_ordinal_; 336 float scroll_y_ordinal_;
343 float scroll_velocity_x_ordinal_; 337 float scroll_velocity_x_ordinal_;
344 float scroll_velocity_y_ordinal_; 338 float scroll_velocity_y_ordinal_;
345 float velocity_x_ordinal_; 339 float velocity_x_ordinal_;
346 float velocity_y_ordinal_; 340 float velocity_y_ordinal_;
347 float scroll_x_hint_; 341 float scroll_x_hint_;
348 float scroll_y_hint_; 342 float scroll_y_hint_;
349 float scale_; 343 float scale_;
350 gfx::Rect bounding_box_; 344 gfx::Rect bounding_box_;
351 int tap_count_; 345 int tap_count_;
352 int flags_;
353 346
354 ui::EventType wait_until_event_; 347 ui::EventType wait_until_event_;
355 348
356 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 349 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate);
357 }; 350 };
358 351
359 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 352 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
360 public: 353 public:
361 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) 354 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher)
362 : window_(NULL), 355 : window_(NULL),
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 scoped_ptr<ui::GestureRecognizer> new_gr_; 549 scoped_ptr<ui::GestureRecognizer> new_gr_;
557 550
558 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter); 551 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter);
559 }; 552 };
560 553
561 class TimedEvents { 554 class TimedEvents {
562 private: 555 private:
563 int simulated_now_; 556 int simulated_now_;
564 557
565 public: 558 public:
566 // Use a non-zero start time to pass DCHECKs which ensure events have had a 559 TimedEvents() : simulated_now_(0) {
567 // time assigned.
568 TimedEvents() : simulated_now_(1) {
569 } 560 }
570 561
571 base::TimeDelta Now() { 562 base::TimeDelta Now() {
572 base::TimeDelta t = base::TimeDelta::FromMilliseconds(simulated_now_); 563 base::TimeDelta t = base::TimeDelta::FromMilliseconds(simulated_now_);
573 simulated_now_++; 564 simulated_now_++;
574 return t; 565 return t;
575 } 566 }
576 567
577 base::TimeDelta LeapForward(int time_in_millis) { 568 base::TimeDelta LeapForward(int time_in_millis) {
578 simulated_now_ += time_in_millis; 569 simulated_now_ += time_in_millis;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 target->RemovePreTargetHandler(this); 687 target->RemovePreTargetHandler(this);
697 target->parent()->RemoveChild(target); 688 target->parent()->RemoveChild(target);
698 } 689 }
699 } 690 }
700 691
701 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler); 692 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler);
702 }; 693 };
703 694
704 } // namespace 695 } // namespace
705 696
706 class GestureRecognizerTest : public AuraTestBase, 697 class GestureRecognizerTest : public AuraTestBase {
707 public ::testing::WithParamInterface<bool> {
708 public: 698 public:
709 GestureRecognizerTest() {} 699 GestureRecognizerTest() {}
710 700
711 bool UsingUnifiedGR() {
712 return GetParam();
713 }
714
715 virtual void SetUp() OVERRIDE { 701 virtual void SetUp() OVERRIDE {
716 // TODO(tdresser): Once unified GR has landed, only run these tests once. 702 CommandLine::ForCurrentProcess()->AppendSwitch(
717 if (UsingUnifiedGR()) { 703 switches::kEnableScrollPrediction);
718 // TODO(tdresser): use unified GR once it's available.
719 // CommandLine::ForCurrentProcess()->AppendSwitch(
720 // switches::kUseUnifiedGestureDetector);
721 }
722
723 AuraTestBase::SetUp(); 704 AuraTestBase::SetUp();
724 } 705 }
725 706
726 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); 707 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest);
727 }; 708 };
728 709
729 // Check that appropriate touch events generate tap gesture events. 710 // Check that appropriate touch events generate tap gesture events.
730 TEST_P(GestureRecognizerTest, GestureEventTap) { 711 TEST_F(GestureRecognizerTest, GestureEventTap) {
731 scoped_ptr<GestureEventConsumeDelegate> delegate( 712 scoped_ptr<GestureEventConsumeDelegate> delegate(
732 new GestureEventConsumeDelegate()); 713 new GestureEventConsumeDelegate());
733 TimedEvents tes; 714 TimedEvents tes;
734 const int kWindowWidth = 123; 715 const int kWindowWidth = 123;
735 const int kWindowHeight = 45; 716 const int kWindowHeight = 45;
736 const int kTouchId = 2; 717 const int kTouchId = 2;
737 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 718 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
738 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 719 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
739 delegate.get(), -1234, bounds, root_window())); 720 delegate.get(), -1234, bounds, root_window()));
740 721
(...skipping 30 matching lines...) Expand all
771 EXPECT_TRUE(delegate->end()); 752 EXPECT_TRUE(delegate->end());
772 EXPECT_FALSE(delegate->scroll_begin()); 753 EXPECT_FALSE(delegate->scroll_begin());
773 EXPECT_FALSE(delegate->scroll_update()); 754 EXPECT_FALSE(delegate->scroll_update());
774 EXPECT_FALSE(delegate->scroll_end()); 755 EXPECT_FALSE(delegate->scroll_end());
775 756
776 EXPECT_EQ(1, delegate->tap_count()); 757 EXPECT_EQ(1, delegate->tap_count());
777 } 758 }
778 759
779 // Check that appropriate touch events generate tap gesture events 760 // Check that appropriate touch events generate tap gesture events
780 // when information about the touch radii are provided. 761 // when information about the touch radii are provided.
781 TEST_P(GestureRecognizerTest, GestureEventTapRegion) { 762 TEST_F(GestureRecognizerTest, GestureEventTapRegion) {
782 scoped_ptr<GestureEventConsumeDelegate> delegate( 763 scoped_ptr<GestureEventConsumeDelegate> delegate(
783 new GestureEventConsumeDelegate()); 764 new GestureEventConsumeDelegate());
784 TimedEvents tes; 765 TimedEvents tes;
785 const int kWindowWidth = 800; 766 const int kWindowWidth = 800;
786 const int kWindowHeight = 600; 767 const int kWindowHeight = 600;
787 const int kTouchId = 2; 768 const int kTouchId = 2;
788 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 769 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
789 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 770 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
790 delegate.get(), -1234, bounds, root_window())); 771 delegate.get(), -1234, bounds, root_window()));
791 772
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 EXPECT_EQ(1, delegate->tap_count()); 992 EXPECT_EQ(1, delegate->tap_count());
1012 gfx::Point actual_point(delegate->tap_location()); 993 gfx::Point actual_point(delegate->tap_location());
1013 EXPECT_EQ(33, delegate->bounding_box().width()); 994 EXPECT_EQ(33, delegate->bounding_box().width());
1014 EXPECT_EQ(32, delegate->bounding_box().height()); 995 EXPECT_EQ(32, delegate->bounding_box().height());
1015 EXPECT_EQ(397, actual_point.x()); 996 EXPECT_EQ(397, actual_point.x());
1016 EXPECT_EQ(149, actual_point.y()); 997 EXPECT_EQ(149, actual_point.y());
1017 } 998 }
1018 } 999 }
1019 1000
1020 // Check that appropriate touch events generate scroll gesture events. 1001 // Check that appropriate touch events generate scroll gesture events.
1021 TEST_P(GestureRecognizerTest, GestureEventScroll) { 1002 TEST_F(GestureRecognizerTest, GestureEventScroll) {
1022 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of 1003 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of
1023 // that distance to be consumed by the slop, so we set the slop radius to 1004 // that distance to be consumed by the slop, so we set the slop radius to
1024 // sqrt(5 * 5 + 5 * 5). 1005 // sqrt(5 * 5 + 5 * 5).
1025 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( 1006 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1026 sqrt(static_cast<double>(5 * 5 + 5 * 5))); 1007 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1027 scoped_ptr<GestureEventConsumeDelegate> delegate( 1008 scoped_ptr<GestureEventConsumeDelegate> delegate(
1028 new GestureEventConsumeDelegate()); 1009 new GestureEventConsumeDelegate());
1029 TimedEvents tes; 1010 TimedEvents tes;
1030 const int kWindowWidth = 123; 1011 const int kWindowWidth = 123;
1031 const int kWindowHeight = 45; 1012 const int kWindowHeight = 45;
(...skipping 23 matching lines...) Expand all
1055 // The slop consumed 5 dips 1036 // The slop consumed 5 dips
1056 EXPECT_FLOAT_EQ(5.5, delegate->scroll_x()); 1037 EXPECT_FLOAT_EQ(5.5, delegate->scroll_x());
1057 EXPECT_FLOAT_EQ(5.5, delegate->scroll_y()); 1038 EXPECT_FLOAT_EQ(5.5, delegate->scroll_y());
1058 EXPECT_EQ(gfx::Point(1, 1).ToString(), 1039 EXPECT_EQ(gfx::Point(1, 1).ToString(),
1059 delegate->scroll_begin_position().ToString()); 1040 delegate->scroll_begin_position().ToString());
1060 1041
1061 // When scrolling with a single finger, the bounding box of the gesture should 1042 // When scrolling with a single finger, the bounding box of the gesture should
1062 // be empty, since it's a single point and the radius for testing is zero. 1043 // be empty, since it's a single point and the radius for testing is zero.
1063 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1044 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1064 1045
1065 // Move some more to generate a few more scroll updates. Make sure that we get 1046 // Move some more to generate a few more scroll updates.
1066 // out of the snap channel for the unified GR. 1047 tes.SendScrollEvent(event_processor(), 91, 192, kTouchId, delegate.get());
1067 tes.SendScrollEvent(event_processor(), 20, 120, kTouchId, delegate.get());
1068 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 1048 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
1069 EXPECT_FLOAT_EQ(-91.5, delegate->scroll_x()); 1049 EXPECT_FLOAT_EQ(-20.5, delegate->scroll_x());
1070 EXPECT_FLOAT_EQ(-91.5, delegate->scroll_y()); 1050 EXPECT_FLOAT_EQ(-19.5, delegate->scroll_y());
1071 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1051 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1072 1052
1073 tes.SendScrollEvent(event_processor(), 50, 124, kTouchId, delegate.get()); 1053 tes.SendScrollEvent(event_processor(), 121, 196, kTouchId, delegate.get());
1074 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 1054 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
1075 EXPECT_EQ(30, delegate->scroll_x()); 1055 EXPECT_EQ(30, delegate->scroll_x());
1076 EXPECT_EQ(4, delegate->scroll_y()); 1056 EXPECT_EQ(4, delegate->scroll_y());
1077 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1057 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1078 1058
1079 // Release the touch. This should end the scroll. 1059 // Release the touch. This should end the scroll.
1080 delegate->Reset(); 1060 delegate->Reset();
1081 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1061 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1082 kTouchId, 1062 kTouchId,
1083 tes.LeapForward(50)); 1063 tes.LeapForward(50));
1084 DispatchEventUsingWindowDispatcher(&release); 1064 DispatchEventUsingWindowDispatcher(&release);
1085 EXPECT_2_EVENTS(delegate->events(), 1065 EXPECT_2_EVENTS(delegate->events(),
1086 ui::ET_SCROLL_FLING_START, 1066 ui::ET_SCROLL_FLING_START,
1087 ui::ET_GESTURE_END); 1067 ui::ET_GESTURE_END);
1088 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1068 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1089 } 1069 }
1090 1070
1091 // Check that predicted scroll update positions are correct. 1071 // Check that predicted scroll update positions are correct.
1092 TEST_P(GestureRecognizerTest, GestureEventScrollPrediction) { 1072 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) {
1093 const double prediction_interval = 0.03; 1073 const double prediction_interval = 0.03;
1094 ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval); 1074 ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval);
1095 // We'll start by moving the touch point by (5, 5). We want all of that 1075 // We'll start by moving the touch point by (5, 5). We want all of that
1096 // distance to be consumed by the slop, so we set the slop radius to 1076 // distance to be consumed by the slop, so we set the slop radius to
1097 // sqrt(5 * 5 + 5 * 5). 1077 // sqrt(5 * 5 + 5 * 5).
1098 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( 1078 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1099 sqrt(static_cast<double>(5 * 5 + 5 * 5))); 1079 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1100 1080
1101 scoped_ptr<GestureEventConsumeDelegate> delegate( 1081 scoped_ptr<GestureEventConsumeDelegate> delegate(
1102 new GestureEventConsumeDelegate()); 1082 new GestureEventConsumeDelegate());
(...skipping 11 matching lines...) Expand all
1114 gfx::Vector2dF total_scroll; 1094 gfx::Vector2dF total_scroll;
1115 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(96, 196), 1095 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(96, 196),
1116 kTouchId, tes.Now()); 1096 kTouchId, tes.Now());
1117 DispatchEventUsingWindowDispatcher(&press); 1097 DispatchEventUsingWindowDispatcher(&press);
1118 EXPECT_2_EVENTS(delegate->events(), 1098 EXPECT_2_EVENTS(delegate->events(),
1119 ui::ET_GESTURE_BEGIN, 1099 ui::ET_GESTURE_BEGIN,
1120 ui::ET_GESTURE_TAP_DOWN); 1100 ui::ET_GESTURE_TAP_DOWN);
1121 delegate->Reset(); 1101 delegate->Reset();
1122 1102
1123 // Get rid of touch slop. 1103 // Get rid of touch slop.
1124 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(111, 211), 1104 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(101, 201),
1125 kTouchId, tes.Now()); 1105 kTouchId, tes.Now());
1126 DispatchEventUsingWindowDispatcher(&move); 1106 DispatchEventUsingWindowDispatcher(&move);
1127 EXPECT_3_EVENTS(delegate->events(), 1107 EXPECT_3_EVENTS(delegate->events(),
1128 ui::ET_GESTURE_TAP_CANCEL, 1108 ui::ET_GESTURE_TAP_CANCEL,
1129 ui::ET_GESTURE_SCROLL_BEGIN, 1109 ui::ET_GESTURE_SCROLL_BEGIN,
1130 ui::ET_GESTURE_SCROLL_UPDATE); 1110 ui::ET_GESTURE_SCROLL_UPDATE);
1131 total_scroll.set_x(total_scroll.x() + delegate->scroll_x()); 1111 total_scroll.set_x(total_scroll.x() + delegate->scroll_x());
1132 total_scroll.set_y(total_scroll.y() + delegate->scroll_y()); 1112 total_scroll.set_y(total_scroll.y() + delegate->scroll_y());
1133 1113
1134 // Move the touch-point enough so that it is considered as a scroll. This 1114 // Move the touch-point enough so that it is considered as a scroll. This
(...skipping 22 matching lines...) Expand all
1157 1137
1158 // Release the touch. This should end the scroll. 1138 // Release the touch. This should end the scroll.
1159 delegate->Reset(); 1139 delegate->Reset();
1160 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1140 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1161 kTouchId, 1141 kTouchId,
1162 tes.LeapForward(50)); 1142 tes.LeapForward(50));
1163 DispatchEventUsingWindowDispatcher(&release); 1143 DispatchEventUsingWindowDispatcher(&release);
1164 } 1144 }
1165 1145
1166 // Check that the bounding box during a scroll event is correct. 1146 // Check that the bounding box during a scroll event is correct.
1167 TEST_P(GestureRecognizerTest, GestureEventScrollBoundingBox) { 1147 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) {
1168 TimedEvents tes; 1148 TimedEvents tes;
1169 for (int radius = 1; radius <= 10; ++radius) { 1149 for (int radius = 1; radius <= 10; ++radius) {
1170 ui::GestureConfiguration::set_default_radius(radius); 1150 ui::GestureConfiguration::set_default_radius(radius);
1171 scoped_ptr<GestureEventConsumeDelegate> delegate( 1151 scoped_ptr<GestureEventConsumeDelegate> delegate(
1172 new GestureEventConsumeDelegate()); 1152 new GestureEventConsumeDelegate());
1173 const int kWindowWidth = 123; 1153 const int kWindowWidth = 123;
1174 const int kWindowHeight = 45; 1154 const int kWindowHeight = 45;
1175 const int kTouchId = 5; 1155 const int kTouchId = 5;
1176 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1156 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1177 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1157 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 kPositionY + kScrollAmount - radius, 1194 kPositionY + kScrollAmount - radius,
1215 radius * 2, 1195 radius * 2,
1216 radius * 2).ToString(), 1196 radius * 2).ToString(),
1217 delegate->bounding_box().ToString()); 1197 delegate->bounding_box().ToString());
1218 } 1198 }
1219 ui::GestureConfiguration::set_default_radius(0); 1199 ui::GestureConfiguration::set_default_radius(0);
1220 } 1200 }
1221 1201
1222 // Check Scroll End Events report correct velocities 1202 // Check Scroll End Events report correct velocities
1223 // if the user was on a horizontal rail 1203 // if the user was on a horizontal rail
1224 TEST_P(GestureRecognizerTest, GestureEventHorizontalRailFling) { 1204 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) {
1225 scoped_ptr<GestureEventConsumeDelegate> delegate( 1205 scoped_ptr<GestureEventConsumeDelegate> delegate(
1226 new GestureEventConsumeDelegate()); 1206 new GestureEventConsumeDelegate());
1227 TimedEvents tes; 1207 TimedEvents tes;
1228 const int kTouchId = 7; 1208 const int kTouchId = 7;
1229 gfx::Rect bounds(0, 0, 1000, 1000); 1209 gfx::Rect bounds(0, 0, 1000, 1000);
1230 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1210 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1231 delegate.get(), -1234, bounds, root_window())); 1211 delegate.get(), -1234, bounds, root_window()));
1232 1212
1233 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1213 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1234 kTouchId, tes.Now()); 1214 kTouchId, tes.Now());
1235 DispatchEventUsingWindowDispatcher(&press); 1215 DispatchEventUsingWindowDispatcher(&press);
1236 1216
1237 // Get rid of touch slop. 1217 // Get rid of touch slop.
1238 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0), 1218 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0),
1239 kTouchId, tes.Now()); 1219 kTouchId, tes.Now());
1240 DispatchEventUsingWindowDispatcher(&move); 1220 DispatchEventUsingWindowDispatcher(&move);
1241 delegate->Reset(); 1221 delegate->Reset();
1242 1222
1243 1223
1244 // Move the touch-point horizontally enough that it is considered a 1224 // Move the touch-point horizontally enough that it is considered a
1245 // horizontal scroll. 1225 // horizontal scroll.
1246 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); 1226 tes.SendScrollEvent(event_processor(), 25, 1, kTouchId, delegate.get());
1247 EXPECT_FLOAT_EQ(0, delegate->scroll_y()); 1227 EXPECT_EQ(0, delegate->scroll_y());
1248 EXPECT_FLOAT_EQ(1, delegate->scroll_y_ordinal()); 1228 EXPECT_EQ(1, delegate->scroll_y_ordinal());
1249 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); 1229 EXPECT_EQ(20, delegate->scroll_x());
1250 EXPECT_FLOAT_EQ(20, delegate->scroll_x_ordinal()); 1230 EXPECT_EQ(20, delegate->scroll_x_ordinal());
1251 1231
1252 // Get a high x velocity, while still staying on the rail 1232 // Get a high x velocity, while still staying on the rail
1253 tes.SendScrollEvents(event_processor(), 1, 1, 1233 tes.SendScrollEvents(event_processor(), 1, 1,
1254 100, 10, kTouchId, 1, 1234 100, 10, kTouchId, 1,
1255 ui::GestureConfiguration::points_buffered_for_velocity(), 1235 ui::GestureConfiguration::points_buffered_for_velocity(),
1256 delegate.get()); 1236 delegate.get());
1257 1237
1258 delegate->Reset(); 1238 delegate->Reset();
1259 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1239 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1260 kTouchId, tes.Now()); 1240 kTouchId, tes.Now());
1261 DispatchEventUsingWindowDispatcher(&release); 1241 DispatchEventUsingWindowDispatcher(&release);
1262 1242
1263 EXPECT_TRUE(delegate->fling()); 1243 EXPECT_TRUE(delegate->fling());
1264 EXPECT_FALSE(delegate->scroll_end()); 1244 EXPECT_FALSE(delegate->scroll_end());
1265 EXPECT_GT(delegate->velocity_x(), 0); 1245 EXPECT_GT(delegate->velocity_x(), 0);
1266 EXPECT_EQ(0, delegate->velocity_y()); 1246 EXPECT_EQ(0, delegate->velocity_y());
1267 } 1247 }
1268 1248
1269 // Check Scroll End Events report correct velocities 1249 // Check Scroll End Events report correct velocities
1270 // if the user was on a vertical rail 1250 // if the user was on a vertical rail
1271 TEST_P(GestureRecognizerTest, GestureEventVerticalRailFling) { 1251 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
1272 scoped_ptr<GestureEventConsumeDelegate> delegate( 1252 scoped_ptr<GestureEventConsumeDelegate> delegate(
1273 new GestureEventConsumeDelegate()); 1253 new GestureEventConsumeDelegate());
1274 TimedEvents tes; 1254 TimedEvents tes;
1275 const int kTouchId = 7; 1255 const int kTouchId = 7;
1276 gfx::Rect bounds(0, 0, 1000, 1000); 1256 gfx::Rect bounds(0, 0, 1000, 1000);
1277 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1257 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1278 delegate.get(), -1234, bounds, root_window())); 1258 delegate.get(), -1234, bounds, root_window()));
1279 1259
1280 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1260 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1281 kTouchId, tes.Now()); 1261 kTouchId, tes.Now());
1282 DispatchEventUsingWindowDispatcher(&press); 1262 DispatchEventUsingWindowDispatcher(&press);
1283 1263
1284 // Get rid of touch slop. 1264 // Get rid of touch slop.
1285 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 10), 1265 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5),
1286 kTouchId, tes.Now()); 1266 kTouchId, tes.Now());
1287 DispatchEventUsingWindowDispatcher(&move); 1267 DispatchEventUsingWindowDispatcher(&move);
1288 delegate->Reset(); 1268 delegate->Reset();
1289 1269
1290 // Move the touch-point vertically enough that it is considered a 1270 // Move the touch-point vertically enough that it is considered a
1291 // vertical scroll. 1271 // vertical scroll.
1292 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get()); 1272 tes.SendScrollEvent(event_processor(), 1, 25, kTouchId, delegate.get());
1293 EXPECT_EQ(20, delegate->scroll_y()); 1273 EXPECT_EQ(20, delegate->scroll_y());
1294 EXPECT_EQ(20, delegate->scroll_y_ordinal()); 1274 EXPECT_EQ(20, delegate->scroll_y_ordinal());
1295 EXPECT_EQ(0, delegate->scroll_x()); 1275 EXPECT_EQ(0, delegate->scroll_x());
1296 EXPECT_EQ(1, delegate->scroll_x_ordinal()); 1276 EXPECT_EQ(1, delegate->scroll_x_ordinal());
1297 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1277 EXPECT_EQ(0, delegate->scroll_velocity_x());
1298 1278
1299 // Get a high y velocity, while still staying on the rail 1279 // Get a high y velocity, while still staying on the rail
1300 tes.SendScrollEvents(event_processor(), 1, 6, 1280 tes.SendScrollEvents(event_processor(), 1, 6,
1301 10, 100, kTouchId, 1, 1281 10, 100, kTouchId, 1,
1302 ui::GestureConfiguration::points_buffered_for_velocity(), 1282 ui::GestureConfiguration::points_buffered_for_velocity(),
1303 delegate.get()); 1283 delegate.get());
1304 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1284 EXPECT_EQ(0, delegate->scroll_velocity_x());
1305 1285
1306 delegate->Reset(); 1286 delegate->Reset();
1307 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206), 1287 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206),
1308 kTouchId, tes.Now()); 1288 kTouchId, tes.Now());
1309 DispatchEventUsingWindowDispatcher(&release); 1289 DispatchEventUsingWindowDispatcher(&release);
1310 1290
1311 EXPECT_TRUE(delegate->fling()); 1291 EXPECT_TRUE(delegate->fling());
1312 EXPECT_FALSE(delegate->scroll_end()); 1292 EXPECT_FALSE(delegate->scroll_end());
1313 EXPECT_EQ(0, delegate->velocity_x()); 1293 EXPECT_EQ(0, delegate->velocity_x());
1314 EXPECT_GT(delegate->velocity_y(), 0); 1294 EXPECT_GT(delegate->velocity_y(), 0);
1315 } 1295 }
1316 1296
1317 // Check Scroll End Events report non-zero velocities if the user is not on a 1297 // Check Scroll End Events reports zero velocities
1318 // rail 1298 // if the user is not on a rail
1319 TEST_P(GestureRecognizerTest, GestureEventNonRailFling) { 1299 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
1320 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0); 1300 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
1321 scoped_ptr<GestureEventConsumeDelegate> delegate( 1301 scoped_ptr<GestureEventConsumeDelegate> delegate(
1322 new GestureEventConsumeDelegate()); 1302 new GestureEventConsumeDelegate());
1323 TimedEvents tes; 1303 TimedEvents tes;
1324 const int kTouchId = 7; 1304 const int kTouchId = 7;
1325 gfx::Rect bounds(0, 0, 1000, 1000); 1305 gfx::Rect bounds(0, 0, 1000, 1000);
1326 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1306 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1327 delegate.get(), -1234, bounds, root_window())); 1307 delegate.get(), -1234, bounds, root_window()));
1328 1308
1329 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1309 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1330 kTouchId, tes.Now()); 1310 kTouchId, tes.Now());
1331 DispatchEventUsingWindowDispatcher(&press); 1311 DispatchEventUsingWindowDispatcher(&press);
1332 1312
1333 // Move the touch-point such that a non-rail scroll begins, and we're outside 1313 // Move the touch-point such that a non-rail scroll begins
1334 // the snap channel for the unified GR. 1314 tes.SendScrollEvent(event_processor(), 20, 20, kTouchId, delegate.get());
1335 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get()); 1315 EXPECT_EQ(20, delegate->scroll_y());
1336 EXPECT_EQ(50, delegate->scroll_y()); 1316 EXPECT_EQ(20, delegate->scroll_x());
1337 EXPECT_EQ(50, delegate->scroll_x());
1338 1317
1339 tes.SendScrollEvents(event_processor(), 1, 1, 1318 tes.SendScrollEvents(event_processor(), 1, 1,
1340 10, 100, kTouchId, 1, 1319 10, 100, kTouchId, 1,
1341 ui::GestureConfiguration::points_buffered_for_velocity(), 1320 ui::GestureConfiguration::points_buffered_for_velocity(),
1342 delegate.get()); 1321 delegate.get());
1343 1322
1344 delegate->Reset(); 1323 delegate->Reset();
1345 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1324 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1346 kTouchId, tes.Now()); 1325 kTouchId, tes.Now());
1347 DispatchEventUsingWindowDispatcher(&release); 1326 DispatchEventUsingWindowDispatcher(&release);
1348 1327
1349 EXPECT_TRUE(delegate->fling()); 1328 EXPECT_TRUE(delegate->fling());
1350 EXPECT_FALSE(delegate->scroll_end()); 1329 EXPECT_FALSE(delegate->scroll_end());
1351 EXPECT_GT(delegate->velocity_x(), 0); 1330 EXPECT_GT(delegate->velocity_x(), 0);
1352 EXPECT_GT(delegate->velocity_y(), 0); 1331 EXPECT_GT(delegate->velocity_y(), 0);
1353 } 1332 }
1354 1333
1355 // Check that appropriate touch events generate long press events 1334 // Check that appropriate touch events generate long press events
1356 TEST_P(GestureRecognizerTest, GestureEventLongPress) { 1335 TEST_F(GestureRecognizerTest, GestureEventLongPress) {
1357 scoped_ptr<GestureEventConsumeDelegate> delegate( 1336 scoped_ptr<GestureEventConsumeDelegate> delegate(
1358 new GestureEventConsumeDelegate()); 1337 new GestureEventConsumeDelegate());
1338 TimedEvents tes;
1359 const int kWindowWidth = 123; 1339 const int kWindowWidth = 123;
1360 const int kWindowHeight = 45; 1340 const int kWindowHeight = 45;
1361 const int kTouchId = 2; 1341 const int kTouchId = 2;
1362 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1342 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1363 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1343 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1364 delegate.get(), -1234, bounds, root_window())); 1344 delegate.get(), -1234, bounds, root_window()));
1365 1345
1366 delegate->Reset(); 1346 delegate->Reset();
1367 1347
1368 TimerTestGestureRecognizer* gesture_recognizer = 1348 TimerTestGestureRecognizer* gesture_recognizer =
1369 new TimerTestGestureRecognizer(); 1349 new TimerTestGestureRecognizer();
1370 1350
1371 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 1351 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
1372 1352
1373 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, 1353 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1374 gfx::Point(101, 201), 1354 kTouchId, tes.Now());
1375 kTouchId,
1376 ui::EventTimeForNow());
1377 DispatchEventUsingWindowDispatcher(&press1); 1355 DispatchEventUsingWindowDispatcher(&press1);
1378 EXPECT_TRUE(delegate->tap_down()); 1356 EXPECT_TRUE(delegate->tap_down());
1379 EXPECT_TRUE(delegate->begin()); 1357 EXPECT_TRUE(delegate->begin());
1380 EXPECT_FALSE(delegate->tap_cancel()); 1358 EXPECT_FALSE(delegate->tap_cancel());
1381 1359
1382 // We haven't pressed long enough for a long press to occur 1360 // We haven't pressed long enough for a long press to occur
1383 EXPECT_FALSE(delegate->long_press()); 1361 EXPECT_FALSE(delegate->long_press());
1384 1362
1385 // Wait until the timer runs out 1363 // Wait until the timer runs out
1386 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 1364 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
1387 EXPECT_TRUE(delegate->long_press()); 1365 EXPECT_TRUE(delegate->long_press());
1388 EXPECT_FALSE(delegate->tap_cancel()); 1366 EXPECT_FALSE(delegate->tap_cancel());
1389 1367
1390 delegate->Reset(); 1368 delegate->Reset();
1391 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, 1369 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1392 gfx::Point(101, 201), 1370 kTouchId, tes.Now());
1393 kTouchId,
1394 ui::EventTimeForNow());
1395 DispatchEventUsingWindowDispatcher(&release1); 1371 DispatchEventUsingWindowDispatcher(&release1);
1396 EXPECT_FALSE(delegate->long_press()); 1372 EXPECT_FALSE(delegate->long_press());
1397 1373
1398 // Note the tap cancel isn't dispatched until the release 1374 // Note the tap down isn't cancelled until the release
1399 EXPECT_TRUE(delegate->tap_cancel()); 1375 EXPECT_TRUE(delegate->tap_cancel());
1400 EXPECT_FALSE(delegate->tap());
1401 } 1376 }
1402 1377
1403 // Check that scrolling cancels a long press 1378 // Check that scrolling cancels a long press
1404 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { 1379 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
1405 scoped_ptr<GestureEventConsumeDelegate> delegate( 1380 scoped_ptr<GestureEventConsumeDelegate> delegate(
1406 new GestureEventConsumeDelegate()); 1381 new GestureEventConsumeDelegate());
1407 TimedEvents tes; 1382 TimedEvents tes;
1408 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); 1383 ui::GestureConfiguration::set_long_press_time_in_seconds(.01);
1409 const int kWindowWidth = 123; 1384 const int kWindowWidth = 123;
1410 const int kWindowHeight = 45; 1385 const int kWindowHeight = 45;
1411 const int kTouchId = 6; 1386 const int kTouchId = 6;
1412 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1387 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1413 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1388 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1414 delegate.get(), -1234, bounds, root_window())); 1389 delegate.get(), -1234, bounds, root_window()));
(...skipping 26 matching lines...) Expand all
1441 1416
1442 delegate->Reset(); 1417 delegate->Reset();
1443 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1418 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1444 kTouchId, tes.LeapForward(10)); 1419 kTouchId, tes.LeapForward(10));
1445 DispatchEventUsingWindowDispatcher(&release1); 1420 DispatchEventUsingWindowDispatcher(&release1);
1446 EXPECT_FALSE(delegate->long_press()); 1421 EXPECT_FALSE(delegate->long_press());
1447 EXPECT_FALSE(delegate->tap_cancel()); 1422 EXPECT_FALSE(delegate->tap_cancel());
1448 } 1423 }
1449 1424
1450 // Check that appropriate touch events generate long tap events 1425 // Check that appropriate touch events generate long tap events
1451 TEST_P(GestureRecognizerTest, GestureEventLongTap) { 1426 TEST_F(GestureRecognizerTest, GestureEventLongTap) {
1452 scoped_ptr<GestureEventConsumeDelegate> delegate( 1427 scoped_ptr<GestureEventConsumeDelegate> delegate(
1453 new GestureEventConsumeDelegate()); 1428 new GestureEventConsumeDelegate());
1429 TimedEvents tes;
1454 const int kWindowWidth = 123; 1430 const int kWindowWidth = 123;
1455 const int kWindowHeight = 45; 1431 const int kWindowHeight = 45;
1456 const int kTouchId = 2; 1432 const int kTouchId = 2;
1457 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1433 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1458 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1434 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1459 delegate.get(), -1234, bounds, root_window())); 1435 delegate.get(), -1234, bounds, root_window()));
1460 1436
1461 delegate->Reset(); 1437 delegate->Reset();
1462 1438
1463 TimerTestGestureRecognizer* gesture_recognizer = 1439 TimerTestGestureRecognizer* gesture_recognizer =
1464 new TimerTestGestureRecognizer(); 1440 new TimerTestGestureRecognizer();
1465 1441
1466 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 1442 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
1467 1443
1468 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, 1444 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1469 gfx::Point(101, 201), 1445 kTouchId, tes.Now());
1470 kTouchId,
1471 ui::EventTimeForNow());
1472 DispatchEventUsingWindowDispatcher(&press1); 1446 DispatchEventUsingWindowDispatcher(&press1);
1473 EXPECT_TRUE(delegate->tap_down()); 1447 EXPECT_TRUE(delegate->tap_down());
1474 EXPECT_TRUE(delegate->begin()); 1448 EXPECT_TRUE(delegate->begin());
1475 EXPECT_FALSE(delegate->tap_cancel()); 1449 EXPECT_FALSE(delegate->tap_cancel());
1476 1450
1477 // We haven't pressed long enough for a long press to occur 1451 // We haven't pressed long enough for a long press to occur
1478 EXPECT_FALSE(delegate->long_press()); 1452 EXPECT_FALSE(delegate->long_press());
1479 1453
1480 // Wait until the timer runs out 1454 // Wait until the timer runs out
1481 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 1455 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
1482 EXPECT_TRUE(delegate->long_press()); 1456 EXPECT_TRUE(delegate->long_press());
1483 EXPECT_FALSE(delegate->tap_cancel()); 1457 EXPECT_FALSE(delegate->tap_cancel());
1484 1458
1485 delegate->Reset(); 1459 delegate->Reset();
1486 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, 1460 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1487 gfx::Point(101, 201), 1461 kTouchId, tes.Now());
1488 kTouchId,
1489 ui::EventTimeForNow());
1490 DispatchEventUsingWindowDispatcher(&release1); 1462 DispatchEventUsingWindowDispatcher(&release1);
1491 EXPECT_FALSE(delegate->long_press()); 1463 EXPECT_FALSE(delegate->long_press());
1492 EXPECT_TRUE(delegate->long_tap()); 1464 EXPECT_TRUE(delegate->long_tap());
1493 1465
1494 // Note the tap cancel isn't dispatched until the release 1466 // Note the tap down isn't cancelled until the release
1495 EXPECT_TRUE(delegate->tap_cancel()); 1467 EXPECT_TRUE(delegate->tap_cancel());
1496 EXPECT_FALSE(delegate->tap());
1497 } 1468 }
1498 1469
1499 // Check that second tap cancels a long press 1470 // Check that second tap cancels a long press
1500 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { 1471 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
1501 // TODO(tdresser): enable this test with unified GR once two finger tap is
1502 // supported. See crbug.com/354396.
1503 if (UsingUnifiedGR())
1504 return;
1505
1506 scoped_ptr<GestureEventConsumeDelegate> delegate( 1472 scoped_ptr<GestureEventConsumeDelegate> delegate(
1507 new GestureEventConsumeDelegate()); 1473 new GestureEventConsumeDelegate());
1508 TimedEvents tes; 1474 TimedEvents tes;
1509 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); 1475 ui::GestureConfiguration::set_long_press_time_in_seconds(.01);
1510 const int kWindowWidth = 300; 1476 const int kWindowWidth = 300;
1511 const int kWindowHeight = 400; 1477 const int kWindowHeight = 400;
1512 const int kTouchId1 = 8; 1478 const int kTouchId1 = 8;
1513 const int kTouchId2 = 2; 1479 const int kTouchId2 = 2;
1514 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1480 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1515 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1481 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1518 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1553 kTouchId1, tes.Now()); 1519 kTouchId1, tes.Now());
1554 DispatchEventUsingWindowDispatcher(&release1); 1520 DispatchEventUsingWindowDispatcher(&release1);
1555 EXPECT_FALSE(delegate->long_press()); 1521 EXPECT_FALSE(delegate->long_press());
1556 EXPECT_TRUE(delegate->two_finger_tap()); 1522 EXPECT_TRUE(delegate->two_finger_tap());
1557 EXPECT_FALSE(delegate->tap_cancel()); 1523 EXPECT_FALSE(delegate->tap_cancel());
1558 } 1524 }
1559 1525
1560 // Check that horizontal scroll gestures cause scrolls on horizontal rails. 1526 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1561 // Also tests that horizontal rails can be broken. 1527 // Also tests that horizontal rails can be broken.
1562 TEST_P(GestureRecognizerTest, GestureEventHorizontalRailScroll) { 1528 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
1563 scoped_ptr<GestureEventConsumeDelegate> delegate( 1529 scoped_ptr<GestureEventConsumeDelegate> delegate(
1564 new GestureEventConsumeDelegate()); 1530 new GestureEventConsumeDelegate());
1565 TimedEvents tes; 1531 TimedEvents tes;
1566 const int kTouchId = 7; 1532 const int kTouchId = 7;
1567 gfx::Rect bounds(0, 0, 1000, 1000); 1533 gfx::Rect bounds(0, 0, 1000, 1000);
1568 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1534 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1569 delegate.get(), -1234, bounds, root_window())); 1535 delegate.get(), -1234, bounds, root_window()));
1570 1536
1571 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1537 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1572 kTouchId, tes.Now()); 1538 kTouchId, tes.Now());
1573 DispatchEventUsingWindowDispatcher(&press); 1539 DispatchEventUsingWindowDispatcher(&press);
1574 1540
1575 // Get rid of touch slop. 1541 // Get rid of touch slop.
1576 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0), 1542 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0),
1577 kTouchId, tes.Now()); 1543 kTouchId, tes.Now());
1578 1544
1579 DispatchEventUsingWindowDispatcher(&move); 1545 DispatchEventUsingWindowDispatcher(&move);
1580 delegate->Reset(); 1546 delegate->Reset();
1581 1547
1582 // Move the touch-point horizontally enough that it is considered a 1548 // Move the touch-point horizontally enough that it is considered a
1583 // horizontal scroll. 1549 // horizontal scroll.
1584 tes.SendScrollEvent(event_processor(), 25, 0, kTouchId, delegate.get()); 1550 tes.SendScrollEvent(event_processor(), 25, 1, kTouchId, delegate.get());
1585 EXPECT_EQ(0, delegate->scroll_y()); 1551 EXPECT_EQ(0, delegate->scroll_y());
1586 EXPECT_EQ(20, delegate->scroll_x()); 1552 EXPECT_EQ(20, delegate->scroll_x());
1587 1553
1588 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get()); 1554 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get());
1589 EXPECT_TRUE(delegate->scroll_update()); 1555 EXPECT_TRUE(delegate->scroll_update());
1590 EXPECT_EQ(5, delegate->scroll_x()); 1556 EXPECT_EQ(5, delegate->scroll_x());
1591 // y shouldn't change, as we're on a horizontal rail. 1557 // y shouldn't change, as we're on a horizontal rail.
1592 EXPECT_EQ(0, delegate->scroll_y()); 1558 EXPECT_EQ(0, delegate->scroll_y());
1593 1559
1594 // Send enough information that a velocity can be calculated for the gesture, 1560 // Send enough information that a velocity can be calculated for the gesture,
1595 // and we can break the rail 1561 // and we can break the rail
1596 tes.SendScrollEvents(event_processor(), 1, 1, 1562 tes.SendScrollEvents(event_processor(), 1, 1,
1597 6, 100, kTouchId, 1, 1563 6, 100, kTouchId, 1,
1598 ui::GestureConfiguration::points_buffered_for_velocity(), 1564 ui::GestureConfiguration::points_buffered_for_velocity(),
1599 delegate.get()); 1565 delegate.get());
1600 1566
1601 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get()); 1567 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get());
1602 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get()); 1568 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get());
1603 1569
1604 // The rail should be broken 1570 // The rail should be broken
1605 EXPECT_TRUE(delegate->scroll_update()); 1571 EXPECT_TRUE(delegate->scroll_update());
1606 EXPECT_EQ(5, delegate->scroll_x()); 1572 EXPECT_EQ(5, delegate->scroll_x());
1607 EXPECT_EQ(5, delegate->scroll_y()); 1573 EXPECT_EQ(5, delegate->scroll_y());
1608 } 1574 }
1609 1575
1610 // Check that vertical scroll gestures cause scrolls on vertical rails. 1576 // Check that vertical scroll gestures cause scrolls on vertical rails.
1611 // Also tests that vertical rails can be broken. 1577 // Also tests that vertical rails can be broken.
1612 TEST_P(GestureRecognizerTest, GestureEventVerticalRailScroll) { 1578 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
1613 scoped_ptr<GestureEventConsumeDelegate> delegate( 1579 scoped_ptr<GestureEventConsumeDelegate> delegate(
1614 new GestureEventConsumeDelegate()); 1580 new GestureEventConsumeDelegate());
1615 TimedEvents tes; 1581 TimedEvents tes;
1616 const int kTouchId = 7; 1582 const int kTouchId = 7;
1617 gfx::Rect bounds(0, 0, 1000, 1000); 1583 gfx::Rect bounds(0, 0, 1000, 1000);
1618 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1584 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1619 delegate.get(), -1234, bounds, root_window())); 1585 delegate.get(), -1234, bounds, root_window()));
1620 1586
1621 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1587 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1622 kTouchId, tes.Now()); 1588 kTouchId, tes.Now());
1623 DispatchEventUsingWindowDispatcher(&press); 1589 DispatchEventUsingWindowDispatcher(&press);
1624 1590
1625 // Get rid of touch slop. 1591 // Get rid of touch slop.
1626 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5), 1592 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5),
1627 kTouchId, tes.Now()); 1593 kTouchId, tes.Now());
1628 DispatchEventUsingWindowDispatcher(&move); 1594 DispatchEventUsingWindowDispatcher(&move);
1629 delegate->Reset(); 1595 delegate->Reset();
1630 1596
1631 // Move the touch-point vertically enough that it is considered a 1597 // Move the touch-point vertically enough that it is considered a
1632 // vertical scroll. 1598 // vertical scroll.
1633 tes.SendScrollEvent(event_processor(), 0, 25, kTouchId, delegate.get()); 1599 tes.SendScrollEvent(event_processor(), 1, 25, kTouchId, delegate.get());
1634 EXPECT_EQ(0, delegate->scroll_x()); 1600 EXPECT_EQ(0, delegate->scroll_x());
1635 EXPECT_EQ(20, delegate->scroll_y()); 1601 EXPECT_EQ(20, delegate->scroll_y());
1636 1602
1637 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get()); 1603 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get());
1638 EXPECT_TRUE(delegate->scroll_update()); 1604 EXPECT_TRUE(delegate->scroll_update());
1639 EXPECT_EQ(5, delegate->scroll_y()); 1605 EXPECT_EQ(5, delegate->scroll_y());
1640 // x shouldn't change, as we're on a vertical rail. 1606 // x shouldn't change, as we're on a vertical rail.
1641 EXPECT_EQ(0, delegate->scroll_x()); 1607 EXPECT_EQ(0, delegate->scroll_x());
1642 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1608 EXPECT_EQ(0, delegate->scroll_velocity_x());
1643 1609
1644 // Send enough information that a velocity can be calculated for the gesture, 1610 // Send enough information that a velocity can be calculated for the gesture,
1645 // and we can break the rail 1611 // and we can break the rail
1646 tes.SendScrollEvents(event_processor(), 1, 6, 1612 tes.SendScrollEvents(event_processor(), 1, 6,
1647 100, 1, kTouchId, 1, 1613 100, 1, kTouchId, 1,
1648 ui::GestureConfiguration::points_buffered_for_velocity(), 1614 ui::GestureConfiguration::points_buffered_for_velocity(),
1649 delegate.get()); 1615 delegate.get());
1650 1616
1651 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get()); 1617 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get());
1652 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get()); 1618 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get());
1653 1619
1654 // The rail should be broken 1620 // The rail should be broken
1655 EXPECT_TRUE(delegate->scroll_update()); 1621 EXPECT_TRUE(delegate->scroll_update());
1656 EXPECT_EQ(5, delegate->scroll_x()); 1622 EXPECT_EQ(5, delegate->scroll_x());
1657 EXPECT_EQ(5, delegate->scroll_y()); 1623 EXPECT_EQ(5, delegate->scroll_y());
1658 } 1624 }
1659 1625
1660 TEST_P(GestureRecognizerTest, GestureTapFollowedByScroll) { 1626 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
1661 // We'll start by moving the touch point by (5, 5). We want all of that 1627 // We'll start by moving the touch point by (5, 5). We want all of that
1662 // distance to be consumed by the slop, so we set the slop radius to 1628 // distance to be consumed by the slop, so we set the slop radius to
1663 // sqrt(5 * 5 + 5 * 5). 1629 // sqrt(5 * 5 + 5 * 5).
1664 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( 1630 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1665 sqrt(static_cast<double>(5 * 5 + 5 * 5))); 1631 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1666 1632
1667 // First, tap. Then, do a scroll using the same touch-id. 1633 // First, tap. Then, do a scroll using the same touch-id.
1668 scoped_ptr<GestureEventConsumeDelegate> delegate( 1634 scoped_ptr<GestureEventConsumeDelegate> delegate(
1669 new GestureEventConsumeDelegate()); 1635 new GestureEventConsumeDelegate());
1670 TimedEvents tes; 1636 TimedEvents tes;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 kTouchId, tes.LeapForward(1000)); 1672 kTouchId, tes.LeapForward(1000));
1707 DispatchEventUsingWindowDispatcher(&press1); 1673 DispatchEventUsingWindowDispatcher(&press1);
1708 EXPECT_FALSE(delegate->tap()); 1674 EXPECT_FALSE(delegate->tap());
1709 EXPECT_TRUE(delegate->tap_down()); 1675 EXPECT_TRUE(delegate->tap_down());
1710 EXPECT_FALSE(delegate->tap_cancel()); 1676 EXPECT_FALSE(delegate->tap_cancel());
1711 EXPECT_FALSE(delegate->scroll_begin()); 1677 EXPECT_FALSE(delegate->scroll_begin());
1712 EXPECT_FALSE(delegate->scroll_update()); 1678 EXPECT_FALSE(delegate->scroll_update());
1713 EXPECT_FALSE(delegate->scroll_end()); 1679 EXPECT_FALSE(delegate->scroll_end());
1714 1680
1715 // Get rid of touch slop. 1681 // Get rid of touch slop.
1716 ui::TouchEvent move_remove_slop(ui::ET_TOUCH_MOVED, gfx::Point(116, 216), 1682 ui::TouchEvent move_remove_slop(ui::ET_TOUCH_MOVED, gfx::Point(106, 206),
1717 kTouchId, tes.Now()); 1683 kTouchId, tes.Now());
1718 DispatchEventUsingWindowDispatcher(&move_remove_slop); 1684 DispatchEventUsingWindowDispatcher(&move_remove_slop);
1719 EXPECT_TRUE(delegate->tap_cancel()); 1685 EXPECT_TRUE(delegate->tap_cancel());
1720 EXPECT_TRUE(delegate->scroll_begin()); 1686 EXPECT_TRUE(delegate->scroll_begin());
1721 EXPECT_TRUE(delegate->scroll_update()); 1687 EXPECT_FALSE(delegate->scroll_update());
1722 EXPECT_EQ(15, delegate->scroll_x_hint()); 1688 EXPECT_EQ(5, delegate->scroll_x_hint());
1723 EXPECT_EQ(15, delegate->scroll_y_hint()); 1689 EXPECT_EQ(5, delegate->scroll_y_hint());
1724 1690
1725 delegate->Reset(); 1691 delegate->Reset();
1726 1692
1727 // Move the touch-point enough so that it is considered as a scroll. This 1693 // Move the touch-point enough so that it is considered as a scroll. This
1728 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1694 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1729 // The first movement is diagonal, to ensure that we have a free scroll, 1695 // The first movement is diagonal, to ensure that we have a free scroll,
1730 // and not a rail scroll. 1696 // and not a rail scroll.
1731 delegate->Reset(); 1697 delegate->Reset();
1732 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(135, 235), 1698 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(135, 235),
1733 kTouchId, tes.Now()); 1699 kTouchId, tes.Now());
1734 DispatchEventUsingWindowDispatcher(&move); 1700 DispatchEventUsingWindowDispatcher(&move);
1735 EXPECT_FALSE(delegate->tap()); 1701 EXPECT_FALSE(delegate->tap());
1736 EXPECT_FALSE(delegate->tap_down()); 1702 EXPECT_FALSE(delegate->tap_down());
1737 EXPECT_FALSE(delegate->tap_cancel()); 1703 EXPECT_FALSE(delegate->tap_cancel());
1738 EXPECT_FALSE(delegate->scroll_begin()); 1704 EXPECT_FALSE(delegate->scroll_begin());
1739 EXPECT_TRUE(delegate->scroll_update()); 1705 EXPECT_TRUE(delegate->scroll_update());
1740 EXPECT_FALSE(delegate->scroll_end()); 1706 EXPECT_FALSE(delegate->scroll_end());
1741 EXPECT_EQ(19, delegate->scroll_x()); 1707 EXPECT_EQ(29, delegate->scroll_x());
1742 EXPECT_EQ(19, delegate->scroll_y()); 1708 EXPECT_EQ(29, delegate->scroll_y());
1743 1709
1744 // Move some more to generate a few more scroll updates. 1710 // Move some more to generate a few more scroll updates.
1745 delegate->Reset(); 1711 delegate->Reset();
1746 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(115, 216), 1712 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(115, 216),
1747 kTouchId, tes.Now()); 1713 kTouchId, tes.Now());
1748 DispatchEventUsingWindowDispatcher(&move1); 1714 DispatchEventUsingWindowDispatcher(&move1);
1749 EXPECT_FALSE(delegate->tap()); 1715 EXPECT_FALSE(delegate->tap());
1750 EXPECT_FALSE(delegate->tap_down()); 1716 EXPECT_FALSE(delegate->tap_down());
1751 EXPECT_FALSE(delegate->tap_cancel()); 1717 EXPECT_FALSE(delegate->tap_cancel());
1752 EXPECT_FALSE(delegate->scroll_begin()); 1718 EXPECT_FALSE(delegate->scroll_begin());
(...skipping 24 matching lines...) Expand all
1777 DispatchEventUsingWindowDispatcher(&release1); 1743 DispatchEventUsingWindowDispatcher(&release1);
1778 EXPECT_FALSE(delegate->tap()); 1744 EXPECT_FALSE(delegate->tap());
1779 EXPECT_FALSE(delegate->tap_down()); 1745 EXPECT_FALSE(delegate->tap_down());
1780 EXPECT_FALSE(delegate->tap_cancel()); 1746 EXPECT_FALSE(delegate->tap_cancel());
1781 EXPECT_FALSE(delegate->scroll_begin()); 1747 EXPECT_FALSE(delegate->scroll_begin());
1782 EXPECT_FALSE(delegate->scroll_update()); 1748 EXPECT_FALSE(delegate->scroll_update());
1783 EXPECT_FALSE(delegate->scroll_end()); 1749 EXPECT_FALSE(delegate->scroll_end());
1784 EXPECT_TRUE(delegate->fling()); 1750 EXPECT_TRUE(delegate->fling());
1785 } 1751 }
1786 1752
1787 TEST_P(GestureRecognizerTest, AsynchronousGestureRecognition) { 1753 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
1788 // TODO(tdresser): enable this test with unified GR once two finger tap is
1789 // supported. See crbug.com/354396.
1790 if (UsingUnifiedGR())
1791 return;
1792 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 1754 scoped_ptr<QueueTouchEventDelegate> queued_delegate(
1793 new QueueTouchEventDelegate(host()->dispatcher())); 1755 new QueueTouchEventDelegate(host()->dispatcher()));
1794 const int kWindowWidth = 123; 1756 const int kWindowWidth = 123;
1795 const int kWindowHeight = 45; 1757 const int kWindowHeight = 45;
1796 const int kTouchId1 = 6; 1758 const int kTouchId1 = 6;
1797 const int kTouchId2 = 4; 1759 const int kTouchId2 = 4;
1798 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1760 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1799 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 1761 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
1800 queued_delegate.get(), -1234, bounds, root_window())); 1762 queued_delegate.get(), -1234, bounds, root_window()));
1801 1763
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 EXPECT_FALSE(queued_delegate->end()); 1935 EXPECT_FALSE(queued_delegate->end());
1974 EXPECT_TRUE(queued_delegate->scroll_begin()); 1936 EXPECT_TRUE(queued_delegate->scroll_begin());
1975 EXPECT_FALSE(queued_delegate->scroll_update()); 1937 EXPECT_FALSE(queued_delegate->scroll_update());
1976 EXPECT_FALSE(queued_delegate->scroll_end()); 1938 EXPECT_FALSE(queued_delegate->scroll_end());
1977 EXPECT_TRUE(queued_delegate->pinch_begin()); 1939 EXPECT_TRUE(queued_delegate->pinch_begin());
1978 EXPECT_FALSE(queued_delegate->pinch_update()); 1940 EXPECT_FALSE(queued_delegate->pinch_update());
1979 EXPECT_FALSE(queued_delegate->pinch_end()); 1941 EXPECT_FALSE(queued_delegate->pinch_end());
1980 } 1942 }
1981 1943
1982 // Check that appropriate touch events generate pinch gesture events. 1944 // Check that appropriate touch events generate pinch gesture events.
1983 TEST_P(GestureRecognizerTest, GestureEventPinchFromScroll) { 1945 TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) {
1984 // Disabled for unified GR due to differences in when pinch begin is sent. The
1985 // Aura GR sends it earlier than is necessary.
1986 if (UsingUnifiedGR())
1987 return;
1988
1989 scoped_ptr<GestureEventConsumeDelegate> delegate( 1946 scoped_ptr<GestureEventConsumeDelegate> delegate(
1990 new GestureEventConsumeDelegate()); 1947 new GestureEventConsumeDelegate());
1991 TimedEvents tes; 1948 TimedEvents tes;
1992 const int kWindowWidth = 300; 1949 const int kWindowWidth = 300;
1993 const int kWindowHeight = 400; 1950 const int kWindowHeight = 400;
1994 const int kTouchId1 = 5; 1951 const int kTouchId1 = 5;
1995 const int kTouchId2 = 3; 1952 const int kTouchId2 = 3;
1996 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1953 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1997 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1954 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1998 delegate.get(), -1234, bounds, root_window())); 1955 delegate.get(), -1234, bounds, root_window()));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2020
2064 // Move the second finger. This should still generate a scroll. 2021 // Move the second finger. This should still generate a scroll.
2065 delegate->Reset(); 2022 delegate->Reset();
2066 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 2023 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
2067 kTouchId2, tes.Now()); 2024 kTouchId2, tes.Now());
2068 DispatchEventUsingWindowDispatcher(&move5); 2025 DispatchEventUsingWindowDispatcher(&move5);
2069 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 2026 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
2070 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2027 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
2071 } 2028 }
2072 2029
2073 TEST_P(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { 2030 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
2074 scoped_ptr<GestureEventConsumeDelegate> delegate( 2031 scoped_ptr<GestureEventConsumeDelegate> delegate(
2075 new GestureEventConsumeDelegate()); 2032 new GestureEventConsumeDelegate());
2076 TimedEvents tes; 2033 TimedEvents tes;
2077 const int kWindowWidth = 300; 2034 const int kWindowWidth = 300;
2078 const int kWindowHeight = 400; 2035 const int kWindowHeight = 400;
2079 const int kTouchId1 = 5; 2036 const int kTouchId1 = 5;
2080 const int kTouchId2 = 3; 2037 const int kTouchId2 = 3;
2081 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 2038 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
2082 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2039 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2083 delegate.get(), -1234, bounds, root_window())); 2040 delegate.get(), -1234, bounds, root_window()));
(...skipping 27 matching lines...) Expand all
2111 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId2, delegate.get()); 2068 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId2, delegate.get());
2112 EXPECT_TRUE(delegate->scroll_update()); 2069 EXPECT_TRUE(delegate->scroll_update());
2113 2070
2114 // Pinch again 2071 // Pinch again
2115 delegate->Reset(); 2072 delegate->Reset();
2116 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2073 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
2117 kTouchId1, tes.Now()); 2074 kTouchId1, tes.Now());
2118 DispatchEventUsingWindowDispatcher(&press3); 2075 DispatchEventUsingWindowDispatcher(&press3);
2119 // Now the touch points are close. So we will go into two finger tap. 2076 // Now the touch points are close. So we will go into two finger tap.
2120 // Move the touch-point enough to break two-finger-tap and enter pinch. 2077 // Move the touch-point enough to break two-finger-tap and enter pinch.
2121 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50), 2078 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202),
2122 kTouchId1, tes.Now()); 2079 kTouchId1, tes.Now());
2123 DispatchEventUsingWindowDispatcher(&move2); 2080 DispatchEventUsingWindowDispatcher(&move2);
2124 EXPECT_TRUE(delegate->pinch_begin()); 2081 EXPECT_TRUE(delegate->pinch_begin());
2125 2082
2126 tes.SendScrollEvent(event_processor(), 300, 300, kTouchId1, delegate.get()); 2083 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId1, delegate.get());
2127 EXPECT_TRUE(delegate->pinch_update()); 2084 EXPECT_TRUE(delegate->pinch_update());
2128 } 2085 }
2129 2086
2130 TEST_P(GestureRecognizerTest, GestureEventPinchFromTap) { 2087 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
2131 // TODO(tdresser): enable this test with unified GR once two finger tap.
2132 if (UsingUnifiedGR())
2133 return;
2134
2135 scoped_ptr<GestureEventConsumeDelegate> delegate( 2088 scoped_ptr<GestureEventConsumeDelegate> delegate(
2136 new GestureEventConsumeDelegate()); 2089 new GestureEventConsumeDelegate());
2137 TimedEvents tes; 2090 TimedEvents tes;
2138 const int kWindowWidth = 300; 2091 const int kWindowWidth = 300;
2139 const int kWindowHeight = 400; 2092 const int kWindowHeight = 400;
2140 const int kTouchId1 = 3; 2093 const int kTouchId1 = 3;
2141 const int kTouchId2 = 5; 2094 const int kTouchId2 = 5;
2142 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 2095 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
2143 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2096 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2144 delegate.get(), -1234, bounds, root_window())); 2097 delegate.get(), -1234, bounds, root_window()));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 2151
2199 // Move the second finger. This should still generate a scroll. 2152 // Move the second finger. This should still generate a scroll.
2200 delegate->Reset(); 2153 delegate->Reset();
2201 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 2154 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
2202 kTouchId2, tes.Now()); 2155 kTouchId2, tes.Now());
2203 DispatchEventUsingWindowDispatcher(&move5); 2156 DispatchEventUsingWindowDispatcher(&move5);
2204 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 2157 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
2205 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2158 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
2206 } 2159 }
2207 2160
2208 TEST_P(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { 2161 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
2209 scoped_ptr<GestureEventConsumeDelegate> delegate( 2162 scoped_ptr<GestureEventConsumeDelegate> delegate(
2210 new GestureEventConsumeDelegate()); 2163 new GestureEventConsumeDelegate());
2211 TimedEvents tes; 2164 TimedEvents tes;
2212 2165
2213 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2166 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2214 6, tes.Now()); 2167 6, tes.Now());
2215 DispatchEventUsingWindowDispatcher(&release1); 2168 DispatchEventUsingWindowDispatcher(&release1);
2216 EXPECT_FALSE(delegate->tap()); 2169 EXPECT_FALSE(delegate->tap());
2217 EXPECT_FALSE(delegate->tap_down()); 2170 EXPECT_FALSE(delegate->tap_down());
2218 } 2171 }
2219 2172
2220 // Check that a touch is locked to the window of the closest current touch 2173 // Check that a touch is locked to the window of the closest current touch
2221 // within max_separation_for_gesture_touches_in_pixels 2174 // within max_separation_for_gesture_touches_in_pixels
2222 TEST_P(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { 2175 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
2223 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl(); 2176 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl();
2224 TimedEvents tes; 2177 TimedEvents tes;
2225 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2178 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2226 2179
2227 ui::GestureConsumer* target; 2180 ui::GestureConsumer* target;
2228 const int kNumWindows = 4; 2181 const int kNumWindows = 4;
2229 2182
2230 scoped_ptr<GestureEventConsumeDelegate*[]> delegates( 2183 scoped_ptr<GestureEventConsumeDelegate*[]> delegates(
2231 new GestureEventConsumeDelegate*[kNumWindows]); 2184 new GestureEventConsumeDelegate*[kNumWindows]);
2232 2185
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 2251
2299 for (int i = 0; i < kNumWindows; ++i) { 2252 for (int i = 0; i < kNumWindows; ++i) {
2300 // Delete windows before deleting delegates. 2253 // Delete windows before deleting delegates.
2301 delete windows[i]; 2254 delete windows[i];
2302 delete delegates[i]; 2255 delete delegates[i];
2303 } 2256 }
2304 } 2257 }
2305 2258
2306 // Check that a touch's target will not be effected by a touch on a different 2259 // Check that a touch's target will not be effected by a touch on a different
2307 // screen. 2260 // screen.
2308 TEST_P(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) { 2261 TEST_F(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) {
2309 scoped_ptr<GestureEventConsumeDelegate> delegate( 2262 scoped_ptr<GestureEventConsumeDelegate> delegate(
2310 new GestureEventConsumeDelegate()); 2263 new GestureEventConsumeDelegate());
2311 gfx::Rect bounds(0, 0, 10, 10); 2264 gfx::Rect bounds(0, 0, 10, 10);
2312 scoped_ptr<aura::Window> window( 2265 scoped_ptr<aura::Window> window(
2313 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); 2266 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
2314 2267
2315 const int kTouchId1 = 8; 2268 const int kTouchId1 = 8;
2316 const int kTouchId2 = 2; 2269 const int kTouchId2 = 2;
2317 TimedEvents tes; 2270 TimedEvents tes;
2318 2271
2319 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5), 2272 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5),
2320 kTouchId1, tes.Now()); 2273 kTouchId1, tes.Now());
2321 press1.set_source_device_id(1); 2274 press1.set_source_device_id(1);
2322 DispatchEventUsingWindowDispatcher(&press1); 2275 DispatchEventUsingWindowDispatcher(&press1);
2323 2276
2324 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2277 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2325 kTouchId2, tes.Now()); 2278 kTouchId2, tes.Now());
2326 press2.set_source_device_id(2); 2279 press2.set_source_device_id(2);
2327 DispatchEventUsingWindowDispatcher(&press2); 2280 DispatchEventUsingWindowDispatcher(&press2);
2328 2281
2329 // The second press should not have been locked to the same target as the 2282 // The second press should not have been locked to the same target as the
2330 // first, as they occured on different displays. 2283 // first, as they occured on different displays.
2331 EXPECT_NE( 2284 EXPECT_NE(
2332 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1), 2285 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1),
2333 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)); 2286 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
2334 } 2287 }
2335 2288
2336 // Check that touch events outside the root window are still handled 2289 // Check that touch events outside the root window are still handled
2337 // by the root window's gesture sequence. 2290 // by the root window's gesture sequence.
2338 TEST_P(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { 2291 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
2339 // TODO(tdresser): write a version of this test for the unified GR.
2340 if (UsingUnifiedGR())
2341 return;
2342
2343 TestGestureRecognizer* gesture_recognizer = 2292 TestGestureRecognizer* gesture_recognizer =
2344 new TestGestureRecognizer(); 2293 new TestGestureRecognizer();
2345 TimedEvents tes; 2294 TimedEvents tes;
2346 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2295 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2347 2296
2348 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( 2297 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds(
2349 gfx::Rect(-100, -100, 2000, 2000), root_window())); 2298 gfx::Rect(-100, -100, 2000, 2000), root_window()));
2350 2299
2351 ui::GestureSequence* window_gesture_sequence = 2300 ui::GestureSequence* window_gesture_sequence =
2352 gesture_recognizer->GetGestureSequenceForTesting(window.get()); 2301 gesture_recognizer->GetGestureSequenceForTesting(window.get());
2353 2302
2354 ui::GestureSequence* root_window_gesture_sequence = 2303 ui::GestureSequence* root_window_gesture_sequence =
2355 gesture_recognizer->GetGestureSequenceForTesting(root_window()); 2304 gesture_recognizer->GetGestureSequenceForTesting(root_window());
2356 2305
2357 gfx::Point pos1(-10, -10); 2306 gfx::Point pos1(-10, -10);
2358 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now()); 2307 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now());
2359 DispatchEventUsingWindowDispatcher(&press1); 2308 DispatchEventUsingWindowDispatcher(&press1);
2360 2309
2361 gfx::Point pos2(1000, 1000); 2310 gfx::Point pos2(1000, 1000);
2362 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, tes.Now()); 2311 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, tes.Now());
2363 DispatchEventUsingWindowDispatcher(&press2); 2312 DispatchEventUsingWindowDispatcher(&press2);
2364 2313
2365 // As these presses were outside the root window, they should be 2314 // As these presses were outside the root window, they should be
2366 // associated with the root window. 2315 // associated with the root window.
2367 EXPECT_EQ(0, window_gesture_sequence->point_count()); 2316 EXPECT_EQ(0, window_gesture_sequence->point_count());
2368 EXPECT_EQ(2, root_window_gesture_sequence->point_count()); 2317 EXPECT_EQ(2, root_window_gesture_sequence->point_count());
2369 } 2318 }
2370 2319
2371 TEST_P(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { 2320 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
2372 scoped_ptr<QueueTouchEventDelegate> delegate( 2321 scoped_ptr<QueueTouchEventDelegate> delegate(
2373 new QueueTouchEventDelegate(host()->dispatcher())); 2322 new QueueTouchEventDelegate(host()->dispatcher()));
2374 TimedEvents tes; 2323 TimedEvents tes;
2375 const int kTouchId = 2; 2324 const int kTouchId = 2;
2376 gfx::Rect bounds(100, 200, 100, 100); 2325 gfx::Rect bounds(100, 200, 100, 100);
2377 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2326 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2378 delegate.get(), -1234, bounds, root_window())); 2327 delegate.get(), -1234, bounds, root_window()));
2379 delegate->set_window(window.get()); 2328 delegate->set_window(window.get());
2380 2329
2381 delegate->Reset(); 2330 delegate->Reset();
2382 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2331 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2383 kTouchId, tes.Now()); 2332 kTouchId, tes.Now());
2384 DispatchEventUsingWindowDispatcher(&press); 2333 DispatchEventUsingWindowDispatcher(&press);
2385 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2334 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2386 kTouchId, tes.LeapForward(50)); 2335 kTouchId, tes.LeapForward(50));
2387 DispatchEventUsingWindowDispatcher(&release); 2336 DispatchEventUsingWindowDispatcher(&release);
2388 2337
2389 delegate->Reset(); 2338 delegate->Reset();
2390 delegate->ReceivedAck(); 2339 delegate->ReceivedAck();
2391 EXPECT_TRUE(delegate->tap_down()); 2340 EXPECT_TRUE(delegate->tap_down());
2392 delegate->Reset(); 2341 delegate->Reset();
2393 delegate->ReceivedAckPreventDefaulted(); 2342 delegate->ReceivedAckPreventDefaulted();
2394 EXPECT_FALSE(delegate->tap()); 2343 EXPECT_FALSE(delegate->tap());
2395 EXPECT_TRUE(delegate->tap_cancel()); 2344 EXPECT_TRUE(delegate->tap_cancel());
2396 } 2345 }
2397 2346
2398 TEST_P(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) { 2347 TEST_F(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) {
2399 // Disabled for unified GR due to differences in when pinch begin is sent. The
2400 // Aura GR sends it earlier than is necessary.
2401 if (UsingUnifiedGR())
2402 return;
2403
2404 scoped_ptr<QueueTouchEventDelegate> delegate( 2348 scoped_ptr<QueueTouchEventDelegate> delegate(
2405 new QueueTouchEventDelegate(host()->dispatcher())); 2349 new QueueTouchEventDelegate(host()->dispatcher()));
2406 TimedEvents tes; 2350 TimedEvents tes;
2407 const int kTouchId1 = 7; 2351 const int kTouchId1 = 7;
2408 const int kTouchId2 = 5; 2352 const int kTouchId2 = 5;
2409 gfx::Rect bounds(10, 20, 100, 100); 2353 gfx::Rect bounds(10, 20, 100, 100);
2410 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2354 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2411 delegate.get(), -1234, bounds, root_window())); 2355 delegate.get(), -1234, bounds, root_window()));
2412 delegate->set_window(window.get()); 2356 delegate->set_window(window.get());
2413 2357
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 delegate->ReceivedAckPreventDefaulted(); 2431 delegate->ReceivedAckPreventDefaulted();
2488 EXPECT_TRUE(delegate->pinch_end()); 2432 EXPECT_TRUE(delegate->pinch_end());
2489 EXPECT_TRUE(delegate->end()); 2433 EXPECT_TRUE(delegate->end());
2490 2434
2491 delegate->Reset(); 2435 delegate->Reset();
2492 delegate->ReceivedAckPreventDefaulted(); 2436 delegate->ReceivedAckPreventDefaulted();
2493 EXPECT_TRUE(delegate->scroll_end()); 2437 EXPECT_TRUE(delegate->scroll_end());
2494 EXPECT_TRUE(delegate->end()); 2438 EXPECT_TRUE(delegate->end());
2495 } 2439 }
2496 2440
2497 TEST_P(GestureRecognizerTest, GestureEndLocation) { 2441 TEST_F(GestureRecognizerTest, GestureEndLocation) {
2498 GestureEventConsumeDelegate delegate; 2442 GestureEventConsumeDelegate delegate;
2499 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2443 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2500 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2444 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2501 EventGenerator generator(root_window(), window.get()); 2445 EventGenerator generator(root_window(), window.get());
2502 const gfx::Point begin(20, 20); 2446 const gfx::Point begin(20, 20);
2503 const gfx::Point end(150, 150); 2447 const gfx::Point end(150, 150);
2504 const gfx::Vector2d window_offset = 2448 const gfx::Vector2d window_offset =
2505 window->bounds().origin().OffsetFromOrigin(); 2449 window->bounds().origin().OffsetFromOrigin();
2506 generator.GestureScrollSequence(begin, end, 2450 generator.GestureScrollSequence(begin, end,
2507 base::TimeDelta::FromMilliseconds(20), 2451 base::TimeDelta::FromMilliseconds(20),
2508 10); 2452 10);
2509 EXPECT_EQ((begin - window_offset).ToString(), 2453 EXPECT_EQ((begin - window_offset).ToString(),
2510 delegate.scroll_begin_position().ToString()); 2454 delegate.scroll_begin_position().ToString());
2511 EXPECT_EQ((end - window_offset).ToString(), 2455 EXPECT_EQ((end - window_offset).ToString(),
2512 delegate.gesture_end_location().ToString()); 2456 delegate.gesture_end_location().ToString());
2513 } 2457 }
2514 2458
2515 TEST_P(GestureRecognizerTest, CaptureSendsGestureEnd) { 2459 TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) {
2516 scoped_ptr<GestureEventConsumeDelegate> delegate( 2460 scoped_ptr<GestureEventConsumeDelegate> delegate(
2517 new GestureEventConsumeDelegate()); 2461 new GestureEventConsumeDelegate());
2518 TestGestureRecognizer* gesture_recognizer = 2462 TestGestureRecognizer* gesture_recognizer =
2519 new TestGestureRecognizer(); 2463 new TestGestureRecognizer();
2520 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2464 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2521 2465
2522 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2466 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2523 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2467 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2524 EventGenerator generator(root_window()); 2468 EventGenerator generator(root_window());
2525 2469
2526 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10)); 2470 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10));
2527 generator.PressTouch(); 2471 generator.PressTouch();
2528 RunAllPendingInMessageLoop(); 2472 RunAllPendingInMessageLoop();
2529 2473
2530 EXPECT_TRUE(delegate->tap_down()); 2474 EXPECT_TRUE(delegate->tap_down());
2531 2475
2532 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds( 2476 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds(
2533 gfx::Rect(10, 10, 200, 200), root_window())); 2477 gfx::Rect(10, 10, 200, 200), root_window()));
2534 capture->SetCapture(); 2478 capture->SetCapture();
2535 RunAllPendingInMessageLoop(); 2479 RunAllPendingInMessageLoop();
2536 2480
2537 EXPECT_TRUE(delegate->end()); 2481 EXPECT_TRUE(delegate->end());
2538 EXPECT_TRUE(delegate->tap_cancel()); 2482 EXPECT_TRUE(delegate->tap_cancel());
2539 } 2483 }
2540 2484
2541 // Check that previous touch actions that are completely finished (either 2485 // Check that previous touch actions that are completely finished (either
2542 // released or cancelled), do not receive extra synthetic cancels upon change of 2486 // released or cancelled), do not receive extra synthetic cancels upon change of
2543 // capture. 2487 // capture.
2544 TEST_P(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) { 2488 TEST_F(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) {
2545 scoped_ptr<GestureEventConsumeDelegate> delegate( 2489 scoped_ptr<GestureEventConsumeDelegate> delegate(
2546 new GestureEventConsumeDelegate()); 2490 new GestureEventConsumeDelegate());
2547 scoped_ptr<TestEventHandler> handler(new TestEventHandler); 2491 scoped_ptr<TestEventHandler> handler(new TestEventHandler);
2548 root_window()->AddPreTargetHandler(handler.get()); 2492 root_window()->AddPreTargetHandler(handler.get());
2549 2493
2550 // Create a window and set it as the capture window. 2494 // Create a window and set it as the capture window.
2551 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(delegate.get(), 2495 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(delegate.get(),
2552 -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2496 -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2553 window1->SetCapture(); 2497 window1->SetCapture();
2554 2498
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 gfx::Rect(100, 100, 300, 300), root_window())); 2531 gfx::Rect(100, 100, 300, 300), root_window()));
2588 window2->SetCapture(); 2532 window2->SetCapture();
2589 RunAllPendingInMessageLoop(); 2533 RunAllPendingInMessageLoop();
2590 // Check that setting capture does not generate any synthetic touch-cancels 2534 // Check that setting capture does not generate any synthetic touch-cancels
2591 // for the two previously finished touch actions. 2535 // for the two previously finished touch actions.
2592 EXPECT_EQ(1, handler->touch_cancelled_count()); 2536 EXPECT_EQ(1, handler->touch_cancelled_count());
2593 2537
2594 root_window()->RemovePreTargetHandler(handler.get()); 2538 root_window()->RemovePreTargetHandler(handler.get());
2595 } 2539 }
2596 2540
2597 // Tests that a press with the same touch id as an existing touch is ignored. 2541 TEST_F(GestureRecognizerTest, PressDoesNotCrash) {
2598 TEST_P(GestureRecognizerTest, PressDoesNotCrash) {
2599 scoped_ptr<GestureEventConsumeDelegate> delegate( 2542 scoped_ptr<GestureEventConsumeDelegate> delegate(
2600 new GestureEventConsumeDelegate()); 2543 new GestureEventConsumeDelegate());
2601 TestGestureRecognizer* gesture_recognizer = 2544 TestGestureRecognizer* gesture_recognizer =
2602 new TestGestureRecognizer(); 2545 new TestGestureRecognizer();
2603 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2546 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2604 TimedEvents tes; 2547 TimedEvents tes;
2605 2548
2606 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2549 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2607 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2550 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2608 2551
2609 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, tes.Now()); 2552 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, tes.Now());
2610 press.set_radius_x(40); 2553 press.set_radius_x(40);
2611 DispatchEventUsingWindowDispatcher(&press); 2554 DispatchEventUsingWindowDispatcher(&press);
2612 EXPECT_TRUE(delegate->tap_down()); 2555 EXPECT_TRUE(delegate->tap_down());
2613 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(), 2556 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(),
2614 delegate->bounding_box().ToString()); 2557 delegate->bounding_box().ToString());
2615 delegate->Reset(); 2558 delegate->Reset();
2616 2559
2617 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, tes.Now()); 2560 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, tes.Now());
2618 DispatchEventUsingWindowDispatcher(&press2); 2561 DispatchEventUsingWindowDispatcher(&press2);
2619 2562
2620 // This new press should not generate a tap-down. 2563 // This new press should not generate a tap-down.
2621 EXPECT_FALSE(delegate->begin()); 2564 EXPECT_FALSE(delegate->begin());
2622 EXPECT_FALSE(delegate->tap_down()); 2565 EXPECT_FALSE(delegate->tap_down());
2623 EXPECT_FALSE(delegate->tap_cancel()); 2566 EXPECT_FALSE(delegate->tap_cancel());
2624 EXPECT_FALSE(delegate->scroll_begin()); 2567 EXPECT_FALSE(delegate->scroll_begin());
2625 } 2568 }
2626 2569
2627 TEST_P(GestureRecognizerTest, TwoFingerTap) { 2570 TEST_F(GestureRecognizerTest, TwoFingerTap) {
2628 // TODO(tdresser): enable this test with unified GR once two finger tap is
2629 // supported. See crbug.com/354396.
2630 if (UsingUnifiedGR())
2631 return;
2632
2633 scoped_ptr<GestureEventConsumeDelegate> delegate( 2571 scoped_ptr<GestureEventConsumeDelegate> delegate(
2634 new GestureEventConsumeDelegate()); 2572 new GestureEventConsumeDelegate());
2635 const int kWindowWidth = 123; 2573 const int kWindowWidth = 123;
2636 const int kWindowHeight = 45; 2574 const int kWindowHeight = 45;
2637 const int kTouchId1 = 2; 2575 const int kTouchId1 = 2;
2638 const int kTouchId2 = 3; 2576 const int kTouchId2 = 3;
2639 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2577 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2640 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2578 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2641 delegate.get(), -1234, bounds, root_window())); 2579 delegate.get(), -1234, bounds, root_window()));
2642 TimedEvents tes; 2580 TimedEvents tes;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2710 EXPECT_FALSE(delegate->tap()); 2648 EXPECT_FALSE(delegate->tap());
2711 EXPECT_FALSE(delegate->tap_down()); 2649 EXPECT_FALSE(delegate->tap_down());
2712 EXPECT_FALSE(delegate->tap_cancel()); 2650 EXPECT_FALSE(delegate->tap_cancel());
2713 EXPECT_FALSE(delegate->scroll_begin()); 2651 EXPECT_FALSE(delegate->scroll_begin());
2714 EXPECT_FALSE(delegate->scroll_update()); 2652 EXPECT_FALSE(delegate->scroll_update());
2715 EXPECT_FALSE(delegate->scroll_end()); 2653 EXPECT_FALSE(delegate->scroll_end());
2716 EXPECT_TRUE(delegate->fling()); 2654 EXPECT_TRUE(delegate->fling());
2717 EXPECT_FALSE(delegate->two_finger_tap()); 2655 EXPECT_FALSE(delegate->two_finger_tap());
2718 } 2656 }
2719 2657
2720 TEST_P(GestureRecognizerTest, TwoFingerTapExpired) { 2658 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) {
2721 scoped_ptr<GestureEventConsumeDelegate> delegate( 2659 scoped_ptr<GestureEventConsumeDelegate> delegate(
2722 new GestureEventConsumeDelegate()); 2660 new GestureEventConsumeDelegate());
2723 const int kWindowWidth = 123; 2661 const int kWindowWidth = 123;
2724 const int kWindowHeight = 45; 2662 const int kWindowHeight = 45;
2725 const int kTouchId1 = 2; 2663 const int kTouchId1 = 2;
2726 const int kTouchId2 = 3; 2664 const int kTouchId2 = 3;
2727 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2665 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2728 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2666 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2729 delegate.get(), -1234, bounds, root_window())); 2667 delegate.get(), -1234, bounds, root_window()));
2730 TimedEvents tes; 2668 TimedEvents tes;
(...skipping 20 matching lines...) Expand all
2751 // Make sure there is enough delay before the touch is released so that it is 2689 // Make sure there is enough delay before the touch is released so that it is
2752 // recognized as a tap. 2690 // recognized as a tap.
2753 delegate->Reset(); 2691 delegate->Reset();
2754 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2692 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
2755 kTouchId2, tes.LeapForward(50)); 2693 kTouchId2, tes.LeapForward(50));
2756 2694
2757 DispatchEventUsingWindowDispatcher(&release2); 2695 DispatchEventUsingWindowDispatcher(&release2);
2758 EXPECT_FALSE(delegate->two_finger_tap()); 2696 EXPECT_FALSE(delegate->two_finger_tap());
2759 } 2697 }
2760 2698
2761 TEST_P(GestureRecognizerTest, TwoFingerTapChangesToPinch) { 2699 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
2762 // TODO(tdresser): enable this test with unified GR once two finger tap is
2763 // supported. See crbug.com/354396.
2764 if (UsingUnifiedGR())
2765 return;
2766
2767 scoped_ptr<GestureEventConsumeDelegate> delegate( 2700 scoped_ptr<GestureEventConsumeDelegate> delegate(
2768 new GestureEventConsumeDelegate()); 2701 new GestureEventConsumeDelegate());
2769 const int kWindowWidth = 123; 2702 const int kWindowWidth = 123;
2770 const int kWindowHeight = 45; 2703 const int kWindowHeight = 45;
2771 const int kTouchId1 = 2; 2704 const int kTouchId1 = 2;
2772 const int kTouchId2 = 3; 2705 const int kTouchId2 = 3;
2773 TimedEvents tes; 2706 TimedEvents tes;
2774 2707
2775 // Test moving first finger 2708 // Test moving first finger
2776 { 2709 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 delegate->Reset(); 2761 delegate->Reset();
2829 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2762 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2830 kTouchId1, tes.LeapForward(50)); 2763 kTouchId1, tes.LeapForward(50));
2831 2764
2832 DispatchEventUsingWindowDispatcher(&release); 2765 DispatchEventUsingWindowDispatcher(&release);
2833 EXPECT_FALSE(delegate->two_finger_tap()); 2766 EXPECT_FALSE(delegate->two_finger_tap());
2834 EXPECT_TRUE(delegate->pinch_end()); 2767 EXPECT_TRUE(delegate->pinch_end());
2835 } 2768 }
2836 } 2769 }
2837 2770
2838 TEST_P(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) { 2771 TEST_F(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) {
2839 // Disabled for unified GR due to differences in when pinch begin is sent. The
2840 // Aura GR sends it earlier than is necessary.
2841 if (UsingUnifiedGR())
2842 return;
2843
2844 scoped_ptr<GestureEventConsumeDelegate> delegate( 2772 scoped_ptr<GestureEventConsumeDelegate> delegate(
2845 new GestureEventConsumeDelegate()); 2773 new GestureEventConsumeDelegate());
2846 const int kWindowWidth = 123; 2774 const int kWindowWidth = 123;
2847 const int kWindowHeight = 45; 2775 const int kWindowHeight = 45;
2848 const int kTouchId1 = 2; 2776 const int kTouchId1 = 2;
2849 const int kTouchId2 = 3; 2777 const int kTouchId2 = 3;
2850 TimedEvents tes; 2778 TimedEvents tes;
2851 2779
2852 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2780 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2853 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2781 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 16 matching lines...) Expand all
2870 // is recognized as a tap. 2798 // is recognized as a tap.
2871 delegate->Reset(); 2799 delegate->Reset();
2872 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2800 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2873 kTouchId2, tes.LeapForward(50)); 2801 kTouchId2, tes.LeapForward(50));
2874 2802
2875 DispatchEventUsingWindowDispatcher(&release); 2803 DispatchEventUsingWindowDispatcher(&release);
2876 EXPECT_FALSE(delegate->two_finger_tap()); 2804 EXPECT_FALSE(delegate->two_finger_tap());
2877 EXPECT_TRUE(delegate->pinch_end()); 2805 EXPECT_TRUE(delegate->pinch_end());
2878 } 2806 }
2879 2807
2880 TEST_P(GestureRecognizerTest, MultiFingerSwipe) { 2808 TEST_F(GestureRecognizerTest, MultiFingerSwipe) {
2881 scoped_ptr<GestureEventConsumeDelegate> delegate( 2809 scoped_ptr<GestureEventConsumeDelegate> delegate(
2882 new GestureEventConsumeDelegate()); 2810 new GestureEventConsumeDelegate());
2883 const int kWindowWidth = 123; 2811 const int kWindowWidth = 123;
2884 const int kWindowHeight = 45; 2812 const int kWindowHeight = 45;
2885 2813
2886 gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight); 2814 gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight);
2887 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2815 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2888 delegate.get(), -1234, bounds, root_window())); 2816 delegate.get(), -1234, bounds, root_window()));
2889 2817
2890 const int kSteps = 15; 2818 const int kSteps = 15;
2891 const int kTouchPoints = 4; 2819 const int kTouchPoints = 4;
2892 gfx::Point points[kTouchPoints] = { 2820 gfx::Point points[kTouchPoints] = {
2893 gfx::Point(10, 30), 2821 gfx::Point(10, 30),
2894 gfx::Point(30, 20), 2822 gfx::Point(30, 20),
2895 gfx::Point(50, 30), 2823 gfx::Point(50, 30),
2896 gfx::Point(80, 50) 2824 gfx::Point(80, 50)
2897 }; 2825 };
2898 2826
2899 aura::test::EventGenerator generator(root_window(), window.get()); 2827 aura::test::EventGenerator generator(root_window(), window.get());
2900 2828
2901 // The unified gesture recognizer assumes a finger has stopped if it hasn't
2902 // moved for too long. See ui/events/gesture_detection/velocity_tracker.cc's
2903 // kAssumePointerStoppedTimeMs.
2904 for (int count = 2; count <= kTouchPoints; ++count) { 2829 for (int count = 2; count <= kTouchPoints; ++count) {
2905 generator.GestureMultiFingerScroll( 2830 generator.GestureMultiFingerScroll(
2906 count, points, 10, kSteps, 0, -11 * kSteps); 2831 count, points, 1000, kSteps, 0, -11 * kSteps);
2907 EXPECT_TRUE(delegate->swipe_up()); 2832 EXPECT_TRUE(delegate->swipe_up());
2908 delegate->Reset(); 2833 delegate->Reset();
2909 2834
2910 generator.GestureMultiFingerScroll( 2835 generator.GestureMultiFingerScroll(
2911 count, points, 10, kSteps, 0, 11 * kSteps); 2836 count, points, 1000, kSteps, 0, 11 * kSteps);
2912 EXPECT_TRUE(delegate->swipe_down()); 2837 EXPECT_TRUE(delegate->swipe_down());
2913 delegate->Reset(); 2838 delegate->Reset();
2914 2839
2915 generator.GestureMultiFingerScroll( 2840 generator.GestureMultiFingerScroll(
2916 count, points, 10, kSteps, -11 * kSteps, 0); 2841 count, points, 1000, kSteps, -11 * kSteps, 0);
2917 EXPECT_TRUE(delegate->swipe_left()); 2842 EXPECT_TRUE(delegate->swipe_left());
2918 delegate->Reset(); 2843 delegate->Reset();
2919 2844
2920 generator.GestureMultiFingerScroll( 2845 generator.GestureMultiFingerScroll(
2921 count, points, 10, kSteps, 11 * kSteps, 0); 2846 count, points, 1000, kSteps, 11 * kSteps, 0);
2922 EXPECT_TRUE(delegate->swipe_right()); 2847 EXPECT_TRUE(delegate->swipe_right());
2923 delegate->Reset(); 2848 delegate->Reset();
2924 } 2849 }
2925 } 2850 }
2926 2851
2927 TEST_P(GestureRecognizerTest, TwoFingerTapCancelled) { 2852 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) {
2928 scoped_ptr<GestureEventConsumeDelegate> delegate( 2853 scoped_ptr<GestureEventConsumeDelegate> delegate(
2929 new GestureEventConsumeDelegate()); 2854 new GestureEventConsumeDelegate());
2930 const int kWindowWidth = 123; 2855 const int kWindowWidth = 123;
2931 const int kWindowHeight = 45; 2856 const int kWindowHeight = 45;
2932 const int kTouchId1 = 2; 2857 const int kTouchId1 = 2;
2933 const int kTouchId2 = 3; 2858 const int kTouchId2 = 3;
2934 TimedEvents tes; 2859 TimedEvents tes;
2935 2860
2936 // Test canceling first finger. 2861 // Test canceling first finger.
2937 { 2862 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2991 // is recognized as a tap. 2916 // is recognized as a tap.
2992 delegate->Reset(); 2917 delegate->Reset();
2993 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2918 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2994 kTouchId1, tes.LeapForward(50)); 2919 kTouchId1, tes.LeapForward(50));
2995 2920
2996 DispatchEventUsingWindowDispatcher(&release); 2921 DispatchEventUsingWindowDispatcher(&release);
2997 EXPECT_FALSE(delegate->two_finger_tap()); 2922 EXPECT_FALSE(delegate->two_finger_tap());
2998 } 2923 }
2999 } 2924 }
3000 2925
3001 TEST_P(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { 2926 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
3002 // Disabled for unified GR due to differences in when scroll update is
3003 // sent. The Aura GR will never send a ScrollUpdate with a ScrollBegin, but
3004 // the unified GR will.
3005 if (UsingUnifiedGR())
3006 return;
3007
3008 scoped_ptr<GestureEventConsumeDelegate> delegate( 2927 scoped_ptr<GestureEventConsumeDelegate> delegate(
3009 new GestureEventConsumeDelegate()); 2928 new GestureEventConsumeDelegate());
3010 const int kWindowWidth = 523; 2929 const int kWindowWidth = 523;
3011 const int kWindowHeight = 45; 2930 const int kWindowHeight = 45;
3012 const int kTouchId1 = 2; 2931 const int kTouchId1 = 2;
3013 const int kTouchId2 = 3; 2932 const int kTouchId2 = 3;
3014 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2933 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3015 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2934 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3016 delegate.get(), -1234, bounds, root_window())); 2935 delegate.get(), -1234, bounds, root_window()));
3017 TimedEvents tes; 2936 TimedEvents tes;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3054 EXPECT_TRUE(delegate->scroll_begin()); 2973 EXPECT_TRUE(delegate->scroll_begin());
3055 EXPECT_FALSE(delegate->scroll_update()); 2974 EXPECT_FALSE(delegate->scroll_update());
3056 EXPECT_FALSE(delegate->scroll_end()); 2975 EXPECT_FALSE(delegate->scroll_end());
3057 EXPECT_FALSE(delegate->long_press()); 2976 EXPECT_FALSE(delegate->long_press());
3058 EXPECT_FALSE(delegate->two_finger_tap()); 2977 EXPECT_FALSE(delegate->two_finger_tap());
3059 EXPECT_TRUE(delegate->pinch_begin()); 2978 EXPECT_TRUE(delegate->pinch_begin());
3060 } 2979 }
3061 2980
3062 // Verifies if a window is the target of multiple touch-ids and we hide the 2981 // Verifies if a window is the target of multiple touch-ids and we hide the
3063 // window everything is cleaned up correctly. 2982 // window everything is cleaned up correctly.
3064 TEST_P(GestureRecognizerTest, FlushAllOnHide) { 2983 TEST_F(GestureRecognizerTest, FlushAllOnHide) {
3065 scoped_ptr<GestureEventConsumeDelegate> delegate( 2984 scoped_ptr<GestureEventConsumeDelegate> delegate(
3066 new GestureEventConsumeDelegate()); 2985 new GestureEventConsumeDelegate());
3067 gfx::Rect bounds(0, 0, 200, 200); 2986 gfx::Rect bounds(0, 0, 200, 200);
3068 scoped_ptr<aura::Window> window( 2987 scoped_ptr<aura::Window> window(
3069 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); 2988 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
3070 const int kTouchId1 = 8; 2989 const int kTouchId1 = 8;
3071 const int kTouchId2 = 2; 2990 const int kTouchId2 = 2;
3072 TimedEvents tes; 2991 TimedEvents tes;
3073 2992
3074 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2993 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
3075 kTouchId1, tes.Now()); 2994 kTouchId1, tes.Now());
3076 DispatchEventUsingWindowDispatcher(&press1); 2995 DispatchEventUsingWindowDispatcher(&press1);
3077 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2996 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
3078 kTouchId2, tes.Now()); 2997 kTouchId2, tes.Now());
3079 DispatchEventUsingWindowDispatcher(&press2); 2998 DispatchEventUsingWindowDispatcher(&press2);
3080 window->Hide(); 2999 window->Hide();
3081 EXPECT_EQ(NULL, 3000 EXPECT_EQ(NULL,
3082 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1)); 3001 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1));
3083 EXPECT_EQ(NULL, 3002 EXPECT_EQ(NULL,
3084 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)); 3003 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
3085 } 3004 }
3086 3005
3087 TEST_P(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { 3006 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
3088 // TODO(tdresser): write a version of this test for the unified GR.
3089 if (UsingUnifiedGR())
3090 return;
3091
3092 scoped_ptr<QueueTouchEventDelegate> delegate( 3007 scoped_ptr<QueueTouchEventDelegate> delegate(
3093 new QueueTouchEventDelegate(host()->dispatcher())); 3008 new QueueTouchEventDelegate(host()->dispatcher()));
3094 const int kTouchId = 2; 3009 const int kTouchId = 2;
3095 gfx::Rect bounds(100, 200, 100, 100); 3010 gfx::Rect bounds(100, 200, 100, 100);
3096 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3011 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3097 delegate.get(), -1234, bounds, root_window())); 3012 delegate.get(), -1234, bounds, root_window()));
3098 delegate->set_window(window.get()); 3013 delegate->set_window(window.get());
3099 TimedEvents tes; 3014 TimedEvents tes;
3100 3015
3101 TimerTestGestureRecognizer* gesture_recognizer = 3016 TimerTestGestureRecognizer* gesture_recognizer =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 GestureEventConsumeDelegate::OnTouchEvent(touch); 3056 GestureEventConsumeDelegate::OnTouchEvent(touch);
3142 } 3057 }
3143 3058
3144 bool consume_touch_move_; 3059 bool consume_touch_move_;
3145 3060
3146 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); 3061 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate);
3147 }; 3062 };
3148 3063
3149 // Same as GestureEventScroll, but tests that the behavior is the same 3064 // Same as GestureEventScroll, but tests that the behavior is the same
3150 // even if all the touch-move events are consumed. 3065 // even if all the touch-move events are consumed.
3151 TEST_P(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) { 3066 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
3152 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3067 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3153 new ConsumesTouchMovesDelegate()); 3068 new ConsumesTouchMovesDelegate());
3154 const int kWindowWidth = 123; 3069 const int kWindowWidth = 123;
3155 const int kWindowHeight = 45; 3070 const int kWindowHeight = 45;
3156 const int kTouchId = 5; 3071 const int kTouchId = 5;
3157 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3072 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3158 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3073 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3159 delegate.get(), -1234, bounds, root_window())); 3074 delegate.get(), -1234, bounds, root_window()));
3160 TimedEvents tes; 3075 TimedEvents tes;
3161 3076
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 EXPECT_FALSE(delegate->tap_down()); 3108 EXPECT_FALSE(delegate->tap_down());
3194 EXPECT_FALSE(delegate->tap_cancel()); 3109 EXPECT_FALSE(delegate->tap_cancel());
3195 EXPECT_FALSE(delegate->begin()); 3110 EXPECT_FALSE(delegate->begin());
3196 EXPECT_TRUE(delegate->end()); 3111 EXPECT_TRUE(delegate->end());
3197 EXPECT_FALSE(delegate->scroll_begin()); 3112 EXPECT_FALSE(delegate->scroll_begin());
3198 EXPECT_FALSE(delegate->scroll_update()); 3113 EXPECT_FALSE(delegate->scroll_update());
3199 EXPECT_FALSE(delegate->scroll_end()); 3114 EXPECT_FALSE(delegate->scroll_end());
3200 } 3115 }
3201 3116
3202 // Tests the behavior of 2F scroll when all the touch-move events are consumed. 3117 // Tests the behavior of 2F scroll when all the touch-move events are consumed.
3203 TEST_P(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) { 3118 TEST_F(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) {
3204 // TODO(tdresser): enable this test with unified GR once two finger tap is
3205 // supported. See crbug.com/354396.
3206 if (UsingUnifiedGR())
3207 return;
3208
3209 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3119 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3210 new ConsumesTouchMovesDelegate()); 3120 new ConsumesTouchMovesDelegate());
3211 const int kWindowWidth = 123; 3121 const int kWindowWidth = 123;
3212 const int kWindowHeight = 100; 3122 const int kWindowHeight = 100;
3213 const int kTouchId1 = 2; 3123 const int kTouchId1 = 2;
3214 const int kTouchId2 = 3; 3124 const int kTouchId2 = 3;
3215 TimedEvents tes; 3125 TimedEvents tes;
3216 3126
3217 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3127 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3218 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3128 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3305 EXPECT_TRUE(delegate->fling()); 3215 EXPECT_TRUE(delegate->fling());
3306 3216
3307 EXPECT_FALSE(delegate->pinch_begin()); 3217 EXPECT_FALSE(delegate->pinch_begin());
3308 EXPECT_FALSE(delegate->pinch_update()); 3218 EXPECT_FALSE(delegate->pinch_update());
3309 EXPECT_FALSE(delegate->pinch_end()); 3219 EXPECT_FALSE(delegate->pinch_end());
3310 } 3220 }
3311 3221
3312 // Like as GestureEventTouchMoveConsumed but tests the different behavior 3222 // Like as GestureEventTouchMoveConsumed but tests the different behavior
3313 // depending on whether the events were consumed before or after the scroll 3223 // depending on whether the events were consumed before or after the scroll
3314 // started. 3224 // started.
3315 TEST_P(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) { 3225 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) {
3316 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3226 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3317 new ConsumesTouchMovesDelegate()); 3227 new ConsumesTouchMovesDelegate());
3318 const int kWindowWidth = 123; 3228 const int kWindowWidth = 123;
3319 const int kWindowHeight = 45; 3229 const int kWindowHeight = 45;
3320 const int kTouchId = 5; 3230 const int kTouchId = 5;
3321 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3231 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3322 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3232 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3323 delegate.get(), -1234, bounds, root_window())); 3233 delegate.get(), -1234, bounds, root_window()));
3324 TimedEvents tes; 3234 TimedEvents tes;
3325 3235
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 EXPECT_FALSE(delegate->tap_cancel()); 3309 EXPECT_FALSE(delegate->tap_cancel());
3400 EXPECT_FALSE(delegate->begin()); 3310 EXPECT_FALSE(delegate->begin());
3401 EXPECT_TRUE(delegate->end()); 3311 EXPECT_TRUE(delegate->end());
3402 EXPECT_FALSE(delegate->scroll_begin()); 3312 EXPECT_FALSE(delegate->scroll_begin());
3403 EXPECT_FALSE(delegate->scroll_update()); 3313 EXPECT_FALSE(delegate->scroll_update());
3404 EXPECT_FALSE(delegate->scroll_end()); 3314 EXPECT_FALSE(delegate->scroll_end());
3405 EXPECT_FALSE(delegate->fling()); 3315 EXPECT_FALSE(delegate->fling());
3406 } 3316 }
3407 3317
3408 // Check that appropriate touch events generate double tap gesture events. 3318 // Check that appropriate touch events generate double tap gesture events.
3409 TEST_P(GestureRecognizerTest, GestureEventDoubleTap) { 3319 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) {
3410 // TODO(tdresser): enable this test with unified GR once double / triple tap
3411 // gestures work. See crbug.com/357270.
3412 if (UsingUnifiedGR())
3413 return;
3414
3415 scoped_ptr<GestureEventConsumeDelegate> delegate( 3320 scoped_ptr<GestureEventConsumeDelegate> delegate(
3416 new GestureEventConsumeDelegate()); 3321 new GestureEventConsumeDelegate());
3417 const int kWindowWidth = 123; 3322 const int kWindowWidth = 123;
3418 const int kWindowHeight = 45; 3323 const int kWindowHeight = 45;
3419 const int kTouchId = 2; 3324 const int kTouchId = 2;
3420 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3325 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3421 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3326 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3422 delegate.get(), -1234, bounds, root_window())); 3327 delegate.get(), -1234, bounds, root_window()));
3423 TimedEvents tes; 3328 TimedEvents tes;
3424 3329
(...skipping 20 matching lines...) Expand all
3445 EXPECT_TRUE(delegate->begin()); 3350 EXPECT_TRUE(delegate->begin());
3446 EXPECT_TRUE(delegate->end()); 3351 EXPECT_TRUE(delegate->end());
3447 EXPECT_FALSE(delegate->scroll_begin()); 3352 EXPECT_FALSE(delegate->scroll_begin());
3448 EXPECT_FALSE(delegate->scroll_update()); 3353 EXPECT_FALSE(delegate->scroll_update());
3449 EXPECT_FALSE(delegate->scroll_end()); 3354 EXPECT_FALSE(delegate->scroll_end());
3450 3355
3451 EXPECT_EQ(2, delegate->tap_count()); 3356 EXPECT_EQ(2, delegate->tap_count());
3452 } 3357 }
3453 3358
3454 // Check that appropriate touch events generate triple tap gesture events. 3359 // Check that appropriate touch events generate triple tap gesture events.
3455 TEST_P(GestureRecognizerTest, GestureEventTripleTap) { 3360 TEST_F(GestureRecognizerTest, GestureEventTripleTap) {
3456 // TODO(tdresser): enable this test with unified GR once double / triple tap
3457 // gestures work. See crbug.com/357270.
3458 if (UsingUnifiedGR())
3459 return;
3460
3461 scoped_ptr<GestureEventConsumeDelegate> delegate( 3361 scoped_ptr<GestureEventConsumeDelegate> delegate(
3462 new GestureEventConsumeDelegate()); 3362 new GestureEventConsumeDelegate());
3463 const int kWindowWidth = 123; 3363 const int kWindowWidth = 123;
3464 const int kWindowHeight = 45; 3364 const int kWindowHeight = 45;
3465 const int kTouchId = 2; 3365 const int kTouchId = 2;
3466 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3366 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3467 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3367 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3468 delegate.get(), -1234, bounds, root_window())); 3368 delegate.get(), -1234, bounds, root_window()));
3469 TimedEvents tes; 3369 TimedEvents tes;
3470 3370
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3505 EXPECT_TRUE(delegate->begin()); 3405 EXPECT_TRUE(delegate->begin());
3506 EXPECT_TRUE(delegate->end()); 3406 EXPECT_TRUE(delegate->end());
3507 EXPECT_FALSE(delegate->scroll_begin()); 3407 EXPECT_FALSE(delegate->scroll_begin());
3508 EXPECT_FALSE(delegate->scroll_update()); 3408 EXPECT_FALSE(delegate->scroll_update());
3509 EXPECT_FALSE(delegate->scroll_end()); 3409 EXPECT_FALSE(delegate->scroll_end());
3510 3410
3511 EXPECT_EQ(3, delegate->tap_count()); 3411 EXPECT_EQ(3, delegate->tap_count());
3512 } 3412 }
3513 3413
3514 // Check that we don't get a double tap when the two taps are far apart. 3414 // Check that we don't get a double tap when the two taps are far apart.
3515 TEST_P(GestureRecognizerTest, TwoTapsFarApart) { 3415 TEST_F(GestureRecognizerTest, TwoTapsFarApart) {
3516 scoped_ptr<GestureEventConsumeDelegate> delegate( 3416 scoped_ptr<GestureEventConsumeDelegate> delegate(
3517 new GestureEventConsumeDelegate()); 3417 new GestureEventConsumeDelegate());
3518 const int kWindowWidth = 123; 3418 const int kWindowWidth = 123;
3519 const int kWindowHeight = 45; 3419 const int kWindowHeight = 45;
3520 const int kTouchId = 2; 3420 const int kTouchId = 2;
3521 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3421 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3522 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3422 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3523 delegate.get(), -1234, bounds, root_window())); 3423 delegate.get(), -1234, bounds, root_window()));
3524 TimedEvents tes; 3424 TimedEvents tes;
3525 3425
(...skipping 21 matching lines...) Expand all
3547 EXPECT_TRUE(delegate->end()); 3447 EXPECT_TRUE(delegate->end());
3548 EXPECT_FALSE(delegate->scroll_begin()); 3448 EXPECT_FALSE(delegate->scroll_begin());
3549 EXPECT_FALSE(delegate->scroll_update()); 3449 EXPECT_FALSE(delegate->scroll_update());
3550 EXPECT_FALSE(delegate->scroll_end()); 3450 EXPECT_FALSE(delegate->scroll_end());
3551 3451
3552 EXPECT_EQ(1, delegate->tap_count()); 3452 EXPECT_EQ(1, delegate->tap_count());
3553 } 3453 }
3554 3454
3555 // Check that we don't get a double tap when the two taps have a long enough 3455 // Check that we don't get a double tap when the two taps have a long enough
3556 // delay in between. 3456 // delay in between.
3557 TEST_P(GestureRecognizerTest, TwoTapsWithDelayBetween) { 3457 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) {
3558 scoped_ptr<GestureEventConsumeDelegate> delegate( 3458 scoped_ptr<GestureEventConsumeDelegate> delegate(
3559 new GestureEventConsumeDelegate()); 3459 new GestureEventConsumeDelegate());
3560 const int kWindowWidth = 123; 3460 const int kWindowWidth = 123;
3561 const int kWindowHeight = 45; 3461 const int kWindowHeight = 45;
3562 const int kTouchId = 2; 3462 const int kTouchId = 2;
3563 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3463 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3564 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3464 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3565 delegate.get(), -1234, bounds, root_window())); 3465 delegate.get(), -1234, bounds, root_window()));
3566 TimedEvents tes; 3466 TimedEvents tes;
3567 3467
(...skipping 22 matching lines...) Expand all
3590 EXPECT_FALSE(delegate->scroll_begin()); 3490 EXPECT_FALSE(delegate->scroll_begin());
3591 EXPECT_FALSE(delegate->scroll_update()); 3491 EXPECT_FALSE(delegate->scroll_update());
3592 EXPECT_FALSE(delegate->scroll_end()); 3492 EXPECT_FALSE(delegate->scroll_end());
3593 3493
3594 EXPECT_EQ(1, delegate->tap_count()); 3494 EXPECT_EQ(1, delegate->tap_count());
3595 } 3495 }
3596 3496
3597 // Checks that if the bounding-box of a gesture changes because of change in 3497 // Checks that if the bounding-box of a gesture changes because of change in
3598 // radius of a touch-point, and not because of change in position, then there 3498 // radius of a touch-point, and not because of change in position, then there
3599 // are not gesture events from that. 3499 // are not gesture events from that.
3600 TEST_P(GestureRecognizerTest, BoundingBoxRadiusChange) { 3500 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) {
3601 // TODO(tdresser): enable this test with unified GR when (if?) bounding box
3602 // behavior is unified.
3603 if (UsingUnifiedGR())
3604 return;
3605
3606 scoped_ptr<GestureEventConsumeDelegate> delegate( 3501 scoped_ptr<GestureEventConsumeDelegate> delegate(
3607 new GestureEventConsumeDelegate()); 3502 new GestureEventConsumeDelegate());
3608 const int kWindowWidth = 234; 3503 const int kWindowWidth = 234;
3609 const int kWindowHeight = 345; 3504 const int kWindowHeight = 345;
3610 const int kTouchId = 5, kTouchId2 = 7; 3505 const int kTouchId = 5, kTouchId2 = 7;
3611 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3506 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3612 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3507 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3613 delegate.get(), -1234, bounds, root_window())); 3508 delegate.get(), -1234, bounds, root_window()));
3614 TimedEvents tes; 3509 TimedEvents tes;
3615 3510
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3649 EXPECT_FALSE(delegate->tap()); 3544 EXPECT_FALSE(delegate->tap());
3650 EXPECT_FALSE(delegate->tap_cancel()); 3545 EXPECT_FALSE(delegate->tap_cancel());
3651 EXPECT_FALSE(delegate->scroll_update()); 3546 EXPECT_FALSE(delegate->scroll_update());
3652 EXPECT_FALSE(delegate->pinch_update()); 3547 EXPECT_FALSE(delegate->pinch_update());
3653 3548
3654 delegate->Reset(); 3549 delegate->Reset();
3655 } 3550 }
3656 3551
3657 // Checks that slow scrolls deliver the correct deltas. 3552 // Checks that slow scrolls deliver the correct deltas.
3658 // In particular, fix for http;//crbug.com/150573. 3553 // In particular, fix for http;//crbug.com/150573.
3659 TEST_P(GestureRecognizerTest, NoDriftInScroll) { 3554 TEST_F(GestureRecognizerTest, NoDriftInScroll) {
3660 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); 3555 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
3661 ui::GestureConfiguration::set_min_scroll_delta_squared(9); 3556 ui::GestureConfiguration::set_min_scroll_delta_squared(9);
3662 scoped_ptr<GestureEventConsumeDelegate> delegate( 3557 scoped_ptr<GestureEventConsumeDelegate> delegate(
3663 new GestureEventConsumeDelegate()); 3558 new GestureEventConsumeDelegate());
3664 const int kWindowWidth = 234; 3559 const int kWindowWidth = 234;
3665 const int kWindowHeight = 345; 3560 const int kWindowHeight = 345;
3666 const int kTouchId = 5; 3561 const int kTouchId = 5;
3667 TimedEvents tes; 3562 TimedEvents tes;
3668 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3563 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3669 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3564 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3707 DispatchEventUsingWindowDispatcher(&move4); 3602 DispatchEventUsingWindowDispatcher(&move4);
3708 EXPECT_TRUE(delegate->scroll_update()); 3603 EXPECT_TRUE(delegate->scroll_update());
3709 EXPECT_EQ(-1, delegate->scroll_y()); 3604 EXPECT_EQ(-1, delegate->scroll_y());
3710 3605
3711 delegate->Reset(); 3606 delegate->Reset();
3712 } 3607 }
3713 3608
3714 // Ensure that move events which are preventDefaulted will cause a tap 3609 // Ensure that move events which are preventDefaulted will cause a tap
3715 // cancel gesture event to be fired if the move would normally cause a 3610 // cancel gesture event to be fired if the move would normally cause a
3716 // scroll. See bug http://crbug.com/146397. 3611 // scroll. See bug http://crbug.com/146397.
3717 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) { 3612 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) {
3718 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3613 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
3719 new ConsumesTouchMovesDelegate()); 3614 new ConsumesTouchMovesDelegate());
3720 const int kTouchId = 5; 3615 const int kTouchId = 5;
3721 gfx::Rect bounds(100, 200, 123, 45); 3616 gfx::Rect bounds(100, 200, 123, 45);
3722 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3617 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3723 delegate.get(), -1234, bounds, root_window())); 3618 delegate.get(), -1234, bounds, root_window()));
3724 TimedEvents tes; 3619 TimedEvents tes;
3725 3620
3726 delegate->Reset(); 3621 delegate->Reset();
3727 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3622 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3728 kTouchId, tes.Now()); 3623 kTouchId, tes.Now());
3729 3624
3730 delegate->set_consume_touch_move(false); 3625 delegate->set_consume_touch_move(false);
3731 DispatchEventUsingWindowDispatcher(&press); 3626 DispatchEventUsingWindowDispatcher(&press);
3732 delegate->set_consume_touch_move(true); 3627 delegate->set_consume_touch_move(true);
3733 delegate->Reset(); 3628 delegate->Reset();
3734 // Move the touch-point enough so that it would normally be considered a 3629 // Move the touch-point enough so that it would normally be considered a
3735 // scroll. But since the touch-moves will be consumed, the scroll should not 3630 // scroll. But since the touch-moves will be consumed, the scroll should not
3736 // start. 3631 // start.
3737 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); 3632 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
3738 EXPECT_FALSE(delegate->tap()); 3633 EXPECT_FALSE(delegate->tap());
3739 EXPECT_FALSE(delegate->tap_down()); 3634 EXPECT_FALSE(delegate->tap_down());
3740 EXPECT_TRUE(delegate->tap_cancel()); 3635 EXPECT_TRUE(delegate->tap_cancel());
3741 EXPECT_FALSE(delegate->begin()); 3636 EXPECT_FALSE(delegate->begin());
3742 EXPECT_FALSE(delegate->scroll_begin()); 3637 EXPECT_FALSE(delegate->scroll_begin());
3743 EXPECT_FALSE(delegate->scroll_update()); 3638 EXPECT_FALSE(delegate->scroll_update());
3744 EXPECT_FALSE(delegate->scroll_end()); 3639 EXPECT_FALSE(delegate->scroll_end());
3745 } 3640 }
3746 3641
3747 TEST_P(GestureRecognizerTest, 3642 TEST_F(GestureRecognizerTest,
3748 TransferEventDispatchesTouchCancel) { 3643 TransferEventDispatchesTouchCancel) {
3749 scoped_ptr<GestureEventConsumeDelegate> delegate( 3644 scoped_ptr<GestureEventConsumeDelegate> delegate(
3750 new GestureEventConsumeDelegate()); 3645 new GestureEventConsumeDelegate());
3751 TimedEvents tes; 3646 TimedEvents tes;
3752 const int kWindowWidth = 800; 3647 const int kWindowWidth = 800;
3753 const int kWindowHeight = 600; 3648 const int kWindowHeight = 600;
3754 const int kTouchId = 2; 3649 const int kTouchId = 2;
3755 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3650 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3756 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3651 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3757 delegate.get(), -1234, bounds, root_window())); 3652 delegate.get(), -1234, bounds, root_window()));
(...skipping 22 matching lines...) Expand all
3780 gesture_recognizer->GetTouchLockedTarget(press)); 3675 gesture_recognizer->GetTouchLockedTarget(press));
3781 gesture_recognizer->TransferEventsTo(window.get(), NULL); 3676 gesture_recognizer->TransferEventsTo(window.get(), NULL);
3782 EXPECT_EQ(NULL, 3677 EXPECT_EQ(NULL,
3783 gesture_recognizer->GetTouchLockedTarget(press)); 3678 gesture_recognizer->GetTouchLockedTarget(press));
3784 // The event-handler removes |window| from its parent on the first 3679 // The event-handler removes |window| from its parent on the first
3785 // touch-cancel event, so it won't receive the second touch-cancel event. 3680 // touch-cancel event, so it won't receive the second touch-cancel event.
3786 EXPECT_EQ(1, handler->touch_cancelled_count()); 3681 EXPECT_EQ(1, handler->touch_cancelled_count());
3787 } 3682 }
3788 3683
3789 // Check that appropriate touch events generate show press events 3684 // Check that appropriate touch events generate show press events
3790 TEST_P(GestureRecognizerTest, GestureEventShowPress) { 3685 TEST_F(GestureRecognizerTest, GestureEventShowPress) {
3791 scoped_ptr<GestureEventConsumeDelegate> delegate( 3686 scoped_ptr<GestureEventConsumeDelegate> delegate(
3792 new GestureEventConsumeDelegate()); 3687 new GestureEventConsumeDelegate());
3793 TimedEvents tes; 3688 TimedEvents tes;
3794 const int kWindowWidth = 123; 3689 const int kWindowWidth = 123;
3795 const int kWindowHeight = 45; 3690 const int kWindowHeight = 45;
3796 const int kTouchId = 2; 3691 const int kTouchId = 2;
3797 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3692 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3798 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3693 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3799 delegate.get(), -1234, bounds, root_window())); 3694 delegate.get(), -1234, bounds, root_window()));
3800 3695
(...skipping 18 matching lines...) Expand all
3819 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS); 3714 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS);
3820 EXPECT_TRUE(delegate->show_press()); 3715 EXPECT_TRUE(delegate->show_press());
3821 EXPECT_FALSE(delegate->tap_cancel()); 3716 EXPECT_FALSE(delegate->tap_cancel());
3822 3717
3823 delegate->Reset(); 3718 delegate->Reset();
3824 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3719 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3825 kTouchId, tes.Now()); 3720 kTouchId, tes.Now());
3826 DispatchEventUsingWindowDispatcher(&release1); 3721 DispatchEventUsingWindowDispatcher(&release1);
3827 EXPECT_FALSE(delegate->long_press()); 3722 EXPECT_FALSE(delegate->long_press());
3828 3723
3829 // Note the tap isn't dispatched until the release 3724 // Note the tap down isn't cancelled until the release
3830 EXPECT_FALSE(delegate->tap_cancel()); 3725 EXPECT_TRUE(delegate->tap_cancel());
3831 EXPECT_TRUE(delegate->tap());
3832 } 3726 }
3833 3727
3834 // Check that scrolling cancels a show press 3728 // Check that scrolling cancels a show press
3835 TEST_P(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) { 3729 TEST_F(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) {
3836 scoped_ptr<GestureEventConsumeDelegate> delegate( 3730 scoped_ptr<GestureEventConsumeDelegate> delegate(
3837 new GestureEventConsumeDelegate()); 3731 new GestureEventConsumeDelegate());
3838 TimedEvents tes; 3732 TimedEvents tes;
3839 const int kWindowWidth = 123; 3733 const int kWindowWidth = 123;
3840 const int kWindowHeight = 45; 3734 const int kWindowHeight = 45;
3841 const int kTouchId = 6; 3735 const int kTouchId = 6;
3842 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3736 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3843 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3737 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3844 delegate.get(), -1234, bounds, root_window())); 3738 delegate.get(), -1234, bounds, root_window()));
3845 3739
(...skipping 26 matching lines...) Expand all
3872 3766
3873 delegate->Reset(); 3767 delegate->Reset();
3874 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3768 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3875 kTouchId, tes.LeapForward(10)); 3769 kTouchId, tes.LeapForward(10));
3876 DispatchEventUsingWindowDispatcher(&release1); 3770 DispatchEventUsingWindowDispatcher(&release1);
3877 EXPECT_FALSE(delegate->show_press()); 3771 EXPECT_FALSE(delegate->show_press());
3878 EXPECT_FALSE(delegate->tap_cancel()); 3772 EXPECT_FALSE(delegate->tap_cancel());
3879 } 3773 }
3880 3774
3881 // Test that show press events are sent immediately on tap 3775 // Test that show press events are sent immediately on tap
3882 TEST_P(GestureRecognizerTest, GestureEventShowPressSentOnTap) { 3776 TEST_F(GestureRecognizerTest, GestureEventShowPressSentOnTap) {
3883 scoped_ptr<GestureEventConsumeDelegate> delegate( 3777 scoped_ptr<GestureEventConsumeDelegate> delegate(
3884 new GestureEventConsumeDelegate()); 3778 new GestureEventConsumeDelegate());
3885 TimedEvents tes; 3779 TimedEvents tes;
3886 const int kWindowWidth = 123; 3780 const int kWindowWidth = 123;
3887 const int kWindowHeight = 45; 3781 const int kWindowHeight = 45;
3888 const int kTouchId = 6; 3782 const int kTouchId = 6;
3889 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3783 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3890 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3784 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3891 delegate.get(), -1234, bounds, root_window())); 3785 delegate.get(), -1234, bounds, root_window()));
3892 3786
(...skipping 11 matching lines...) Expand all
3904 delegate->Reset(); 3798 delegate->Reset();
3905 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3799 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3906 kTouchId, tes.LeapForward(50)); 3800 kTouchId, tes.LeapForward(50));
3907 DispatchEventUsingWindowDispatcher(&release1); 3801 DispatchEventUsingWindowDispatcher(&release1);
3908 EXPECT_TRUE(delegate->show_press()); 3802 EXPECT_TRUE(delegate->show_press());
3909 EXPECT_FALSE(delegate->tap_cancel()); 3803 EXPECT_FALSE(delegate->tap_cancel());
3910 EXPECT_TRUE(delegate->tap()); 3804 EXPECT_TRUE(delegate->tap());
3911 } 3805 }
3912 3806
3913 // Test that consuming the first move touch event prevents a scroll. 3807 // Test that consuming the first move touch event prevents a scroll.
3914 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) { 3808 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) {
3915 scoped_ptr<QueueTouchEventDelegate> delegate( 3809 scoped_ptr<QueueTouchEventDelegate> delegate(
3916 new QueueTouchEventDelegate(host()->dispatcher())); 3810 new QueueTouchEventDelegate(host()->dispatcher()));
3917 TimedEvents tes; 3811 TimedEvents tes;
3918 const int kTouchId = 7; 3812 const int kTouchId = 7;
3919 gfx::Rect bounds(0, 0, 1000, 1000); 3813 gfx::Rect bounds(0, 0, 1000, 1000);
3920 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3814 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3921 delegate.get(), -1234, bounds, root_window())); 3815 delegate.get(), -1234, bounds, root_window()));
3922 3816
3923 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3817 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3924 kTouchId, tes.Now()); 3818 kTouchId, tes.Now());
3925 DispatchEventUsingWindowDispatcher(&press); 3819 DispatchEventUsingWindowDispatcher(&press);
3926 delegate->ReceivedAck(); 3820 delegate->ReceivedAck();
3927 3821
3928 // A touch move within the slop region is never consumed in web contents. The 3822 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
3929 // unified GR won't prevent scroll if a touch move within the slop region is
3930 // consumed, so make sure this touch move exceeds the slop region.
3931 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10),
3932 kTouchId, tes.Now()); 3823 kTouchId, tes.Now());
3933 DispatchEventUsingWindowDispatcher(&move1); 3824 DispatchEventUsingWindowDispatcher(&move1);
3934 delegate->ReceivedAckPreventDefaulted(); 3825 delegate->ReceivedAckPreventDefaulted();
3935 3826
3936 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 3827 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
3937 kTouchId, tes.Now()); 3828 kTouchId, tes.Now());
3938 DispatchEventUsingWindowDispatcher(&move2); 3829 DispatchEventUsingWindowDispatcher(&move2);
3939 delegate->ReceivedAck(); 3830 delegate->ReceivedAck();
3940 3831
3941 EXPECT_FALSE(delegate->scroll_begin()); 3832 EXPECT_FALSE(delegate->scroll_begin());
3942 EXPECT_FALSE(delegate->scroll_update()); 3833 EXPECT_FALSE(delegate->scroll_update());
3943 } 3834 }
3944 3835
3945 // Test that consuming the first touch move event of a touch point doesn't 3836 // Test that consuming the first touch move event of a touch point doesn't
3946 // prevent pinching once an additional touch has been pressed. 3837 // prevent pinching once an additional touch has been pressed.
3947 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) { 3838 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) {
3948 // Consuming moves within the touch slop and the the disposition handling of
3949 // pinch events behave differently between the Unified GR and the Aura GR.
3950 if (UsingUnifiedGR())
3951 return;
3952
3953 scoped_ptr<QueueTouchEventDelegate> delegate( 3839 scoped_ptr<QueueTouchEventDelegate> delegate(
3954 new QueueTouchEventDelegate(host()->dispatcher())); 3840 new QueueTouchEventDelegate(host()->dispatcher()));
3955 TimedEvents tes; 3841 TimedEvents tes;
3956 const int kTouchId1 = 7; 3842 const int kTouchId1 = 7;
3957 const int kTouchId2 = 4; 3843 const int kTouchId2 = 4;
3958 gfx::Rect bounds(0, 0, 1000, 1000); 3844 gfx::Rect bounds(0, 0, 1000, 1000);
3959 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3845 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3960 delegate.get(), -1234, bounds, root_window())); 3846 delegate.get(), -1234, bounds, root_window()));
3961 3847
3962 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3848 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3999 kTouchId2, tes.Now()); 3885 kTouchId2, tes.Now());
4000 DispatchEventUsingWindowDispatcher(&move4); 3886 DispatchEventUsingWindowDispatcher(&move4);
4001 delegate->ReceivedAck(); 3887 delegate->ReceivedAck();
4002 3888
4003 EXPECT_TRUE(delegate->pinch_update()); 3889 EXPECT_TRUE(delegate->pinch_update());
4004 EXPECT_EQ(10, delegate->scroll_x()); 3890 EXPECT_EQ(10, delegate->scroll_x());
4005 EXPECT_EQ(10, delegate->scroll_y()); 3891 EXPECT_EQ(10, delegate->scroll_y());
4006 } 3892 }
4007 3893
4008 // Test that consuming the first move touch doesn't prevent a tap. 3894 // Test that consuming the first move touch doesn't prevent a tap.
4009 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) { 3895 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) {
4010 scoped_ptr<QueueTouchEventDelegate> delegate( 3896 scoped_ptr<QueueTouchEventDelegate> delegate(
4011 new QueueTouchEventDelegate(host()->dispatcher())); 3897 new QueueTouchEventDelegate(host()->dispatcher()));
4012 TimedEvents tes; 3898 TimedEvents tes;
4013 const int kTouchId = 7; 3899 const int kTouchId = 7;
4014 gfx::Rect bounds(0, 0, 1000, 1000); 3900 gfx::Rect bounds(0, 0, 1000, 1000);
4015 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3901 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4016 delegate.get(), -1234, bounds, root_window())); 3902 delegate.get(), -1234, bounds, root_window()));
4017 3903
4018 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3904 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
4019 kTouchId, tes.Now()); 3905 kTouchId, tes.Now());
4020 DispatchEventUsingWindowDispatcher(&press); 3906 DispatchEventUsingWindowDispatcher(&press);
4021 delegate->ReceivedAck(); 3907 delegate->ReceivedAck();
4022 3908
4023 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2), 3909 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
4024 kTouchId, tes.Now()); 3910 kTouchId, tes.Now());
4025 DispatchEventUsingWindowDispatcher(&move); 3911 DispatchEventUsingWindowDispatcher(&move);
4026 delegate->ReceivedAckPreventDefaulted(); 3912 delegate->ReceivedAckPreventDefaulted();
4027 3913
4028 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(2, 2), 3914 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(2, 2),
4029 kTouchId, tes.LeapForward(50)); 3915 kTouchId, tes.LeapForward(50));
4030 DispatchEventUsingWindowDispatcher(&release); 3916 DispatchEventUsingWindowDispatcher(&release);
4031 delegate->ReceivedAck(); 3917 delegate->ReceivedAck();
4032 3918
4033 EXPECT_TRUE(delegate->tap()); 3919 EXPECT_TRUE(delegate->tap());
4034 } 3920 }
4035 3921
4036 // Test that consuming the first move touch doesn't prevent a long press. 3922 // Test that consuming the first move touch doesn't prevent a long press.
4037 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) { 3923 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) {
4038 scoped_ptr<QueueTouchEventDelegate> delegate( 3924 scoped_ptr<QueueTouchEventDelegate> delegate(
4039 new QueueTouchEventDelegate(host()->dispatcher())); 3925 new QueueTouchEventDelegate(host()->dispatcher()));
4040 TimedEvents tes; 3926 TimedEvents tes;
4041 const int kWindowWidth = 123; 3927 const int kWindowWidth = 123;
4042 const int kWindowHeight = 45; 3928 const int kWindowHeight = 45;
4043 const int kTouchId = 2; 3929 const int kTouchId = 2;
4044 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3930 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
4045 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3931 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4046 delegate.get(), -1234, bounds, root_window())); 3932 delegate.get(), -1234, bounds, root_window()));
4047 3933
(...skipping 13 matching lines...) Expand all
4061 kTouchId, tes.Now()); 3947 kTouchId, tes.Now());
4062 DispatchEventUsingWindowDispatcher(&move); 3948 DispatchEventUsingWindowDispatcher(&move);
4063 delegate->ReceivedAckPreventDefaulted(); 3949 delegate->ReceivedAckPreventDefaulted();
4064 3950
4065 // Wait until the timer runs out 3951 // Wait until the timer runs out
4066 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 3952 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
4067 EXPECT_TRUE(delegate->long_press()); 3953 EXPECT_TRUE(delegate->long_press());
4068 } 3954 }
4069 3955
4070 // Tests that the deltas are correct when leaving the slop region very slowly. 3956 // Tests that the deltas are correct when leaving the slop region very slowly.
4071 TEST_P(GestureRecognizerTest, TestExceedingSlopSlowly) { 3957 TEST_F(GestureRecognizerTest, TestExceedingSlopSlowly) {
4072 // Disabled for unified GR due to subtle differences in touch slop handling.
4073 if (UsingUnifiedGR())
4074 return;
4075
4076 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); 3958 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
4077 scoped_ptr<GestureEventConsumeDelegate> delegate( 3959 scoped_ptr<GestureEventConsumeDelegate> delegate(
4078 new GestureEventConsumeDelegate()); 3960 new GestureEventConsumeDelegate());
4079 const int kWindowWidth = 234; 3961 const int kWindowWidth = 234;
4080 const int kWindowHeight = 345; 3962 const int kWindowHeight = 345;
4081 const int kTouchId = 5; 3963 const int kTouchId = 5;
4082 TimedEvents tes; 3964 TimedEvents tes;
4083 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3965 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
4084 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3966 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4085 delegate.get(), -1234, bounds, root_window())); 3967 delegate.get(), -1234, bounds, root_window()));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4123 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(14, 10), kTouchId, 4005 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(14, 10), kTouchId,
4124 tes.LeapForward(40)); 4006 tes.LeapForward(40));
4125 DispatchEventUsingWindowDispatcher(&move4); 4007 DispatchEventUsingWindowDispatcher(&move4);
4126 EXPECT_FALSE(delegate->scroll_begin()); 4008 EXPECT_FALSE(delegate->scroll_begin());
4127 EXPECT_TRUE(delegate->scroll_update()); 4009 EXPECT_TRUE(delegate->scroll_update());
4128 EXPECT_EQ(1, delegate->scroll_x()); 4010 EXPECT_EQ(1, delegate->scroll_x());
4129 EXPECT_EQ(0, delegate->scroll_x_hint()); 4011 EXPECT_EQ(0, delegate->scroll_x_hint());
4130 delegate->Reset(); 4012 delegate->Reset();
4131 } 4013 }
4132 4014
4133 TEST_P(GestureRecognizerTest, ScrollAlternatelyConsumedTest) { 4015 TEST_F(GestureRecognizerTest, ScrollAlternatelyConsumedTest) {
4134 scoped_ptr<QueueTouchEventDelegate> delegate( 4016 scoped_ptr<QueueTouchEventDelegate> delegate(
4135 new QueueTouchEventDelegate(host()->dispatcher())); 4017 new QueueTouchEventDelegate(host()->dispatcher()));
4136 TimedEvents tes; 4018 TimedEvents tes;
4137 const int kWindowWidth = 3000; 4019 const int kWindowWidth = 3000;
4138 const int kWindowHeight = 3000; 4020 const int kWindowHeight = 3000;
4139 const int kTouchId = 2; 4021 const int kTouchId = 2;
4140 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 4022 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
4141 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4023 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4142 delegate.get(), -1234, bounds, root_window())); 4024 delegate.get(), -1234, bounds, root_window()));
4143 4025
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4182 ui::TouchEvent move3( 4064 ui::TouchEvent move3(
4183 ui::ET_TOUCH_MOVED, gfx::Point(x, y), kTouchId, tes.Now()); 4065 ui::ET_TOUCH_MOVED, gfx::Point(x, y), kTouchId, tes.Now());
4184 DispatchEventUsingWindowDispatcher(&move3); 4066 DispatchEventUsingWindowDispatcher(&move3);
4185 delegate->ReceivedAckPreventDefaulted(); 4067 delegate->ReceivedAckPreventDefaulted();
4186 EXPECT_FALSE(delegate->scroll_begin()); 4068 EXPECT_FALSE(delegate->scroll_begin());
4187 EXPECT_FALSE(delegate->scroll_update()); 4069 EXPECT_FALSE(delegate->scroll_update());
4188 delegate->Reset(); 4070 delegate->Reset();
4189 } 4071 }
4190 } 4072 }
4191 4073
4192 TEST_P(GestureRecognizerTest, PinchAlternatelyConsumedTest) { 4074 TEST_F(GestureRecognizerTest, PinchAlternatelyConsumedTest) {
4193 // Disabled for unified GR due to differences in when scroll update is
4194 // sent. The Aura GR will never send a ScrollUpdate with a ScrollBegin, but
4195 // the unified GR will.
4196 if (UsingUnifiedGR())
4197 return;
4198
4199 scoped_ptr<QueueTouchEventDelegate> delegate( 4075 scoped_ptr<QueueTouchEventDelegate> delegate(
4200 new QueueTouchEventDelegate(host()->dispatcher())); 4076 new QueueTouchEventDelegate(host()->dispatcher()));
4201 TimedEvents tes; 4077 TimedEvents tes;
4202 const int kWindowWidth = 3000; 4078 const int kWindowWidth = 3000;
4203 const int kWindowHeight = 3000; 4079 const int kWindowHeight = 3000;
4204 const int kTouchId1 = 5; 4080 const int kTouchId1 = 5;
4205 const int kTouchId2 = 7; 4081 const int kTouchId2 = 7;
4206 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 4082 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
4207 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4083 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4208 delegate.get(), -1234, bounds, root_window())); 4084 delegate.get(), -1234, bounds, root_window()));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4272 EXPECT_FALSE(delegate->scroll_begin()); 4148 EXPECT_FALSE(delegate->scroll_begin());
4273 EXPECT_FALSE(delegate->scroll_update()); 4149 EXPECT_FALSE(delegate->scroll_update());
4274 EXPECT_FALSE(delegate->scroll_end()); 4150 EXPECT_FALSE(delegate->scroll_end());
4275 EXPECT_FALSE(delegate->pinch_begin()); 4151 EXPECT_FALSE(delegate->pinch_begin());
4276 EXPECT_FALSE(delegate->pinch_update()); 4152 EXPECT_FALSE(delegate->pinch_update());
4277 EXPECT_FALSE(delegate->pinch_end()); 4153 EXPECT_FALSE(delegate->pinch_end());
4278 delegate->Reset(); 4154 delegate->Reset();
4279 } 4155 }
4280 } 4156 }
4281 4157
4282 // Test that touch event flags are passed through to the gesture event.
4283 TEST_P(GestureRecognizerTest, GestureEventFlagsPassedFromTouchEvent) {
4284 scoped_ptr<GestureEventConsumeDelegate> delegate(
4285 new GestureEventConsumeDelegate());
4286 TimedEvents tes;
4287 const int kWindowWidth = 123;
4288 const int kWindowHeight = 45;
4289 const int kTouchId = 6;
4290 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
4291 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4292 delegate.get(), -1234, bounds, root_window()));
4293
4294 delegate->Reset();
4295
4296 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
4297 kTouchId, tes.Now());
4298 DispatchEventUsingWindowDispatcher(&press1);
4299 EXPECT_TRUE(delegate->tap_down());
4300
4301 int default_flags = delegate->flags();
4302
4303 ui::TouchEvent move1(
4304 ui::ET_TOUCH_MOVED, gfx::Point(397, 149), kTouchId, tes.LeapForward(50));
4305 move1.set_flags(992);
4306
4307 DispatchEventUsingWindowDispatcher(&move1);
4308 EXPECT_NE(default_flags, delegate->flags());
4309 }
4310
4311 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4312 GestureRecognizerTest,
4313 ::testing::Bool());
4314
4315 } // namespace test 4158 } // namespace test
4316 } // namespace aura 4159 } // 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