Home | History | Annotate | Download | only in runner
      1 /*
      2  * Copyright (C) 2010 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 /*
     32   EventSender class:
     33   Bound to a JavaScript window.eventSender object using
     34   CppBoundClass::bindToJavascript(), this allows layout tests to fire DOM events.
     35 */
     36 
     37 #ifndef EventSender_h
     38 #define EventSender_h
     39 
     40 #include "CppBoundClass.h"
     41 #include "public/platform/WebPoint.h"
     42 #include "public/testing/WebTask.h"
     43 #include "public/web/WebDragOperation.h"
     44 #include "public/web/WebInputEvent.h"
     45 #include <memory>
     46 
     47 namespace WebKit {
     48 class WebDragData;
     49 class WebView;
     50 struct WebContextMenuData;
     51 }
     52 
     53 namespace WebTestRunner {
     54 
     55 class WebTestDelegate;
     56 
     57 class EventSender : public CppBoundClass {
     58 public:
     59     EventSender();
     60     ~EventSender();
     61 
     62     void setDelegate(WebTestDelegate* delegate) { m_delegate = delegate; }
     63     void setWebView(WebKit::WebView* webView) { m_webView = webView; }
     64 
     65     void setContextMenuData(const WebKit::WebContextMenuData&);
     66 
     67     // Resets some static variable state.
     68     void reset();
     69 
     70     // Simulate drag&drop system call.
     71     void doDragDrop(const WebKit::WebDragData&, WebKit::WebDragOperationsMask);
     72 
     73     // Test helper for dragging out images.
     74     void dumpFilenameBeingDragged(const CppArgumentList&, CppVariant*);
     75 
     76     // JS callback methods.
     77     void contextClick(const CppArgumentList&, CppVariant*);
     78     void mouseDown(const CppArgumentList&, CppVariant*);
     79     void mouseUp(const CppArgumentList&, CppVariant*);
     80     void mouseMoveTo(const CppArgumentList&, CppVariant*);
     81     void leapForward(const CppArgumentList&, CppVariant*);
     82     void keyDown(const CppArgumentList&, CppVariant*);
     83     void dispatchMessage(const CppArgumentList&, CppVariant*);
     84     // FIXME: These aren't really events. They should be moved to layout controller.
     85     void textZoomIn(const CppArgumentList&, CppVariant*);
     86     void textZoomOut(const CppArgumentList&, CppVariant*);
     87     void zoomPageIn(const CppArgumentList&, CppVariant*);
     88     void zoomPageOut(const CppArgumentList&, CppVariant*);
     89     void setPageScaleFactor(const CppArgumentList&, CppVariant*);
     90 
     91     void mouseDragBegin(const CppArgumentList&, CppVariant*);
     92     void mouseScrollBy(const CppArgumentList&, CppVariant*);
     93     void continuousMouseScrollBy(const CppArgumentList&, CppVariant*);
     94     void scheduleAsynchronousClick(const CppArgumentList&, CppVariant*);
     95     void scheduleAsynchronousKeyDown(const CppArgumentList&, CppVariant*);
     96     void beginDragWithFiles(const CppArgumentList&, CppVariant*);
     97     CppVariant dragMode;
     98 
     99     void addTouchPoint(const CppArgumentList&, CppVariant*);
    100     void cancelTouchPoint(const CppArgumentList&, CppVariant*);
    101     void clearTouchPoints(const CppArgumentList&, CppVariant*);
    102     void releaseTouchPoint(const CppArgumentList&, CppVariant*);
    103     void setTouchModifier(const CppArgumentList&, CppVariant*);
    104     void touchCancel(const CppArgumentList&, CppVariant*);
    105     void touchEnd(const CppArgumentList&, CppVariant*);
    106     void touchMove(const CppArgumentList&, CppVariant*);
    107     void touchStart(const CppArgumentList&, CppVariant*);
    108     void updateTouchPoint(const CppArgumentList&, CppVariant*);
    109 
    110     void gestureFlingCancel(const CppArgumentList&, CppVariant*);
    111     void gestureFlingStart(const CppArgumentList&, CppVariant*);
    112     void gestureScrollBegin(const CppArgumentList&, CppVariant*);
    113     void gestureScrollEnd(const CppArgumentList&, CppVariant*);
    114     void gestureScrollFirstPoint(const CppArgumentList&, CppVariant*);
    115     void gestureScrollUpdate(const CppArgumentList&, CppVariant*);
    116     void gestureScrollUpdateWithoutPropagation(const CppArgumentList&, CppVariant*);
    117     void gestureTap(const CppArgumentList&, CppVariant*);
    118     void gestureTapDown(const CppArgumentList&, CppVariant*);
    119     void gestureTapCancel(const CppArgumentList&, CppVariant*);
    120     void gestureLongPress(const CppArgumentList&, CppVariant*);
    121     void gestureLongTap(const CppArgumentList&, CppVariant*);
    122     void gestureTwoFingerTap(const CppArgumentList&, CppVariant*);
    123     void gestureEvent(WebKit::WebInputEvent::Type, const CppArgumentList&);
    124 
    125     // Setting this to false makes EventSender not force layout() calls.
    126     // This makes it possible to test the standard WebCore event dispatch.
    127     CppVariant forceLayoutOnEvents;
    128 
    129     // Unimplemented stubs
    130     void enableDOMUIEventLogging(const CppArgumentList&, CppVariant*);
    131     void fireKeyboardEventsToElement(const CppArgumentList&, CppVariant*);
    132     void clearKillRing(const CppArgumentList&, CppVariant*);
    133 
    134     // Properties used in layout tests.
    135 #if defined(OS_WIN)
    136     CppVariant wmKeyDown;
    137     CppVariant wmKeyUp;
    138     CppVariant wmChar;
    139     CppVariant wmDeadChar;
    140     CppVariant wmSysKeyDown;
    141     CppVariant wmSysKeyUp;
    142     CppVariant wmSysChar;
    143     CppVariant wmSysDeadChar;
    144 #endif
    145 
    146     WebTaskList* taskList() { return &m_taskList; }
    147 
    148 private:
    149     WebKit::WebView* webview() { return m_webView; }
    150 
    151     // Returns true if dragMode is true.
    152     bool isDragMode() { return dragMode.isBool() && dragMode.toBoolean(); }
    153 
    154     bool shouldForceLayoutOnEvents() const { return forceLayoutOnEvents.isBool() && forceLayoutOnEvents.toBoolean(); }
    155 
    156     // Sometimes we queue up mouse move and mouse up events for drag drop
    157     // handling purposes. These methods dispatch the event.
    158     void doMouseMove(const WebKit::WebMouseEvent&);
    159     void doMouseUp(const WebKit::WebMouseEvent&);
    160     static void doLeapForward(int milliseconds);
    161     void replaySavedEvents();
    162 
    163     // Helper to return the button type given a button code
    164     static WebKit::WebMouseEvent::Button getButtonTypeFromButtonNumber(int);
    165 
    166     // Helper to extract the button number from the optional argument in
    167     // mouseDown and mouseUp
    168     static int getButtonNumberFromSingleArg(const CppArgumentList&);
    169 
    170     // Returns true if the specified key code passed in needs a shift key
    171     // modifier to be passed into the generated event.
    172     bool needsShiftModifier(int);
    173 
    174     void finishDragAndDrop(const WebKit::WebMouseEvent&, WebKit::WebDragOperation);
    175     void updateClickCountForButton(WebKit::WebMouseEvent::Button);
    176 
    177     // Compose a touch event from the current touch points and send it.
    178     void sendCurrentTouchEvent(const WebKit::WebInputEvent::Type);
    179 
    180     // Handle a request to send a wheel event.
    181     void handleMouseWheel(const CppArgumentList&, CppVariant*, bool continuous);
    182 
    183     WebTaskList m_taskList;
    184 
    185     WebTestDelegate* m_delegate;
    186     WebKit::WebView* m_webView;
    187 
    188     std::auto_ptr<WebKit::WebContextMenuData> m_lastContextMenuData;
    189 
    190     // Location of the touch point that initiated a gesture.
    191     WebKit::WebPoint m_currentGestureLocation;
    192 
    193     // Location of last mouseMoveTo event.
    194     static WebKit::WebPoint lastMousePos;
    195 
    196     // Currently pressed mouse button (Left/Right/Middle or None)
    197     static WebKit::WebMouseEvent::Button pressedButton;
    198 
    199     // The last button number passed to mouseDown and mouseUp.
    200     // Used to determine whether the click count continues to
    201     // increment or not.
    202     static WebKit::WebMouseEvent::Button lastButtonType;
    203 };
    204 
    205 }
    206 
    207 #endif // EventSender_h
    208