| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 12 #include "ui/aura/test/aura_test_base.h" | 12 #include "ui/aura/test/aura_test_base.h" |
| 13 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
| 14 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
| 17 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 18 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
| 19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 20 #include "ui/events/event_switches.h" | 20 #include "ui/events/event_switches.h" |
| 21 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 22 #include "ui/events/gestures/gesture_configuration.h" | 22 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 23 #include "ui/events/gestures/gesture_recognizer_impl.h" | 23 #include "ui/events/gestures/gesture_recognizer_impl.h" |
| 24 #include "ui/events/gestures/gesture_types.h" | 24 #include "ui/events/gestures/gesture_types.h" |
| 25 #include "ui/events/test/event_generator.h" | 25 #include "ui/events/test/event_generator.h" |
| 26 #include "ui/events/test/events_test_utils.h" | 26 #include "ui/events/test/events_test_utils.h" |
| 27 #include "ui/gfx/point.h" | 27 #include "ui/gfx/point.h" |
| 28 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
| 29 | 29 |
| 30 #include <queue> | 30 #include <queue> |
| 31 | 31 |
| 32 namespace aura { | 32 namespace aura { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 gesture_end_location_ = gesture->location(); | 221 gesture_end_location_ = gesture->location(); |
| 222 break; | 222 break; |
| 223 case ui::ET_GESTURE_SCROLL_BEGIN: | 223 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 224 scroll_begin_ = true; | 224 scroll_begin_ = true; |
| 225 scroll_begin_position_ = gesture->location(); | 225 scroll_begin_position_ = gesture->location(); |
| 226 scroll_x_hint_ = gesture->details().scroll_x_hint(); | 226 scroll_x_hint_ = gesture->details().scroll_x_hint(); |
| 227 scroll_y_hint_ = gesture->details().scroll_y_hint(); | 227 scroll_y_hint_ = gesture->details().scroll_y_hint(); |
| 228 break; | 228 break; |
| 229 case ui::ET_GESTURE_SCROLL_UPDATE: | 229 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 230 scroll_update_ = true; | 230 scroll_update_ = true; |
| 231 // base::debug::StackTrace().Print(); |
| 232 |
| 231 scroll_x_ += gesture->details().scroll_x(); | 233 scroll_x_ += gesture->details().scroll_x(); |
| 232 scroll_y_ += gesture->details().scroll_y(); | 234 scroll_y_ += gesture->details().scroll_y(); |
| 233 break; | 235 break; |
| 234 case ui::ET_GESTURE_SCROLL_END: | 236 case ui::ET_GESTURE_SCROLL_END: |
| 235 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); | 237 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); |
| 236 scroll_end_ = true; | 238 scroll_end_ = true; |
| 237 break; | 239 break; |
| 238 case ui::ET_GESTURE_PINCH_BEGIN: | 240 case ui::ET_GESTURE_PINCH_BEGIN: |
| 239 pinch_begin_ = true; | 241 pinch_begin_ = true; |
| 240 break; | 242 break; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 630 |
| 629 } // namespace | 631 } // namespace |
| 630 | 632 |
| 631 class GestureRecognizerTest : public AuraTestBase, | 633 class GestureRecognizerTest : public AuraTestBase, |
| 632 public ::testing::WithParamInterface<bool> { | 634 public ::testing::WithParamInterface<bool> { |
| 633 public: | 635 public: |
| 634 GestureRecognizerTest() {} | 636 GestureRecognizerTest() {} |
| 635 | 637 |
| 636 virtual void SetUp() OVERRIDE { | 638 virtual void SetUp() OVERRIDE { |
| 637 AuraTestBase::SetUp(); | 639 AuraTestBase::SetUp(); |
| 638 ui::GestureConfiguration::set_show_press_delay_in_ms(2); | 640 ui::GestureConfiguration::GetInstance()->set_show_press_delay_in_ms(2); |
| 639 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003); | 641 ui::GestureConfiguration::GetInstance()->set_long_press_timeout_in_ms(3); |
| 640 } | 642 } |
| 641 | 643 |
| 642 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); | 644 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); |
| 643 }; | 645 }; |
| 644 | 646 |
| 645 // Check that appropriate touch events generate tap gesture events. | 647 // Check that appropriate touch events generate tap gesture events. |
| 646 TEST_F(GestureRecognizerTest, GestureEventTap) { | 648 TEST_F(GestureRecognizerTest, GestureEventTap) { |
| 647 scoped_ptr<GestureEventConsumeDelegate> delegate( | 649 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 648 new GestureEventConsumeDelegate()); | 650 new GestureEventConsumeDelegate()); |
| 649 TimedEvents tes; | 651 TimedEvents tes; |
| 650 const int kWindowWidth = 123; | 652 const int kWindowWidth = 123; |
| 651 const int kWindowHeight = 45; | 653 const int kWindowHeight = 45; |
| 652 const int kTouchId = 2; | 654 const int kTouchId = 2; |
| 653 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 655 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 654 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 656 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 655 delegate.get(), -1234, bounds, root_window())); | 657 delegate.get(), -1234, bounds, root_window())); |
| 656 | 658 |
| 657 delegate->Reset(); | 659 delegate->Reset(); |
| 660 |
| 658 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 661 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
| 659 kTouchId, tes.Now()); | 662 kTouchId, tes.Now()); |
| 660 DispatchEventUsingWindowDispatcher(&press); | 663 DispatchEventUsingWindowDispatcher(&press); |
| 661 EXPECT_FALSE(delegate->tap()); | 664 EXPECT_FALSE(delegate->tap()); |
| 662 EXPECT_FALSE(delegate->show_press()); | 665 EXPECT_FALSE(delegate->show_press()); |
| 663 EXPECT_TRUE(delegate->tap_down()); | 666 EXPECT_TRUE(delegate->tap_down()); |
| 664 EXPECT_FALSE(delegate->tap_cancel()); | 667 EXPECT_FALSE(delegate->tap_cancel()); |
| 665 EXPECT_TRUE(delegate->begin()); | 668 EXPECT_TRUE(delegate->begin()); |
| 666 EXPECT_FALSE(delegate->scroll_begin()); | 669 EXPECT_FALSE(delegate->scroll_begin()); |
| 667 EXPECT_FALSE(delegate->scroll_update()); | 670 EXPECT_FALSE(delegate->scroll_update()); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 EXPECT_EQ(401, actual_point.x()); | 934 EXPECT_EQ(401, actual_point.x()); |
| 932 EXPECT_EQ(149, actual_point.y()); | 935 EXPECT_EQ(149, actual_point.y()); |
| 933 } | 936 } |
| 934 } | 937 } |
| 935 | 938 |
| 936 // Check that appropriate touch events generate scroll gesture events. | 939 // Check that appropriate touch events generate scroll gesture events. |
| 937 TEST_F(GestureRecognizerTest, GestureEventScroll) { | 940 TEST_F(GestureRecognizerTest, GestureEventScroll) { |
| 938 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of | 941 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of |
| 939 // that distance to be consumed by the slop, so we set the slop radius to | 942 // that distance to be consumed by the slop, so we set the slop radius to |
| 940 // sqrt(5 * 5 + 5 * 5). | 943 // sqrt(5 * 5 + 5 * 5). |
| 941 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | 944 ui::GestureConfiguration::GetInstance() |
| 942 sqrt(static_cast<double>(5 * 5 + 5 * 5))); | 945 ->set_max_touch_move_in_pixels_for_click( |
| 946 sqrt(static_cast<double>(5 * 5 + 5 * 5))); |
| 943 scoped_ptr<GestureEventConsumeDelegate> delegate( | 947 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 944 new GestureEventConsumeDelegate()); | 948 new GestureEventConsumeDelegate()); |
| 945 TimedEvents tes; | 949 TimedEvents tes; |
| 946 const int kWindowWidth = 123; | 950 const int kWindowWidth = 123; |
| 947 const int kWindowHeight = 45; | 951 const int kWindowHeight = 45; |
| 948 const int kTouchId = 5; | 952 const int kTouchId = 5; |
| 949 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 953 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 950 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 954 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 951 delegate.get(), -1234, bounds, root_window())); | 955 delegate.get(), -1234, bounds, root_window())); |
| 952 | 956 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 ui::ET_SCROLL_FLING_START, | 1006 ui::ET_SCROLL_FLING_START, |
| 1003 ui::ET_GESTURE_END); | 1007 ui::ET_GESTURE_END); |
| 1004 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 1008 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
| 1005 } | 1009 } |
| 1006 | 1010 |
| 1007 // Check that predicted scroll update positions are correct. | 1011 // Check that predicted scroll update positions are correct. |
| 1008 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { | 1012 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { |
| 1009 // We'll start by moving the touch point by (5, 5). We want all of that | 1013 // We'll start by moving the touch point by (5, 5). We want all of that |
| 1010 // distance to be consumed by the slop, so we set the slop radius to | 1014 // distance to be consumed by the slop, so we set the slop radius to |
| 1011 // sqrt(5 * 5 + 5 * 5). | 1015 // sqrt(5 * 5 + 5 * 5). |
| 1012 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | 1016 ui::GestureConfiguration::GetInstance() |
| 1013 sqrt(static_cast<double>(5 * 5 + 5 * 5))); | 1017 ->set_max_touch_move_in_pixels_for_click( |
| 1018 sqrt(static_cast<double>(5 * 5 + 5 * 5))); |
| 1014 | 1019 |
| 1015 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1020 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1016 new GestureEventConsumeDelegate()); | 1021 new GestureEventConsumeDelegate()); |
| 1017 TimedEvents tes; | 1022 TimedEvents tes; |
| 1018 const int kWindowWidth = 123; | 1023 const int kWindowWidth = 123; |
| 1019 const int kWindowHeight = 45; | 1024 const int kWindowHeight = 45; |
| 1020 const int kTouchId = 5; | 1025 const int kTouchId = 5; |
| 1021 gfx::Rect bounds(95, 195, kWindowWidth, kWindowHeight); | 1026 gfx::Rect bounds(95, 195, kWindowWidth, kWindowHeight); |
| 1022 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1027 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1023 delegate.get(), -1234, bounds, root_window())); | 1028 delegate.get(), -1234, bounds, root_window())); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1079 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
| 1075 kTouchId, | 1080 kTouchId, |
| 1076 tes.LeapForward(50)); | 1081 tes.LeapForward(50)); |
| 1077 DispatchEventUsingWindowDispatcher(&release); | 1082 DispatchEventUsingWindowDispatcher(&release); |
| 1078 } | 1083 } |
| 1079 | 1084 |
| 1080 // Check that the bounding box during a scroll event is correct. | 1085 // Check that the bounding box during a scroll event is correct. |
| 1081 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { | 1086 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { |
| 1082 TimedEvents tes; | 1087 TimedEvents tes; |
| 1083 for (int radius = 1; radius <= 10; ++radius) { | 1088 for (int radius = 1; radius <= 10; ++radius) { |
| 1084 ui::GestureConfiguration::set_default_radius(radius); | 1089 ui::GestureConfiguration::GetInstance()->set_default_radius(radius); |
| 1085 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1090 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1086 new GestureEventConsumeDelegate()); | 1091 new GestureEventConsumeDelegate()); |
| 1087 const int kWindowWidth = 123; | 1092 const int kWindowWidth = 123; |
| 1088 const int kWindowHeight = 45; | 1093 const int kWindowHeight = 45; |
| 1089 const int kTouchId = 5; | 1094 const int kTouchId = 5; |
| 1090 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1095 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 1091 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1096 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1092 delegate.get(), -1234, bounds, root_window())); | 1097 delegate.get(), -1234, bounds, root_window())); |
| 1093 | 1098 |
| 1094 const int kPositionX = 101; | 1099 const int kPositionX = 101; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1123 kPositionY + kScrollAmount), | 1128 kPositionY + kScrollAmount), |
| 1124 kTouchId, press.time_stamp() + | 1129 kTouchId, press.time_stamp() + |
| 1125 base::TimeDelta::FromMilliseconds(50)); | 1130 base::TimeDelta::FromMilliseconds(50)); |
| 1126 DispatchEventUsingWindowDispatcher(&release); | 1131 DispatchEventUsingWindowDispatcher(&release); |
| 1127 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, | 1132 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, |
| 1128 kPositionY + kScrollAmount - radius, | 1133 kPositionY + kScrollAmount - radius, |
| 1129 radius * 2, | 1134 radius * 2, |
| 1130 radius * 2).ToString(), | 1135 radius * 2).ToString(), |
| 1131 delegate->bounding_box().ToString()); | 1136 delegate->bounding_box().ToString()); |
| 1132 } | 1137 } |
| 1133 ui::GestureConfiguration::set_default_radius(0); | 1138 ui::GestureConfiguration::GetInstance()->set_default_radius(0); |
| 1134 } | 1139 } |
| 1135 | 1140 |
| 1136 // Check Scroll End Events report correct velocities | 1141 // Check Scroll End Events report correct velocities |
| 1137 // if the user was on a horizontal rail | 1142 // if the user was on a horizontal rail |
| 1138 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { | 1143 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { |
| 1139 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1144 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1140 new GestureEventConsumeDelegate()); | 1145 new GestureEventConsumeDelegate()); |
| 1141 TimedEvents tes; | 1146 TimedEvents tes; |
| 1142 const int kTouchId = 7; | 1147 const int kTouchId = 7; |
| 1143 gfx::Rect bounds(0, 0, 1000, 1000); | 1148 gfx::Rect bounds(0, 0, 1000, 1000); |
| 1144 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1149 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1145 delegate.get(), -1234, bounds, root_window())); | 1150 delegate.get(), -1234, bounds, root_window())); |
| 1146 | 1151 |
| 1147 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 1152 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
| 1148 kTouchId, tes.Now()); | 1153 kTouchId, tes.Now()); |
| 1149 DispatchEventUsingWindowDispatcher(&press); | 1154 DispatchEventUsingWindowDispatcher(&press); |
| 1150 | 1155 |
| 1151 // Get rid of touch slop. | 1156 // Get rid of touch slop. |
| 1152 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0), | 1157 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0), |
| 1153 kTouchId, tes.Now()); | 1158 kTouchId, tes.Now()); |
| 1154 DispatchEventUsingWindowDispatcher(&move); | 1159 DispatchEventUsingWindowDispatcher(&move); |
| 1155 delegate->Reset(); | 1160 delegate->Reset(); |
| 1156 | 1161 |
| 1157 | 1162 |
| 1158 // Move the touch-point horizontally enough that it is considered a | 1163 // Move the touch-point horizontally enough that it is considered a |
| 1159 // horizontal scroll. | 1164 // horizontal scroll. |
| 1160 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); | 1165 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); |
| 1166 |
| 1161 EXPECT_FLOAT_EQ(0, delegate->scroll_y()); | 1167 EXPECT_FLOAT_EQ(0, delegate->scroll_y()); |
| 1162 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); | 1168 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); |
| 1163 | 1169 |
| 1164 // Get a high x velocity, while still staying on the rail | 1170 // Get a high x velocity, while still staying on the rail |
| 1165 const int kScrollAmount = 8; | 1171 const int kScrollAmount = 8; |
| 1166 tes.SendScrollEvents(event_processor(), | 1172 tes.SendScrollEvents(event_processor(), |
| 1167 1, | 1173 1, |
| 1168 1, | 1174 1, |
| 1169 100, | 1175 100, |
| 1170 10, | 1176 10, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 | 1238 |
| 1233 EXPECT_TRUE(delegate->fling()); | 1239 EXPECT_TRUE(delegate->fling()); |
| 1234 EXPECT_FALSE(delegate->scroll_end()); | 1240 EXPECT_FALSE(delegate->scroll_end()); |
| 1235 EXPECT_EQ(0, delegate->velocity_x()); | 1241 EXPECT_EQ(0, delegate->velocity_x()); |
| 1236 EXPECT_GT(delegate->velocity_y(), 0); | 1242 EXPECT_GT(delegate->velocity_y(), 0); |
| 1237 } | 1243 } |
| 1238 | 1244 |
| 1239 // Check Scroll End Events report non-zero velocities if the user is not on a | 1245 // Check Scroll End Events report non-zero velocities if the user is not on a |
| 1240 // rail | 1246 // rail |
| 1241 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { | 1247 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { |
| 1242 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0); | 1248 ui::GestureConfiguration::GetInstance() |
| 1249 ->set_max_touch_move_in_pixels_for_click(0); |
| 1243 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1250 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1244 new GestureEventConsumeDelegate()); | 1251 new GestureEventConsumeDelegate()); |
| 1245 TimedEvents tes; | 1252 TimedEvents tes; |
| 1246 const int kTouchId = 7; | 1253 const int kTouchId = 7; |
| 1247 gfx::Rect bounds(0, 0, 1000, 1000); | 1254 gfx::Rect bounds(0, 0, 1000, 1000); |
| 1248 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1255 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1249 delegate.get(), -1234, bounds, root_window())); | 1256 delegate.get(), -1234, bounds, root_window())); |
| 1250 | 1257 |
| 1251 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 1258 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
| 1252 kTouchId, tes.Now()); | 1259 kTouchId, tes.Now()); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 delegate->Reset(); | 1366 delegate->Reset(); |
| 1360 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1367 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
| 1361 kTouchId, tes.LeapForward(10)); | 1368 kTouchId, tes.LeapForward(10)); |
| 1362 DispatchEventUsingWindowDispatcher(&release1); | 1369 DispatchEventUsingWindowDispatcher(&release1); |
| 1363 EXPECT_FALSE(delegate->long_press()); | 1370 EXPECT_FALSE(delegate->long_press()); |
| 1364 EXPECT_FALSE(delegate->tap_cancel()); | 1371 EXPECT_FALSE(delegate->tap_cancel()); |
| 1365 } | 1372 } |
| 1366 | 1373 |
| 1367 // Check that appropriate touch events generate long tap events | 1374 // Check that appropriate touch events generate long tap events |
| 1368 TEST_F(GestureRecognizerTest, GestureEventLongTap) { | 1375 TEST_F(GestureRecognizerTest, GestureEventLongTap) { |
| 1369 ui::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click( | 1376 ui::GestureConfiguration::GetInstance() |
| 1370 0.0025); | 1377 ->set_max_touch_down_duration_in_seconds_for_click(0.0025); |
| 1371 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1378 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1372 new GestureEventConsumeDelegate()); | 1379 new GestureEventConsumeDelegate()); |
| 1373 const int kWindowWidth = 123; | 1380 const int kWindowWidth = 123; |
| 1374 const int kWindowHeight = 45; | 1381 const int kWindowHeight = 45; |
| 1375 const int kTouchId = 2; | 1382 const int kTouchId = 2; |
| 1376 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1383 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 1377 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1384 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1378 delegate.get(), -1234, bounds, root_window())); | 1385 delegate.get(), -1234, bounds, root_window())); |
| 1379 | 1386 |
| 1380 delegate->Reset(); | 1387 delegate->Reset(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 // The rail should be broken | 1573 // The rail should be broken |
| 1567 EXPECT_TRUE(delegate->scroll_update()); | 1574 EXPECT_TRUE(delegate->scroll_update()); |
| 1568 EXPECT_EQ(5, delegate->scroll_x()); | 1575 EXPECT_EQ(5, delegate->scroll_x()); |
| 1569 EXPECT_EQ(5, delegate->scroll_y()); | 1576 EXPECT_EQ(5, delegate->scroll_y()); |
| 1570 } | 1577 } |
| 1571 | 1578 |
| 1572 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { | 1579 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { |
| 1573 // We'll start by moving the touch point by (5, 5). We want all of that | 1580 // We'll start by moving the touch point by (5, 5). We want all of that |
| 1574 // distance to be consumed by the slop, so we set the slop radius to | 1581 // distance to be consumed by the slop, so we set the slop radius to |
| 1575 // sqrt(5 * 5 + 5 * 5). | 1582 // sqrt(5 * 5 + 5 * 5). |
| 1576 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | 1583 ui::GestureConfiguration::GetInstance() |
| 1577 sqrt(static_cast<double>(5 * 5 + 5 * 5))); | 1584 ->set_max_touch_move_in_pixels_for_click( |
| 1585 sqrt(static_cast<double>(5 * 5 + 5 * 5))); |
| 1578 | 1586 |
| 1579 // First, tap. Then, do a scroll using the same touch-id. | 1587 // First, tap. Then, do a scroll using the same touch-id. |
| 1580 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1588 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1581 new GestureEventConsumeDelegate()); | 1589 new GestureEventConsumeDelegate()); |
| 1582 TimedEvents tes; | 1590 TimedEvents tes; |
| 1583 const int kWindowWidth = 123; | 1591 const int kWindowWidth = 123; |
| 1584 const int kWindowHeight = 45; | 1592 const int kWindowHeight = 45; |
| 1585 const int kTouchId = 3; | 1593 const int kTouchId = 3; |
| 1586 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1594 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 1587 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1595 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 EXPECT_FALSE(queued_delegate->begin()); | 1832 EXPECT_FALSE(queued_delegate->begin()); |
| 1825 EXPECT_FALSE(queued_delegate->end()); | 1833 EXPECT_FALSE(queued_delegate->end()); |
| 1826 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1834 EXPECT_FALSE(queued_delegate->scroll_begin()); |
| 1827 EXPECT_FALSE(queued_delegate->scroll_update()); | 1835 EXPECT_FALSE(queued_delegate->scroll_update()); |
| 1828 EXPECT_FALSE(queued_delegate->scroll_end()); | 1836 EXPECT_FALSE(queued_delegate->scroll_end()); |
| 1829 | 1837 |
| 1830 // Move the second touch-point enough so that it is considered a pinch. This | 1838 // Move the second touch-point enough so that it is considered a pinch. This |
| 1831 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. | 1839 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. |
| 1832 queued_delegate->Reset(); | 1840 queued_delegate->Reset(); |
| 1833 delegate->Reset(); | 1841 delegate->Reset(); |
| 1834 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); | 1842 int x_move = ui::GestureConfiguration::GetInstance() |
| 1843 ->max_touch_move_in_pixels_for_click(); |
| 1835 ui::TouchEvent move( | 1844 ui::TouchEvent move( |
| 1836 ui::ET_TOUCH_MOVED, gfx::Point(203 + x_move, 303), kTouchId2, tes.Now()); | 1845 ui::ET_TOUCH_MOVED, gfx::Point(203 + x_move, 303), kTouchId2, tes.Now()); |
| 1837 DispatchEventUsingWindowDispatcher(&move); | 1846 DispatchEventUsingWindowDispatcher(&move); |
| 1838 EXPECT_FALSE(delegate->tap()); | 1847 EXPECT_FALSE(delegate->tap()); |
| 1839 EXPECT_FALSE(delegate->tap_down()); | 1848 EXPECT_FALSE(delegate->tap_down()); |
| 1840 EXPECT_FALSE(delegate->tap_cancel()); | 1849 EXPECT_FALSE(delegate->tap_cancel()); |
| 1841 EXPECT_FALSE(delegate->begin()); | 1850 EXPECT_FALSE(delegate->begin()); |
| 1842 EXPECT_FALSE(delegate->scroll_begin()); | 1851 EXPECT_FALSE(delegate->scroll_begin()); |
| 1843 EXPECT_FALSE(delegate->scroll_update()); | 1852 EXPECT_FALSE(delegate->scroll_update()); |
| 1844 EXPECT_FALSE(delegate->scroll_end()); | 1853 EXPECT_FALSE(delegate->scroll_end()); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2125 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl(); | 2134 ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl(); |
| 2126 TimedEvents tes; | 2135 TimedEvents tes; |
| 2127 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); | 2136 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); |
| 2128 | 2137 |
| 2129 ui::GestureConsumer* target; | 2138 ui::GestureConsumer* target; |
| 2130 const int kNumWindows = 4; | 2139 const int kNumWindows = 4; |
| 2131 | 2140 |
| 2132 scoped_ptr<GestureEventConsumeDelegate*[]> delegates( | 2141 scoped_ptr<GestureEventConsumeDelegate*[]> delegates( |
| 2133 new GestureEventConsumeDelegate*[kNumWindows]); | 2142 new GestureEventConsumeDelegate*[kNumWindows]); |
| 2134 | 2143 |
| 2135 ui::GestureConfiguration:: | 2144 ui::GestureConfiguration::GetInstance() |
| 2136 set_max_separation_for_gesture_touches_in_pixels(499); | 2145 ->set_max_separation_for_gesture_touches_in_pixels(499); |
| 2137 | 2146 |
| 2138 scoped_ptr<gfx::Rect[]> window_bounds(new gfx::Rect[kNumWindows]); | 2147 scoped_ptr<gfx::Rect[]> window_bounds(new gfx::Rect[kNumWindows]); |
| 2139 window_bounds[0] = gfx::Rect(0, 0, 1, 1); | 2148 window_bounds[0] = gfx::Rect(0, 0, 1, 1); |
| 2140 window_bounds[1] = gfx::Rect(500, 0, 1, 1); | 2149 window_bounds[1] = gfx::Rect(500, 0, 1, 1); |
| 2141 window_bounds[2] = gfx::Rect(0, 500, 1, 1); | 2150 window_bounds[2] = gfx::Rect(0, 500, 1, 1); |
| 2142 window_bounds[3] = gfx::Rect(500, 500, 1, 1); | 2151 window_bounds[3] = gfx::Rect(500, 500, 1, 1); |
| 2143 | 2152 |
| 2144 scoped_ptr<aura::Window*[]> windows(new aura::Window*[kNumWindows]); | 2153 scoped_ptr<aura::Window*[]> windows(new aura::Window*[kNumWindows]); |
| 2145 | 2154 |
| 2146 // Instantiate windows with |window_bounds| and touch each window at | 2155 // Instantiate windows with |window_bounds| and touch each window at |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3453 EXPECT_FALSE(delegate->tap_cancel()); | 3462 EXPECT_FALSE(delegate->tap_cancel()); |
| 3454 EXPECT_FALSE(delegate->scroll_update()); | 3463 EXPECT_FALSE(delegate->scroll_update()); |
| 3455 EXPECT_FALSE(delegate->pinch_update()); | 3464 EXPECT_FALSE(delegate->pinch_update()); |
| 3456 | 3465 |
| 3457 delegate->Reset(); | 3466 delegate->Reset(); |
| 3458 } | 3467 } |
| 3459 | 3468 |
| 3460 // Checks that slow scrolls deliver the correct deltas. | 3469 // Checks that slow scrolls deliver the correct deltas. |
| 3461 // In particular, fix for http;//crbug.com/150573. | 3470 // In particular, fix for http;//crbug.com/150573. |
| 3462 TEST_F(GestureRecognizerTest, NoDriftInScroll) { | 3471 TEST_F(GestureRecognizerTest, NoDriftInScroll) { |
| 3463 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); | 3472 ui::GestureConfiguration::GetInstance() |
| 3473 ->set_max_touch_move_in_pixels_for_click(3); |
| 3464 scoped_ptr<GestureEventConsumeDelegate> delegate( | 3474 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 3465 new GestureEventConsumeDelegate()); | 3475 new GestureEventConsumeDelegate()); |
| 3466 const int kWindowWidth = 234; | 3476 const int kWindowWidth = 234; |
| 3467 const int kWindowHeight = 345; | 3477 const int kWindowHeight = 345; |
| 3468 const int kTouchId = 5; | 3478 const int kTouchId = 5; |
| 3469 TimedEvents tes; | 3479 TimedEvents tes; |
| 3470 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 3480 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 3471 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 3481 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 3472 delegate.get(), -1234, bounds, root_window())); | 3482 delegate.get(), -1234, bounds, root_window())); |
| 3473 | 3483 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3804 DispatchEventUsingWindowDispatcher(&move); | 3814 DispatchEventUsingWindowDispatcher(&move); |
| 3805 delegate->ReceivedAckPreventDefaulted(); | 3815 delegate->ReceivedAckPreventDefaulted(); |
| 3806 | 3816 |
| 3807 // Wait until the timer runs out | 3817 // Wait until the timer runs out |
| 3808 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); | 3818 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); |
| 3809 EXPECT_TRUE(delegate->long_press()); | 3819 EXPECT_TRUE(delegate->long_press()); |
| 3810 } | 3820 } |
| 3811 | 3821 |
| 3812 // Tests that the deltas are correct when leaving the slop region very slowly. | 3822 // Tests that the deltas are correct when leaving the slop region very slowly. |
| 3813 TEST_F(GestureRecognizerTest, TestExceedingSlopSlowly) { | 3823 TEST_F(GestureRecognizerTest, TestExceedingSlopSlowly) { |
| 3814 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); | 3824 ui::GestureConfiguration::GetInstance() |
| 3825 ->set_max_touch_move_in_pixels_for_click(3); |
| 3815 scoped_ptr<GestureEventConsumeDelegate> delegate( | 3826 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 3816 new GestureEventConsumeDelegate()); | 3827 new GestureEventConsumeDelegate()); |
| 3817 const int kWindowWidth = 234; | 3828 const int kWindowWidth = 234; |
| 3818 const int kWindowHeight = 345; | 3829 const int kWindowHeight = 345; |
| 3819 const int kTouchId = 5; | 3830 const int kTouchId = 5; |
| 3820 TimedEvents tes; | 3831 TimedEvents tes; |
| 3821 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); | 3832 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); |
| 3822 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 3833 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 3823 delegate.get(), -1234, bounds, root_window())); | 3834 delegate.get(), -1234, bounds, root_window())); |
| 3824 | 3835 |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4303 ui::TouchEvent move3( | 4314 ui::TouchEvent move3( |
| 4304 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); | 4315 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); |
| 4305 DispatchEventUsingWindowDispatcher(&move3); | 4316 DispatchEventUsingWindowDispatcher(&move3); |
| 4306 | 4317 |
| 4307 delegate->ReceivedAck(); | 4318 delegate->ReceivedAck(); |
| 4308 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); | 4319 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); |
| 4309 } | 4320 } |
| 4310 | 4321 |
| 4311 } // namespace test | 4322 } // namespace test |
| 4312 } // namespace aura | 4323 } // namespace aura |
| OLD | NEW |