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