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

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

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 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
« no previous file with comments | « ui/aura/env.cc ('k') | ui/aura/input_state_lookup.h » ('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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 NOTREACHED(); 277 NOTREACHED();
278 } 278 }
279 if (wait_until_event_ == gesture->type() && run_loop_) { 279 if (wait_until_event_ == gesture->type() && run_loop_) {
280 run_loop_->Quit(); 280 run_loop_->Quit();
281 wait_until_event_ = ui::ET_UNKNOWN; 281 wait_until_event_ = ui::ET_UNKNOWN;
282 } 282 }
283 gesture->StopPropagation(); 283 gesture->StopPropagation();
284 } 284 }
285 285
286 private: 286 private:
287 scoped_ptr<base::RunLoop> run_loop_; 287 std::unique_ptr<base::RunLoop> run_loop_;
288 std::vector<ui::EventType> events_; 288 std::vector<ui::EventType> events_;
289 289
290 bool tap_; 290 bool tap_;
291 bool tap_down_; 291 bool tap_down_;
292 bool tap_cancel_; 292 bool tap_cancel_;
293 bool begin_; 293 bool begin_;
294 bool end_; 294 bool end_;
295 bool scroll_begin_; 295 bool scroll_begin_;
296 bool scroll_update_; 296 bool scroll_update_;
297 bool scroll_end_; 297 bool scroll_end_;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 original_gr_ = ui::GestureRecognizer::Get(); 467 original_gr_ = ui::GestureRecognizer::Get();
468 ui::SetGestureRecognizerForTesting(new_gr_.get()); 468 ui::SetGestureRecognizerForTesting(new_gr_.get());
469 } 469 }
470 470
471 virtual ~ScopedGestureRecognizerSetter() { 471 virtual ~ScopedGestureRecognizerSetter() {
472 ui::SetGestureRecognizerForTesting(original_gr_); 472 ui::SetGestureRecognizerForTesting(original_gr_);
473 } 473 }
474 474
475 private: 475 private:
476 ui::GestureRecognizer* original_gr_; 476 ui::GestureRecognizer* original_gr_;
477 scoped_ptr<ui::GestureRecognizer> new_gr_; 477 std::unique_ptr<ui::GestureRecognizer> new_gr_;
478 478
479 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter); 479 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter);
480 }; 480 };
481 481
482 class TimedEvents { 482 class TimedEvents {
483 private: 483 private:
484 int simulated_now_; 484 int simulated_now_;
485 485
486 public: 486 public:
487 // Use a non-zero start time to pass DCHECKs which ensure events have had a 487 // Use a non-zero start time to pass DCHECKs which ensure events have had a
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 switches::kCompensateForUnstablePinchZoom); 677 switches::kCompensateForUnstablePinchZoom);
678 ui::GestureConfiguration::GetInstance()->set_min_pinch_update_span_delta(5); 678 ui::GestureConfiguration::GetInstance()->set_min_pinch_update_span_delta(5);
679 } 679 }
680 680
681 private: 681 private:
682 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerWithSwitchTest); 682 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerWithSwitchTest);
683 }; 683 };
684 684
685 // Check that appropriate touch events generate tap gesture events. 685 // Check that appropriate touch events generate tap gesture events.
686 TEST_F(GestureRecognizerTest, GestureEventTap) { 686 TEST_F(GestureRecognizerTest, GestureEventTap) {
687 scoped_ptr<GestureEventConsumeDelegate> delegate( 687 std::unique_ptr<GestureEventConsumeDelegate> delegate(
688 new GestureEventConsumeDelegate()); 688 new GestureEventConsumeDelegate());
689 TimedEvents tes; 689 TimedEvents tes;
690 const int kWindowWidth = 123; 690 const int kWindowWidth = 123;
691 const int kWindowHeight = 45; 691 const int kWindowHeight = 45;
692 const int kTouchId = 2; 692 const int kTouchId = 2;
693 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 693 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
694 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 694 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
695 delegate.get(), -1234, bounds, root_window())); 695 delegate.get(), -1234, bounds, root_window()));
696 696
697 delegate->Reset(); 697 delegate->Reset();
698 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 698 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
699 kTouchId, tes.Now()); 699 kTouchId, tes.Now());
700 DispatchEventUsingWindowDispatcher(&press); 700 DispatchEventUsingWindowDispatcher(&press);
701 EXPECT_FALSE(delegate->tap()); 701 EXPECT_FALSE(delegate->tap());
702 EXPECT_FALSE(delegate->show_press()); 702 EXPECT_FALSE(delegate->show_press());
703 EXPECT_TRUE(delegate->tap_down()); 703 EXPECT_TRUE(delegate->tap_down());
704 EXPECT_FALSE(delegate->tap_cancel()); 704 EXPECT_FALSE(delegate->tap_cancel());
(...skipping 23 matching lines...) Expand all
728 EXPECT_FALSE(delegate->scroll_begin()); 728 EXPECT_FALSE(delegate->scroll_begin());
729 EXPECT_FALSE(delegate->scroll_update()); 729 EXPECT_FALSE(delegate->scroll_update());
730 EXPECT_FALSE(delegate->scroll_end()); 730 EXPECT_FALSE(delegate->scroll_end());
731 731
732 EXPECT_EQ(1, delegate->tap_count()); 732 EXPECT_EQ(1, delegate->tap_count());
733 } 733 }
734 734
735 // Check that appropriate touch events generate tap gesture events 735 // Check that appropriate touch events generate tap gesture events
736 // when information about the touch radii are provided. 736 // when information about the touch radii are provided.
737 TEST_F(GestureRecognizerTest, GestureEventTapRegion) { 737 TEST_F(GestureRecognizerTest, GestureEventTapRegion) {
738 scoped_ptr<GestureEventConsumeDelegate> delegate( 738 std::unique_ptr<GestureEventConsumeDelegate> delegate(
739 new GestureEventConsumeDelegate()); 739 new GestureEventConsumeDelegate());
740 TimedEvents tes; 740 TimedEvents tes;
741 const int kWindowWidth = 800; 741 const int kWindowWidth = 800;
742 const int kWindowHeight = 600; 742 const int kWindowHeight = 600;
743 const int kTouchId = 2; 743 const int kTouchId = 2;
744 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 744 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
745 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 745 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
746 delegate.get(), -1234, bounds, root_window())); 746 delegate.get(), -1234, bounds, root_window()));
747 747
748 // Test with no ET_TOUCH_MOVED events. 748 // Test with no ET_TOUCH_MOVED events.
749 { 749 {
750 delegate->Reset(); 750 delegate->Reset();
751 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 751 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
752 kTouchId, tes.Now()); 752 kTouchId, tes.Now());
753 SetTouchRadius(&press, 5, 12); 753 SetTouchRadius(&press, 5, 12);
754 DispatchEventUsingWindowDispatcher(&press); 754 DispatchEventUsingWindowDispatcher(&press);
755 EXPECT_FALSE(delegate->tap()); 755 EXPECT_FALSE(delegate->tap());
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 } 961 }
962 } 962 }
963 963
964 // Check that appropriate touch events generate scroll gesture events. 964 // Check that appropriate touch events generate scroll gesture events.
965 TEST_F(GestureRecognizerTest, GestureEventScroll) { 965 TEST_F(GestureRecognizerTest, GestureEventScroll) {
966 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of 966 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of
967 // that distance to be consumed by the slop, so we set the slop radius to 967 // that distance to be consumed by the slop, so we set the slop radius to
968 // sqrt(5 * 5 + 5 * 5). 968 // sqrt(5 * 5 + 5 * 5).
969 ui::GestureConfiguration::GetInstance() 969 ui::GestureConfiguration::GetInstance()
970 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5)); 970 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5));
971 scoped_ptr<GestureEventConsumeDelegate> delegate( 971 std::unique_ptr<GestureEventConsumeDelegate> delegate(
972 new GestureEventConsumeDelegate()); 972 new GestureEventConsumeDelegate());
973 TimedEvents tes; 973 TimedEvents tes;
974 const int kWindowWidth = 123; 974 const int kWindowWidth = 123;
975 const int kWindowHeight = 45; 975 const int kWindowHeight = 45;
976 const int kTouchId = 5; 976 const int kTouchId = 5;
977 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 977 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
978 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 978 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
979 delegate.get(), -1234, bounds, root_window())); 979 delegate.get(), -1234, bounds, root_window()));
980 980
981 delegate->Reset(); 981 delegate->Reset();
982 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 982 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
983 kTouchId, tes.Now()); 983 kTouchId, tes.Now());
984 DispatchEventUsingWindowDispatcher(&press); 984 DispatchEventUsingWindowDispatcher(&press);
985 EXPECT_2_EVENTS(delegate->events(), 985 EXPECT_2_EVENTS(delegate->events(),
986 ui::ET_GESTURE_BEGIN, 986 ui::ET_GESTURE_BEGIN,
987 ui::ET_GESTURE_TAP_DOWN); 987 ui::ET_GESTURE_TAP_DOWN);
988 988
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 } 1033 }
1034 1034
1035 // Check that predicted scroll update positions are correct. 1035 // Check that predicted scroll update positions are correct.
1036 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { 1036 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) {
1037 // We'll start by moving the touch point by (5, 5). We want all of that 1037 // We'll start by moving the touch point by (5, 5). We want all of that
1038 // distance to be consumed by the slop, so we set the slop radius to 1038 // distance to be consumed by the slop, so we set the slop radius to
1039 // sqrt(5 * 5 + 5 * 5). 1039 // sqrt(5 * 5 + 5 * 5).
1040 ui::GestureConfiguration::GetInstance() 1040 ui::GestureConfiguration::GetInstance()
1041 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5)); 1041 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5));
1042 1042
1043 scoped_ptr<GestureEventConsumeDelegate> delegate( 1043 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1044 new GestureEventConsumeDelegate()); 1044 new GestureEventConsumeDelegate());
1045 TimedEvents tes; 1045 TimedEvents tes;
1046 const int kWindowWidth = 123; 1046 const int kWindowWidth = 123;
1047 const int kWindowHeight = 45; 1047 const int kWindowHeight = 45;
1048 const int kTouchId = 5; 1048 const int kTouchId = 5;
1049 gfx::Rect bounds(95, 195, kWindowWidth, kWindowHeight); 1049 gfx::Rect bounds(95, 195, kWindowWidth, kWindowHeight);
1050 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1050 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1051 delegate.get(), -1234, bounds, root_window())); 1051 delegate.get(), -1234, bounds, root_window()));
1052 1052
1053 delegate->Reset(); 1053 delegate->Reset();
1054 // Tracks the total scroll since we want to verify that the correct position 1054 // Tracks the total scroll since we want to verify that the correct position
1055 // will be scrolled to throughout the prediction. 1055 // will be scrolled to throughout the prediction.
1056 gfx::Vector2dF total_scroll; 1056 gfx::Vector2dF total_scroll;
1057 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(96, 196), 1057 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(96, 196),
1058 kTouchId, tes.Now()); 1058 kTouchId, tes.Now());
1059 DispatchEventUsingWindowDispatcher(&press); 1059 DispatchEventUsingWindowDispatcher(&press);
1060 EXPECT_2_EVENTS(delegate->events(), 1060 EXPECT_2_EVENTS(delegate->events(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 kTouchId, 1103 kTouchId,
1104 tes.LeapForward(50)); 1104 tes.LeapForward(50));
1105 DispatchEventUsingWindowDispatcher(&release); 1105 DispatchEventUsingWindowDispatcher(&release);
1106 } 1106 }
1107 1107
1108 // Check that the bounding box during a scroll event is correct. 1108 // Check that the bounding box during a scroll event is correct.
1109 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { 1109 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) {
1110 TimedEvents tes; 1110 TimedEvents tes;
1111 for (int radius = 1; radius <= 10; ++radius) { 1111 for (int radius = 1; radius <= 10; ++radius) {
1112 ui::GestureConfiguration::GetInstance()->set_default_radius(radius); 1112 ui::GestureConfiguration::GetInstance()->set_default_radius(radius);
1113 scoped_ptr<GestureEventConsumeDelegate> delegate( 1113 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1114 new GestureEventConsumeDelegate()); 1114 new GestureEventConsumeDelegate());
1115 const int kWindowWidth = 123; 1115 const int kWindowWidth = 123;
1116 const int kWindowHeight = 45; 1116 const int kWindowHeight = 45;
1117 const int kTouchId = 5; 1117 const int kTouchId = 5;
1118 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1118 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1119 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1119 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1120 delegate.get(), -1234, bounds, root_window())); 1120 delegate.get(), -1234, bounds, root_window()));
1121 1121
1122 const int kPositionX = 101; 1122 const int kPositionX = 101;
1123 const int kPositionY = 201; 1123 const int kPositionY = 201;
1124 delegate->Reset(); 1124 delegate->Reset();
1125 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 1125 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
1126 gfx::Point(kPositionX, kPositionY), kTouchId, 1126 gfx::Point(kPositionX, kPositionY), kTouchId,
1127 tes.Now()); 1127 tes.Now());
1128 DispatchEventUsingWindowDispatcher(&press); 1128 DispatchEventUsingWindowDispatcher(&press);
1129 EXPECT_EQ(gfx::Rect(kPositionX - radius, kPositionY - radius, radius * 2, 1129 EXPECT_EQ(gfx::Rect(kPositionX - radius, kPositionY - radius, radius * 2,
(...skipping 21 matching lines...) Expand all
1151 gfx::Rect(kPositionX + kScrollAmount - radius, 1151 gfx::Rect(kPositionX + kScrollAmount - radius,
1152 kPositionY + kScrollAmount - radius, radius * 2, radius * 2), 1152 kPositionY + kScrollAmount - radius, radius * 2, radius * 2),
1153 delegate->bounding_box()); 1153 delegate->bounding_box());
1154 } 1154 }
1155 ui::GestureConfiguration::GetInstance()->set_default_radius(0); 1155 ui::GestureConfiguration::GetInstance()->set_default_radius(0);
1156 } 1156 }
1157 1157
1158 // Check Scroll End Events report correct velocities 1158 // Check Scroll End Events report correct velocities
1159 // if the user was on a horizontal rail 1159 // if the user was on a horizontal rail
1160 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { 1160 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) {
1161 scoped_ptr<GestureEventConsumeDelegate> delegate( 1161 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1162 new GestureEventConsumeDelegate()); 1162 new GestureEventConsumeDelegate());
1163 TimedEvents tes; 1163 TimedEvents tes;
1164 const int kTouchId = 7; 1164 const int kTouchId = 7;
1165 gfx::Rect bounds(0, 0, 1000, 1000); 1165 gfx::Rect bounds(0, 0, 1000, 1000);
1166 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1166 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1167 delegate.get(), -1234, bounds, root_window())); 1167 delegate.get(), -1234, bounds, root_window()));
1168 1168
1169 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1169 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1170 kTouchId, tes.Now()); 1170 kTouchId, tes.Now());
1171 DispatchEventUsingWindowDispatcher(&press); 1171 DispatchEventUsingWindowDispatcher(&press);
1172 1172
1173 // Get rid of touch slop. 1173 // Get rid of touch slop.
1174 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0), 1174 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0),
1175 kTouchId, tes.Now()); 1175 kTouchId, tes.Now());
1176 DispatchEventUsingWindowDispatcher(&move); 1176 DispatchEventUsingWindowDispatcher(&move);
(...skipping 25 matching lines...) Expand all
1202 1202
1203 EXPECT_TRUE(delegate->fling()); 1203 EXPECT_TRUE(delegate->fling());
1204 EXPECT_FALSE(delegate->scroll_end()); 1204 EXPECT_FALSE(delegate->scroll_end());
1205 EXPECT_GT(delegate->velocity_x(), 0); 1205 EXPECT_GT(delegate->velocity_x(), 0);
1206 EXPECT_EQ(0, delegate->velocity_y()); 1206 EXPECT_EQ(0, delegate->velocity_y());
1207 } 1207 }
1208 1208
1209 // Check Scroll End Events report correct velocities 1209 // Check Scroll End Events report correct velocities
1210 // if the user was on a vertical rail 1210 // if the user was on a vertical rail
1211 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { 1211 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
1212 scoped_ptr<GestureEventConsumeDelegate> delegate( 1212 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1213 new GestureEventConsumeDelegate()); 1213 new GestureEventConsumeDelegate());
1214 TimedEvents tes; 1214 TimedEvents tes;
1215 const int kTouchId = 7; 1215 const int kTouchId = 7;
1216 gfx::Rect bounds(0, 0, 1000, 1000); 1216 gfx::Rect bounds(0, 0, 1000, 1000);
1217 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1217 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1218 delegate.get(), -1234, bounds, root_window())); 1218 delegate.get(), -1234, bounds, root_window()));
1219 1219
1220 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1220 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1221 kTouchId, tes.Now()); 1221 kTouchId, tes.Now());
1222 DispatchEventUsingWindowDispatcher(&press); 1222 DispatchEventUsingWindowDispatcher(&press);
1223 1223
1224 // Get rid of touch slop. 1224 // Get rid of touch slop.
1225 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 10), 1225 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 10),
1226 kTouchId, tes.Now()); 1226 kTouchId, tes.Now());
1227 DispatchEventUsingWindowDispatcher(&move); 1227 DispatchEventUsingWindowDispatcher(&move);
(...skipping 28 matching lines...) Expand all
1256 EXPECT_FALSE(delegate->scroll_end()); 1256 EXPECT_FALSE(delegate->scroll_end());
1257 EXPECT_EQ(0, delegate->velocity_x()); 1257 EXPECT_EQ(0, delegate->velocity_x());
1258 EXPECT_GT(delegate->velocity_y(), 0); 1258 EXPECT_GT(delegate->velocity_y(), 0);
1259 } 1259 }
1260 1260
1261 // Check Scroll End Events report non-zero velocities if the user is not on a 1261 // Check Scroll End Events report non-zero velocities if the user is not on a
1262 // rail 1262 // rail
1263 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { 1263 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
1264 ui::GestureConfiguration::GetInstance() 1264 ui::GestureConfiguration::GetInstance()
1265 ->set_max_touch_move_in_pixels_for_click(0); 1265 ->set_max_touch_move_in_pixels_for_click(0);
1266 scoped_ptr<GestureEventConsumeDelegate> delegate( 1266 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1267 new GestureEventConsumeDelegate()); 1267 new GestureEventConsumeDelegate());
1268 TimedEvents tes; 1268 TimedEvents tes;
1269 const int kTouchId = 7; 1269 const int kTouchId = 7;
1270 gfx::Rect bounds(0, 0, 1000, 1000); 1270 gfx::Rect bounds(0, 0, 1000, 1000);
1271 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1271 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1272 delegate.get(), -1234, bounds, root_window())); 1272 delegate.get(), -1234, bounds, root_window()));
1273 1273
1274 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1274 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1275 kTouchId, tes.Now()); 1275 kTouchId, tes.Now());
1276 DispatchEventUsingWindowDispatcher(&press); 1276 DispatchEventUsingWindowDispatcher(&press);
1277 1277
1278 // Move the touch-point such that a non-rail scroll begins, and we're outside 1278 // Move the touch-point such that a non-rail scroll begins, and we're outside
1279 // the snap channel for the unified GR. 1279 // the snap channel for the unified GR.
1280 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get()); 1280 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get());
1281 EXPECT_EQ(50, delegate->scroll_y()); 1281 EXPECT_EQ(50, delegate->scroll_y());
(...skipping 16 matching lines...) Expand all
1298 DispatchEventUsingWindowDispatcher(&release); 1298 DispatchEventUsingWindowDispatcher(&release);
1299 1299
1300 EXPECT_TRUE(delegate->fling()); 1300 EXPECT_TRUE(delegate->fling());
1301 EXPECT_FALSE(delegate->scroll_end()); 1301 EXPECT_FALSE(delegate->scroll_end());
1302 EXPECT_GT(delegate->velocity_x(), 0); 1302 EXPECT_GT(delegate->velocity_x(), 0);
1303 EXPECT_GT(delegate->velocity_y(), 0); 1303 EXPECT_GT(delegate->velocity_y(), 0);
1304 } 1304 }
1305 1305
1306 // Check that appropriate touch events generate long press events 1306 // Check that appropriate touch events generate long press events
1307 TEST_F(GestureRecognizerTest, GestureEventLongPress) { 1307 TEST_F(GestureRecognizerTest, GestureEventLongPress) {
1308 scoped_ptr<GestureEventConsumeDelegate> delegate( 1308 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1309 new GestureEventConsumeDelegate()); 1309 new GestureEventConsumeDelegate());
1310 const int kWindowWidth = 123; 1310 const int kWindowWidth = 123;
1311 const int kWindowHeight = 45; 1311 const int kWindowHeight = 45;
1312 const int kTouchId = 2; 1312 const int kTouchId = 2;
1313 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1313 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1314 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1314 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1315 delegate.get(), -1234, bounds, root_window())); 1315 delegate.get(), -1234, bounds, root_window()));
1316 1316
1317 delegate->Reset(); 1317 delegate->Reset();
1318 1318
1319 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, 1319 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED,
1320 gfx::Point(101, 201), 1320 gfx::Point(101, 201),
1321 kTouchId, 1321 kTouchId,
1322 ui::EventTimeForNow()); 1322 ui::EventTimeForNow());
1323 DispatchEventUsingWindowDispatcher(&press1); 1323 DispatchEventUsingWindowDispatcher(&press1);
1324 EXPECT_TRUE(delegate->tap_down()); 1324 EXPECT_TRUE(delegate->tap_down());
(...skipping 16 matching lines...) Expand all
1341 DispatchEventUsingWindowDispatcher(&release1); 1341 DispatchEventUsingWindowDispatcher(&release1);
1342 EXPECT_FALSE(delegate->long_press()); 1342 EXPECT_FALSE(delegate->long_press());
1343 1343
1344 // Note the tap cancel isn't dispatched until the release 1344 // Note the tap cancel isn't dispatched until the release
1345 EXPECT_TRUE(delegate->tap_cancel()); 1345 EXPECT_TRUE(delegate->tap_cancel());
1346 EXPECT_FALSE(delegate->tap()); 1346 EXPECT_FALSE(delegate->tap());
1347 } 1347 }
1348 1348
1349 // Check that scrolling prevents a long press. 1349 // Check that scrolling prevents a long press.
1350 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { 1350 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
1351 scoped_ptr<GestureEventConsumeDelegate> delegate( 1351 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1352 new GestureEventConsumeDelegate()); 1352 new GestureEventConsumeDelegate());
1353 TimedEvents tes; 1353 TimedEvents tes;
1354 const int kWindowWidth = 123; 1354 const int kWindowWidth = 123;
1355 const int kWindowHeight = 45; 1355 const int kWindowHeight = 45;
1356 const int kTouchId = 6; 1356 const int kTouchId = 6;
1357 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1357 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1358 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1358 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1359 delegate.get(), -1234, bounds, root_window())); 1359 delegate.get(), -1234, bounds, root_window()));
1360 1360
1361 delegate->Reset(); 1361 delegate->Reset();
1362 1362
1363 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1363 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1364 kTouchId, tes.Now()); 1364 kTouchId, tes.Now());
1365 DispatchEventUsingWindowDispatcher(&press1); 1365 DispatchEventUsingWindowDispatcher(&press1);
1366 EXPECT_TRUE(delegate->tap_down()); 1366 EXPECT_TRUE(delegate->tap_down());
1367 1367
1368 // We haven't pressed long enough for a long press to occur 1368 // We haven't pressed long enough for a long press to occur
(...skipping 15 matching lines...) Expand all
1384 kTouchId, tes.LeapForward(10)); 1384 kTouchId, tes.LeapForward(10));
1385 DispatchEventUsingWindowDispatcher(&release1); 1385 DispatchEventUsingWindowDispatcher(&release1);
1386 EXPECT_FALSE(delegate->long_press()); 1386 EXPECT_FALSE(delegate->long_press());
1387 EXPECT_FALSE(delegate->tap_cancel()); 1387 EXPECT_FALSE(delegate->tap_cancel());
1388 } 1388 }
1389 1389
1390 // Check that appropriate touch events generate long tap events 1390 // Check that appropriate touch events generate long tap events
1391 TEST_F(GestureRecognizerTest, GestureEventLongTap) { 1391 TEST_F(GestureRecognizerTest, GestureEventLongTap) {
1392 ui::GestureConfiguration::GetInstance() 1392 ui::GestureConfiguration::GetInstance()
1393 ->set_max_touch_down_duration_for_click_in_ms(3); 1393 ->set_max_touch_down_duration_for_click_in_ms(3);
1394 scoped_ptr<GestureEventConsumeDelegate> delegate( 1394 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1395 new GestureEventConsumeDelegate()); 1395 new GestureEventConsumeDelegate());
1396 const int kWindowWidth = 123; 1396 const int kWindowWidth = 123;
1397 const int kWindowHeight = 45; 1397 const int kWindowHeight = 45;
1398 const int kTouchId = 2; 1398 const int kTouchId = 2;
1399 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1399 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1400 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1400 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1401 delegate.get(), -1234, bounds, root_window())); 1401 delegate.get(), -1234, bounds, root_window()));
1402 1402
1403 delegate->Reset(); 1403 delegate->Reset();
1404 1404
1405 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, 1405 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED,
1406 gfx::Point(101, 201), 1406 gfx::Point(101, 201),
1407 kTouchId, 1407 kTouchId,
1408 ui::EventTimeForNow()); 1408 ui::EventTimeForNow());
1409 DispatchEventUsingWindowDispatcher(&press1); 1409 DispatchEventUsingWindowDispatcher(&press1);
1410 EXPECT_TRUE(delegate->tap_down()); 1410 EXPECT_TRUE(delegate->tap_down());
(...skipping 17 matching lines...) Expand all
1428 EXPECT_FALSE(delegate->long_press()); 1428 EXPECT_FALSE(delegate->long_press());
1429 EXPECT_TRUE(delegate->long_tap()); 1429 EXPECT_TRUE(delegate->long_tap());
1430 1430
1431 // Note the tap cancel isn't dispatched until the release 1431 // Note the tap cancel isn't dispatched until the release
1432 EXPECT_TRUE(delegate->tap_cancel()); 1432 EXPECT_TRUE(delegate->tap_cancel());
1433 EXPECT_FALSE(delegate->tap()); 1433 EXPECT_FALSE(delegate->tap());
1434 } 1434 }
1435 1435
1436 // Check that second tap cancels a long press 1436 // Check that second tap cancels a long press
1437 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { 1437 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
1438 scoped_ptr<GestureEventConsumeDelegate> delegate( 1438 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1439 new GestureEventConsumeDelegate()); 1439 new GestureEventConsumeDelegate());
1440 TimedEvents tes; 1440 TimedEvents tes;
1441 const int kWindowWidth = 300; 1441 const int kWindowWidth = 300;
1442 const int kWindowHeight = 400; 1442 const int kWindowHeight = 400;
1443 const int kTouchId1 = 8; 1443 const int kTouchId1 = 8;
1444 const int kTouchId2 = 2; 1444 const int kTouchId2 = 2;
1445 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1445 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1446 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1446 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1447 delegate.get(), -1234, bounds, root_window())); 1447 delegate.get(), -1234, bounds, root_window()));
1448 1448
1449 delegate->Reset(); 1449 delegate->Reset();
1450 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1450 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1451 kTouchId1, tes.Now()); 1451 kTouchId1, tes.Now());
1452 DispatchEventUsingWindowDispatcher(&press); 1452 DispatchEventUsingWindowDispatcher(&press);
1453 EXPECT_TRUE(delegate->tap_down()); 1453 EXPECT_TRUE(delegate->tap_down());
1454 EXPECT_TRUE(delegate->begin()); 1454 EXPECT_TRUE(delegate->begin());
1455 1455
1456 // We haven't pressed long enough for a long press to occur 1456 // We haven't pressed long enough for a long press to occur
(...skipping 19 matching lines...) Expand all
1476 kTouchId1, tes.Now()); 1476 kTouchId1, tes.Now());
1477 DispatchEventUsingWindowDispatcher(&release1); 1477 DispatchEventUsingWindowDispatcher(&release1);
1478 EXPECT_FALSE(delegate->long_press()); 1478 EXPECT_FALSE(delegate->long_press());
1479 EXPECT_TRUE(delegate->two_finger_tap()); 1479 EXPECT_TRUE(delegate->two_finger_tap());
1480 EXPECT_FALSE(delegate->tap_cancel()); 1480 EXPECT_FALSE(delegate->tap_cancel());
1481 } 1481 }
1482 1482
1483 // Check that horizontal scroll gestures cause scrolls on horizontal rails. 1483 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1484 // Also tests that horizontal rails can be broken. 1484 // Also tests that horizontal rails can be broken.
1485 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { 1485 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
1486 scoped_ptr<GestureEventConsumeDelegate> delegate( 1486 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1487 new GestureEventConsumeDelegate()); 1487 new GestureEventConsumeDelegate());
1488 TimedEvents tes; 1488 TimedEvents tes;
1489 const int kTouchId = 7; 1489 const int kTouchId = 7;
1490 gfx::Rect bounds(0, 0, 1000, 1000); 1490 gfx::Rect bounds(0, 0, 1000, 1000);
1491 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1491 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1492 delegate.get(), -1234, bounds, root_window())); 1492 delegate.get(), -1234, bounds, root_window()));
1493 1493
1494 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1494 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1495 kTouchId, tes.Now()); 1495 kTouchId, tes.Now());
1496 DispatchEventUsingWindowDispatcher(&press); 1496 DispatchEventUsingWindowDispatcher(&press);
1497 1497
1498 // Get rid of touch slop. 1498 // Get rid of touch slop.
1499 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0), 1499 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0),
1500 kTouchId, tes.Now()); 1500 kTouchId, tes.Now());
1501 1501
(...skipping 30 matching lines...) Expand all
1532 1532
1533 // The rail should be broken 1533 // The rail should be broken
1534 EXPECT_TRUE(delegate->scroll_update()); 1534 EXPECT_TRUE(delegate->scroll_update());
1535 EXPECT_EQ(5, delegate->scroll_x()); 1535 EXPECT_EQ(5, delegate->scroll_x());
1536 EXPECT_EQ(5, delegate->scroll_y()); 1536 EXPECT_EQ(5, delegate->scroll_y());
1537 } 1537 }
1538 1538
1539 // Check that vertical scroll gestures cause scrolls on vertical rails. 1539 // Check that vertical scroll gestures cause scrolls on vertical rails.
1540 // Also tests that vertical rails can be broken. 1540 // Also tests that vertical rails can be broken.
1541 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { 1541 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
1542 scoped_ptr<GestureEventConsumeDelegate> delegate( 1542 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1543 new GestureEventConsumeDelegate()); 1543 new GestureEventConsumeDelegate());
1544 TimedEvents tes; 1544 TimedEvents tes;
1545 const int kTouchId = 7; 1545 const int kTouchId = 7;
1546 gfx::Rect bounds(0, 0, 1000, 1000); 1546 gfx::Rect bounds(0, 0, 1000, 1000);
1547 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1547 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1548 delegate.get(), -1234, bounds, root_window())); 1548 delegate.get(), -1234, bounds, root_window()));
1549 1549
1550 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1550 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1551 kTouchId, tes.Now()); 1551 kTouchId, tes.Now());
1552 DispatchEventUsingWindowDispatcher(&press); 1552 DispatchEventUsingWindowDispatcher(&press);
1553 1553
1554 // Get rid of touch slop. 1554 // Get rid of touch slop.
1555 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5), 1555 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5),
1556 kTouchId, tes.Now()); 1556 kTouchId, tes.Now());
1557 DispatchEventUsingWindowDispatcher(&move); 1557 DispatchEventUsingWindowDispatcher(&move);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 } 1593 }
1594 1594
1595 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { 1595 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
1596 // We'll start by moving the touch point by (5, 5). We want all of that 1596 // We'll start by moving the touch point by (5, 5). We want all of that
1597 // distance to be consumed by the slop, so we set the slop radius to 1597 // distance to be consumed by the slop, so we set the slop radius to
1598 // sqrt(5 * 5 + 5 * 5). 1598 // sqrt(5 * 5 + 5 * 5).
1599 ui::GestureConfiguration::GetInstance() 1599 ui::GestureConfiguration::GetInstance()
1600 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5)); 1600 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5));
1601 1601
1602 // First, tap. Then, do a scroll using the same touch-id. 1602 // First, tap. Then, do a scroll using the same touch-id.
1603 scoped_ptr<GestureEventConsumeDelegate> delegate( 1603 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1604 new GestureEventConsumeDelegate()); 1604 new GestureEventConsumeDelegate());
1605 TimedEvents tes; 1605 TimedEvents tes;
1606 const int kWindowWidth = 123; 1606 const int kWindowWidth = 123;
1607 const int kWindowHeight = 45; 1607 const int kWindowHeight = 45;
1608 const int kTouchId = 3; 1608 const int kTouchId = 3;
1609 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1609 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1610 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1610 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1611 delegate.get(), -1234, bounds, root_window())); 1611 delegate.get(), -1234, bounds, root_window()));
1612 1612
1613 delegate->Reset(); 1613 delegate->Reset();
1614 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1614 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1615 kTouchId, tes.Now()); 1615 kTouchId, tes.Now());
1616 DispatchEventUsingWindowDispatcher(&press); 1616 DispatchEventUsingWindowDispatcher(&press);
1617 EXPECT_FALSE(delegate->tap()); 1617 EXPECT_FALSE(delegate->tap());
1618 EXPECT_TRUE(delegate->tap_down()); 1618 EXPECT_TRUE(delegate->tap_down());
1619 EXPECT_FALSE(delegate->tap_cancel()); 1619 EXPECT_FALSE(delegate->tap_cancel());
1620 EXPECT_FALSE(delegate->scroll_begin()); 1620 EXPECT_FALSE(delegate->scroll_begin());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 EXPECT_FALSE(delegate->tap()); 1713 EXPECT_FALSE(delegate->tap());
1714 EXPECT_FALSE(delegate->tap_down()); 1714 EXPECT_FALSE(delegate->tap_down());
1715 EXPECT_FALSE(delegate->tap_cancel()); 1715 EXPECT_FALSE(delegate->tap_cancel());
1716 EXPECT_FALSE(delegate->scroll_begin()); 1716 EXPECT_FALSE(delegate->scroll_begin());
1717 EXPECT_FALSE(delegate->scroll_update()); 1717 EXPECT_FALSE(delegate->scroll_update());
1718 EXPECT_FALSE(delegate->scroll_end()); 1718 EXPECT_FALSE(delegate->scroll_end());
1719 EXPECT_TRUE(delegate->fling()); 1719 EXPECT_TRUE(delegate->fling());
1720 } 1720 }
1721 1721
1722 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { 1722 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
1723 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 1723 std::unique_ptr<QueueTouchEventDelegate> queued_delegate(
1724 new QueueTouchEventDelegate(host()->dispatcher())); 1724 new QueueTouchEventDelegate(host()->dispatcher()));
1725 TimedEvents tes; 1725 TimedEvents tes;
1726 const int kWindowWidth = 123; 1726 const int kWindowWidth = 123;
1727 const int kWindowHeight = 45; 1727 const int kWindowHeight = 45;
1728 const int kTouchId1 = 6; 1728 const int kTouchId1 = 6;
1729 const int kTouchId2 = 4; 1729 const int kTouchId2 = 4;
1730 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1730 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1731 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 1731 std::unique_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
1732 queued_delegate.get(), -1234, bounds, root_window())); 1732 queued_delegate.get(), -1234, bounds, root_window()));
1733 1733
1734 queued_delegate->set_window(queue.get()); 1734 queued_delegate->set_window(queue.get());
1735 1735
1736 // Touch down on the window. This should not generate any gesture event. 1736 // Touch down on the window. This should not generate any gesture event.
1737 queued_delegate->Reset(); 1737 queued_delegate->Reset();
1738 ui::TouchEvent press( 1738 ui::TouchEvent press(
1739 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now()); 1739 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now());
1740 DispatchEventUsingWindowDispatcher(&press); 1740 DispatchEventUsingWindowDispatcher(&press);
1741 EXPECT_FALSE(queued_delegate->tap()); 1741 EXPECT_FALSE(queued_delegate->tap());
(...skipping 17 matching lines...) Expand all
1759 EXPECT_FALSE(queued_delegate->tap_down()); 1759 EXPECT_FALSE(queued_delegate->tap_down());
1760 EXPECT_FALSE(queued_delegate->tap_cancel()); 1760 EXPECT_FALSE(queued_delegate->tap_cancel());
1761 EXPECT_FALSE(queued_delegate->begin()); 1761 EXPECT_FALSE(queued_delegate->begin());
1762 EXPECT_FALSE(queued_delegate->end()); 1762 EXPECT_FALSE(queued_delegate->end());
1763 EXPECT_FALSE(queued_delegate->scroll_begin()); 1763 EXPECT_FALSE(queued_delegate->scroll_begin());
1764 EXPECT_FALSE(queued_delegate->scroll_update()); 1764 EXPECT_FALSE(queued_delegate->scroll_update());
1765 EXPECT_FALSE(queued_delegate->scroll_end()); 1765 EXPECT_FALSE(queued_delegate->scroll_end());
1766 1766
1767 // Create another window, and place a touch-down on it. This should create a 1767 // Create another window, and place a touch-down on it. This should create a
1768 // tap-down gesture. 1768 // tap-down gesture.
1769 scoped_ptr<GestureEventConsumeDelegate> delegate( 1769 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1770 new GestureEventConsumeDelegate()); 1770 new GestureEventConsumeDelegate());
1771 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1771 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1772 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window())); 1772 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window()));
1773 delegate->Reset(); 1773 delegate->Reset();
1774 ui::TouchEvent press2( 1774 ui::TouchEvent press2(
1775 ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), kTouchId2, tes.Now()); 1775 ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), kTouchId2, tes.Now());
1776 DispatchEventUsingWindowDispatcher(&press2); 1776 DispatchEventUsingWindowDispatcher(&press2);
1777 EXPECT_FALSE(delegate->tap()); 1777 EXPECT_FALSE(delegate->tap());
1778 EXPECT_TRUE(delegate->tap_down()); 1778 EXPECT_TRUE(delegate->tap_down());
1779 EXPECT_FALSE(delegate->tap_cancel()); 1779 EXPECT_FALSE(delegate->tap_cancel());
1780 EXPECT_FALSE(queued_delegate->begin()); 1780 EXPECT_FALSE(queued_delegate->begin());
1781 EXPECT_FALSE(queued_delegate->end()); 1781 EXPECT_FALSE(queued_delegate->end());
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 1912
1913 EXPECT_TRUE(queued_delegate->scroll_update()); 1913 EXPECT_TRUE(queued_delegate->scroll_update());
1914 EXPECT_FALSE(queued_delegate->scroll_end()); 1914 EXPECT_FALSE(queued_delegate->scroll_end());
1915 EXPECT_TRUE(queued_delegate->pinch_begin()); 1915 EXPECT_TRUE(queued_delegate->pinch_begin());
1916 EXPECT_FALSE(queued_delegate->pinch_update()); 1916 EXPECT_FALSE(queued_delegate->pinch_update());
1917 EXPECT_FALSE(queued_delegate->pinch_end()); 1917 EXPECT_FALSE(queued_delegate->pinch_end());
1918 } 1918 }
1919 1919
1920 // Check that appropriate touch events generate pinch gesture events. 1920 // Check that appropriate touch events generate pinch gesture events.
1921 TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) { 1921 TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) {
1922 scoped_ptr<GestureEventConsumeDelegate> delegate( 1922 std::unique_ptr<GestureEventConsumeDelegate> delegate(
1923 new GestureEventConsumeDelegate()); 1923 new GestureEventConsumeDelegate());
1924 TimedEvents tes; 1924 TimedEvents tes;
1925 const int kWindowWidth = 300; 1925 const int kWindowWidth = 300;
1926 const int kWindowHeight = 400; 1926 const int kWindowHeight = 400;
1927 const int kTouchId1 = 5; 1927 const int kTouchId1 = 5;
1928 const int kTouchId2 = 3; 1928 const int kTouchId2 = 3;
1929 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1929 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1930 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1930 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1931 delegate.get(), -1234, bounds, root_window())); 1931 delegate.get(), -1234, bounds, root_window()));
1932 1932
1933 delegate->Reset(); 1933 delegate->Reset();
1934 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1934 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1935 kTouchId1, tes.Now()); 1935 kTouchId1, tes.Now());
1936 DispatchEventUsingWindowDispatcher(&press); 1936 DispatchEventUsingWindowDispatcher(&press);
1937 EXPECT_2_EVENTS(delegate->events(), 1937 EXPECT_2_EVENTS(delegate->events(),
1938 ui::ET_GESTURE_BEGIN, 1938 ui::ET_GESTURE_BEGIN,
1939 ui::ET_GESTURE_TAP_DOWN); 1939 ui::ET_GESTURE_TAP_DOWN);
1940 1940
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 // Move the second finger. This should still generate a scroll. 1995 // Move the second finger. This should still generate a scroll.
1996 delegate->Reset(); 1996 delegate->Reset();
1997 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1997 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
1998 kTouchId2, tes.Now()); 1998 kTouchId2, tes.Now());
1999 DispatchEventUsingWindowDispatcher(&move5); 1999 DispatchEventUsingWindowDispatcher(&move5);
2000 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 2000 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
2001 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2001 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
2002 } 2002 }
2003 2003
2004 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { 2004 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
2005 scoped_ptr<GestureEventConsumeDelegate> delegate( 2005 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2006 new GestureEventConsumeDelegate()); 2006 new GestureEventConsumeDelegate());
2007 TimedEvents tes; 2007 TimedEvents tes;
2008 const int kWindowWidth = 300; 2008 const int kWindowWidth = 300;
2009 const int kWindowHeight = 400; 2009 const int kWindowHeight = 400;
2010 const int kTouchId1 = 5; 2010 const int kTouchId1 = 5;
2011 const int kTouchId2 = 3; 2011 const int kTouchId2 = 3;
2012 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 2012 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
2013 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2013 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2014 delegate.get(), -1234, bounds, root_window())); 2014 delegate.get(), -1234, bounds, root_window()));
2015 2015
2016 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 2016 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
2017 kTouchId1, tes.Now()); 2017 kTouchId1, tes.Now());
2018 DispatchEventUsingWindowDispatcher(&press); 2018 DispatchEventUsingWindowDispatcher(&press);
2019 delegate->Reset(); 2019 delegate->Reset();
2020 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2020 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
2021 kTouchId2, tes.Now()); 2021 kTouchId2, tes.Now());
2022 DispatchEventUsingWindowDispatcher(&press2); 2022 DispatchEventUsingWindowDispatcher(&press2);
2023 EXPECT_FALSE(delegate->pinch_begin()); 2023 EXPECT_FALSE(delegate->pinch_begin());
(...skipping 28 matching lines...) Expand all
2052 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50), 2052 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50),
2053 kTouchId1, tes.Now()); 2053 kTouchId1, tes.Now());
2054 DispatchEventUsingWindowDispatcher(&move2); 2054 DispatchEventUsingWindowDispatcher(&move2);
2055 EXPECT_TRUE(delegate->pinch_begin()); 2055 EXPECT_TRUE(delegate->pinch_begin());
2056 2056
2057 tes.SendScrollEvent(event_processor(), 350, 350, kTouchId1, delegate.get()); 2057 tes.SendScrollEvent(event_processor(), 350, 350, kTouchId1, delegate.get());
2058 EXPECT_TRUE(delegate->pinch_update()); 2058 EXPECT_TRUE(delegate->pinch_update());
2059 } 2059 }
2060 2060
2061 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { 2061 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
2062 scoped_ptr<GestureEventConsumeDelegate> delegate( 2062 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2063 new GestureEventConsumeDelegate()); 2063 new GestureEventConsumeDelegate());
2064 TimedEvents tes; 2064 TimedEvents tes;
2065 const int kWindowWidth = 300; 2065 const int kWindowWidth = 300;
2066 const int kWindowHeight = 400; 2066 const int kWindowHeight = 400;
2067 const int kTouchId1 = 3; 2067 const int kTouchId1 = 3;
2068 const int kTouchId2 = 5; 2068 const int kTouchId2 = 5;
2069 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 2069 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
2070 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2070 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2071 delegate.get(), -1234, bounds, root_window())); 2071 delegate.get(), -1234, bounds, root_window()));
2072 2072
2073 delegate->Reset(); 2073 delegate->Reset();
2074 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 2074 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
2075 kTouchId1, tes.Now()); 2075 kTouchId1, tes.Now());
2076 DispatchEventUsingWindowDispatcher(&press); 2076 DispatchEventUsingWindowDispatcher(&press);
2077 EXPECT_2_EVENTS(delegate->events(), 2077 EXPECT_2_EVENTS(delegate->events(),
2078 ui::ET_GESTURE_BEGIN, 2078 ui::ET_GESTURE_BEGIN,
2079 ui::ET_GESTURE_TAP_DOWN); 2079 ui::ET_GESTURE_TAP_DOWN);
2080 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2080 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 // Move the second finger. This should still generate a scroll. 2127 // Move the second finger. This should still generate a scroll.
2128 delegate->Reset(); 2128 delegate->Reset();
2129 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 2129 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
2130 kTouchId2, tes.Now()); 2130 kTouchId2, tes.Now());
2131 DispatchEventUsingWindowDispatcher(&move5); 2131 DispatchEventUsingWindowDispatcher(&move5);
2132 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 2132 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
2133 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2133 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
2134 } 2134 }
2135 2135
2136 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { 2136 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
2137 scoped_ptr<GestureEventConsumeDelegate> delegate( 2137 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2138 new GestureEventConsumeDelegate()); 2138 new GestureEventConsumeDelegate());
2139 TimedEvents tes; 2139 TimedEvents tes;
2140 2140
2141 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2141 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2142 6, tes.Now()); 2142 6, tes.Now());
2143 DispatchEventUsingWindowDispatcher(&release1); 2143 DispatchEventUsingWindowDispatcher(&release1);
2144 EXPECT_FALSE(delegate->tap()); 2144 EXPECT_FALSE(delegate->tap());
2145 EXPECT_FALSE(delegate->tap_down()); 2145 EXPECT_FALSE(delegate->tap_down());
2146 } 2146 }
2147 2147
2148 // Check that a touch is locked to the window of the closest current touch 2148 // Check that a touch is locked to the window of the closest current touch
2149 // within max_separation_for_gesture_touches_in_pixels 2149 // within max_separation_for_gesture_touches_in_pixels
2150 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { 2150 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
2151 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl(); 2151 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl();
2152 TimedEvents tes; 2152 TimedEvents tes;
2153 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2153 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2154 2154
2155 ui::GestureConsumer* target; 2155 ui::GestureConsumer* target;
2156 const int kNumWindows = 4; 2156 const int kNumWindows = 4;
2157 2157
2158 scoped_ptr<GestureEventConsumeDelegate*[]> delegates( 2158 std::unique_ptr<GestureEventConsumeDelegate* []> delegates(
2159 new GestureEventConsumeDelegate*[kNumWindows]); 2159 new GestureEventConsumeDelegate*[kNumWindows]);
2160 2160
2161 ui::GestureConfiguration::GetInstance() 2161 ui::GestureConfiguration::GetInstance()
2162 ->set_max_separation_for_gesture_touches_in_pixels(499); 2162 ->set_max_separation_for_gesture_touches_in_pixels(499);
2163 2163
2164 scoped_ptr<gfx::Rect[]> window_bounds(new gfx::Rect[kNumWindows]); 2164 std::unique_ptr<gfx::Rect[]> window_bounds(new gfx::Rect[kNumWindows]);
2165 window_bounds[0] = gfx::Rect(0, 0, 1, 1); 2165 window_bounds[0] = gfx::Rect(0, 0, 1, 1);
2166 window_bounds[1] = gfx::Rect(500, 0, 1, 1); 2166 window_bounds[1] = gfx::Rect(500, 0, 1, 1);
2167 window_bounds[2] = gfx::Rect(0, 500, 1, 1); 2167 window_bounds[2] = gfx::Rect(0, 500, 1, 1);
2168 window_bounds[3] = gfx::Rect(500, 500, 1, 1); 2168 window_bounds[3] = gfx::Rect(500, 500, 1, 1);
2169 2169
2170 scoped_ptr<aura::Window*[]> windows(new aura::Window*[kNumWindows]); 2170 std::unique_ptr<aura::Window* []> windows(new aura::Window*[kNumWindows]);
2171 2171
2172 // Instantiate windows with |window_bounds| and touch each window at 2172 // Instantiate windows with |window_bounds| and touch each window at
2173 // its origin. 2173 // its origin.
2174 for (int i = 0; i < kNumWindows; ++i) { 2174 for (int i = 0; i < kNumWindows; ++i) {
2175 delegates[i] = new GestureEventConsumeDelegate(); 2175 delegates[i] = new GestureEventConsumeDelegate();
2176 windows[i] = CreateTestWindowWithDelegate( 2176 windows[i] = CreateTestWindowWithDelegate(
2177 delegates[i], i, window_bounds[i], root_window()); 2177 delegates[i], i, window_bounds[i], root_window());
2178 windows[i]->set_id(i); 2178 windows[i]->set_id(i);
2179 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(), 2179 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(),
2180 i, tes.Now()); 2180 i, tes.Now());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 for (int i = 0; i < kNumWindows; ++i) { 2236 for (int i = 0; i < kNumWindows; ++i) {
2237 // Delete windows before deleting delegates. 2237 // Delete windows before deleting delegates.
2238 delete windows[i]; 2238 delete windows[i];
2239 delete delegates[i]; 2239 delete delegates[i];
2240 } 2240 }
2241 } 2241 }
2242 2242
2243 // Check that a touch's target will not be effected by a touch on a different 2243 // Check that a touch's target will not be effected by a touch on a different
2244 // screen. 2244 // screen.
2245 TEST_F(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) { 2245 TEST_F(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) {
2246 scoped_ptr<GestureEventConsumeDelegate> delegate( 2246 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2247 new GestureEventConsumeDelegate()); 2247 new GestureEventConsumeDelegate());
2248 gfx::Rect bounds(0, 0, 10, 10); 2248 gfx::Rect bounds(0, 0, 10, 10);
2249 scoped_ptr<aura::Window> window( 2249 std::unique_ptr<aura::Window> window(
2250 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); 2250 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
2251 2251
2252 const int kTouchId1 = 8; 2252 const int kTouchId1 = 8;
2253 const int kTouchId2 = 2; 2253 const int kTouchId2 = 2;
2254 TimedEvents tes; 2254 TimedEvents tes;
2255 2255
2256 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5), 2256 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5),
2257 kTouchId1, tes.Now()); 2257 kTouchId1, tes.Now());
2258 ui::EventTestApi test_press1(&press1); 2258 ui::EventTestApi test_press1(&press1);
2259 test_press1.set_source_device_id(1); 2259 test_press1.set_source_device_id(1);
2260 DispatchEventUsingWindowDispatcher(&press1); 2260 DispatchEventUsingWindowDispatcher(&press1);
2261 2261
2262 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2262 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2263 kTouchId2, tes.Now()); 2263 kTouchId2, tes.Now());
2264 ui::EventTestApi test_press2(&press2); 2264 ui::EventTestApi test_press2(&press2);
2265 test_press2.set_source_device_id(2); 2265 test_press2.set_source_device_id(2);
2266 DispatchEventUsingWindowDispatcher(&press2); 2266 DispatchEventUsingWindowDispatcher(&press2);
2267 2267
2268 // The second press should not have been locked to the same target as the 2268 // The second press should not have been locked to the same target as the
2269 // first, as they occured on different displays. 2269 // first, as they occured on different displays.
2270 EXPECT_NE( 2270 EXPECT_NE(
2271 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1), 2271 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1),
2272 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)); 2272 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
2273 } 2273 }
2274 2274
2275 // Check that touch events outside the root window are still handled 2275 // Check that touch events outside the root window are still handled
2276 // by the root window's gesture sequence. 2276 // by the root window's gesture sequence.
2277 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { 2277 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
2278 TimedEvents tes; 2278 TimedEvents tes;
2279 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( 2279 std::unique_ptr<aura::Window> window(CreateTestWindowWithBounds(
2280 gfx::Rect(-100, -100, 2000, 2000), root_window())); 2280 gfx::Rect(-100, -100, 2000, 2000), root_window()));
2281 2281
2282 gfx::Point pos1(-10, -10); 2282 gfx::Point pos1(-10, -10);
2283 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now()); 2283 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now());
2284 DispatchEventUsingWindowDispatcher(&press1); 2284 DispatchEventUsingWindowDispatcher(&press1);
2285 2285
2286 gfx::Point pos2(1000, 1000); 2286 gfx::Point pos2(1000, 1000);
2287 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, tes.Now()); 2287 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, tes.Now());
2288 DispatchEventUsingWindowDispatcher(&press2); 2288 DispatchEventUsingWindowDispatcher(&press2);
2289 2289
2290 // As these presses were outside the root window, they should be 2290 // As these presses were outside the root window, they should be
2291 // associated with the root window. 2291 // associated with the root window.
2292 EXPECT_EQ(root_window(), 2292 EXPECT_EQ(root_window(),
2293 static_cast<aura::Window*>( 2293 static_cast<aura::Window*>(
2294 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1))); 2294 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1)));
2295 EXPECT_EQ(root_window(), 2295 EXPECT_EQ(root_window(),
2296 static_cast<aura::Window*>( 2296 static_cast<aura::Window*>(
2297 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2))); 2297 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)));
2298 } 2298 }
2299 2299
2300 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { 2300 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
2301 scoped_ptr<QueueTouchEventDelegate> delegate( 2301 std::unique_ptr<QueueTouchEventDelegate> delegate(
2302 new QueueTouchEventDelegate(host()->dispatcher())); 2302 new QueueTouchEventDelegate(host()->dispatcher()));
2303 TimedEvents tes; 2303 TimedEvents tes;
2304 const int kTouchId = 2; 2304 const int kTouchId = 2;
2305 gfx::Rect bounds(100, 200, 100, 100); 2305 gfx::Rect bounds(100, 200, 100, 100);
2306 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2306 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2307 delegate.get(), -1234, bounds, root_window())); 2307 delegate.get(), -1234, bounds, root_window()));
2308 delegate->set_window(window.get()); 2308 delegate->set_window(window.get());
2309 2309
2310 delegate->Reset(); 2310 delegate->Reset();
2311 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2311 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2312 kTouchId, tes.Now()); 2312 kTouchId, tes.Now());
2313 DispatchEventUsingWindowDispatcher(&press); 2313 DispatchEventUsingWindowDispatcher(&press);
2314 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2314 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2315 kTouchId, tes.LeapForward(50)); 2315 kTouchId, tes.LeapForward(50));
2316 DispatchEventUsingWindowDispatcher(&release); 2316 DispatchEventUsingWindowDispatcher(&release);
2317 2317
2318 delegate->Reset(); 2318 delegate->Reset();
2319 delegate->ReceivedAck(); 2319 delegate->ReceivedAck();
2320 EXPECT_TRUE(delegate->tap_down()); 2320 EXPECT_TRUE(delegate->tap_down());
2321 delegate->Reset(); 2321 delegate->Reset();
2322 delegate->ReceivedAckPreventDefaulted(); 2322 delegate->ReceivedAckPreventDefaulted();
2323 EXPECT_FALSE(delegate->tap()); 2323 EXPECT_FALSE(delegate->tap());
2324 EXPECT_TRUE(delegate->tap_cancel()); 2324 EXPECT_TRUE(delegate->tap_cancel());
2325 } 2325 }
2326 2326
2327 TEST_F(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) { 2327 TEST_F(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) {
2328 scoped_ptr<QueueTouchEventDelegate> delegate( 2328 std::unique_ptr<QueueTouchEventDelegate> delegate(
2329 new QueueTouchEventDelegate(host()->dispatcher())); 2329 new QueueTouchEventDelegate(host()->dispatcher()));
2330 TimedEvents tes; 2330 TimedEvents tes;
2331 const int kTouchId1 = 7; 2331 const int kTouchId1 = 7;
2332 const int kTouchId2 = 5; 2332 const int kTouchId2 = 5;
2333 gfx::Rect bounds(10, 20, 100, 100); 2333 gfx::Rect bounds(10, 20, 100, 100);
2334 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2334 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2335 delegate.get(), -1234, bounds, root_window())); 2335 delegate.get(), -1234, bounds, root_window()));
2336 delegate->set_window(window.get()); 2336 delegate->set_window(window.get());
2337 2337
2338 { 2338 {
2339 delegate->Reset(); 2339 delegate->Reset();
2340 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(15, 25), kTouchId1, 2340 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(15, 25), kTouchId1,
2341 tes.Now()); 2341 tes.Now());
2342 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(20, 95), kTouchId1, 2342 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(20, 95), kTouchId1,
2343 tes.LeapForward(200)); 2343 tes.LeapForward(200));
2344 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(15, 25), kTouchId1, 2344 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(15, 25), kTouchId1,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 delegate->events(), ui::ET_GESTURE_PINCH_END, ui::ET_GESTURE_END); 2421 delegate->events(), ui::ET_GESTURE_PINCH_END, ui::ET_GESTURE_END);
2422 2422
2423 delegate->Reset(); 2423 delegate->Reset();
2424 delegate->ReceivedAckPreventDefaulted(); 2424 delegate->ReceivedAckPreventDefaulted();
2425 EXPECT_2_EVENTS( 2425 EXPECT_2_EVENTS(
2426 delegate->events(), ui::ET_GESTURE_SCROLL_END, ui::ET_GESTURE_END); 2426 delegate->events(), ui::ET_GESTURE_SCROLL_END, ui::ET_GESTURE_END);
2427 } 2427 }
2428 2428
2429 TEST_F(GestureRecognizerTest, GestureEndLocation) { 2429 TEST_F(GestureRecognizerTest, GestureEndLocation) {
2430 GestureEventConsumeDelegate delegate; 2430 GestureEventConsumeDelegate delegate;
2431 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2431 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2432 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2432 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2433 ui::test::EventGenerator generator(root_window(), window.get()); 2433 ui::test::EventGenerator generator(root_window(), window.get());
2434 const gfx::Point begin(20, 20); 2434 const gfx::Point begin(20, 20);
2435 const gfx::Point end(150, 150); 2435 const gfx::Point end(150, 150);
2436 const gfx::Vector2d window_offset = 2436 const gfx::Vector2d window_offset =
2437 window->bounds().origin().OffsetFromOrigin(); 2437 window->bounds().origin().OffsetFromOrigin();
2438 generator.GestureScrollSequence(begin, end, 2438 generator.GestureScrollSequence(begin, end,
2439 base::TimeDelta::FromMilliseconds(20), 2439 base::TimeDelta::FromMilliseconds(20),
2440 10); 2440 10);
2441 EXPECT_EQ((begin - window_offset).ToString(), 2441 EXPECT_EQ((begin - window_offset).ToString(),
2442 delegate.scroll_begin_position().ToString()); 2442 delegate.scroll_begin_position().ToString());
2443 EXPECT_EQ((end - window_offset).ToString(), 2443 EXPECT_EQ((end - window_offset).ToString(),
2444 delegate.gesture_end_location().ToString()); 2444 delegate.gesture_end_location().ToString());
2445 } 2445 }
2446 2446
2447 TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) { 2447 TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) {
2448 scoped_ptr<GestureEventConsumeDelegate> delegate( 2448 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2449 new GestureEventConsumeDelegate()); 2449 new GestureEventConsumeDelegate());
2450 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2450 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2451 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2451 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2452 ui::test::EventGenerator generator(root_window()); 2452 ui::test::EventGenerator generator(root_window());
2453 2453
2454 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10)); 2454 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10));
2455 generator.PressTouch(); 2455 generator.PressTouch();
2456 RunAllPendingInMessageLoop(); 2456 RunAllPendingInMessageLoop();
2457 2457
2458 EXPECT_TRUE(delegate->tap_down()); 2458 EXPECT_TRUE(delegate->tap_down());
2459 2459
2460 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds( 2460 std::unique_ptr<aura::Window> capture(
2461 gfx::Rect(10, 10, 200, 200), root_window())); 2461 CreateTestWindowWithBounds(gfx::Rect(10, 10, 200, 200), root_window()));
2462 capture->SetCapture(); 2462 capture->SetCapture();
2463 RunAllPendingInMessageLoop(); 2463 RunAllPendingInMessageLoop();
2464 2464
2465 EXPECT_TRUE(delegate->end()); 2465 EXPECT_TRUE(delegate->end());
2466 EXPECT_TRUE(delegate->tap_cancel()); 2466 EXPECT_TRUE(delegate->tap_cancel());
2467 } 2467 }
2468 2468
2469 // Check that previous touch actions that are completely finished (either 2469 // Check that previous touch actions that are completely finished (either
2470 // released or cancelled), do not receive extra synthetic cancels upon change of 2470 // released or cancelled), do not receive extra synthetic cancels upon change of
2471 // capture. 2471 // capture.
2472 TEST_F(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) { 2472 TEST_F(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) {
2473 scoped_ptr<GestureEventConsumeDelegate> delegate( 2473 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2474 new GestureEventConsumeDelegate()); 2474 new GestureEventConsumeDelegate());
2475 scoped_ptr<TestEventHandler> handler(new TestEventHandler); 2475 std::unique_ptr<TestEventHandler> handler(new TestEventHandler);
2476 root_window()->AddPreTargetHandler(handler.get()); 2476 root_window()->AddPreTargetHandler(handler.get());
2477 2477
2478 // Create a window and set it as the capture window. 2478 // Create a window and set it as the capture window.
2479 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(delegate.get(), 2479 std::unique_ptr<aura::Window> window1(CreateTestWindowWithDelegate(
2480 -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2480 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2481 window1->SetCapture(); 2481 window1->SetCapture();
2482 2482
2483 ui::test::EventGenerator generator(root_window()); 2483 ui::test::EventGenerator generator(root_window());
2484 TimedEvents tes; 2484 TimedEvents tes;
2485 2485
2486 // Generate two touch-press events on the window. 2486 // Generate two touch-press events on the window.
2487 scoped_ptr<ui::TouchEvent> touch0(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, 2487 std::unique_ptr<ui::TouchEvent> touch0(new ui::TouchEvent(
2488 gfx::Point(20, 20), 0, 2488 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 0, tes.Now()));
2489 tes.Now())); 2489 std::unique_ptr<ui::TouchEvent> touch1(new ui::TouchEvent(
2490 scoped_ptr<ui::TouchEvent> touch1(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, 2490 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 1, tes.Now()));
2491 gfx::Point(30, 30), 1,
2492 tes.Now()));
2493 generator.Dispatch(touch0.get()); 2491 generator.Dispatch(touch0.get());
2494 generator.Dispatch(touch1.get()); 2492 generator.Dispatch(touch1.get());
2495 RunAllPendingInMessageLoop(); 2493 RunAllPendingInMessageLoop();
2496 EXPECT_EQ(2, handler->touch_pressed_count()); 2494 EXPECT_EQ(2, handler->touch_pressed_count());
2497 2495
2498 // Advance time. 2496 // Advance time.
2499 tes.LeapForward(1000); 2497 tes.LeapForward(1000);
2500 2498
2501 // End the two touches, one by a touch-release and one by a touch-cancel; to 2499 // End the two touches, one by a touch-release and one by a touch-cancel; to
2502 // cover both cases. 2500 // cover both cases.
2503 touch0.reset(new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0, 2501 touch0.reset(new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0,
2504 tes.Now())); 2502 tes.Now()));
2505 touch1.reset(new ui::TouchEvent(ui::ET_TOUCH_CANCELLED, gfx::Point(30, 30), 1, 2503 touch1.reset(new ui::TouchEvent(ui::ET_TOUCH_CANCELLED, gfx::Point(30, 30), 1,
2506 tes.Now())); 2504 tes.Now()));
2507 generator.Dispatch(touch0.get()); 2505 generator.Dispatch(touch0.get());
2508 generator.Dispatch(touch1.get()); 2506 generator.Dispatch(touch1.get());
2509 RunAllPendingInMessageLoop(); 2507 RunAllPendingInMessageLoop();
2510 EXPECT_EQ(1, handler->touch_released_count()); 2508 EXPECT_EQ(1, handler->touch_released_count());
2511 EXPECT_EQ(1, handler->touch_cancelled_count()); 2509 EXPECT_EQ(1, handler->touch_cancelled_count());
2512 2510
2513 // Create a new window and set it as the new capture window. 2511 // Create a new window and set it as the new capture window.
2514 scoped_ptr<aura::Window> window2(CreateTestWindowWithBounds( 2512 std::unique_ptr<aura::Window> window2(
2515 gfx::Rect(100, 100, 300, 300), root_window())); 2513 CreateTestWindowWithBounds(gfx::Rect(100, 100, 300, 300), root_window()));
2516 window2->SetCapture(); 2514 window2->SetCapture();
2517 RunAllPendingInMessageLoop(); 2515 RunAllPendingInMessageLoop();
2518 // Check that setting capture does not generate any synthetic touch-cancels 2516 // Check that setting capture does not generate any synthetic touch-cancels
2519 // for the two previously finished touch actions. 2517 // for the two previously finished touch actions.
2520 EXPECT_EQ(1, handler->touch_cancelled_count()); 2518 EXPECT_EQ(1, handler->touch_cancelled_count());
2521 2519
2522 root_window()->RemovePreTargetHandler(handler.get()); 2520 root_window()->RemovePreTargetHandler(handler.get());
2523 } 2521 }
2524 2522
2525 // Tests that a press with the same touch id as an existing touch is ignored. 2523 // Tests that a press with the same touch id as an existing touch is ignored.
2526 TEST_F(GestureRecognizerTest, PressDoesNotCrash) { 2524 TEST_F(GestureRecognizerTest, PressDoesNotCrash) {
2527 scoped_ptr<GestureEventConsumeDelegate> delegate( 2525 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2528 new GestureEventConsumeDelegate()); 2526 new GestureEventConsumeDelegate());
2529 TimedEvents tes; 2527 TimedEvents tes;
2530 2528
2531 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2529 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2532 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2530 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2533 2531
2534 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, tes.Now()); 2532 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, tes.Now());
2535 SetTouchRadius(&press, 40, 0); 2533 SetTouchRadius(&press, 40, 0);
2536 DispatchEventUsingWindowDispatcher(&press); 2534 DispatchEventUsingWindowDispatcher(&press);
2537 EXPECT_TRUE(delegate->tap_down()); 2535 EXPECT_TRUE(delegate->tap_down());
2538 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(), 2536 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(),
2539 delegate->bounding_box().ToString()); 2537 delegate->bounding_box().ToString());
2540 delegate->Reset(); 2538 delegate->Reset();
2541 2539
2542 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, tes.Now()); 2540 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, tes.Now());
2543 DispatchEventUsingWindowDispatcher(&press2); 2541 DispatchEventUsingWindowDispatcher(&press2);
2544 2542
2545 // FIXME(tdresser): this should not generate a tap down; however, 2543 // FIXME(tdresser): this should not generate a tap down; however,
2546 // there is at least one case where we need to allow a touch press 2544 // there is at least one case where we need to allow a touch press
2547 // from a currently used touch id. See crbug.com/373125 for details. 2545 // from a currently used touch id. See crbug.com/373125 for details.
2548 EXPECT_TRUE(delegate->begin()); 2546 EXPECT_TRUE(delegate->begin());
2549 EXPECT_TRUE(delegate->tap_down()); 2547 EXPECT_TRUE(delegate->tap_down());
2550 EXPECT_TRUE(delegate->tap_cancel()); 2548 EXPECT_TRUE(delegate->tap_cancel());
2551 EXPECT_FALSE(delegate->scroll_begin()); 2549 EXPECT_FALSE(delegate->scroll_begin());
2552 } 2550 }
2553 2551
2554 TEST_F(GestureRecognizerTest, TwoFingerTap) { 2552 TEST_F(GestureRecognizerTest, TwoFingerTap) {
2555 scoped_ptr<GestureEventConsumeDelegate> delegate( 2553 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2556 new GestureEventConsumeDelegate()); 2554 new GestureEventConsumeDelegate());
2557 const int kWindowWidth = 123; 2555 const int kWindowWidth = 123;
2558 const int kWindowHeight = 45; 2556 const int kWindowHeight = 45;
2559 const int kTouchId1 = 2; 2557 const int kTouchId1 = 2;
2560 const int kTouchId2 = 3; 2558 const int kTouchId2 = 3;
2561 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2559 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2562 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2560 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2563 delegate.get(), -1234, bounds, root_window())); 2561 delegate.get(), -1234, bounds, root_window()));
2564 TimedEvents tes; 2562 TimedEvents tes;
2565 2563
2566 delegate->Reset(); 2564 delegate->Reset();
2567 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2565 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2568 kTouchId1, tes.Now()); 2566 kTouchId1, tes.Now());
2569 DispatchEventUsingWindowDispatcher(&press1); 2567 DispatchEventUsingWindowDispatcher(&press1);
2570 EXPECT_2_EVENTS( 2568 EXPECT_2_EVENTS(
2571 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN); 2569 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
2572 2570
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 delegate->Reset(); 2602 delegate->Reset();
2605 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2603 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
2606 kTouchId2, tes.LeapForward(50)); 2604 kTouchId2, tes.LeapForward(50));
2607 2605
2608 DispatchEventUsingWindowDispatcher(&release2); 2606 DispatchEventUsingWindowDispatcher(&release2);
2609 EXPECT_2_EVENTS( 2607 EXPECT_2_EVENTS(
2610 delegate->events(), ui::ET_GESTURE_SCROLL_END, ui::ET_GESTURE_END); 2608 delegate->events(), ui::ET_GESTURE_SCROLL_END, ui::ET_GESTURE_END);
2611 } 2609 }
2612 2610
2613 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) { 2611 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) {
2614 scoped_ptr<GestureEventConsumeDelegate> delegate( 2612 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2615 new GestureEventConsumeDelegate()); 2613 new GestureEventConsumeDelegate());
2616 const int kWindowWidth = 123; 2614 const int kWindowWidth = 123;
2617 const int kWindowHeight = 45; 2615 const int kWindowHeight = 45;
2618 const int kTouchId1 = 2; 2616 const int kTouchId1 = 2;
2619 const int kTouchId2 = 3; 2617 const int kTouchId2 = 3;
2620 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2618 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2621 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2619 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2622 delegate.get(), -1234, bounds, root_window())); 2620 delegate.get(), -1234, bounds, root_window()));
2623 TimedEvents tes; 2621 TimedEvents tes;
2624 2622
2625 delegate->Reset(); 2623 delegate->Reset();
2626 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2624 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2627 kTouchId1, tes.Now()); 2625 kTouchId1, tes.Now());
2628 DispatchEventUsingWindowDispatcher(&press1); 2626 DispatchEventUsingWindowDispatcher(&press1);
2629 2627
2630 delegate->Reset(); 2628 delegate->Reset();
2631 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2629 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
(...skipping 13 matching lines...) Expand all
2645 // recognized as a tap. 2643 // recognized as a tap.
2646 delegate->Reset(); 2644 delegate->Reset();
2647 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2645 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
2648 kTouchId2, tes.LeapForward(50)); 2646 kTouchId2, tes.LeapForward(50));
2649 2647
2650 DispatchEventUsingWindowDispatcher(&release2); 2648 DispatchEventUsingWindowDispatcher(&release2);
2651 EXPECT_FALSE(delegate->two_finger_tap()); 2649 EXPECT_FALSE(delegate->two_finger_tap());
2652 } 2650 }
2653 2651
2654 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) { 2652 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
2655 scoped_ptr<GestureEventConsumeDelegate> delegate( 2653 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2656 new GestureEventConsumeDelegate()); 2654 new GestureEventConsumeDelegate());
2657 const int kWindowWidth = 123; 2655 const int kWindowWidth = 123;
2658 const int kWindowHeight = 45; 2656 const int kWindowHeight = 45;
2659 const int kTouchId1 = 2; 2657 const int kTouchId1 = 2;
2660 const int kTouchId2 = 3; 2658 const int kTouchId2 = 3;
2661 TimedEvents tes; 2659 TimedEvents tes;
2662 2660
2663 // Test moving first finger 2661 // Test moving first finger
2664 { 2662 {
2665 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2663 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2666 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2664 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2667 delegate.get(), -1234, bounds, root_window())); 2665 delegate.get(), -1234, bounds, root_window()));
2668 2666
2669 delegate->Reset(); 2667 delegate->Reset();
2670 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2668 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2671 kTouchId1, tes.Now()); 2669 kTouchId1, tes.Now());
2672 DispatchEventUsingWindowDispatcher(&press1); 2670 DispatchEventUsingWindowDispatcher(&press1);
2673 2671
2674 delegate->Reset(); 2672 delegate->Reset();
2675 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2673 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2676 kTouchId2, tes.Now()); 2674 kTouchId2, tes.Now());
(...skipping 10 matching lines...) Expand all
2687 kTouchId2, tes.LeapForward(50)); 2685 kTouchId2, tes.LeapForward(50));
2688 2686
2689 DispatchEventUsingWindowDispatcher(&release); 2687 DispatchEventUsingWindowDispatcher(&release);
2690 EXPECT_FALSE(delegate->two_finger_tap()); 2688 EXPECT_FALSE(delegate->two_finger_tap());
2691 EXPECT_TRUE(delegate->pinch_end()); 2689 EXPECT_TRUE(delegate->pinch_end());
2692 } 2690 }
2693 2691
2694 // Test moving second finger 2692 // Test moving second finger
2695 { 2693 {
2696 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2694 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2697 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2695 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2698 delegate.get(), -1234, bounds, root_window())); 2696 delegate.get(), -1234, bounds, root_window()));
2699 2697
2700 delegate->Reset(); 2698 delegate->Reset();
2701 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2699 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2702 kTouchId1, tes.Now()); 2700 kTouchId1, tes.Now());
2703 DispatchEventUsingWindowDispatcher(&press1); 2701 DispatchEventUsingWindowDispatcher(&press1);
2704 2702
2705 delegate->Reset(); 2703 delegate->Reset();
2706 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2704 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2707 kTouchId2, tes.Now()); 2705 kTouchId2, tes.Now());
2708 DispatchEventUsingWindowDispatcher(&press2); 2706 DispatchEventUsingWindowDispatcher(&press2);
2709 2707
2710 tes.SendScrollEvent(event_processor(), 301, 230, kTouchId2, delegate.get()); 2708 tes.SendScrollEvent(event_processor(), 301, 230, kTouchId2, delegate.get());
2711 EXPECT_FALSE(delegate->two_finger_tap()); 2709 EXPECT_FALSE(delegate->two_finger_tap());
2712 EXPECT_TRUE(delegate->pinch_begin()); 2710 EXPECT_TRUE(delegate->pinch_begin());
2713 2711
2714 // Make sure there is enough delay before the touch is released so that it 2712 // Make sure there is enough delay before the touch is released so that it
2715 // is recognized as a tap. 2713 // is recognized as a tap.
2716 delegate->Reset(); 2714 delegate->Reset();
2717 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2715 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2718 kTouchId1, tes.LeapForward(50)); 2716 kTouchId1, tes.LeapForward(50));
2719 2717
2720 DispatchEventUsingWindowDispatcher(&release); 2718 DispatchEventUsingWindowDispatcher(&release);
2721 EXPECT_FALSE(delegate->two_finger_tap()); 2719 EXPECT_FALSE(delegate->two_finger_tap());
2722 EXPECT_TRUE(delegate->pinch_end()); 2720 EXPECT_TRUE(delegate->pinch_end());
2723 } 2721 }
2724 } 2722 }
2725 2723
2726 TEST_F(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) { 2724 TEST_F(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) {
2727 scoped_ptr<GestureEventConsumeDelegate> delegate( 2725 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2728 new GestureEventConsumeDelegate()); 2726 new GestureEventConsumeDelegate());
2729 const int kWindowWidth = 123; 2727 const int kWindowWidth = 123;
2730 const int kWindowHeight = 45; 2728 const int kWindowHeight = 45;
2731 const int kTouchId1 = 2; 2729 const int kTouchId1 = 2;
2732 const int kTouchId2 = 3; 2730 const int kTouchId2 = 3;
2733 TimedEvents tes; 2731 TimedEvents tes;
2734 2732
2735 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2733 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2736 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2734 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2737 delegate.get(), -1234, bounds, root_window())); 2735 delegate.get(), -1234, bounds, root_window()));
2738 2736
2739 delegate->Reset(); 2737 delegate->Reset();
2740 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2738 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2741 kTouchId1, tes.Now()); 2739 kTouchId1, tes.Now());
2742 DispatchEventUsingWindowDispatcher(&press1); 2740 DispatchEventUsingWindowDispatcher(&press1);
2743 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId1, delegate.get()); 2741 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId1, delegate.get());
2744 2742
2745 delegate->Reset(); 2743 delegate->Reset();
2746 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2744 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2747 kTouchId2, tes.Now()); 2745 kTouchId2, tes.Now());
2748 DispatchEventUsingWindowDispatcher(&press2); 2746 DispatchEventUsingWindowDispatcher(&press2);
2749 2747
2750 EXPECT_FALSE(delegate->pinch_begin()); 2748 EXPECT_FALSE(delegate->pinch_begin());
2751 2749
2752 // Make sure there is enough delay before the touch is released so that it 2750 // Make sure there is enough delay before the touch is released so that it
2753 // is recognized as a tap. 2751 // is recognized as a tap.
2754 delegate->Reset(); 2752 delegate->Reset();
2755 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2753 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2756 kTouchId2, tes.LeapForward(50)); 2754 kTouchId2, tes.LeapForward(50));
2757 2755
2758 DispatchEventUsingWindowDispatcher(&release); 2756 DispatchEventUsingWindowDispatcher(&release);
2759 EXPECT_FALSE(delegate->two_finger_tap()); 2757 EXPECT_FALSE(delegate->two_finger_tap());
2760 EXPECT_FALSE(delegate->pinch_end()); 2758 EXPECT_FALSE(delegate->pinch_end());
2761 } 2759 }
2762 2760
2763 TEST_F(GestureRecognizerTest, MultiFingerSwipe) { 2761 TEST_F(GestureRecognizerTest, MultiFingerSwipe) {
2764 scoped_ptr<GestureEventConsumeDelegate> delegate( 2762 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2765 new GestureEventConsumeDelegate()); 2763 new GestureEventConsumeDelegate());
2766 const int kWindowWidth = 123; 2764 const int kWindowWidth = 123;
2767 const int kWindowHeight = 45; 2765 const int kWindowHeight = 45;
2768 2766
2769 gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight); 2767 gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight);
2770 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2768 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2771 delegate.get(), -1234, bounds, root_window())); 2769 delegate.get(), -1234, bounds, root_window()));
2772 2770
2773 const int kSteps = 15; 2771 const int kSteps = 15;
2774 const int kTouchPoints = 4; 2772 const int kTouchPoints = 4;
2775 gfx::Point points[kTouchPoints] = { 2773 gfx::Point points[kTouchPoints] = {
2776 gfx::Point(10, 30), 2774 gfx::Point(10, 30),
2777 gfx::Point(30, 20), 2775 gfx::Point(30, 20),
2778 gfx::Point(50, 30), 2776 gfx::Point(50, 30),
2779 gfx::Point(80, 50) 2777 gfx::Point(80, 50)
2780 }; 2778 };
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 delegate->Reset(); 2814 delegate->Reset();
2817 2815
2818 generator.GestureMultiFingerScroll( 2816 generator.GestureMultiFingerScroll(
2819 count, points, 10, kSteps, 3 * kSteps, 12 * kSteps); 2817 count, points, 10, kSteps, 3 * kSteps, 12 * kSteps);
2820 EXPECT_TRUE(delegate->swipe_down()); 2818 EXPECT_TRUE(delegate->swipe_down());
2821 delegate->Reset(); 2819 delegate->Reset();
2822 } 2820 }
2823 } 2821 }
2824 2822
2825 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) { 2823 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) {
2826 scoped_ptr<GestureEventConsumeDelegate> delegate( 2824 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2827 new GestureEventConsumeDelegate()); 2825 new GestureEventConsumeDelegate());
2828 const int kWindowWidth = 123; 2826 const int kWindowWidth = 123;
2829 const int kWindowHeight = 45; 2827 const int kWindowHeight = 45;
2830 const int kTouchId1 = 2; 2828 const int kTouchId1 = 2;
2831 const int kTouchId2 = 3; 2829 const int kTouchId2 = 3;
2832 TimedEvents tes; 2830 TimedEvents tes;
2833 2831
2834 // Test canceling first finger. 2832 // Test canceling first finger.
2835 { 2833 {
2836 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2834 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2837 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2835 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2838 delegate.get(), -1234, bounds, root_window())); 2836 delegate.get(), -1234, bounds, root_window()));
2839 2837
2840 delegate->Reset(); 2838 delegate->Reset();
2841 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2839 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2842 kTouchId1, tes.Now()); 2840 kTouchId1, tes.Now());
2843 DispatchEventUsingWindowDispatcher(&press1); 2841 DispatchEventUsingWindowDispatcher(&press1);
2844 2842
2845 delegate->Reset(); 2843 delegate->Reset();
2846 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2844 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2847 kTouchId2, tes.Now()); 2845 kTouchId2, tes.Now());
(...skipping 11 matching lines...) Expand all
2859 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2857 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2860 kTouchId2, tes.LeapForward(50)); 2858 kTouchId2, tes.LeapForward(50));
2861 2859
2862 DispatchEventUsingWindowDispatcher(&release); 2860 DispatchEventUsingWindowDispatcher(&release);
2863 EXPECT_FALSE(delegate->two_finger_tap()); 2861 EXPECT_FALSE(delegate->two_finger_tap());
2864 } 2862 }
2865 2863
2866 // Test canceling second finger 2864 // Test canceling second finger
2867 { 2865 {
2868 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2866 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2869 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2867 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2870 delegate.get(), -1234, bounds, root_window())); 2868 delegate.get(), -1234, bounds, root_window()));
2871 2869
2872 delegate->Reset(); 2870 delegate->Reset();
2873 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2871 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2874 kTouchId1, tes.Now()); 2872 kTouchId1, tes.Now());
2875 DispatchEventUsingWindowDispatcher(&press1); 2873 DispatchEventUsingWindowDispatcher(&press1);
2876 2874
2877 delegate->Reset(); 2875 delegate->Reset();
2878 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2876 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2879 kTouchId2, tes.Now()); 2877 kTouchId2, tes.Now());
(...skipping 10 matching lines...) Expand all
2890 delegate->Reset(); 2888 delegate->Reset();
2891 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2889 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2892 kTouchId1, tes.LeapForward(50)); 2890 kTouchId1, tes.LeapForward(50));
2893 2891
2894 DispatchEventUsingWindowDispatcher(&release); 2892 DispatchEventUsingWindowDispatcher(&release);
2895 EXPECT_FALSE(delegate->two_finger_tap()); 2893 EXPECT_FALSE(delegate->two_finger_tap());
2896 } 2894 }
2897 } 2895 }
2898 2896
2899 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { 2897 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
2900 scoped_ptr<GestureEventConsumeDelegate> delegate( 2898 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2901 new GestureEventConsumeDelegate()); 2899 new GestureEventConsumeDelegate());
2902 const int kWindowWidth = 523; 2900 const int kWindowWidth = 523;
2903 const int kWindowHeight = 45; 2901 const int kWindowHeight = 45;
2904 const int kTouchId1 = 2; 2902 const int kTouchId1 = 2;
2905 const int kTouchId2 = 3; 2903 const int kTouchId2 = 3;
2906 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2904 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2907 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2905 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2908 delegate.get(), -1234, bounds, root_window())); 2906 delegate.get(), -1234, bounds, root_window()));
2909 TimedEvents tes; 2907 TimedEvents tes;
2910 2908
2911 delegate->Reset(); 2909 delegate->Reset();
2912 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2910 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2913 kTouchId1, tes.Now()); 2911 kTouchId1, tes.Now());
2914 DispatchEventUsingWindowDispatcher(&press1); 2912 DispatchEventUsingWindowDispatcher(&press1);
2915 EXPECT_FALSE(delegate->tap()); 2913 EXPECT_FALSE(delegate->tap());
2916 EXPECT_TRUE(delegate->tap_down()); 2914 EXPECT_TRUE(delegate->tap_down());
2917 EXPECT_FALSE(delegate->tap_cancel()); 2915 EXPECT_FALSE(delegate->tap_cancel());
(...skipping 29 matching lines...) Expand all
2947 EXPECT_TRUE(delegate->scroll_update()); 2945 EXPECT_TRUE(delegate->scroll_update());
2948 EXPECT_FALSE(delegate->scroll_end()); 2946 EXPECT_FALSE(delegate->scroll_end());
2949 EXPECT_FALSE(delegate->long_press()); 2947 EXPECT_FALSE(delegate->long_press());
2950 EXPECT_FALSE(delegate->two_finger_tap()); 2948 EXPECT_FALSE(delegate->two_finger_tap());
2951 EXPECT_TRUE(delegate->pinch_begin()); 2949 EXPECT_TRUE(delegate->pinch_begin());
2952 } 2950 }
2953 2951
2954 // Verifies if a window is the target of multiple touch-ids and we hide the 2952 // Verifies if a window is the target of multiple touch-ids and we hide the
2955 // window everything is cleaned up correctly. 2953 // window everything is cleaned up correctly.
2956 TEST_F(GestureRecognizerTest, FlushAllOnHide) { 2954 TEST_F(GestureRecognizerTest, FlushAllOnHide) {
2957 scoped_ptr<GestureEventConsumeDelegate> delegate( 2955 std::unique_ptr<GestureEventConsumeDelegate> delegate(
2958 new GestureEventConsumeDelegate()); 2956 new GestureEventConsumeDelegate());
2959 gfx::Rect bounds(0, 0, 200, 200); 2957 gfx::Rect bounds(0, 0, 200, 200);
2960 scoped_ptr<aura::Window> window( 2958 std::unique_ptr<aura::Window> window(
2961 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); 2959 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
2962 const int kTouchId1 = 8; 2960 const int kTouchId1 = 8;
2963 const int kTouchId2 = 2; 2961 const int kTouchId2 = 2;
2964 TimedEvents tes; 2962 TimedEvents tes;
2965 2963
2966 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2964 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
2967 kTouchId1, tes.Now()); 2965 kTouchId1, tes.Now());
2968 DispatchEventUsingWindowDispatcher(&press1); 2966 DispatchEventUsingWindowDispatcher(&press1);
2969 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2967 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2970 kTouchId2, tes.Now()); 2968 kTouchId2, tes.Now());
2971 DispatchEventUsingWindowDispatcher(&press2); 2969 DispatchEventUsingWindowDispatcher(&press2);
2972 window->Hide(); 2970 window->Hide();
2973 EXPECT_EQ(NULL, 2971 EXPECT_EQ(NULL,
2974 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1)); 2972 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1));
2975 EXPECT_EQ(NULL, 2973 EXPECT_EQ(NULL,
2976 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)); 2974 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
2977 } 2975 }
2978 2976
2979 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { 2977 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
2980 scoped_ptr<QueueTouchEventDelegate> delegate( 2978 std::unique_ptr<QueueTouchEventDelegate> delegate(
2981 new QueueTouchEventDelegate(host()->dispatcher())); 2979 new QueueTouchEventDelegate(host()->dispatcher()));
2982 const int kTouchId = 2; 2980 const int kTouchId = 2;
2983 gfx::Rect bounds(100, 200, 100, 100); 2981 gfx::Rect bounds(100, 200, 100, 100);
2984 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2982 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2985 delegate.get(), -1234, bounds, root_window())); 2983 delegate.get(), -1234, bounds, root_window()));
2986 delegate->set_window(window.get()); 2984 delegate->set_window(window.get());
2987 TimedEvents tes; 2985 TimedEvents tes;
2988 2986
2989 delegate->Reset(); 2987 delegate->Reset();
2990 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2988 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2991 kTouchId, tes.Now()); 2989 kTouchId, tes.Now());
2992 DispatchEventUsingWindowDispatcher(&press); 2990 DispatchEventUsingWindowDispatcher(&press);
2993 // Scroll around, to cancel the long press 2991 // Scroll around, to cancel the long press
2994 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); 2992 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
(...skipping 28 matching lines...) Expand all
3023 } 3021 }
3024 3022
3025 bool consume_touch_move_; 3023 bool consume_touch_move_;
3026 3024
3027 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); 3025 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate);
3028 }; 3026 };
3029 3027
3030 // Same as GestureEventScroll, but tests that the behavior is the same 3028 // Same as GestureEventScroll, but tests that the behavior is the same
3031 // even if all the touch-move events are consumed. 3029 // even if all the touch-move events are consumed.
3032 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) { 3030 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
3033 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3031 std::unique_ptr<ConsumesTouchMovesDelegate> delegate(
3034 new ConsumesTouchMovesDelegate()); 3032 new ConsumesTouchMovesDelegate());
3035 const int kWindowWidth = 123; 3033 const int kWindowWidth = 123;
3036 const int kWindowHeight = 45; 3034 const int kWindowHeight = 45;
3037 const int kTouchId = 5; 3035 const int kTouchId = 5;
3038 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3036 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3039 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3037 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3040 delegate.get(), -1234, bounds, root_window())); 3038 delegate.get(), -1234, bounds, root_window()));
3041 TimedEvents tes; 3039 TimedEvents tes;
3042 3040
3043 delegate->Reset(); 3041 delegate->Reset();
3044 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3042 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3045 kTouchId, tes.Now()); 3043 kTouchId, tes.Now());
3046 DispatchEventUsingWindowDispatcher(&press); 3044 DispatchEventUsingWindowDispatcher(&press);
3047 EXPECT_FALSE(delegate->tap()); 3045 EXPECT_FALSE(delegate->tap());
3048 EXPECT_TRUE(delegate->tap_down()); 3046 EXPECT_TRUE(delegate->tap_down());
3049 EXPECT_FALSE(delegate->tap_cancel()); 3047 EXPECT_FALSE(delegate->tap_cancel());
(...skipping 28 matching lines...) Expand all
3078 EXPECT_TRUE(delegate->end()); 3076 EXPECT_TRUE(delegate->end());
3079 EXPECT_FALSE(delegate->scroll_begin()); 3077 EXPECT_FALSE(delegate->scroll_begin());
3080 EXPECT_FALSE(delegate->scroll_update()); 3078 EXPECT_FALSE(delegate->scroll_update());
3081 3079
3082 EXPECT_TRUE(delegate->scroll_end()); 3080 EXPECT_TRUE(delegate->scroll_end());
3083 } 3081 }
3084 3082
3085 // Tests the behavior of 2F scroll when some of the touch-move events are 3083 // Tests the behavior of 2F scroll when some of the touch-move events are
3086 // consumed. 3084 // consumed.
3087 TEST_F(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) { 3085 TEST_F(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) {
3088 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3086 std::unique_ptr<ConsumesTouchMovesDelegate> delegate(
3089 new ConsumesTouchMovesDelegate()); 3087 new ConsumesTouchMovesDelegate());
3090 const int kWindowWidth = 123; 3088 const int kWindowWidth = 123;
3091 const int kWindowHeight = 100; 3089 const int kWindowHeight = 100;
3092 const int kTouchId1 = 2; 3090 const int kTouchId1 = 2;
3093 const int kTouchId2 = 3; 3091 const int kTouchId2 = 3;
3094 TimedEvents tes; 3092 TimedEvents tes;
3095 3093
3096 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3094 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3097 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3095 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3098 delegate.get(), -1234, bounds, root_window())); 3096 delegate.get(), -1234, bounds, root_window()));
3099 3097
3100 delegate->Reset(); 3098 delegate->Reset();
3101 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3099 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3102 kTouchId1, tes.Now()); 3100 kTouchId1, tes.Now());
3103 DispatchEventUsingWindowDispatcher(&press1); 3101 DispatchEventUsingWindowDispatcher(&press1);
3104 tes.SendScrollEvent(event_processor(), 131, 231, kTouchId1, delegate.get()); 3102 tes.SendScrollEvent(event_processor(), 131, 231, kTouchId1, delegate.get());
3105 3103
3106 EXPECT_2_EVENTS(delegate->events(), 3104 EXPECT_2_EVENTS(delegate->events(),
3107 ui::ET_GESTURE_TAP_CANCEL, 3105 ui::ET_GESTURE_TAP_CANCEL,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 EXPECT_3_EVENTS(delegate->events(), 3141 EXPECT_3_EVENTS(delegate->events(),
3144 ui::ET_GESTURE_END, 3142 ui::ET_GESTURE_END,
3145 ui::ET_SCROLL_FLING_START, 3143 ui::ET_SCROLL_FLING_START,
3146 ui::ET_GESTURE_END); 3144 ui::ET_GESTURE_END);
3147 } 3145 }
3148 3146
3149 // Like as GestureEventTouchMoveConsumed but tests the different behavior 3147 // Like as GestureEventTouchMoveConsumed but tests the different behavior
3150 // depending on whether the events were consumed before or after the scroll 3148 // depending on whether the events were consumed before or after the scroll
3151 // started. 3149 // started.
3152 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) { 3150 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) {
3153 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3151 std::unique_ptr<ConsumesTouchMovesDelegate> delegate(
3154 new ConsumesTouchMovesDelegate()); 3152 new ConsumesTouchMovesDelegate());
3155 const int kWindowWidth = 123; 3153 const int kWindowWidth = 123;
3156 const int kWindowHeight = 45; 3154 const int kWindowHeight = 45;
3157 const int kTouchId = 5; 3155 const int kTouchId = 5;
3158 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3156 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3159 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3157 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3160 delegate.get(), -1234, bounds, root_window())); 3158 delegate.get(), -1234, bounds, root_window()));
3161 TimedEvents tes; 3159 TimedEvents tes;
3162 3160
3163 delegate->Reset(); 3161 delegate->Reset();
3164 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3162 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3165 kTouchId, tes.Now()); 3163 kTouchId, tes.Now());
3166 DispatchEventUsingWindowDispatcher(&press); 3164 DispatchEventUsingWindowDispatcher(&press);
3167 EXPECT_FALSE(delegate->tap()); 3165 EXPECT_FALSE(delegate->tap());
3168 EXPECT_TRUE(delegate->tap_down()); 3166 EXPECT_TRUE(delegate->tap_down());
3169 EXPECT_FALSE(delegate->tap_cancel()); 3167 EXPECT_FALSE(delegate->tap_cancel());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3241 EXPECT_TRUE(delegate->end()); 3239 EXPECT_TRUE(delegate->end());
3242 EXPECT_FALSE(delegate->scroll_begin()); 3240 EXPECT_FALSE(delegate->scroll_begin());
3243 EXPECT_FALSE(delegate->scroll_update()); 3241 EXPECT_FALSE(delegate->scroll_update());
3244 EXPECT_FALSE(delegate->fling()); 3242 EXPECT_FALSE(delegate->fling());
3245 3243
3246 EXPECT_TRUE(delegate->scroll_end()); 3244 EXPECT_TRUE(delegate->scroll_end());
3247 } 3245 }
3248 3246
3249 // Check that appropriate touch events generate double tap gesture events. 3247 // Check that appropriate touch events generate double tap gesture events.
3250 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) { 3248 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) {
3251 scoped_ptr<GestureEventConsumeDelegate> delegate( 3249 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3252 new GestureEventConsumeDelegate()); 3250 new GestureEventConsumeDelegate());
3253 const int kWindowWidth = 123; 3251 const int kWindowWidth = 123;
3254 const int kWindowHeight = 45; 3252 const int kWindowHeight = 45;
3255 const int kTouchId = 2; 3253 const int kTouchId = 2;
3256 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3254 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3257 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3255 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3258 delegate.get(), -1234, bounds, root_window())); 3256 delegate.get(), -1234, bounds, root_window()));
3259 TimedEvents tes; 3257 TimedEvents tes;
3260 3258
3261 // First tap (tested in GestureEventTap) 3259 // First tap (tested in GestureEventTap)
3262 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201), 3260 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201),
3263 kTouchId, tes.Now()); 3261 kTouchId, tes.Now());
3264 DispatchEventUsingWindowDispatcher(&press1); 3262 DispatchEventUsingWindowDispatcher(&press1);
3265 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201), 3263 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201),
3266 kTouchId, tes.LeapForward(50)); 3264 kTouchId, tes.LeapForward(50));
3267 DispatchEventUsingWindowDispatcher(&release1); 3265 DispatchEventUsingWindowDispatcher(&release1);
(...skipping 14 matching lines...) Expand all
3282 EXPECT_TRUE(delegate->end()); 3280 EXPECT_TRUE(delegate->end());
3283 EXPECT_FALSE(delegate->scroll_begin()); 3281 EXPECT_FALSE(delegate->scroll_begin());
3284 EXPECT_FALSE(delegate->scroll_update()); 3282 EXPECT_FALSE(delegate->scroll_update());
3285 EXPECT_FALSE(delegate->scroll_end()); 3283 EXPECT_FALSE(delegate->scroll_end());
3286 3284
3287 EXPECT_EQ(2, delegate->tap_count()); 3285 EXPECT_EQ(2, delegate->tap_count());
3288 } 3286 }
3289 3287
3290 // Check that appropriate touch events generate triple tap gesture events. 3288 // Check that appropriate touch events generate triple tap gesture events.
3291 TEST_F(GestureRecognizerTest, GestureEventTripleTap) { 3289 TEST_F(GestureRecognizerTest, GestureEventTripleTap) {
3292 scoped_ptr<GestureEventConsumeDelegate> delegate( 3290 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3293 new GestureEventConsumeDelegate()); 3291 new GestureEventConsumeDelegate());
3294 const int kWindowWidth = 123; 3292 const int kWindowWidth = 123;
3295 const int kWindowHeight = 45; 3293 const int kWindowHeight = 45;
3296 const int kTouchId = 2; 3294 const int kTouchId = 2;
3297 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3295 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3298 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3296 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3299 delegate.get(), -1234, bounds, root_window())); 3297 delegate.get(), -1234, bounds, root_window()));
3300 TimedEvents tes; 3298 TimedEvents tes;
3301 3299
3302 // First tap (tested in GestureEventTap) 3300 // First tap (tested in GestureEventTap)
3303 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201), 3301 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201),
3304 kTouchId, tes.Now()); 3302 kTouchId, tes.Now());
3305 DispatchEventUsingWindowDispatcher(&press1); 3303 DispatchEventUsingWindowDispatcher(&press1);
3306 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201), 3304 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201),
3307 kTouchId, tes.LeapForward(50)); 3305 kTouchId, tes.LeapForward(50));
3308 DispatchEventUsingWindowDispatcher(&release1); 3306 DispatchEventUsingWindowDispatcher(&release1);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3350 EXPECT_TRUE(delegate->end()); 3348 EXPECT_TRUE(delegate->end());
3351 EXPECT_FALSE(delegate->scroll_begin()); 3349 EXPECT_FALSE(delegate->scroll_begin());
3352 EXPECT_FALSE(delegate->scroll_update()); 3350 EXPECT_FALSE(delegate->scroll_update());
3353 EXPECT_FALSE(delegate->scroll_end()); 3351 EXPECT_FALSE(delegate->scroll_end());
3354 EXPECT_EQ(1 + (i % 3), delegate->tap_count()); 3352 EXPECT_EQ(1 + (i % 3), delegate->tap_count());
3355 } 3353 }
3356 } 3354 }
3357 3355
3358 // Check that we don't get a double tap when the two taps are far apart. 3356 // Check that we don't get a double tap when the two taps are far apart.
3359 TEST_F(GestureRecognizerTest, TwoTapsFarApart) { 3357 TEST_F(GestureRecognizerTest, TwoTapsFarApart) {
3360 scoped_ptr<GestureEventConsumeDelegate> delegate( 3358 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3361 new GestureEventConsumeDelegate()); 3359 new GestureEventConsumeDelegate());
3362 const int kWindowWidth = 123; 3360 const int kWindowWidth = 123;
3363 const int kWindowHeight = 45; 3361 const int kWindowHeight = 45;
3364 const int kTouchId = 2; 3362 const int kTouchId = 2;
3365 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3363 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3366 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3364 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3367 delegate.get(), -1234, bounds, root_window())); 3365 delegate.get(), -1234, bounds, root_window()));
3368 TimedEvents tes; 3366 TimedEvents tes;
3369 3367
3370 // First tap (tested in GestureEventTap) 3368 // First tap (tested in GestureEventTap)
3371 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3369 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3372 kTouchId, tes.Now()); 3370 kTouchId, tes.Now());
3373 DispatchEventUsingWindowDispatcher(&press1); 3371 DispatchEventUsingWindowDispatcher(&press1);
3374 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3372 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3375 kTouchId, tes.LeapForward(50)); 3373 kTouchId, tes.LeapForward(50));
3376 DispatchEventUsingWindowDispatcher(&release1); 3374 DispatchEventUsingWindowDispatcher(&release1);
(...skipping 15 matching lines...) Expand all
3392 EXPECT_FALSE(delegate->scroll_begin()); 3390 EXPECT_FALSE(delegate->scroll_begin());
3393 EXPECT_FALSE(delegate->scroll_update()); 3391 EXPECT_FALSE(delegate->scroll_update());
3394 EXPECT_FALSE(delegate->scroll_end()); 3392 EXPECT_FALSE(delegate->scroll_end());
3395 3393
3396 EXPECT_EQ(1, delegate->tap_count()); 3394 EXPECT_EQ(1, delegate->tap_count());
3397 } 3395 }
3398 3396
3399 // Check that we don't get a double tap when the two taps have a long enough 3397 // Check that we don't get a double tap when the two taps have a long enough
3400 // delay in between. 3398 // delay in between.
3401 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) { 3399 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) {
3402 scoped_ptr<GestureEventConsumeDelegate> delegate( 3400 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3403 new GestureEventConsumeDelegate()); 3401 new GestureEventConsumeDelegate());
3404 const int kWindowWidth = 123; 3402 const int kWindowWidth = 123;
3405 const int kWindowHeight = 45; 3403 const int kWindowHeight = 45;
3406 const int kTouchId = 2; 3404 const int kTouchId = 2;
3407 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3405 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3408 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3406 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3409 delegate.get(), -1234, bounds, root_window())); 3407 delegate.get(), -1234, bounds, root_window()));
3410 TimedEvents tes; 3408 TimedEvents tes;
3411 3409
3412 // First tap (tested in GestureEventTap) 3410 // First tap (tested in GestureEventTap)
3413 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3411 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3414 kTouchId, tes.Now()); 3412 kTouchId, tes.Now());
3415 DispatchEventUsingWindowDispatcher(&press1); 3413 DispatchEventUsingWindowDispatcher(&press1);
3416 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3414 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3417 kTouchId, tes.LeapForward(50)); 3415 kTouchId, tes.LeapForward(50));
3418 DispatchEventUsingWindowDispatcher(&release1); 3416 DispatchEventUsingWindowDispatcher(&release1);
(...skipping 16 matching lines...) Expand all
3435 EXPECT_FALSE(delegate->scroll_update()); 3433 EXPECT_FALSE(delegate->scroll_update());
3436 EXPECT_FALSE(delegate->scroll_end()); 3434 EXPECT_FALSE(delegate->scroll_end());
3437 3435
3438 EXPECT_EQ(1, delegate->tap_count()); 3436 EXPECT_EQ(1, delegate->tap_count());
3439 } 3437 }
3440 3438
3441 // Checks that if the bounding-box of a gesture changes because of change in 3439 // Checks that if the bounding-box of a gesture changes because of change in
3442 // radius of a touch-point, and not because of change in position, then there 3440 // radius of a touch-point, and not because of change in position, then there
3443 // are not gesture events from that. 3441 // are not gesture events from that.
3444 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) { 3442 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) {
3445 scoped_ptr<GestureEventConsumeDelegate> delegate( 3443 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3446 new GestureEventConsumeDelegate()); 3444 new GestureEventConsumeDelegate());
3447 const int kWindowWidth = 234; 3445 const int kWindowWidth = 234;
3448 const int kWindowHeight = 345; 3446 const int kWindowHeight = 345;
3449 const int kTouchId = 5, kTouchId2 = 7; 3447 const int kTouchId = 5, kTouchId2 = 7;
3450 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3448 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3451 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3449 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3452 delegate.get(), -1234, bounds, root_window())); 3450 delegate.get(), -1234, bounds, root_window()));
3453 TimedEvents tes; 3451 TimedEvents tes;
3454 3452
3455 ui::TouchEvent press1( 3453 ui::TouchEvent press1(
3456 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, tes.Now()); 3454 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, tes.Now());
3457 DispatchEventUsingWindowDispatcher(&press1); 3455 DispatchEventUsingWindowDispatcher(&press1);
3458 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 3456 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
3459 3457
3460 delegate->Reset(); 3458 delegate->Reset();
3461 3459
(...skipping 28 matching lines...) Expand all
3490 EXPECT_FALSE(delegate->pinch_update()); 3488 EXPECT_FALSE(delegate->pinch_update());
3491 3489
3492 delegate->Reset(); 3490 delegate->Reset();
3493 } 3491 }
3494 3492
3495 // Checks that slow scrolls deliver the correct deltas. 3493 // Checks that slow scrolls deliver the correct deltas.
3496 // In particular, fix for http;//crbug.com/150573. 3494 // In particular, fix for http;//crbug.com/150573.
3497 TEST_F(GestureRecognizerTest, NoDriftInScroll) { 3495 TEST_F(GestureRecognizerTest, NoDriftInScroll) {
3498 ui::GestureConfiguration::GetInstance() 3496 ui::GestureConfiguration::GetInstance()
3499 ->set_max_touch_move_in_pixels_for_click(3); 3497 ->set_max_touch_move_in_pixels_for_click(3);
3500 scoped_ptr<GestureEventConsumeDelegate> delegate( 3498 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3501 new GestureEventConsumeDelegate()); 3499 new GestureEventConsumeDelegate());
3502 const int kWindowWidth = 234; 3500 const int kWindowWidth = 234;
3503 const int kWindowHeight = 345; 3501 const int kWindowHeight = 345;
3504 const int kTouchId = 5; 3502 const int kTouchId = 5;
3505 TimedEvents tes; 3503 TimedEvents tes;
3506 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3504 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3507 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3505 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3508 delegate.get(), -1234, bounds, root_window())); 3506 delegate.get(), -1234, bounds, root_window()));
3509 3507
3510 ui::TouchEvent press1( 3508 ui::TouchEvent press1(
3511 ui::ET_TOUCH_PRESSED, gfx::Point(101, 208), kTouchId, tes.Now()); 3509 ui::ET_TOUCH_PRESSED, gfx::Point(101, 208), kTouchId, tes.Now());
3512 DispatchEventUsingWindowDispatcher(&press1); 3510 DispatchEventUsingWindowDispatcher(&press1);
3513 EXPECT_TRUE(delegate->begin()); 3511 EXPECT_TRUE(delegate->begin());
3514 3512
3515 delegate->Reset(); 3513 delegate->Reset();
3516 3514
3517 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(101, 206), kTouchId, 3515 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(101, 206), kTouchId,
(...skipping 28 matching lines...) Expand all
3546 EXPECT_TRUE(delegate->scroll_update()); 3544 EXPECT_TRUE(delegate->scroll_update());
3547 EXPECT_EQ(-1, delegate->scroll_y()); 3545 EXPECT_EQ(-1, delegate->scroll_y());
3548 3546
3549 delegate->Reset(); 3547 delegate->Reset();
3550 } 3548 }
3551 3549
3552 // Ensure that move events which are preventDefaulted will cause a tap 3550 // Ensure that move events which are preventDefaulted will cause a tap
3553 // cancel gesture event to be fired if the move would normally cause a 3551 // cancel gesture event to be fired if the move would normally cause a
3554 // scroll. See bug http://crbug.com/146397. 3552 // scroll. See bug http://crbug.com/146397.
3555 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) { 3553 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) {
3556 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3554 std::unique_ptr<ConsumesTouchMovesDelegate> delegate(
3557 new ConsumesTouchMovesDelegate()); 3555 new ConsumesTouchMovesDelegate());
3558 const int kTouchId = 5; 3556 const int kTouchId = 5;
3559 gfx::Rect bounds(100, 200, 123, 45); 3557 gfx::Rect bounds(100, 200, 123, 45);
3560 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3558 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3561 delegate.get(), -1234, bounds, root_window())); 3559 delegate.get(), -1234, bounds, root_window()));
3562 TimedEvents tes; 3560 TimedEvents tes;
3563 3561
3564 delegate->Reset(); 3562 delegate->Reset();
3565 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3563 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3566 kTouchId, tes.Now()); 3564 kTouchId, tes.Now());
3567 3565
3568 delegate->set_consume_touch_move(false); 3566 delegate->set_consume_touch_move(false);
3569 DispatchEventUsingWindowDispatcher(&press); 3567 DispatchEventUsingWindowDispatcher(&press);
3570 delegate->set_consume_touch_move(true); 3568 delegate->set_consume_touch_move(true);
3571 delegate->Reset(); 3569 delegate->Reset();
3572 // Move the touch-point enough so that it would normally be considered a 3570 // Move the touch-point enough so that it would normally be considered a
3573 // scroll. But since the touch-moves will be consumed, no scrolling should 3571 // scroll. But since the touch-moves will be consumed, no scrolling should
3574 // occur. 3572 // occur.
3575 // With the unified gesture detector, we will receive a scroll begin gesture, 3573 // With the unified gesture detector, we will receive a scroll begin gesture,
3576 // whereas with the aura gesture recognizer we won't. 3574 // whereas with the aura gesture recognizer we won't.
3577 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); 3575 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
3578 EXPECT_FALSE(delegate->tap()); 3576 EXPECT_FALSE(delegate->tap());
3579 EXPECT_FALSE(delegate->tap_down()); 3577 EXPECT_FALSE(delegate->tap_down());
3580 EXPECT_TRUE(delegate->tap_cancel()); 3578 EXPECT_TRUE(delegate->tap_cancel());
3581 EXPECT_FALSE(delegate->begin()); 3579 EXPECT_FALSE(delegate->begin());
3582 EXPECT_FALSE(delegate->scroll_update()); 3580 EXPECT_FALSE(delegate->scroll_update());
3583 EXPECT_FALSE(delegate->scroll_end()); 3581 EXPECT_FALSE(delegate->scroll_end());
3584 } 3582 }
3585 3583
3586 TEST_F(GestureRecognizerTest, CancelAllActiveTouches) { 3584 TEST_F(GestureRecognizerTest, CancelAllActiveTouches) {
3587 scoped_ptr<GestureEventConsumeDelegate> delegate( 3585 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3588 new GestureEventConsumeDelegate()); 3586 new GestureEventConsumeDelegate());
3589 TimedEvents tes; 3587 TimedEvents tes;
3590 const int kWindowWidth = 800; 3588 const int kWindowWidth = 800;
3591 const int kWindowHeight = 600; 3589 const int kWindowHeight = 600;
3592 const int kTouchId1 = 1; 3590 const int kTouchId1 = 1;
3593 const int kTouchId2 = 2; 3591 const int kTouchId2 = 2;
3594 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3592 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3595 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3593 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3596 delegate.get(), -1234, bounds, root_window())); 3594 delegate.get(), -1234, bounds, root_window()));
3597 scoped_ptr<TestEventHandler> handler(new TestEventHandler()); 3595 std::unique_ptr<TestEventHandler> handler(new TestEventHandler());
3598 window->AddPreTargetHandler(handler.get()); 3596 window->AddPreTargetHandler(handler.get());
3599 3597
3600 // Start a gesture sequence on |window|. Then cancel all touches. 3598 // Start a gesture sequence on |window|. Then cancel all touches.
3601 // Make sure |window| receives a touch-cancel event. 3599 // Make sure |window| receives a touch-cancel event.
3602 delegate->Reset(); 3600 delegate->Reset();
3603 ui::TouchEvent press( 3601 ui::TouchEvent press(
3604 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now()); 3602 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now());
3605 DispatchEventUsingWindowDispatcher(&press); 3603 DispatchEventUsingWindowDispatcher(&press);
3606 EXPECT_2_EVENTS( 3604 EXPECT_2_EVENTS(
3607 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN); 3605 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
(...skipping 28 matching lines...) Expand all
3636 ui::ET_GESTURE_END, 3634 ui::ET_GESTURE_END,
3637 ui::ET_GESTURE_END); 3635 ui::ET_GESTURE_END);
3638 const std::vector<gfx::PointF>& points = handler->cancelled_touch_points(); 3636 const std::vector<gfx::PointF>& points = handler->cancelled_touch_points();
3639 EXPECT_EQ(2U, points.size()); 3637 EXPECT_EQ(2U, points.size());
3640 EXPECT_EQ(gfx::PointF(101.f, 201.f), points[0]); 3638 EXPECT_EQ(gfx::PointF(101.f, 201.f), points[0]);
3641 EXPECT_EQ(gfx::PointF(350.f, 300.f), points[1]); 3639 EXPECT_EQ(gfx::PointF(350.f, 300.f), points[1]);
3642 } 3640 }
3643 3641
3644 // Check that appropriate touch events generate show press events 3642 // Check that appropriate touch events generate show press events
3645 TEST_F(GestureRecognizerTest, GestureEventShowPress) { 3643 TEST_F(GestureRecognizerTest, GestureEventShowPress) {
3646 scoped_ptr<GestureEventConsumeDelegate> delegate( 3644 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3647 new GestureEventConsumeDelegate()); 3645 new GestureEventConsumeDelegate());
3648 TimedEvents tes; 3646 TimedEvents tes;
3649 const int kWindowWidth = 123; 3647 const int kWindowWidth = 123;
3650 const int kWindowHeight = 45; 3648 const int kWindowHeight = 45;
3651 const int kTouchId = 2; 3649 const int kTouchId = 2;
3652 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3650 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3653 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3651 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3654 delegate.get(), -1234, bounds, root_window())); 3652 delegate.get(), -1234, bounds, root_window()));
3655 3653
3656 delegate->Reset(); 3654 delegate->Reset();
3657 3655
3658 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3656 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3659 kTouchId, tes.Now()); 3657 kTouchId, tes.Now());
3660 DispatchEventUsingWindowDispatcher(&press1); 3658 DispatchEventUsingWindowDispatcher(&press1);
3661 EXPECT_TRUE(delegate->tap_down()); 3659 EXPECT_TRUE(delegate->tap_down());
3662 EXPECT_TRUE(delegate->begin()); 3660 EXPECT_TRUE(delegate->begin());
3663 EXPECT_FALSE(delegate->tap_cancel()); 3661 EXPECT_FALSE(delegate->tap_cancel());
(...skipping 12 matching lines...) Expand all
3676 DispatchEventUsingWindowDispatcher(&release1); 3674 DispatchEventUsingWindowDispatcher(&release1);
3677 EXPECT_FALSE(delegate->long_press()); 3675 EXPECT_FALSE(delegate->long_press());
3678 3676
3679 // Note the tap isn't dispatched until the release 3677 // Note the tap isn't dispatched until the release
3680 EXPECT_FALSE(delegate->tap_cancel()); 3678 EXPECT_FALSE(delegate->tap_cancel());
3681 EXPECT_TRUE(delegate->tap()); 3679 EXPECT_TRUE(delegate->tap());
3682 } 3680 }
3683 3681
3684 // Check that scrolling cancels a show press 3682 // Check that scrolling cancels a show press
3685 TEST_F(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) { 3683 TEST_F(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) {
3686 scoped_ptr<GestureEventConsumeDelegate> delegate( 3684 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3687 new GestureEventConsumeDelegate()); 3685 new GestureEventConsumeDelegate());
3688 TimedEvents tes; 3686 TimedEvents tes;
3689 const int kWindowWidth = 123; 3687 const int kWindowWidth = 123;
3690 const int kWindowHeight = 45; 3688 const int kWindowHeight = 45;
3691 const int kTouchId = 6; 3689 const int kTouchId = 6;
3692 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3690 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3693 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3691 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3694 delegate.get(), -1234, bounds, root_window())); 3692 delegate.get(), -1234, bounds, root_window()));
3695 3693
3696 delegate->Reset(); 3694 delegate->Reset();
3697 3695
3698 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3696 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3699 kTouchId, tes.Now()); 3697 kTouchId, tes.Now());
3700 DispatchEventUsingWindowDispatcher(&press1); 3698 DispatchEventUsingWindowDispatcher(&press1);
3701 EXPECT_TRUE(delegate->tap_down()); 3699 EXPECT_TRUE(delegate->tap_down());
3702 3700
3703 // We haven't pressed long enough for a show press to occur 3701 // We haven't pressed long enough for a show press to occur
(...skipping 10 matching lines...) Expand all
3714 delegate->Reset(); 3712 delegate->Reset();
3715 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3713 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3716 kTouchId, tes.LeapForward(10)); 3714 kTouchId, tes.LeapForward(10));
3717 DispatchEventUsingWindowDispatcher(&release1); 3715 DispatchEventUsingWindowDispatcher(&release1);
3718 EXPECT_FALSE(delegate->show_press()); 3716 EXPECT_FALSE(delegate->show_press());
3719 EXPECT_FALSE(delegate->tap_cancel()); 3717 EXPECT_FALSE(delegate->tap_cancel());
3720 } 3718 }
3721 3719
3722 // Test that show press events are sent immediately on tap 3720 // Test that show press events are sent immediately on tap
3723 TEST_F(GestureRecognizerTest, GestureEventShowPressSentOnTap) { 3721 TEST_F(GestureRecognizerTest, GestureEventShowPressSentOnTap) {
3724 scoped_ptr<GestureEventConsumeDelegate> delegate( 3722 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3725 new GestureEventConsumeDelegate()); 3723 new GestureEventConsumeDelegate());
3726 TimedEvents tes; 3724 TimedEvents tes;
3727 const int kWindowWidth = 123; 3725 const int kWindowWidth = 123;
3728 const int kWindowHeight = 45; 3726 const int kWindowHeight = 45;
3729 const int kTouchId = 6; 3727 const int kTouchId = 6;
3730 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3728 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3731 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3729 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3732 delegate.get(), -1234, bounds, root_window())); 3730 delegate.get(), -1234, bounds, root_window()));
3733 3731
3734 delegate->Reset(); 3732 delegate->Reset();
3735 3733
3736 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3734 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3737 kTouchId, tes.Now()); 3735 kTouchId, tes.Now());
3738 DispatchEventUsingWindowDispatcher(&press1); 3736 DispatchEventUsingWindowDispatcher(&press1);
3739 EXPECT_TRUE(delegate->tap_down()); 3737 EXPECT_TRUE(delegate->tap_down());
3740 3738
3741 // We haven't pressed long enough for a show press to occur 3739 // We haven't pressed long enough for a show press to occur
3742 EXPECT_FALSE(delegate->show_press()); 3740 EXPECT_FALSE(delegate->show_press());
3743 EXPECT_FALSE(delegate->tap_cancel()); 3741 EXPECT_FALSE(delegate->tap_cancel());
3744 3742
3745 delegate->Reset(); 3743 delegate->Reset();
3746 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3744 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3747 kTouchId, tes.LeapForward(50)); 3745 kTouchId, tes.LeapForward(50));
3748 DispatchEventUsingWindowDispatcher(&release1); 3746 DispatchEventUsingWindowDispatcher(&release1);
3749 EXPECT_TRUE(delegate->show_press()); 3747 EXPECT_TRUE(delegate->show_press());
3750 EXPECT_FALSE(delegate->tap_cancel()); 3748 EXPECT_FALSE(delegate->tap_cancel());
3751 EXPECT_TRUE(delegate->tap()); 3749 EXPECT_TRUE(delegate->tap());
3752 } 3750 }
3753 3751
3754 // Test that consuming the first move touch event prevents a scroll. 3752 // Test that consuming the first move touch event prevents a scroll.
3755 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) { 3753 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) {
3756 scoped_ptr<QueueTouchEventDelegate> delegate( 3754 std::unique_ptr<QueueTouchEventDelegate> delegate(
3757 new QueueTouchEventDelegate(host()->dispatcher())); 3755 new QueueTouchEventDelegate(host()->dispatcher()));
3758 TimedEvents tes; 3756 TimedEvents tes;
3759 const int kTouchId = 7; 3757 const int kTouchId = 7;
3760 gfx::Rect bounds(0, 0, 1000, 1000); 3758 gfx::Rect bounds(0, 0, 1000, 1000);
3761 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3759 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3762 delegate.get(), -1234, bounds, root_window())); 3760 delegate.get(), -1234, bounds, root_window()));
3763 delegate->set_window(window.get()); 3761 delegate->set_window(window.get());
3764 3762
3765 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3763 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3766 kTouchId, tes.Now()); 3764 kTouchId, tes.Now());
3767 DispatchEventUsingWindowDispatcher(&press); 3765 DispatchEventUsingWindowDispatcher(&press);
3768 delegate->ReceivedAck(); 3766 delegate->ReceivedAck();
3769 3767
3770 // A touch move within the slop region is never consumed in web contents. The 3768 // A touch move within the slop region is never consumed in web contents. The
3771 // unified GR won't prevent scroll if a touch move within the slop region is 3769 // unified GR won't prevent scroll if a touch move within the slop region is
3772 // consumed, so make sure this touch move exceeds the slop region. 3770 // consumed, so make sure this touch move exceeds the slop region.
3773 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 3771 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10),
3774 kTouchId, tes.Now()); 3772 kTouchId, tes.Now());
3775 DispatchEventUsingWindowDispatcher(&move1); 3773 DispatchEventUsingWindowDispatcher(&move1);
3776 delegate->ReceivedAckPreventDefaulted(); 3774 delegate->ReceivedAckPreventDefaulted();
3777 3775
3778 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 3776 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
3779 kTouchId, tes.Now()); 3777 kTouchId, tes.Now());
3780 DispatchEventUsingWindowDispatcher(&move2); 3778 DispatchEventUsingWindowDispatcher(&move2);
3781 delegate->ReceivedAck(); 3779 delegate->ReceivedAck();
3782 3780
3783 // With the unified gesture detector, consuming the first touch move event 3781 // With the unified gesture detector, consuming the first touch move event
3784 // won't prevent all future scrolling. 3782 // won't prevent all future scrolling.
3785 EXPECT_TRUE(delegate->scroll_begin()); 3783 EXPECT_TRUE(delegate->scroll_begin());
3786 EXPECT_TRUE(delegate->scroll_update()); 3784 EXPECT_TRUE(delegate->scroll_update());
3787 } 3785 }
3788 3786
3789 // Test that consuming the first move touch doesn't prevent a tap. 3787 // Test that consuming the first move touch doesn't prevent a tap.
3790 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) { 3788 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) {
3791 scoped_ptr<QueueTouchEventDelegate> delegate( 3789 std::unique_ptr<QueueTouchEventDelegate> delegate(
3792 new QueueTouchEventDelegate(host()->dispatcher())); 3790 new QueueTouchEventDelegate(host()->dispatcher()));
3793 TimedEvents tes; 3791 TimedEvents tes;
3794 const int kTouchId = 7; 3792 const int kTouchId = 7;
3795 gfx::Rect bounds(0, 0, 1000, 1000); 3793 gfx::Rect bounds(0, 0, 1000, 1000);
3796 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3794 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3797 delegate.get(), -1234, bounds, root_window())); 3795 delegate.get(), -1234, bounds, root_window()));
3798 delegate->set_window(window.get()); 3796 delegate->set_window(window.get());
3799 3797
3800 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3798 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3801 kTouchId, tes.Now()); 3799 kTouchId, tes.Now());
3802 DispatchEventUsingWindowDispatcher(&press); 3800 DispatchEventUsingWindowDispatcher(&press);
3803 delegate->ReceivedAck(); 3801 delegate->ReceivedAck();
3804 3802
3805 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2), 3803 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
3806 kTouchId, tes.Now()); 3804 kTouchId, tes.Now());
3807 DispatchEventUsingWindowDispatcher(&move); 3805 DispatchEventUsingWindowDispatcher(&move);
3808 delegate->ReceivedAckPreventDefaulted(); 3806 delegate->ReceivedAckPreventDefaulted();
3809 3807
3810 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(2, 2), 3808 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(2, 2),
3811 kTouchId, tes.LeapForward(50)); 3809 kTouchId, tes.LeapForward(50));
3812 DispatchEventUsingWindowDispatcher(&release); 3810 DispatchEventUsingWindowDispatcher(&release);
3813 delegate->ReceivedAck(); 3811 delegate->ReceivedAck();
3814 3812
3815 EXPECT_TRUE(delegate->tap()); 3813 EXPECT_TRUE(delegate->tap());
3816 } 3814 }
3817 3815
3818 // Test that consuming the first move touch doesn't prevent a long press. 3816 // Test that consuming the first move touch doesn't prevent a long press.
3819 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) { 3817 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) {
3820 scoped_ptr<QueueTouchEventDelegate> delegate( 3818 std::unique_ptr<QueueTouchEventDelegate> delegate(
3821 new QueueTouchEventDelegate(host()->dispatcher())); 3819 new QueueTouchEventDelegate(host()->dispatcher()));
3822 TimedEvents tes; 3820 TimedEvents tes;
3823 const int kWindowWidth = 123; 3821 const int kWindowWidth = 123;
3824 const int kWindowHeight = 45; 3822 const int kWindowHeight = 45;
3825 const int kTouchId = 2; 3823 const int kTouchId = 2;
3826 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3824 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3827 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3825 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3828 delegate.get(), -1234, bounds, root_window())); 3826 delegate.get(), -1234, bounds, root_window()));
3829 delegate->set_window(window.get()); 3827 delegate->set_window(window.get());
3830 3828
3831 delegate->Reset(); 3829 delegate->Reset();
3832 3830
3833 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3831 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3834 kTouchId, tes.Now()); 3832 kTouchId, tes.Now());
3835 DispatchEventUsingWindowDispatcher(&press1); 3833 DispatchEventUsingWindowDispatcher(&press1);
3836 delegate->ReceivedAck(); 3834 delegate->ReceivedAck();
3837 3835
3838 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103, 203), 3836 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103, 203),
3839 kTouchId, tes.Now()); 3837 kTouchId, tes.Now());
3840 DispatchEventUsingWindowDispatcher(&move); 3838 DispatchEventUsingWindowDispatcher(&move);
3841 delegate->ReceivedAckPreventDefaulted(); 3839 delegate->ReceivedAckPreventDefaulted();
3842 3840
3843 // Wait until the timer runs out 3841 // Wait until the timer runs out
3844 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 3842 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
3845 EXPECT_TRUE(delegate->long_press()); 3843 EXPECT_TRUE(delegate->long_press());
3846 } 3844 }
3847 3845
3848 // Tests that the deltas are correct when leaving the slop region very slowly. 3846 // Tests that the deltas are correct when leaving the slop region very slowly.
3849 TEST_F(GestureRecognizerTest, TestExceedingSlopSlowly) { 3847 TEST_F(GestureRecognizerTest, TestExceedingSlopSlowly) {
3850 ui::GestureConfiguration::GetInstance() 3848 ui::GestureConfiguration::GetInstance()
3851 ->set_max_touch_move_in_pixels_for_click(3); 3849 ->set_max_touch_move_in_pixels_for_click(3);
3852 scoped_ptr<GestureEventConsumeDelegate> delegate( 3850 std::unique_ptr<GestureEventConsumeDelegate> delegate(
3853 new GestureEventConsumeDelegate()); 3851 new GestureEventConsumeDelegate());
3854 const int kWindowWidth = 234; 3852 const int kWindowWidth = 234;
3855 const int kWindowHeight = 345; 3853 const int kWindowHeight = 345;
3856 const int kTouchId = 5; 3854 const int kTouchId = 5;
3857 TimedEvents tes; 3855 TimedEvents tes;
3858 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3856 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3859 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3857 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3860 delegate.get(), -1234, bounds, root_window())); 3858 delegate.get(), -1234, bounds, root_window()));
3861 3859
3862 ui::TouchEvent press( 3860 ui::TouchEvent press(
3863 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId, tes.Now()); 3861 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId, tes.Now());
3864 DispatchEventUsingWindowDispatcher(&press); 3862 DispatchEventUsingWindowDispatcher(&press);
3865 EXPECT_FALSE(delegate->scroll_begin()); 3863 EXPECT_FALSE(delegate->scroll_begin());
3866 EXPECT_FALSE(delegate->scroll_update()); 3864 EXPECT_FALSE(delegate->scroll_update());
3867 delegate->Reset(); 3865 delegate->Reset();
3868 3866
3869 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(11, 10), kTouchId, 3867 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(11, 10), kTouchId,
(...skipping 29 matching lines...) Expand all
3899 tes.LeapForward(40)); 3897 tes.LeapForward(40));
3900 DispatchEventUsingWindowDispatcher(&move4); 3898 DispatchEventUsingWindowDispatcher(&move4);
3901 EXPECT_FALSE(delegate->scroll_begin()); 3899 EXPECT_FALSE(delegate->scroll_begin());
3902 EXPECT_TRUE(delegate->scroll_update()); 3900 EXPECT_TRUE(delegate->scroll_update());
3903 EXPECT_NEAR(0.9, delegate->scroll_x(), 0.0001); 3901 EXPECT_NEAR(0.9, delegate->scroll_x(), 0.0001);
3904 EXPECT_EQ(0.f, delegate->scroll_x_hint()); 3902 EXPECT_EQ(0.f, delegate->scroll_x_hint());
3905 delegate->Reset(); 3903 delegate->Reset();
3906 } 3904 }
3907 3905
3908 TEST_F(GestureRecognizerTest, ScrollAlternatelyConsumedTest) { 3906 TEST_F(GestureRecognizerTest, ScrollAlternatelyConsumedTest) {
3909 scoped_ptr<QueueTouchEventDelegate> delegate( 3907 std::unique_ptr<QueueTouchEventDelegate> delegate(
3910 new QueueTouchEventDelegate(host()->dispatcher())); 3908 new QueueTouchEventDelegate(host()->dispatcher()));
3911 TimedEvents tes; 3909 TimedEvents tes;
3912 const int kWindowWidth = 3000; 3910 const int kWindowWidth = 3000;
3913 const int kWindowHeight = 3000; 3911 const int kWindowHeight = 3000;
3914 const int kTouchId = 2; 3912 const int kTouchId = 2;
3915 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3913 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3916 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3914 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3917 delegate.get(), -1234, bounds, root_window())); 3915 delegate.get(), -1234, bounds, root_window()));
3918 delegate->set_window(window.get()); 3916 delegate->set_window(window.get());
3919 3917
3920 delegate->Reset(); 3918 delegate->Reset();
3921 3919
3922 int x = 0; 3920 int x = 0;
3923 int y = 0; 3921 int y = 0;
3924 3922
3925 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), 3923 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(x, y),
3926 kTouchId, tes.Now()); 3924 kTouchId, tes.Now());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3959 ui::ET_TOUCH_MOVED, gfx::Point(x, y), kTouchId, tes.Now()); 3957 ui::ET_TOUCH_MOVED, gfx::Point(x, y), kTouchId, tes.Now());
3960 DispatchEventUsingWindowDispatcher(&move3); 3958 DispatchEventUsingWindowDispatcher(&move3);
3961 delegate->ReceivedAckPreventDefaulted(); 3959 delegate->ReceivedAckPreventDefaulted();
3962 EXPECT_FALSE(delegate->scroll_begin()); 3960 EXPECT_FALSE(delegate->scroll_begin());
3963 EXPECT_FALSE(delegate->scroll_update()); 3961 EXPECT_FALSE(delegate->scroll_update());
3964 delegate->Reset(); 3962 delegate->Reset();
3965 } 3963 }
3966 } 3964 }
3967 3965
3968 TEST_F(GestureRecognizerTest, PinchAlternatelyConsumedTest) { 3966 TEST_F(GestureRecognizerTest, PinchAlternatelyConsumedTest) {
3969 scoped_ptr<QueueTouchEventDelegate> delegate( 3967 std::unique_ptr<QueueTouchEventDelegate> delegate(
3970 new QueueTouchEventDelegate(host()->dispatcher())); 3968 new QueueTouchEventDelegate(host()->dispatcher()));
3971 TimedEvents tes; 3969 TimedEvents tes;
3972 const int kWindowWidth = 3000; 3970 const int kWindowWidth = 3000;
3973 const int kWindowHeight = 3000; 3971 const int kWindowHeight = 3000;
3974 const int kTouchId1 = 5; 3972 const int kTouchId1 = 5;
3975 const int kTouchId2 = 7; 3973 const int kTouchId2 = 7;
3976 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3974 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3977 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3975 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3978 delegate.get(), -1234, bounds, root_window())); 3976 delegate.get(), -1234, bounds, root_window()));
3979 delegate->set_window(window.get()); 3977 delegate->set_window(window.get());
3980 delegate->Reset(); 3978 delegate->Reset();
3981 3979
3982 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3980 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3983 kTouchId1, tes.Now()); 3981 kTouchId1, tes.Now());
3984 DispatchEventUsingWindowDispatcher(&press1); 3982 DispatchEventUsingWindowDispatcher(&press1);
3985 delegate->ReceivedAck(); 3983 delegate->ReceivedAck();
3986 EXPECT_FALSE(delegate->scroll_begin()); 3984 EXPECT_FALSE(delegate->scroll_begin());
3987 EXPECT_FALSE(delegate->scroll_update()); 3985 EXPECT_FALSE(delegate->scroll_update());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4044 EXPECT_FALSE(delegate->scroll_end()); 4042 EXPECT_FALSE(delegate->scroll_end());
4045 EXPECT_FALSE(delegate->pinch_begin()); 4043 EXPECT_FALSE(delegate->pinch_begin());
4046 EXPECT_FALSE(delegate->pinch_update()); 4044 EXPECT_FALSE(delegate->pinch_update());
4047 EXPECT_FALSE(delegate->pinch_end()); 4045 EXPECT_FALSE(delegate->pinch_end());
4048 delegate->Reset(); 4046 delegate->Reset();
4049 } 4047 }
4050 } 4048 }
4051 4049
4052 // Test that touch event flags are passed through to the gesture event. 4050 // Test that touch event flags are passed through to the gesture event.
4053 TEST_F(GestureRecognizerTest, GestureEventFlagsPassedFromTouchEvent) { 4051 TEST_F(GestureRecognizerTest, GestureEventFlagsPassedFromTouchEvent) {
4054 scoped_ptr<GestureEventConsumeDelegate> delegate( 4052 std::unique_ptr<GestureEventConsumeDelegate> delegate(
4055 new GestureEventConsumeDelegate()); 4053 new GestureEventConsumeDelegate());
4056 TimedEvents tes; 4054 TimedEvents tes;
4057 const int kWindowWidth = 123; 4055 const int kWindowWidth = 123;
4058 const int kWindowHeight = 45; 4056 const int kWindowHeight = 45;
4059 const int kTouchId = 6; 4057 const int kTouchId = 6;
4060 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 4058 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
4061 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4059 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4062 delegate.get(), -1234, bounds, root_window())); 4060 delegate.get(), -1234, bounds, root_window()));
4063 4061
4064 delegate->Reset(); 4062 delegate->Reset();
4065 4063
4066 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 4064 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
4067 kTouchId, tes.Now()); 4065 kTouchId, tes.Now());
4068 DispatchEventUsingWindowDispatcher(&press1); 4066 DispatchEventUsingWindowDispatcher(&press1);
4069 EXPECT_TRUE(delegate->tap_down()); 4067 EXPECT_TRUE(delegate->tap_down());
4070 4068
4071 int default_flags = delegate->flags(); 4069 int default_flags = delegate->flags();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4118 ui::EventTimeForNow()); 4116 ui::EventTimeForNow());
4119 DispatchEventUsingWindowDispatcher(&press1); 4117 DispatchEventUsingWindowDispatcher(&press1);
4120 EXPECT_TRUE(window != NULL); 4118 EXPECT_TRUE(window != NULL);
4121 4119
4122 // Wait until the timer runs out. 4120 // Wait until the timer runs out.
4123 delegate.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 4121 delegate.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
4124 EXPECT_EQ(NULL, window); 4122 EXPECT_EQ(NULL, window);
4125 } 4123 }
4126 4124
4127 TEST_F(GestureRecognizerWithSwitchTest, GestureEventSmallPinchDisabled) { 4125 TEST_F(GestureRecognizerWithSwitchTest, GestureEventSmallPinchDisabled) {
4128 scoped_ptr<GestureEventConsumeDelegate> delegate( 4126 std::unique_ptr<GestureEventConsumeDelegate> delegate(
4129 new GestureEventConsumeDelegate()); 4127 new GestureEventConsumeDelegate());
4130 TimedEvents tes; 4128 TimedEvents tes;
4131 const int kWindowWidth = 300; 4129 const int kWindowWidth = 300;
4132 const int kWindowHeight = 400; 4130 const int kWindowHeight = 400;
4133 const int kTouchId1 = 3; 4131 const int kTouchId1 = 3;
4134 const int kTouchId2 = 5; 4132 const int kTouchId2 = 5;
4135 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 4133 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
4136 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4134 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4137 delegate.get(), -1234, bounds, root_window())); 4135 delegate.get(), -1234, bounds, root_window()));
4138 4136
4139 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 4137 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
4140 kTouchId1, tes.Now()); 4138 kTouchId1, tes.Now());
4141 DispatchEventUsingWindowDispatcher(&press1); 4139 DispatchEventUsingWindowDispatcher(&press1);
4142 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 4140 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
4143 kTouchId2, tes.Now()); 4141 kTouchId2, tes.Now());
4144 DispatchEventUsingWindowDispatcher(&press2); 4142 DispatchEventUsingWindowDispatcher(&press2);
4145 4143
4146 // Move the first finger. 4144 // Move the first finger.
(...skipping 10 matching lines...) Expand all
4157 // No pinch update occurs, as kCompensateForUnstablePinchZoom is on and 4155 // No pinch update occurs, as kCompensateForUnstablePinchZoom is on and
4158 // |min_pinch_update_span_delta| was nonzero, and this is a very small pinch. 4156 // |min_pinch_update_span_delta| was nonzero, and this is a very small pinch.
4159 delegate->Reset(); 4157 delegate->Reset();
4160 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(65, 202), 4158 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(65, 202),
4161 kTouchId1, tes.Now()); 4159 kTouchId1, tes.Now());
4162 DispatchEventUsingWindowDispatcher(&move2); 4160 DispatchEventUsingWindowDispatcher(&move2);
4163 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 4161 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
4164 } 4162 }
4165 4163
4166 TEST_F(GestureRecognizerTest, GestureEventSmallPinchEnabled) { 4164 TEST_F(GestureRecognizerTest, GestureEventSmallPinchEnabled) {
4167 scoped_ptr<GestureEventConsumeDelegate> delegate( 4165 std::unique_ptr<GestureEventConsumeDelegate> delegate(
4168 new GestureEventConsumeDelegate()); 4166 new GestureEventConsumeDelegate());
4169 TimedEvents tes; 4167 TimedEvents tes;
4170 const int kWindowWidth = 300; 4168 const int kWindowWidth = 300;
4171 const int kWindowHeight = 400; 4169 const int kWindowHeight = 400;
4172 const int kTouchId1 = 3; 4170 const int kTouchId1 = 3;
4173 const int kTouchId2 = 5; 4171 const int kTouchId2 = 5;
4174 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 4172 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
4175 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4173 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4176 delegate.get(), -1234, bounds, root_window())); 4174 delegate.get(), -1234, bounds, root_window()));
4177 4175
4178 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 4176 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
4179 kTouchId1, tes.Now()); 4177 kTouchId1, tes.Now());
4180 DispatchEventUsingWindowDispatcher(&press1); 4178 DispatchEventUsingWindowDispatcher(&press1);
4181 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 4179 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
4182 kTouchId2, tes.Now()); 4180 kTouchId2, tes.Now());
4183 DispatchEventUsingWindowDispatcher(&press2); 4181 DispatchEventUsingWindowDispatcher(&press2);
4184 4182
4185 // Move the first finger. 4183 // Move the first finger.
(...skipping 12 matching lines...) Expand all
4198 kTouchId1, tes.Now()); 4196 kTouchId1, tes.Now());
4199 DispatchEventUsingWindowDispatcher(&move2); 4197 DispatchEventUsingWindowDispatcher(&move2);
4200 EXPECT_2_EVENTS(delegate->events(), 4198 EXPECT_2_EVENTS(delegate->events(),
4201 ui::ET_GESTURE_SCROLL_UPDATE, 4199 ui::ET_GESTURE_SCROLL_UPDATE,
4202 ui::ET_GESTURE_PINCH_UPDATE); 4200 ui::ET_GESTURE_PINCH_UPDATE);
4203 } 4201 }
4204 4202
4205 // Tests that delaying the ack of a touch release doesn't trigger a long press 4203 // Tests that delaying the ack of a touch release doesn't trigger a long press
4206 // gesture. 4204 // gesture.
4207 TEST_F(GestureRecognizerTest, EagerGestureDetection) { 4205 TEST_F(GestureRecognizerTest, EagerGestureDetection) {
4208 scoped_ptr<QueueTouchEventDelegate> delegate( 4206 std::unique_ptr<QueueTouchEventDelegate> delegate(
4209 new QueueTouchEventDelegate(host()->dispatcher())); 4207 new QueueTouchEventDelegate(host()->dispatcher()));
4210 TimedEvents tes; 4208 TimedEvents tes;
4211 const int kTouchId = 2; 4209 const int kTouchId = 2;
4212 gfx::Rect bounds(100, 200, 100, 100); 4210 gfx::Rect bounds(100, 200, 100, 100);
4213 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4211 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4214 delegate.get(), -1234, bounds, root_window())); 4212 delegate.get(), -1234, bounds, root_window()));
4215 delegate->set_window(window.get()); 4213 delegate->set_window(window.get());
4216 4214
4217 delegate->Reset(); 4215 delegate->Reset();
4218 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 4216 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
4219 kTouchId, tes.Now()); 4217 kTouchId, tes.Now());
4220 DispatchEventUsingWindowDispatcher(&press); 4218 DispatchEventUsingWindowDispatcher(&press);
4221 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 4219 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
4222 kTouchId, tes.LeapForward(50)); 4220 kTouchId, tes.LeapForward(50));
4223 DispatchEventUsingWindowDispatcher(&release); 4221 DispatchEventUsingWindowDispatcher(&release);
4224 4222
4225 delegate->Reset(); 4223 delegate->Reset();
4226 // Ack the touch press. 4224 // Ack the touch press.
4227 delegate->ReceivedAck(); 4225 delegate->ReceivedAck();
4228 EXPECT_TRUE(delegate->tap_down()); 4226 EXPECT_TRUE(delegate->tap_down());
4229 4227
4230 delegate->Reset(); 4228 delegate->Reset();
4231 // Wait until the long press event would fire (if we weren't eager). 4229 // Wait until the long press event would fire (if we weren't eager).
4232 DelayByLongPressTimeout(); 4230 DelayByLongPressTimeout();
4233 4231
4234 // Ack the touch release. 4232 // Ack the touch release.
4235 delegate->ReceivedAck(); 4233 delegate->ReceivedAck();
4236 EXPECT_TRUE(delegate->tap()); 4234 EXPECT_TRUE(delegate->tap());
4237 EXPECT_FALSE(delegate->long_press()); 4235 EXPECT_FALSE(delegate->long_press());
4238 } 4236 }
4239 4237
4240 // This tests crbug.com/405519, in which touch events which the gesture detector 4238 // This tests crbug.com/405519, in which touch events which the gesture detector
4241 // ignores interfere with gesture recognition. 4239 // ignores interfere with gesture recognition.
4242 TEST_F(GestureRecognizerTest, IgnoredEventsDontBreakGestureRecognition) { 4240 TEST_F(GestureRecognizerTest, IgnoredEventsDontBreakGestureRecognition) {
4243 scoped_ptr<QueueTouchEventDelegate> delegate( 4241 std::unique_ptr<QueueTouchEventDelegate> delegate(
4244 new QueueTouchEventDelegate(host()->dispatcher())); 4242 new QueueTouchEventDelegate(host()->dispatcher()));
4245 TimedEvents tes; 4243 TimedEvents tes;
4246 const int kWindowWidth = 300; 4244 const int kWindowWidth = 300;
4247 const int kWindowHeight = 400; 4245 const int kWindowHeight = 400;
4248 const int kTouchId1 = 3; 4246 const int kTouchId1 = 3;
4249 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 4247 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
4250 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4248 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4251 delegate.get(), -1234, bounds, root_window())); 4249 delegate.get(), -1234, bounds, root_window()));
4252 delegate->set_window(window.get()); 4250 delegate->set_window(window.get());
4253 4251
4254 ui::TouchEvent press1( 4252 ui::TouchEvent press1(
4255 ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), kTouchId1, tes.Now()); 4253 ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), kTouchId1, tes.Now());
4256 DispatchEventUsingWindowDispatcher(&press1); 4254 DispatchEventUsingWindowDispatcher(&press1);
4257 delegate->ReceivedAck(); 4255 delegate->ReceivedAck();
4258 4256
4259 EXPECT_2_EVENTS( 4257 EXPECT_2_EVENTS(
4260 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN); 4258 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
(...skipping 26 matching lines...) Expand all
4287 4285
4288 // Ack the previous valid event. The intermediary invalid event shouldn't 4286 // Ack the previous valid event. The intermediary invalid event shouldn't
4289 // interfere. 4287 // interfere.
4290 delegate->ReceivedAck(); 4288 delegate->ReceivedAck();
4291 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 4289 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
4292 } 4290 }
4293 4291
4294 // Tests that an event stream can have a mix of sync and async acks. 4292 // Tests that an event stream can have a mix of sync and async acks.
4295 TEST_F(GestureRecognizerTest, 4293 TEST_F(GestureRecognizerTest,
4296 MixedSyncAndAsyncAcksDontCauseOutOfOrderDispatch) { 4294 MixedSyncAndAsyncAcksDontCauseOutOfOrderDispatch) {
4297 scoped_ptr<QueueTouchEventDelegate> delegate( 4295 std::unique_ptr<QueueTouchEventDelegate> delegate(
4298 new QueueTouchEventDelegate(host()->dispatcher())); 4296 new QueueTouchEventDelegate(host()->dispatcher()));
4299 TimedEvents tes; 4297 TimedEvents tes;
4300 const int kWindowWidth = 300; 4298 const int kWindowWidth = 300;
4301 const int kWindowHeight = 400; 4299 const int kWindowHeight = 400;
4302 const int kTouchId1 = 3; 4300 const int kTouchId1 = 3;
4303 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 4301 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
4304 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4302 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4305 delegate.get(), -1234, bounds, root_window())); 4303 delegate.get(), -1234, bounds, root_window()));
4306 delegate->set_window(window.get()); 4304 delegate->set_window(window.get());
4307 4305
4308 // Start a scroll gesture. 4306 // Start a scroll gesture.
4309 ui::TouchEvent press1( 4307 ui::TouchEvent press1(
4310 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId1, tes.Now()); 4308 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId1, tes.Now());
4311 DispatchEventUsingWindowDispatcher(&press1); 4309 DispatchEventUsingWindowDispatcher(&press1);
4312 delegate->ReceivedAck(); 4310 delegate->ReceivedAck();
4313 4311
4314 ui::TouchEvent move1( 4312 ui::TouchEvent move1(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4362 4360
4363 // The synchronous ack is stuck behind the pending touch move. 4361 // The synchronous ack is stuck behind the pending touch move.
4364 EXPECT_0_EVENTS(delegate->events()); 4362 EXPECT_0_EVENTS(delegate->events());
4365 4363
4366 delegate->ReceivedAck(); 4364 delegate->ReceivedAck();
4367 EXPECT_2_EVENTS(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE, 4365 EXPECT_2_EVENTS(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE,
4368 ui::ET_GESTURE_SCROLL_UPDATE); 4366 ui::ET_GESTURE_SCROLL_UPDATE);
4369 } 4367 }
4370 4368
4371 TEST_F(GestureRecognizerTest, GestureEventTwoWindowsActive) { 4369 TEST_F(GestureRecognizerTest, GestureEventTwoWindowsActive) {
4372 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 4370 std::unique_ptr<QueueTouchEventDelegate> queued_delegate(
4373 new QueueTouchEventDelegate(host()->dispatcher())); 4371 new QueueTouchEventDelegate(host()->dispatcher()));
4374 TimedEvents tes; 4372 TimedEvents tes;
4375 const int kWindowWidth = 123; 4373 const int kWindowWidth = 123;
4376 const int kWindowHeight = 45; 4374 const int kWindowHeight = 45;
4377 const int kTouchId1 = 6; 4375 const int kTouchId1 = 6;
4378 const int kTouchId2 = 4; 4376 const int kTouchId2 = 4;
4379 gfx::Rect bounds(150, 200, kWindowWidth, kWindowHeight); 4377 gfx::Rect bounds(150, 200, kWindowWidth, kWindowHeight);
4380 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4378 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4381 queued_delegate.get(), -1234, bounds, root_window())); 4379 queued_delegate.get(), -1234, bounds, root_window()));
4382 queued_delegate->set_window(window.get()); 4380 queued_delegate->set_window(window.get());
4383 4381
4384 // Touch down on the window. This should not generate any gesture event. 4382 // Touch down on the window. This should not generate any gesture event.
4385 queued_delegate->Reset(); 4383 queued_delegate->Reset();
4386 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(151, 201), kTouchId1, 4384 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(151, 201), kTouchId1,
4387 tes.Now()); 4385 tes.Now());
4388 DispatchEventUsingWindowDispatcher(&press); 4386 DispatchEventUsingWindowDispatcher(&press);
4389 EXPECT_FALSE(queued_delegate->tap()); 4387 EXPECT_FALSE(queued_delegate->tap());
4390 EXPECT_FALSE(queued_delegate->tap_down()); 4388 EXPECT_FALSE(queued_delegate->tap_down());
4391 EXPECT_FALSE(queued_delegate->tap_cancel()); 4389 EXPECT_FALSE(queued_delegate->tap_cancel());
4392 EXPECT_FALSE(queued_delegate->begin()); 4390 EXPECT_FALSE(queued_delegate->begin());
4393 EXPECT_FALSE(queued_delegate->scroll_begin()); 4391 EXPECT_FALSE(queued_delegate->scroll_begin());
4394 EXPECT_FALSE(queued_delegate->scroll_update()); 4392 EXPECT_FALSE(queued_delegate->scroll_update());
4395 EXPECT_FALSE(queued_delegate->scroll_end()); 4393 EXPECT_FALSE(queued_delegate->scroll_end());
4396 4394
4397 // Touch down on the second window. This should not generate any 4395 // Touch down on the second window. This should not generate any
4398 // gesture event. 4396 // gesture event.
4399 scoped_ptr<QueueTouchEventDelegate> queued_delegate2( 4397 std::unique_ptr<QueueTouchEventDelegate> queued_delegate2(
4400 new QueueTouchEventDelegate(host()->dispatcher())); 4398 new QueueTouchEventDelegate(host()->dispatcher()));
4401 gfx::Rect bounds2(0, 0, kWindowWidth, kWindowHeight); 4399 gfx::Rect bounds2(0, 0, kWindowWidth, kWindowHeight);
4402 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( 4400 std::unique_ptr<aura::Window> window2(CreateTestWindowWithDelegate(
4403 queued_delegate2.get(), -2345, bounds2, root_window())); 4401 queued_delegate2.get(), -2345, bounds2, root_window()));
4404 queued_delegate2->set_window(window2.get()); 4402 queued_delegate2->set_window(window2.get());
4405 4403
4406 queued_delegate2->Reset(); 4404 queued_delegate2->Reset();
4407 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(1, 1), kTouchId2, 4405 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(1, 1), kTouchId2,
4408 tes.Now()); 4406 tes.Now());
4409 DispatchEventUsingWindowDispatcher(&press2); 4407 DispatchEventUsingWindowDispatcher(&press2);
4410 EXPECT_FALSE(queued_delegate2->tap()); 4408 EXPECT_FALSE(queued_delegate2->tap());
4411 EXPECT_FALSE(queued_delegate2->tap_down()); 4409 EXPECT_FALSE(queued_delegate2->tap_down());
4412 EXPECT_FALSE(queued_delegate2->tap_cancel()); 4410 EXPECT_FALSE(queued_delegate2->tap_cancel());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4444 EXPECT_FALSE(queued_delegate2->long_press()); 4442 EXPECT_FALSE(queued_delegate2->long_press());
4445 4443
4446 queued_delegate->Reset(); 4444 queued_delegate->Reset();
4447 queued_delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS); 4445 queued_delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS);
4448 EXPECT_TRUE(queued_delegate->show_press()); 4446 EXPECT_TRUE(queued_delegate->show_press());
4449 EXPECT_FALSE(queued_delegate->tap_down()); 4447 EXPECT_FALSE(queued_delegate->tap_down());
4450 } 4448 }
4451 4449
4452 } // namespace test 4450 } // namespace test
4453 } // namespace aura 4451 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/env.cc ('k') | ui/aura/input_state_lookup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698