1 // Copyright 2013 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 "content/browser/renderer_host/input/input_router_unittest.h"
7 #include "content/browser/renderer_host/input/input_router.h"
8 #include "content/common/input_messages.h"
10 using WebKit::WebGestureEvent;
11 using WebKit::WebInputEvent;
12 using WebKit::WebMouseEvent;
13 using WebKit::WebMouseWheelEvent;
14 using WebKit::WebTouchEvent;
15 using WebKit::WebTouchPoint;
19 InputRouterTest::InputRouterTest() {}
20 InputRouterTest::~InputRouterTest() {}
22 void InputRouterTest::SetUp() {
23 browser_context_.reset(new TestBrowserContext());
24 process_.reset(new MockRenderProcessHost(browser_context_.get()));
25 client_.reset(new MockInputRouterClient());
26 ack_handler_.reset(new MockInputAckHandler());
27 input_router_ = CreateInputRouter(process_.get(),
31 client_->set_input_router(input_router_.get());
32 ack_handler_->set_input_router(input_router_.get());
35 void InputRouterTest::TearDown() {
36 // Process all pending tasks to avoid InputRouterTest::leaks.
37 base::MessageLoop::current()->RunUntilIdle();
39 input_router_.reset();
42 browser_context_.reset();
45 void InputRouterTest::SimulateKeyboardEvent(WebInputEvent::Type type,
47 input_router_->SendKeyboardEvent(
48 SyntheticWebKeyboardEventBuilder::Build(type),
53 void InputRouterTest::SimulateWheelEvent(float dX,
57 input_router_->SendWheelEvent(
58 MouseWheelEventWithLatencyInfo(
59 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise),
63 void InputRouterTest::SimulateMouseMove(int x, int y, int modifiers) {
64 input_router_->SendMouseEvent(
65 MouseEventWithLatencyInfo(SyntheticWebMouseEventBuilder::Build(
66 WebInputEvent::MouseMove, x, y, modifiers),
70 void InputRouterTest::SimulateWheelEventWithPhase(
71 WebMouseWheelEvent::Phase phase) {
72 input_router_->SendWheelEvent(
73 MouseWheelEventWithLatencyInfo(
74 SyntheticWebMouseWheelEventBuilder::Build(phase), ui::LatencyInfo()));
77 // Inject provided synthetic WebGestureEvent instance.
78 void InputRouterTest::SimulateGestureEvent(
79 const WebGestureEvent& gesture) {
80 GestureEventWithLatencyInfo gesture_with_latency(gesture, ui::LatencyInfo());
81 input_router_->SendGestureEvent(gesture_with_latency);
84 // Inject simple synthetic WebGestureEvent instances.
85 void InputRouterTest::SimulateGestureEvent(
86 WebInputEvent::Type type,
87 WebGestureEvent::SourceDevice sourceDevice) {
89 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
92 void InputRouterTest::SimulateGestureScrollUpdateEvent(float dX,
96 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
99 void InputRouterTest::SimulateGesturePinchUpdateEvent(float scale,
103 SimulateGestureEvent(
104 SyntheticWebGestureEventBuilder::BuildPinchUpdate(scale,
110 // Inject synthetic GestureFlingStart events.
111 void InputRouterTest::SimulateGestureFlingStartEvent(
114 WebGestureEvent::SourceDevice sourceDevice) {
115 SimulateGestureEvent(
116 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
121 void InputRouterTest::SimulateTouchEvent(int x, int y) {
122 PressTouchPoint(x, y);
126 // Set the timestamp for the touch-event.
127 void InputRouterTest::SetTouchTimestamp(base::TimeDelta timestamp) {
128 touch_event_.SetTimestamp(timestamp);
131 // Sends a touch event (irrespective of whether the page has a touch-event
133 void InputRouterTest::SendTouchEvent() {
134 input_router_->SendTouchEvent(
135 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo()));
136 touch_event_.ResetPoints();
139 int InputRouterTest::PressTouchPoint(int x, int y) {
140 return touch_event_.PressPoint(x, y);
143 void InputRouterTest::MoveTouchPoint(int index, int x, int y) {
144 touch_event_.MovePoint(index, x, y);
147 void InputRouterTest::ReleaseTouchPoint(int index) {
148 touch_event_.ReleasePoint(index);
151 } // namespace content