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

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

Issue 133273013: Consuming any touch move before SCROLL_START prevents the scroll from occuring in Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address sadrul's comments. Created 6 years, 11 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 | « no previous file | ui/events/gestures/gesture_sequence.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 3723 matching lines...) Expand 10 before | Expand all | Expand 10 after
3734 3734
3735 delegate->Reset(); 3735 delegate->Reset();
3736 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3736 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3737 kTouchId, tes.LeapForward(50)); 3737 kTouchId, tes.LeapForward(50));
3738 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release1); 3738 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release1);
3739 EXPECT_TRUE(delegate->show_press()); 3739 EXPECT_TRUE(delegate->show_press());
3740 EXPECT_FALSE(delegate->tap_cancel()); 3740 EXPECT_FALSE(delegate->tap_cancel());
3741 EXPECT_TRUE(delegate->tap()); 3741 EXPECT_TRUE(delegate->tap());
3742 } 3742 }
3743 3743
3744 // Test that consuming the first move touch event prevents a scroll.
3745 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) {
3746 scoped_ptr<QueueTouchEventDelegate> delegate(
3747 new QueueTouchEventDelegate(dispatcher()));
3748 TimedEvents tes;
3749 const int kTouchId = 7;
3750 gfx::Rect bounds(0, 0, 1000, 1000);
3751 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3752 delegate.get(), -1234, bounds, root_window()));
3753
3754 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3755 kTouchId, tes.Now());
3756 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press);
3757 delegate->ReceivedAck();
3758
3759 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
3760 kTouchId, tes.Now());
3761 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move1);
3762 delegate->ReceivedAckPreventDefaulted();
3763
3764 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
3765 kTouchId, tes.Now());
3766 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move2);
3767 delegate->ReceivedAck();
3768
3769 EXPECT_FALSE(delegate->scroll_begin());
3770 EXPECT_FALSE(delegate->scroll_update());
3771 }
3772
3773 // Test that consuming the first touch move event of a touch point doesn't
3774 // prevent pinching once an additional touch has been pressed.
3775 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) {
3776 scoped_ptr<QueueTouchEventDelegate> delegate(
3777 new QueueTouchEventDelegate(dispatcher()));
3778 TimedEvents tes;
3779 const int kTouchId1 = 7;
3780 const int kTouchId2 = 4;
3781 gfx::Rect bounds(0, 0, 1000, 1000);
3782 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3783 delegate.get(), -1234, bounds, root_window()));
3784
3785 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3786 kTouchId1, tes.Now());
3787 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press1);
3788 delegate->ReceivedAck();
3789
3790 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
3791 kTouchId1, tes.Now());
3792 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move1);
3793 delegate->ReceivedAckPreventDefaulted();
3794
3795 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
3796 kTouchId1, tes.Now());
3797 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move2);
3798 delegate->ReceivedAck();
3799
3800 // We can't scroll, because a move has been consumed.
3801 EXPECT_FALSE(delegate->scroll_begin());
3802 EXPECT_FALSE(delegate->scroll_update());
3803 EXPECT_FALSE(delegate->pinch_begin());
3804
3805 // An additional press will allow us to pinch.
3806 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3807 kTouchId2, tes.Now());
3808 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press2);
3809 delegate->ReceivedAck();
3810
3811 ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
3812 kTouchId2, tes.Now());
3813 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move3);
3814 delegate->ReceivedAck();
3815
3816 EXPECT_TRUE(delegate->pinch_begin());
3817 EXPECT_FALSE(delegate->pinch_update());
3818
3819 delegate->Reset();
3820
3821 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(40, 40),
3822 kTouchId2, tes.Now());
3823 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move4);
3824 delegate->ReceivedAck();
3825
3826 EXPECT_TRUE(delegate->pinch_update());
3827 EXPECT_EQ(10, delegate->scroll_x());
3828 EXPECT_EQ(10, delegate->scroll_y());
3829 }
3830
3831 // Test that consuming the first move touch doesn't prevent a tap.
3832 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) {
3833 scoped_ptr<QueueTouchEventDelegate> delegate(
3834 new QueueTouchEventDelegate(dispatcher()));
3835 TimedEvents tes;
3836 const int kTouchId = 7;
3837 gfx::Rect bounds(0, 0, 1000, 1000);
3838 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3839 delegate.get(), -1234, bounds, root_window()));
3840
3841 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3842 kTouchId, tes.Now());
3843 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press);
3844 delegate->ReceivedAck();
3845
3846 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
3847 kTouchId, tes.Now());
3848 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move);
3849 delegate->ReceivedAckPreventDefaulted();
3850
3851 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(2, 2),
3852 kTouchId, tes.LeapForward(50));
3853 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release);
3854 delegate->ReceivedAck();
3855
3856 EXPECT_TRUE(delegate->tap());
3857 }
3858
3859 // Test that consuming the first move touch doesn't prevent a long press.
3860 TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) {
3861 scoped_ptr<QueueTouchEventDelegate> delegate(
3862 new QueueTouchEventDelegate(dispatcher()));
3863 TimedEvents tes;
3864 const int kWindowWidth = 123;
3865 const int kWindowHeight = 45;
3866 const int kTouchId = 2;
3867 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
3868 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3869 delegate.get(), -1234, bounds, root_window()));
3870
3871 delegate->Reset();
3872
3873 TimerTestGestureRecognizer* gesture_recognizer =
3874 new TimerTestGestureRecognizer();
3875
3876 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
3877
3878 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3879 kTouchId, tes.Now());
3880 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press1);
3881 delegate->ReceivedAck();
3882
3883 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103, 203),
3884 kTouchId, tes.Now());
3885 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move);
3886 delegate->ReceivedAckPreventDefaulted();
3887
3888 // Wait until the timer runs out
3889 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
3890 EXPECT_TRUE(delegate->long_press());
3891 }
3892
3744 } // namespace test 3893 } // namespace test
3745 } // namespace aura 3894 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/events/gestures/gesture_sequence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698