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