1 // Copyright 2014 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.
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_EVENT_SENDER_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_EVENT_SENDER_H_
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "build/build_config.h"
16 #include "content/shell/renderer/test_runner/WebTask.h"
17 #include "third_party/WebKit/public/platform/WebDragData.h"
18 #include "third_party/WebKit/public/platform/WebPoint.h"
19 #include "third_party/WebKit/public/web/WebDragOperation.h"
20 #include "third_party/WebKit/public/web/WebInputEvent.h"
21 #include "third_party/WebKit/public/web/WebTouchPoint.h"
26 struct WebContextMenuData
;
33 namespace WebTestRunner
{
35 class WebTestDelegate
;
40 // Key event location code introduced in DOM Level 3.
41 // See also: http://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents
42 enum KeyLocationCode
{
43 DOMKeyLocationStandard
= 0x00,
44 DOMKeyLocationLeft
= 0x01,
45 DOMKeyLocationRight
= 0x02,
46 DOMKeyLocationNumpad
= 0x03
49 class EventSender
: public base::SupportsWeakPtr
<EventSender
> {
51 explicit EventSender(WebTestRunner::TestInterfaces
*);
52 virtual ~EventSender();
55 void Install(blink::WebFrame
*);
56 void SetDelegate(WebTestRunner::WebTestDelegate
*);
57 void SetWebView(blink::WebView
*);
59 void SetContextMenuData(const blink::WebContextMenuData
&);
61 void DoDragDrop(const blink::WebDragData
&, blink::WebDragOperationsMask
);
63 void MouseDown(int button_number
, int modifiers
);
64 void MouseUp(int button_number
, int modifiers
);
65 void KeyDown(const std::string
& code_str
,
67 KeyLocationCode location
);
69 WebTestRunner::WebTaskList
* taskList() { return &task_list_
; }
72 friend class EventSenderBindings
;
85 blink::WebMouseEvent::Button button_type
; // For MouseUp.
86 blink::WebPoint pos
; // For MouseMove.
87 int milliseconds
; // For LeapForward.
91 void EnableDOMUIEventLogging();
92 void FireKeyboardEventsToElement();
95 std::vector
<std::string
> ContextClick();
102 void SetPageZoomFactor(double zoom_factor
);
104 void SetPageScaleFactor(float scale_factor
, int x
, int y
);
106 void ClearTouchPoints();
107 void ReleaseTouchPoint(unsigned index
);
108 void UpdateTouchPoint(unsigned index
, int x
, int y
);
109 void CancelTouchPoint(unsigned index
);
110 void SetTouchModifier(const std::string
& key_name
, bool set_mask
);
111 void SetTouchCancelable(bool cancelable
);
112 void ThrowTouchPointError();
114 void DumpFilenameBeingDragged();
116 void GestureFlingCancel();
117 void GestureFlingStart(float x
, float y
, float velocity_x
, float velocity_y
);
118 void GestureScrollFirstPoint(int x
, int y
);
125 void LeapForward(int milliseconds
);
127 void BeginDragWithFiles(const std::vector
<std::string
>& files
);
129 void AddTouchPoint(gin::Arguments
* args
);
131 void MouseDragBegin();
133 void MouseMomentumBegin();
135 void GestureScrollBegin(gin::Arguments
* args
);
136 void GestureScrollEnd(gin::Arguments
* args
);
137 void GestureScrollUpdate(gin::Arguments
* args
);
138 void GestureScrollUpdateWithoutPropagation(gin::Arguments
* args
);
139 void GestureTap(gin::Arguments
* args
);
140 void GestureTapDown(gin::Arguments
* args
);
141 void GestureShowPress(gin::Arguments
* args
);
142 void GestureTapCancel(gin::Arguments
* args
);
143 void GestureLongPress(gin::Arguments
* args
);
144 void GestureLongTap(gin::Arguments
* args
);
145 void GestureTwoFingerTap(gin::Arguments
* args
);
147 void ContinuousMouseScrollBy(gin::Arguments
* args
);
148 void MouseMoveTo(gin::Arguments
* args
);
149 void MouseScrollBy(gin::Arguments
* args
);
150 void MouseMomentumScrollBy(gin::Arguments
* args
);
151 void MouseMomentumEnd();
152 void ScheduleAsynchronousClick(int button_number
, int modifiers
);
153 void ScheduleAsynchronousKeyDown(const std::string
& code_str
,
155 KeyLocationCode location
);
157 double GetCurrentEventTimeSec();
159 void DoLeapForward(int milliseconds
);
161 void SendCurrentTouchEvent(blink::WebInputEvent::Type
);
163 void GestureEvent(blink::WebInputEvent::Type
, gin::Arguments
*);
165 void UpdateClickCountForButton(blink::WebMouseEvent::Button
);
167 void InitMouseWheelEvent(gin::Arguments
* args
,
169 blink::WebMouseWheelEvent
* event
);
171 void FinishDragAndDrop(const blink::WebMouseEvent
&, blink::WebDragOperation
);
173 void DoMouseUp(const blink::WebMouseEvent
&);
174 void DoMouseMove(const blink::WebMouseEvent
&);
175 void ReplaySavedEvents();
177 bool force_layout_on_events() const { return force_layout_on_events_
; }
178 void set_force_layout_on_events(bool force
) {
179 force_layout_on_events_
= force
;
182 bool is_drag_mode() const { return is_drag_mode_
; }
183 void set_is_drag_mode(bool drag_mode
) { is_drag_mode_
= drag_mode
; }
186 int wm_key_down() const { return wm_key_down_
; }
187 void set_wm_key_down(int key_down
) { wm_key_down_
= key_down
; }
189 int wm_key_up() const { return wm_key_up_
; }
190 void set_wm_key_up(int key_up
) { wm_key_up_
= key_up
; }
192 int wm_char() const { return wm_char_
; }
193 void set_wm_char(int wm_char
) { wm_char_
= wm_char
; }
195 int wm_dead_char() const { return wm_dead_char_
; }
196 void set_wm_dead_char(int dead_char
) {
197 wm_dead_char_
= dead_char
;
200 int wm_sys_key_down() const { return wm_sys_key_down_
; }
201 void set_wm_sys_key_down(int key_down
) { wm_sys_key_down_
= key_down
; }
203 int wm_sys_key_up() const { return wm_sys_key_up_
; }
204 void set_wm_sys_key_up(int key_up
) { wm_sys_key_up_
= key_up
; }
206 int wm_sys_char() const { return wm_sys_char_
; }
207 void set_wm_sys_char(int sys_char
) { wm_sys_char_
= sys_char
; }
209 int wm_sys_dead_char() const { return wm_sys_dead_char_
; }
210 void set_wm_sys_dead_char(int sys_dead_char
) {
211 wm_sys_dead_char_
= sys_dead_char
;
218 int wm_sys_key_down_
;
221 int wm_sys_dead_char_
;
224 WebTestRunner::WebTaskList task_list_
;
226 WebTestRunner::TestInterfaces
* interfaces_
;
227 WebTestRunner::WebTestDelegate
* delegate_
;
228 blink::WebView
* view_
;
230 bool force_layout_on_events_
;
232 // When set to true (the default value), we batch mouse move and mouse up
233 // events so we can simulate drag & drop.
236 int touch_modifiers_
;
237 bool touch_cancelable_
;
238 std::vector
<blink::WebTouchPoint
> touch_points_
;
240 scoped_ptr
<blink::WebContextMenuData
> last_context_menu_data_
;
242 blink::WebDragData current_drag_data_
;
244 // Location of the touch point that initiated a gesture.
245 blink::WebPoint current_gesture_location_
;
247 // Currently pressed mouse button (Left/Right/Middle or None).
248 static blink::WebMouseEvent::Button pressed_button_
;
250 bool replaying_saved_events_
;
252 std::deque
<SavedEvent
> mouse_event_queue_
;
254 blink::WebDragOperationsMask current_drag_effects_allowed_
;
256 // Location of last mouseMoveTo event.
257 static blink::WebPoint last_mouse_pos_
;
259 // Time and place of the last mouse up event.
260 double last_click_time_sec_
;
261 blink::WebPoint last_click_pos_
;
263 // The last button number passed to mouseDown and mouseUp.
264 // Used to determine whether the click count continues to increment or not.
265 static blink::WebMouseEvent::Button last_button_type_
;
267 blink::WebDragOperation current_drag_effect_
;
269 uint32 time_offset_ms_
;
272 base::WeakPtrFactory
<EventSender
> weak_factory_
;
274 DISALLOW_COPY_AND_ASSIGN(EventSender
);
277 } // namespace content
279 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_EVENT_SENDER_H_