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 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50), | 2084 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 50), |
2085 kTouchId1, tes.Now()); | 2085 kTouchId1, tes.Now()); |
2086 DispatchEventUsingWindowDispatcher(&move2); | 2086 DispatchEventUsingWindowDispatcher(&move2); |
2087 EXPECT_TRUE(delegate->pinch_begin()); | 2087 EXPECT_TRUE(delegate->pinch_begin()); |
2088 | 2088 |
2089 tes.SendScrollEvent(event_processor(), 350, 350, kTouchId1, delegate.get()); | 2089 tes.SendScrollEvent(event_processor(), 350, 350, kTouchId1, delegate.get()); |
2090 EXPECT_TRUE(delegate->pinch_update()); | 2090 EXPECT_TRUE(delegate->pinch_update()); |
2091 } | 2091 } |
2092 | 2092 |
2093 TEST_P(GestureRecognizerTest, GestureEventPinchFromTap) { | 2093 TEST_P(GestureRecognizerTest, GestureEventPinchFromTap) { |
2094 // TODO(tdresser): enable this test with unified GR once two finger tap. | 2094 // Disabled under unified gesture recognizer due to behavior differences in |
| 2095 // scroll and bounding box behavior. |
2095 if (UsingUnifiedGR()) | 2096 if (UsingUnifiedGR()) |
2096 return; | 2097 return; |
2097 | 2098 |
2098 scoped_ptr<GestureEventConsumeDelegate> delegate( | 2099 scoped_ptr<GestureEventConsumeDelegate> delegate( |
2099 new GestureEventConsumeDelegate()); | 2100 new GestureEventConsumeDelegate()); |
2100 TimedEvents tes; | 2101 TimedEvents tes; |
2101 const int kWindowWidth = 300; | 2102 const int kWindowWidth = 300; |
2102 const int kWindowHeight = 400; | 2103 const int kWindowHeight = 400; |
2103 const int kTouchId1 = 3; | 2104 const int kTouchId1 = 3; |
2104 const int kTouchId2 = 5; | 2105 const int kTouchId2 = 5; |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3130 EXPECT_FALSE(delegate->scroll_end()); | 3131 EXPECT_FALSE(delegate->scroll_end()); |
3131 | 3132 |
3132 // Move the touch-point enough so that it would normally be considered a | 3133 // Move the touch-point enough so that it would normally be considered a |
3133 // scroll. But since the touch-moves will be consumed, the scroll should not | 3134 // scroll. But since the touch-moves will be consumed, the scroll should not |
3134 // start. | 3135 // start. |
3135 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); | 3136 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); |
3136 EXPECT_FALSE(delegate->tap()); | 3137 EXPECT_FALSE(delegate->tap()); |
3137 EXPECT_FALSE(delegate->tap_down()); | 3138 EXPECT_FALSE(delegate->tap_down()); |
3138 EXPECT_TRUE(delegate->tap_cancel()); | 3139 EXPECT_TRUE(delegate->tap_cancel()); |
3139 EXPECT_FALSE(delegate->begin()); | 3140 EXPECT_FALSE(delegate->begin()); |
3140 EXPECT_FALSE(delegate->scroll_begin()); | |
3141 EXPECT_FALSE(delegate->scroll_update()); | 3141 EXPECT_FALSE(delegate->scroll_update()); |
3142 EXPECT_FALSE(delegate->scroll_end()); | 3142 EXPECT_FALSE(delegate->scroll_end()); |
3143 | 3143 |
| 3144 // With the unified gesture detector, consuming the first touch move event |
| 3145 // won't prevent all future scrolling. |
| 3146 if (UsingUnifiedGR()) |
| 3147 EXPECT_TRUE(delegate->scroll_begin()); |
| 3148 else |
| 3149 EXPECT_FALSE(delegate->scroll_begin()); |
| 3150 |
3144 // 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 |
3145 // a tap. | 3152 // a tap. |
3146 delegate->Reset(); | 3153 delegate->Reset(); |
3147 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(130, 230), | 3154 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(130, 230), |
3148 kTouchId, tes.LeapForward(50)); | 3155 kTouchId, tes.LeapForward(50)); |
3149 DispatchEventUsingWindowDispatcher(&release); | 3156 DispatchEventUsingWindowDispatcher(&release); |
3150 EXPECT_FALSE(delegate->tap()); | 3157 EXPECT_FALSE(delegate->tap()); |
3151 EXPECT_FALSE(delegate->tap_down()); | 3158 EXPECT_FALSE(delegate->tap_down()); |
3152 EXPECT_FALSE(delegate->tap_cancel()); | 3159 EXPECT_FALSE(delegate->tap_cancel()); |
3153 EXPECT_FALSE(delegate->begin()); | 3160 EXPECT_FALSE(delegate->begin()); |
3154 EXPECT_TRUE(delegate->end()); | 3161 EXPECT_TRUE(delegate->end()); |
3155 EXPECT_FALSE(delegate->scroll_begin()); | 3162 EXPECT_FALSE(delegate->scroll_begin()); |
3156 EXPECT_FALSE(delegate->scroll_update()); | 3163 EXPECT_FALSE(delegate->scroll_update()); |
3157 EXPECT_FALSE(delegate->scroll_end()); | 3164 |
| 3165 if (UsingUnifiedGR()) |
| 3166 EXPECT_TRUE(delegate->scroll_end()); |
| 3167 else |
| 3168 EXPECT_FALSE(delegate->scroll_end()); |
3158 } | 3169 } |
3159 | 3170 |
3160 // Tests the behavior of 2F scroll when all the touch-move events are consumed. | 3171 // Tests the behavior of 2F scroll when all the touch-move events are consumed. |
3161 TEST_P(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) { | 3172 TEST_P(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) { |
3162 // TODO(tdresser): enable this test with unified GR once two finger tap is | 3173 // TODO(tdresser): enable this test with unified GR once two finger tap is |
3163 // supported. See crbug.com/354396. | 3174 // supported. See crbug.com/354396. |
3164 if (UsingUnifiedGR()) | 3175 if (UsingUnifiedGR()) |
3165 return; | 3176 return; |
3166 | 3177 |
3167 scoped_ptr<ConsumesTouchMovesDelegate> delegate( | 3178 scoped_ptr<ConsumesTouchMovesDelegate> delegate( |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3294 EXPECT_FALSE(delegate->scroll_end()); | 3305 EXPECT_FALSE(delegate->scroll_end()); |
3295 | 3306 |
3296 // Move the touch-point enough so that it would normally be considered a | 3307 // Move the touch-point enough so that it would normally be considered a |
3297 // scroll. But since the touch-moves will be consumed, the scroll should not | 3308 // scroll. But since the touch-moves will be consumed, the scroll should not |
3298 // start. | 3309 // start. |
3299 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); | 3310 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); |
3300 EXPECT_FALSE(delegate->tap()); | 3311 EXPECT_FALSE(delegate->tap()); |
3301 EXPECT_FALSE(delegate->tap_down()); | 3312 EXPECT_FALSE(delegate->tap_down()); |
3302 EXPECT_TRUE(delegate->tap_cancel()); | 3313 EXPECT_TRUE(delegate->tap_cancel()); |
3303 EXPECT_FALSE(delegate->begin()); | 3314 EXPECT_FALSE(delegate->begin()); |
3304 EXPECT_FALSE(delegate->scroll_begin()); | |
3305 EXPECT_FALSE(delegate->scroll_update()); | 3315 EXPECT_FALSE(delegate->scroll_update()); |
3306 EXPECT_FALSE(delegate->scroll_end()); | 3316 EXPECT_FALSE(delegate->scroll_end()); |
3307 | 3317 |
| 3318 // With the unified gesture detector, consuming the first touch move event |
| 3319 // won't prevent all future scrolling. |
| 3320 if (UsingUnifiedGR()) |
| 3321 EXPECT_TRUE(delegate->scroll_begin()); |
| 3322 else |
| 3323 EXPECT_FALSE(delegate->scroll_begin()); |
| 3324 |
3308 // Now, stop consuming touch-move events, and move the touch-point again. | 3325 // Now, stop consuming touch-move events, and move the touch-point again. |
3309 delegate->set_consume_touch_move(false); | 3326 delegate->set_consume_touch_move(false); |
3310 tes.SendScrollEvent(event_processor(), 159, 259, kTouchId, delegate.get()); | 3327 tes.SendScrollEvent(event_processor(), 159, 259, kTouchId, delegate.get()); |
3311 EXPECT_FALSE(delegate->tap()); | 3328 EXPECT_FALSE(delegate->tap()); |
3312 EXPECT_FALSE(delegate->tap_down()); | 3329 EXPECT_FALSE(delegate->tap_down()); |
3313 EXPECT_FALSE(delegate->tap_cancel()); | 3330 EXPECT_FALSE(delegate->tap_cancel()); |
3314 EXPECT_FALSE(delegate->begin()); | 3331 EXPECT_FALSE(delegate->begin()); |
3315 EXPECT_FALSE(delegate->scroll_begin()); | 3332 EXPECT_FALSE(delegate->scroll_begin()); |
3316 EXPECT_FALSE(delegate->scroll_update()); | |
3317 EXPECT_FALSE(delegate->scroll_end()); | 3333 EXPECT_FALSE(delegate->scroll_end()); |
3318 // No scroll has occurred, because an early touch move was consumed. | 3334 |
3319 EXPECT_EQ(0, delegate->scroll_x()); | 3335 if (UsingUnifiedGR()) { |
3320 EXPECT_EQ(0, delegate->scroll_y()); | 3336 // Scroll not prevented by consumed first touch move. |
3321 EXPECT_EQ(gfx::Point(0, 0).ToString(), | 3337 EXPECT_TRUE(delegate->scroll_update()); |
3322 delegate->scroll_begin_position().ToString()); | 3338 EXPECT_EQ(29, delegate->scroll_x()); |
| 3339 EXPECT_EQ(29, delegate->scroll_y()); |
| 3340 EXPECT_EQ(gfx::Point(0, 0).ToString(), |
| 3341 delegate->scroll_begin_position().ToString()); |
| 3342 } else { |
| 3343 EXPECT_FALSE(delegate->scroll_update()); |
| 3344 // No scroll has occurred, because an early touch move was consumed. |
| 3345 EXPECT_EQ(0, delegate->scroll_x()); |
| 3346 EXPECT_EQ(0, delegate->scroll_y()); |
| 3347 EXPECT_EQ(gfx::Point(0, 0).ToString(), |
| 3348 delegate->scroll_begin_position().ToString()); |
| 3349 } |
3323 | 3350 |
3324 // Start consuming touch-move events again. | 3351 // Start consuming touch-move events again. |
3325 delegate->set_consume_touch_move(true); | 3352 delegate->set_consume_touch_move(true); |
3326 | 3353 |
3327 // Move some more to generate a few more scroll updates. | 3354 // Move some more to generate a few more scroll updates. |
3328 tes.SendScrollEvent(event_processor(), 110, 211, kTouchId, delegate.get()); | 3355 tes.SendScrollEvent(event_processor(), 110, 211, kTouchId, delegate.get()); |
3329 EXPECT_FALSE(delegate->tap()); | 3356 EXPECT_FALSE(delegate->tap()); |
3330 EXPECT_FALSE(delegate->tap_down()); | 3357 EXPECT_FALSE(delegate->tap_down()); |
3331 EXPECT_FALSE(delegate->tap_cancel()); | 3358 EXPECT_FALSE(delegate->tap_cancel()); |
3332 EXPECT_FALSE(delegate->begin()); | 3359 EXPECT_FALSE(delegate->begin()); |
(...skipping 19 matching lines...) Expand all Loading... |
3352 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 3379 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
3353 kTouchId, tes.LeapForward(50)); | 3380 kTouchId, tes.LeapForward(50)); |
3354 DispatchEventUsingWindowDispatcher(&release); | 3381 DispatchEventUsingWindowDispatcher(&release); |
3355 EXPECT_FALSE(delegate->tap()); | 3382 EXPECT_FALSE(delegate->tap()); |
3356 EXPECT_FALSE(delegate->tap_down()); | 3383 EXPECT_FALSE(delegate->tap_down()); |
3357 EXPECT_FALSE(delegate->tap_cancel()); | 3384 EXPECT_FALSE(delegate->tap_cancel()); |
3358 EXPECT_FALSE(delegate->begin()); | 3385 EXPECT_FALSE(delegate->begin()); |
3359 EXPECT_TRUE(delegate->end()); | 3386 EXPECT_TRUE(delegate->end()); |
3360 EXPECT_FALSE(delegate->scroll_begin()); | 3387 EXPECT_FALSE(delegate->scroll_begin()); |
3361 EXPECT_FALSE(delegate->scroll_update()); | 3388 EXPECT_FALSE(delegate->scroll_update()); |
3362 EXPECT_FALSE(delegate->scroll_end()); | |
3363 EXPECT_FALSE(delegate->fling()); | 3389 EXPECT_FALSE(delegate->fling()); |
| 3390 |
| 3391 if (UsingUnifiedGR()) |
| 3392 EXPECT_TRUE(delegate->scroll_end()); |
| 3393 else |
| 3394 EXPECT_FALSE(delegate->scroll_end()); |
3364 } | 3395 } |
3365 | 3396 |
3366 // Check that appropriate touch events generate double tap gesture events. | 3397 // Check that appropriate touch events generate double tap gesture events. |
3367 TEST_P(GestureRecognizerTest, GestureEventDoubleTap) { | 3398 TEST_P(GestureRecognizerTest, GestureEventDoubleTap) { |
3368 scoped_ptr<GestureEventConsumeDelegate> delegate( | 3399 scoped_ptr<GestureEventConsumeDelegate> delegate( |
3369 new GestureEventConsumeDelegate()); | 3400 new GestureEventConsumeDelegate()); |
3370 const int kWindowWidth = 123; | 3401 const int kWindowWidth = 123; |
3371 const int kWindowHeight = 45; | 3402 const int kWindowHeight = 45; |
3372 const int kTouchId = 2; | 3403 const int kTouchId = 2; |
3373 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 3404 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3691 | 3722 |
3692 delegate->Reset(); | 3723 delegate->Reset(); |
3693 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 3724 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
3694 kTouchId, tes.Now()); | 3725 kTouchId, tes.Now()); |
3695 | 3726 |
3696 delegate->set_consume_touch_move(false); | 3727 delegate->set_consume_touch_move(false); |
3697 DispatchEventUsingWindowDispatcher(&press); | 3728 DispatchEventUsingWindowDispatcher(&press); |
3698 delegate->set_consume_touch_move(true); | 3729 delegate->set_consume_touch_move(true); |
3699 delegate->Reset(); | 3730 delegate->Reset(); |
3700 // Move the touch-point enough so that it would normally be considered a | 3731 // Move the touch-point enough so that it would normally be considered a |
3701 // scroll. But since the touch-moves will be consumed, the scroll should not | 3732 // scroll. But since the touch-moves will be consumed, no scrolling should |
3702 // start. | 3733 // occur. |
| 3734 // With the unified gesture detector, we will receive a scroll begin gesture, |
| 3735 // whereas with the aura gesture recognizer we won't. |
3703 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); | 3736 tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get()); |
3704 EXPECT_FALSE(delegate->tap()); | 3737 EXPECT_FALSE(delegate->tap()); |
3705 EXPECT_FALSE(delegate->tap_down()); | 3738 EXPECT_FALSE(delegate->tap_down()); |
3706 EXPECT_TRUE(delegate->tap_cancel()); | 3739 EXPECT_TRUE(delegate->tap_cancel()); |
3707 EXPECT_FALSE(delegate->begin()); | 3740 EXPECT_FALSE(delegate->begin()); |
3708 EXPECT_FALSE(delegate->scroll_begin()); | |
3709 EXPECT_FALSE(delegate->scroll_update()); | 3741 EXPECT_FALSE(delegate->scroll_update()); |
3710 EXPECT_FALSE(delegate->scroll_end()); | 3742 EXPECT_FALSE(delegate->scroll_end()); |
3711 } | 3743 } |
3712 | 3744 |
3713 TEST_P(GestureRecognizerTest, | 3745 TEST_P(GestureRecognizerTest, |
3714 TransferEventDispatchesTouchCancel) { | 3746 TransferEventDispatchesTouchCancel) { |
3715 scoped_ptr<GestureEventConsumeDelegate> delegate( | 3747 scoped_ptr<GestureEventConsumeDelegate> delegate( |
3716 new GestureEventConsumeDelegate()); | 3748 new GestureEventConsumeDelegate()); |
3717 TimedEvents tes; | 3749 TimedEvents tes; |
3718 const int kWindowWidth = 800; | 3750 const int kWindowWidth = 800; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3897 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), | 3929 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), |
3898 kTouchId, tes.Now()); | 3930 kTouchId, tes.Now()); |
3899 DispatchEventUsingWindowDispatcher(&move1); | 3931 DispatchEventUsingWindowDispatcher(&move1); |
3900 delegate->ReceivedAckPreventDefaulted(); | 3932 delegate->ReceivedAckPreventDefaulted(); |
3901 | 3933 |
3902 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), | 3934 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), |
3903 kTouchId, tes.Now()); | 3935 kTouchId, tes.Now()); |
3904 DispatchEventUsingWindowDispatcher(&move2); | 3936 DispatchEventUsingWindowDispatcher(&move2); |
3905 delegate->ReceivedAck(); | 3937 delegate->ReceivedAck(); |
3906 | 3938 |
3907 EXPECT_FALSE(delegate->scroll_begin()); | 3939 if (UsingUnifiedGR()) { |
3908 EXPECT_FALSE(delegate->scroll_update()); | 3940 // With the unified gesture detector, consuming the first touch move event |
| 3941 // won't prevent all future scrolling. |
| 3942 EXPECT_TRUE(delegate->scroll_begin()); |
| 3943 EXPECT_TRUE(delegate->scroll_update()); |
| 3944 } else { |
| 3945 EXPECT_FALSE(delegate->scroll_begin()); |
| 3946 EXPECT_FALSE(delegate->scroll_update()); |
| 3947 } |
3909 } | 3948 } |
3910 | 3949 |
3911 // Test that consuming the first touch move event of a touch point doesn't | 3950 // Test that consuming the first touch move event of a touch point doesn't |
3912 // prevent pinching once an additional touch has been pressed. | 3951 // prevent pinching once an additional touch has been pressed. |
3913 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) { | 3952 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) { |
3914 // Consuming moves within the touch slop and the the disposition handling of | 3953 // Consuming moves within the touch slop and the the disposition handling of |
3915 // pinch events behave differently between the Unified GR and the Aura GR. | 3954 // pinch events behave differently between the Unified GR and the Aura GR. |
3916 if (UsingUnifiedGR()) | 3955 if (UsingUnifiedGR()) |
3917 return; | 3956 return; |
3918 | 3957 |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4330 EXPECT_TRUE(delegate->show_press()); | 4369 EXPECT_TRUE(delegate->show_press()); |
4331 EXPECT_EQ(0U, delegate->latency_info().latency_components.size()); | 4370 EXPECT_EQ(0U, delegate->latency_info().latency_components.size()); |
4332 } | 4371 } |
4333 | 4372 |
4334 INSTANTIATE_TEST_CASE_P(GestureRecognizer, | 4373 INSTANTIATE_TEST_CASE_P(GestureRecognizer, |
4335 GestureRecognizerTest, | 4374 GestureRecognizerTest, |
4336 ::testing::Bool()); | 4375 ::testing::Bool()); |
4337 | 4376 |
4338 } // namespace test | 4377 } // namespace test |
4339 } // namespace aura | 4378 } // namespace aura |
OLD | NEW |