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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 float x_start, | 493 float x_start, |
494 float y_start, | 494 float y_start, |
495 int dx, | 495 int dx, |
496 int dy, | 496 int dy, |
497 int touch_id, | 497 int touch_id, |
498 int time_step, | 498 int time_step, |
499 int num_steps, | 499 int num_steps, |
500 GestureEventConsumeDelegate* delegate) { | 500 GestureEventConsumeDelegate* delegate) { |
501 int x = x_start; | 501 int x = x_start; |
502 int y = y_start; | 502 int y = y_start; |
503 | |
tdresser
2014/09/12 18:39:57
Might as well leave this space here.
lanwei
2014/09/12 18:47:49
Done.
| |
504 for (int i = 0; i < num_steps; i++) { | 503 for (int i = 0; i < num_steps; i++) { |
505 x += dx; | 504 x += dx; |
506 y += dy; | 505 y += dy; |
507 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::PointF(x, y), | 506 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::PointF(x, y), |
508 touch_id, | 507 touch_id, |
509 base::TimeDelta::FromMilliseconds(simulated_now_)); | 508 base::TimeDelta::FromMilliseconds(simulated_now_)); |
510 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); | 509 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); |
511 ASSERT_FALSE(details.dispatcher_destroyed); | 510 ASSERT_FALSE(details.dispatcher_destroyed); |
512 simulated_now_ += time_step; | 511 simulated_now_ += time_step; |
513 } | 512 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 | 627 |
629 } // namespace | 628 } // namespace |
630 | 629 |
631 class GestureRecognizerTest : public AuraTestBase, | 630 class GestureRecognizerTest : public AuraTestBase, |
632 public ::testing::WithParamInterface<bool> { | 631 public ::testing::WithParamInterface<bool> { |
633 public: | 632 public: |
634 GestureRecognizerTest() {} | 633 GestureRecognizerTest() {} |
635 | 634 |
636 virtual void SetUp() OVERRIDE { | 635 virtual void SetUp() OVERRIDE { |
637 AuraTestBase::SetUp(); | 636 AuraTestBase::SetUp(); |
638 ui::GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click( | |
639 0.001); | |
640 ui::GestureConfiguration::set_show_press_delay_in_ms(2); | 637 ui::GestureConfiguration::set_show_press_delay_in_ms(2); |
641 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003); | 638 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003); |
642 } | 639 } |
643 | 640 |
644 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); | 641 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); |
645 }; | 642 }; |
646 | 643 |
647 // Check that appropriate touch events generate tap gesture events. | 644 // Check that appropriate touch events generate tap gesture events. |
648 TEST_F(GestureRecognizerTest, GestureEventTap) { | 645 TEST_F(GestureRecognizerTest, GestureEventTap) { |
649 scoped_ptr<GestureEventConsumeDelegate> delegate( | 646 scoped_ptr<GestureEventConsumeDelegate> delegate( |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 tes.LeapForward(50)); | 998 tes.LeapForward(50)); |
1002 DispatchEventUsingWindowDispatcher(&release); | 999 DispatchEventUsingWindowDispatcher(&release); |
1003 EXPECT_2_EVENTS(delegate->events(), | 1000 EXPECT_2_EVENTS(delegate->events(), |
1004 ui::ET_SCROLL_FLING_START, | 1001 ui::ET_SCROLL_FLING_START, |
1005 ui::ET_GESTURE_END); | 1002 ui::ET_GESTURE_END); |
1006 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 1003 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
1007 } | 1004 } |
1008 | 1005 |
1009 // Check that predicted scroll update positions are correct. | 1006 // Check that predicted scroll update positions are correct. |
1010 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { | 1007 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { |
1011 const double prediction_interval = 0.03; | 1008 // We'll start by moving the touch point by (5, 5). We want all of that |
1012 ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval); | |
1013 // We'll start by moving the touch point by (5, 5). We want all of that | |
1014 // distance to be consumed by the slop, so we set the slop radius to | 1009 // distance to be consumed by the slop, so we set the slop radius to |
1015 // sqrt(5 * 5 + 5 * 5). | 1010 // sqrt(5 * 5 + 5 * 5). |
1016 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | 1011 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( |
1017 sqrt(static_cast<double>(5 * 5 + 5 * 5))); | 1012 sqrt(static_cast<double>(5 * 5 + 5 * 5))); |
1018 | 1013 |
1019 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1014 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1020 new GestureEventConsumeDelegate()); | 1015 new GestureEventConsumeDelegate()); |
1021 TimedEvents tes; | 1016 TimedEvents tes; |
1022 const int kWindowWidth = 123; | 1017 const int kWindowWidth = 123; |
1023 const int kWindowHeight = 45; | 1018 const int kWindowHeight = 45; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1159 delegate->Reset(); | 1154 delegate->Reset(); |
1160 | 1155 |
1161 | 1156 |
1162 // Move the touch-point horizontally enough that it is considered a | 1157 // Move the touch-point horizontally enough that it is considered a |
1163 // horizontal scroll. | 1158 // horizontal scroll. |
1164 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); | 1159 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); |
1165 EXPECT_FLOAT_EQ(0, delegate->scroll_y()); | 1160 EXPECT_FLOAT_EQ(0, delegate->scroll_y()); |
1166 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); | 1161 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); |
1167 | 1162 |
1168 // Get a high x velocity, while still staying on the rail | 1163 // Get a high x velocity, while still staying on the rail |
1169 tes.SendScrollEvents(event_processor(), 1, 1, | 1164 const int kScrollAmount = 8; |
1170 100, 10, kTouchId, 1, | 1165 tes.SendScrollEvents(event_processor(), |
1171 ui::GestureConfiguration::points_buffered_for_velocity(), | 1166 1, |
1172 delegate.get()); | 1167 1, |
1168 100, | |
1169 10, | |
1170 kTouchId, | |
1171 1, | |
1172 kScrollAmount, | |
1173 delegate.get()); | |
1173 | 1174 |
1174 delegate->Reset(); | 1175 delegate->Reset(); |
1175 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1176 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1176 kTouchId, tes.Now()); | 1177 kTouchId, tes.Now()); |
1177 DispatchEventUsingWindowDispatcher(&release); | 1178 DispatchEventUsingWindowDispatcher(&release); |
1178 | 1179 |
1179 EXPECT_TRUE(delegate->fling()); | 1180 EXPECT_TRUE(delegate->fling()); |
1180 EXPECT_FALSE(delegate->scroll_end()); | 1181 EXPECT_FALSE(delegate->scroll_end()); |
1181 EXPECT_GT(delegate->velocity_x(), 0); | 1182 EXPECT_GT(delegate->velocity_x(), 0); |
1182 EXPECT_EQ(0, delegate->velocity_y()); | 1183 EXPECT_EQ(0, delegate->velocity_y()); |
(...skipping 21 matching lines...) Expand all Loading... | |
1204 delegate->Reset(); | 1205 delegate->Reset(); |
1205 | 1206 |
1206 // Move the touch-point vertically enough that it is considered a | 1207 // Move the touch-point vertically enough that it is considered a |
1207 // vertical scroll. | 1208 // vertical scroll. |
1208 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get()); | 1209 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get()); |
1209 EXPECT_EQ(20, delegate->scroll_y()); | 1210 EXPECT_EQ(20, delegate->scroll_y()); |
1210 EXPECT_EQ(0, delegate->scroll_x()); | 1211 EXPECT_EQ(0, delegate->scroll_x()); |
1211 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1212 EXPECT_EQ(0, delegate->scroll_velocity_x()); |
1212 | 1213 |
1213 // Get a high y velocity, while still staying on the rail | 1214 // Get a high y velocity, while still staying on the rail |
1214 tes.SendScrollEvents(event_processor(), 1, 6, | 1215 const int kScrollAmount = 8; |
1215 10, 100, kTouchId, 1, | 1216 tes.SendScrollEvents(event_processor(), |
1216 ui::GestureConfiguration::points_buffered_for_velocity(), | 1217 1, |
1218 6, | |
1219 10, | |
1220 100, | |
1221 kTouchId, | |
1222 1, | |
1223 kScrollAmount, | |
1217 delegate.get()); | 1224 delegate.get()); |
1218 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1225 EXPECT_EQ(0, delegate->scroll_velocity_x()); |
1219 | 1226 |
1220 delegate->Reset(); | 1227 delegate->Reset(); |
1221 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206), | 1228 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206), |
1222 kTouchId, tes.Now()); | 1229 kTouchId, tes.Now()); |
1223 DispatchEventUsingWindowDispatcher(&release); | 1230 DispatchEventUsingWindowDispatcher(&release); |
1224 | 1231 |
1225 EXPECT_TRUE(delegate->fling()); | 1232 EXPECT_TRUE(delegate->fling()); |
1226 EXPECT_FALSE(delegate->scroll_end()); | 1233 EXPECT_FALSE(delegate->scroll_end()); |
(...skipping 16 matching lines...) Expand all Loading... | |
1243 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 1250 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
1244 kTouchId, tes.Now()); | 1251 kTouchId, tes.Now()); |
1245 DispatchEventUsingWindowDispatcher(&press); | 1252 DispatchEventUsingWindowDispatcher(&press); |
1246 | 1253 |
1247 // Move the touch-point such that a non-rail scroll begins, and we're outside | 1254 // Move the touch-point such that a non-rail scroll begins, and we're outside |
1248 // the snap channel for the unified GR. | 1255 // the snap channel for the unified GR. |
1249 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get()); | 1256 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get()); |
1250 EXPECT_EQ(50, delegate->scroll_y()); | 1257 EXPECT_EQ(50, delegate->scroll_y()); |
1251 EXPECT_EQ(50, delegate->scroll_x()); | 1258 EXPECT_EQ(50, delegate->scroll_x()); |
1252 | 1259 |
1253 tes.SendScrollEvents(event_processor(), 1, 1, | 1260 const int kScrollAmount = 8; |
1254 10, 100, kTouchId, 1, | 1261 tes.SendScrollEvents(event_processor(), |
1255 ui::GestureConfiguration::points_buffered_for_velocity(), | 1262 1, |
1263 1, | |
1264 10, | |
1265 100, | |
1266 kTouchId, | |
1267 1, | |
1268 kScrollAmount, | |
1256 delegate.get()); | 1269 delegate.get()); |
1257 | 1270 |
1258 delegate->Reset(); | 1271 delegate->Reset(); |
1259 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1272 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1260 kTouchId, tes.Now()); | 1273 kTouchId, tes.Now()); |
1261 DispatchEventUsingWindowDispatcher(&release); | 1274 DispatchEventUsingWindowDispatcher(&release); |
1262 | 1275 |
1263 EXPECT_TRUE(delegate->fling()); | 1276 EXPECT_TRUE(delegate->fling()); |
1264 EXPECT_FALSE(delegate->scroll_end()); | 1277 EXPECT_FALSE(delegate->scroll_end()); |
1265 EXPECT_GT(delegate->velocity_x(), 0); | 1278 EXPECT_GT(delegate->velocity_x(), 0); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 EXPECT_EQ(20, delegate->scroll_x()); | 1485 EXPECT_EQ(20, delegate->scroll_x()); |
1473 | 1486 |
1474 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get()); | 1487 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get()); |
1475 EXPECT_TRUE(delegate->scroll_update()); | 1488 EXPECT_TRUE(delegate->scroll_update()); |
1476 EXPECT_EQ(5, delegate->scroll_x()); | 1489 EXPECT_EQ(5, delegate->scroll_x()); |
1477 // y shouldn't change, as we're on a horizontal rail. | 1490 // y shouldn't change, as we're on a horizontal rail. |
1478 EXPECT_EQ(0, delegate->scroll_y()); | 1491 EXPECT_EQ(0, delegate->scroll_y()); |
1479 | 1492 |
1480 // Send enough information that a velocity can be calculated for the gesture, | 1493 // Send enough information that a velocity can be calculated for the gesture, |
1481 // and we can break the rail | 1494 // and we can break the rail |
1482 tes.SendScrollEvents(event_processor(), 1, 1, | 1495 const int kScrollAmount = 8; |
1483 6, 100, kTouchId, 1, | 1496 tes.SendScrollEvents(event_processor(), |
1484 ui::GestureConfiguration::points_buffered_for_velocity(), | 1497 1, |
1498 1, | |
1499 6, | |
1500 100, | |
1501 kTouchId, | |
1502 1, | |
1503 kScrollAmount, | |
1485 delegate.get()); | 1504 delegate.get()); |
1486 | 1505 |
1487 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get()); | 1506 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get()); |
1488 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get()); | 1507 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get()); |
1489 | 1508 |
1490 // The rail should be broken | 1509 // The rail should be broken |
1491 EXPECT_TRUE(delegate->scroll_update()); | 1510 EXPECT_TRUE(delegate->scroll_update()); |
1492 EXPECT_EQ(5, delegate->scroll_x()); | 1511 EXPECT_EQ(5, delegate->scroll_x()); |
1493 EXPECT_EQ(5, delegate->scroll_y()); | 1512 EXPECT_EQ(5, delegate->scroll_y()); |
1494 } | 1513 } |
(...skipping 27 matching lines...) Expand all Loading... | |
1522 | 1541 |
1523 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get()); | 1542 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get()); |
1524 EXPECT_TRUE(delegate->scroll_update()); | 1543 EXPECT_TRUE(delegate->scroll_update()); |
1525 EXPECT_EQ(5, delegate->scroll_y()); | 1544 EXPECT_EQ(5, delegate->scroll_y()); |
1526 // x shouldn't change, as we're on a vertical rail. | 1545 // x shouldn't change, as we're on a vertical rail. |
1527 EXPECT_EQ(0, delegate->scroll_x()); | 1546 EXPECT_EQ(0, delegate->scroll_x()); |
1528 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1547 EXPECT_EQ(0, delegate->scroll_velocity_x()); |
1529 | 1548 |
1530 // Send enough information that a velocity can be calculated for the gesture, | 1549 // Send enough information that a velocity can be calculated for the gesture, |
1531 // and we can break the rail | 1550 // and we can break the rail |
1532 tes.SendScrollEvents(event_processor(), 1, 6, | 1551 const int kScrollAmount = 8; |
1533 100, 1, kTouchId, 1, | 1552 tes.SendScrollEvents(event_processor(), |
1534 ui::GestureConfiguration::points_buffered_for_velocity(), | 1553 1, |
1554 6, | |
1555 100, | |
1556 1, | |
1557 kTouchId, | |
1558 1, | |
1559 kScrollAmount, | |
1535 delegate.get()); | 1560 delegate.get()); |
1536 | 1561 |
1537 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get()); | 1562 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get()); |
1538 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get()); | 1563 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get()); |
1539 | 1564 |
1540 // The rail should be broken | 1565 // The rail should be broken |
1541 EXPECT_TRUE(delegate->scroll_update()); | 1566 EXPECT_TRUE(delegate->scroll_update()); |
1542 EXPECT_EQ(5, delegate->scroll_x()); | 1567 EXPECT_EQ(5, delegate->scroll_x()); |
1543 EXPECT_EQ(5, delegate->scroll_y()); | 1568 EXPECT_EQ(5, delegate->scroll_y()); |
1544 } | 1569 } |
(...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3428 EXPECT_FALSE(delegate->scroll_update()); | 3453 EXPECT_FALSE(delegate->scroll_update()); |
3429 EXPECT_FALSE(delegate->pinch_update()); | 3454 EXPECT_FALSE(delegate->pinch_update()); |
3430 | 3455 |
3431 delegate->Reset(); | 3456 delegate->Reset(); |
3432 } | 3457 } |
3433 | 3458 |
3434 // Checks that slow scrolls deliver the correct deltas. | 3459 // Checks that slow scrolls deliver the correct deltas. |
3435 // In particular, fix for http;//crbug.com/150573. | 3460 // In particular, fix for http;//crbug.com/150573. |
3436 TEST_F(GestureRecognizerTest, NoDriftInScroll) { | 3461 TEST_F(GestureRecognizerTest, NoDriftInScroll) { |
3437 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); | 3462 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); |
3438 ui::GestureConfiguration::set_min_scroll_delta_squared(9); | |
3439 scoped_ptr<GestureEventConsumeDelegate> delegate( | 3463 scoped_ptr<GestureEventConsumeDelegate> delegate( |
3440 new GestureEventConsumeDelegate()); | 3464 new GestureEventConsumeDelegate()); |
3441 const int kWindowWidth = 234; | 3465 const int kWindowWidth = 234; |
3442 const int kWindowHeight = 345; | 3466 const int kWindowHeight = 345; |
3443 const int kTouchId = 5; | 3467 const int kTouchId = 5; |
3444 TimedEvents tes; | 3468 TimedEvents tes; |
3445 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 3469 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
3446 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 3470 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
3447 delegate.get(), -1234, bounds, root_window())); | 3471 delegate.get(), -1234, bounds, root_window())); |
3448 | 3472 |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4278 ui::TouchEvent move3( | 4302 ui::TouchEvent move3( |
4279 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); | 4303 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); |
4280 DispatchEventUsingWindowDispatcher(&move3); | 4304 DispatchEventUsingWindowDispatcher(&move3); |
4281 | 4305 |
4282 delegate->ReceivedAck(); | 4306 delegate->ReceivedAck(); |
4283 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); | 4307 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); |
4284 } | 4308 } |
4285 | 4309 |
4286 } // namespace test | 4310 } // namespace test |
4287 } // namespace aura | 4311 } // namespace aura |
OLD | NEW |