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

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

Issue 282593002: Reland Unified Gesture Recognizer for Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again... Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/aura.gyp ('k') | ui/aura/window_event_dispatcher.h » ('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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 public: 675 public:
676 GestureRecognizerTest() {} 676 GestureRecognizerTest() {}
677 677
678 bool UsingUnifiedGR() { 678 bool UsingUnifiedGR() {
679 return GetParam(); 679 return GetParam();
680 } 680 }
681 681
682 virtual void SetUp() OVERRIDE { 682 virtual void SetUp() OVERRIDE {
683 // TODO(tdresser): Once unified GR has landed, only run these tests once. 683 // TODO(tdresser): Once unified GR has landed, only run these tests once.
684 if (UsingUnifiedGR()) { 684 if (UsingUnifiedGR()) {
685 // TODO(tdresser): use unified GR once it's available. 685 CommandLine::ForCurrentProcess()->AppendSwitch(
686 // CommandLine::ForCurrentProcess()->AppendSwitch( 686 switches::kUseUnifiedGestureDetector);
687 // switches::kUseUnifiedGestureDetector);
688 } 687 }
689 688
690 AuraTestBase::SetUp(); 689 AuraTestBase::SetUp();
691 } 690 }
692 691
692 virtual void TearDown() OVERRIDE {
693 AuraTestBase::TearDown();
694 RunAllPendingInMessageLoop();
695 }
696
693 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); 697 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest);
694 }; 698 };
695 699
696 // Check that appropriate touch events generate tap gesture events. 700 // Check that appropriate touch events generate tap gesture events.
697 TEST_P(GestureRecognizerTest, GestureEventTap) { 701 TEST_P(GestureRecognizerTest, GestureEventTap) {
698 scoped_ptr<GestureEventConsumeDelegate> delegate( 702 scoped_ptr<GestureEventConsumeDelegate> delegate(
699 new GestureEventConsumeDelegate()); 703 new GestureEventConsumeDelegate());
700 TimedEvents tes; 704 TimedEvents tes;
701 const int kWindowWidth = 123; 705 const int kWindowWidth = 123;
702 const int kWindowHeight = 45; 706 const int kWindowHeight = 45;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 EXPECT_FALSE(delegate->scroll_begin()); 743 EXPECT_FALSE(delegate->scroll_begin());
740 EXPECT_FALSE(delegate->scroll_update()); 744 EXPECT_FALSE(delegate->scroll_update());
741 EXPECT_FALSE(delegate->scroll_end()); 745 EXPECT_FALSE(delegate->scroll_end());
742 746
743 EXPECT_EQ(1, delegate->tap_count()); 747 EXPECT_EQ(1, delegate->tap_count());
744 } 748 }
745 749
746 // Check that appropriate touch events generate tap gesture events 750 // Check that appropriate touch events generate tap gesture events
747 // when information about the touch radii are provided. 751 // when information about the touch radii are provided.
748 TEST_P(GestureRecognizerTest, GestureEventTapRegion) { 752 TEST_P(GestureRecognizerTest, GestureEventTapRegion) {
753 // TODO(tdresser): enable this test with unified GR once we resolve the
754 // bounding box differences. See crbug.com/366641.
755 if (UsingUnifiedGR())
756 return;
757
749 scoped_ptr<GestureEventConsumeDelegate> delegate( 758 scoped_ptr<GestureEventConsumeDelegate> delegate(
750 new GestureEventConsumeDelegate()); 759 new GestureEventConsumeDelegate());
751 TimedEvents tes; 760 TimedEvents tes;
752 const int kWindowWidth = 800; 761 const int kWindowWidth = 800;
753 const int kWindowHeight = 600; 762 const int kWindowHeight = 600;
754 const int kTouchId = 2; 763 const int kTouchId = 2;
755 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 764 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
756 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 765 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
757 delegate.get(), -1234, bounds, root_window())); 766 delegate.get(), -1234, bounds, root_window()));
758 767
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 EXPECT_FALSE(delegate->long_press()); 1463 EXPECT_FALSE(delegate->long_press());
1455 EXPECT_TRUE(delegate->long_tap()); 1464 EXPECT_TRUE(delegate->long_tap());
1456 1465
1457 // Note the tap cancel isn't dispatched until the release 1466 // Note the tap cancel isn't dispatched until the release
1458 EXPECT_TRUE(delegate->tap_cancel()); 1467 EXPECT_TRUE(delegate->tap_cancel());
1459 EXPECT_FALSE(delegate->tap()); 1468 EXPECT_FALSE(delegate->tap());
1460 } 1469 }
1461 1470
1462 // Check that second tap cancels a long press 1471 // Check that second tap cancels a long press
1463 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { 1472 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
1464 // TODO(tdresser): enable this test with unified GR once two finger tap is
1465 // supported. See crbug.com/354396.
1466 if (UsingUnifiedGR())
1467 return;
1468
1469 scoped_ptr<GestureEventConsumeDelegate> delegate( 1473 scoped_ptr<GestureEventConsumeDelegate> delegate(
1470 new GestureEventConsumeDelegate()); 1474 new GestureEventConsumeDelegate());
1471 TimedEvents tes; 1475 TimedEvents tes;
1472 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); 1476 ui::GestureConfiguration::set_long_press_time_in_seconds(.01);
1473 const int kWindowWidth = 300; 1477 const int kWindowWidth = 300;
1474 const int kWindowHeight = 400; 1478 const int kWindowHeight = 400;
1475 const int kTouchId1 = 8; 1479 const int kTouchId1 = 8;
1476 const int kTouchId2 = 2; 1480 const int kTouchId2 = 2;
1477 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1481 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1478 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1482 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 EXPECT_FALSE(delegate->tap()); 1745 EXPECT_FALSE(delegate->tap());
1742 EXPECT_FALSE(delegate->tap_down()); 1746 EXPECT_FALSE(delegate->tap_down());
1743 EXPECT_FALSE(delegate->tap_cancel()); 1747 EXPECT_FALSE(delegate->tap_cancel());
1744 EXPECT_FALSE(delegate->scroll_begin()); 1748 EXPECT_FALSE(delegate->scroll_begin());
1745 EXPECT_FALSE(delegate->scroll_update()); 1749 EXPECT_FALSE(delegate->scroll_update());
1746 EXPECT_FALSE(delegate->scroll_end()); 1750 EXPECT_FALSE(delegate->scroll_end());
1747 EXPECT_TRUE(delegate->fling()); 1751 EXPECT_TRUE(delegate->fling());
1748 } 1752 }
1749 1753
1750 TEST_P(GestureRecognizerTest, AsynchronousGestureRecognition) { 1754 TEST_P(GestureRecognizerTest, AsynchronousGestureRecognition) {
1751 // TODO(tdresser): enable this test with unified GR once two finger tap is
1752 // supported. See crbug.com/354396.
1753 if (UsingUnifiedGR())
1754 return;
1755 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 1755 scoped_ptr<QueueTouchEventDelegate> queued_delegate(
1756 new QueueTouchEventDelegate(host()->dispatcher())); 1756 new QueueTouchEventDelegate(host()->dispatcher()));
1757 const int kWindowWidth = 123; 1757 const int kWindowWidth = 123;
1758 const int kWindowHeight = 45; 1758 const int kWindowHeight = 45;
1759 const int kTouchId1 = 6; 1759 const int kTouchId1 = 6;
1760 const int kTouchId2 = 4; 1760 const int kTouchId2 = 4;
1761 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1761 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1762 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 1762 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
1763 queued_delegate.get(), -1234, bounds, root_window())); 1763 queued_delegate.get(), -1234, bounds, root_window()));
1764 1764
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 EXPECT_FALSE(queued_delegate->end()); 1877 EXPECT_FALSE(queued_delegate->end());
1878 EXPECT_FALSE(queued_delegate->scroll_begin()); 1878 EXPECT_FALSE(queued_delegate->scroll_begin());
1879 EXPECT_FALSE(queued_delegate->scroll_update()); 1879 EXPECT_FALSE(queued_delegate->scroll_update());
1880 EXPECT_FALSE(queued_delegate->scroll_end()); 1880 EXPECT_FALSE(queued_delegate->scroll_end());
1881 1881
1882 // Move the second touch-point enough so that it is considered a pinch. This 1882 // Move the second touch-point enough so that it is considered a pinch. This
1883 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. 1883 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures.
1884 queued_delegate->Reset(); 1884 queued_delegate->Reset();
1885 delegate->Reset(); 1885 delegate->Reset();
1886 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); 1886 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
1887 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203), 1887 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(203 + x_move, 303),
1888 kTouchId2, GetTime()); 1888 kTouchId2, GetTime());
1889 DispatchEventUsingWindowDispatcher(&move); 1889 DispatchEventUsingWindowDispatcher(&move);
1890 EXPECT_FALSE(delegate->tap()); 1890 EXPECT_FALSE(delegate->tap());
1891 EXPECT_FALSE(delegate->tap_down()); 1891 EXPECT_FALSE(delegate->tap_down());
1892 EXPECT_FALSE(delegate->tap_cancel()); 1892 EXPECT_FALSE(delegate->tap_cancel());
1893 EXPECT_FALSE(delegate->begin()); 1893 EXPECT_FALSE(delegate->begin());
1894 EXPECT_FALSE(delegate->scroll_begin()); 1894 EXPECT_FALSE(delegate->scroll_begin());
1895 EXPECT_FALSE(delegate->scroll_update()); 1895 EXPECT_FALSE(delegate->scroll_update());
1896 EXPECT_FALSE(delegate->scroll_end()); 1896 EXPECT_FALSE(delegate->scroll_end());
1897 EXPECT_FALSE(queued_delegate->tap()); 1897 EXPECT_FALSE(queued_delegate->tap());
(...skipping 30 matching lines...) Expand all
1928 EXPECT_FALSE(queued_delegate->pinch_end()); 1928 EXPECT_FALSE(queued_delegate->pinch_end());
1929 1929
1930 queued_delegate->Reset(); 1930 queued_delegate->Reset();
1931 queued_delegate->ReceivedAck(); 1931 queued_delegate->ReceivedAck();
1932 EXPECT_FALSE(queued_delegate->tap()); 1932 EXPECT_FALSE(queued_delegate->tap());
1933 EXPECT_FALSE(queued_delegate->tap_down()); 1933 EXPECT_FALSE(queued_delegate->tap_down());
1934 EXPECT_FALSE(queued_delegate->tap_cancel()); 1934 EXPECT_FALSE(queued_delegate->tap_cancel());
1935 EXPECT_FALSE(queued_delegate->begin()); 1935 EXPECT_FALSE(queued_delegate->begin());
1936 EXPECT_FALSE(queued_delegate->end()); 1936 EXPECT_FALSE(queued_delegate->end());
1937 EXPECT_TRUE(queued_delegate->scroll_begin()); 1937 EXPECT_TRUE(queued_delegate->scroll_begin());
1938 EXPECT_FALSE(queued_delegate->scroll_update()); 1938 // TODO(tdresser): uncomment once we've switched to the unified GR.
1939 // EXPECT_TRUE(queued_delegate->scroll_update());
1939 EXPECT_FALSE(queued_delegate->scroll_end()); 1940 EXPECT_FALSE(queued_delegate->scroll_end());
1940 EXPECT_TRUE(queued_delegate->pinch_begin()); 1941 EXPECT_TRUE(queued_delegate->pinch_begin());
1941 EXPECT_FALSE(queued_delegate->pinch_update()); 1942 EXPECT_FALSE(queued_delegate->pinch_update());
1942 EXPECT_FALSE(queued_delegate->pinch_end()); 1943 EXPECT_FALSE(queued_delegate->pinch_end());
1943 } 1944 }
1944 1945
1945 // Check that appropriate touch events generate pinch gesture events. 1946 // Check that appropriate touch events generate pinch gesture events.
1946 TEST_P(GestureRecognizerTest, GestureEventPinchFromScroll) { 1947 TEST_P(GestureRecognizerTest, GestureEventPinchFromScroll) {
1947 // Disabled for unified GR due to differences in when pinch begin is sent. The 1948 // Disabled for unified GR due to differences in when pinch begin is sent. The
1948 // Aura GR sends it earlier than is necessary. 1949 // Aura GR sends it earlier than is necessary.
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 // recognized as a tap. 2716 // recognized as a tap.
2716 delegate->Reset(); 2717 delegate->Reset();
2717 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2718 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
2718 kTouchId2, tes.LeapForward(50)); 2719 kTouchId2, tes.LeapForward(50));
2719 2720
2720 DispatchEventUsingWindowDispatcher(&release2); 2721 DispatchEventUsingWindowDispatcher(&release2);
2721 EXPECT_FALSE(delegate->two_finger_tap()); 2722 EXPECT_FALSE(delegate->two_finger_tap());
2722 } 2723 }
2723 2724
2724 TEST_P(GestureRecognizerTest, TwoFingerTapChangesToPinch) { 2725 TEST_P(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
2725 // TODO(tdresser): enable this test with unified GR once two finger tap is
2726 // supported. See crbug.com/354396.
2727 if (UsingUnifiedGR())
2728 return;
2729
2730 scoped_ptr<GestureEventConsumeDelegate> delegate( 2726 scoped_ptr<GestureEventConsumeDelegate> delegate(
2731 new GestureEventConsumeDelegate()); 2727 new GestureEventConsumeDelegate());
2732 const int kWindowWidth = 123; 2728 const int kWindowWidth = 123;
2733 const int kWindowHeight = 45; 2729 const int kWindowHeight = 45;
2734 const int kTouchId1 = 2; 2730 const int kTouchId1 = 2;
2735 const int kTouchId2 = 3; 2731 const int kTouchId2 = 3;
2736 TimedEvents tes; 2732 TimedEvents tes;
2737 2733
2738 // Test moving first finger 2734 // Test moving first finger
2739 { 2735 {
2740 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2736 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2741 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2737 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2742 delegate.get(), -1234, bounds, root_window())); 2738 delegate.get(), -1234, bounds, root_window()));
2743 2739
2744 delegate->Reset(); 2740 delegate->Reset();
2745 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2741 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2746 kTouchId1, tes.Now()); 2742 kTouchId1, tes.Now());
2747 DispatchEventUsingWindowDispatcher(&press1); 2743 DispatchEventUsingWindowDispatcher(&press1);
2748 2744
2749 delegate->Reset(); 2745 delegate->Reset();
2750 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2746 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2751 kTouchId2, tes.Now()); 2747 kTouchId2, tes.Now());
2752 DispatchEventUsingWindowDispatcher(&press2); 2748 DispatchEventUsingWindowDispatcher(&press2);
2753 2749
2754 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId1, delegate.get()); 2750 tes.SendScrollEvent(event_processor(), 230, 330, kTouchId1, delegate.get());
2755 EXPECT_FALSE(delegate->two_finger_tap()); 2751 EXPECT_FALSE(delegate->two_finger_tap());
2756 EXPECT_TRUE(delegate->pinch_begin()); 2752 EXPECT_TRUE(delegate->pinch_begin());
2757 2753
2758 // Make sure there is enough delay before the touch is released so that it 2754 // Make sure there is enough delay before the touch is released so that it
2759 // is recognized as a tap. 2755 // is recognized as a tap.
2760 delegate->Reset(); 2756 delegate->Reset();
2761 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2757 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2762 kTouchId2, tes.LeapForward(50)); 2758 kTouchId2, tes.LeapForward(50));
2763 2759
2764 DispatchEventUsingWindowDispatcher(&release); 2760 DispatchEventUsingWindowDispatcher(&release);
(...skipping 10 matching lines...) Expand all
2775 delegate->Reset(); 2771 delegate->Reset();
2776 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2772 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2777 kTouchId1, tes.Now()); 2773 kTouchId1, tes.Now());
2778 DispatchEventUsingWindowDispatcher(&press1); 2774 DispatchEventUsingWindowDispatcher(&press1);
2779 2775
2780 delegate->Reset(); 2776 delegate->Reset();
2781 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2777 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2782 kTouchId2, tes.Now()); 2778 kTouchId2, tes.Now());
2783 DispatchEventUsingWindowDispatcher(&press2); 2779 DispatchEventUsingWindowDispatcher(&press2);
2784 2780
2785 tes.SendScrollEvent(event_processor(), 101, 230, kTouchId2, delegate.get()); 2781 tes.SendScrollEvent(event_processor(), 301, 230, kTouchId2, delegate.get());
2786 EXPECT_FALSE(delegate->two_finger_tap()); 2782 EXPECT_FALSE(delegate->two_finger_tap());
2787 EXPECT_TRUE(delegate->pinch_begin()); 2783 EXPECT_TRUE(delegate->pinch_begin());
2788 2784
2789 // Make sure there is enough delay before the touch is released so that it 2785 // Make sure there is enough delay before the touch is released so that it
2790 // is recognized as a tap. 2786 // is recognized as a tap.
2791 delegate->Reset(); 2787 delegate->Reset();
2792 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2788 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2793 kTouchId1, tes.LeapForward(50)); 2789 kTouchId1, tes.LeapForward(50));
2794 2790
2795 DispatchEventUsingWindowDispatcher(&release); 2791 DispatchEventUsingWindowDispatcher(&release);
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
4268 move1.set_flags(992); 4264 move1.set_flags(992);
4269 4265
4270 DispatchEventUsingWindowDispatcher(&move1); 4266 DispatchEventUsingWindowDispatcher(&move1);
4271 EXPECT_NE(default_flags, delegate->flags()); 4267 EXPECT_NE(default_flags, delegate->flags());
4272 } 4268 }
4273 4269
4274 // TODO - re-enable these tests once memory management issues have been sorted 4270 // TODO - re-enable these tests once memory management issues have been sorted
4275 // out. See crbug.com/371990. 4271 // out. See crbug.com/371990.
4276 INSTANTIATE_TEST_CASE_P(GestureRecognizer, 4272 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4277 GestureRecognizerTest, 4273 GestureRecognizerTest,
4278 ::testing::Values(false)); 4274 ::testing::Bool());
4279 4275
4280 } // namespace test 4276 } // namespace test
4281 } // namespace aura 4277 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/aura.gyp ('k') | ui/aura/window_event_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698