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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 15742013: overscroll: Do not overscroll if the beginning of a scroll was consumed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/shared_memory.h" 7 #include "base/shared_memory.h"
8 #include "base/timer.h" 8 #include "base/timer.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/renderer_host/backing_store.h" 10 #include "content/browser/renderer_host/backing_store.h"
(...skipping 3108 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 SimulateWheelEvent(0, -5, 0, true); // sent directly 3119 SimulateWheelEvent(0, -5, 0, true); // sent directly
3120 SimulateWheelEvent(0, -1, 0, true); // enqueued 3120 SimulateWheelEvent(0, -1, 0, true); // enqueued
3121 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event 3121 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
3122 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event 3122 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
3123 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event 3123 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
3124 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers 3124 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
3125 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); 3125 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3126 EXPECT_EQ(1U, process_->sink().message_count()); 3126 EXPECT_EQ(1U, process_->sink().message_count());
3127 process_->sink().ClearMessages(); 3127 process_->sink().ClearMessages();
3128 3128
3129 // Receive ACK the first wheel event as processed. 3129 // Receive ACK the first wheel event as not processed.
3130 SendInputEventACK(WebInputEvent::MouseWheel, 3130 SendInputEventACK(WebInputEvent::MouseWheel,
3131 INPUT_EVENT_ACK_STATE_CONSUMED); 3131 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3132 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); 3132 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3133 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 3133 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3134 EXPECT_EQ(1U, process_->sink().message_count()); 3134 EXPECT_EQ(1U, process_->sink().message_count());
3135 process_->sink().ClearMessages(); 3135 process_->sink().ClearMessages();
3136 3136
3137 // Receive ACK for the second (coalesced) event as not processed. This will 3137 // Receive ACK for the second (coalesced) event as not processed. This will
3138 // start a back navigation. However, this will also cause the queued next 3138 // start a back navigation. However, this will also cause the queued next
3139 // event to be sent to the renderer. But since overscroll navigation has 3139 // event to be sent to the renderer. But since overscroll navigation has
3140 // started, that event will also be included in the overscroll computation 3140 // started, that event will also be included in the overscroll computation
3141 // instead of being sent to the renderer. So the result will be an overscroll 3141 // instead of being sent to the renderer. So the result will be an overscroll
3142 // back navigation, and no event will be sent to the renderer. 3142 // back navigation, and no event will be sent to the renderer.
3143 SendInputEventACK(WebInputEvent::MouseWheel, 3143 SendInputEventACK(WebInputEvent::MouseWheel,
3144 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 3144 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3145 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode()); 3145 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
3146 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode()); 3146 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode());
3147 EXPECT_EQ(-75.f, host_->overscroll_delta_x()); 3147 EXPECT_EQ(-75.f, host_->overscroll_delta_x());
3148 EXPECT_EQ(-25.f, host_->overscroll_delegate()->delta_x()); 3148 EXPECT_EQ(-25.f, host_->overscroll_delegate()->delta_x());
3149 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y()); 3149 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
3150 EXPECT_EQ(0U, process_->sink().message_count()); 3150 EXPECT_EQ(0U, process_->sink().message_count());
3151 3151
3152 // Send a mouse-move event. This should cancel the overscroll navigation. 3152 // Send a mouse-move event. This should cancel the overscroll navigation.
3153 SimulateMouseMove(5, 10, 0); 3153 SimulateMouseMove(5, 10, 0);
3154 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); 3154 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3155 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 3155 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3156 } 3156 }
3157 3157
3158 // Tests that if some scroll events are consumed towards the start, then
3159 // subsequent scrolls do not overscroll.
3160 TEST_F(RenderWidgetHostTest, WheelScrollConsumedDoNotOverscroll) {
3161 host_->SetupForOverscrollControllerTest();
3162 process_->sink().ClearMessages();
3163
3164 // Simulate wheel events.
3165 SimulateWheelEvent(0, -5, 0, true); // sent directly
3166 SimulateWheelEvent(0, -1, 0, true); // enqueued
3167 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
3168 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
3169 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
3170 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
3171 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3172 EXPECT_EQ(1U, process_->sink().message_count());
3173 process_->sink().ClearMessages();
3174
3175 // Receive ACK the first wheel event as processed.
3176 SendInputEventACK(WebInputEvent::MouseWheel,
3177 INPUT_EVENT_ACK_STATE_CONSUMED);
3178 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3179 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3180 EXPECT_EQ(1U, process_->sink().message_count());
3181 process_->sink().ClearMessages();
3182
3183 // Receive ACK for the second (coalesced) event as not processed. This should
3184 // not initiate overscroll, since the beginning of the scroll has been
3185 // consumed. The queued event with different modifiers should be sent to the
3186 // renderer.
3187 SendInputEventACK(WebInputEvent::MouseWheel,
3188 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3189 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3190 EXPECT_EQ(1U, process_->sink().message_count());
3191
3192 process_->sink().ClearMessages();
3193 SendInputEventACK(WebInputEvent::MouseWheel,
3194 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3195 EXPECT_EQ(0U, process_->sink().message_count());
3196 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3197
3198 // Indicate the end of the scrolling from the touchpad.
3199 SimulateGestureFlingStartEvent(-1200.f, 0.f, WebGestureEvent::Touchpad);
3200 EXPECT_EQ(1U, process_->sink().message_count());
3201
3202 // Start another scroll. This time, do not consume any scroll events.
3203 process_->sink().ClearMessages();
3204 SimulateWheelEvent(0, -5, 0, true); // sent directly
3205 SimulateWheelEvent(0, -1, 0, true); // enqueued
3206 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
3207 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
3208 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
3209 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
3210 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3211 EXPECT_EQ(1U, process_->sink().message_count());
3212 process_->sink().ClearMessages();
3213
3214 // Receive ACK for the first wheel and the subsequent coalesced event as not
3215 // processed. This should start a back-overscroll.
3216 SendInputEventACK(WebInputEvent::MouseWheel,
3217 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3218 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3219 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3220 EXPECT_EQ(1U, process_->sink().message_count());
3221 process_->sink().ClearMessages();
3222 SendInputEventACK(WebInputEvent::MouseWheel,
3223 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3224 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
3225 }
3226
3158 // Tests that wheel-scrolling correctly turns overscroll on and off. 3227 // Tests that wheel-scrolling correctly turns overscroll on and off.
3159 TEST_F(RenderWidgetHostTest, WheelScrollOverscrollToggle) { 3228 TEST_F(RenderWidgetHostTest, WheelScrollOverscrollToggle) {
3160 host_->SetupForOverscrollControllerTest(); 3229 host_->SetupForOverscrollControllerTest();
3161 process_->sink().ClearMessages(); 3230 process_->sink().ClearMessages();
3162 3231
3163 // Send a wheel event. ACK the event as not processed. This should not 3232 // Send a wheel event. ACK the event as not processed. This should not
3164 // initiate an overscroll gesture since it doesn't cross the threshold yet. 3233 // initiate an overscroll gesture since it doesn't cross the threshold yet.
3165 SimulateWheelEvent(10, -5, 0, true); 3234 SimulateWheelEvent(10, -5, 0, true);
3166 EXPECT_EQ(1U, process_->sink().message_count()); 3235 EXPECT_EQ(1U, process_->sink().message_count());
3167 SendInputEventACK(WebInputEvent::MouseWheel, 3236 SendInputEventACK(WebInputEvent::MouseWheel,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
3367 // controller. This also tests that the overscroll controller and the 3436 // controller. This also tests that the overscroll controller and the
3368 // gesture-event filter play nice with each other. 3437 // gesture-event filter play nice with each other.
3369 TEST_F(RenderWidgetHostTest, GestureScrollOverscrolls) { 3438 TEST_F(RenderWidgetHostTest, GestureScrollOverscrolls) {
3370 // Turn off debounce handling for test isolation. 3439 // Turn off debounce handling for test isolation.
3371 host_->SetupForOverscrollControllerTest(); 3440 host_->SetupForOverscrollControllerTest();
3372 host_->set_debounce_interval_time_ms(0); 3441 host_->set_debounce_interval_time_ms(0);
3373 process_->sink().ClearMessages(); 3442 process_->sink().ClearMessages();
3374 3443
3375 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 3444 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
3376 WebGestureEvent::Touchscreen); 3445 WebGestureEvent::Touchscreen);
3377 SimulateGestureScrollUpdateEvent(8, -5, 0);
3378
3379 // ACK both events as being processed.
3380 SendInputEventACK(WebInputEvent::GestureScrollBegin, 3446 SendInputEventACK(WebInputEvent::GestureScrollBegin,
3381 INPUT_EVENT_ACK_STATE_CONSUMED); 3447 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3382 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
3383 INPUT_EVENT_ACK_STATE_CONSUMED);
3384 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); 3448 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3385 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 3449 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3386 3450
3387 // Send another gesture event and ACK as not being processed. This should 3451 // Send another gesture event and ACK as not being processed. This should
3388 // initiate the navigation gesture. 3452 // initiate the navigation gesture.
3389 SimulateGestureScrollUpdateEvent(55, -5, 0); 3453 SimulateGestureScrollUpdateEvent(55, -5, 0);
3390 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 3454 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
3391 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 3455 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3392 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode()); 3456 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
3393 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); 3457 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
(...skipping 21 matching lines...) Expand all
3415 // the event to the renderer. The gesture-event filter should receive this 3479 // the event to the renderer. The gesture-event filter should receive this
3416 // event. 3480 // event.
3417 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, 3481 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
3418 WebGestureEvent::Touchscreen); 3482 WebGestureEvent::Touchscreen);
3419 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); 3483 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3420 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 3484 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3421 EXPECT_EQ(1U, process_->sink().message_count()); 3485 EXPECT_EQ(1U, process_->sink().message_count());
3422 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize()); 3486 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
3423 } 3487 }
3424 3488
3489 // Tests that if the page is scrolled because of a scroll-gesture, then that
3490 // particular scroll sequence never generates overscroll, even if there is no
3491 // content to scroll on the page anymore.
3492 TEST_F(RenderWidgetHostTest, GestureScrollConsumedDoNotOverscroll) {
3493 // Turn off debounce handling for test isolation.
3494 host_->SetupForOverscrollControllerTest();
3495 host_->set_debounce_interval_time_ms(0);
3496 process_->sink().ClearMessages();
3497
3498 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
3499 WebGestureEvent::Touchscreen);
3500 SimulateGestureScrollUpdateEvent(8, -5, 0);
3501
3502 // ACK both events as being processed.
3503 SendInputEventACK(WebInputEvent::GestureScrollBegin,
3504 INPUT_EVENT_ACK_STATE_CONSUMED);
3505 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
3506 INPUT_EVENT_ACK_STATE_CONSUMED);
3507 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3508 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3509
3510 // Send another gesture event and ACK as not being processed. This should
3511 // not initiate overscroll because the beginning of the scroll event did
3512 // scroll some content on the page.
3513 SimulateGestureScrollUpdateEvent(55, -5, 0);
3514 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
3515 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3516 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3517 }
3518
3425 // Tests that the overscroll controller plays nice with touch-scrolls and the 3519 // Tests that the overscroll controller plays nice with touch-scrolls and the
3426 // gesture event filter with debounce filtering turned on. 3520 // gesture event filter with debounce filtering turned on.
3427 TEST_F(RenderWidgetHostTest, GestureScrollDebounceOverscrolls) { 3521 TEST_F(RenderWidgetHostTest, GestureScrollDebounceOverscrolls) {
3428 host_->SetupForOverscrollControllerTest(); 3522 host_->SetupForOverscrollControllerTest();
3429 host_->set_debounce_interval_time_ms(100); 3523 host_->set_debounce_interval_time_ms(100);
3430 process_->sink().ClearMessages(); 3524 process_->sink().ClearMessages();
3431 3525
3432 // Start scrolling. Receive ACK as it being processed. 3526 // Start scrolling. Receive ACK as it being processed.
3433 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 3527 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
3434 WebGestureEvent::Touchscreen); 3528 WebGestureEvent::Touchscreen);
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
3871 EXPECT_EQ(1U, process_->sink().message_count()); 3965 EXPECT_EQ(1U, process_->sink().message_count());
3872 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 3966 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
3873 InputMsg_HandleInputEvent::ID)); 3967 InputMsg_HandleInputEvent::ID));
3874 process_->sink().ClearMessages(); 3968 process_->sink().ClearMessages();
3875 3969
3876 // Check that the correct unhandled wheel event was received. 3970 // Check that the correct unhandled wheel event was received.
3877 EXPECT_EQ(view_->unhandled_wheel_event().deltaY, -5); 3971 EXPECT_EQ(view_->unhandled_wheel_event().deltaY, -5);
3878 } 3972 }
3879 3973
3880 } // namespace content 3974 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698