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

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

Issue 228973003: Don't treat first touch move differently from future touch moves (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add extra return. Created 6 years, 5 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
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 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50), 2091 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50),
2092 kTouchId1, tes.Now()); 2092 kTouchId1, tes.Now());
2093 DispatchEventUsingWindowDispatcher(&move2); 2093 DispatchEventUsingWindowDispatcher(&move2);
2094 EXPECT_TRUE(delegate->pinch_begin()); 2094 EXPECT_TRUE(delegate->pinch_begin());
2095 2095
2096 tes.SendScrollEvent(event_processor(), 350, 350, kTouchId1, delegate.get()); 2096 tes.SendScrollEvent(event_processor(), 350, 350, kTouchId1, delegate.get());
2097 EXPECT_TRUE(delegate->pinch_update()); 2097 EXPECT_TRUE(delegate->pinch_update());
2098 } 2098 }
2099 2099
2100 TEST_P(GestureRecognizerTest, GestureEventPinchFromTap) { 2100 TEST_P(GestureRecognizerTest, GestureEventPinchFromTap) {
2101 // TODO(tdresser): enable this test with unified GR once two finger tap. 2101 // Disabled under unified gesture recognizer due to behavior differences in
2102 // scroll and bounding box behavior.
2102 if (UsingUnifiedGR()) 2103 if (UsingUnifiedGR())
2103 return; 2104 return;
2104 2105
2105 scoped_ptr<GestureEventConsumeDelegate> delegate( 2106 scoped_ptr<GestureEventConsumeDelegate> delegate(
2106 new GestureEventConsumeDelegate()); 2107 new GestureEventConsumeDelegate());
2107 TimedEvents tes; 2108 TimedEvents tes;
2108 const int kWindowWidth = 300; 2109 const int kWindowWidth = 300;
2109 const int kWindowHeight = 400; 2110 const int kWindowHeight = 400;
2110 const int kTouchId1 = 3; 2111 const int kTouchId1 = 3;
2111 const int kTouchId2 = 5; 2112 const int kTouchId2 = 5;
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
3137 EXPECT_FALSE(delegate->scroll_end()); 3138 EXPECT_FALSE(delegate->scroll_end());
3138 3139
3139 // Move the touch-point enough so that it would normally be considered a 3140 // Move the touch-point enough so that it would normally be considered a
3140 // scroll. But since the touch-moves will be consumed, the scroll should not 3141 // scroll. But since the touch-moves will be consumed, the scroll should not
3141 // start. 3142 // start.
3142 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); 3143 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
3143 EXPECT_FALSE(delegate->tap()); 3144 EXPECT_FALSE(delegate->tap());
3144 EXPECT_FALSE(delegate->tap_down()); 3145 EXPECT_FALSE(delegate->tap_down());
3145 EXPECT_TRUE(delegate->tap_cancel()); 3146 EXPECT_TRUE(delegate->tap_cancel());
3146 EXPECT_FALSE(delegate->begin()); 3147 EXPECT_FALSE(delegate->begin());
3147 EXPECT_FALSE(delegate->scroll_begin());
3148 EXPECT_FALSE(delegate->scroll_update()); 3148 EXPECT_FALSE(delegate->scroll_update());
3149 EXPECT_FALSE(delegate->scroll_end()); 3149 EXPECT_FALSE(delegate->scroll_end());
3150 3150
3151 // With the unified gesture detector, consuming the first touch move event
3152 // won't prevent all future scrolling.
3153 if (UsingUnifiedGR())
3154 EXPECT_TRUE(delegate->scroll_begin());
3155 else
3156 EXPECT_FALSE(delegate->scroll_begin());
3157
3151 // Release the touch back at the start point. This should end without causing 3158 // Release the touch back at the start point. This should end without causing
3152 // a tap. 3159 // a tap.
3153 delegate->Reset(); 3160 delegate->Reset();
3154 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(130, 230), 3161 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(130, 230),
3155 kTouchId, tes.LeapForward(50)); 3162 kTouchId, tes.LeapForward(50));
3156 DispatchEventUsingWindowDispatcher(&release); 3163 DispatchEventUsingWindowDispatcher(&release);
3157 EXPECT_FALSE(delegate->tap()); 3164 EXPECT_FALSE(delegate->tap());
3158 EXPECT_FALSE(delegate->tap_down()); 3165 EXPECT_FALSE(delegate->tap_down());
3159 EXPECT_FALSE(delegate->tap_cancel()); 3166 EXPECT_FALSE(delegate->tap_cancel());
3160 EXPECT_FALSE(delegate->begin()); 3167 EXPECT_FALSE(delegate->begin());
3161 EXPECT_TRUE(delegate->end()); 3168 EXPECT_TRUE(delegate->end());
3162 EXPECT_FALSE(delegate->scroll_begin()); 3169 EXPECT_FALSE(delegate->scroll_begin());
3163 EXPECT_FALSE(delegate->scroll_update()); 3170 EXPECT_FALSE(delegate->scroll_update());
3164 EXPECT_FALSE(delegate->scroll_end()); 3171
3172 if (UsingUnifiedGR())
3173 EXPECT_TRUE(delegate->scroll_end());
3174 else
3175 EXPECT_FALSE(delegate->scroll_end());
3165 } 3176 }
3166 3177
3167 // Tests the behavior of 2F scroll when all the touch-move events are consumed. 3178 // Tests the behavior of 2F scroll when all the touch-move events are consumed.
3168 TEST_P(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) { 3179 TEST_P(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) {
3169 // TODO(tdresser): enable this test with unified GR once two finger tap is 3180 // TODO(tdresser): enable this test with unified GR once two finger tap is
3170 // supported. See crbug.com/354396. 3181 // supported. See crbug.com/354396.
3171 if (UsingUnifiedGR()) 3182 if (UsingUnifiedGR())
3172 return; 3183 return;
3173 3184
3174 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3185 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 EXPECT_FALSE(delegate->scroll_end()); 3312 EXPECT_FALSE(delegate->scroll_end());
3302 3313
3303 // Move the touch-point enough so that it would normally be considered a 3314 // Move the touch-point enough so that it would normally be considered a
3304 // scroll. But since the touch-moves will be consumed, the scroll should not 3315 // scroll. But since the touch-moves will be consumed, the scroll should not
3305 // start. 3316 // start.
3306 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); 3317 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
3307 EXPECT_FALSE(delegate->tap()); 3318 EXPECT_FALSE(delegate->tap());
3308 EXPECT_FALSE(delegate->tap_down()); 3319 EXPECT_FALSE(delegate->tap_down());
3309 EXPECT_TRUE(delegate->tap_cancel()); 3320 EXPECT_TRUE(delegate->tap_cancel());
3310 EXPECT_FALSE(delegate->begin()); 3321 EXPECT_FALSE(delegate->begin());
3311 EXPECT_FALSE(delegate->scroll_begin());
3312 EXPECT_FALSE(delegate->scroll_update()); 3322 EXPECT_FALSE(delegate->scroll_update());
3313 EXPECT_FALSE(delegate->scroll_end()); 3323 EXPECT_FALSE(delegate->scroll_end());
3314 3324
3325 // With the unified gesture detector, consuming the first touch move event
3326 // won't prevent all future scrolling.
3327 if (UsingUnifiedGR())
3328 EXPECT_TRUE(delegate->scroll_begin());
3329 else
3330 EXPECT_FALSE(delegate->scroll_begin());
3331
3315 // Now, stop consuming touch-move events, and move the touch-point again. 3332 // Now, stop consuming touch-move events, and move the touch-point again.
3316 delegate->set_consume_touch_move(false); 3333 delegate->set_consume_touch_move(false);
3317 tes.SendScrollEvent(event_processor(), 159, 259, kTouchId, delegate.get()); 3334 tes.SendScrollEvent(event_processor(), 159, 259, kTouchId, delegate.get());
3318 EXPECT_FALSE(delegate->tap()); 3335 EXPECT_FALSE(delegate->tap());
3319 EXPECT_FALSE(delegate->tap_down()); 3336 EXPECT_FALSE(delegate->tap_down());
3320 EXPECT_FALSE(delegate->tap_cancel()); 3337 EXPECT_FALSE(delegate->tap_cancel());
3321 EXPECT_FALSE(delegate->begin()); 3338 EXPECT_FALSE(delegate->begin());
3322 EXPECT_FALSE(delegate->scroll_begin()); 3339 EXPECT_FALSE(delegate->scroll_begin());
3323 EXPECT_FALSE(delegate->scroll_update());
3324 EXPECT_FALSE(delegate->scroll_end()); 3340 EXPECT_FALSE(delegate->scroll_end());
3325 // No scroll has occurred, because an early touch move was consumed. 3341
3326 EXPECT_EQ(0, delegate->scroll_x()); 3342 if (UsingUnifiedGR()) {
3327 EXPECT_EQ(0, delegate->scroll_y()); 3343 // Scroll not prevented by consumed first touch move.
3328 EXPECT_EQ(gfx::Point(0, 0).ToString(), 3344 EXPECT_TRUE(delegate->scroll_update());
3329 delegate->scroll_begin_position().ToString()); 3345 EXPECT_EQ(29, delegate->scroll_x());
3346 EXPECT_EQ(29, delegate->scroll_y());
3347 EXPECT_EQ(gfx::Point(0, 0).ToString(),
3348 delegate->scroll_begin_position().ToString());
3349 } else {
3350 EXPECT_FALSE(delegate->scroll_update());
3351 // No scroll has occurred, because an early touch move was consumed.
3352 EXPECT_EQ(0, delegate->scroll_x());
3353 EXPECT_EQ(0, delegate->scroll_y());
3354 EXPECT_EQ(gfx::Point(0, 0).ToString(),
3355 delegate->scroll_begin_position().ToString());
3356 }
3330 3357
3331 // Start consuming touch-move events again. 3358 // Start consuming touch-move events again.
3332 delegate->set_consume_touch_move(true); 3359 delegate->set_consume_touch_move(true);
3333 3360
3334 // Move some more to generate a few more scroll updates. 3361 // Move some more to generate a few more scroll updates.
3335 tes.SendScrollEvent(event_processor(), 110, 211, kTouchId, delegate.get()); 3362 tes.SendScrollEvent(event_processor(), 110, 211, kTouchId, delegate.get());
3336 EXPECT_FALSE(delegate->tap()); 3363 EXPECT_FALSE(delegate->tap());
3337 EXPECT_FALSE(delegate->tap_down()); 3364 EXPECT_FALSE(delegate->tap_down());
3338 EXPECT_FALSE(delegate->tap_cancel()); 3365 EXPECT_FALSE(delegate->tap_cancel());
3339 EXPECT_FALSE(delegate->begin()); 3366 EXPECT_FALSE(delegate->begin());
(...skipping 19 matching lines...) Expand all
3359 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3386 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3360 kTouchId, tes.LeapForward(50)); 3387 kTouchId, tes.LeapForward(50));
3361 DispatchEventUsingWindowDispatcher(&release); 3388 DispatchEventUsingWindowDispatcher(&release);
3362 EXPECT_FALSE(delegate->tap()); 3389 EXPECT_FALSE(delegate->tap());
3363 EXPECT_FALSE(delegate->tap_down()); 3390 EXPECT_FALSE(delegate->tap_down());
3364 EXPECT_FALSE(delegate->tap_cancel()); 3391 EXPECT_FALSE(delegate->tap_cancel());
3365 EXPECT_FALSE(delegate->begin()); 3392 EXPECT_FALSE(delegate->begin());
3366 EXPECT_TRUE(delegate->end()); 3393 EXPECT_TRUE(delegate->end());
3367 EXPECT_FALSE(delegate->scroll_begin()); 3394 EXPECT_FALSE(delegate->scroll_begin());
3368 EXPECT_FALSE(delegate->scroll_update()); 3395 EXPECT_FALSE(delegate->scroll_update());
3369 EXPECT_FALSE(delegate->scroll_end());
3370 EXPECT_FALSE(delegate->fling()); 3396 EXPECT_FALSE(delegate->fling());
3397
3398 if (UsingUnifiedGR())
3399 EXPECT_TRUE(delegate->scroll_end());
3400 else
3401 EXPECT_FALSE(delegate->scroll_end());
3371 } 3402 }
3372 3403
3373 // Check that appropriate touch events generate double tap gesture events. 3404 // Check that appropriate touch events generate double tap gesture events.
3374 TEST_P(GestureRecognizerTest, GestureEventDoubleTap) { 3405 TEST_P(GestureRecognizerTest, GestureEventDoubleTap) {
3375 scoped_ptr<GestureEventConsumeDelegate> delegate( 3406 scoped_ptr<GestureEventConsumeDelegate> delegate(
3376 new GestureEventConsumeDelegate()); 3407 new GestureEventConsumeDelegate());
3377 const int kWindowWidth = 123; 3408 const int kWindowWidth = 123;
3378 const int kWindowHeight = 45; 3409 const int kWindowHeight = 45;
3379 const int kTouchId = 2; 3410 const int kTouchId = 2;
3380 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3411 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 3729
3699 delegate->Reset(); 3730 delegate->Reset();
3700 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3731 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3701 kTouchId, tes.Now()); 3732 kTouchId, tes.Now());
3702 3733
3703 delegate->set_consume_touch_move(false); 3734 delegate->set_consume_touch_move(false);
3704 DispatchEventUsingWindowDispatcher(&press); 3735 DispatchEventUsingWindowDispatcher(&press);
3705 delegate->set_consume_touch_move(true); 3736 delegate->set_consume_touch_move(true);
3706 delegate->Reset(); 3737 delegate->Reset();
3707 // Move the touch-point enough so that it would normally be considered a 3738 // Move the touch-point enough so that it would normally be considered a
3708 // scroll. But since the touch-moves will be consumed, the scroll should not 3739 // scroll. But since the touch-moves will be consumed, no scrolling should
3709 // start. 3740 // occur.
3741 // With the unified gesture detector, we will receive a scroll begin gesture,
3742 // whereas with the aura gesture recognizer we won't.
3710 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); 3743 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
3711 EXPECT_FALSE(delegate->tap()); 3744 EXPECT_FALSE(delegate->tap());
3712 EXPECT_FALSE(delegate->tap_down()); 3745 EXPECT_FALSE(delegate->tap_down());
3713 EXPECT_TRUE(delegate->tap_cancel()); 3746 EXPECT_TRUE(delegate->tap_cancel());
3714 EXPECT_FALSE(delegate->begin()); 3747 EXPECT_FALSE(delegate->begin());
3715 EXPECT_FALSE(delegate->scroll_begin());
3716 EXPECT_FALSE(delegate->scroll_update()); 3748 EXPECT_FALSE(delegate->scroll_update());
3717 EXPECT_FALSE(delegate->scroll_end()); 3749 EXPECT_FALSE(delegate->scroll_end());
3718 } 3750 }
3719 3751
3720 TEST_P(GestureRecognizerTest, 3752 TEST_P(GestureRecognizerTest,
3721 TransferEventDispatchesTouchCancel) { 3753 TransferEventDispatchesTouchCancel) {
3722 scoped_ptr<GestureEventConsumeDelegate> delegate( 3754 scoped_ptr<GestureEventConsumeDelegate> delegate(
3723 new GestureEventConsumeDelegate()); 3755 new GestureEventConsumeDelegate());
3724 TimedEvents tes; 3756 TimedEvents tes;
3725 const int kWindowWidth = 800; 3757 const int kWindowWidth = 800;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
3904 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 3936 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10),
3905 kTouchId, tes.Now()); 3937 kTouchId, tes.Now());
3906 DispatchEventUsingWindowDispatcher(&move1); 3938 DispatchEventUsingWindowDispatcher(&move1);
3907 delegate->ReceivedAckPreventDefaulted(); 3939 delegate->ReceivedAckPreventDefaulted();
3908 3940
3909 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 3941 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
3910 kTouchId, tes.Now()); 3942 kTouchId, tes.Now());
3911 DispatchEventUsingWindowDispatcher(&move2); 3943 DispatchEventUsingWindowDispatcher(&move2);
3912 delegate->ReceivedAck(); 3944 delegate->ReceivedAck();
3913 3945
3914 EXPECT_FALSE(delegate->scroll_begin()); 3946 if (UsingUnifiedGR()) {
3915 EXPECT_FALSE(delegate->scroll_update()); 3947 // With the unified gesture detector, consuming the first touch move event
3948 // won't prevent all future scrolling.
3949 EXPECT_TRUE(delegate->scroll_begin());
3950 EXPECT_TRUE(delegate->scroll_update());
3951 } else {
3952 EXPECT_FALSE(delegate->scroll_begin());
3953 EXPECT_FALSE(delegate->scroll_update());
3954 }
3916 } 3955 }
3917 3956
3918 // Test that consuming the first touch move event of a touch point doesn't 3957 // Test that consuming the first touch move event of a touch point doesn't
3919 // prevent pinching once an additional touch has been pressed. 3958 // prevent pinching once an additional touch has been pressed.
3920 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) { 3959 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) {
3921 // Consuming moves within the touch slop and the the disposition handling of 3960 // Consuming moves within the touch slop and the the disposition handling of
3922 // pinch events behave differently between the Unified GR and the Aura GR. 3961 // pinch events behave differently between the Unified GR and the Aura GR.
3923 if (UsingUnifiedGR()) 3962 if (UsingUnifiedGR())
3924 return; 3963 return;
3925 3964
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
4383 delegate.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 4422 delegate.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
4384 EXPECT_EQ(NULL, window); 4423 EXPECT_EQ(NULL, window);
4385 } 4424 }
4386 4425
4387 INSTANTIATE_TEST_CASE_P(GestureRecognizer, 4426 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4388 GestureRecognizerTest, 4427 GestureRecognizerTest,
4389 ::testing::Bool()); 4428 ::testing::Bool());
4390 4429
4391 } // namespace test 4430 } // namespace test
4392 } // namespace aura 4431 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698