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

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

Issue 9751011: Gesture recognition constants should all be stored in the GestureConfiguration object. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Protect unit tests from changes in GestureConfiguration. Created 8 years, 9 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
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/timer.h" 5 #include "base/timer.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/aura/event.h" 7 #include "ui/aura/event.h"
8 #include "ui/aura/gestures/gesture_configuration.h"
8 #include "ui/aura/gestures/gesture_recognizer_aura.h" 9 #include "ui/aura/gestures/gesture_recognizer_aura.h"
9 #include "ui/aura/gestures/gesture_sequence.h" 10 #include "ui/aura/gestures/gesture_sequence.h"
10 #include "ui/aura/root_window.h" 11 #include "ui/aura/root_window.h"
11 #include "ui/aura/test/aura_test_base.h" 12 #include "ui/aura/test/aura_test_base.h"
12 #include "ui/aura/test/test_window_delegate.h" 13 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/test/test_windows.h" 14 #include "ui/aura/test/test_windows.h"
14 #include "ui/base/hit_test.h" 15 #include "ui/base/hit_test.h"
15 #include "ui/gfx/point.h" 16 #include "ui/gfx/point.h"
16 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
17 18
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 void SendScrollEvent(RootWindow* root_window, 310 void SendScrollEvent(RootWindow* root_window,
310 int x, 311 int x,
311 int y, 312 int y,
312 int touch_id, 313 int touch_id,
313 GestureEventConsumeDelegate* delegate) { 314 GestureEventConsumeDelegate* delegate) {
314 delegate->Reset(); 315 delegate->Reset();
315 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id); 316 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id);
316 root_window->DispatchTouchEvent(&move); 317 root_window->DispatchTouchEvent(&move);
317 } 318 }
318 319
319 const int kBufferedPoints = 10;
320
321 } // namespace 320 } // namespace
322 321
323 typedef AuraTestBase GestureRecognizerTest; 322 typedef AuraTestBase GestureRecognizerTest;
324 323
325 // Check that appropriate touch events generate tap gesture events. 324 // Check that appropriate touch events generate tap gesture events.
326 TEST_F(GestureRecognizerTest, GestureEventTap) { 325 TEST_F(GestureRecognizerTest, GestureEventTap) {
327 scoped_ptr<GestureEventConsumeDelegate> delegate( 326 scoped_ptr<GestureEventConsumeDelegate> delegate(
328 new GestureEventConsumeDelegate()); 327 new GestureEventConsumeDelegate());
329 const int kWindowWidth = 123; 328 const int kWindowWidth = 123;
330 const int kWindowHeight = 45; 329 const int kWindowHeight = 45;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 root_window()->DispatchTouchEvent(&press); 446 root_window()->DispatchTouchEvent(&press);
448 447
449 // Move the touch-point horizontally enough that it is considered a 448 // Move the touch-point horizontally enough that it is considered a
450 // horizontal scroll. 449 // horizontal scroll.
451 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 450 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
452 EXPECT_EQ(0, delegate->scroll_y()); 451 EXPECT_EQ(0, delegate->scroll_y());
453 EXPECT_EQ(20, delegate->scroll_x()); 452 EXPECT_EQ(20, delegate->scroll_x());
454 453
455 // Get a high x velocity, while still staying on the rail 454 // Get a high x velocity, while still staying on the rail
456 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 455 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
457 100, 10, kTouchId, 1, kBufferedPoints, delegate.get()); 456 100, 10, kTouchId, 1,
457 GestureConfiguration::points_buffered_for_velocity(),
458 delegate.get());
458 459
459 delegate->Reset(); 460 delegate->Reset();
460 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); 461 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
461 root_window()->DispatchTouchEvent(&release); 462 root_window()->DispatchTouchEvent(&release);
462 463
463 EXPECT_TRUE(delegate->scroll_end()); 464 EXPECT_TRUE(delegate->scroll_end());
464 EXPECT_EQ(100000, delegate->velocity_x()); 465 EXPECT_EQ(100000, delegate->velocity_x());
465 EXPECT_EQ(0, delegate->velocity_y()); 466 EXPECT_EQ(0, delegate->velocity_y());
466 } 467 }
467 468
(...skipping 11 matching lines...) Expand all
479 root_window()->DispatchTouchEvent(&press); 480 root_window()->DispatchTouchEvent(&press);
480 481
481 // Move the touch-point vertically enough that it is considered a 482 // Move the touch-point vertically enough that it is considered a
482 // vertical scroll. 483 // vertical scroll.
483 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 484 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
484 EXPECT_EQ(20, delegate->scroll_y()); 485 EXPECT_EQ(20, delegate->scroll_y());
485 EXPECT_EQ(0, delegate->scroll_x()); 486 EXPECT_EQ(0, delegate->scroll_x());
486 487
487 // Get a high y velocity, while still staying on the rail 488 // Get a high y velocity, while still staying on the rail
488 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 489 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
489 10, 100, kTouchId, 1, kBufferedPoints, delegate.get()); 490 10, 100, kTouchId, 1,
491 GestureConfiguration::points_buffered_for_velocity(),
492 delegate.get());
490 493
491 delegate->Reset(); 494 delegate->Reset();
492 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); 495 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
493 root_window()->DispatchTouchEvent(&release); 496 root_window()->DispatchTouchEvent(&release);
494 497
495 EXPECT_TRUE(delegate->scroll_end()); 498 EXPECT_TRUE(delegate->scroll_end());
496 EXPECT_EQ(0, delegate->velocity_x()); 499 EXPECT_EQ(0, delegate->velocity_x());
497 EXPECT_EQ(100000, delegate->velocity_y()); 500 EXPECT_EQ(100000, delegate->velocity_y());
498 } 501 }
499 502
500 // Check Scroll End Events report correct velocities 503 // Check Scroll End Events report correct velocities
501 // if the user is not on a rail 504 // if the user is not on a rail
502 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { 505 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
503 scoped_ptr<GestureEventConsumeDelegate> delegate( 506 scoped_ptr<GestureEventConsumeDelegate> delegate(
504 new GestureEventConsumeDelegate()); 507 new GestureEventConsumeDelegate());
505 const int kTouchId = 7; 508 const int kTouchId = 7;
506 gfx::Rect bounds(0, 0, 1000, 1000); 509 gfx::Rect bounds(0, 0, 1000, 1000);
507 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 510 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
508 delegate.get(), -1234, bounds, NULL)); 511 delegate.get(), -1234, bounds, NULL));
509 512
510 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId); 513 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId);
511 root_window()->DispatchTouchEvent(&press); 514 root_window()->DispatchTouchEvent(&press);
512 515
513 // Move the touch-point such that a non-rail scroll begins 516 // Move the touch-point such that a non-rail scroll begins
514 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); 517 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get());
515 EXPECT_EQ(20, delegate->scroll_y()); 518 EXPECT_EQ(20, delegate->scroll_y());
516 EXPECT_EQ(20, delegate->scroll_x()); 519 EXPECT_EQ(20, delegate->scroll_x());
517 520
518 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 521 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
519 10, 100, kTouchId, 1, kBufferedPoints, delegate.get()); 522 10, 100, kTouchId, 1,
523 GestureConfiguration::points_buffered_for_velocity(),
524 delegate.get());
520 525
521 delegate->Reset(); 526 delegate->Reset();
522 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); 527 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
523 root_window()->DispatchTouchEvent(&release); 528 root_window()->DispatchTouchEvent(&release);
524 529
525 EXPECT_TRUE(delegate->scroll_end()); 530 EXPECT_TRUE(delegate->scroll_end());
526 EXPECT_EQ(10000, delegate->velocity_x()); 531 EXPECT_EQ(10000, delegate->velocity_x());
527 EXPECT_EQ(100000, delegate->velocity_y()); 532 EXPECT_EQ(100000, delegate->velocity_y());
528 } 533 }
529 534
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 679
675 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); 680 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get());
676 EXPECT_TRUE(delegate->scroll_update()); 681 EXPECT_TRUE(delegate->scroll_update());
677 EXPECT_EQ(5, delegate->scroll_x()); 682 EXPECT_EQ(5, delegate->scroll_x());
678 // y shouldn't change, as we're on a horizontal rail. 683 // y shouldn't change, as we're on a horizontal rail.
679 EXPECT_EQ(0, delegate->scroll_y()); 684 EXPECT_EQ(0, delegate->scroll_y());
680 685
681 // Send enough information that a velocity can be calculated for the gesture, 686 // Send enough information that a velocity can be calculated for the gesture,
682 // and we can break the rail 687 // and we can break the rail
683 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 688 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
684 1, 100, kTouchId, 1, kBufferedPoints, delegate.get()); 689 1, 100, kTouchId, 1,
690 GestureConfiguration::points_buffered_for_velocity(),
691 delegate.get());
685 692
686 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); 693 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
687 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); 694 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
688 695
689 // The rail should be broken 696 // The rail should be broken
690 EXPECT_TRUE(delegate->scroll_update()); 697 EXPECT_TRUE(delegate->scroll_update());
691 EXPECT_EQ(5, delegate->scroll_x()); 698 EXPECT_EQ(5, delegate->scroll_x());
692 EXPECT_EQ(5, delegate->scroll_y()); 699 EXPECT_EQ(5, delegate->scroll_y());
693 } 700 }
694 701
(...skipping 18 matching lines...) Expand all
713 720
714 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); 721 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get());
715 EXPECT_TRUE(delegate->scroll_update()); 722 EXPECT_TRUE(delegate->scroll_update());
716 EXPECT_EQ(5, delegate->scroll_y()); 723 EXPECT_EQ(5, delegate->scroll_y());
717 // x shouldn't change, as we're on a vertical rail. 724 // x shouldn't change, as we're on a vertical rail.
718 EXPECT_EQ(0, delegate->scroll_x()); 725 EXPECT_EQ(0, delegate->scroll_x());
719 726
720 // Send enough information that a velocity can be calculated for the gesture, 727 // Send enough information that a velocity can be calculated for the gesture,
721 // and we can break the rail 728 // and we can break the rail
722 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 729 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
723 100, 1, kTouchId, 1, kBufferedPoints, delegate.get()); 730 100, 1, kTouchId, 1,
731 GestureConfiguration::points_buffered_for_velocity(),
732 delegate.get());
724 733
725 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); 734 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
726 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); 735 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
727 736
728 // The rail should be broken 737 // The rail should be broken
729 EXPECT_TRUE(delegate->scroll_update()); 738 EXPECT_TRUE(delegate->scroll_update());
730 EXPECT_EQ(5, delegate->scroll_x()); 739 EXPECT_EQ(5, delegate->scroll_x());
731 EXPECT_EQ(5, delegate->scroll_y()); 740 EXPECT_EQ(5, delegate->scroll_y());
732 } 741 }
733 742
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 delegate->Reset(); 1249 delegate->Reset();
1241 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(100, 100), kTouchId1); 1250 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(100, 100), kTouchId1);
1242 1251
1243 root_window()->DispatchTouchEvent(&press1); 1252 root_window()->DispatchTouchEvent(&press1);
1244 1253
1245 delegate->Reset(); 1254 delegate->Reset();
1246 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(110, 110), kTouchId2); 1255 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(110, 110), kTouchId2);
1247 root_window()->DispatchTouchEvent(&press2); 1256 root_window()->DispatchTouchEvent(&press2);
1248 1257
1249 SendScrollEvents(root_window(), 100, 100, press1.time_stamp(), 1258 SendScrollEvents(root_window(), 100, 100, press1.time_stamp(),
1250 1, 10, kTouchId1, 1, kBufferedPoints, delegate.get()); 1259 1, 10, kTouchId1, 1,
1260 GestureConfiguration::points_buffered_for_velocity(),
1261 delegate.get());
1251 1262
1252 SendScrollEvents(root_window(), 110, 110, press1.time_stamp() + 1263 SendScrollEvents(root_window(), 110, 110, press1.time_stamp() +
1253 base::TimeDelta::FromMilliseconds(1000), 1264 base::TimeDelta::FromMilliseconds(1000),
1254 1, 10, kTouchId2, 1, kBufferedPoints, delegate.get()); 1265 1, 10, kTouchId2, 1,
1266 GestureConfiguration::points_buffered_for_velocity(),
1267 delegate.get());
1255 // At no point were both fingers moving at the same time, 1268 // At no point were both fingers moving at the same time,
1256 // so no scrolling should have occurred 1269 // so no scrolling should have occurred
1257 1270
1258 EXPECT_EQ(0, delegate->scroll_x()); 1271 EXPECT_EQ(0, delegate->scroll_x());
1259 EXPECT_EQ(0, delegate->scroll_y()); 1272 EXPECT_EQ(0, delegate->scroll_y());
1260 } 1273 }
1261 1274
1262 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { 1275 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
1263 scoped_ptr<GestureEventConsumeDelegate> delegate( 1276 scoped_ptr<GestureEventConsumeDelegate> delegate(
1264 new GestureEventConsumeDelegate()); 1277 new GestureEventConsumeDelegate());
1265 1278
1266 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 6); 1279 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 6);
1267 root_window()->DispatchTouchEvent(&release1); 1280 root_window()->DispatchTouchEvent(&release1);
1268 EXPECT_FALSE(delegate->tap()); 1281 EXPECT_FALSE(delegate->tap());
1269 EXPECT_FALSE(delegate->tap_down()); 1282 EXPECT_FALSE(delegate->tap_down());
1270 } 1283 }
1271 1284
1272 } // namespace test 1285 } // namespace test
1273 } // namespace aura 1286 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698