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

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

Issue 22354005: Add support for maintaining ordinal values through GestureRecognizer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix to fling Created 7 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.cc » ('j') | ui/base/gestures/gesture_types.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 swipe_left_(false), 83 swipe_left_(false),
84 swipe_right_(false), 84 swipe_right_(false),
85 swipe_up_(false), 85 swipe_up_(false),
86 swipe_down_(false), 86 swipe_down_(false),
87 scroll_x_(0), 87 scroll_x_(0),
88 scroll_y_(0), 88 scroll_y_(0),
89 scroll_velocity_x_(0), 89 scroll_velocity_x_(0),
90 scroll_velocity_y_(0), 90 scroll_velocity_y_(0),
91 velocity_x_(0), 91 velocity_x_(0),
92 velocity_y_(0), 92 velocity_y_(0),
93 scroll_x_ordinal_(0),
94 scroll_y_ordinal_(0),
95 scroll_velocity_x_ordinal_(0),
96 scroll_velocity_y_ordinal_(0),
97 velocity_x_ordinal_(0),
98 velocity_y_ordinal_(0),
93 tap_count_(0), 99 tap_count_(0),
94 wait_until_event_(ui::ET_UNKNOWN) { 100 wait_until_event_(ui::ET_UNKNOWN) {
95 } 101 }
96 102
97 virtual ~GestureEventConsumeDelegate() {} 103 virtual ~GestureEventConsumeDelegate() {}
98 104
99 void Reset() { 105 void Reset() {
100 events_.clear(); 106 events_.clear();
101 tap_ = false; 107 tap_ = false;
102 tap_down_ = false; 108 tap_down_ = false;
(...skipping 16 matching lines...) Expand all
119 125
120 scroll_begin_position_.SetPoint(0, 0); 126 scroll_begin_position_.SetPoint(0, 0);
121 tap_location_.SetPoint(0, 0); 127 tap_location_.SetPoint(0, 0);
122 128
123 scroll_x_ = 0; 129 scroll_x_ = 0;
124 scroll_y_ = 0; 130 scroll_y_ = 0;
125 scroll_velocity_x_ = 0; 131 scroll_velocity_x_ = 0;
126 scroll_velocity_y_ = 0; 132 scroll_velocity_y_ = 0;
127 velocity_x_ = 0; 133 velocity_x_ = 0;
128 velocity_y_ = 0; 134 velocity_y_ = 0;
135 scroll_x_ordinal_ = 0;
136 scroll_y_ordinal_ = 0;
137 scroll_velocity_x_ordinal_ = 0;
138 scroll_velocity_y_ordinal_ = 0;
139 velocity_x_ordinal_ = 0;
140 velocity_y_ordinal_ = 0;
129 tap_count_ = 0; 141 tap_count_ = 0;
130 } 142 }
131 143
132 const std::vector<ui::EventType>& events() const { return events_; }; 144 const std::vector<ui::EventType>& events() const { return events_; };
133 145
134 bool tap() const { return tap_; } 146 bool tap() const { return tap_; }
135 bool tap_down() const { return tap_down_; } 147 bool tap_down() const { return tap_down_; }
136 bool tap_cancel() const { return tap_cancel_; } 148 bool tap_cancel() const { return tap_cancel_; }
137 bool begin() const { return begin_; } 149 bool begin() const { return begin_; }
138 bool end() const { return end_; } 150 bool end() const { return end_; }
(...skipping 17 matching lines...) Expand all
156 } 168 }
157 169
158 const gfx::Point tap_location() const { 170 const gfx::Point tap_location() const {
159 return tap_location_; 171 return tap_location_;
160 } 172 }
161 173
162 float scroll_x() const { return scroll_x_; } 174 float scroll_x() const { return scroll_x_; }
163 float scroll_y() const { return scroll_y_; } 175 float scroll_y() const { return scroll_y_; }
164 float scroll_velocity_x() const { return scroll_velocity_x_; } 176 float scroll_velocity_x() const { return scroll_velocity_x_; }
165 float scroll_velocity_y() const { return scroll_velocity_y_; } 177 float scroll_velocity_y() const { return scroll_velocity_y_; }
166 int touch_id() const { return touch_id_; }
167 float velocity_x() const { return velocity_x_; } 178 float velocity_x() const { return velocity_x_; }
168 float velocity_y() const { return velocity_y_; } 179 float velocity_y() const { return velocity_y_; }
180 float scroll_x_ordinal() const { return scroll_x_ordinal_; }
181 float scroll_y_ordinal() const { return scroll_y_ordinal_; }
182 float scroll_velocity_x_ordinal() const { return scroll_velocity_x_ordinal_; }
183 float scroll_velocity_y_ordinal() const { return scroll_velocity_y_ordinal_; }
184 float velocity_x_ordinal() const { return velocity_x_ordinal_; }
185 float velocity_y_ordinal() const { return velocity_y_ordinal_; }
186 int touch_id() const { return touch_id_; }
169 const gfx::Rect& bounding_box() const { return bounding_box_; } 187 const gfx::Rect& bounding_box() const { return bounding_box_; }
170 int tap_count() const { return tap_count_; } 188 int tap_count() const { return tap_count_; }
171 189
172 void WaitUntilReceivedGesture(ui::EventType type) { 190 void WaitUntilReceivedGesture(ui::EventType type) {
173 wait_until_event_ = type; 191 wait_until_event_ = type;
174 run_loop_.reset(new base::RunLoop( 192 run_loop_.reset(new base::RunLoop(
175 Env::GetInstance()->GetDispatcher())); 193 Env::GetInstance()->GetDispatcher()));
176 run_loop_->Run(); 194 run_loop_->Run();
177 } 195 }
178 196
(...skipping 21 matching lines...) Expand all
200 case ui::ET_GESTURE_SCROLL_BEGIN: 218 case ui::ET_GESTURE_SCROLL_BEGIN:
201 scroll_begin_ = true; 219 scroll_begin_ = true;
202 scroll_begin_position_ = gesture->location(); 220 scroll_begin_position_ = gesture->location();
203 break; 221 break;
204 case ui::ET_GESTURE_SCROLL_UPDATE: 222 case ui::ET_GESTURE_SCROLL_UPDATE:
205 scroll_update_ = true; 223 scroll_update_ = true;
206 scroll_x_ += gesture->details().scroll_x(); 224 scroll_x_ += gesture->details().scroll_x();
207 scroll_y_ += gesture->details().scroll_y(); 225 scroll_y_ += gesture->details().scroll_y();
208 scroll_velocity_x_ = gesture->details().velocity_x(); 226 scroll_velocity_x_ = gesture->details().velocity_x();
209 scroll_velocity_y_ = gesture->details().velocity_y(); 227 scroll_velocity_y_ = gesture->details().velocity_y();
228 scroll_x_ordinal_ += gesture->details().scroll_x_ordinal();
229 scroll_y_ordinal_ += gesture->details().scroll_y_ordinal();
230 scroll_velocity_x_ordinal_ = gesture->details().velocity_x_ordinal();
231 scroll_velocity_y_ordinal_ = gesture->details().velocity_y_ordinal();
210 break; 232 break;
211 case ui::ET_GESTURE_SCROLL_END: 233 case ui::ET_GESTURE_SCROLL_END:
212 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); 234 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0);
213 scroll_end_ = true; 235 scroll_end_ = true;
214 break; 236 break;
215 case ui::ET_GESTURE_PINCH_BEGIN: 237 case ui::ET_GESTURE_PINCH_BEGIN:
216 pinch_begin_ = true; 238 pinch_begin_ = true;
217 break; 239 break;
218 case ui::ET_GESTURE_PINCH_UPDATE: 240 case ui::ET_GESTURE_PINCH_UPDATE:
219 pinch_update_ = true; 241 pinch_update_ = true;
220 break; 242 break;
221 case ui::ET_GESTURE_PINCH_END: 243 case ui::ET_GESTURE_PINCH_END:
222 pinch_end_ = true; 244 pinch_end_ = true;
223 break; 245 break;
224 case ui::ET_GESTURE_LONG_PRESS: 246 case ui::ET_GESTURE_LONG_PRESS:
225 long_press_ = true; 247 long_press_ = true;
226 touch_id_ = gesture->details().touch_id(); 248 touch_id_ = gesture->details().touch_id();
227 break; 249 break;
228 case ui::ET_GESTURE_LONG_TAP: 250 case ui::ET_GESTURE_LONG_TAP:
229 long_tap_ = true; 251 long_tap_ = true;
230 break; 252 break;
231 case ui::ET_SCROLL_FLING_START: 253 case ui::ET_SCROLL_FLING_START:
232 EXPECT_TRUE(gesture->details().velocity_x() != 0 || 254 EXPECT_TRUE(gesture->details().velocity_x() != 0 ||
233 gesture->details().velocity_y() != 0); 255 gesture->details().velocity_y() != 0);
234 EXPECT_FALSE(scroll_end_); 256 EXPECT_FALSE(scroll_end_);
235 fling_ = true; 257 fling_ = true;
236 velocity_x_ = gesture->details().velocity_x(); 258 velocity_x_ = gesture->details().velocity_x();
237 velocity_y_ = gesture->details().velocity_y(); 259 velocity_y_ = gesture->details().velocity_y();
260 velocity_x_ordinal_ = gesture->details().velocity_x_ordinal();
261 velocity_y_ordinal_ = gesture->details().velocity_y_ordinal();
238 break; 262 break;
239 case ui::ET_GESTURE_TWO_FINGER_TAP: 263 case ui::ET_GESTURE_TWO_FINGER_TAP:
240 two_finger_tap_ = true; 264 two_finger_tap_ = true;
241 break; 265 break;
242 case ui::ET_GESTURE_MULTIFINGER_SWIPE: 266 case ui::ET_GESTURE_MULTIFINGER_SWIPE:
243 swipe_left_ = gesture->details().swipe_left(); 267 swipe_left_ = gesture->details().swipe_left();
244 swipe_right_ = gesture->details().swipe_right(); 268 swipe_right_ = gesture->details().swipe_right();
245 swipe_up_ = gesture->details().swipe_up(); 269 swipe_up_ = gesture->details().swipe_up();
246 swipe_down_ = gesture->details().swipe_down(); 270 swipe_down_ = gesture->details().swipe_down();
247 break; 271 break;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 305
282 gfx::Point scroll_begin_position_; 306 gfx::Point scroll_begin_position_;
283 gfx::Point tap_location_; 307 gfx::Point tap_location_;
284 308
285 float scroll_x_; 309 float scroll_x_;
286 float scroll_y_; 310 float scroll_y_;
287 float scroll_velocity_x_; 311 float scroll_velocity_x_;
288 float scroll_velocity_y_; 312 float scroll_velocity_y_;
289 float velocity_x_; 313 float velocity_x_;
290 float velocity_y_; 314 float velocity_y_;
315 float scroll_x_ordinal_;
316 float scroll_y_ordinal_;
317 float scroll_velocity_x_ordinal_;
318 float scroll_velocity_y_ordinal_;
319 float velocity_x_ordinal_;
320 float velocity_y_ordinal_;
291 int touch_id_; 321 int touch_id_;
292 gfx::Rect bounding_box_; 322 gfx::Rect bounding_box_;
293 int tap_count_; 323 int tap_count_;
294 324
295 ui::EventType wait_until_event_; 325 ui::EventType wait_until_event_;
296 326
297 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 327 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate);
298 }; 328 };
299 329
300 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 330 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 delegate.get(), -1234, bounds, root_window())); 1126 delegate.get(), -1234, bounds, root_window()));
1097 1127
1098 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1128 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1099 kTouchId, tes.Now()); 1129 kTouchId, tes.Now());
1100 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1130 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1101 1131
1102 // Move the touch-point horizontally enough that it is considered a 1132 // Move the touch-point horizontally enough that it is considered a
1103 // horizontal scroll. 1133 // horizontal scroll.
1104 tes.SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 1134 tes.SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
1105 EXPECT_EQ(0, delegate->scroll_y()); 1135 EXPECT_EQ(0, delegate->scroll_y());
1136 EXPECT_EQ(1, delegate->scroll_y_ordinal());
1106 EXPECT_EQ(20, delegate->scroll_x()); 1137 EXPECT_EQ(20, delegate->scroll_x());
1138 EXPECT_EQ(20, delegate->scroll_x_ordinal());
1107 1139
1108 // Get a high x velocity, while still staying on the rail 1140 // Get a high x velocity, while still staying on the rail
1109 tes.SendScrollEvents(root_window(), 1, 1, 1141 tes.SendScrollEvents(root_window(), 1, 1,
1110 100, 10, kTouchId, 1, 1142 100, 10, kTouchId, 1,
1111 ui::GestureConfiguration::points_buffered_for_velocity(), 1143 ui::GestureConfiguration::points_buffered_for_velocity(),
1112 delegate.get()); 1144 delegate.get());
1113 // The y-velocity during the scroll should be 0 since this is in a horizontal 1145 // The y-velocity during the scroll should be 0 since this is in a horizontal
1114 // rail scroll. 1146 // rail scroll.
1115 EXPECT_GT(delegate->scroll_velocity_x(), 0); 1147 EXPECT_GT(delegate->scroll_velocity_x(), 0);
1116 EXPECT_EQ(0, delegate->scroll_velocity_y()); 1148 EXPECT_EQ(0, delegate->scroll_velocity_y());
(...skipping 21 matching lines...) Expand all
1138 delegate.get(), -1234, bounds, root_window())); 1170 delegate.get(), -1234, bounds, root_window()));
1139 1171
1140 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1172 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1141 kTouchId, tes.Now()); 1173 kTouchId, tes.Now());
1142 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1174 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1143 1175
1144 // Move the touch-point vertically enough that it is considered a 1176 // Move the touch-point vertically enough that it is considered a
1145 // vertical scroll. 1177 // vertical scroll.
1146 tes.SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 1178 tes.SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
1147 EXPECT_EQ(20, delegate->scroll_y()); 1179 EXPECT_EQ(20, delegate->scroll_y());
1180 EXPECT_EQ(20, delegate->scroll_y_ordinal());
1148 EXPECT_EQ(0, delegate->scroll_x()); 1181 EXPECT_EQ(0, delegate->scroll_x());
1182 EXPECT_EQ(1, delegate->scroll_x_ordinal());
1149 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1183 EXPECT_EQ(0, delegate->scroll_velocity_x());
1184 EXPECT_GT(delegate->scroll_velocity_x_ordinal(), 0);
1150 1185
1151 // Get a high y velocity, while still staying on the rail 1186 // Get a high y velocity, while still staying on the rail
1152 tes.SendScrollEvents(root_window(), 1, 1, 1187 tes.SendScrollEvents(root_window(), 1, 1,
1153 10, 100, kTouchId, 1, 1188 10, 100, kTouchId, 1,
1154 ui::GestureConfiguration::points_buffered_for_velocity(), 1189 ui::GestureConfiguration::points_buffered_for_velocity(),
1155 delegate.get()); 1190 delegate.get());
1156 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1191 EXPECT_EQ(0, delegate->scroll_velocity_x());
1157 EXPECT_GT(delegate->scroll_velocity_y(), 0); 1192 EXPECT_GT(delegate->scroll_velocity_y(), 0);
1158 1193
1159 delegate->Reset(); 1194 delegate->Reset();
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 tes.LeapForward(40)); 3413 tes.LeapForward(40));
3379 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 3414 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4);
3380 EXPECT_TRUE(delegate->scroll_update()); 3415 EXPECT_TRUE(delegate->scroll_update());
3381 EXPECT_EQ(-1, delegate->scroll_y()); 3416 EXPECT_EQ(-1, delegate->scroll_y());
3382 3417
3383 delegate->Reset(); 3418 delegate->Reset();
3384 } 3419 }
3385 3420
3386 } // namespace test 3421 } // namespace test
3387 } // namespace aura 3422 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/base/gestures/gesture_sequence.cc » ('j') | ui/base/gestures/gesture_types.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698