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

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

Issue 570633002: Remove unsupported parameters by the unified gesture detector from Gesture Configuration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | ui/aura/test/aura_test_base.cc » ('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/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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 628
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_min_touch_down_duration_in_seconds_for_click(
639 0.001);
640 ui::GestureConfiguration::set_show_press_delay_in_ms(2); 638 ui::GestureConfiguration::set_show_press_delay_in_ms(2);
641 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003); 639 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003);
642 } 640 }
643 641
644 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); 642 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest);
645 }; 643 };
646 644
647 // Check that appropriate touch events generate tap gesture events. 645 // Check that appropriate touch events generate tap gesture events.
648 TEST_F(GestureRecognizerTest, GestureEventTap) { 646 TEST_F(GestureRecognizerTest, GestureEventTap) {
649 scoped_ptr<GestureEventConsumeDelegate> delegate( 647 scoped_ptr<GestureEventConsumeDelegate> delegate(
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 tes.LeapForward(50)); 999 tes.LeapForward(50));
1002 DispatchEventUsingWindowDispatcher(&release); 1000 DispatchEventUsingWindowDispatcher(&release);
1003 EXPECT_2_EVENTS(delegate->events(), 1001 EXPECT_2_EVENTS(delegate->events(),
1004 ui::ET_SCROLL_FLING_START, 1002 ui::ET_SCROLL_FLING_START,
1005 ui::ET_GESTURE_END); 1003 ui::ET_GESTURE_END);
1006 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1004 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1007 } 1005 }
1008 1006
1009 // Check that predicted scroll update positions are correct. 1007 // Check that predicted scroll update positions are correct.
1010 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { 1008 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) {
1011 const double prediction_interval = 0.03; 1009 // 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 1010 // distance to be consumed by the slop, so we set the slop radius to
1015 // sqrt(5 * 5 + 5 * 5). 1011 // sqrt(5 * 5 + 5 * 5).
1016 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click( 1012 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
1017 sqrt(static_cast<double>(5 * 5 + 5 * 5))); 1013 sqrt(static_cast<double>(5 * 5 + 5 * 5)));
1018 1014
1019 scoped_ptr<GestureEventConsumeDelegate> delegate( 1015 scoped_ptr<GestureEventConsumeDelegate> delegate(
1020 new GestureEventConsumeDelegate()); 1016 new GestureEventConsumeDelegate());
1021 TimedEvents tes; 1017 TimedEvents tes;
1022 const int kWindowWidth = 123; 1018 const int kWindowWidth = 123;
1023 const int kWindowHeight = 45; 1019 const int kWindowHeight = 45;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 delegate->Reset(); 1155 delegate->Reset();
1160 1156
1161 1157
1162 // Move the touch-point horizontally enough that it is considered a 1158 // Move the touch-point horizontally enough that it is considered a
1163 // horizontal scroll. 1159 // horizontal scroll.
1164 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get()); 1160 tes.SendScrollEvent(event_processor(), 30, 1, kTouchId, delegate.get());
1165 EXPECT_FLOAT_EQ(0, delegate->scroll_y()); 1161 EXPECT_FLOAT_EQ(0, delegate->scroll_y());
1166 EXPECT_FLOAT_EQ(20, delegate->scroll_x()); 1162 EXPECT_FLOAT_EQ(20, delegate->scroll_x());
1167 1163
1168 // Get a high x velocity, while still staying on the rail 1164 // Get a high x velocity, while still staying on the rail
1169 tes.SendScrollEvents(event_processor(), 1, 1, 1165 const int kScrollAmount = 8;
1170 100, 10, kTouchId, 1, 1166 tes.SendScrollEvents(event_processor(),
1171 ui::GestureConfiguration::points_buffered_for_velocity(), 1167 1,
1172 delegate.get()); 1168 1,
1169 100,
1170 10,
1171 kTouchId,
1172 1,
1173 kScrollAmount,
1174 delegate.get());
1173 1175
1174 delegate->Reset(); 1176 delegate->Reset();
1175 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1177 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1176 kTouchId, tes.Now()); 1178 kTouchId, tes.Now());
1177 DispatchEventUsingWindowDispatcher(&release); 1179 DispatchEventUsingWindowDispatcher(&release);
1178 1180
1179 EXPECT_TRUE(delegate->fling()); 1181 EXPECT_TRUE(delegate->fling());
1180 EXPECT_FALSE(delegate->scroll_end()); 1182 EXPECT_FALSE(delegate->scroll_end());
1181 EXPECT_GT(delegate->velocity_x(), 0); 1183 EXPECT_GT(delegate->velocity_x(), 0);
1182 EXPECT_EQ(0, delegate->velocity_y()); 1184 EXPECT_EQ(0, delegate->velocity_y());
(...skipping 21 matching lines...) Expand all
1204 delegate->Reset(); 1206 delegate->Reset();
1205 1207
1206 // Move the touch-point vertically enough that it is considered a 1208 // Move the touch-point vertically enough that it is considered a
1207 // vertical scroll. 1209 // vertical scroll.
1208 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get()); 1210 tes.SendScrollEvent(event_processor(), 1, 30, kTouchId, delegate.get());
1209 EXPECT_EQ(20, delegate->scroll_y()); 1211 EXPECT_EQ(20, delegate->scroll_y());
1210 EXPECT_EQ(0, delegate->scroll_x()); 1212 EXPECT_EQ(0, delegate->scroll_x());
1211 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1213 EXPECT_EQ(0, delegate->scroll_velocity_x());
1212 1214
1213 // Get a high y velocity, while still staying on the rail 1215 // Get a high y velocity, while still staying on the rail
1214 tes.SendScrollEvents(event_processor(), 1, 6, 1216 const int kScrollAmount = 8;
1215 10, 100, kTouchId, 1, 1217 tes.SendScrollEvents(event_processor(),
1216 ui::GestureConfiguration::points_buffered_for_velocity(), 1218 1,
1219 6,
1220 10,
1221 100,
1222 kTouchId,
1223 1,
1224 kScrollAmount,
1217 delegate.get()); 1225 delegate.get());
1218 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1226 EXPECT_EQ(0, delegate->scroll_velocity_x());
1219 1227
1220 delegate->Reset(); 1228 delegate->Reset();
1221 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206), 1229 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 206),
1222 kTouchId, tes.Now()); 1230 kTouchId, tes.Now());
1223 DispatchEventUsingWindowDispatcher(&release); 1231 DispatchEventUsingWindowDispatcher(&release);
1224 1232
1225 EXPECT_TRUE(delegate->fling()); 1233 EXPECT_TRUE(delegate->fling());
1226 EXPECT_FALSE(delegate->scroll_end()); 1234 EXPECT_FALSE(delegate->scroll_end());
(...skipping 16 matching lines...) Expand all
1243 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1251 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1244 kTouchId, tes.Now()); 1252 kTouchId, tes.Now());
1245 DispatchEventUsingWindowDispatcher(&press); 1253 DispatchEventUsingWindowDispatcher(&press);
1246 1254
1247 // Move the touch-point such that a non-rail scroll begins, and we're outside 1255 // Move the touch-point such that a non-rail scroll begins, and we're outside
1248 // the snap channel for the unified GR. 1256 // the snap channel for the unified GR.
1249 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get()); 1257 tes.SendScrollEvent(event_processor(), 50, 50, kTouchId, delegate.get());
1250 EXPECT_EQ(50, delegate->scroll_y()); 1258 EXPECT_EQ(50, delegate->scroll_y());
1251 EXPECT_EQ(50, delegate->scroll_x()); 1259 EXPECT_EQ(50, delegate->scroll_x());
1252 1260
1253 tes.SendScrollEvents(event_processor(), 1, 1, 1261 const int kScrollAmount = 8;
1254 10, 100, kTouchId, 1, 1262 tes.SendScrollEvents(event_processor(),
1255 ui::GestureConfiguration::points_buffered_for_velocity(), 1263 1,
1264 1,
1265 10,
1266 100,
1267 kTouchId,
1268 1,
1269 kScrollAmount,
1256 delegate.get()); 1270 delegate.get());
1257 1271
1258 delegate->Reset(); 1272 delegate->Reset();
1259 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1273 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1260 kTouchId, tes.Now()); 1274 kTouchId, tes.Now());
1261 DispatchEventUsingWindowDispatcher(&release); 1275 DispatchEventUsingWindowDispatcher(&release);
1262 1276
1263 EXPECT_TRUE(delegate->fling()); 1277 EXPECT_TRUE(delegate->fling());
1264 EXPECT_FALSE(delegate->scroll_end()); 1278 EXPECT_FALSE(delegate->scroll_end());
1265 EXPECT_GT(delegate->velocity_x(), 0); 1279 EXPECT_GT(delegate->velocity_x(), 0);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 EXPECT_EQ(20, delegate->scroll_x()); 1486 EXPECT_EQ(20, delegate->scroll_x());
1473 1487
1474 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get()); 1488 tes.SendScrollEvent(event_processor(), 30, 6, kTouchId, delegate.get());
1475 EXPECT_TRUE(delegate->scroll_update()); 1489 EXPECT_TRUE(delegate->scroll_update());
1476 EXPECT_EQ(5, delegate->scroll_x()); 1490 EXPECT_EQ(5, delegate->scroll_x());
1477 // y shouldn't change, as we're on a horizontal rail. 1491 // y shouldn't change, as we're on a horizontal rail.
1478 EXPECT_EQ(0, delegate->scroll_y()); 1492 EXPECT_EQ(0, delegate->scroll_y());
1479 1493
1480 // Send enough information that a velocity can be calculated for the gesture, 1494 // Send enough information that a velocity can be calculated for the gesture,
1481 // and we can break the rail 1495 // and we can break the rail
1482 tes.SendScrollEvents(event_processor(), 1, 1, 1496 const int kScrollAmount = 8;
1483 6, 100, kTouchId, 1, 1497 tes.SendScrollEvents(event_processor(),
1484 ui::GestureConfiguration::points_buffered_for_velocity(), 1498 1,
1499 1,
1500 6,
1501 100,
1502 kTouchId,
1503 1,
1504 kScrollAmount,
1485 delegate.get()); 1505 delegate.get());
1486 1506
1487 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get()); 1507 tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get());
1488 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get()); 1508 tes.SendScrollEvent(event_processor(), 10, 5, kTouchId, delegate.get());
1489 1509
1490 // The rail should be broken 1510 // The rail should be broken
1491 EXPECT_TRUE(delegate->scroll_update()); 1511 EXPECT_TRUE(delegate->scroll_update());
1492 EXPECT_EQ(5, delegate->scroll_x()); 1512 EXPECT_EQ(5, delegate->scroll_x());
1493 EXPECT_EQ(5, delegate->scroll_y()); 1513 EXPECT_EQ(5, delegate->scroll_y());
1494 } 1514 }
(...skipping 27 matching lines...) Expand all
1522 1542
1523 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get()); 1543 tes.SendScrollEvent(event_processor(), 6, 30, kTouchId, delegate.get());
1524 EXPECT_TRUE(delegate->scroll_update()); 1544 EXPECT_TRUE(delegate->scroll_update());
1525 EXPECT_EQ(5, delegate->scroll_y()); 1545 EXPECT_EQ(5, delegate->scroll_y());
1526 // x shouldn't change, as we're on a vertical rail. 1546 // x shouldn't change, as we're on a vertical rail.
1527 EXPECT_EQ(0, delegate->scroll_x()); 1547 EXPECT_EQ(0, delegate->scroll_x());
1528 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1548 EXPECT_EQ(0, delegate->scroll_velocity_x());
1529 1549
1530 // Send enough information that a velocity can be calculated for the gesture, 1550 // Send enough information that a velocity can be calculated for the gesture,
1531 // and we can break the rail 1551 // and we can break the rail
1532 tes.SendScrollEvents(event_processor(), 1, 6, 1552 const int kScrollAmount = 8;
1533 100, 1, kTouchId, 1, 1553 tes.SendScrollEvents(event_processor(),
1534 ui::GestureConfiguration::points_buffered_for_velocity(), 1554 1,
1555 6,
1556 100,
1557 1,
1558 kTouchId,
1559 1,
1560 kScrollAmount,
1535 delegate.get()); 1561 delegate.get());
1536 1562
1537 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get()); 1563 tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get());
1538 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get()); 1564 tes.SendScrollEvent(event_processor(), 5, 10, kTouchId, delegate.get());
1539 1565
1540 // The rail should be broken 1566 // The rail should be broken
1541 EXPECT_TRUE(delegate->scroll_update()); 1567 EXPECT_TRUE(delegate->scroll_update());
1542 EXPECT_EQ(5, delegate->scroll_x()); 1568 EXPECT_EQ(5, delegate->scroll_x());
1543 EXPECT_EQ(5, delegate->scroll_y()); 1569 EXPECT_EQ(5, delegate->scroll_y());
1544 } 1570 }
(...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after
3428 EXPECT_FALSE(delegate->scroll_update()); 3454 EXPECT_FALSE(delegate->scroll_update());
3429 EXPECT_FALSE(delegate->pinch_update()); 3455 EXPECT_FALSE(delegate->pinch_update());
3430 3456
3431 delegate->Reset(); 3457 delegate->Reset();
3432 } 3458 }
3433 3459
3434 // Checks that slow scrolls deliver the correct deltas. 3460 // Checks that slow scrolls deliver the correct deltas.
3435 // In particular, fix for http;//crbug.com/150573. 3461 // In particular, fix for http;//crbug.com/150573.
3436 TEST_F(GestureRecognizerTest, NoDriftInScroll) { 3462 TEST_F(GestureRecognizerTest, NoDriftInScroll) {
3437 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); 3463 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( 3464 scoped_ptr<GestureEventConsumeDelegate> delegate(
3440 new GestureEventConsumeDelegate()); 3465 new GestureEventConsumeDelegate());
3441 const int kWindowWidth = 234; 3466 const int kWindowWidth = 234;
3442 const int kWindowHeight = 345; 3467 const int kWindowHeight = 345;
3443 const int kTouchId = 5; 3468 const int kTouchId = 5;
3444 TimedEvents tes; 3469 TimedEvents tes;
3445 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3470 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3446 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3471 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3447 delegate.get(), -1234, bounds, root_window())); 3472 delegate.get(), -1234, bounds, root_window()));
3448 3473
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
4278 ui::TouchEvent move3( 4303 ui::TouchEvent move3(
4279 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); 4304 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now());
4280 DispatchEventUsingWindowDispatcher(&move3); 4305 DispatchEventUsingWindowDispatcher(&move3);
4281 4306
4282 delegate->ReceivedAck(); 4307 delegate->ReceivedAck();
4283 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 4308 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
4284 } 4309 }
4285 4310
4286 } // namespace test 4311 } // namespace test
4287 } // namespace aura 4312 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/aura/test/aura_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698