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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/shared_memory.h"
9 #include "base/timer/timer.h"
10 #include "content/browser/browser_thread_impl.h"
11 #include "content/browser/renderer_host/backing_store.h"
12 #include "content/browser/renderer_host/input/gesture_event_queue.h"
13 #include "content/browser/renderer_host/input/input_router_impl.h"
14 #include "content/browser/renderer_host/input/tap_suppression_controller.h"
15 #include "content/browser/renderer_host/input/tap_suppression_controller_client.h"
16 #include "content/browser/renderer_host/input/touch_event_queue.h"
17 #include "content/browser/renderer_host/overscroll_controller.h"
18 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
19 #include "content/browser/renderer_host/render_widget_host_delegate.h"
20 #include "content/common/input/synthetic_web_input_event_builders.h"
21 #include "content/common/input_messages.h"
22 #include "content/common/view_messages.h"
23 #include "content/port/browser/render_widget_host_view_port.h"
24 #include "content/public/test/mock_render_process_host.h"
25 #include "content/public/test/test_browser_context.h"
26 #include "content/test/test_render_view_host.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/events/keycodes/keyboard_codes.h"
29 #include "ui/gfx/canvas.h"
30 #include "ui/gfx/screen.h"
33 #include "content/browser/compositor/image_transport_factory.h"
34 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
35 #include "ui/aura/env.h"
36 #include "ui/aura/test/test_screen.h"
37 #include "ui/compositor/test/test_context_factory.h"
40 #if defined(OS_WIN) || defined(USE_AURA)
41 #include "content/browser/renderer_host/ui_events_helper.h"
42 #include "ui/events/event.h"
45 using base::TimeDelta;
46 using blink::WebGestureEvent;
47 using blink::WebInputEvent;
48 using blink::WebKeyboardEvent;
49 using blink::WebMouseWheelEvent;
50 using blink::WebTouchEvent;
51 using blink::WebTouchPoint;
55 // TestOverscrollDelegate ------------------------------------------------------
57 class TestOverscrollDelegate : public OverscrollControllerDelegate {
59 explicit TestOverscrollDelegate(RenderWidgetHostView* view)
61 current_mode_(OVERSCROLL_NONE),
62 completed_mode_(OVERSCROLL_NONE),
67 virtual ~TestOverscrollDelegate() {}
69 OverscrollMode current_mode() const { return current_mode_; }
70 OverscrollMode completed_mode() const { return completed_mode_; }
71 float delta_x() const { return delta_x_; }
72 float delta_y() const { return delta_y_; }
75 current_mode_ = OVERSCROLL_NONE;
76 completed_mode_ = OVERSCROLL_NONE;
77 delta_x_ = delta_y_ = 0.f;
81 // Overridden from OverscrollControllerDelegate:
82 virtual gfx::Rect GetVisibleBounds() const OVERRIDE {
83 return view_->IsShowing() ? view_->GetViewBounds() : gfx::Rect();
86 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE {
91 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE {
92 EXPECT_EQ(current_mode_, overscroll_mode);
93 completed_mode_ = overscroll_mode;
94 current_mode_ = OVERSCROLL_NONE;
97 virtual void OnOverscrollModeChange(OverscrollMode old_mode,
98 OverscrollMode new_mode) OVERRIDE {
99 EXPECT_EQ(current_mode_, old_mode);
100 current_mode_ = new_mode;
101 delta_x_ = delta_y_ = 0.f;
104 RenderWidgetHostView* view_;
105 OverscrollMode current_mode_;
106 OverscrollMode completed_mode_;
110 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate);
113 // MockInputRouter -------------------------------------------------------------
115 class MockInputRouter : public InputRouter {
117 explicit MockInputRouter(InputRouterClient* client)
118 : send_event_called_(false),
119 sent_mouse_event_(false),
120 sent_wheel_event_(false),
121 sent_keyboard_event_(false),
122 sent_gesture_event_(false),
123 send_touch_event_not_cancelled_(false),
124 message_received_(false),
127 virtual ~MockInputRouter() {}
130 virtual void Flush() OVERRIDE {
131 flush_called_ = true;
133 virtual bool SendInput(scoped_ptr<IPC::Message> message) OVERRIDE {
134 send_event_called_ = true;
137 virtual void SendMouseEvent(
138 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE {
139 sent_mouse_event_ = true;
141 virtual void SendWheelEvent(
142 const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE {
143 sent_wheel_event_ = true;
145 virtual void SendKeyboardEvent(
146 const NativeWebKeyboardEvent& key_event,
147 const ui::LatencyInfo& latency_info,
148 bool is_shortcut) OVERRIDE {
149 sent_keyboard_event_ = true;
151 virtual void SendGestureEvent(
152 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE {
153 sent_gesture_event_ = true;
155 virtual void SendTouchEvent(
156 const TouchEventWithLatencyInfo& touch_event) OVERRIDE {
157 send_touch_event_not_cancelled_ =
158 client_->FilterInputEvent(touch_event.event, touch_event.latency) ==
159 INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
161 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE {
165 virtual bool ShouldForwardTouchEvent() const OVERRIDE { return true; }
166 virtual void OnViewUpdated(int view_flags) OVERRIDE {}
169 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
170 message_received_ = true;
175 bool send_event_called_;
176 bool sent_mouse_event_;
177 bool sent_wheel_event_;
178 bool sent_keyboard_event_;
179 bool sent_gesture_event_;
180 bool send_touch_event_not_cancelled_;
181 bool message_received_;
184 InputRouterClient* client_;
186 DISALLOW_COPY_AND_ASSIGN(MockInputRouter);
189 // MockRenderWidgetHost ----------------------------------------------------
191 class MockRenderWidgetHost : public RenderWidgetHostImpl {
193 MockRenderWidgetHost(
194 RenderWidgetHostDelegate* delegate,
195 RenderProcessHost* process,
197 : RenderWidgetHostImpl(delegate, process, routing_id, false),
198 unresponsive_timer_fired_(false) {
199 input_router_impl_ = static_cast<InputRouterImpl*>(input_router_.get());
202 // Allow poking at a few private members.
203 using RenderWidgetHostImpl::OnUpdateRect;
204 using RenderWidgetHostImpl::RendererExited;
205 using RenderWidgetHostImpl::last_requested_size_;
206 using RenderWidgetHostImpl::is_hidden_;
207 using RenderWidgetHostImpl::resize_ack_pending_;
208 using RenderWidgetHostImpl::input_router_;
210 bool unresponsive_timer_fired() const {
211 return unresponsive_timer_fired_;
214 void set_hung_renderer_delay_ms(int delay_ms) {
215 hung_renderer_delay_ms_ = delay_ms;
218 unsigned GestureEventLastQueueEventSize() const {
219 return gesture_event_queue()->coalesced_gesture_events_.size();
222 WebGestureEvent GestureEventSecondFromLastQueueEvent() const {
223 return gesture_event_queue()->coalesced_gesture_events_.at(
224 GestureEventLastQueueEventSize() - 2).event;
227 WebGestureEvent GestureEventLastQueueEvent() const {
228 return gesture_event_queue()->coalesced_gesture_events_.back().event;
231 unsigned GestureEventDebouncingQueueSize() const {
232 return gesture_event_queue()->debouncing_deferral_queue_.size();
235 WebGestureEvent GestureEventQueueEventAt(int i) const {
236 return gesture_event_queue()->coalesced_gesture_events_.at(i).event;
239 bool ScrollingInProgress() const {
240 return gesture_event_queue()->scrolling_in_progress_;
243 bool FlingInProgress() const {
244 return gesture_event_queue()->fling_in_progress_;
247 bool WillIgnoreNextACK() const {
248 return gesture_event_queue()->ignore_next_ack_;
251 void SetupForOverscrollControllerTest() {
252 SetOverscrollControllerEnabled(true);
253 overscroll_delegate_.reset(new TestOverscrollDelegate(GetView()));
254 overscroll_controller_->set_delegate(overscroll_delegate_.get());
257 void DisableGestureDebounce() {
258 gesture_event_queue()->set_debounce_enabled_for_testing(false);
261 void set_debounce_interval_time_ms(int delay_ms) {
262 gesture_event_queue()->
263 set_debounce_interval_time_ms_for_testing(delay_ms);
266 bool TouchEventQueueEmpty() const {
267 return touch_event_queue()->empty();
270 bool ScrollStateIsContentScrolling() const {
271 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING;
274 bool ScrollStateIsOverscrolling() const {
275 return scroll_state() == OverscrollController::STATE_OVERSCROLLING;
278 bool ScrollStateIsUnknown() const {
279 return scroll_state() == OverscrollController::STATE_UNKNOWN;
282 OverscrollController::ScrollState scroll_state() const {
283 return overscroll_controller_->scroll_state_;
286 OverscrollMode overscroll_mode() const {
287 return overscroll_controller_->overscroll_mode_;
290 float overscroll_delta_x() const {
291 return overscroll_controller_->overscroll_delta_x_;
294 float overscroll_delta_y() const {
295 return overscroll_controller_->overscroll_delta_y_;
298 TestOverscrollDelegate* overscroll_delegate() {
299 return overscroll_delegate_.get();
302 void SetupForInputRouterTest() {
303 mock_input_router_ = new MockInputRouter(this);
304 input_router_.reset(mock_input_router_);
307 MockInputRouter* mock_input_router() {
308 return mock_input_router_;
312 virtual void NotifyRendererUnresponsive() OVERRIDE {
313 unresponsive_timer_fired_ = true;
316 const TouchEventQueue* touch_event_queue() const {
317 return input_router_impl_->touch_event_queue_.get();
320 const GestureEventQueue* gesture_event_queue() const {
321 return input_router_impl_->gesture_event_queue_.get();
324 GestureEventQueue* gesture_event_queue() {
325 return input_router_impl_->gesture_event_queue_.get();
329 bool unresponsive_timer_fired_;
331 // |input_router_impl_| and |mock_input_router_| are owned by
332 // RenderWidgetHostImpl. The handles below are provided for convenience so
333 // that we don't have to reinterpret_cast it all the time.
334 InputRouterImpl* input_router_impl_;
335 MockInputRouter* mock_input_router_;
337 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_;
339 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost);
344 // RenderWidgetHostProcess -----------------------------------------------------
346 class RenderWidgetHostProcess : public MockRenderProcessHost {
348 explicit RenderWidgetHostProcess(BrowserContext* browser_context)
349 : MockRenderProcessHost(browser_context),
350 current_update_buf_(NULL),
351 update_msg_should_reply_(false),
352 update_msg_reply_flags_(0) {
354 virtual ~RenderWidgetHostProcess() {
355 delete current_update_buf_;
358 void set_update_msg_should_reply(bool reply) {
359 update_msg_should_reply_ = reply;
361 void set_update_msg_reply_flags(int flags) {
362 update_msg_reply_flags_ = flags;
365 // Fills the given update parameters with resonable default values.
366 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params);
368 virtual bool HasConnection() const OVERRIDE { return true; }
371 virtual bool WaitForBackingStoreMsg(int render_widget_id,
372 const base::TimeDelta& max_delay,
373 IPC::Message* msg) OVERRIDE;
375 TransportDIB* current_update_buf_;
377 // Set to true when WaitForBackingStoreMsg should return a successful update
378 // message reply. False implies timeout.
379 bool update_msg_should_reply_;
381 // Indicates the flags that should be sent with a repaint request. This
382 // only has an effect when update_msg_should_reply_ is true.
383 int update_msg_reply_flags_;
385 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess);
388 void RenderWidgetHostProcess::InitUpdateRectParams(
389 ViewHostMsg_UpdateRect_Params* params) {
390 // Create the shared backing store.
391 const int w = 100, h = 100;
392 const size_t pixel_size = w * h * 4;
394 if (!current_update_buf_)
395 current_update_buf_ = TransportDIB::Create(pixel_size, 0);
396 params->bitmap = current_update_buf_->id();
397 params->bitmap_rect = gfx::Rect(0, 0, w, h);
398 params->scroll_delta = gfx::Vector2d();
399 params->copy_rects.push_back(params->bitmap_rect);
400 params->view_size = gfx::Size(w, h);
401 params->flags = update_msg_reply_flags_;
402 params->needs_ack = true;
403 params->scale_factor = 1;
406 bool RenderWidgetHostProcess::WaitForBackingStoreMsg(
407 int render_widget_id,
408 const base::TimeDelta& max_delay,
410 if (!update_msg_should_reply_)
413 // Construct a fake update reply.
414 ViewHostMsg_UpdateRect_Params params;
415 InitUpdateRectParams(¶ms);
417 ViewHostMsg_UpdateRect message(render_widget_id, params);
422 // TestView --------------------------------------------------------------------
424 // This test view allows us to specify the size, and keep track of acked
426 class TestView : public TestRenderWidgetHostView {
428 explicit TestView(RenderWidgetHostImpl* rwh)
429 : TestRenderWidgetHostView(rwh),
430 acked_event_count_(0),
431 gesture_event_type_(-1),
432 use_fake_physical_backing_size_(false),
433 ack_result_(INPUT_EVENT_ACK_STATE_UNKNOWN) {
436 // Sets the bounds returned by GetViewBounds.
437 void set_bounds(const gfx::Rect& bounds) {
441 const WebTouchEvent& acked_event() const { return acked_event_; }
442 int acked_event_count() const { return acked_event_count_; }
443 void ClearAckedEvent() {
444 acked_event_.type = blink::WebInputEvent::Undefined;
445 acked_event_count_ = 0;
448 const WebMouseWheelEvent& unhandled_wheel_event() const {
449 return unhandled_wheel_event_;
451 int gesture_event_type() const { return gesture_event_type_; }
452 InputEventAckState ack_result() const { return ack_result_; }
454 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) {
455 use_fake_physical_backing_size_ = true;
456 mock_physical_backing_size_ = mock_physical_backing_size;
458 void ClearMockPhysicalBackingSize() {
459 use_fake_physical_backing_size_ = false;
462 // RenderWidgetHostView override.
463 virtual gfx::Rect GetViewBounds() const OVERRIDE {
466 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
467 InputEventAckState ack_result) OVERRIDE {
468 acked_event_ = touch.event;
469 ++acked_event_count_;
471 virtual void UnhandledWheelEvent(const WebMouseWheelEvent& event) OVERRIDE {
472 unhandled_wheel_event_ = event;
474 virtual void GestureEventAck(const WebGestureEvent& event,
475 InputEventAckState ack_result) OVERRIDE {
476 gesture_event_type_ = event.type;
477 ack_result_ = ack_result;
479 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE {
480 if (use_fake_physical_backing_size_)
481 return mock_physical_backing_size_;
482 return TestRenderWidgetHostView::GetPhysicalBackingSize();
486 WebMouseWheelEvent unhandled_wheel_event_;
487 WebTouchEvent acked_event_;
488 int acked_event_count_;
489 int gesture_event_type_;
491 bool use_fake_physical_backing_size_;
492 gfx::Size mock_physical_backing_size_;
493 InputEventAckState ack_result_;
495 DISALLOW_COPY_AND_ASSIGN(TestView);
498 // MockRenderWidgetHostDelegate --------------------------------------------
500 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
502 MockRenderWidgetHostDelegate()
503 : prehandle_keyboard_event_(false),
504 prehandle_keyboard_event_called_(false),
505 prehandle_keyboard_event_type_(WebInputEvent::Undefined),
506 unhandled_keyboard_event_called_(false),
507 unhandled_keyboard_event_type_(WebInputEvent::Undefined) {
509 virtual ~MockRenderWidgetHostDelegate() {}
511 // Tests that make sure we ignore keyboard event acknowledgments to events we
512 // didn't send work by making sure we didn't call UnhandledKeyboardEvent().
513 bool unhandled_keyboard_event_called() const {
514 return unhandled_keyboard_event_called_;
517 WebInputEvent::Type unhandled_keyboard_event_type() const {
518 return unhandled_keyboard_event_type_;
521 bool prehandle_keyboard_event_called() const {
522 return prehandle_keyboard_event_called_;
525 WebInputEvent::Type prehandle_keyboard_event_type() const {
526 return prehandle_keyboard_event_type_;
529 void set_prehandle_keyboard_event(bool handle) {
530 prehandle_keyboard_event_ = handle;
534 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
535 bool* is_keyboard_shortcut) OVERRIDE {
536 prehandle_keyboard_event_type_ = event.type;
537 prehandle_keyboard_event_called_ = true;
538 return prehandle_keyboard_event_;
541 virtual void HandleKeyboardEvent(
542 const NativeWebKeyboardEvent& event) OVERRIDE {
543 unhandled_keyboard_event_type_ = event.type;
544 unhandled_keyboard_event_called_ = true;
548 bool prehandle_keyboard_event_;
549 bool prehandle_keyboard_event_called_;
550 WebInputEvent::Type prehandle_keyboard_event_type_;
552 bool unhandled_keyboard_event_called_;
553 WebInputEvent::Type unhandled_keyboard_event_type_;
556 // RenderWidgetHostTest --------------------------------------------------------
558 class RenderWidgetHostTest : public testing::Test {
560 RenderWidgetHostTest()
562 handle_key_press_event_(false),
563 handle_mouse_event_(false) {
565 virtual ~RenderWidgetHostTest() {
568 bool KeyPressEventCallback(const NativeWebKeyboardEvent& /* event */) {
569 return handle_key_press_event_;
571 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) {
572 return handle_mouse_event_;
577 virtual void SetUp() {
578 browser_context_.reset(new TestBrowserContext());
579 delegate_.reset(new MockRenderWidgetHostDelegate());
580 process_ = new RenderWidgetHostProcess(browser_context_.get());
581 #if defined(USE_AURA)
582 ImageTransportFactory::InitializeForUnitTests(
583 scoped_ptr<ui::ContextFactory>(new ui::TestContextFactory));
584 aura::Env::CreateInstance();
585 screen_.reset(aura::TestScreen::Create());
586 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
589 new MockRenderWidgetHost(delegate_.get(), process_, MSG_ROUTING_NONE));
590 view_.reset(new TestView(host_.get()));
591 host_->SetView(view_.get());
594 virtual void TearDown() {
599 browser_context_.reset();
601 #if defined(USE_AURA)
602 aura::Env::DeleteInstance();
604 ImageTransportFactory::Terminate();
607 // Process all pending tasks to avoid leaks.
608 base::MessageLoop::current()->RunUntilIdle();
611 int64 GetLatencyComponentId() {
612 return host_->GetLatencyComponentId();
615 void SendInputEventACK(WebInputEvent::Type type,
616 InputEventAckState ack_result) {
617 scoped_ptr<IPC::Message> response(
618 new InputHostMsg_HandleInputEvent_ACK(0, type, ack_result,
620 host_->OnMessageReceived(*response);
623 void SimulateKeyboardEvent(WebInputEvent::Type type) {
624 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type);
625 NativeWebKeyboardEvent native_event;
626 memcpy(&native_event, &event, sizeof(event));
627 host_->ForwardKeyboardEvent(native_event);
630 void SimulateMouseEvent(WebInputEvent::Type type) {
631 host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type));
634 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type,
635 const ui::LatencyInfo& ui_latency) {
636 host_->ForwardMouseEventWithLatencyInfo(
637 SyntheticWebMouseEventBuilder::Build(type),
641 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) {
642 host_->ForwardWheelEvent(
643 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise));
646 void SimulateWheelEventWithLatencyInfo(float dX,
650 const ui::LatencyInfo& ui_latency) {
651 host_->ForwardWheelEventWithLatencyInfo(
652 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise),
656 void SimulateMouseMove(int x, int y, int modifiers) {
657 host_->ForwardMouseEvent(
658 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove,
664 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) {
665 host_->ForwardWheelEvent(SyntheticWebMouseWheelEventBuilder::Build(phase));
668 // Inject provided synthetic WebGestureEvent instance.
669 void SimulateGestureEventCore(const WebGestureEvent& gesture_event) {
670 host_->ForwardGestureEvent(gesture_event);
673 void SimulateGestureEventCoreWithLatencyInfo(
674 const WebGestureEvent& gesture_event,
675 const ui::LatencyInfo& ui_latency) {
676 host_->ForwardGestureEventWithLatencyInfo(gesture_event, ui_latency);
679 // Inject simple synthetic WebGestureEvent instances.
680 void SimulateGestureEvent(WebInputEvent::Type type,
681 WebGestureEvent::SourceDevice sourceDevice) {
682 SimulateGestureEventCore(
683 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
686 void SimulateGestureEventWithLatencyInfo(
687 WebInputEvent::Type type,
688 WebGestureEvent::SourceDevice sourceDevice,
689 const ui::LatencyInfo& ui_latency) {
690 SimulateGestureEventCoreWithLatencyInfo(
691 SyntheticWebGestureEventBuilder::Build(type, sourceDevice),
695 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
696 SimulateGestureEventCore(
697 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
700 void SimulateGesturePinchUpdateEvent(float scale,
704 SimulateGestureEventCore(
705 SyntheticWebGestureEventBuilder::BuildPinchUpdate(scale,
711 // Inject synthetic GestureFlingStart events.
712 void SimulateGestureFlingStartEvent(
715 WebGestureEvent::SourceDevice sourceDevice) {
716 SimulateGestureEventCore(
717 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
722 // Set the timestamp for the touch-event.
723 void SetTouchTimestamp(base::TimeDelta timestamp) {
724 touch_event_.SetTimestamp(timestamp);
727 // Sends a touch event (irrespective of whether the page has a touch-event
729 void SendTouchEvent() {
730 host_->ForwardTouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo());
732 touch_event_.ResetPoints();
735 int PressTouchPoint(int x, int y) {
736 return touch_event_.PressPoint(x, y);
739 void MoveTouchPoint(int index, int x, int y) {
740 touch_event_.MovePoint(index, x, y);
743 void ReleaseTouchPoint(int index) {
744 touch_event_.ReleasePoint(index);
747 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) {
748 PickleIterator iter(message);
751 if (!message.ReadData(&iter, &data, &data_length))
753 return reinterpret_cast<const WebInputEvent*>(data);
756 base::MessageLoopForUI message_loop_;
758 scoped_ptr<TestBrowserContext> browser_context_;
759 RenderWidgetHostProcess* process_; // Deleted automatically by the widget.
760 scoped_ptr<MockRenderWidgetHostDelegate> delegate_;
761 scoped_ptr<MockRenderWidgetHost> host_;
762 scoped_ptr<TestView> view_;
763 scoped_ptr<gfx::Screen> screen_;
764 bool handle_key_press_event_;
765 bool handle_mouse_event_;
768 SyntheticWebTouchEvent touch_event_;
770 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
773 #if GTEST_HAS_PARAM_TEST
774 // RenderWidgetHostWithSourceTest ----------------------------------------------
776 // This is for tests that are to be run for all source devices.
777 class RenderWidgetHostWithSourceTest
778 : public RenderWidgetHostTest,
779 public testing::WithParamInterface<WebGestureEvent::SourceDevice> {
781 #endif // GTEST_HAS_PARAM_TEST
785 // -----------------------------------------------------------------------------
787 TEST_F(RenderWidgetHostTest, Resize) {
788 // The initial bounds is the empty rect, and the screen info hasn't been sent
789 // yet, so setting it to the same thing shouldn't send the resize message.
790 view_->set_bounds(gfx::Rect());
792 EXPECT_FALSE(host_->resize_ack_pending_);
793 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
795 // Setting the bounds to a "real" rect should send out the notification.
796 // but should not expect ack for empty physical backing size.
797 gfx::Rect original_size(0, 0, 100, 100);
798 process_->sink().ClearMessages();
799 view_->set_bounds(original_size);
800 view_->SetMockPhysicalBackingSize(gfx::Size());
802 EXPECT_FALSE(host_->resize_ack_pending_);
803 EXPECT_EQ(original_size.size(), host_->last_requested_size_);
804 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
806 // Setting the bounds to a "real" rect should send out the notification.
807 // but should not expect ack for only physical backing size change.
808 process_->sink().ClearMessages();
809 view_->ClearMockPhysicalBackingSize();
811 EXPECT_FALSE(host_->resize_ack_pending_);
812 EXPECT_EQ(original_size.size(), host_->last_requested_size_);
813 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
815 // Send out a update that's not a resize ack after setting resize ack pending
816 // flag. This should not clean the resize ack pending flag.
817 process_->sink().ClearMessages();
818 gfx::Rect second_size(0, 0, 110, 110);
819 EXPECT_FALSE(host_->resize_ack_pending_);
820 view_->set_bounds(second_size);
822 EXPECT_TRUE(host_->resize_ack_pending_);
823 ViewHostMsg_UpdateRect_Params params;
824 process_->InitUpdateRectParams(¶ms);
825 host_->OnUpdateRect(params);
826 EXPECT_TRUE(host_->resize_ack_pending_);
827 EXPECT_EQ(second_size.size(), host_->last_requested_size_);
829 // Sending out a new notification should NOT send out a new IPC message since
830 // a resize ACK is pending.
831 gfx::Rect third_size(0, 0, 120, 120);
832 process_->sink().ClearMessages();
833 view_->set_bounds(third_size);
835 EXPECT_TRUE(host_->resize_ack_pending_);
836 EXPECT_EQ(second_size.size(), host_->last_requested_size_);
837 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
839 // Send a update that's a resize ack, but for the original_size we sent. Since
840 // this isn't the second_size, the message handler should immediately send
841 // a new resize message for the new size to the renderer.
842 process_->sink().ClearMessages();
843 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
844 params.view_size = original_size.size();
845 host_->OnUpdateRect(params);
846 EXPECT_TRUE(host_->resize_ack_pending_);
847 EXPECT_EQ(third_size.size(), host_->last_requested_size_);
848 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
850 // Send the resize ack for the latest size.
851 process_->sink().ClearMessages();
852 params.view_size = third_size.size();
853 host_->OnUpdateRect(params);
854 EXPECT_FALSE(host_->resize_ack_pending_);
855 EXPECT_EQ(third_size.size(), host_->last_requested_size_);
856 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
858 // Now clearing the bounds should send out a notification but we shouldn't
859 // expect a resize ack (since the renderer won't ack empty sizes). The message
860 // should contain the new size (0x0) and not the previous one that we skipped
861 process_->sink().ClearMessages();
862 view_->set_bounds(gfx::Rect());
864 EXPECT_FALSE(host_->resize_ack_pending_);
865 EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
866 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
868 // Send a rect that has no area but has either width or height set.
869 process_->sink().ClearMessages();
870 view_->set_bounds(gfx::Rect(0, 0, 0, 30));
872 EXPECT_FALSE(host_->resize_ack_pending_);
873 EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_);
874 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
876 // Set the same size again. It should not be sent again.
877 process_->sink().ClearMessages();
879 EXPECT_FALSE(host_->resize_ack_pending_);
880 EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_);
881 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
883 // A different size should be sent again, however.
884 view_->set_bounds(gfx::Rect(0, 0, 0, 31));
886 EXPECT_FALSE(host_->resize_ack_pending_);
887 EXPECT_EQ(gfx::Size(0, 31), host_->last_requested_size_);
888 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
891 // Test for crbug.com/25097. If a renderer crashes between a resize and the
892 // corresponding update message, we must be sure to clear the resize ack logic.
893 TEST_F(RenderWidgetHostTest, ResizeThenCrash) {
894 // Clear the first Resize message that carried screen info.
895 process_->sink().ClearMessages();
897 // Setting the bounds to a "real" rect should send out the notification.
898 gfx::Rect original_size(0, 0, 100, 100);
899 view_->set_bounds(original_size);
901 EXPECT_TRUE(host_->resize_ack_pending_);
902 EXPECT_EQ(original_size.size(), host_->last_requested_size_);
903 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
905 // Simulate a renderer crash before the update message. Ensure all the
906 // resize ack logic is cleared. Must clear the view first so it doesn't get
908 host_->SetView(NULL);
909 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
910 EXPECT_FALSE(host_->resize_ack_pending_);
911 EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
913 // Reset the view so we can exit the test cleanly.
914 host_->SetView(view_.get());
917 // Tests setting custom background
918 TEST_F(RenderWidgetHostTest, Background) {
919 #if !defined(OS_MACOSX)
920 scoped_ptr<RenderWidgetHostView> view(
921 RenderWidgetHostView::CreateViewForWidget(host_.get()));
922 #if defined(OS_LINUX) || defined(USE_AURA)
923 // TODO(derat): Call this on all platforms: http://crbug.com/102450.
924 // InitAsChild doesn't seem to work if NULL parent is passed on Windows,
925 // which leads to DCHECK failure in RenderWidgetHostView::Destroy.
926 // When you enable this for OS_WIN, enable |view.release()->Destroy()|
928 view->InitAsChild(NULL);
930 host_->SetView(view.get());
932 // Create a checkerboard background to test with.
933 gfx::Canvas canvas(gfx::Size(4, 4), 1.0f, true);
934 canvas.FillRect(gfx::Rect(0, 0, 2, 2), SK_ColorBLACK);
935 canvas.FillRect(gfx::Rect(2, 0, 2, 2), SK_ColorWHITE);
936 canvas.FillRect(gfx::Rect(0, 2, 2, 2), SK_ColorWHITE);
937 canvas.FillRect(gfx::Rect(2, 2, 2, 2), SK_ColorBLACK);
938 const SkBitmap& background =
939 canvas.sk_canvas()->getDevice()->accessBitmap(false);
941 // Set the background and make sure we get back a copy.
942 view->SetBackground(background);
943 EXPECT_EQ(4, view->GetBackground().width());
944 EXPECT_EQ(4, view->GetBackground().height());
945 EXPECT_EQ(background.getSize(), view->GetBackground().getSize());
946 background.lockPixels();
947 view->GetBackground().lockPixels();
948 EXPECT_TRUE(0 == memcmp(background.getPixels(),
949 view->GetBackground().getPixels(),
950 background.getSize()));
951 view->GetBackground().unlockPixels();
952 background.unlockPixels();
954 const IPC::Message* set_background =
955 process_->sink().GetUniqueMessageMatching(ViewMsg_SetBackground::ID);
956 ASSERT_TRUE(set_background);
957 Tuple1<SkBitmap> sent_background;
958 ViewMsg_SetBackground::Read(set_background, &sent_background);
959 EXPECT_EQ(background.getSize(), sent_background.a.getSize());
960 background.lockPixels();
961 sent_background.a.lockPixels();
962 EXPECT_TRUE(0 == memcmp(background.getPixels(),
963 sent_background.a.getPixels(),
964 background.getSize()));
965 sent_background.a.unlockPixels();
966 background.unlockPixels();
968 #if defined(OS_LINUX) || defined(USE_AURA)
969 // See the comment above |InitAsChild(NULL)|.
970 host_->SetView(NULL);
971 static_cast<RenderWidgetHostViewPort*>(view.release())->Destroy();
975 // TODO(port): Mac does not have gfx::Canvas. Maybe we can just change this
976 // test to use SkCanvas directly?
979 // TODO(aa): It would be nice to factor out the painting logic so that we
980 // could test that, but it appears that would mean painting everything twice
981 // since windows HDC structures are opaque.
984 // Tests getting the backing store with the renderer not setting repaint ack
986 TEST_F(RenderWidgetHostTest, GetBackingStore_NoRepaintAck) {
987 // First set the view size to match what the renderer is rendering.
988 ViewHostMsg_UpdateRect_Params params;
989 process_->InitUpdateRectParams(¶ms);
990 view_->set_bounds(gfx::Rect(params.view_size));
992 // We don't currently have a backing store, and if the renderer doesn't send
993 // one in time, we should get nothing.
994 process_->set_update_msg_should_reply(false);
995 BackingStore* backing = host_->GetBackingStore(true);
996 EXPECT_FALSE(backing);
997 // The widget host should have sent a request for a repaint, and there should
999 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
1000 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(
1001 ViewMsg_UpdateRect_ACK::ID));
1003 // Allowing the renderer to reply in time should give is a backing store.
1004 process_->sink().ClearMessages();
1005 process_->set_update_msg_should_reply(true);
1006 process_->set_update_msg_reply_flags(0);
1007 backing = host_->GetBackingStore(true);
1008 EXPECT_TRUE(backing);
1009 // The widget host should NOT have sent a request for a repaint, since there
1010 // was an ACK already pending.
1011 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
1012 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
1013 ViewMsg_UpdateRect_ACK::ID));
1016 // Tests getting the backing store with the renderer sending a repaint ack.
1017 TEST_F(RenderWidgetHostTest, GetBackingStore_RepaintAck) {
1018 // First set the view size to match what the renderer is rendering.
1019 ViewHostMsg_UpdateRect_Params params;
1020 process_->InitUpdateRectParams(¶ms);
1021 view_->set_bounds(gfx::Rect(params.view_size));
1023 // Doing a request request with the update message allowed should work and
1024 // the repaint ack should work.
1025 process_->set_update_msg_should_reply(true);
1026 process_->set_update_msg_reply_flags(
1027 ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK);
1028 BackingStore* backing = host_->GetBackingStore(true);
1029 EXPECT_TRUE(backing);
1030 // We still should not have sent out a repaint request since the last flags
1031 // didn't have the repaint ack set, and the pending flag will still be set.
1032 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
1033 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
1034 ViewMsg_UpdateRect_ACK::ID));
1036 // Asking again for the backing store should just re-use the existing one
1037 // and not send any messagse.
1038 process_->sink().ClearMessages();
1039 backing = host_->GetBackingStore(true);
1040 EXPECT_TRUE(backing);
1041 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
1042 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(
1043 ViewMsg_UpdateRect_ACK::ID));
1046 // Test that we don't paint when we're hidden, but we still send the ACK. Most
1047 // of the rest of the painting is tested in the GetBackingStore* ones.
1048 TEST_F(RenderWidgetHostTest, HiddenPaint) {
1049 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
1050 // Hide the widget, it should have sent out a message to the renderer.
1051 EXPECT_FALSE(host_->is_hidden_);
1053 EXPECT_TRUE(host_->is_hidden_);
1054 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_WasHidden::ID));
1056 // Send it an update as from the renderer.
1057 process_->sink().ClearMessages();
1058 ViewHostMsg_UpdateRect_Params params;
1059 process_->InitUpdateRectParams(¶ms);
1060 host_->OnUpdateRect(params);
1062 // It should have sent out the ACK.
1063 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
1064 ViewMsg_UpdateRect_ACK::ID));
1067 process_->sink().ClearMessages();
1069 EXPECT_FALSE(host_->is_hidden_);
1071 // It should have sent out a restored message with a request to paint.
1072 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching(
1073 ViewMsg_WasShown::ID);
1074 ASSERT_TRUE(restored);
1075 Tuple1<bool> needs_repaint;
1076 ViewMsg_WasShown::Read(restored, &needs_repaint);
1077 EXPECT_TRUE(needs_repaint.a);
1080 TEST_F(RenderWidgetHostTest, IgnoreKeyEventsHandledByRenderer) {
1081 // Simulate a keyboard event.
1082 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
1084 // Make sure we sent the input event to the renderer.
1085 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
1086 InputMsg_HandleInputEvent::ID));
1087 process_->sink().ClearMessages();
1089 // Send the simulated response from the renderer back.
1090 SendInputEventACK(WebInputEvent::RawKeyDown,
1091 INPUT_EVENT_ACK_STATE_CONSUMED);
1092 EXPECT_FALSE(delegate_->unhandled_keyboard_event_called());
1095 TEST_F(RenderWidgetHostTest, PreHandleRawKeyDownEvent) {
1096 // Simluate the situation that the browser handled the key down event during
1097 // pre-handle phrase.
1098 delegate_->set_prehandle_keyboard_event(true);
1099 process_->sink().ClearMessages();
1101 // Simulate a keyboard event.
1102 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
1104 EXPECT_TRUE(delegate_->prehandle_keyboard_event_called());
1105 EXPECT_EQ(WebInputEvent::RawKeyDown,
1106 delegate_->prehandle_keyboard_event_type());
1108 // Make sure the RawKeyDown event is not sent to the renderer.
1109 EXPECT_EQ(0U, process_->sink().message_count());
1111 // The browser won't pre-handle a Char event.
1112 delegate_->set_prehandle_keyboard_event(false);
1114 // Forward the Char event.
1115 SimulateKeyboardEvent(WebInputEvent::Char);
1117 // Make sure the Char event is suppressed.
1118 EXPECT_EQ(0U, process_->sink().message_count());
1120 // Forward the KeyUp event.
1121 SimulateKeyboardEvent(WebInputEvent::KeyUp);
1123 // Make sure only KeyUp was sent to the renderer.
1124 EXPECT_EQ(1U, process_->sink().message_count());
1125 EXPECT_EQ(InputMsg_HandleInputEvent::ID,
1126 process_->sink().GetMessageAt(0)->type());
1127 process_->sink().ClearMessages();
1129 // Send the simulated response from the renderer back.
1130 SendInputEventACK(WebInputEvent::KeyUp,
1131 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1133 EXPECT_TRUE(delegate_->unhandled_keyboard_event_called());
1134 EXPECT_EQ(WebInputEvent::KeyUp, delegate_->unhandled_keyboard_event_type());
1137 TEST_F(RenderWidgetHostTest, UnhandledWheelEvent) {
1138 SimulateWheelEvent(-5, 0, 0, true);
1140 // Make sure we sent the input event to the renderer.
1141 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
1142 InputMsg_HandleInputEvent::ID));
1143 process_->sink().ClearMessages();
1145 // Send the simulated response from the renderer back.
1146 SendInputEventACK(WebInputEvent::MouseWheel,
1147 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1148 EXPECT_EQ(-5, view_->unhandled_wheel_event().deltaX);
1151 TEST_F(RenderWidgetHostTest, UnhandledGestureEvent) {
1152 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1153 WebGestureEvent::Touchscreen);
1155 // Make sure we sent the input event to the renderer.
1156 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
1157 InputMsg_HandleInputEvent::ID));
1158 process_->sink().ClearMessages();
1160 // Send the simulated response from the renderer back.
1161 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1162 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1163 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, view_->gesture_event_type());
1164 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, view_->ack_result());
1167 // Test that the hang monitor timer expires properly if a new timer is started
1168 // while one is in progress (see crbug.com/11007).
1169 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) {
1170 // Start with a short timeout.
1171 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10));
1173 // Immediately try to add a long 30 second timeout.
1174 EXPECT_FALSE(host_->unresponsive_timer_fired());
1175 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30));
1177 // Wait long enough for first timeout and see if it fired.
1178 base::MessageLoop::current()->PostDelayedTask(
1180 base::MessageLoop::QuitClosure(),
1181 TimeDelta::FromMilliseconds(10));
1182 base::MessageLoop::current()->Run();
1183 EXPECT_TRUE(host_->unresponsive_timer_fired());
1186 // Test that the hang monitor timer expires properly if it is started, stopped,
1187 // and then started again.
1188 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) {
1189 // Start with a short timeout, then stop it.
1190 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10));
1191 host_->StopHangMonitorTimeout();
1193 // Start it again to ensure it still works.
1194 EXPECT_FALSE(host_->unresponsive_timer_fired());
1195 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10));
1197 // Wait long enough for first timeout and see if it fired.
1198 base::MessageLoop::current()->PostDelayedTask(
1200 base::MessageLoop::QuitClosure(),
1201 TimeDelta::FromMilliseconds(40));
1202 base::MessageLoop::current()->Run();
1203 EXPECT_TRUE(host_->unresponsive_timer_fired());
1206 // Test that the hang monitor timer expires properly if it is started, then
1207 // updated to a shorter duration.
1208 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) {
1209 // Start with a timeout.
1210 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100));
1212 // Start it again with shorter delay.
1213 EXPECT_FALSE(host_->unresponsive_timer_fired());
1214 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20));
1216 // Wait long enough for the second timeout and see if it fired.
1217 base::MessageLoop::current()->PostDelayedTask(
1219 base::MessageLoop::QuitClosure(),
1220 TimeDelta::FromMilliseconds(25));
1221 base::MessageLoop::current()->Run();
1222 EXPECT_TRUE(host_->unresponsive_timer_fired());
1225 // Test that the hang monitor catches two input events but only one ack.
1226 // This can happen if the second input event causes the renderer to hang.
1227 // This test will catch a regression of crbug.com/111185.
1228 TEST_F(RenderWidgetHostTest, MultipleInputEvents) {
1229 // Configure the host to wait 10ms before considering
1230 // the renderer hung.
1231 host_->set_hung_renderer_delay_ms(10);
1233 // Send two events but only one ack.
1234 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
1235 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
1236 SendInputEventACK(WebInputEvent::RawKeyDown,
1237 INPUT_EVENT_ACK_STATE_CONSUMED);
1239 // Wait long enough for first timeout and see if it fired.
1240 base::MessageLoop::current()->PostDelayedTask(
1242 base::MessageLoop::QuitClosure(),
1243 TimeDelta::FromMilliseconds(40));
1244 base::MessageLoop::current()->Run();
1245 EXPECT_TRUE(host_->unresponsive_timer_fired());
1248 // This test is not valid for Windows because getting the shared memory
1249 // size doesn't work.
1250 #if !defined(OS_WIN)
1251 TEST_F(RenderWidgetHostTest, IncorrectBitmapScaleFactor) {
1252 ViewHostMsg_UpdateRect_Params params;
1253 process_->InitUpdateRectParams(¶ms);
1254 params.scale_factor = params.scale_factor * 2;
1256 EXPECT_EQ(0, process_->bad_msg_count());
1257 host_->OnUpdateRect(params);
1258 EXPECT_EQ(1, process_->bad_msg_count());
1262 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
1264 TEST_F(RenderWidgetHostTest, WheelScrollEventOverscrolls) {
1265 host_->SetupForOverscrollControllerTest();
1266 process_->sink().ClearMessages();
1268 // Simulate wheel events.
1269 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1270 SimulateWheelEvent(-1, 1, 0, true); // enqueued
1271 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1272 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1273 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1274 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1275 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1276 EXPECT_EQ(1U, process_->sink().message_count());
1277 process_->sink().ClearMessages();
1279 // Receive ACK the first wheel event as not processed.
1280 SendInputEventACK(WebInputEvent::MouseWheel,
1281 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1282 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1283 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1284 EXPECT_EQ(1U, process_->sink().message_count());
1285 process_->sink().ClearMessages();
1287 // Receive ACK for the second (coalesced) event as not processed. This will
1288 // start a back navigation. However, this will also cause the queued next
1289 // event to be sent to the renderer. But since overscroll navigation has
1290 // started, that event will also be included in the overscroll computation
1291 // instead of being sent to the renderer. So the result will be an overscroll
1292 // back navigation, and no event will be sent to the renderer.
1293 SendInputEventACK(WebInputEvent::MouseWheel,
1294 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1295 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
1296 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode());
1297 EXPECT_EQ(-81.f, host_->overscroll_delta_x());
1298 EXPECT_EQ(-31.f, host_->overscroll_delegate()->delta_x());
1299 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1300 EXPECT_EQ(0U, process_->sink().message_count());
1302 // Send a mouse-move event. This should cancel the overscroll navigation.
1303 SimulateMouseMove(5, 10, 0);
1304 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1305 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1306 EXPECT_EQ(1U, process_->sink().message_count());
1309 // Tests that if some scroll events are consumed towards the start, then
1310 // subsequent scrolls do not horizontal overscroll.
1311 TEST_F(RenderWidgetHostTest, WheelScrollConsumedDoNotHorizOverscroll) {
1312 host_->SetupForOverscrollControllerTest();
1313 process_->sink().ClearMessages();
1315 // Simulate wheel events.
1316 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1317 SimulateWheelEvent(-1, -1, 0, true); // enqueued
1318 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1319 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1320 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1321 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1322 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1323 EXPECT_EQ(1U, process_->sink().message_count());
1324 process_->sink().ClearMessages();
1326 // Receive ACK the first wheel event as processed.
1327 SendInputEventACK(WebInputEvent::MouseWheel,
1328 INPUT_EVENT_ACK_STATE_CONSUMED);
1329 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1330 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1331 EXPECT_EQ(1U, process_->sink().message_count());
1332 process_->sink().ClearMessages();
1334 // Receive ACK for the second (coalesced) event as not processed. This should
1335 // not initiate overscroll, since the beginning of the scroll has been
1336 // consumed. The queued event with different modifiers should be sent to the
1338 SendInputEventACK(WebInputEvent::MouseWheel,
1339 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1340 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1341 EXPECT_EQ(1U, process_->sink().message_count());
1343 process_->sink().ClearMessages();
1344 SendInputEventACK(WebInputEvent::MouseWheel,
1345 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1346 EXPECT_EQ(0U, process_->sink().message_count());
1347 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1349 // Indicate the end of the scrolling from the touchpad.
1350 SimulateGestureFlingStartEvent(-1200.f, 0.f, WebGestureEvent::Touchpad);
1351 EXPECT_EQ(1U, process_->sink().message_count());
1353 // Start another scroll. This time, do not consume any scroll events.
1354 process_->sink().ClearMessages();
1355 SimulateWheelEvent(0, -5, 0, true); // sent directly
1356 SimulateWheelEvent(0, -1, 0, true); // enqueued
1357 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1358 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1359 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1360 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1361 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1362 EXPECT_EQ(1U, process_->sink().message_count());
1363 process_->sink().ClearMessages();
1365 // Receive ACK for the first wheel and the subsequent coalesced event as not
1366 // processed. This should start a back-overscroll.
1367 SendInputEventACK(WebInputEvent::MouseWheel,
1368 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1369 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1370 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1371 EXPECT_EQ(1U, process_->sink().message_count());
1372 process_->sink().ClearMessages();
1373 SendInputEventACK(WebInputEvent::MouseWheel,
1374 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1375 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
1378 // Tests that wheel-scrolling correctly turns overscroll on and off.
1379 TEST_F(RenderWidgetHostTest, WheelScrollOverscrollToggle) {
1380 host_->SetupForOverscrollControllerTest();
1381 process_->sink().ClearMessages();
1383 // Send a wheel event. ACK the event as not processed. This should not
1384 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1385 SimulateWheelEvent(10, 0, 0, true);
1386 EXPECT_EQ(1U, process_->sink().message_count());
1387 SendInputEventACK(WebInputEvent::MouseWheel,
1388 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1389 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1390 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1391 process_->sink().ClearMessages();
1393 // Scroll some more so as to not overscroll.
1394 SimulateWheelEvent(10, 0, 0, true);
1395 EXPECT_EQ(1U, process_->sink().message_count());
1396 SendInputEventACK(WebInputEvent::MouseWheel,
1397 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1398 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1399 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1400 process_->sink().ClearMessages();
1402 // Scroll some more to initiate an overscroll.
1403 SimulateWheelEvent(40, 0, 0, true);
1404 EXPECT_EQ(1U, process_->sink().message_count());
1405 SendInputEventACK(WebInputEvent::MouseWheel,
1406 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1407 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1408 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1409 EXPECT_EQ(60.f, host_->overscroll_delta_x());
1410 EXPECT_EQ(10.f, host_->overscroll_delegate()->delta_x());
1411 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1412 process_->sink().ClearMessages();
1414 // Scroll in the reverse direction enough to abort the overscroll.
1415 SimulateWheelEvent(-20, 0, 0, true);
1416 EXPECT_EQ(0U, process_->sink().message_count());
1417 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1418 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1420 // Continue to scroll in the reverse direction.
1421 SimulateWheelEvent(-20, 0, 0, true);
1422 EXPECT_EQ(1U, process_->sink().message_count());
1423 SendInputEventACK(WebInputEvent::MouseWheel,
1424 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1425 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1426 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1427 process_->sink().ClearMessages();
1429 // Continue to scroll in the reverse direction enough to initiate overscroll
1430 // in that direction.
1431 SimulateWheelEvent(-55, 0, 0, true);
1432 EXPECT_EQ(1U, process_->sink().message_count());
1433 SendInputEventACK(WebInputEvent::MouseWheel,
1434 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1435 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
1436 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode());
1437 EXPECT_EQ(-75.f, host_->overscroll_delta_x());
1438 EXPECT_EQ(-25.f, host_->overscroll_delegate()->delta_x());
1439 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1442 TEST_F(RenderWidgetHostTest, ScrollEventsOverscrollWithFling) {
1443 host_->SetupForOverscrollControllerTest();
1444 process_->sink().ClearMessages();
1446 // Send a wheel event. ACK the event as not processed. This should not
1447 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1448 SimulateWheelEvent(10, 0, 0, true);
1449 EXPECT_EQ(1U, process_->sink().message_count());
1450 SendInputEventACK(WebInputEvent::MouseWheel,
1451 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1452 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1453 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1454 process_->sink().ClearMessages();
1456 // Scroll some more so as to not overscroll.
1457 SimulateWheelEvent(20, 0, 0, true);
1458 EXPECT_EQ(1U, process_->sink().message_count());
1459 SendInputEventACK(WebInputEvent::MouseWheel,
1460 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1461 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1462 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1463 process_->sink().ClearMessages();
1465 // Scroll some more to initiate an overscroll.
1466 SimulateWheelEvent(30, 0, 0, true);
1467 EXPECT_EQ(1U, process_->sink().message_count());
1468 SendInputEventACK(WebInputEvent::MouseWheel,
1469 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1470 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1471 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1472 EXPECT_EQ(60.f, host_->overscroll_delta_x());
1473 EXPECT_EQ(10.f, host_->overscroll_delegate()->delta_x());
1474 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1475 process_->sink().ClearMessages();
1476 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1478 // Send a fling start, but with a small velocity, so that the overscroll is
1479 // aborted. The fling should proceed to the renderer, through the gesture
1481 SimulateGestureFlingStartEvent(0.f, 0.1f, WebGestureEvent::Touchpad);
1482 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1483 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1484 EXPECT_EQ(1U, process_->sink().message_count());
1487 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
1488 // the zero-velocity fling does not reach the renderer.
1489 TEST_F(RenderWidgetHostTest, ScrollEventsOverscrollWithZeroFling) {
1490 host_->SetupForOverscrollControllerTest();
1491 process_->sink().ClearMessages();
1493 // Send a wheel event. ACK the event as not processed. This should not
1494 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1495 SimulateWheelEvent(10, 0, 0, true);
1496 EXPECT_EQ(1U, process_->sink().message_count());
1497 SendInputEventACK(WebInputEvent::MouseWheel,
1498 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1499 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1500 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1501 process_->sink().ClearMessages();
1503 // Scroll some more so as to not overscroll.
1504 SimulateWheelEvent(20, 0, 0, true);
1505 EXPECT_EQ(1U, process_->sink().message_count());
1506 SendInputEventACK(WebInputEvent::MouseWheel,
1507 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1508 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1509 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1510 process_->sink().ClearMessages();
1512 // Scroll some more to initiate an overscroll.
1513 SimulateWheelEvent(30, 0, 0, true);
1514 EXPECT_EQ(1U, process_->sink().message_count());
1515 SendInputEventACK(WebInputEvent::MouseWheel,
1516 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1517 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1518 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1519 EXPECT_EQ(60.f, host_->overscroll_delta_x());
1520 EXPECT_EQ(10.f, host_->overscroll_delegate()->delta_x());
1521 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1522 process_->sink().ClearMessages();
1523 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1525 // Send a fling start, but with a small velocity, so that the overscroll is
1526 // aborted. The fling should proceed to the renderer, through the gesture
1528 SimulateGestureFlingStartEvent(10.f, 0.f, WebGestureEvent::Touchpad);
1529 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1530 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1531 EXPECT_EQ(1U, process_->sink().message_count());
1534 // Tests that a fling in the opposite direction of the overscroll cancels the
1535 // overscroll nav instead of completing it.
1536 TEST_F(RenderWidgetHostTest, ReverseFlingCancelsOverscroll) {
1537 host_->SetupForOverscrollControllerTest();
1538 host_->DisableGestureDebounce();
1539 process_->sink().ClearMessages();
1540 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
1544 // Start and end a gesture in the same direction without processing the
1545 // gesture events in the renderer. This should initiate and complete an
1546 // overscroll navigation.
1547 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1548 WebGestureEvent::Touchscreen);
1549 SimulateGestureScrollUpdateEvent(300, -5, 0);
1550 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1551 INPUT_EVENT_ACK_STATE_CONSUMED);
1552 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1553 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1554 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1555 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1556 process_->sink().ClearMessages();
1558 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1559 WebGestureEvent::Touchscreen);
1560 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
1561 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1562 EXPECT_EQ(1U, process_->sink().message_count());
1563 SendInputEventACK(WebInputEvent::GestureScrollEnd,
1564 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1568 // Start over, except instead of ending the gesture with ScrollEnd, end it
1569 // with a FlingStart, with velocity in the reverse direction. This should
1570 // initiate an overscroll navigation, but it should be cancelled because of
1571 // the fling in the opposite direction.
1572 host_->overscroll_delegate()->Reset();
1573 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1574 WebGestureEvent::Touchscreen);
1575 SimulateGestureScrollUpdateEvent(-300, -5, 0);
1576 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1577 INPUT_EVENT_ACK_STATE_CONSUMED);
1578 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1579 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1580 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
1581 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode());
1582 process_->sink().ClearMessages();
1584 SimulateGestureFlingStartEvent(100, 0, WebGestureEvent::Touchscreen);
1585 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
1586 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1587 EXPECT_EQ(1U, process_->sink().message_count());
1591 // Tests that touch-scroll events are handled correctly by the overscroll
1592 // controller. This also tests that the overscroll controller and the
1593 // gesture-event filter play nice with each other.
1594 TEST_F(RenderWidgetHostTest, GestureScrollOverscrolls) {
1595 // Turn off debounce handling for test isolation.
1596 host_->SetupForOverscrollControllerTest();
1597 host_->DisableGestureDebounce();
1598 process_->sink().ClearMessages();
1600 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1601 WebGestureEvent::Touchscreen);
1602 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1603 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1604 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1605 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1607 // Send another gesture event and ACK as not being processed. This should
1608 // initiate the navigation gesture.
1609 SimulateGestureScrollUpdateEvent(55, -5, 0);
1610 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1611 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1612 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1613 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1614 EXPECT_EQ(55.f, host_->overscroll_delta_x());
1615 EXPECT_EQ(-5.f, host_->overscroll_delta_y());
1616 EXPECT_EQ(5.f, host_->overscroll_delegate()->delta_x());
1617 EXPECT_EQ(-5.f, host_->overscroll_delegate()->delta_y());
1618 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1619 process_->sink().ClearMessages();
1621 // Send another gesture update event. This event should be consumed by the
1622 // controller, and not be forwarded to the renderer. The gesture-event filter
1623 // should not also receive this event.
1624 SimulateGestureScrollUpdateEvent(10, -5, 0);
1625 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1626 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1627 EXPECT_EQ(65.f, host_->overscroll_delta_x());
1628 EXPECT_EQ(-10.f, host_->overscroll_delta_y());
1629 EXPECT_EQ(15.f, host_->overscroll_delegate()->delta_x());
1630 EXPECT_EQ(-10.f, host_->overscroll_delegate()->delta_y());
1631 EXPECT_EQ(0U, process_->sink().message_count());
1632 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1634 // Now send a scroll end. This should cancel the overscroll gesture, and send
1635 // the event to the renderer. The gesture-event filter should receive this
1637 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1638 WebGestureEvent::Touchscreen);
1639 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1640 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1641 EXPECT_EQ(1U, process_->sink().message_count());
1642 // The scroll end event will have received a synthetic ack from the input
1644 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1647 // Tests that if the page is scrolled because of a scroll-gesture, then that
1648 // particular scroll sequence never generates overscroll if the scroll direction
1650 TEST_F(RenderWidgetHostTest, GestureScrollConsumedHorizontal) {
1651 // Turn off debounce handling for test isolation.
1652 host_->SetupForOverscrollControllerTest();
1653 host_->DisableGestureDebounce();
1654 process_->sink().ClearMessages();
1656 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1657 WebGestureEvent::Touchscreen);
1658 SimulateGestureScrollUpdateEvent(10, 0, 0);
1660 // Start scrolling on content. ACK both events as being processed.
1661 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1662 INPUT_EVENT_ACK_STATE_CONSUMED);
1663 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1664 INPUT_EVENT_ACK_STATE_CONSUMED);
1665 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1666 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1667 process_->sink().ClearMessages();
1669 // Send another gesture event and ACK as not being processed. This should
1670 // not initiate overscroll because the beginning of the scroll event did
1671 // scroll some content on the page. Since there was no overscroll, the event
1672 // should reach the renderer.
1673 SimulateGestureScrollUpdateEvent(55, 0, 0);
1674 EXPECT_EQ(1U, process_->sink().message_count());
1675 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1676 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1677 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1680 // Tests that the overscroll controller plays nice with touch-scrolls and the
1681 // gesture event filter with debounce filtering turned on.
1682 TEST_F(RenderWidgetHostTest, GestureScrollDebounceOverscrolls) {
1683 host_->SetupForOverscrollControllerTest();
1684 host_->set_debounce_interval_time_ms(100);
1685 process_->sink().ClearMessages();
1687 // Start scrolling. Receive ACK as it being processed.
1688 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1689 WebGestureEvent::Touchscreen);
1690 EXPECT_EQ(1U, process_->sink().message_count());
1691 process_->sink().ClearMessages();
1692 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1693 INPUT_EVENT_ACK_STATE_CONSUMED);
1695 // Send update events.
1696 SimulateGestureScrollUpdateEvent(25, 0, 0);
1697 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1698 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1699 EXPECT_TRUE(host_->ScrollingInProgress());
1700 EXPECT_EQ(1U, process_->sink().message_count());
1701 process_->sink().ClearMessages();
1703 // Quickly end and restart the scroll gesture. These two events should get
1705 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1706 WebGestureEvent::Touchscreen);
1707 EXPECT_EQ(0U, process_->sink().message_count());
1708 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1709 EXPECT_EQ(1U, host_->GestureEventDebouncingQueueSize());
1711 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1712 WebGestureEvent::Touchscreen);
1713 EXPECT_EQ(0U, process_->sink().message_count());
1714 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1715 EXPECT_EQ(2U, host_->GestureEventDebouncingQueueSize());
1717 // Send another update event. This should get into the queue.
1718 SimulateGestureScrollUpdateEvent(30, 0, 0);
1719 EXPECT_EQ(0U, process_->sink().message_count());
1720 EXPECT_EQ(2U, host_->GestureEventLastQueueEventSize());
1721 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1722 EXPECT_TRUE(host_->ScrollingInProgress());
1724 // Receive an ACK for the first scroll-update event as not being processed.
1725 // This will contribute to the overscroll gesture, but not enough for the
1726 // overscroll controller to start consuming gesture events. This also cause
1727 // the queued gesture event to be forwarded to the renderer.
1728 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1729 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1730 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1731 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1732 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1733 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1734 EXPECT_EQ(1U, process_->sink().message_count());
1735 process_->sink().ClearMessages();
1737 // Send another update event. This should get into the queue.
1738 SimulateGestureScrollUpdateEvent(10, 0, 0);
1739 EXPECT_EQ(0U, process_->sink().message_count());
1740 EXPECT_EQ(2U, host_->GestureEventLastQueueEventSize());
1741 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1742 EXPECT_TRUE(host_->ScrollingInProgress());
1744 // Receive an ACK for the second scroll-update event as not being processed.
1745 // This will now initiate an overscroll. This will also cause the queued
1746 // gesture event to be released. But instead of going to the renderer, it will
1747 // be consumed by the overscroll controller.
1748 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1749 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1750 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1751 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1752 EXPECT_EQ(65.f, host_->overscroll_delta_x());
1753 EXPECT_EQ(15.f, host_->overscroll_delegate()->delta_x());
1754 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1755 EXPECT_EQ(0U, process_->sink().message_count());
1756 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1757 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1760 // Tests that the gesture debounce timer plays nice with the overscroll
1762 TEST_F(RenderWidgetHostTest, GestureScrollDebounceTimerOverscroll) {
1763 host_->SetupForOverscrollControllerTest();
1764 host_->set_debounce_interval_time_ms(10);
1765 process_->sink().ClearMessages();
1767 // Start scrolling. Receive ACK as it being processed.
1768 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1769 WebGestureEvent::Touchscreen);
1770 EXPECT_EQ(1U, process_->sink().message_count());
1771 process_->sink().ClearMessages();
1772 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1773 INPUT_EVENT_ACK_STATE_CONSUMED);
1775 // Send update events.
1776 SimulateGestureScrollUpdateEvent(55, 0, 0);
1777 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1778 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1779 EXPECT_TRUE(host_->ScrollingInProgress());
1780 EXPECT_EQ(1U, process_->sink().message_count());
1781 process_->sink().ClearMessages();
1783 // Send an end event. This should get in the debounce queue.
1784 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1785 WebGestureEvent::Touchscreen);
1786 EXPECT_EQ(0U, process_->sink().message_count());
1787 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1788 EXPECT_EQ(1U, host_->GestureEventDebouncingQueueSize());
1790 // Receive ACK for the scroll-update event.
1791 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1792 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1793 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1794 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1795 EXPECT_EQ(55.f, host_->overscroll_delta_x());
1796 EXPECT_EQ(5.f, host_->overscroll_delegate()->delta_x());
1797 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1798 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1799 EXPECT_EQ(1U, host_->GestureEventDebouncingQueueSize());
1800 EXPECT_EQ(0U, process_->sink().message_count());
1802 // Let the timer for the debounce queue fire. That should release the queued
1803 // scroll-end event. Since overscroll has started, but there hasn't been
1804 // enough overscroll to complete the gesture, the overscroll controller
1805 // will reset the state. The scroll-end should therefore be dispatched to the
1806 // renderer, and the gesture-event-filter should await an ACK for it.
1807 base::MessageLoop::current()->PostDelayedTask(
1809 base::MessageLoop::QuitClosure(),
1810 TimeDelta::FromMilliseconds(15));
1811 base::MessageLoop::current()->Run();
1813 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1814 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1815 // The scroll end event will have received a synthetic ack from the input
1817 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1818 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1819 EXPECT_EQ(1U, process_->sink().message_count());
1822 // Tests that when touch-events are dispatched to the renderer, the overscroll
1823 // gesture deals with them correctly.
1824 TEST_F(RenderWidgetHostTest, OverscrollWithTouchEvents) {
1825 host_->SetupForOverscrollControllerTest();
1826 host_->set_debounce_interval_time_ms(10);
1827 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1828 process_->sink().ClearMessages();
1829 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
1832 // The test sends an intermingled sequence of touch and gesture events.
1834 PressTouchPoint(0, 1);
1836 EXPECT_EQ(1U, process_->sink().message_count());
1837 process_->sink().ClearMessages();
1838 SendInputEventACK(WebInputEvent::TouchStart,
1839 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1841 MoveTouchPoint(0, 20, 5);
1843 EXPECT_EQ(1U, process_->sink().message_count());
1844 process_->sink().ClearMessages();
1845 SendInputEventACK(WebInputEvent::TouchMove,
1846 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1848 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1849 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1851 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1852 WebGestureEvent::Touchscreen);
1853 SimulateGestureScrollUpdateEvent(20, 0, 0);
1854 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1855 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1856 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1857 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1858 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1859 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1860 process_->sink().ClearMessages();
1862 // Another touch move event should reach the renderer since overscroll hasn't
1864 MoveTouchPoint(0, 65, 10);
1866 EXPECT_EQ(1U, process_->sink().message_count());
1867 process_->sink().ClearMessages();
1869 SendInputEventACK(WebInputEvent::TouchMove,
1870 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1871 SimulateGestureScrollUpdateEvent(45, 0, 0);
1872 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1873 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1874 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1875 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1876 EXPECT_EQ(65.f, host_->overscroll_delta_x());
1877 EXPECT_EQ(15.f, host_->overscroll_delegate()->delta_x());
1878 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1879 EXPECT_TRUE(host_->TouchEventQueueEmpty());
1880 process_->sink().ClearMessages();
1882 // Send another touch event. The page should get the touch-move event, even
1883 // though overscroll has started.
1884 MoveTouchPoint(0, 55, 5);
1886 EXPECT_EQ(1U, process_->sink().message_count());
1887 EXPECT_FALSE(host_->TouchEventQueueEmpty());
1888 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1889 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1890 EXPECT_EQ(65.f, host_->overscroll_delta_x());
1891 EXPECT_EQ(15.f, host_->overscroll_delegate()->delta_x());
1892 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1894 SendInputEventACK(WebInputEvent::TouchMove,
1895 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1896 EXPECT_TRUE(host_->TouchEventQueueEmpty());
1897 process_->sink().ClearMessages();
1899 SimulateGestureScrollUpdateEvent(-10, 0, 0);
1900 EXPECT_EQ(0U, process_->sink().message_count());
1901 EXPECT_TRUE(host_->TouchEventQueueEmpty());
1902 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1903 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1904 EXPECT_EQ(55.f, host_->overscroll_delta_x());
1905 EXPECT_EQ(5.f, host_->overscroll_delegate()->delta_x());
1906 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1908 MoveTouchPoint(0, 255, 5);
1910 EXPECT_EQ(1U, process_->sink().message_count());
1911 EXPECT_FALSE(host_->TouchEventQueueEmpty());
1912 process_->sink().ClearMessages();
1913 SendInputEventACK(WebInputEvent::TouchMove,
1914 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1916 SimulateGestureScrollUpdateEvent(200, 0, 0);
1917 EXPECT_EQ(0U, process_->sink().message_count());
1918 EXPECT_TRUE(host_->TouchEventQueueEmpty());
1919 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1920 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1921 EXPECT_EQ(255.f, host_->overscroll_delta_x());
1922 EXPECT_EQ(205.f, host_->overscroll_delegate()->delta_x());
1923 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
1925 // The touch-end/cancel event should always reach the renderer if the page has
1927 ReleaseTouchPoint(0);
1929 EXPECT_EQ(1U, process_->sink().message_count());
1930 EXPECT_FALSE(host_->TouchEventQueueEmpty());
1931 process_->sink().ClearMessages();
1933 SendInputEventACK(WebInputEvent::TouchEnd,
1934 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1935 EXPECT_EQ(0U, process_->sink().message_count());
1936 EXPECT_TRUE(host_->TouchEventQueueEmpty());
1938 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
1939 WebGestureEvent::Touchscreen);
1940 base::MessageLoop::current()->PostDelayedTask(
1942 base::MessageLoop::QuitClosure(),
1943 TimeDelta::FromMilliseconds(10));
1944 base::MessageLoop::current()->Run();
1945 EXPECT_EQ(1U, process_->sink().message_count());
1946 EXPECT_TRUE(host_->TouchEventQueueEmpty());
1947 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1948 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1949 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
1952 // Tests that touch-gesture end is dispatched to the renderer at the end of a
1953 // touch-gesture initiated overscroll.
1954 TEST_F(RenderWidgetHostTest, TouchGestureEndDispatchedAfterOverscrollComplete) {
1955 host_->SetupForOverscrollControllerTest();
1956 host_->set_debounce_interval_time_ms(10);
1957 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1958 process_->sink().ClearMessages();
1959 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
1962 // Start scrolling. Receive ACK as it being processed.
1963 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1964 WebGestureEvent::Touchscreen);
1965 EXPECT_EQ(1U, process_->sink().message_count());
1966 // The scroll begin event will have received a synthetic ack from the input
1968 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1969 process_->sink().ClearMessages();
1970 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1971 INPUT_EVENT_ACK_STATE_CONSUMED);
1972 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1973 EXPECT_EQ(0U, process_->sink().message_count());
1974 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1975 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1977 // Send update events.
1978 SimulateGestureScrollUpdateEvent(55, -5, 0);
1979 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
1980 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
1981 EXPECT_TRUE(host_->ScrollingInProgress());
1982 EXPECT_EQ(1U, process_->sink().message_count());
1983 process_->sink().ClearMessages();
1984 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
1985 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
1987 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1988 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1989 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
1990 EXPECT_EQ(0U, process_->sink().message_count());
1991 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
1992 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
1993 EXPECT_EQ(55.f, host_->overscroll_delta_x());
1994 EXPECT_EQ(5.f, host_->overscroll_delegate()->delta_x());
1995 EXPECT_EQ(-5.f, host_->overscroll_delegate()->delta_y());
1998 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
1999 WebGestureEvent::Touchscreen);
2000 EXPECT_EQ(0U, process_->sink().message_count());
2001 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2002 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2003 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
2004 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2005 EXPECT_EQ(1U, host_->GestureEventDebouncingQueueSize());
2006 base::MessageLoop::current()->PostDelayedTask(
2008 base::MessageLoop::QuitClosure(),
2009 TimeDelta::FromMilliseconds(10));
2010 base::MessageLoop::current()->Run();
2011 EXPECT_EQ(1U, process_->sink().message_count());
2012 process_->sink().ClearMessages();
2013 // The scroll end event will have received a synthetic ack from the input
2015 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2016 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
2018 SendInputEventACK(blink::WebInputEvent::GestureScrollEnd,
2019 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2020 EXPECT_EQ(0U, process_->sink().message_count());
2021 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2022 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
2024 // Start scrolling. Receive ACK as it being processed.
2025 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2026 WebGestureEvent::Touchscreen);
2027 EXPECT_EQ(1U, process_->sink().message_count());
2028 // The scroll begin event will have received a synthetic ack from the input
2030 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2031 process_->sink().ClearMessages();
2032 SendInputEventACK(WebInputEvent::GestureScrollBegin,
2033 INPUT_EVENT_ACK_STATE_CONSUMED);
2034 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2035 EXPECT_EQ(0U, process_->sink().message_count());
2036 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2037 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2039 // Send update events.
2040 SimulateGestureScrollUpdateEvent(235, -5, 0);
2041 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
2042 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
2043 EXPECT_TRUE(host_->ScrollingInProgress());
2044 EXPECT_EQ(1U, process_->sink().message_count());
2045 process_->sink().ClearMessages();
2046 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2047 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2049 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2050 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2051 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2052 EXPECT_EQ(0U, process_->sink().message_count());
2053 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
2054 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
2055 EXPECT_EQ(235.f, host_->overscroll_delta_x());
2056 EXPECT_EQ(185.f, host_->overscroll_delegate()->delta_x());
2057 EXPECT_EQ(-5.f, host_->overscroll_delegate()->delta_y());
2060 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2061 WebGestureEvent::Touchscreen);
2062 EXPECT_EQ(0U, process_->sink().message_count());
2063 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2064 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2065 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
2066 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2067 EXPECT_EQ(1U, host_->GestureEventDebouncingQueueSize());
2069 base::MessageLoop::current()->PostDelayedTask(
2071 base::MessageLoop::QuitClosure(),
2072 TimeDelta::FromMilliseconds(10));
2073 base::MessageLoop::current()->Run();
2074 EXPECT_EQ(1U, process_->sink().message_count());
2075 process_->sink().ClearMessages();
2076 // The scroll end event will have received a synthetic ack from the input
2078 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2079 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
2081 SendInputEventACK(blink::WebInputEvent::GestureScrollEnd,
2082 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2083 EXPECT_EQ(0U, process_->sink().message_count());
2084 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize());
2085 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
2088 TEST_F(RenderWidgetHostTest, OverscrollDirectionChange) {
2089 host_->SetupForOverscrollControllerTest();
2090 host_->set_debounce_interval_time_ms(100);
2091 process_->sink().ClearMessages();
2093 // Start scrolling. Receive ACK as it being processed.
2094 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2095 WebGestureEvent::Touchscreen);
2096 EXPECT_EQ(1U, process_->sink().message_count());
2097 process_->sink().ClearMessages();
2098 SendInputEventACK(WebInputEvent::GestureScrollBegin,
2099 INPUT_EVENT_ACK_STATE_CONSUMED);
2101 // Send update events and receive ack as not consumed.
2102 SimulateGestureScrollUpdateEvent(125, -5, 0);
2103 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
2104 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize());
2105 EXPECT_TRUE(host_->ScrollingInProgress());
2106 EXPECT_EQ(1U, process_->sink().message_count());
2107 process_->sink().ClearMessages();
2109 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2110 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2111 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
2112 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
2113 EXPECT_EQ(0U, process_->sink().message_count());
2115 // Send another update event, but in the reverse direction. The overscroll
2116 // controller will consume the event, and reset the overscroll mode.
2117 SimulateGestureScrollUpdateEvent(-260, 0, 0);
2118 EXPECT_EQ(0U, process_->sink().message_count());
2119 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2121 // Since the overscroll mode has been reset, the next scroll update events
2122 // should reach the renderer.
2123 SimulateGestureScrollUpdateEvent(-20, 0, 0);
2124 EXPECT_EQ(1U, process_->sink().message_count());
2125 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2128 // Tests that if a mouse-move event completes the overscroll gesture, future
2129 // move events do reach the renderer.
2130 TEST_F(RenderWidgetHostTest, OverscrollMouseMoveCompletion) {
2131 host_->SetupForOverscrollControllerTest();
2132 host_->DisableGestureDebounce();
2133 process_->sink().ClearMessages();
2134 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
2137 SimulateWheelEvent(5, 0, 0, true); // sent directly
2138 SimulateWheelEvent(-1, 0, 0, true); // enqueued
2139 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2140 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2141 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2142 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2143 EXPECT_EQ(1U, process_->sink().message_count());
2144 process_->sink().ClearMessages();
2146 // Receive ACK the first wheel event as not processed.
2147 SendInputEventACK(WebInputEvent::MouseWheel,
2148 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2149 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2150 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2151 EXPECT_EQ(1U, process_->sink().message_count());
2152 process_->sink().ClearMessages();
2154 // Receive ACK for the second (coalesced) event as not processed. This will
2155 // start an overcroll gesture.
2156 SendInputEventACK(WebInputEvent::MouseWheel,
2157 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2158 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
2159 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode());
2160 EXPECT_EQ(0U, process_->sink().message_count());
2162 // Send a mouse-move event. This should cancel the overscroll navigation
2163 // (since the amount overscrolled is not above the threshold), and so the
2164 // mouse-move should reach the renderer.
2165 SimulateMouseMove(5, 10, 0);
2166 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2167 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
2168 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2169 EXPECT_EQ(1U, process_->sink().message_count());
2170 process_->sink().ClearMessages();
2172 SendInputEventACK(WebInputEvent::MouseMove,
2173 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2175 // Moving the mouse more should continue to send the events to the renderer.
2176 SimulateMouseMove(5, 10, 0);
2177 SendInputEventACK(WebInputEvent::MouseMove,
2178 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2179 EXPECT_EQ(1U, process_->sink().message_count());
2180 process_->sink().ClearMessages();
2182 // Now try with gestures.
2183 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2184 WebGestureEvent::Touchscreen);
2185 SimulateGestureScrollUpdateEvent(300, -5, 0);
2186 SendInputEventACK(WebInputEvent::GestureScrollBegin,
2187 INPUT_EVENT_ACK_STATE_CONSUMED);
2188 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2189 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2190 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
2191 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
2192 process_->sink().ClearMessages();
2194 // Overscroll gesture is in progress. Send a mouse-move now. This should
2195 // complete the gesture (because the amount overscrolled is above the
2197 SimulateMouseMove(5, 10, 0);
2198 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
2199 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2200 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2201 EXPECT_EQ(1U, process_->sink().message_count());
2202 process_->sink().ClearMessages();
2203 SendInputEventACK(WebInputEvent::MouseMove,
2204 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2206 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2207 WebGestureEvent::Touchscreen);
2208 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2209 EXPECT_EQ(1U, process_->sink().message_count());
2210 process_->sink().ClearMessages();
2211 SendInputEventACK(WebInputEvent::GestureScrollEnd,
2212 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2214 // Move mouse some more. The mouse-move events should reach the renderer.
2215 SimulateMouseMove(5, 10, 0);
2216 EXPECT_EQ(1U, process_->sink().message_count());
2218 SendInputEventACK(WebInputEvent::MouseMove,
2219 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2220 process_->sink().ClearMessages();
2223 // Tests that if a page scrolled, then the overscroll controller's states are
2224 // reset after the end of the scroll.
2225 TEST_F(RenderWidgetHostTest, OverscrollStateResetsAfterScroll) {
2226 host_->SetupForOverscrollControllerTest();
2227 host_->DisableGestureDebounce();
2228 process_->sink().ClearMessages();
2229 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
2232 SimulateWheelEvent(0, 5, 0, true); // sent directly
2233 SimulateWheelEvent(0, 30, 0, true); // enqueued
2234 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
2235 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
2236 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2237 EXPECT_EQ(1U, process_->sink().message_count());
2238 process_->sink().ClearMessages();
2240 // The first wheel event is consumed. Dispatches the queued wheel event.
2241 SendInputEventACK(WebInputEvent::MouseWheel,
2242 INPUT_EVENT_ACK_STATE_CONSUMED);
2243 EXPECT_TRUE(host_->ScrollStateIsContentScrolling());
2244 EXPECT_EQ(1U, process_->sink().message_count());
2245 process_->sink().ClearMessages();
2247 // The second wheel event is consumed.
2248 SendInputEventACK(WebInputEvent::MouseWheel,
2249 INPUT_EVENT_ACK_STATE_CONSUMED);
2250 EXPECT_TRUE(host_->ScrollStateIsContentScrolling());
2252 // Touchpad scroll can end with a zero-velocity fling. But it is not
2253 // dispatched, but it should still reset the overscroll controller state.
2254 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad);
2255 EXPECT_TRUE(host_->ScrollStateIsUnknown());
2256 EXPECT_EQ(0U, process_->sink().message_count());
2258 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2259 SimulateWheelEvent(-60, 0, 0, true); // enqueued
2260 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
2261 EXPECT_EQ(1U, process_->sink().message_count());
2262 EXPECT_TRUE(host_->ScrollStateIsUnknown());
2263 process_->sink().ClearMessages();
2265 // The first wheel scroll did not scroll content. Overscroll should not start
2266 // yet, since enough hasn't been scrolled.
2267 SendInputEventACK(WebInputEvent::MouseWheel,
2268 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2269 EXPECT_TRUE(host_->ScrollStateIsUnknown());
2270 EXPECT_EQ(1U, process_->sink().message_count());
2271 process_->sink().ClearMessages();
2273 SendInputEventACK(WebInputEvent::MouseWheel,
2274 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2275 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode());
2276 EXPECT_TRUE(host_->ScrollStateIsOverscrolling());
2277 EXPECT_EQ(0U, process_->sink().message_count());
2279 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad);
2280 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2281 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->completed_mode());
2282 EXPECT_TRUE(host_->ScrollStateIsUnknown());
2283 EXPECT_EQ(0U, process_->sink().message_count());
2284 process_->sink().ClearMessages();
2287 TEST_F(RenderWidgetHostTest, OverscrollResetsOnBlur) {
2288 host_->SetupForOverscrollControllerTest();
2289 process_->sink().ClearMessages();
2290 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
2293 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
2295 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2296 WebGestureEvent::Touchscreen);
2297 SimulateGestureScrollUpdateEvent(300, -5, 0);
2298 SendInputEventACK(WebInputEvent::GestureScrollBegin,
2299 INPUT_EVENT_ACK_STATE_CONSUMED);
2300 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2301 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2302 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
2303 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
2306 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode());
2307 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2308 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
2309 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_x());
2310 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y());
2311 process_->sink().ClearMessages();
2313 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2314 WebGestureEvent::Touchscreen);
2315 EXPECT_EQ(0U, process_->sink().message_count());
2317 // Start a scroll gesture again. This should correctly start the overscroll
2318 // after the threshold.
2319 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2320 WebGestureEvent::Touchscreen);
2321 SimulateGestureScrollUpdateEvent(300, -5, 0);
2322 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2323 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2324 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode());
2325 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
2326 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
2328 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2329 WebGestureEvent::Touchscreen);
2330 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2331 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
2332 process_->sink().ClearMessages();
2335 #define TEST_InputRouterRoutes_NOARGS(INPUTMSG) \
2336 TEST_F(RenderWidgetHostTest, InputRouterRoutes##INPUTMSG) { \
2337 host_->SetupForInputRouterTest(); \
2338 host_->INPUTMSG(); \
2339 EXPECT_TRUE(host_->mock_input_router()->send_event_called_); \
2342 TEST_InputRouterRoutes_NOARGS(Undo);
2343 TEST_InputRouterRoutes_NOARGS(Redo);
2344 TEST_InputRouterRoutes_NOARGS(Cut);
2345 TEST_InputRouterRoutes_NOARGS(Copy);
2346 #if defined(OS_MACOSX)
2347 TEST_InputRouterRoutes_NOARGS(CopyToFindPboard);
2349 TEST_InputRouterRoutes_NOARGS(Paste);
2350 TEST_InputRouterRoutes_NOARGS(PasteAndMatchStyle);
2351 TEST_InputRouterRoutes_NOARGS(Delete);
2352 TEST_InputRouterRoutes_NOARGS(SelectAll);
2353 TEST_InputRouterRoutes_NOARGS(Unselect);
2354 TEST_InputRouterRoutes_NOARGS(Focus);
2355 TEST_InputRouterRoutes_NOARGS(Blur);
2356 TEST_InputRouterRoutes_NOARGS(LostCapture);
2358 #undef TEST_InputRouterRoutes_NOARGS
2360 TEST_F(RenderWidgetHostTest, InputRouterRoutesReplace) {
2361 host_->SetupForInputRouterTest();
2362 host_->Replace(base::string16());
2363 EXPECT_TRUE(host_->mock_input_router()->send_event_called_);
2366 TEST_F(RenderWidgetHostTest, InputRouterRoutesReplaceMisspelling) {
2367 host_->SetupForInputRouterTest();
2368 host_->ReplaceMisspelling(base::string16());
2369 EXPECT_TRUE(host_->mock_input_router()->send_event_called_);
2372 TEST_F(RenderWidgetHostTest, IgnoreInputEvent) {
2373 host_->SetupForInputRouterTest();
2375 host_->SetIgnoreInputEvents(true);
2377 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
2378 EXPECT_FALSE(host_->mock_input_router()->sent_keyboard_event_);
2380 SimulateMouseEvent(WebInputEvent::MouseMove);
2381 EXPECT_FALSE(host_->mock_input_router()->sent_mouse_event_);
2383 SimulateWheelEvent(0, 100, 0, true);
2384 EXPECT_FALSE(host_->mock_input_router()->sent_wheel_event_);
2386 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2387 WebGestureEvent::Touchscreen);
2388 EXPECT_FALSE(host_->mock_input_router()->sent_gesture_event_);
2390 PressTouchPoint(100, 100);
2392 EXPECT_FALSE(host_->mock_input_router()->send_touch_event_not_cancelled_);
2395 TEST_F(RenderWidgetHostTest, KeyboardListenerIgnoresEvent) {
2396 host_->SetupForInputRouterTest();
2397 host_->AddKeyPressEventCallback(
2398 base::Bind(&RenderWidgetHostTest::KeyPressEventCallback,
2399 base::Unretained(this)));
2400 handle_key_press_event_ = false;
2401 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
2403 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2406 TEST_F(RenderWidgetHostTest, KeyboardListenerSuppressFollowingEvents) {
2407 host_->SetupForInputRouterTest();
2409 host_->AddKeyPressEventCallback(
2410 base::Bind(&RenderWidgetHostTest::KeyPressEventCallback,
2411 base::Unretained(this)));
2413 // The callback handles the first event
2414 handle_key_press_event_ = true;
2415 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
2417 EXPECT_FALSE(host_->mock_input_router()->sent_keyboard_event_);
2419 // Following Char events should be suppressed
2420 handle_key_press_event_ = false;
2421 SimulateKeyboardEvent(WebInputEvent::Char);
2422 EXPECT_FALSE(host_->mock_input_router()->sent_keyboard_event_);
2423 SimulateKeyboardEvent(WebInputEvent::Char);
2424 EXPECT_FALSE(host_->mock_input_router()->sent_keyboard_event_);
2426 // Sending RawKeyDown event should stop suppression
2427 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
2428 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2430 host_->mock_input_router()->sent_keyboard_event_ = false;
2431 SimulateKeyboardEvent(WebInputEvent::Char);
2432 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2435 TEST_F(RenderWidgetHostTest, MouseEventCallbackCanHandleEvent) {
2436 host_->SetupForInputRouterTest();
2438 host_->AddMouseEventCallback(
2439 base::Bind(&RenderWidgetHostTest::MouseEventCallback,
2440 base::Unretained(this)));
2442 handle_mouse_event_ = true;
2443 SimulateMouseEvent(WebInputEvent::MouseDown);
2445 EXPECT_FALSE(host_->mock_input_router()->sent_mouse_event_);
2447 handle_mouse_event_ = false;
2448 SimulateMouseEvent(WebInputEvent::MouseDown);
2450 EXPECT_TRUE(host_->mock_input_router()->sent_mouse_event_);
2453 TEST_F(RenderWidgetHostTest, InputRouterReceivesHandleInputEvent_ACK) {
2454 host_->SetupForInputRouterTest();
2456 SendInputEventACK(WebInputEvent::RawKeyDown,
2457 INPUT_EVENT_ACK_STATE_CONSUMED);
2459 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2462 TEST_F(RenderWidgetHostTest, InputRouterReceivesMoveCaret_ACK) {
2463 host_->SetupForInputRouterTest();
2465 host_->OnMessageReceived(ViewHostMsg_MoveCaret_ACK(0));
2467 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2470 TEST_F(RenderWidgetHostTest, InputRouterReceivesSelectRange_ACK) {
2471 host_->SetupForInputRouterTest();
2473 host_->OnMessageReceived(ViewHostMsg_SelectRange_ACK(0));
2475 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2478 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) {
2479 host_->SetupForInputRouterTest();
2481 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2483 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2487 void CheckLatencyInfoComponentInMessage(RenderWidgetHostProcess* process,
2489 WebInputEvent::Type input_type) {
2490 const WebInputEvent* event = NULL;
2491 ui::LatencyInfo latency_info;
2492 bool is_keyboard_shortcut;
2493 const IPC::Message* message = process->sink().GetUniqueMessageMatching(
2494 InputMsg_HandleInputEvent::ID);
2495 ASSERT_TRUE(message);
2496 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(
2497 message, &event, &latency_info, &is_keyboard_shortcut));
2498 EXPECT_TRUE(latency_info.FindLatency(
2499 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
2502 process->sink().ClearMessages();
2505 // Tests that after input event passes through RWHI through ForwardXXXEvent()
2506 // or ForwardXXXEventWithLatencyInfo(), LatencyInfo component
2507 // ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT will always present in the
2508 // event's LatencyInfo.
2509 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyComponent) {
2510 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2511 process_->sink().ClearMessages();
2513 // Tests RWHI::ForwardWheelEvent().
2514 SimulateWheelEvent(-5, 0, 0, true);
2515 CheckLatencyInfoComponentInMessage(
2516 process_, GetLatencyComponentId(), WebInputEvent::MouseWheel);
2517 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2519 // Tests RWHI::ForwardWheelEventWithLatencyInfo().
2520 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo());
2521 CheckLatencyInfoComponentInMessage(
2522 process_, GetLatencyComponentId(), WebInputEvent::MouseWheel);
2523 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2525 // Tests RWHI::ForwardMouseEvent().
2526 SimulateMouseEvent(WebInputEvent::MouseMove);
2527 CheckLatencyInfoComponentInMessage(
2528 process_, GetLatencyComponentId(), WebInputEvent::MouseMove);
2529 SendInputEventACK(WebInputEvent::MouseMove, INPUT_EVENT_ACK_STATE_CONSUMED);
2531 // Tests RWHI::ForwardMouseEventWithLatencyInfo().
2532 SimulateMouseEventWithLatencyInfo(WebInputEvent::MouseMove,
2534 CheckLatencyInfoComponentInMessage(
2535 process_, GetLatencyComponentId(), WebInputEvent::MouseMove);
2536 SendInputEventACK(WebInputEvent::MouseMove, INPUT_EVENT_ACK_STATE_CONSUMED);
2538 // Tests RWHI::ForwardGestureEvent().
2539 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
2540 WebGestureEvent::Touchscreen);
2541 CheckLatencyInfoComponentInMessage(
2542 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollUpdate);
2543 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2544 INPUT_EVENT_ACK_STATE_CONSUMED);
2546 // Tests RWHI::ForwardGestureEventWithLatencyInfo().
2547 SimulateGestureEventWithLatencyInfo(WebInputEvent::GestureScrollUpdate,
2548 WebGestureEvent::Touchscreen,
2550 CheckLatencyInfoComponentInMessage(
2551 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollUpdate);
2552 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2553 INPUT_EVENT_ACK_STATE_CONSUMED);
2555 // Tests RWHI::ForwardTouchEventWithLatencyInfo().
2556 PressTouchPoint(0, 1);
2558 CheckLatencyInfoComponentInMessage(
2559 process_, GetLatencyComponentId(), WebInputEvent::TouchStart);
2560 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
2563 } // namespace content