| 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/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
| 6 #include "base/timer.h" | 6 #include "base/timer.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/aura/event.h" | 8 #include "ui/aura/event.h" |
| 9 #include "ui/aura/gestures/gesture_configuration.h" | 9 #include "ui/aura/gestures/gesture_configuration.h" |
| 10 #include "ui/aura/gestures/gesture_recognizer_aura.h" | 10 #include "ui/aura/gestures/gesture_recognizer_aura.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 void SendScrollEvent(RootWindow* root_window, | 313 void SendScrollEvent(RootWindow* root_window, |
| 314 int x, | 314 int x, |
| 315 int y, | 315 int y, |
| 316 int touch_id, | 316 int touch_id, |
| 317 GestureEventConsumeDelegate* delegate) { | 317 GestureEventConsumeDelegate* delegate) { |
| 318 delegate->Reset(); | 318 delegate->Reset(); |
| 319 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id); | 319 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id); |
| 320 root_window->DispatchTouchEvent(&move); | 320 root_window->DispatchTouchEvent(&move); |
| 321 } | 321 } |
| 322 | 322 |
| 323 const int kBufferedPoints = 10; | |
| 324 | |
| 325 } // namespace | 323 } // namespace |
| 326 | 324 |
| 327 typedef AuraTestBase GestureRecognizerTest; | 325 typedef AuraTestBase GestureRecognizerTest; |
| 328 | 326 |
| 329 // Check that appropriate touch events generate tap gesture events. | 327 // Check that appropriate touch events generate tap gesture events. |
| 330 TEST_F(GestureRecognizerTest, GestureEventTap) { | 328 TEST_F(GestureRecognizerTest, GestureEventTap) { |
| 331 scoped_ptr<GestureEventConsumeDelegate> delegate( | 329 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 332 new GestureEventConsumeDelegate()); | 330 new GestureEventConsumeDelegate()); |
| 333 const int kWindowWidth = 123; | 331 const int kWindowWidth = 123; |
| 334 const int kWindowHeight = 45; | 332 const int kWindowHeight = 45; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 root_window()->DispatchTouchEvent(&press); | 449 root_window()->DispatchTouchEvent(&press); |
| 452 | 450 |
| 453 // Move the touch-point horizontally enough that it is considered a | 451 // Move the touch-point horizontally enough that it is considered a |
| 454 // horizontal scroll. | 452 // horizontal scroll. |
| 455 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); | 453 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); |
| 456 EXPECT_EQ(0, delegate->scroll_y()); | 454 EXPECT_EQ(0, delegate->scroll_y()); |
| 457 EXPECT_EQ(20, delegate->scroll_x()); | 455 EXPECT_EQ(20, delegate->scroll_x()); |
| 458 | 456 |
| 459 // Get a high x velocity, while still staying on the rail | 457 // Get a high x velocity, while still staying on the rail |
| 460 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 458 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
| 461 100, 10, kTouchId, 1, kBufferedPoints, delegate.get()); | 459 100, 10, kTouchId, 1, |
| 460 GestureConfiguration::points_buffered_for_velocity(), |
| 461 delegate.get()); |
| 462 | 462 |
| 463 delegate->Reset(); | 463 delegate->Reset(); |
| 464 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); | 464 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); |
| 465 root_window()->DispatchTouchEvent(&release); | 465 root_window()->DispatchTouchEvent(&release); |
| 466 | 466 |
| 467 EXPECT_TRUE(delegate->scroll_end()); | 467 EXPECT_TRUE(delegate->scroll_end()); |
| 468 EXPECT_EQ(100000, delegate->velocity_x()); | 468 EXPECT_EQ(100000, delegate->velocity_x()); |
| 469 EXPECT_EQ(0, delegate->velocity_y()); | 469 EXPECT_EQ(0, delegate->velocity_y()); |
| 470 } | 470 } |
| 471 | 471 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 483 root_window()->DispatchTouchEvent(&press); | 483 root_window()->DispatchTouchEvent(&press); |
| 484 | 484 |
| 485 // Move the touch-point vertically enough that it is considered a | 485 // Move the touch-point vertically enough that it is considered a |
| 486 // vertical scroll. | 486 // vertical scroll. |
| 487 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); | 487 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); |
| 488 EXPECT_EQ(20, delegate->scroll_y()); | 488 EXPECT_EQ(20, delegate->scroll_y()); |
| 489 EXPECT_EQ(0, delegate->scroll_x()); | 489 EXPECT_EQ(0, delegate->scroll_x()); |
| 490 | 490 |
| 491 // Get a high y velocity, while still staying on the rail | 491 // Get a high y velocity, while still staying on the rail |
| 492 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 492 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
| 493 10, 100, kTouchId, 1, kBufferedPoints, delegate.get()); | 493 10, 100, kTouchId, 1, |
| 494 GestureConfiguration::points_buffered_for_velocity(), |
| 495 delegate.get()); |
| 494 | 496 |
| 495 delegate->Reset(); | 497 delegate->Reset(); |
| 496 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); | 498 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); |
| 497 root_window()->DispatchTouchEvent(&release); | 499 root_window()->DispatchTouchEvent(&release); |
| 498 | 500 |
| 499 EXPECT_TRUE(delegate->scroll_end()); | 501 EXPECT_TRUE(delegate->scroll_end()); |
| 500 EXPECT_EQ(0, delegate->velocity_x()); | 502 EXPECT_EQ(0, delegate->velocity_x()); |
| 501 EXPECT_EQ(100000, delegate->velocity_y()); | 503 EXPECT_EQ(100000, delegate->velocity_y()); |
| 502 } | 504 } |
| 503 | 505 |
| 504 // Check Scroll End Events report correct velocities | 506 // Check Scroll End Events report correct velocities |
| 505 // if the user is not on a rail | 507 // if the user is not on a rail |
| 506 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { | 508 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { |
| 507 scoped_ptr<GestureEventConsumeDelegate> delegate( | 509 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 508 new GestureEventConsumeDelegate()); | 510 new GestureEventConsumeDelegate()); |
| 509 const int kTouchId = 7; | 511 const int kTouchId = 7; |
| 510 gfx::Rect bounds(0, 0, 1000, 1000); | 512 gfx::Rect bounds(0, 0, 1000, 1000); |
| 511 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 513 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 512 delegate.get(), -1234, bounds, NULL)); | 514 delegate.get(), -1234, bounds, NULL)); |
| 513 | 515 |
| 514 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId); | 516 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId); |
| 515 root_window()->DispatchTouchEvent(&press); | 517 root_window()->DispatchTouchEvent(&press); |
| 516 | 518 |
| 517 // Move the touch-point such that a non-rail scroll begins | 519 // Move the touch-point such that a non-rail scroll begins |
| 518 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); | 520 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); |
| 519 EXPECT_EQ(20, delegate->scroll_y()); | 521 EXPECT_EQ(20, delegate->scroll_y()); |
| 520 EXPECT_EQ(20, delegate->scroll_x()); | 522 EXPECT_EQ(20, delegate->scroll_x()); |
| 521 | 523 |
| 522 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 524 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
| 523 10, 100, kTouchId, 1, kBufferedPoints, delegate.get()); | 525 10, 100, kTouchId, 1, |
| 526 GestureConfiguration::points_buffered_for_velocity(), |
| 527 delegate.get()); |
| 524 | 528 |
| 525 delegate->Reset(); | 529 delegate->Reset(); |
| 526 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); | 530 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId); |
| 527 root_window()->DispatchTouchEvent(&release); | 531 root_window()->DispatchTouchEvent(&release); |
| 528 | 532 |
| 529 EXPECT_TRUE(delegate->scroll_end()); | 533 EXPECT_TRUE(delegate->scroll_end()); |
| 530 EXPECT_EQ(10000, delegate->velocity_x()); | 534 EXPECT_EQ(10000, delegate->velocity_x()); |
| 531 EXPECT_EQ(100000, delegate->velocity_y()); | 535 EXPECT_EQ(100000, delegate->velocity_y()); |
| 532 } | 536 } |
| 533 | 537 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 682 |
| 679 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); | 683 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); |
| 680 EXPECT_TRUE(delegate->scroll_update()); | 684 EXPECT_TRUE(delegate->scroll_update()); |
| 681 EXPECT_EQ(5, delegate->scroll_x()); | 685 EXPECT_EQ(5, delegate->scroll_x()); |
| 682 // y shouldn't change, as we're on a horizontal rail. | 686 // y shouldn't change, as we're on a horizontal rail. |
| 683 EXPECT_EQ(0, delegate->scroll_y()); | 687 EXPECT_EQ(0, delegate->scroll_y()); |
| 684 | 688 |
| 685 // Send enough information that a velocity can be calculated for the gesture, | 689 // Send enough information that a velocity can be calculated for the gesture, |
| 686 // and we can break the rail | 690 // and we can break the rail |
| 687 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 691 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
| 688 1, 100, kTouchId, 1, kBufferedPoints, delegate.get()); | 692 1, 100, kTouchId, 1, |
| 693 GestureConfiguration::points_buffered_for_velocity(), |
| 694 delegate.get()); |
| 689 | 695 |
| 690 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); | 696 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); |
| 691 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); | 697 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); |
| 692 | 698 |
| 693 // The rail should be broken | 699 // The rail should be broken |
| 694 EXPECT_TRUE(delegate->scroll_update()); | 700 EXPECT_TRUE(delegate->scroll_update()); |
| 695 EXPECT_EQ(5, delegate->scroll_x()); | 701 EXPECT_EQ(5, delegate->scroll_x()); |
| 696 EXPECT_EQ(5, delegate->scroll_y()); | 702 EXPECT_EQ(5, delegate->scroll_y()); |
| 697 } | 703 } |
| 698 | 704 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 717 | 723 |
| 718 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); | 724 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); |
| 719 EXPECT_TRUE(delegate->scroll_update()); | 725 EXPECT_TRUE(delegate->scroll_update()); |
| 720 EXPECT_EQ(5, delegate->scroll_y()); | 726 EXPECT_EQ(5, delegate->scroll_y()); |
| 721 // x shouldn't change, as we're on a vertical rail. | 727 // x shouldn't change, as we're on a vertical rail. |
| 722 EXPECT_EQ(0, delegate->scroll_x()); | 728 EXPECT_EQ(0, delegate->scroll_x()); |
| 723 | 729 |
| 724 // Send enough information that a velocity can be calculated for the gesture, | 730 // Send enough information that a velocity can be calculated for the gesture, |
| 725 // and we can break the rail | 731 // and we can break the rail |
| 726 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 732 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
| 727 100, 1, kTouchId, 1, kBufferedPoints, delegate.get()); | 733 100, 1, kTouchId, 1, |
| 734 GestureConfiguration::points_buffered_for_velocity(), |
| 735 delegate.get()); |
| 728 | 736 |
| 729 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); | 737 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); |
| 730 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); | 738 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); |
| 731 | 739 |
| 732 // The rail should be broken | 740 // The rail should be broken |
| 733 EXPECT_TRUE(delegate->scroll_update()); | 741 EXPECT_TRUE(delegate->scroll_update()); |
| 734 EXPECT_EQ(5, delegate->scroll_x()); | 742 EXPECT_EQ(5, delegate->scroll_x()); |
| 735 EXPECT_EQ(5, delegate->scroll_y()); | 743 EXPECT_EQ(5, delegate->scroll_y()); |
| 736 } | 744 } |
| 737 | 745 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 delegate->Reset(); | 1260 delegate->Reset(); |
| 1253 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(100, 100), kTouchId1); | 1261 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(100, 100), kTouchId1); |
| 1254 | 1262 |
| 1255 root_window()->DispatchTouchEvent(&press1); | 1263 root_window()->DispatchTouchEvent(&press1); |
| 1256 | 1264 |
| 1257 delegate->Reset(); | 1265 delegate->Reset(); |
| 1258 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(110, 110), kTouchId2); | 1266 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(110, 110), kTouchId2); |
| 1259 root_window()->DispatchTouchEvent(&press2); | 1267 root_window()->DispatchTouchEvent(&press2); |
| 1260 | 1268 |
| 1261 SendScrollEvents(root_window(), 100, 100, press1.time_stamp(), | 1269 SendScrollEvents(root_window(), 100, 100, press1.time_stamp(), |
| 1262 1, 10, kTouchId1, 1, kBufferedPoints, delegate.get()); | 1270 1, 10, kTouchId1, 1, |
| 1271 GestureConfiguration::points_buffered_for_velocity(), |
| 1272 delegate.get()); |
| 1263 | 1273 |
| 1264 SendScrollEvents(root_window(), 110, 110, press1.time_stamp() + | 1274 SendScrollEvents(root_window(), 110, 110, press1.time_stamp() + |
| 1265 base::TimeDelta::FromMilliseconds(1000), | 1275 base::TimeDelta::FromMilliseconds(1000), |
| 1266 1, 10, kTouchId2, 1, kBufferedPoints, delegate.get()); | 1276 1, 10, kTouchId2, 1, |
| 1277 GestureConfiguration::points_buffered_for_velocity(), |
| 1278 delegate.get()); |
| 1267 // At no point were both fingers moving at the same time, | 1279 // At no point were both fingers moving at the same time, |
| 1268 // so no scrolling should have occurred | 1280 // so no scrolling should have occurred |
| 1269 | 1281 |
| 1270 EXPECT_EQ(0, delegate->scroll_x()); | 1282 EXPECT_EQ(0, delegate->scroll_x()); |
| 1271 EXPECT_EQ(0, delegate->scroll_y()); | 1283 EXPECT_EQ(0, delegate->scroll_y()); |
| 1272 } | 1284 } |
| 1273 | 1285 |
| 1274 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { | 1286 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { |
| 1275 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1287 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1276 new GestureEventConsumeDelegate()); | 1288 new GestureEventConsumeDelegate()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 // Move a touch associated with windows[2] to 1000, 1000 | 1362 // Move a touch associated with windows[2] to 1000, 1000 |
| 1351 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), kNumWindows); | 1363 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), kNumWindows); |
| 1352 root_window()->DispatchTouchEvent(&move2); | 1364 root_window()->DispatchTouchEvent(&move2); |
| 1353 | 1365 |
| 1354 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); | 1366 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); |
| 1355 EXPECT_EQ(windows[2], target); | 1367 EXPECT_EQ(windows[2], target); |
| 1356 } | 1368 } |
| 1357 | 1369 |
| 1358 } // namespace test | 1370 } // namespace test |
| 1359 } // namespace aura | 1371 } // namespace aura |
| OLD | NEW |