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