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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 scroll_x_(0), | 90 scroll_x_(0), |
91 scroll_y_(0), | 91 scroll_y_(0), |
92 scroll_velocity_x_(0), | 92 scroll_velocity_x_(0), |
93 scroll_velocity_y_(0), | 93 scroll_velocity_y_(0), |
94 velocity_x_(0), | 94 velocity_x_(0), |
95 velocity_y_(0), | 95 velocity_y_(0), |
96 scroll_x_hint_(0), | 96 scroll_x_hint_(0), |
97 scroll_y_hint_(0), | 97 scroll_y_hint_(0), |
98 tap_count_(0), | 98 tap_count_(0), |
99 flags_(0), | 99 flags_(0), |
| 100 scroll_rail_state_(ui::GestureEventDetails::ScrollRailState::Free), |
100 wait_until_event_(ui::ET_UNKNOWN) {} | 101 wait_until_event_(ui::ET_UNKNOWN) {} |
101 | 102 |
102 ~GestureEventConsumeDelegate() override {} | 103 ~GestureEventConsumeDelegate() override {} |
103 | 104 |
104 void Reset() { | 105 void Reset() { |
105 events_.clear(); | 106 events_.clear(); |
106 tap_ = false; | 107 tap_ = false; |
107 tap_down_ = false; | 108 tap_down_ = false; |
108 tap_cancel_ = false; | 109 tap_cancel_ = false; |
109 begin_ = false; | 110 begin_ = false; |
(...skipping 21 matching lines...) Expand all Loading... |
131 scroll_y_ = 0; | 132 scroll_y_ = 0; |
132 scroll_velocity_x_ = 0; | 133 scroll_velocity_x_ = 0; |
133 scroll_velocity_y_ = 0; | 134 scroll_velocity_y_ = 0; |
134 velocity_x_ = 0; | 135 velocity_x_ = 0; |
135 velocity_y_ = 0; | 136 velocity_y_ = 0; |
136 scroll_x_hint_ = 0; | 137 scroll_x_hint_ = 0; |
137 scroll_y_hint_ = 0; | 138 scroll_y_hint_ = 0; |
138 tap_count_ = 0; | 139 tap_count_ = 0; |
139 scale_ = 0; | 140 scale_ = 0; |
140 flags_ = 0; | 141 flags_ = 0; |
| 142 scroll_rail_state_ = ui::GestureEventDetails::ScrollRailState::Free; |
141 latency_info_.Clear(); | 143 latency_info_.Clear(); |
142 } | 144 } |
143 | 145 |
144 const std::vector<ui::EventType>& events() const { return events_; }; | 146 const std::vector<ui::EventType>& events() const { return events_; }; |
145 | 147 |
146 bool tap() const { return tap_; } | 148 bool tap() const { return tap_; } |
147 bool tap_down() const { return tap_down_; } | 149 bool tap_down() const { return tap_down_; } |
148 bool tap_cancel() const { return tap_cancel_; } | 150 bool tap_cancel() const { return tap_cancel_; } |
149 bool begin() const { return begin_; } | 151 bool begin() const { return begin_; } |
150 bool end() const { return end_; } | 152 bool end() const { return end_; } |
(...skipping 30 matching lines...) Expand all Loading... |
181 float scroll_velocity_x() const { return scroll_velocity_x_; } | 183 float scroll_velocity_x() const { return scroll_velocity_x_; } |
182 float scroll_velocity_y() const { return scroll_velocity_y_; } | 184 float scroll_velocity_y() const { return scroll_velocity_y_; } |
183 float velocity_x() const { return velocity_x_; } | 185 float velocity_x() const { return velocity_x_; } |
184 float velocity_y() const { return velocity_y_; } | 186 float velocity_y() const { return velocity_y_; } |
185 float scroll_x_hint() const { return scroll_x_hint_; } | 187 float scroll_x_hint() const { return scroll_x_hint_; } |
186 float scroll_y_hint() const { return scroll_y_hint_; } | 188 float scroll_y_hint() const { return scroll_y_hint_; } |
187 float scale() const { return scale_; } | 189 float scale() const { return scale_; } |
188 const gfx::Rect& bounding_box() const { return bounding_box_; } | 190 const gfx::Rect& bounding_box() const { return bounding_box_; } |
189 int tap_count() const { return tap_count_; } | 191 int tap_count() const { return tap_count_; } |
190 int flags() const { return flags_; } | 192 int flags() const { return flags_; } |
| 193 ui::GestureEventDetails::ScrollRailState scroll_rail_state() const { |
| 194 return scroll_rail_state_; |
| 195 } |
191 const ui::LatencyInfo& latency_info() const { return latency_info_; } | 196 const ui::LatencyInfo& latency_info() const { return latency_info_; } |
192 | 197 |
193 void WaitUntilReceivedGesture(ui::EventType type) { | 198 void WaitUntilReceivedGesture(ui::EventType type) { |
194 wait_until_event_ = type; | 199 wait_until_event_ = type; |
195 run_loop_.reset(new base::RunLoop()); | 200 run_loop_.reset(new base::RunLoop()); |
196 run_loop_->Run(); | 201 run_loop_->Run(); |
197 } | 202 } |
198 | 203 |
199 void OnGestureEvent(ui::GestureEvent* gesture) override { | 204 void OnGestureEvent(ui::GestureEvent* gesture) override { |
200 events_.push_back(gesture->type()); | 205 events_.push_back(gesture->type()); |
(...skipping 22 matching lines...) Expand all Loading... |
223 case ui::ET_GESTURE_SCROLL_BEGIN: | 228 case ui::ET_GESTURE_SCROLL_BEGIN: |
224 scroll_begin_ = true; | 229 scroll_begin_ = true; |
225 scroll_begin_position_ = gesture->location(); | 230 scroll_begin_position_ = gesture->location(); |
226 scroll_x_hint_ = gesture->details().scroll_x_hint(); | 231 scroll_x_hint_ = gesture->details().scroll_x_hint(); |
227 scroll_y_hint_ = gesture->details().scroll_y_hint(); | 232 scroll_y_hint_ = gesture->details().scroll_y_hint(); |
228 break; | 233 break; |
229 case ui::ET_GESTURE_SCROLL_UPDATE: | 234 case ui::ET_GESTURE_SCROLL_UPDATE: |
230 scroll_update_ = true; | 235 scroll_update_ = true; |
231 scroll_x_ += gesture->details().scroll_x(); | 236 scroll_x_ += gesture->details().scroll_x(); |
232 scroll_y_ += gesture->details().scroll_y(); | 237 scroll_y_ += gesture->details().scroll_y(); |
| 238 scroll_rail_state_ = gesture->details().scroll_rail_state(); |
233 break; | 239 break; |
234 case ui::ET_GESTURE_SCROLL_END: | 240 case ui::ET_GESTURE_SCROLL_END: |
235 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); | 241 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); |
236 scroll_end_ = true; | 242 scroll_end_ = true; |
237 break; | 243 break; |
238 case ui::ET_GESTURE_PINCH_BEGIN: | 244 case ui::ET_GESTURE_PINCH_BEGIN: |
239 pinch_begin_ = true; | 245 pinch_begin_ = true; |
240 break; | 246 break; |
241 case ui::ET_GESTURE_PINCH_UPDATE: | 247 case ui::ET_GESTURE_PINCH_UPDATE: |
242 pinch_update_ = true; | 248 pinch_update_ = true; |
243 scale_ = gesture->details().scale(); | 249 scale_ = gesture->details().scale(); |
244 break; | 250 break; |
245 case ui::ET_GESTURE_PINCH_END: | 251 case ui::ET_GESTURE_PINCH_END: |
246 pinch_end_ = true; | 252 pinch_end_ = true; |
247 break; | 253 break; |
248 case ui::ET_GESTURE_LONG_PRESS: | 254 case ui::ET_GESTURE_LONG_PRESS: |
249 long_press_ = true; | 255 long_press_ = true; |
250 break; | 256 break; |
251 case ui::ET_GESTURE_LONG_TAP: | 257 case ui::ET_GESTURE_LONG_TAP: |
252 long_tap_ = true; | 258 long_tap_ = true; |
253 break; | 259 break; |
254 case ui::ET_SCROLL_FLING_START: | 260 case ui::ET_SCROLL_FLING_START: |
255 EXPECT_TRUE(gesture->details().velocity_x() != 0 || | 261 EXPECT_TRUE(gesture->details().velocity_x() != 0 || |
256 gesture->details().velocity_y() != 0); | 262 gesture->details().velocity_y() != 0); |
| 263 scroll_rail_state_ = gesture->details().scroll_rail_state(); |
257 EXPECT_FALSE(scroll_end_); | 264 EXPECT_FALSE(scroll_end_); |
258 fling_ = true; | 265 fling_ = true; |
259 velocity_x_ = gesture->details().velocity_x(); | 266 velocity_x_ = gesture->details().velocity_x(); |
260 velocity_y_ = gesture->details().velocity_y(); | 267 velocity_y_ = gesture->details().velocity_y(); |
261 break; | 268 break; |
262 case ui::ET_GESTURE_TWO_FINGER_TAP: | 269 case ui::ET_GESTURE_TWO_FINGER_TAP: |
263 two_finger_tap_ = true; | 270 two_finger_tap_ = true; |
264 break; | 271 break; |
265 case ui::ET_GESTURE_SHOW_PRESS: | 272 case ui::ET_GESTURE_SHOW_PRESS: |
266 show_press_ = true; | 273 show_press_ = true; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 float scroll_velocity_x_; | 325 float scroll_velocity_x_; |
319 float scroll_velocity_y_; | 326 float scroll_velocity_y_; |
320 float velocity_x_; | 327 float velocity_x_; |
321 float velocity_y_; | 328 float velocity_y_; |
322 float scroll_x_hint_; | 329 float scroll_x_hint_; |
323 float scroll_y_hint_; | 330 float scroll_y_hint_; |
324 float scale_; | 331 float scale_; |
325 gfx::Rect bounding_box_; | 332 gfx::Rect bounding_box_; |
326 int tap_count_; | 333 int tap_count_; |
327 int flags_; | 334 int flags_; |
| 335 ui::GestureEventDetails::ScrollRailState scroll_rail_state_; |
328 ui::LatencyInfo latency_info_; | 336 ui::LatencyInfo latency_info_; |
329 | 337 |
330 ui::EventType wait_until_event_; | 338 ui::EventType wait_until_event_; |
331 | 339 |
332 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); | 340 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); |
333 }; | 341 }; |
334 | 342 |
335 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { | 343 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { |
336 public: | 344 public: |
337 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) | 345 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 // Get rid of touch slop. | 1183 // Get rid of touch slop. |
1176 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0), | 1184 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 0), |
1177 kTouchId, tes.Now()); | 1185 kTouchId, tes.Now()); |
1178 DispatchEventUsingWindowDispatcher(&move); | 1186 DispatchEventUsingWindowDispatcher(&move); |
1179 delegate->Reset(); | 1187 delegate->Reset(); |
1180 | 1188 |
1181 | 1189 |
1182 // Move the touch-point horizontally enough that it is considered a | 1190 // Move the touch-point horizontally enough that it is considered a |
1183 // horizontal scroll. | 1191 // horizontal scroll. |
1184 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); | 1192 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); |
1185 EXPECT_FLOAT_EQ(0, delegate->scroll_y()); | 1193 EXPECT_FLOAT_EQ(1, delegate->scroll_y()); |
1186 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); | 1194 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); |
| 1195 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Horizontal, |
| 1196 delegate->scroll_rail_state()); |
1187 | 1197 |
1188 // Get a high x velocity, while still staying on the rail | 1198 // Get a high x velocity, while still staying on the rail |
1189 const int kScrollAmount = 8; | 1199 const int kScrollAmount = 8; |
1190 tes.SendScrollEvents(event_processor(), | 1200 tes.SendScrollEvents(event_processor(), |
1191 1, | 1201 1, |
1192 1, | 1202 1, |
1193 100, | 1203 100, |
1194 10, | 1204 10, |
1195 kTouchId, | 1205 kTouchId, |
1196 1, | 1206 1, |
1197 kScrollAmount, | 1207 kScrollAmount, |
1198 delegate.get()); | 1208 delegate.get()); |
1199 | 1209 |
1200 delegate->Reset(); | 1210 delegate->Reset(); |
1201 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1211 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1202 kTouchId, tes.Now()); | 1212 kTouchId, tes.Now()); |
1203 DispatchEventUsingWindowDispatcher(&release); | 1213 DispatchEventUsingWindowDispatcher(&release); |
1204 | 1214 |
1205 EXPECT_TRUE(delegate->fling()); | 1215 EXPECT_TRUE(delegate->fling()); |
1206 EXPECT_FALSE(delegate->scroll_end()); | 1216 EXPECT_FALSE(delegate->scroll_end()); |
1207 EXPECT_GT(delegate->velocity_x(), 0); | 1217 EXPECT_GT(delegate->velocity_x(), 0); |
1208 EXPECT_EQ(0, delegate->velocity_y()); | 1218 EXPECT_GT(delegate->velocity_y(), 0); |
| 1219 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Horizontal, |
| 1220 delegate->scroll_rail_state()); |
1209 } | 1221 } |
1210 | 1222 |
1211 // Check Scroll End Events report correct velocities | 1223 // Check Scroll End Events report correct velocities |
1212 // if the user was on a vertical rail | 1224 // if the user was on a vertical rail |
1213 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { | 1225 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { |
1214 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1226 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1215 new GestureEventConsumeDelegate()); | 1227 new GestureEventConsumeDelegate()); |
1216 TimedEvents tes; | 1228 TimedEvents tes; |
1217 const int kTouchId = 7; | 1229 const int kTouchId = 7; |
1218 gfx::Rect bounds(0, 0, 1000, 1000); | 1230 gfx::Rect bounds(0, 0, 1000, 1000); |
1219 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1231 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1220 delegate.get(), -1234, bounds, root_window())); | 1232 delegate.get(), -1234, bounds, root_window())); |
1221 | 1233 |
1222 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 1234 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
1223 kTouchId, tes.Now()); | 1235 kTouchId, tes.Now()); |
1224 DispatchEventUsingWindowDispatcher(&press); | 1236 DispatchEventUsingWindowDispatcher(&press); |
1225 | 1237 |
1226 // Get rid of touch slop. | 1238 // Get rid of touch slop. |
1227 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 10), | 1239 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 10), |
1228 kTouchId, tes.Now()); | 1240 kTouchId, tes.Now()); |
1229 DispatchEventUsingWindowDispatcher(&move); | 1241 DispatchEventUsingWindowDispatcher(&move); |
1230 delegate->Reset(); | 1242 delegate->Reset(); |
1231 | 1243 |
1232 // Move the touch-point vertically enough that it is considered a | 1244 // Move the touch-point vertically enough that it is considered a |
1233 // vertical scroll. | 1245 // vertical scroll. |
1234 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get()); | 1246 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get()); |
1235 EXPECT_EQ(20, delegate->scroll_y()); | 1247 EXPECT_EQ(20, delegate->scroll_y()); |
1236 EXPECT_EQ(0, delegate->scroll_x()); | 1248 EXPECT_EQ(1, delegate->scroll_x()); |
1237 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1249 EXPECT_EQ(0, delegate->scroll_velocity_x()); |
| 1250 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Vertical, |
| 1251 delegate->scroll_rail_state()); |
1238 | 1252 |
1239 // Get a high y velocity, while still staying on the rail | 1253 // Get a high y velocity, while still staying on the rail |
1240 const int kScrollAmount = 8; | 1254 const int kScrollAmount = 8; |
1241 tes.SendScrollEvents(event_processor(), | 1255 tes.SendScrollEvents(event_processor(), |
1242 1, | 1256 1, |
1243 6, | 1257 6, |
1244 10, | 1258 10, |
1245 100, | 1259 100, |
1246 kTouchId, | 1260 kTouchId, |
1247 1, | 1261 1, |
1248 kScrollAmount, | 1262 kScrollAmount, |
1249 delegate.get()); | 1263 delegate.get()); |
1250 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1264 EXPECT_EQ(0, delegate->scroll_velocity_x()); |
1251 | 1265 |
1252 delegate->Reset(); | 1266 delegate->Reset(); |
1253 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206), | 1267 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206), |
1254 kTouchId, tes.Now()); | 1268 kTouchId, tes.Now()); |
1255 DispatchEventUsingWindowDispatcher(&release); | 1269 DispatchEventUsingWindowDispatcher(&release); |
1256 | 1270 |
1257 EXPECT_TRUE(delegate->fling()); | 1271 EXPECT_TRUE(delegate->fling()); |
1258 EXPECT_FALSE(delegate->scroll_end()); | 1272 EXPECT_FALSE(delegate->scroll_end()); |
1259 EXPECT_EQ(0, delegate->velocity_x()); | 1273 EXPECT_GT(delegate->velocity_x(), 0); |
1260 EXPECT_GT(delegate->velocity_y(), 0); | 1274 EXPECT_GT(delegate->velocity_y(), 0); |
| 1275 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Vertical, |
| 1276 delegate->scroll_rail_state()); |
1261 } | 1277 } |
1262 | 1278 |
1263 // Check Scroll End Events report non-zero velocities if the user is not on a | 1279 // Check Scroll End Events report non-zero velocities if the user is not on a |
1264 // rail | 1280 // rail |
1265 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { | 1281 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { |
1266 ui::GestureConfiguration::GetInstance() | 1282 ui::GestureConfiguration::GetInstance() |
1267 ->set_max_touch_move_in_pixels_for_click(0); | 1283 ->set_max_touch_move_in_pixels_for_click(0); |
1268 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1284 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1269 new GestureEventConsumeDelegate()); | 1285 new GestureEventConsumeDelegate()); |
1270 TimedEvents tes; | 1286 TimedEvents tes; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 | 1522 |
1507 // Move the touch-point horizontally enough that it is considered a | 1523 // Move the touch-point horizontally enough that it is considered a |
1508 // horizontal scroll. | 1524 // horizontal scroll. |
1509 tes.SendScrollEvent(event_processor(), 25, 0, kTouchId, delegate.get()); | 1525 tes.SendScrollEvent(event_processor(), 25, 0, kTouchId, delegate.get()); |
1510 EXPECT_EQ(0, delegate->scroll_y()); | 1526 EXPECT_EQ(0, delegate->scroll_y()); |
1511 EXPECT_EQ(20, delegate->scroll_x()); | 1527 EXPECT_EQ(20, delegate->scroll_x()); |
1512 | 1528 |
1513 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get()); | 1529 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get()); |
1514 EXPECT_TRUE(delegate->scroll_update()); | 1530 EXPECT_TRUE(delegate->scroll_update()); |
1515 EXPECT_EQ(5, delegate->scroll_x()); | 1531 EXPECT_EQ(5, delegate->scroll_x()); |
1516 // y shouldn't change, as we're on a horizontal rail. | 1532 EXPECT_EQ(6, delegate->scroll_y()); |
1517 EXPECT_EQ(0, delegate->scroll_y()); | 1533 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Horizontal, |
| 1534 delegate->scroll_rail_state()); |
1518 | 1535 |
1519 // Send enough information that a velocity can be calculated for the gesture, | 1536 // Send enough information that a velocity can be calculated for the gesture, |
1520 // and we can break the rail | 1537 // and we can break the rail |
1521 const int kScrollAmount = 8; | 1538 const int kScrollAmount = 8; |
1522 tes.SendScrollEvents(event_processor(), | 1539 tes.SendScrollEvents(event_processor(), |
1523 1, | 1540 1, |
1524 1, | 1541 1, |
1525 6, | 1542 6, |
1526 100, | 1543 100, |
1527 kTouchId, | 1544 kTouchId, |
1528 1, | 1545 1, |
1529 kScrollAmount, | 1546 kScrollAmount, |
1530 delegate.get()); | 1547 delegate.get()); |
1531 | 1548 |
1532 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get()); | 1549 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get()); |
1533 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get()); | 1550 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get()); |
1534 | 1551 |
1535 // The rail should be broken | 1552 // The rail should be broken |
1536 EXPECT_TRUE(delegate->scroll_update()); | 1553 EXPECT_TRUE(delegate->scroll_update()); |
1537 EXPECT_EQ(5, delegate->scroll_x()); | 1554 EXPECT_EQ(5, delegate->scroll_x()); |
1538 EXPECT_EQ(5, delegate->scroll_y()); | 1555 EXPECT_EQ(5, delegate->scroll_y()); |
| 1556 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Free, |
| 1557 delegate->scroll_rail_state()); |
1539 } | 1558 } |
1540 | 1559 |
1541 // Check that vertical scroll gestures cause scrolls on vertical rails. | 1560 // Check that vertical scroll gestures cause scrolls on vertical rails. |
1542 // Also tests that vertical rails can be broken. | 1561 // Also tests that vertical rails can be broken. |
1543 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { | 1562 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { |
1544 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1563 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1545 new GestureEventConsumeDelegate()); | 1564 new GestureEventConsumeDelegate()); |
1546 TimedEvents tes; | 1565 TimedEvents tes; |
1547 const int kTouchId = 7; | 1566 const int kTouchId = 7; |
1548 gfx::Rect bounds(0, 0, 1000, 1000); | 1567 gfx::Rect bounds(0, 0, 1000, 1000); |
(...skipping 12 matching lines...) Expand all Loading... |
1561 | 1580 |
1562 // Move the touch-point vertically enough that it is considered a | 1581 // Move the touch-point vertically enough that it is considered a |
1563 // vertical scroll. | 1582 // vertical scroll. |
1564 tes.SendScrollEvent(event_processor(), 0, 25, kTouchId, delegate.get()); | 1583 tes.SendScrollEvent(event_processor(), 0, 25, kTouchId, delegate.get()); |
1565 EXPECT_EQ(0, delegate->scroll_x()); | 1584 EXPECT_EQ(0, delegate->scroll_x()); |
1566 EXPECT_EQ(20, delegate->scroll_y()); | 1585 EXPECT_EQ(20, delegate->scroll_y()); |
1567 | 1586 |
1568 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get()); | 1587 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get()); |
1569 EXPECT_TRUE(delegate->scroll_update()); | 1588 EXPECT_TRUE(delegate->scroll_update()); |
1570 EXPECT_EQ(5, delegate->scroll_y()); | 1589 EXPECT_EQ(5, delegate->scroll_y()); |
1571 // x shouldn't change, as we're on a vertical rail. | 1590 EXPECT_EQ(6, delegate->scroll_x()); |
1572 EXPECT_EQ(0, delegate->scroll_x()); | 1591 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Vertical, |
1573 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1592 delegate->scroll_rail_state()); |
1574 | 1593 |
1575 // Send enough information that a velocity can be calculated for the gesture, | 1594 // Send enough information that a velocity can be calculated for the gesture, |
1576 // and we can break the rail | 1595 // and we can break the rail |
1577 const int kScrollAmount = 8; | 1596 const int kScrollAmount = 8; |
1578 tes.SendScrollEvents(event_processor(), | 1597 tes.SendScrollEvents(event_processor(), |
1579 1, | 1598 1, |
1580 6, | 1599 6, |
1581 100, | 1600 100, |
1582 1, | 1601 1, |
1583 kTouchId, | 1602 kTouchId, |
1584 1, | 1603 1, |
1585 kScrollAmount, | 1604 kScrollAmount, |
1586 delegate.get()); | 1605 delegate.get()); |
1587 | 1606 |
1588 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get()); | 1607 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get()); |
1589 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get()); | 1608 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get()); |
1590 | 1609 |
1591 // The rail should be broken | 1610 // The rail should be broken |
1592 EXPECT_TRUE(delegate->scroll_update()); | 1611 EXPECT_TRUE(delegate->scroll_update()); |
1593 EXPECT_EQ(5, delegate->scroll_x()); | 1612 EXPECT_EQ(5, delegate->scroll_x()); |
1594 EXPECT_EQ(5, delegate->scroll_y()); | 1613 EXPECT_EQ(5, delegate->scroll_y()); |
| 1614 EXPECT_EQ(ui::GestureEventDetails::ScrollRailState::Free, |
| 1615 delegate->scroll_rail_state()); |
1595 } | 1616 } |
1596 | 1617 |
1597 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { | 1618 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { |
1598 // We'll start by moving the touch point by (5, 5). We want all of that | 1619 // We'll start by moving the touch point by (5, 5). We want all of that |
1599 // distance to be consumed by the slop, so we set the slop radius to | 1620 // distance to be consumed by the slop, so we set the slop radius to |
1600 // sqrt(5 * 5 + 5 * 5). | 1621 // sqrt(5 * 5 + 5 * 5). |
1601 ui::GestureConfiguration::GetInstance() | 1622 ui::GestureConfiguration::GetInstance() |
1602 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5)); | 1623 ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5)); |
1603 | 1624 |
1604 // First, tap. Then, do a scroll using the same touch-id. | 1625 // First, tap. Then, do a scroll using the same touch-id. |
(...skipping 2811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4416 // The synchronous ack is stuck behind the pending touch move. | 4437 // The synchronous ack is stuck behind the pending touch move. |
4417 EXPECT_0_EVENTS(delegate->events()); | 4438 EXPECT_0_EVENTS(delegate->events()); |
4418 | 4439 |
4419 delegate->ReceivedAck(); | 4440 delegate->ReceivedAck(); |
4420 EXPECT_2_EVENTS(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE, | 4441 EXPECT_2_EVENTS(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE, |
4421 ui::ET_GESTURE_SCROLL_UPDATE); | 4442 ui::ET_GESTURE_SCROLL_UPDATE); |
4422 } | 4443 } |
4423 | 4444 |
4424 } // namespace test | 4445 } // namespace test |
4425 } // namespace aura | 4446 } // namespace aura |
OLD | NEW |