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 COMPONENTS_TEST_RUNNER_EVENT_SENDER_H_
6 #define COMPONENTS_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 "components/test_runner/web_task.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 test_runner
{
36 class WebTestDelegate
;
38 // Key event location code introduced in DOM Level 3.
39 // See also: http://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents
40 enum KeyLocationCode
{
41 DOMKeyLocationStandard
= 0x00,
42 DOMKeyLocationLeft
= 0x01,
43 DOMKeyLocationRight
= 0x02,
44 DOMKeyLocationNumpad
= 0x03
47 class EventSender
: public base::SupportsWeakPtr
<EventSender
> {
49 explicit EventSender(TestInterfaces
*);
50 virtual ~EventSender();
53 void Install(blink::WebFrame
*);
54 void SetDelegate(WebTestDelegate
*);
55 void SetWebView(blink::WebView
*);
57 void SetContextMenuData(const blink::WebContextMenuData
&);
59 void DoDragDrop(const blink::WebDragData
&, blink::WebDragOperationsMask
);
61 void MouseDown(int button_number
, int modifiers
);
62 void MouseUp(int button_number
, int modifiers
);
63 void KeyDown(const std::string
& code_str
,
65 KeyLocationCode location
);
67 WebTaskList
* mutable_task_list() { return &task_list_
; }
70 friend class EventSenderBindings
;
83 blink::WebMouseEvent::Button button_type
; // For MouseUp.
84 blink::WebPoint pos
; // For MouseMove.
85 int milliseconds
; // For LeapForward.
89 void EnableDOMUIEventLogging();
90 void FireKeyboardEventsToElement();
93 std::vector
<std::string
> ContextClick();
100 void SetPageZoomFactor(double zoom_factor
);
102 void ClearTouchPoints();
103 void ReleaseTouchPoint(unsigned index
);
104 void UpdateTouchPoint(unsigned index
, float x
, float y
);
105 void CancelTouchPoint(unsigned index
);
106 void SetTouchModifier(const std::string
& key_name
, bool set_mask
);
107 void SetTouchCancelable(bool cancelable
);
108 void ThrowTouchPointError();
110 void DumpFilenameBeingDragged();
112 void GestureFlingCancel();
113 void GestureFlingStart(float x
,
117 gin::Arguments
* args
);
118 void GestureScrollFirstPoint(int x
, int y
);
122 void TouchMoveCausingScrollIfUncanceled();
126 void LeapForward(int milliseconds
);
128 void BeginDragWithFiles(const std::vector
<std::string
>& files
);
130 void AddTouchPoint(gin::Arguments
* args
);
132 void MouseDragBegin();
135 void GestureScrollBegin(gin::Arguments
* args
);
136 void GestureScrollEnd(gin::Arguments
* args
);
137 void GestureScrollUpdate(gin::Arguments
* args
);
138 void GesturePinchBegin(gin::Arguments
* args
);
139 void GesturePinchEnd(gin::Arguments
* args
);
140 void GesturePinchUpdate(gin::Arguments
* args
);
141 void GestureTap(gin::Arguments
* args
);
142 void GestureTapDown(gin::Arguments
* args
);
143 void GestureShowPress(gin::Arguments
* args
);
144 void GestureTapCancel(gin::Arguments
* args
);
145 void GestureLongPress(gin::Arguments
* args
);
146 void GestureLongTap(gin::Arguments
* args
);
147 void GestureTwoFingerTap(gin::Arguments
* args
);
149 void ContinuousMouseScrollBy(gin::Arguments
* args
);
150 void MouseMoveTo(gin::Arguments
* args
);
152 void TrackpadScrollBegin();
153 void TrackpadScroll(gin::Arguments
* args
);
154 void TrackpadScrollEnd();
155 void MouseScrollBy(gin::Arguments
* args
);
156 void MouseMomentumBegin();
157 void MouseMomentumBegin2(gin::Arguments
* args
);
158 void MouseMomentumScrollBy(gin::Arguments
* args
);
159 void MouseMomentumEnd();
160 void ScheduleAsynchronousClick(int button_number
, int modifiers
);
161 void ScheduleAsynchronousKeyDown(const std::string
& code_str
,
163 KeyLocationCode location
);
165 double GetCurrentEventTimeSec();
167 void DoLeapForward(int milliseconds
);
169 void SendCurrentTouchEvent(blink::WebInputEvent::Type
, bool);
171 void GestureEvent(blink::WebInputEvent::Type
,
174 void UpdateClickCountForButton(blink::WebMouseEvent::Button
);
176 void InitMouseWheelEvent(gin::Arguments
* args
,
178 blink::WebMouseWheelEvent
* event
);
180 void FinishDragAndDrop(const blink::WebMouseEvent
&, blink::WebDragOperation
);
182 void DoMouseUp(const blink::WebMouseEvent
&);
183 void DoMouseMove(const blink::WebMouseEvent
&);
184 void ReplaySavedEvents();
185 bool HandleInputEventOnViewOrPopup(const blink::WebInputEvent
&);
187 bool force_layout_on_events() const { return force_layout_on_events_
; }
188 void set_force_layout_on_events(bool force
) {
189 force_layout_on_events_
= force
;
192 bool is_drag_mode() const { return is_drag_mode_
; }
193 void set_is_drag_mode(bool drag_mode
) { is_drag_mode_
= drag_mode
; }
196 int wm_key_down() const { return wm_key_down_
; }
197 void set_wm_key_down(int key_down
) { wm_key_down_
= key_down
; }
199 int wm_key_up() const { return wm_key_up_
; }
200 void set_wm_key_up(int key_up
) { wm_key_up_
= key_up
; }
202 int wm_char() const { return wm_char_
; }
203 void set_wm_char(int wm_char
) { wm_char_
= wm_char
; }
205 int wm_dead_char() const { return wm_dead_char_
; }
206 void set_wm_dead_char(int dead_char
) {
207 wm_dead_char_
= dead_char
;
210 int wm_sys_key_down() const { return wm_sys_key_down_
; }
211 void set_wm_sys_key_down(int key_down
) { wm_sys_key_down_
= key_down
; }
213 int wm_sys_key_up() const { return wm_sys_key_up_
; }
214 void set_wm_sys_key_up(int key_up
) { wm_sys_key_up_
= key_up
; }
216 int wm_sys_char() const { return wm_sys_char_
; }
217 void set_wm_sys_char(int sys_char
) { wm_sys_char_
= sys_char
; }
219 int wm_sys_dead_char() const { return wm_sys_dead_char_
; }
220 void set_wm_sys_dead_char(int sys_dead_char
) {
221 wm_sys_dead_char_
= sys_dead_char
;
228 int wm_sys_key_down_
;
231 int wm_sys_dead_char_
;
234 WebTaskList task_list_
;
236 TestInterfaces
* interfaces_
;
237 WebTestDelegate
* delegate_
;
238 blink::WebView
* view_
;
240 bool force_layout_on_events_
;
242 // When set to true (the default value), we batch mouse move and mouse up
243 // events so we can simulate drag & drop.
246 int touch_modifiers_
;
247 bool touch_cancelable_
;
248 std::vector
<blink::WebTouchPoint
> touch_points_
;
250 scoped_ptr
<blink::WebContextMenuData
> last_context_menu_data_
;
252 blink::WebDragData current_drag_data_
;
254 // Location of the touch point that initiated a gesture.
255 blink::WebPoint current_gesture_location_
;
257 // Currently pressed mouse button (Left/Right/Middle or None).
258 static blink::WebMouseEvent::Button pressed_button_
;
259 static int modifiers_
;
261 bool replaying_saved_events_
;
263 std::deque
<SavedEvent
> mouse_event_queue_
;
265 blink::WebDragOperationsMask current_drag_effects_allowed_
;
267 // Location of last mouseMoveTo event.
268 static blink::WebPoint last_mouse_pos_
;
270 // Time and place of the last mouse up event.
271 double last_click_time_sec_
;
272 blink::WebPoint last_click_pos_
;
274 // The last button number passed to mouseDown and mouseUp.
275 // Used to determine whether the click count continues to increment or not.
276 static blink::WebMouseEvent::Button last_button_type_
;
278 blink::WebDragOperation current_drag_effect_
;
280 uint32 time_offset_ms_
;
283 base::WeakPtrFactory
<EventSender
> weak_factory_
;
285 DISALLOW_COPY_AND_ASSIGN(EventSender
);
288 } // namespace test_runner
290 #endif // COMPONENTS_TEST_RUNNER_EVENT_SENDER_H_