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

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

Issue 10837329: gesture: Include velocity in scroll-update gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/base/gestures/gesture_sequence.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 "base/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/aura/root_window.h" 9 #include "ui/aura/root_window.h"
10 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/test/aura_test_base.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 scroll_update_(false), 43 scroll_update_(false),
44 scroll_end_(false), 44 scroll_end_(false),
45 pinch_begin_(false), 45 pinch_begin_(false),
46 pinch_update_(false), 46 pinch_update_(false),
47 pinch_end_(false), 47 pinch_end_(false),
48 long_press_(false), 48 long_press_(false),
49 fling_(false), 49 fling_(false),
50 two_finger_tap_(false), 50 two_finger_tap_(false),
51 scroll_x_(0), 51 scroll_x_(0),
52 scroll_y_(0), 52 scroll_y_(0),
53 scroll_velocity_x_(0),
54 scroll_velocity_y_(0),
53 velocity_x_(0), 55 velocity_x_(0),
54 velocity_y_(0), 56 velocity_y_(0),
55 tap_count_(0) { 57 tap_count_(0) {
56 } 58 }
57 59
58 virtual ~GestureEventConsumeDelegate() {} 60 virtual ~GestureEventConsumeDelegate() {}
59 61
60 void Reset() { 62 void Reset() {
61 tap_ = false; 63 tap_ = false;
62 tap_down_ = false; 64 tap_down_ = false;
63 begin_ = false; 65 begin_ = false;
64 end_ = false; 66 end_ = false;
65 double_tap_ = false; 67 double_tap_ = false;
66 scroll_begin_ = false; 68 scroll_begin_ = false;
67 scroll_update_ = false; 69 scroll_update_ = false;
68 scroll_end_ = false; 70 scroll_end_ = false;
69 pinch_begin_ = false; 71 pinch_begin_ = false;
70 pinch_update_ = false; 72 pinch_update_ = false;
71 pinch_end_ = false; 73 pinch_end_ = false;
72 long_press_ = false; 74 long_press_ = false;
73 fling_ = false; 75 fling_ = false;
74 two_finger_tap_ = false; 76 two_finger_tap_ = false;
75 77
76 scroll_begin_position_.SetPoint(0, 0); 78 scroll_begin_position_.SetPoint(0, 0);
77 tap_location_.SetPoint(0, 0); 79 tap_location_.SetPoint(0, 0);
78 80
79 scroll_x_ = 0; 81 scroll_x_ = 0;
80 scroll_y_ = 0; 82 scroll_y_ = 0;
83 scroll_velocity_x_ = 0;
84 scroll_velocity_y_ = 0;
81 velocity_x_ = 0; 85 velocity_x_ = 0;
82 velocity_y_ = 0; 86 velocity_y_ = 0;
83 tap_count_ = 0; 87 tap_count_ = 0;
84 } 88 }
85 89
86 bool tap() const { return tap_; } 90 bool tap() const { return tap_; }
87 bool tap_down() const { return tap_down_; } 91 bool tap_down() const { return tap_down_; }
88 bool begin() const { return begin_; } 92 bool begin() const { return begin_; }
89 bool end() const { return end_; } 93 bool end() const { return end_; }
90 bool double_tap() const { return double_tap_; } 94 bool double_tap() const { return double_tap_; }
(...skipping 10 matching lines...) Expand all
101 const gfx::Point scroll_begin_position() const { 105 const gfx::Point scroll_begin_position() const {
102 return scroll_begin_position_; 106 return scroll_begin_position_;
103 } 107 }
104 108
105 const gfx::Point tap_location() const { 109 const gfx::Point tap_location() const {
106 return tap_location_; 110 return tap_location_;
107 } 111 }
108 112
109 float scroll_x() const { return scroll_x_; } 113 float scroll_x() const { return scroll_x_; }
110 float scroll_y() const { return scroll_y_; } 114 float scroll_y() const { return scroll_y_; }
115 float scroll_velocity_x() const { return scroll_velocity_x_; }
116 float scroll_velocity_y() const { return scroll_velocity_y_; }
111 int touch_id() const { return touch_id_; } 117 int touch_id() const { return touch_id_; }
112 float velocity_x() const { return velocity_x_; } 118 float velocity_x() const { return velocity_x_; }
113 float velocity_y() const { return velocity_y_; } 119 float velocity_y() const { return velocity_y_; }
114 const gfx::Rect& bounding_box() const { return bounding_box_; } 120 const gfx::Rect& bounding_box() const { return bounding_box_; }
115 int tap_count() const { return tap_count_; } 121 int tap_count() const { return tap_count_; }
116 122
117 virtual ui::GestureStatus OnGestureEvent( 123 virtual ui::GestureStatus OnGestureEvent(
118 ui::GestureEvent* gesture) OVERRIDE { 124 ui::GestureEvent* gesture) OVERRIDE {
119 bounding_box_ = gesture->details().bounding_box(); 125 bounding_box_ = gesture->details().bounding_box();
120 switch (gesture->type()) { 126 switch (gesture->type()) {
(...skipping 15 matching lines...) Expand all
136 double_tap_ = true; 142 double_tap_ = true;
137 break; 143 break;
138 case ui::ET_GESTURE_SCROLL_BEGIN: 144 case ui::ET_GESTURE_SCROLL_BEGIN:
139 scroll_begin_ = true; 145 scroll_begin_ = true;
140 scroll_begin_position_ = gesture->location(); 146 scroll_begin_position_ = gesture->location();
141 break; 147 break;
142 case ui::ET_GESTURE_SCROLL_UPDATE: 148 case ui::ET_GESTURE_SCROLL_UPDATE:
143 scroll_update_ = true; 149 scroll_update_ = true;
144 scroll_x_ += gesture->details().scroll_x(); 150 scroll_x_ += gesture->details().scroll_x();
145 scroll_y_ += gesture->details().scroll_y(); 151 scroll_y_ += gesture->details().scroll_y();
152 scroll_velocity_x_ = gesture->details().velocity_x();
153 scroll_velocity_y_ = gesture->details().velocity_y();
146 break; 154 break;
147 case ui::ET_GESTURE_SCROLL_END: 155 case ui::ET_GESTURE_SCROLL_END:
148 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); 156 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0);
149 scroll_end_ = true; 157 scroll_end_ = true;
150 break; 158 break;
151 case ui::ET_GESTURE_PINCH_BEGIN: 159 case ui::ET_GESTURE_PINCH_BEGIN:
152 pinch_begin_ = true; 160 pinch_begin_ = true;
153 break; 161 break;
154 case ui::ET_GESTURE_PINCH_UPDATE: 162 case ui::ET_GESTURE_PINCH_UPDATE:
155 pinch_update_ = true; 163 pinch_update_ = true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 bool pinch_end_; 200 bool pinch_end_;
193 bool long_press_; 201 bool long_press_;
194 bool fling_; 202 bool fling_;
195 bool two_finger_tap_; 203 bool two_finger_tap_;
196 204
197 gfx::Point scroll_begin_position_; 205 gfx::Point scroll_begin_position_;
198 gfx::Point tap_location_; 206 gfx::Point tap_location_;
199 207
200 float scroll_x_; 208 float scroll_x_;
201 float scroll_y_; 209 float scroll_y_;
210 float scroll_velocity_x_;
211 float scroll_velocity_y_;
202 float velocity_x_; 212 float velocity_x_;
203 float velocity_y_; 213 float velocity_y_;
204 int touch_id_; 214 int touch_id_;
205 gfx::Rect bounding_box_; 215 gfx::Rect bounding_box_;
206 int tap_count_; 216 int tap_count_;
207 217
208 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 218 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate);
209 }; 219 };
210 220
211 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 221 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 735 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get());
726 EXPECT_FALSE(delegate->tap()); 736 EXPECT_FALSE(delegate->tap());
727 EXPECT_FALSE(delegate->tap_down()); 737 EXPECT_FALSE(delegate->tap_down());
728 EXPECT_FALSE(delegate->begin()); 738 EXPECT_FALSE(delegate->begin());
729 EXPECT_FALSE(delegate->double_tap()); 739 EXPECT_FALSE(delegate->double_tap());
730 EXPECT_TRUE(delegate->scroll_begin()); 740 EXPECT_TRUE(delegate->scroll_begin());
731 EXPECT_TRUE(delegate->scroll_update()); 741 EXPECT_TRUE(delegate->scroll_update());
732 EXPECT_FALSE(delegate->scroll_end()); 742 EXPECT_FALSE(delegate->scroll_end());
733 EXPECT_EQ(29, delegate->scroll_x()); 743 EXPECT_EQ(29, delegate->scroll_x());
734 EXPECT_EQ(29, delegate->scroll_y()); 744 EXPECT_EQ(29, delegate->scroll_y());
745 EXPECT_EQ(0, delegate->scroll_velocity_x());
746 EXPECT_EQ(0, delegate->scroll_velocity_y());
735 EXPECT_EQ(gfx::Point(1, 1).ToString(), 747 EXPECT_EQ(gfx::Point(1, 1).ToString(),
736 delegate->scroll_begin_position().ToString()); 748 delegate->scroll_begin_position().ToString());
737 749
738 // When scrolling with a single finger, the bounding box of the gesture should 750 // When scrolling with a single finger, the bounding box of the gesture should
739 // be empty, since it's a single point and the radius for testing is zero. 751 // be empty, since it's a single point and the radius for testing is zero.
740 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 752 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
741 753
742 // Move some more to generate a few more scroll updates. 754 // Move some more to generate a few more scroll updates.
743 SendScrollEvent(root_window(), 110, 211, kTouchId, delegate.get()); 755 SendScrollEvent(root_window(), 110, 211, kTouchId, delegate.get());
744 EXPECT_FALSE(delegate->tap()); 756 EXPECT_FALSE(delegate->tap());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 // horizontal scroll. 865 // horizontal scroll.
854 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 866 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
855 EXPECT_EQ(0, delegate->scroll_y()); 867 EXPECT_EQ(0, delegate->scroll_y());
856 EXPECT_EQ(20, delegate->scroll_x()); 868 EXPECT_EQ(20, delegate->scroll_x());
857 869
858 // Get a high x velocity, while still staying on the rail 870 // Get a high x velocity, while still staying on the rail
859 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 871 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
860 100, 10, kTouchId, 1, 872 100, 10, kTouchId, 1,
861 ui::GestureConfiguration::points_buffered_for_velocity(), 873 ui::GestureConfiguration::points_buffered_for_velocity(),
862 delegate.get()); 874 delegate.get());
875 // The y-velocity during the scroll should be 0 since this is in a horizontal
876 // rail scroll.
877 EXPECT_GT(delegate->scroll_velocity_x(), 0);
878 EXPECT_EQ(0, delegate->scroll_velocity_y());
863 879
864 delegate->Reset(); 880 delegate->Reset();
865 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 881 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
866 kTouchId, GetTime()); 882 kTouchId, GetTime());
867 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 883 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
868 884
869 EXPECT_TRUE(delegate->fling()); 885 EXPECT_TRUE(delegate->fling());
870 EXPECT_FALSE(delegate->scroll_end()); 886 EXPECT_FALSE(delegate->scroll_end());
871 EXPECT_GT(delegate->velocity_x(), 0); 887 EXPECT_GT(delegate->velocity_x(), 0);
872 EXPECT_EQ(0, delegate->velocity_y()); 888 EXPECT_EQ(0, delegate->velocity_y());
(...skipping 11 matching lines...) Expand all
884 900
885 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 901 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
886 kTouchId, GetTime()); 902 kTouchId, GetTime());
887 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 903 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
888 904
889 // Move the touch-point vertically enough that it is considered a 905 // Move the touch-point vertically enough that it is considered a
890 // vertical scroll. 906 // vertical scroll.
891 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 907 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
892 EXPECT_EQ(20, delegate->scroll_y()); 908 EXPECT_EQ(20, delegate->scroll_y());
893 EXPECT_EQ(0, delegate->scroll_x()); 909 EXPECT_EQ(0, delegate->scroll_x());
910 EXPECT_EQ(0, delegate->scroll_velocity_x());
911 EXPECT_EQ(0, delegate->scroll_velocity_y());
894 912
895 // Get a high y velocity, while still staying on the rail 913 // Get a high y velocity, while still staying on the rail
896 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 914 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
897 10, 100, kTouchId, 1, 915 10, 100, kTouchId, 1,
898 ui::GestureConfiguration::points_buffered_for_velocity(), 916 ui::GestureConfiguration::points_buffered_for_velocity(),
899 delegate.get()); 917 delegate.get());
918 EXPECT_EQ(0, delegate->scroll_velocity_x());
919 EXPECT_GT(delegate->scroll_velocity_y(), 0);
900 920
901 delegate->Reset(); 921 delegate->Reset();
902 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 922 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
903 kTouchId, GetTime()); 923 kTouchId, GetTime());
904 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 924 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
905 925
906 EXPECT_TRUE(delegate->fling()); 926 EXPECT_TRUE(delegate->fling());
907 EXPECT_FALSE(delegate->scroll_end()); 927 EXPECT_FALSE(delegate->scroll_end());
908 EXPECT_EQ(0, delegate->velocity_x()); 928 EXPECT_EQ(0, delegate->velocity_x());
909 EXPECT_GT(delegate->velocity_y(), 0); 929 EXPECT_GT(delegate->velocity_y(), 0);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 // horizontal scroll. 1118 // horizontal scroll.
1099 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 1119 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
1100 EXPECT_EQ(0, delegate->scroll_y()); 1120 EXPECT_EQ(0, delegate->scroll_y());
1101 EXPECT_EQ(20, delegate->scroll_x()); 1121 EXPECT_EQ(20, delegate->scroll_x());
1102 1122
1103 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); 1123 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get());
1104 EXPECT_TRUE(delegate->scroll_update()); 1124 EXPECT_TRUE(delegate->scroll_update());
1105 EXPECT_EQ(5, delegate->scroll_x()); 1125 EXPECT_EQ(5, delegate->scroll_x());
1106 // y shouldn't change, as we're on a horizontal rail. 1126 // y shouldn't change, as we're on a horizontal rail.
1107 EXPECT_EQ(0, delegate->scroll_y()); 1127 EXPECT_EQ(0, delegate->scroll_y());
1128 EXPECT_EQ(0, delegate->scroll_velocity_x());
1129 EXPECT_EQ(0, delegate->scroll_velocity_y());
1108 1130
1109 // Send enough information that a velocity can be calculated for the gesture, 1131 // Send enough information that a velocity can be calculated for the gesture,
1110 // and we can break the rail 1132 // and we can break the rail
1111 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 1133 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
1112 1, 100, kTouchId, 1, 1134 1, 100, kTouchId, 1,
1113 ui::GestureConfiguration::points_buffered_for_velocity(), 1135 ui::GestureConfiguration::points_buffered_for_velocity(),
1114 delegate.get()); 1136 delegate.get());
1137 // Since the scroll is not longer railing, the velocity should be set for both
1138 // axis.
1139 EXPECT_GT(delegate->scroll_velocity_x(), 0);
1140 EXPECT_GT(delegate->scroll_velocity_y(), 0);
1115 1141
1116 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); 1142 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
1117 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); 1143 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
1118 1144
1119 // The rail should be broken 1145 // The rail should be broken
1120 EXPECT_TRUE(delegate->scroll_update()); 1146 EXPECT_TRUE(delegate->scroll_update());
1121 EXPECT_EQ(5, delegate->scroll_x()); 1147 EXPECT_EQ(5, delegate->scroll_x());
1122 EXPECT_EQ(5, delegate->scroll_y()); 1148 EXPECT_EQ(5, delegate->scroll_y());
1123 } 1149 }
1124 1150
(...skipping 15 matching lines...) Expand all
1140 // vertical scroll. 1166 // vertical scroll.
1141 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 1167 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
1142 EXPECT_EQ(0, delegate->scroll_x()); 1168 EXPECT_EQ(0, delegate->scroll_x());
1143 EXPECT_EQ(20, delegate->scroll_y()); 1169 EXPECT_EQ(20, delegate->scroll_y());
1144 1170
1145 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); 1171 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get());
1146 EXPECT_TRUE(delegate->scroll_update()); 1172 EXPECT_TRUE(delegate->scroll_update());
1147 EXPECT_EQ(5, delegate->scroll_y()); 1173 EXPECT_EQ(5, delegate->scroll_y());
1148 // x shouldn't change, as we're on a vertical rail. 1174 // x shouldn't change, as we're on a vertical rail.
1149 EXPECT_EQ(0, delegate->scroll_x()); 1175 EXPECT_EQ(0, delegate->scroll_x());
1176 EXPECT_EQ(0, delegate->scroll_velocity_x());
1177 EXPECT_EQ(0, delegate->scroll_velocity_y());
1150 1178
1151 // Send enough information that a velocity can be calculated for the gesture, 1179 // Send enough information that a velocity can be calculated for the gesture,
1152 // and we can break the rail 1180 // and we can break the rail
1153 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 1181 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
1154 100, 1, kTouchId, 1, 1182 100, 1, kTouchId, 1,
1155 ui::GestureConfiguration::points_buffered_for_velocity(), 1183 ui::GestureConfiguration::points_buffered_for_velocity(),
1156 delegate.get()); 1184 delegate.get());
1185 EXPECT_GT(delegate->scroll_velocity_x(), 0);
1186 EXPECT_GT(delegate->scroll_velocity_y(), 0);
1157 1187
1158 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); 1188 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
1159 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); 1189 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
1160 1190
1161 // The rail should be broken 1191 // The rail should be broken
1162 EXPECT_TRUE(delegate->scroll_update()); 1192 EXPECT_TRUE(delegate->scroll_update());
1163 EXPECT_EQ(5, delegate->scroll_x()); 1193 EXPECT_EQ(5, delegate->scroll_x());
1164 EXPECT_EQ(5, delegate->scroll_y()); 1194 EXPECT_EQ(5, delegate->scroll_y());
1165 } 1195 }
1166 1196
(...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 2763 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
2734 EXPECT_FALSE(delegate->tap()); 2764 EXPECT_FALSE(delegate->tap());
2735 EXPECT_FALSE(delegate->scroll_update()); 2765 EXPECT_FALSE(delegate->scroll_update());
2736 EXPECT_FALSE(delegate->pinch_update()); 2766 EXPECT_FALSE(delegate->pinch_update());
2737 2767
2738 delegate->Reset(); 2768 delegate->Reset();
2739 } 2769 }
2740 2770
2741 } // namespace test 2771 } // namespace test
2742 } // namespace aura 2772 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/base/gestures/gesture_sequence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698