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

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

Issue 16114003: Don't send touch move to renderer while scrolling (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix the case touch event queue could be empty when GetLatestEvent() is called Created 7 years, 6 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
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/command_line.h"
6 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
7 #include "base/shared_memory.h" 8 #include "base/shared_memory.h"
8 #include "base/timer.h" 9 #include "base/timer.h"
9 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/renderer_host/backing_store.h" 11 #include "content/browser/renderer_host/backing_store.h"
11 #include "content/browser/renderer_host/gesture_event_filter.h" 12 #include "content/browser/renderer_host/gesture_event_filter.h"
12 #include "content/browser/renderer_host/overscroll_controller.h" 13 #include "content/browser/renderer_host/overscroll_controller.h"
13 #include "content/browser/renderer_host/overscroll_controller_delegate.h" 14 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
14 #include "content/browser/renderer_host/render_widget_host_delegate.h" 15 #include "content/browser/renderer_host/render_widget_host_delegate.h"
15 #include "content/browser/renderer_host/tap_suppression_controller.h" 16 #include "content/browser/renderer_host/tap_suppression_controller.h"
16 #include "content/browser/renderer_host/tap_suppression_controller_client.h" 17 #include "content/browser/renderer_host/tap_suppression_controller_client.h"
17 #include "content/browser/renderer_host/test_render_view_host.h" 18 #include "content/browser/renderer_host/test_render_view_host.h"
18 #include "content/browser/renderer_host/touch_event_queue.h" 19 #include "content/browser/renderer_host/touch_event_queue.h"
19 #include "content/common/input_messages.h" 20 #include "content/common/input_messages.h"
20 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
21 #include "content/port/browser/render_widget_host_view_port.h" 22 #include "content/port/browser/render_widget_host_view_port.h"
22 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
26 #include "content/public/browser/notification_types.h" 27 #include "content/public/browser/notification_types.h"
28 #include "content/public/common/content_switches.h"
27 #include "content/public/test/mock_render_process_host.h" 29 #include "content/public/test/mock_render_process_host.h"
28 #include "content/public/test/test_browser_context.h" 30 #include "content/public/test/test_browser_context.h"
29 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
30 #include "ui/base/keycodes/keyboard_codes.h" 32 #include "ui/base/keycodes/keyboard_codes.h"
31 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/screen.h" 34 #include "ui/gfx/screen.h"
33 35
34 #if defined(USE_AURA) 36 #if defined(USE_AURA)
35 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 37 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
36 #include "ui/aura/env.h" 38 #include "ui/aura/env.h"
(...skipping 3633 matching lines...) Expand 10 before | Expand all | Expand 10 after
3670 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); 3672 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
3671 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 3673 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
3672 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize()); 3674 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
3673 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); 3675 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
3674 EXPECT_EQ(1U, process_->sink().message_count()); 3676 EXPECT_EQ(1U, process_->sink().message_count());
3675 } 3677 }
3676 3678
3677 // Tests that when touch-events are dispatched to the renderer, the overscroll 3679 // Tests that when touch-events are dispatched to the renderer, the overscroll
3678 // gesture deals with them correctly. 3680 // gesture deals with them correctly.
3679 TEST_F(RenderWidgetHostTest, OverscrollWithTouchEvents) { 3681 TEST_F(RenderWidgetHostTest, OverscrollWithTouchEvents) {
3682 // The event flow in this test is not the same if touch-cancel-on-scroll is
3683 // enabled. So disable touch-cancel-on-scroll for this test.
3684 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
3685 switches::kTouchCancelOnScroll, "0");
3680 host_->SetupForOverscrollControllerTest(); 3686 host_->SetupForOverscrollControllerTest();
3681 host_->set_debounce_interval_time_ms(10); 3687 host_->set_debounce_interval_time_ms(10);
3682 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 3688 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3683 process_->sink().ClearMessages(); 3689 process_->sink().ClearMessages();
3684 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); 3690 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
3685 view_->Show(); 3691 view_->Show();
3686 3692
3687 // The test sends an intermingled sequence of touch and gesture events. 3693 // The test sends an intermingled sequence of touch and gesture events.
3688 3694
3689 PressTouchPoint(0, 1); 3695 PressTouchPoint(0, 1);
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
4228 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); 4234 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
4229 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode()); 4235 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
4230 4236
4231 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, 4237 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
4232 WebGestureEvent::Touchscreen); 4238 WebGestureEvent::Touchscreen);
4233 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 4239 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
4234 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); 4240 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
4235 process_->sink().ClearMessages(); 4241 process_->sink().ClearMessages();
4236 } 4242 }
4237 4243
4244 // Tests that when scroll starts, fake touch cancel is sent to renderer and
4245 // no touch events are sent to renderer during scrolling.
4246 TEST_F(RenderWidgetHostTest, TouchCancelOnScroll) {
4247 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
4248 switches::kTouchCancelOnScroll, "1");
4249 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
4250 host_->set_debounce_interval_time_ms(0);
4251 process_->sink().ClearMessages();
4252 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
4253 view_->Show();
4254
4255 PressTouchPoint(0, 1);
4256 if (host_->ShouldForwardTouchEvent())
sadrul 2013/06/20 08:51:27 Use EXPECT to verify the expectation, since the st
Yufeng Shen (Slow to review) 2013/06/20 17:56:45 Done.
4257 SendTouchEvent();
4258 EXPECT_EQ(1U, process_->sink().message_count());
4259 process_->sink().ClearMessages();
4260 SendInputEventACK(WebInputEvent::TouchStart,
4261 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
4262
4263 MoveTouchPoint(0, 20, 5);
4264 if (host_->ShouldForwardTouchEvent())
4265 SendTouchEvent();
4266 EXPECT_EQ(1U, process_->sink().message_count());
4267 process_->sink().ClearMessages();
4268 SendInputEventACK(WebInputEvent::TouchMove,
4269 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
4270
4271 // GestureScrollBegin does not trigger touch cancel.
4272 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
4273 WebGestureEvent::Touchscreen);
4274 EXPECT_FALSE(host_->is_scroll_update_in_progress());
4275 EXPECT_EQ(1U, process_->sink().message_count());
4276 SendInputEventACK(WebInputEvent::GestureScrollBegin,
4277 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
4278 process_->sink().ClearMessages();
4279
4280 // Touch event keeps coming.
4281 MoveTouchPoint(0, 30, 5);
4282 if (host_->ShouldForwardTouchEvent())
4283 SendTouchEvent();
4284 EXPECT_EQ(1U, process_->sink().message_count());
4285 process_->sink().ClearMessages();
4286
4287 // GestureScrollUpdate triggers touch cancel.
4288 SimulateGestureScrollUpdateEvent(20, 4, 0);
4289 EXPECT_TRUE(host_->is_scroll_update_in_progress());
4290 // TouchCancel & GestureScrollUpdate are sent.
4291 EXPECT_EQ(2U, process_->sink().message_count());
4292 EXPECT_EQ(GetInputEventFromMessage(*process_->sink().GetMessageAt(0))->type,
4293 WebInputEvent::TouchCancel);
4294 EXPECT_EQ(GetInputEventFromMessage(*process_->sink().GetMessageAt(1))->type,
4295 WebInputEvent::GestureScrollUpdate);
4296 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
4297 // Touch event queue should remain empty since we don't want to process
4298 // acked touch cancel.
4299 EXPECT_EQ(0U, host_->TouchEventQueueSize());
4300
4301 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
4302 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
4303 process_->sink().ClearMessages();
4304
4305 // Touch move event should not reach the renderer when scroll update is in
4306 // progress.
4307 MoveTouchPoint(0, 65, 10);
4308 if (host_->ShouldForwardTouchEvent())
4309 SendTouchEvent();
4310 EXPECT_EQ(0U, process_->sink().message_count());
4311 process_->sink().ClearMessages();
4312
4313 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd,
4314 WebGestureEvent::Touchscreen);
4315 EXPECT_FALSE(host_->is_scroll_update_in_progress());
4316 EXPECT_EQ(1U, process_->sink().message_count());
4317 process_->sink().ClearMessages();
4318 SendInputEventACK(WebInputEvent::GestureScrollEnd,
4319 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
4320
4321 // Now touch events should come through to renderer.
4322 MoveTouchPoint(0, 80, 10);
4323 if (host_->ShouldForwardTouchEvent())
4324 SendTouchEvent();
4325 EXPECT_EQ(1U, process_->sink().message_count());
4326 EXPECT_EQ(GetInputEventFromMessage(*process_->sink().GetMessageAt(0))->type,
4327 WebInputEvent::TouchMove);
4328 process_->sink().ClearMessages();
4329 }
4238 } // namespace content 4330 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698