Home | History | Annotate | Download | only in tests
      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 "web/WebInputEventConversion.h"
     34 
     35 #include "core/dom/Touch.h"
     36 #include "core/dom/TouchList.h"
     37 #include "core/events/GestureEvent.h"
     38 #include "core/events/KeyboardEvent.h"
     39 #include "core/events/MouseEvent.h"
     40 #include "core/events/TouchEvent.h"
     41 #include "core/frame/FrameHost.h"
     42 #include "core/frame/FrameView.h"
     43 #include "core/frame/LocalFrame.h"
     44 #include "core/rendering/RenderView.h"
     45 #include "public/web/WebFrame.h"
     46 #include "public/web/WebSettings.h"
     47 #include "web/WebViewImpl.h"
     48 #include "web/tests/FrameTestHelpers.h"
     49 #include "web/tests/URLTestHelpers.h"
     50 #include <gtest/gtest.h>
     51 
     52 using namespace blink;
     53 using namespace WebCore;
     54 
     55 namespace {
     56 
     57 PassRefPtrWillBeRawPtr<WebCore::KeyboardEvent> createKeyboardEventWithLocation(WebCore::KeyboardEvent::KeyLocationCode location)
     58 {
     59     return WebCore::KeyboardEvent::create("keydown", true, true, 0, "", location, false, false, false, false, false);
     60 }
     61 
     62 int getModifiersForKeyLocationCode(WebCore::KeyboardEvent::KeyLocationCode location)
     63 {
     64     RefPtrWillBeRawPtr<WebCore::KeyboardEvent> event = createKeyboardEventWithLocation(location);
     65     blink::WebKeyboardEventBuilder convertedEvent(*event);
     66     return convertedEvent.modifiers;
     67 }
     68 
     69 TEST(WebInputEventConversionTest, WebKeyboardEventBuilder)
     70 {
     71     // Test key location conversion.
     72     int modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_STANDARD);
     73     EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent::IsRight);
     74 
     75     modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_LEFT);
     76     EXPECT_TRUE(modifiers & WebInputEvent::IsLeft);
     77     EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEvent::IsRight);
     78 
     79     modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_RIGHT);
     80     EXPECT_TRUE(modifiers & WebInputEvent::IsRight);
     81     EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEvent::IsLeft);
     82 
     83     modifiers = getModifiersForKeyLocationCode(WebCore::KeyboardEvent::DOM_KEY_LOCATION_NUMPAD);
     84     EXPECT_TRUE(modifiers & WebInputEvent::IsKeyPad);
     85     EXPECT_FALSE(modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent::IsRight);
     86 }
     87 
     88 TEST(WebInputEventConversionTest, WebTouchEventBuilder)
     89 {
     90     RefPtrWillBeRawPtr<WebCore::TouchEvent> event = WebCore::TouchEvent::create();
     91     WebMouseEventBuilder mouse(0, 0, *event);
     92     EXPECT_EQ(WebInputEvent::Undefined, mouse.type);
     93 }
     94 
     95 TEST(WebInputEventConversionTest, InputEventsScaling)
     96 {
     97     const std::string baseURL("http://www.test.com/");
     98     const std::string fileName("fixed_layout.html");
     99 
    100     URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("fixed_layout.html"));
    101     FrameTestHelpers::WebViewHelper webViewHelper;
    102     WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileName, true);
    103     webViewImpl->settings()->setViewportEnabled(true);
    104     int pageWidth = 640;
    105     int pageHeight = 480;
    106     webViewImpl->resize(WebSize(pageWidth, pageHeight));
    107     webViewImpl->layout();
    108 
    109     webViewImpl->setPageScaleFactor(2);
    110 
    111     FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view();
    112     RefPtrWillBeRawPtr<Document> document = toLocalFrame(webViewImpl->page()->mainFrame())->document();
    113     LocalDOMWindow* domWindow = document->domWindow();
    114     RenderView* documentRenderView = document->renderView();
    115 
    116     {
    117         WebMouseEvent webMouseEvent;
    118         webMouseEvent.type = WebInputEvent::MouseMove;
    119         webMouseEvent.x = 10;
    120         webMouseEvent.y = 10;
    121         webMouseEvent.windowX = 10;
    122         webMouseEvent.windowY = 10;
    123         webMouseEvent.globalX = 10;
    124         webMouseEvent.globalY = 10;
    125         webMouseEvent.movementX = 10;
    126         webMouseEvent.movementY = 10;
    127 
    128         PlatformMouseEventBuilder platformMouseBuilder(view, webMouseEvent);
    129         EXPECT_EQ(5, platformMouseBuilder.position().x());
    130         EXPECT_EQ(5, platformMouseBuilder.position().y());
    131         EXPECT_EQ(10, platformMouseBuilder.globalPosition().x());
    132         EXPECT_EQ(10, platformMouseBuilder.globalPosition().y());
    133         EXPECT_EQ(5, platformMouseBuilder.movementDelta().x());
    134         EXPECT_EQ(5, platformMouseBuilder.movementDelta().y());
    135     }
    136 
    137     {
    138         WebGestureEvent webGestureEvent;
    139         webGestureEvent.type = WebInputEvent::GestureScrollUpdate;
    140         webGestureEvent.x = 10;
    141         webGestureEvent.y = 10;
    142         webGestureEvent.globalX = 10;
    143         webGestureEvent.globalY = 10;
    144         webGestureEvent.data.scrollUpdate.deltaX = 10;
    145         webGestureEvent.data.scrollUpdate.deltaY = 10;
    146 
    147         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    148         EXPECT_EQ(5, platformGestureBuilder.position().x());
    149         EXPECT_EQ(5, platformGestureBuilder.position().y());
    150         EXPECT_EQ(10, platformGestureBuilder.globalPosition().x());
    151         EXPECT_EQ(10, platformGestureBuilder.globalPosition().y());
    152         EXPECT_EQ(5, platformGestureBuilder.deltaX());
    153         EXPECT_EQ(5, platformGestureBuilder.deltaY());
    154     }
    155 
    156     {
    157         WebGestureEvent webGestureEvent;
    158         webGestureEvent.type = WebInputEvent::GestureTap;
    159         webGestureEvent.data.tap.width = 10;
    160         webGestureEvent.data.tap.height = 10;
    161 
    162         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    163         EXPECT_EQ(5, platformGestureBuilder.area().width());
    164         EXPECT_EQ(5, platformGestureBuilder.area().height());
    165     }
    166 
    167     {
    168         WebGestureEvent webGestureEvent;
    169         webGestureEvent.type = WebInputEvent::GestureTapUnconfirmed;
    170         webGestureEvent.data.tap.width = 10;
    171         webGestureEvent.data.tap.height = 10;
    172 
    173         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    174         EXPECT_EQ(5, platformGestureBuilder.area().width());
    175         EXPECT_EQ(5, platformGestureBuilder.area().height());
    176     }
    177 
    178     {
    179         WebGestureEvent webGestureEvent;
    180         webGestureEvent.type = WebInputEvent::GestureTapDown;
    181         webGestureEvent.data.tapDown.width = 10;
    182         webGestureEvent.data.tapDown.height = 10;
    183 
    184         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    185         EXPECT_EQ(5, platformGestureBuilder.area().width());
    186         EXPECT_EQ(5, platformGestureBuilder.area().height());
    187     }
    188 
    189     {
    190         WebGestureEvent webGestureEvent;
    191         webGestureEvent.type = WebInputEvent::GestureShowPress;
    192         webGestureEvent.data.showPress.width = 10;
    193         webGestureEvent.data.showPress.height = 10;
    194 
    195         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    196         EXPECT_EQ(5, platformGestureBuilder.area().width());
    197         EXPECT_EQ(5, platformGestureBuilder.area().height());
    198     }
    199 
    200     {
    201         WebGestureEvent webGestureEvent;
    202         webGestureEvent.type = WebInputEvent::GestureLongPress;
    203         webGestureEvent.data.longPress.width = 10;
    204         webGestureEvent.data.longPress.height = 10;
    205 
    206         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    207         EXPECT_EQ(5, platformGestureBuilder.area().width());
    208         EXPECT_EQ(5, platformGestureBuilder.area().height());
    209     }
    210 
    211     {
    212         WebGestureEvent webGestureEvent;
    213         webGestureEvent.type = WebInputEvent::GestureTwoFingerTap;
    214         webGestureEvent.data.twoFingerTap.firstFingerWidth = 10;
    215         webGestureEvent.data.twoFingerTap.firstFingerHeight = 10;
    216 
    217         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    218         EXPECT_EQ(5, platformGestureBuilder.area().width());
    219         EXPECT_EQ(5, platformGestureBuilder.area().height());
    220     }
    221 
    222     {
    223         WebTouchEvent webTouchEvent;
    224         webTouchEvent.type = WebInputEvent::TouchMove;
    225         webTouchEvent.touchesLength = 1;
    226         webTouchEvent.touches[0].state = WebTouchPoint::StateMoved;
    227         webTouchEvent.touches[0].screenPosition.x = 10.6f;
    228         webTouchEvent.touches[0].screenPosition.y = 10.4f;
    229         webTouchEvent.touches[0].position.x = 10.6f;
    230         webTouchEvent.touches[0].position.y = 10.4f;
    231         webTouchEvent.touches[0].radiusX = 10.6f;
    232         webTouchEvent.touches[0].radiusY = 10.4f;
    233 
    234         EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].screenPosition.x);
    235         EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].screenPosition.y);
    236         EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].position.x);
    237         EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].position.y);
    238         EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].radiusX);
    239         EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].radiusY);
    240 
    241         PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
    242         EXPECT_FLOAT_EQ(10.6f, platformTouchBuilder.touchPoints()[0].screenPos().x());
    243         EXPECT_FLOAT_EQ(10.4f, platformTouchBuilder.touchPoints()[0].screenPos().y());
    244         EXPECT_FLOAT_EQ(5.3f, platformTouchBuilder.touchPoints()[0].pos().x());
    245         EXPECT_FLOAT_EQ(5.2f, platformTouchBuilder.touchPoints()[0].pos().y());
    246         EXPECT_FLOAT_EQ(5.3f, platformTouchBuilder.touchPoints()[0].radius().width());
    247         EXPECT_FLOAT_EQ(5.2f, platformTouchBuilder.touchPoints()[0].radius().height());
    248     }
    249 
    250     // Reverse builders should *not* go back to physical pixels, as they are used for plugins
    251     // which expect CSS pixel coordinates.
    252     {
    253         PlatformMouseEvent platformMouseEvent(IntPoint(10, 10), IntPoint(10, 10), LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
    254         RefPtrWillBeRawPtr<MouseEvent> mouseEvent = MouseEvent::create(WebCore::EventTypeNames::mousemove, domWindow, platformMouseEvent, 0, document);
    255         WebMouseEventBuilder webMouseBuilder(view, documentRenderView, *mouseEvent);
    256 
    257         EXPECT_EQ(10, webMouseBuilder.x);
    258         EXPECT_EQ(10, webMouseBuilder.y);
    259         EXPECT_EQ(10, webMouseBuilder.globalX);
    260         EXPECT_EQ(10, webMouseBuilder.globalY);
    261         EXPECT_EQ(10, webMouseBuilder.windowX);
    262         EXPECT_EQ(10, webMouseBuilder.windowY);
    263     }
    264 
    265     {
    266         PlatformMouseEvent platformMouseEvent(IntPoint(10, 10), IntPoint(10, 10), NoButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
    267         RefPtrWillBeRawPtr<MouseEvent> mouseEvent = MouseEvent::create(WebCore::EventTypeNames::mousemove, domWindow, platformMouseEvent, 0, document);
    268         WebMouseEventBuilder webMouseBuilder(view, documentRenderView, *mouseEvent);
    269         EXPECT_EQ(WebMouseEvent::ButtonNone, webMouseBuilder.button);
    270     }
    271 
    272     {
    273         PlatformGestureEvent platformGestureEvent(PlatformEvent::GestureScrollUpdate, IntPoint(10, 10), IntPoint(10, 10), IntSize(10, 10), 0, false, false, false, false, 10, 10, 10, 10);
    274         RefPtrWillBeRawPtr<GestureEvent> gestureEvent = GestureEvent::create(domWindow, platformGestureEvent);
    275         WebGestureEventBuilder webGestureBuilder(view, documentRenderView, *gestureEvent);
    276 
    277         EXPECT_EQ(10, webGestureBuilder.x);
    278         EXPECT_EQ(10, webGestureBuilder.y);
    279         EXPECT_EQ(10, webGestureBuilder.globalX);
    280         EXPECT_EQ(10, webGestureBuilder.globalY);
    281         EXPECT_EQ(10, webGestureBuilder.data.scrollUpdate.deltaX);
    282         EXPECT_EQ(10, webGestureBuilder.data.scrollUpdate.deltaY);
    283     }
    284 
    285     {
    286         RefPtrWillBeRawPtr<Touch> touch = Touch::create(toLocalFrame(webViewImpl->page()->mainFrame()), document.get(), 0, FloatPoint(10, 9.5), FloatPoint(3.5, 2), FloatSize(4, 4.5), 0, 0);
    287         RefPtrWillBeRawPtr<TouchList> touchList = TouchList::create();
    288         touchList->append(touch);
    289         RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(touchList.get(), touchList.get(), touchList.get(), WebCore::EventTypeNames::touchmove, domWindow, false, false, false, false, false);
    290 
    291         WebTouchEventBuilder webTouchBuilder(view, documentRenderView, *touchEvent);
    292         ASSERT_EQ(1u, webTouchBuilder.touchesLength);
    293         EXPECT_EQ(10, webTouchBuilder.touches[0].screenPosition.x);
    294         EXPECT_FLOAT_EQ(9.5, webTouchBuilder.touches[0].screenPosition.y);
    295         EXPECT_FLOAT_EQ(3.5, webTouchBuilder.touches[0].position.x);
    296         EXPECT_FLOAT_EQ(2, webTouchBuilder.touches[0].position.y);
    297         EXPECT_FLOAT_EQ(4, webTouchBuilder.touches[0].radiusX);
    298         EXPECT_FLOAT_EQ(4.5, webTouchBuilder.touches[0].radiusY);
    299         EXPECT_FALSE(webTouchBuilder.cancelable);
    300     }
    301 }
    302 
    303 TEST(WebInputEventConversionTest, InputEventsTransform)
    304 {
    305     const std::string baseURL("http://www.test2.com/");
    306     const std::string fileName("fixed_layout.html");
    307 
    308     URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("fixed_layout.html"));
    309     FrameTestHelpers::WebViewHelper webViewHelper;
    310     WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileName, true);
    311     webViewImpl->settings()->setViewportEnabled(true);
    312     int pageWidth = 640;
    313     int pageHeight = 480;
    314     webViewImpl->resize(WebSize(pageWidth, pageHeight));
    315     webViewImpl->layout();
    316 
    317     webViewImpl->setPageScaleFactor(2);
    318     webViewImpl->setRootLayerTransform(WebSize(10, 20), 1.5);
    319 
    320     FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view();
    321 
    322     {
    323         WebMouseEvent webMouseEvent;
    324         webMouseEvent.type = WebInputEvent::MouseMove;
    325         webMouseEvent.x = 100;
    326         webMouseEvent.y = 110;
    327         webMouseEvent.windowX = 100;
    328         webMouseEvent.windowY = 110;
    329         webMouseEvent.globalX = 100;
    330         webMouseEvent.globalY = 110;
    331         webMouseEvent.movementX = 60;
    332         webMouseEvent.movementY = 60;
    333 
    334         PlatformMouseEventBuilder platformMouseBuilder(view, webMouseEvent);
    335         EXPECT_EQ(30, platformMouseBuilder.position().x());
    336         EXPECT_EQ(30, platformMouseBuilder.position().y());
    337         EXPECT_EQ(100, platformMouseBuilder.globalPosition().x());
    338         EXPECT_EQ(110, platformMouseBuilder.globalPosition().y());
    339         EXPECT_EQ(20, platformMouseBuilder.movementDelta().x());
    340         EXPECT_EQ(20, platformMouseBuilder.movementDelta().y());
    341     }
    342 
    343     {
    344         WebGestureEvent webGestureEvent;
    345         webGestureEvent.type = WebInputEvent::GestureScrollUpdate;
    346         webGestureEvent.x = 100;
    347         webGestureEvent.y = 110;
    348         webGestureEvent.globalX = 100;
    349         webGestureEvent.globalY = 110;
    350         webGestureEvent.data.scrollUpdate.deltaX = 60;
    351         webGestureEvent.data.scrollUpdate.deltaY = 60;
    352 
    353         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    354         EXPECT_EQ(30, platformGestureBuilder.position().x());
    355         EXPECT_EQ(30, platformGestureBuilder.position().y());
    356         EXPECT_EQ(100, platformGestureBuilder.globalPosition().x());
    357         EXPECT_EQ(110, platformGestureBuilder.globalPosition().y());
    358         EXPECT_EQ(20, platformGestureBuilder.deltaX());
    359         EXPECT_EQ(20, platformGestureBuilder.deltaY());
    360     }
    361 
    362     {
    363         WebGestureEvent webGestureEvent;
    364         webGestureEvent.type = WebInputEvent::GestureTap;
    365         webGestureEvent.data.tap.width = 30;
    366         webGestureEvent.data.tap.height = 30;
    367 
    368         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    369         EXPECT_EQ(10, platformGestureBuilder.area().width());
    370         EXPECT_EQ(10, platformGestureBuilder.area().height());
    371     }
    372 
    373     {
    374         WebGestureEvent webGestureEvent;
    375         webGestureEvent.type = WebInputEvent::GestureTapUnconfirmed;
    376         webGestureEvent.data.tap.width = 30;
    377         webGestureEvent.data.tap.height = 30;
    378 
    379         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    380         EXPECT_EQ(10, platformGestureBuilder.area().width());
    381         EXPECT_EQ(10, platformGestureBuilder.area().height());
    382     }
    383 
    384     {
    385         WebGestureEvent webGestureEvent;
    386         webGestureEvent.type = WebInputEvent::GestureTapDown;
    387         webGestureEvent.data.tapDown.width = 30;
    388         webGestureEvent.data.tapDown.height = 30;
    389 
    390         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    391         EXPECT_EQ(10, platformGestureBuilder.area().width());
    392         EXPECT_EQ(10, platformGestureBuilder.area().height());
    393     }
    394 
    395     {
    396         WebGestureEvent webGestureEvent;
    397         webGestureEvent.type = WebInputEvent::GestureShowPress;
    398         webGestureEvent.data.showPress.width = 30;
    399         webGestureEvent.data.showPress.height = 30;
    400 
    401         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    402         EXPECT_EQ(10, platformGestureBuilder.area().width());
    403         EXPECT_EQ(10, platformGestureBuilder.area().height());
    404     }
    405 
    406     {
    407         WebGestureEvent webGestureEvent;
    408         webGestureEvent.type = WebInputEvent::GestureLongPress;
    409         webGestureEvent.data.longPress.width = 30;
    410         webGestureEvent.data.longPress.height = 30;
    411 
    412         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    413         EXPECT_EQ(10, platformGestureBuilder.area().width());
    414         EXPECT_EQ(10, platformGestureBuilder.area().height());
    415     }
    416 
    417     {
    418         WebGestureEvent webGestureEvent;
    419         webGestureEvent.type = WebInputEvent::GestureTwoFingerTap;
    420         webGestureEvent.data.twoFingerTap.firstFingerWidth = 30;
    421         webGestureEvent.data.twoFingerTap.firstFingerHeight = 30;
    422 
    423         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    424         EXPECT_EQ(10, platformGestureBuilder.area().width());
    425         EXPECT_EQ(10, platformGestureBuilder.area().height());
    426     }
    427 
    428     {
    429         WebTouchEvent webTouchEvent;
    430         webTouchEvent.type = WebInputEvent::TouchMove;
    431         webTouchEvent.touchesLength = 1;
    432         webTouchEvent.touches[0].state = WebTouchPoint::StateMoved;
    433         webTouchEvent.touches[0].screenPosition.x = 100;
    434         webTouchEvent.touches[0].screenPosition.y = 110;
    435         webTouchEvent.touches[0].position.x = 100;
    436         webTouchEvent.touches[0].position.y = 110;
    437         webTouchEvent.touches[0].radiusX = 30;
    438         webTouchEvent.touches[0].radiusY = 30;
    439 
    440         PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
    441         EXPECT_FLOAT_EQ(100, platformTouchBuilder.touchPoints()[0].screenPos().x());
    442         EXPECT_FLOAT_EQ(110, platformTouchBuilder.touchPoints()[0].screenPos().y());
    443         EXPECT_FLOAT_EQ(30, platformTouchBuilder.touchPoints()[0].pos().x());
    444         EXPECT_FLOAT_EQ(30, platformTouchBuilder.touchPoints()[0].pos().y());
    445         EXPECT_FLOAT_EQ(10, platformTouchBuilder.touchPoints()[0].radius().width());
    446         EXPECT_FLOAT_EQ(10, platformTouchBuilder.touchPoints()[0].radius().height());
    447     }
    448 }
    449 
    450 TEST(WebInputEventConversionTest, InputEventsConversions)
    451 {
    452     const std::string baseURL("http://www.test3.com/");
    453     const std::string fileName("fixed_layout.html");
    454 
    455     URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("fixed_layout.html"));
    456     FrameTestHelpers::WebViewHelper webViewHelper;
    457     WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileName, true);
    458     int pageWidth = 640;
    459     int pageHeight = 480;
    460     webViewImpl->resize(WebSize(pageWidth, pageHeight));
    461     webViewImpl->layout();
    462 
    463     FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view();
    464     RefPtrWillBeRawPtr<Document> document = toLocalFrame(webViewImpl->page()->mainFrame())->document();
    465     LocalDOMWindow* domWindow = document->domWindow();
    466     RenderView* documentRenderView = document->renderView();
    467 
    468     {
    469         WebGestureEvent webGestureEvent;
    470         webGestureEvent.type = WebInputEvent::GestureTap;
    471         webGestureEvent.x = 10;
    472         webGestureEvent.y = 10;
    473         webGestureEvent.globalX = 10;
    474         webGestureEvent.globalY = 10;
    475         webGestureEvent.data.tap.tapCount = 1;
    476         webGestureEvent.data.tap.width = 10;
    477         webGestureEvent.data.tap.height = 10;
    478 
    479         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    480         EXPECT_EQ(10.f, platformGestureBuilder.position().x());
    481         EXPECT_EQ(10.f, platformGestureBuilder.position().y());
    482         EXPECT_EQ(10.f, platformGestureBuilder.globalPosition().x());
    483         EXPECT_EQ(10.f, platformGestureBuilder.globalPosition().y());
    484         EXPECT_EQ(1, platformGestureBuilder.tapCount());
    485 
    486         RefPtrWillBeRawPtr<WebCore::GestureEvent> coreGestureEvent = WebCore::GestureEvent::create(domWindow, platformGestureBuilder);
    487         WebGestureEventBuilder recreatedWebGestureEvent(view, documentRenderView, *coreGestureEvent);
    488         EXPECT_EQ(webGestureEvent.type, recreatedWebGestureEvent.type);
    489         EXPECT_EQ(webGestureEvent.x, recreatedWebGestureEvent.x);
    490         EXPECT_EQ(webGestureEvent.y, recreatedWebGestureEvent.y);
    491         EXPECT_EQ(webGestureEvent.globalX, recreatedWebGestureEvent.globalX);
    492         EXPECT_EQ(webGestureEvent.globalY, recreatedWebGestureEvent.globalY);
    493         EXPECT_EQ(webGestureEvent.data.tap.tapCount, recreatedWebGestureEvent.data.tap.tapCount);
    494     }
    495 }
    496 
    497 static void setupVirtualViewportPinch(WebSettings* settings)
    498 {
    499     settings->setPinchVirtualViewportEnabled(true);
    500     settings->setAcceleratedCompositingEnabled(true);
    501 }
    502 
    503 TEST(WebInputEventConversionTest, PinchViewportOffset)
    504 {
    505     const std::string baseURL("http://www.test4.com/");
    506     const std::string fileName("fixed_layout.html");
    507 
    508     URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("fixed_layout.html"));
    509     FrameTestHelpers::WebViewHelper webViewHelper;
    510     WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileName, true, 0, 0, setupVirtualViewportPinch);
    511     int pageWidth = 640;
    512     int pageHeight = 480;
    513     webViewImpl->resize(WebSize(pageWidth, pageHeight));
    514     webViewImpl->layout();
    515 
    516     webViewImpl->setPageScaleFactor(2);
    517 
    518     IntPoint pinchOffset(35, 60);
    519     webViewImpl->page()->frameHost().pinchViewport().setLocation(pinchOffset);
    520 
    521     FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view();
    522 
    523     {
    524         WebMouseEvent webMouseEvent;
    525         webMouseEvent.type = WebInputEvent::MouseMove;
    526         webMouseEvent.x = 10;
    527         webMouseEvent.y = 10;
    528         webMouseEvent.windowX = 10;
    529         webMouseEvent.windowY = 10;
    530         webMouseEvent.globalX = 10;
    531         webMouseEvent.globalY = 10;
    532 
    533         PlatformMouseEventBuilder platformMouseBuilder(view, webMouseEvent);
    534         EXPECT_EQ(5 + pinchOffset.x(), platformMouseBuilder.position().x());
    535         EXPECT_EQ(5 + pinchOffset.y(), platformMouseBuilder.position().y());
    536         EXPECT_EQ(10, platformMouseBuilder.globalPosition().x());
    537         EXPECT_EQ(10, platformMouseBuilder.globalPosition().y());
    538     }
    539 
    540     {
    541         WebMouseWheelEvent webMouseWheelEvent;
    542         webMouseWheelEvent.type = WebInputEvent::MouseWheel;
    543         webMouseWheelEvent.x = 10;
    544         webMouseWheelEvent.y = 10;
    545         webMouseWheelEvent.windowX = 10;
    546         webMouseWheelEvent.windowY = 10;
    547         webMouseWheelEvent.globalX = 10;
    548         webMouseWheelEvent.globalY = 10;
    549 
    550         PlatformWheelEventBuilder platformWheelBuilder(view, webMouseWheelEvent);
    551         EXPECT_EQ(5 + pinchOffset.x(), platformWheelBuilder.position().x());
    552         EXPECT_EQ(5 + pinchOffset.y(), platformWheelBuilder.position().y());
    553         EXPECT_EQ(10, platformWheelBuilder.globalPosition().x());
    554         EXPECT_EQ(10, platformWheelBuilder.globalPosition().y());
    555     }
    556 
    557     {
    558         WebGestureEvent webGestureEvent;
    559         webGestureEvent.type = WebInputEvent::GestureScrollUpdate;
    560         webGestureEvent.x = 10;
    561         webGestureEvent.y = 10;
    562         webGestureEvent.globalX = 10;
    563         webGestureEvent.globalY = 10;
    564 
    565         PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent);
    566         EXPECT_EQ(5 + pinchOffset.x(), platformGestureBuilder.position().x());
    567         EXPECT_EQ(5 + pinchOffset.y(), platformGestureBuilder.position().y());
    568         EXPECT_EQ(10, platformGestureBuilder.globalPosition().x());
    569         EXPECT_EQ(10, platformGestureBuilder.globalPosition().y());
    570     }
    571 
    572     {
    573         WebTouchEvent webTouchEvent;
    574         webTouchEvent.type = WebInputEvent::TouchMove;
    575         webTouchEvent.touchesLength = 1;
    576         webTouchEvent.touches[0].state = WebTouchPoint::StateMoved;
    577         webTouchEvent.touches[0].screenPosition.x = 10.6f;
    578         webTouchEvent.touches[0].screenPosition.y = 10.4f;
    579         webTouchEvent.touches[0].position.x = 10.6f;
    580         webTouchEvent.touches[0].position.y = 10.4f;
    581 
    582         EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].screenPosition.x);
    583         EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].screenPosition.y);
    584         EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].position.x);
    585         EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].position.y);
    586 
    587         PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
    588         EXPECT_FLOAT_EQ(10.6f, platformTouchBuilder.touchPoints()[0].screenPos().x());
    589         EXPECT_FLOAT_EQ(10.4f, platformTouchBuilder.touchPoints()[0].screenPos().y());
    590         EXPECT_FLOAT_EQ(5.3f + pinchOffset.x(), platformTouchBuilder.touchPoints()[0].pos().x());
    591         EXPECT_FLOAT_EQ(5.2f + pinchOffset.y(), platformTouchBuilder.touchPoints()[0].pos().y());
    592     }
    593 }
    594 
    595 } // anonymous namespace
    596