1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #include "WebInputEventConversion.h"
34
35 #include <gtest/gtest.h>
36 #include "FrameTestHelpers.h"
37 #include "URLTestHelpers.h"
38 #include "WebFrame.h"
39 #include "WebSettings.h"
40 #include "WebViewImpl.h"
41 #include "core/events/GestureEvent.h"
42 #include "core/events/KeyboardEvent.h"
43 #include "core/events/MouseEvent.h"
44 #include "core/dom/Touch.h"
45 #include "core/events/TouchEvent.h"
46 #include "core/dom/TouchList.h"
47 #include "core/frame/Frame.h"
48 #include "core/frame/FrameView.h"
49
50 using namespace blink;
51 using namespace WebCore;
52
53 namespace {
54
createKeyboardEventWithLocation(WebCore::KeyboardEvent::KeyLocationCode location)55 PassRefPtr<WebCore::KeyboardEvent> createKeyboardEventWithLocation(WebCore::KeyboardEvent::KeyLocationCode location)
56 {
57 return WebCore::KeyboardEvent::create("keydown", true, true, 0, "", location, false, false, false, false, false);
58 }
59
getModifiersForKeyLocationCode(WebCore::KeyboardEvent::KeyLocationCode location)60 int getModifiersForKeyLocationCode(WebCore::KeyboardEvent::KeyLocationCode location)
61 {
62 RefPtr<WebCore::KeyboardEvent> event = createKeyboardEventWithLocation(location);
63 blink::WebKeyboardEventBuilder convertedEvent(*event);
64 return convertedEvent.modifiers;
65 }
66
TEST(WebInputEventConversionTest,WebKeyboardEventBuilder)67 TEST(WebInputEventConversionTest, WebKeyboardEventBuilder)
68 {
69 // Test key location conversion.
70 int modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_STANDARD);
71 EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent::IsRight);
72
73 modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_LEFT);
74 EXPECT_TRUE(modifiers & WebInputEvent::IsLeft);
75 EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEvent::IsRight);
76
77 modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_RIGHT);
78 EXPECT_TRUE(modifiers & WebInputEvent::IsRight);
79 EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEvent::IsLeft);
80
81 modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_NUMPAD);
82 EXPECT_TRUE(modifiers & WebInputEvent::IsKeyPad);
83 EXPECT_FALSE(modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent::IsRight);
84 }
85
TEST(WebInputEventConversionTest,WebTouchEventBuilder)86 TEST(WebInputEventConversionTest, WebTouchEventBuilder)
87 {
88 RefPtr<WebCore::TouchEvent> event = WebCore::TouchEvent::create();
89 WebMouseEventBuilder mouse(0, 0, *event);
90 EXPECT_EQ(WebInputEvent::Undefined, mouse.type);
91 }
92
TEST(WebInputEventConversionTest,InputEventsScaling)93 TEST(WebInputEventConversionTest, InputEventsScaling)
94 {
95 const std::string baseURL("http://www.test.com/");
96 const std::string fileName("fixed_layout.html");
97
98 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("fixed_layout.html"));
99 FrameTestHelpers::WebViewHelper webViewHelper;
100 WebViewImpl* webViewImpl = toWebViewImpl(webViewHelper.initializeAndLoad(baseURL + fileName, true));
101 webViewImpl->settings()->setViewportEnabled(true);
102 int pageWidth = 640;
103 int pageHeight = 480;
104 webViewImpl->resize(WebSize(pageWidth, pageHeight));
105 webViewImpl->layout();
106
107 webViewImpl->setPageScaleFactor(2, WebPoint());
108
109 FrameView* view = webViewImpl->page()->mainFrame()->view();
110 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document();
111 DOMWindow* domWindow = webViewImpl->page()->mainFrame()->document()->domWindow();
112 RenderObject* docRenderer = webViewImpl->page()->mainFrame()->document()->renderer();
113
114 {
115 WebMouseEvent webMouseEvent;
116 webMouseEvent.type = WebInputEvent::MouseMove;
117 webMouseEvent.x = 10;
118 webMouseEvent.y = 10;
119 webMouseEvent.windowX = 10;
120 webMouseEvent.windowY = 10;
121 webMouseEvent.globalX = 10;
122 webMouseEvent.globalY = 10;
123 webMouseEvent.movementX = 10;
124 webMouseEvent.movementY = 10;
125
126 PlatformMouseEventBuilder platformMouseBuilder(view, webMouseEvent);
127 EXPECT_EQ(5, platformMouseBuilder.position().x());
128 EXPECT_EQ(5, platformMouseBuilder.position().y());
129 EXPECT_EQ(10, platformMouseBuilder.globalPosition().x());
130 EXPECT_EQ(10, platformMouseBuilder.globalPosition().y());
131 EXPECT_EQ(5, platformMouseBuilder.movementDelta().x());
132 EXPECT_EQ(5, platformMouseBuilder.movementDelta().y());
133 }
134
135 {
136 WebGestureEvent webGestureEvent;
137 webGestureEvent.type = WebInputEvent::GestureScrollUpdate;
138 webGestureEvent.x = 10;
139 webGestureEvent.y = 10;
140 webGestureEvent.globalX = 10;
141 webGestureEvent.globalY = 10;
142 webGestureEvent.data.scrollUpdate.deltaX = 10;
143 webGestureEvent.data.scrollUpdate.deltaY = 10;
144
145 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
146 EXPECT_EQ(5, platformGestureBuilder.position().x());
147 EXPECT_EQ(5, platformGestureBuilder.position().y());
148 EXPECT_EQ(10, platformGestureBuilder.globalPosition().x());
149 EXPECT_EQ(10, platformGestureBuilder.globalPosition().y());
150 EXPECT_EQ(5, platformGestureBuilder.deltaX());
151 EXPECT_EQ(5, platformGestureBuilder.deltaY());
152 }
153
154 {
155 WebGestureEvent webGestureEvent;
156 webGestureEvent.type = WebInputEvent::GestureTap;
157 webGestureEvent.data.tap.width = 10;
158 webGestureEvent.data.tap.height = 10;
159
160 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
161 EXPECT_EQ(5, platformGestureBuilder.area().width());
162 EXPECT_EQ(5, platformGestureBuilder.area().height());
163 }
164
165 {
166 WebGestureEvent webGestureEvent;
167 webGestureEvent.type = WebInputEvent::GestureTapUnconfirmed;
168 webGestureEvent.data.tap.width = 10;
169 webGestureEvent.data.tap.height = 10;
170
171 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
172 EXPECT_EQ(5, platformGestureBuilder.area().width());
173 EXPECT_EQ(5, platformGestureBuilder.area().height());
174 }
175
176 {
177 WebGestureEvent webGestureEvent;
178 webGestureEvent.type = WebInputEvent::GestureTapDown;
179 webGestureEvent.data.tapDown.width = 10;
180 webGestureEvent.data.tapDown.height = 10;
181
182 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
183 EXPECT_EQ(5, platformGestureBuilder.area().width());
184 EXPECT_EQ(5, platformGestureBuilder.area().height());
185 }
186
187 {
188 WebGestureEvent webGestureEvent;
189 webGestureEvent.type = WebInputEvent::GestureShowPress;
190 webGestureEvent.data.showPress.width = 10;
191 webGestureEvent.data.showPress.height = 10;
192
193 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
194 EXPECT_EQ(5, platformGestureBuilder.area().width());
195 EXPECT_EQ(5, platformGestureBuilder.area().height());
196 }
197
198 {
199 WebGestureEvent webGestureEvent;
200 webGestureEvent.type = WebInputEvent::GestureLongPress;
201 webGestureEvent.data.longPress.width = 10;
202 webGestureEvent.data.longPress.height = 10;
203
204 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
205 EXPECT_EQ(5, platformGestureBuilder.area().width());
206 EXPECT_EQ(5, platformGestureBuilder.area().height());
207 }
208
209 {
210 WebGestureEvent webGestureEvent;
211 webGestureEvent.type = WebInputEvent::GestureTwoFingerTap;
212 webGestureEvent.data.twoFingerTap.firstFingerWidth = 10;
213 webGestureEvent.data.twoFingerTap.firstFingerHeight = 10;
214
215 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
216 EXPECT_EQ(5, platformGestureBuilder.area().width());
217 EXPECT_EQ(5, platformGestureBuilder.area().height());
218 }
219
220 {
221 WebTouchEvent webTouchEvent;
222 webTouchEvent.type = WebInputEvent::TouchMove;
223 webTouchEvent.touchesLength = 1;
224 webTouchEvent.touches[0].state = WebTouchPoint::StateMoved;
225 webTouchEvent.touches[0].screenPosition.x = 10;
226 webTouchEvent.touches[0].screenPosition.y = 10;
227 webTouchEvent.touches[0].position.x = 10;
228 webTouchEvent.touches[0].position.y = 10;
229 webTouchEvent.touches[0].radiusX = 10;
230 webTouchEvent.touches[0].radiusY = 10;
231
232 PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
233 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].screenPos().x());
234 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].screenPos().y());
235 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].pos().x());
236 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].pos().y());
237 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].radiusX());
238 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].radiusY());
239 }
240
241 // Reverse builders should *not* go back to physical pixels, as they are used for plugins
242 // which expect CSS pixel coordinates.
243 {
244 PlatformMouseEvent platformMouseEvent(IntPoint(10, 10), IntPoint(10, 10), LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
245 RefPtr<MouseEvent> mouseEvent = MouseEvent::create(WebCore::EventTypeNames::mousemove, domWindow, platformMouseEvent, 0, document);
246 WebMouseEventBuilder webMouseBuilder(view, docRenderer, *mouseEvent);
247
248 EXPECT_EQ(10, webMouseBuilder.x);
249 EXPECT_EQ(10, webMouseBuilder.y);
250 EXPECT_EQ(10, webMouseBuilder.globalX);
251 EXPECT_EQ(10, webMouseBuilder.globalY);
252 EXPECT_EQ(10, webMouseBuilder.windowX);
253 EXPECT_EQ(10, webMouseBuilder.windowY);
254 }
255
256 {
257 PlatformMouseEvent platformMouseEvent(IntPoint(10, 10), IntPoint(10, 10), NoButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
258 RefPtr<MouseEvent> mouseEvent = MouseEvent::create(WebCore::EventTypeNames::mousemove, domWindow, platformMouseEvent, 0, document);
259 WebMouseEventBuilder webMouseBuilder(view, docRenderer, *mouseEvent);
260 EXPECT_EQ(WebMouseEvent::ButtonNone, webMouseBuilder.button);
261 }
262
263 {
264 PlatformGestureEvent platformGestureEvent(PlatformEvent::GestureScrollUpdate, IntPoint(10, 10), IntPoint(10, 10), IntSize(10, 10), 0, false, false, false, false, 10, 10, 10, 10);
265 RefPtr<GestureEvent> gestureEvent = GestureEvent::create(domWindow, platformGestureEvent);
266 WebGestureEventBuilder webGestureBuilder(view, docRenderer, *gestureEvent);
267
268 EXPECT_EQ(10, webGestureBuilder.x);
269 EXPECT_EQ(10, webGestureBuilder.y);
270 EXPECT_EQ(10, webGestureBuilder.globalX);
271 EXPECT_EQ(10, webGestureBuilder.globalY);
272 EXPECT_EQ(10, webGestureBuilder.data.scrollUpdate.deltaX);
273 EXPECT_EQ(10, webGestureBuilder.data.scrollUpdate.deltaY);
274 }
275
276 {
277 RefPtr<Touch> touch = Touch::create(webViewImpl->page()->mainFrame(), document.get(), 0, 10, 10, 10, 10, 10, 10, 0, 0);
278 RefPtr<TouchList> touchList = TouchList::create();
279 touchList->append(touch);
280 RefPtr<TouchEvent> touchEvent = TouchEvent::create(touchList.get(), touchList.get(), touchList.get(), WebCore::EventTypeNames::touchmove, domWindow, 10, 10, 10, 10, false, false, false, false);
281
282 WebTouchEventBuilder webTouchBuilder(view, docRenderer, *touchEvent);
283 ASSERT_EQ(1u, webTouchBuilder.touchesLength);
284 EXPECT_EQ(10, webTouchBuilder.touches[0].screenPosition.x);
285 EXPECT_EQ(10, webTouchBuilder.touches[0].screenPosition.y);
286 EXPECT_EQ(10, webTouchBuilder.touches[0].position.x);
287 EXPECT_EQ(10, webTouchBuilder.touches[0].position.y);
288 EXPECT_EQ(10, webTouchBuilder.touches[0].radiusX);
289 EXPECT_EQ(10, webTouchBuilder.touches[0].radiusY);
290 }
291 }
292
TEST(WebInputEventConversionTest,InputEventsTransform)293 TEST(WebInputEventConversionTest, InputEventsTransform)
294 {
295 const std::string baseURL("http://www.test2.com/");
296 const std::string fileName("fixed_layout.html");
297
298 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("fixed_layout.html"));
299 FrameTestHelpers::WebViewHelper webViewHelper;
300 WebViewImpl* webViewImpl = toWebViewImpl(webViewHelper.initializeAndLoad(baseURL + fileName, true));
301 webViewImpl->settings()->setViewportEnabled(true);
302 int pageWidth = 640;
303 int pageHeight = 480;
304 webViewImpl->resize(WebSize(pageWidth, pageHeight));
305 webViewImpl->layout();
306
307 webViewImpl->setPageScaleFactor(2, WebPoint());
308 webViewImpl->setRootLayerTransform(WebSize(10, 20), 1.5);
309
310 FrameView* view = webViewImpl->page()->mainFrame()->view();
311 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document();
312
313 {
314 WebMouseEvent webMouseEvent;
315 webMouseEvent.type = WebInputEvent::MouseMove;
316 webMouseEvent.x = 100;
317 webMouseEvent.y = 110;
318 webMouseEvent.windowX = 100;
319 webMouseEvent.windowY = 110;
320 webMouseEvent.globalX = 100;
321 webMouseEvent.globalY = 110;
322 webMouseEvent.movementX = 60;
323 webMouseEvent.movementY = 60;
324
325 PlatformMouseEventBuilder platformMouseBuilder(view, webMouseEvent);
326 EXPECT_EQ(30, platformMouseBuilder.position().x());
327 EXPECT_EQ(30, platformMouseBuilder.position().y());
328 EXPECT_EQ(100, platformMouseBuilder.globalPosition().x());
329 EXPECT_EQ(110, platformMouseBuilder.globalPosition().y());
330 EXPECT_EQ(20, platformMouseBuilder.movementDelta().x());
331 EXPECT_EQ(20, platformMouseBuilder.movementDelta().y());
332 }
333
334 {
335 WebGestureEvent webGestureEvent;
336 webGestureEvent.type = WebInputEvent::GestureScrollUpdate;
337 webGestureEvent.x = 100;
338 webGestureEvent.y = 110;
339 webGestureEvent.globalX = 100;
340 webGestureEvent.globalY = 110;
341 webGestureEvent.data.scrollUpdate.deltaX = 60;
342 webGestureEvent.data.scrollUpdate.deltaY = 60;
343
344 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
345 EXPECT_EQ(30, platformGestureBuilder.position().x());
346 EXPECT_EQ(30, platformGestureBuilder.position().y());
347 EXPECT_EQ(100, platformGestureBuilder.globalPosition().x());
348 EXPECT_EQ(110, platformGestureBuilder.globalPosition().y());
349 EXPECT_EQ(20, platformGestureBuilder.deltaX());
350 EXPECT_EQ(20, platformGestureBuilder.deltaY());
351 }
352
353 {
354 WebGestureEvent webGestureEvent;
355 webGestureEvent.type = WebInputEvent::GestureTap;
356 webGestureEvent.data.tap.width = 30;
357 webGestureEvent.data.tap.height = 30;
358
359 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
360 EXPECT_EQ(10, platformGestureBuilder.area().width());
361 EXPECT_EQ(10, platformGestureBuilder.area().height());
362 }
363
364 {
365 WebGestureEvent webGestureEvent;
366 webGestureEvent.type = WebInputEvent::GestureTapUnconfirmed;
367 webGestureEvent.data.tap.width = 30;
368 webGestureEvent.data.tap.height = 30;
369
370 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
371 EXPECT_EQ(10, platformGestureBuilder.area().width());
372 EXPECT_EQ(10, platformGestureBuilder.area().height());
373 }
374
375 {
376 WebGestureEvent webGestureEvent;
377 webGestureEvent.type = WebInputEvent::GestureTapDown;
378 webGestureEvent.data.tapDown.width = 30;
379 webGestureEvent.data.tapDown.height = 30;
380
381 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
382 EXPECT_EQ(10, platformGestureBuilder.area().width());
383 EXPECT_EQ(10, platformGestureBuilder.area().height());
384 }
385
386 {
387 WebGestureEvent webGestureEvent;
388 webGestureEvent.type = WebInputEvent::GestureShowPress;
389 webGestureEvent.data.showPress.width = 30;
390 webGestureEvent.data.showPress.height = 30;
391
392 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
393 EXPECT_EQ(10, platformGestureBuilder.area().width());
394 EXPECT_EQ(10, platformGestureBuilder.area().height());
395 }
396
397 {
398 WebGestureEvent webGestureEvent;
399 webGestureEvent.type = WebInputEvent::GestureLongPress;
400 webGestureEvent.data.longPress.width = 30;
401 webGestureEvent.data.longPress.height = 30;
402
403 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
404 EXPECT_EQ(10, platformGestureBuilder.area().width());
405 EXPECT_EQ(10, platformGestureBuilder.area().height());
406 }
407
408 {
409 WebGestureEvent webGestureEvent;
410 webGestureEvent.type = WebInputEvent::GestureTwoFingerTap;
411 webGestureEvent.data.twoFingerTap.firstFingerWidth = 30;
412 webGestureEvent.data.twoFingerTap.firstFingerHeight = 30;
413
414 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
415 EXPECT_EQ(10, platformGestureBuilder.area().width());
416 EXPECT_EQ(10, platformGestureBuilder.area().height());
417 }
418
419 {
420 WebTouchEvent webTouchEvent;
421 webTouchEvent.type = WebInputEvent::TouchMove;
422 webTouchEvent.touchesLength = 1;
423 webTouchEvent.touches[0].state = WebTouchPoint::StateMoved;
424 webTouchEvent.touches[0].screenPosition.x = 100;
425 webTouchEvent.touches[0].screenPosition.y = 110;
426 webTouchEvent.touches[0].position.x = 100;
427 webTouchEvent.touches[0].position.y = 110;
428 webTouchEvent.touches[0].radiusX = 30;
429 webTouchEvent.touches[0].radiusY = 30;
430
431 PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
432 EXPECT_EQ(100, platformTouchBuilder.touchPoints()[0].screenPos().x());
433 EXPECT_EQ(110, platformTouchBuilder.touchPoints()[0].screenPos().y());
434 EXPECT_EQ(30, platformTouchBuilder.touchPoints()[0].pos().x());
435 EXPECT_EQ(30, platformTouchBuilder.touchPoints()[0].pos().y());
436 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].radiusX());
437 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].radiusY());
438 }
439 }
440
TEST(WebInputEventConversionTest,InputEventsConversions)441 TEST(WebInputEventConversionTest, InputEventsConversions)
442 {
443 const std::string baseURL("http://www.test3.com/");
444 const std::string fileName("fixed_layout.html");
445
446 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("fixed_layout.html"));
447 FrameTestHelpers::WebViewHelper webViewHelper;
448 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileName, true);
449 int pageWidth = 640;
450 int pageHeight = 480;
451 webViewImpl->resize(WebSize(pageWidth, pageHeight));
452 webViewImpl->layout();
453
454 FrameView* view = webViewImpl->page()->mainFrame()->view();
455 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document();
456 DOMWindow* domWindow = webViewImpl->page()->mainFrame()->document()->domWindow();
457 RenderObject* docRenderer = webViewImpl->page()->mainFrame()->document()->renderer();
458
459 {
460 WebGestureEvent webGestureEvent;
461 webGestureEvent.type = WebInputEvent::GestureTap;
462 webGestureEvent.x = 10;
463 webGestureEvent.y = 10;
464 webGestureEvent.globalX = 10;
465 webGestureEvent.globalY = 10;
466 webGestureEvent.data.tap.tapCount = 1;
467 webGestureEvent.data.tap.width = 10;
468 webGestureEvent.data.tap.height = 10;
469
470 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
471 EXPECT_EQ(10, platformGestureBuilder.position().x());
472 EXPECT_EQ(10, platformGestureBuilder.position().y());
473 EXPECT_EQ(10, platformGestureBuilder.globalPosition().x());
474 EXPECT_EQ(10, platformGestureBuilder.globalPosition().y());
475 EXPECT_EQ(1, platformGestureBuilder.tapCount());
476
477 RefPtr<WebCore::GestureEvent> coreGestureEvent = WebCore::GestureEvent::create(domWindow, platformGestureBuilder);
478 WebGestureEventBuilder recreatedWebGestureEvent(view, docRenderer, *coreGestureEvent);
479 EXPECT_EQ(webGestureEvent.type, recreatedWebGestureEvent.type);
480 EXPECT_EQ(webGestureEvent.x, recreatedWebGestureEvent.x);
481 EXPECT_EQ(webGestureEvent.y, recreatedWebGestureEvent.y);
482 EXPECT_EQ(webGestureEvent.globalX, recreatedWebGestureEvent.globalX);
483 EXPECT_EQ(webGestureEvent.globalY, recreatedWebGestureEvent.globalY);
484 EXPECT_EQ(webGestureEvent.data.tap.tapCount, recreatedWebGestureEvent.data.tap.tapCount);
485 }
486 }
487
488 } // anonymous namespace
489