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" |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 } // namespace | 629 } // namespace |
630 | 630 |
631 class GestureRecognizerTest : public AuraTestBase, | 631 class GestureRecognizerTest : public AuraTestBase, |
632 public ::testing::WithParamInterface<bool> { | 632 public ::testing::WithParamInterface<bool> { |
633 public: | 633 public: |
634 GestureRecognizerTest() {} | 634 GestureRecognizerTest() {} |
635 | 635 |
636 virtual void SetUp() OVERRIDE { | 636 virtual void SetUp() OVERRIDE { |
637 AuraTestBase::SetUp(); | 637 AuraTestBase::SetUp(); |
638 ui::GestureConfiguration::set_show_press_delay_in_ms(2); | 638 ui::GestureConfiguration::set_show_press_delay_in_ms(2); |
639 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003); | 639 ui::GestureConfiguration::set_long_press_time_in_ms(3); |
640 } | 640 } |
641 | 641 |
642 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); | 642 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); |
643 }; | 643 }; |
644 | 644 |
645 // Check that appropriate touch events generate tap gesture events. | 645 // Check that appropriate touch events generate tap gesture events. |
646 TEST_F(GestureRecognizerTest, GestureEventTap) { | 646 TEST_F(GestureRecognizerTest, GestureEventTap) { |
647 scoped_ptr<GestureEventConsumeDelegate> delegate( | 647 scoped_ptr<GestureEventConsumeDelegate> delegate( |
648 new GestureEventConsumeDelegate()); | 648 new GestureEventConsumeDelegate()); |
649 TimedEvents tes; | 649 TimedEvents tes; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 EXPECT_EQ(149, actual_point.y()); | 932 EXPECT_EQ(149, actual_point.y()); |
933 } | 933 } |
934 } | 934 } |
935 | 935 |
936 // Check that appropriate touch events generate scroll gesture events. | 936 // Check that appropriate touch events generate scroll gesture events. |
937 TEST_F(GestureRecognizerTest, GestureEventScroll) { | 937 TEST_F(GestureRecognizerTest, GestureEventScroll) { |
938 // We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of | 938 // 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 | 939 // that distance to be consumed by the slop, so we set the slop radius to |
940 // sqrt(5 * 5 + 5 * 5). | 940 // sqrt(5 * 5 + 5 * 5). |
941 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | 941 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( |
942 sqrt(static_cast<double>(5 * 5 + 5 * 5))); | 942 sqrt(5.f * 5 + 5 * 5)); |
943 scoped_ptr<GestureEventConsumeDelegate> delegate( | 943 scoped_ptr<GestureEventConsumeDelegate> delegate( |
944 new GestureEventConsumeDelegate()); | 944 new GestureEventConsumeDelegate()); |
945 TimedEvents tes; | 945 TimedEvents tes; |
946 const int kWindowWidth = 123; | 946 const int kWindowWidth = 123; |
947 const int kWindowHeight = 45; | 947 const int kWindowHeight = 45; |
948 const int kTouchId = 5; | 948 const int kTouchId = 5; |
949 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 949 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
950 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 950 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
951 delegate.get(), -1234, bounds, root_window())); | 951 delegate.get(), -1234, bounds, root_window())); |
952 | 952 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 ui::ET_GESTURE_END); | 1003 ui::ET_GESTURE_END); |
1004 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 1004 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
1005 } | 1005 } |
1006 | 1006 |
1007 // Check that predicted scroll update positions are correct. | 1007 // Check that predicted scroll update positions are correct. |
1008 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { | 1008 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { |
1009 // We'll start by moving the touch point by (5, 5). We want all of that | 1009 // 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 | 1010 // distance to be consumed by the slop, so we set the slop radius to |
1011 // sqrt(5 * 5 + 5 * 5). | 1011 // sqrt(5 * 5 + 5 * 5). |
1012 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | 1012 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( |
1013 sqrt(static_cast<double>(5 * 5 + 5 * 5))); | 1013 sqrt(5.f * 5 + 5 * 5)); |
1014 | 1014 |
1015 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1015 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1016 new GestureEventConsumeDelegate()); | 1016 new GestureEventConsumeDelegate()); |
1017 TimedEvents tes; | 1017 TimedEvents tes; |
1018 const int kWindowWidth = 123; | 1018 const int kWindowWidth = 123; |
1019 const int kWindowHeight = 45; | 1019 const int kWindowHeight = 45; |
1020 const int kTouchId = 5; | 1020 const int kTouchId = 5; |
1021 gfx::Rect bounds(95, 195, kWindowWidth, kWindowHeight); | 1021 gfx::Rect bounds(95, 195, kWindowWidth, kWindowHeight); |
1022 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1022 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1023 delegate.get(), -1234, bounds, root_window())); | 1023 delegate.get(), -1234, bounds, root_window())); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 delegate->Reset(); | 1073 delegate->Reset(); |
1074 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1074 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1075 kTouchId, | 1075 kTouchId, |
1076 tes.LeapForward(50)); | 1076 tes.LeapForward(50)); |
1077 DispatchEventUsingWindowDispatcher(&release); | 1077 DispatchEventUsingWindowDispatcher(&release); |
1078 } | 1078 } |
1079 | 1079 |
1080 // Check that the bounding box during a scroll event is correct. | 1080 // Check that the bounding box during a scroll event is correct. |
1081 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { | 1081 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { |
1082 TimedEvents tes; | 1082 TimedEvents tes; |
1083 for (int radius = 1; radius <= 10; ++radius) { | 1083 for (float radius = 1; radius <= 10; ++radius) { |
1084 ui::GestureConfiguration::set_default_radius(radius); | 1084 ui::GestureConfiguration::set_default_radius(radius); |
1085 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1085 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1086 new GestureEventConsumeDelegate()); | 1086 new GestureEventConsumeDelegate()); |
1087 const int kWindowWidth = 123; | 1087 const int kWindowWidth = 123; |
1088 const int kWindowHeight = 45; | 1088 const int kWindowHeight = 45; |
1089 const int kTouchId = 5; | 1089 const int kTouchId = 5; |
1090 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1090 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
1091 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1091 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1092 delegate.get(), -1234, bounds, root_window())); | 1092 delegate.get(), -1234, bounds, root_window())); |
1093 | 1093 |
1094 const int kPositionX = 101; | 1094 const float kPositionX = 101; |
rjkroege
2014/10/08 17:45:22
I vaguely recall that there use to be at least one
Peter Kasting
2014/10/08 18:05:54
You can definitely make compilers complain about s
| |
1095 const int kPositionY = 201; | 1095 const float kPositionY = 201; |
1096 delegate->Reset(); | 1096 delegate->Reset(); |
1097 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 1097 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
1098 gfx::Point(kPositionX, kPositionY), | 1098 gfx::PointF(kPositionX, kPositionY), |
1099 kTouchId, | 1099 kTouchId, |
1100 tes.Now()); | 1100 tes.Now()); |
1101 DispatchEventUsingWindowDispatcher(&press); | 1101 DispatchEventUsingWindowDispatcher(&press); |
1102 EXPECT_EQ(gfx::Rect(kPositionX - radius, | 1102 EXPECT_EQ(gfx::RectF(kPositionX - radius, |
1103 kPositionY - radius, | 1103 kPositionY - radius, |
1104 radius * 2, | 1104 radius * 2, |
1105 radius * 2).ToString(), | 1105 radius * 2), |
1106 delegate->bounding_box().ToString()); | 1106 delegate->bounding_box()); |
1107 | 1107 |
1108 const int kScrollAmount = 50; | 1108 const int kScrollAmount = 50; |
1109 tes.SendScrollEvents(event_processor(), kPositionX, kPositionY, | 1109 tes.SendScrollEvents(event_processor(), kPositionX, kPositionY, |
1110 1, 1, kTouchId, 1, kScrollAmount, delegate.get()); | 1110 1, 1, kTouchId, 1, kScrollAmount, delegate.get()); |
1111 EXPECT_EQ(gfx::Point(1, 1).ToString(), | 1111 EXPECT_EQ(gfx::Point(1, 1).ToString(), |
1112 delegate->scroll_begin_position().ToString()); | 1112 delegate->scroll_begin_position().ToString()); |
1113 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, | 1113 EXPECT_EQ(gfx::RectF(kPositionX + kScrollAmount - radius, |
1114 kPositionY + kScrollAmount - radius, | 1114 kPositionY + kScrollAmount - radius, |
1115 radius * 2, | 1115 radius * 2, |
1116 radius * 2).ToString(), | 1116 radius * 2), |
1117 delegate->bounding_box().ToString()); | 1117 delegate->bounding_box()); |
1118 | 1118 |
1119 // Release the touch. This should end the scroll. | 1119 // Release the touch. This should end the scroll. |
1120 delegate->Reset(); | 1120 delegate->Reset(); |
1121 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, | 1121 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, |
1122 gfx::Point(kPositionX + kScrollAmount, | 1122 gfx::PointF(kPositionX + kScrollAmount, |
1123 kPositionY + kScrollAmount), | 1123 kPositionY + kScrollAmount), |
1124 kTouchId, press.time_stamp() + | 1124 kTouchId, press.time_stamp() + |
1125 base::TimeDelta::FromMilliseconds(50)); | 1125 base::TimeDelta::FromMilliseconds(50)); |
1126 DispatchEventUsingWindowDispatcher(&release); | 1126 DispatchEventUsingWindowDispatcher(&release); |
1127 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, | 1127 EXPECT_EQ(gfx::RectF(kPositionX + kScrollAmount - radius, |
1128 kPositionY + kScrollAmount - radius, | 1128 kPositionY + kScrollAmount - radius, |
1129 radius * 2, | 1129 radius * 2, |
1130 radius * 2).ToString(), | 1130 radius * 2), |
1131 delegate->bounding_box().ToString()); | 1131 delegate->bounding_box()); |
1132 } | 1132 } |
1133 ui::GestureConfiguration::set_default_radius(0); | 1133 ui::GestureConfiguration::set_default_radius(0); |
1134 } | 1134 } |
1135 | 1135 |
1136 // Check Scroll End Events report correct velocities | 1136 // Check Scroll End Events report correct velocities |
1137 // if the user was on a horizontal rail | 1137 // if the user was on a horizontal rail |
1138 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { | 1138 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { |
1139 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1139 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1140 new GestureEventConsumeDelegate()); | 1140 new GestureEventConsumeDelegate()); |
1141 TimedEvents tes; | 1141 TimedEvents tes; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1359 delegate->Reset(); | 1359 delegate->Reset(); |
1360 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1360 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1361 kTouchId, tes.LeapForward(10)); | 1361 kTouchId, tes.LeapForward(10)); |
1362 DispatchEventUsingWindowDispatcher(&release1); | 1362 DispatchEventUsingWindowDispatcher(&release1); |
1363 EXPECT_FALSE(delegate->long_press()); | 1363 EXPECT_FALSE(delegate->long_press()); |
1364 EXPECT_FALSE(delegate->tap_cancel()); | 1364 EXPECT_FALSE(delegate->tap_cancel()); |
1365 } | 1365 } |
1366 | 1366 |
1367 // Check that appropriate touch events generate long tap events | 1367 // Check that appropriate touch events generate long tap events |
1368 TEST_F(GestureRecognizerTest, GestureEventLongTap) { | 1368 TEST_F(GestureRecognizerTest, GestureEventLongTap) { |
1369 ui::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click( | 1369 ui::GestureConfiguration::set_max_touch_down_duration_for_click_in_ms(3); |
1370 0.0025); | |
1371 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1370 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1372 new GestureEventConsumeDelegate()); | 1371 new GestureEventConsumeDelegate()); |
1373 const int kWindowWidth = 123; | 1372 const int kWindowWidth = 123; |
1374 const int kWindowHeight = 45; | 1373 const int kWindowHeight = 45; |
1375 const int kTouchId = 2; | 1374 const int kTouchId = 2; |
1376 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1375 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
1377 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1376 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1378 delegate.get(), -1234, bounds, root_window())); | 1377 delegate.get(), -1234, bounds, root_window())); |
1379 | 1378 |
1380 delegate->Reset(); | 1379 delegate->Reset(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1567 EXPECT_TRUE(delegate->scroll_update()); | 1566 EXPECT_TRUE(delegate->scroll_update()); |
1568 EXPECT_EQ(5, delegate->scroll_x()); | 1567 EXPECT_EQ(5, delegate->scroll_x()); |
1569 EXPECT_EQ(5, delegate->scroll_y()); | 1568 EXPECT_EQ(5, delegate->scroll_y()); |
1570 } | 1569 } |
1571 | 1570 |
1572 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { | 1571 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { |
1573 // We'll start by moving the touch point by (5, 5). We want all of that | 1572 // 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 | 1573 // distance to be consumed by the slop, so we set the slop radius to |
1575 // sqrt(5 * 5 + 5 * 5). | 1574 // sqrt(5 * 5 + 5 * 5). |
1576 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | 1575 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( |
1577 sqrt(static_cast<double>(5 * 5 + 5 * 5))); | 1576 sqrt(5.f * 5 + 5 * 5)); |
1578 | 1577 |
1579 // First, tap. Then, do a scroll using the same touch-id. | 1578 // First, tap. Then, do a scroll using the same touch-id. |
1580 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1579 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1581 new GestureEventConsumeDelegate()); | 1580 new GestureEventConsumeDelegate()); |
1582 TimedEvents tes; | 1581 TimedEvents tes; |
1583 const int kWindowWidth = 123; | 1582 const int kWindowWidth = 123; |
1584 const int kWindowHeight = 45; | 1583 const int kWindowHeight = 45; |
1585 const int kTouchId = 3; | 1584 const int kTouchId = 3; |
1586 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1585 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
1587 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1586 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()); | 1823 EXPECT_FALSE(queued_delegate->begin()); |
1825 EXPECT_FALSE(queued_delegate->end()); | 1824 EXPECT_FALSE(queued_delegate->end()); |
1826 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1825 EXPECT_FALSE(queued_delegate->scroll_begin()); |
1827 EXPECT_FALSE(queued_delegate->scroll_update()); | 1826 EXPECT_FALSE(queued_delegate->scroll_update()); |
1828 EXPECT_FALSE(queued_delegate->scroll_end()); | 1827 EXPECT_FALSE(queued_delegate->scroll_end()); |
1829 | 1828 |
1830 // Move the second touch-point enough so that it is considered a pinch. This | 1829 // Move the second touch-point enough so that it is considered a pinch. This |
1831 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. | 1830 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. |
1832 queued_delegate->Reset(); | 1831 queued_delegate->Reset(); |
1833 delegate->Reset(); | 1832 delegate->Reset(); |
1834 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); | |
1835 ui::TouchEvent move( | 1833 ui::TouchEvent move( |
1836 ui::ET_TOUCH_MOVED, gfx::Point(203 + x_move, 303), kTouchId2, tes.Now()); | 1834 ui::ET_TOUCH_MOVED, |
1835 gfx::PointF( | |
1836 203 + ui::GestureConfiguration::max_touch_move_in_pixels_for_click(), | |
1837 303), | |
1838 kTouchId2, | |
1839 tes.Now()); | |
1837 DispatchEventUsingWindowDispatcher(&move); | 1840 DispatchEventUsingWindowDispatcher(&move); |
1838 EXPECT_FALSE(delegate->tap()); | 1841 EXPECT_FALSE(delegate->tap()); |
1839 EXPECT_FALSE(delegate->tap_down()); | 1842 EXPECT_FALSE(delegate->tap_down()); |
1840 EXPECT_FALSE(delegate->tap_cancel()); | 1843 EXPECT_FALSE(delegate->tap_cancel()); |
1841 EXPECT_FALSE(delegate->begin()); | 1844 EXPECT_FALSE(delegate->begin()); |
1842 EXPECT_FALSE(delegate->scroll_begin()); | 1845 EXPECT_FALSE(delegate->scroll_begin()); |
1843 EXPECT_FALSE(delegate->scroll_update()); | 1846 EXPECT_FALSE(delegate->scroll_update()); |
1844 EXPECT_FALSE(delegate->scroll_end()); | 1847 EXPECT_FALSE(delegate->scroll_end()); |
1845 EXPECT_FALSE(queued_delegate->tap()); | 1848 EXPECT_FALSE(queued_delegate->tap()); |
1846 EXPECT_FALSE(queued_delegate->tap_down()); | 1849 EXPECT_FALSE(queued_delegate->tap_down()); |
(...skipping 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4303 ui::TouchEvent move3( | 4306 ui::TouchEvent move3( |
4304 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); | 4307 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); |
4305 DispatchEventUsingWindowDispatcher(&move3); | 4308 DispatchEventUsingWindowDispatcher(&move3); |
4306 | 4309 |
4307 delegate->ReceivedAck(); | 4310 delegate->ReceivedAck(); |
4308 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); | 4311 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); |
4309 } | 4312 } |
4310 | 4313 |
4311 } // namespace test | 4314 } // namespace test |
4312 } // namespace aura | 4315 } // namespace aura |
OLD | NEW |