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

Side by Side Diff: content/browser/renderer_host/input/input_router_unittest.cc

Issue 20356003: Provided batched input delivery with a BufferedInputRouter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: BufferedInputRouter unit tests Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/browser/renderer_host/input/input_router_unittest.h"
6
7 #include "content/browser/renderer_host/input/input_router.h"
8 #include "content/common/input_messages.h"
9 #include "ui/base/keycodes/keyboard_codes.h"
10
11 #if defined(OS_WIN) || defined(USE_AURA)
12 #include "content/browser/renderer_host/ui_events_helper.h"
13 #include "ui/base/events/event.h"
14 #endif
15
16 using WebKit::WebGestureEvent;
17 using WebKit::WebInputEvent;
18 using WebKit::WebMouseEvent;
19 using WebKit::WebMouseWheelEvent;
20 using WebKit::WebTouchEvent;
21 using WebKit::WebTouchPoint;
22
23 namespace content {
24
25 InputRouterTest::InputRouterTest() {}
26 InputRouterTest::~InputRouterTest() {}
27
28 void InputRouterTest::SetUp() {
29 browser_context_.reset(new TestBrowserContext());
30 process_.reset(new MockRenderProcessHost(browser_context_.get()));
31 client_.reset(new MockInputRouterClient());
32 input_router_ = CreateInputRouter(process_.get(),
33 client_.get(),
34 MSG_ROUTING_NONE);
35 client_->set_input_router(input_router_.get());
36 process_->sink().AddFilter(this);
37 }
38
39 void InputRouterTest::TearDown() {
40 // Process all pending tasks to avoid InputRouterTest::leaks.
41 base::MessageLoop::current()->RunUntilIdle();
42
43 input_router_.reset();
44 client_.reset();
45 process_.reset();
46 browser_context_.reset();
47 }
48
49 bool InputRouterTest::OnMessageReceived(const IPC::Message& listener) {
50 return false;
51 }
52
53 void InputRouterTest::SimulateKeyboardEvent(WebInputEvent::Type type) {
54 NativeWebKeyboardEvent key_event;
55 key_event.type = type;
56 key_event.windowsKeyCode = ui::VKEY_L; // non-null made up value.
57 input_router_->SendKeyboardEvent(key_event, ui::LatencyInfo());
58 client_->ExpectSendCalled(true);
59 EXPECT_EQ(type, client_->sent_key_event().type);
60 EXPECT_EQ(key_event.windowsKeyCode,
61 client_->sent_key_event().windowsKeyCode);
62 }
63
64 void InputRouterTest::SimulateWheelEvent(float dX,
65 float dY,
66 int modifiers,
67 bool precise) {
68 WebMouseWheelEvent wheel_event;
69 wheel_event.type = WebInputEvent::MouseWheel;
70 wheel_event.deltaX = dX;
71 wheel_event.deltaY = dY;
72 wheel_event.modifiers = modifiers;
73 wheel_event.hasPreciseScrollingDeltas = precise;
74 input_router_->SendWheelEvent(
75 MouseWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo()));
76 client_->ExpectSendCalled(true);
77 EXPECT_EQ(wheel_event.type, client_->sent_wheel_event().event.type);
78 EXPECT_EQ(dX, client_->sent_wheel_event().event.deltaX);
79 }
80
81 void InputRouterTest::SimulateMouseMove(int x, int y, int modifiers) {
82 WebMouseEvent mouse_event;
83 mouse_event.type = WebInputEvent::MouseMove;
84 mouse_event.x = mouse_event.windowX = x;
85 mouse_event.y = mouse_event.windowY = y;
86 mouse_event.modifiers = modifiers;
87 input_router_->SendMouseEvent(
88 MouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo()));
89 client_->ExpectSendCalled(true);
90 EXPECT_EQ(mouse_event.type, client_->sent_mouse_event().event.type);
91 EXPECT_EQ(x, client_->sent_mouse_event().event.x);
92 }
93
94 void InputRouterTest::SimulateWheelEventWithPhase(
95 WebMouseWheelEvent::Phase phase) {
96 WebMouseWheelEvent wheel_event;
97 wheel_event.type = WebInputEvent::MouseWheel;
98 wheel_event.phase = phase;
99 input_router_->SendWheelEvent(
100 MouseWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo()));
101 client_->ExpectSendCalled(true);
102 EXPECT_EQ(wheel_event.type, client_->sent_wheel_event().event.type);
103 EXPECT_EQ(phase, client_->sent_wheel_event().event.phase);
104 }
105
106 // Inject provided synthetic WebGestureEvent instance.
107 void InputRouterTest::SimulateGestureEventCore(WebInputEvent::Type type,
108 WebGestureEvent::SourceDevice sourceDevice,
109 WebGestureEvent* gesture_event) {
110 gesture_event->type = type;
111 gesture_event->sourceDevice = sourceDevice;
112 GestureEventWithLatencyInfo gesture_with_latency(
113 *gesture_event, ui::LatencyInfo());
114 input_router_->SendGestureEvent(gesture_with_latency);
115 client_->ExpectSendCalled(true);
116 EXPECT_EQ(type, client_->sent_gesture_event().event.type);
117 EXPECT_EQ(sourceDevice, client_->sent_gesture_event().event.sourceDevice);
118 }
119
120 // Inject simple synthetic WebGestureEvent instances.
121 void InputRouterTest::SimulateGestureEvent(WebInputEvent::Type type,
122 WebGestureEvent::SourceDevice sourceDevice) {
123 WebGestureEvent gesture_event;
124 SimulateGestureEventCore(type, sourceDevice, &gesture_event);
125 }
126
127 void InputRouterTest::SimulateGestureScrollUpdateEvent(float dX,
128 float dY,
129 int modifiers) {
130 WebGestureEvent gesture_event;
131 gesture_event.data.scrollUpdate.deltaX = dX;
132 gesture_event.data.scrollUpdate.deltaY = dY;
133 gesture_event.modifiers = modifiers;
134 SimulateGestureEventCore(WebInputEvent::GestureScrollUpdate,
135 WebGestureEvent::Touchscreen, &gesture_event);
136 }
137
138 void InputRouterTest::SimulateGesturePinchUpdateEvent(float scale,
139 float anchorX,
140 float anchorY,
141 int modifiers) {
142 WebGestureEvent gesture_event;
143 gesture_event.data.pinchUpdate.scale = scale;
144 gesture_event.x = anchorX;
145 gesture_event.y = anchorY;
146 gesture_event.modifiers = modifiers;
147 SimulateGestureEventCore(WebInputEvent::GesturePinchUpdate,
148 WebGestureEvent::Touchscreen, &gesture_event);
149 }
150
151 // Inject synthetic GestureFlingStart events.
152 void InputRouterTest::SimulateGestureFlingStartEvent(
153 float velocityX,
154 float velocityY,
155 WebGestureEvent::SourceDevice sourceDevice) {
156 WebGestureEvent gesture_event;
157 gesture_event.data.flingStart.velocityX = velocityX;
158 gesture_event.data.flingStart.velocityY = velocityY;
159 SimulateGestureEventCore(WebInputEvent::GestureFlingStart, sourceDevice,
160 &gesture_event);
161 }
162
163 void InputRouterTest::SimulateTouchEvent(
164 int x,
165 int y) {
166 PressTouchPoint(x, y);
167 SendTouchEvent();
168 }
169
170 // Set the timestamp for the touch-event.
171 void InputRouterTest::SetTouchTimestamp(base::TimeDelta timestamp) {
172 touch_event_.timeStampSeconds = timestamp.InSecondsF();
173 }
174
175 // Sends a touch event (irrespective of whether the page has a touch-event
176 // handler or not).
177 void InputRouterTest::SendTouchEvent() {
178 input_router_->SendTouchEvent(
179 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo()));
180
181 // Mark all the points as stationary. And remove the points that have been
182 // released.
183 int point = 0;
184 for (unsigned int i = 0; i < touch_event_.touchesLength; ++i) {
185 if (touch_event_.touches[i].state == WebTouchPoint::StateReleased)
186 continue;
187
188 touch_event_.touches[point] = touch_event_.touches[i];
189 touch_event_.touches[point].state =
190 WebTouchPoint::StateStationary;
191 ++point;
192 }
193 touch_event_.touchesLength = point;
194 touch_event_.type = WebInputEvent::Undefined;
195 }
196
197 int InputRouterTest::PressTouchPoint(int x, int y) {
198 if (touch_event_.touchesLength == touch_event_.touchesLengthCap)
199 return -1;
200 WebTouchPoint& point =
201 touch_event_.touches[touch_event_.touchesLength];
202 point.id = touch_event_.touchesLength;
203 point.position.x = point.screenPosition.x = x;
204 point.position.y = point.screenPosition.y = y;
205 point.state = WebTouchPoint::StatePressed;
206 point.radiusX = point.radiusY = 1.f;
207 ++touch_event_.touchesLength;
208 touch_event_.type = WebInputEvent::TouchStart;
209 return point.id;
210 }
211
212 void InputRouterTest::MoveTouchPoint(int index, int x, int y) {
213 CHECK(index >= 0 && index < touch_event_.touchesLengthCap);
214 WebTouchPoint& point = touch_event_.touches[index];
215 point.position.x = point.screenPosition.x = x;
216 point.position.y = point.screenPosition.y = y;
217 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
218 touch_event_.type = WebInputEvent::TouchMove;
219 }
220
221 void InputRouterTest::ReleaseTouchPoint(int index) {
222 CHECK(index >= 0 && index < touch_event_.touchesLengthCap);
223 touch_event_.touches[index].state = WebTouchPoint::StateReleased;
224 touch_event_.type = WebInputEvent::TouchEnd;
225 }
226
227 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698