| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_TEST_RUNNER_EVENT_SENDER_H_ | |
| 6 #define COMPONENTS_TEST_RUNNER_EVENT_SENDER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <queue> | |
| 12 #include <string> | |
| 13 #include <unordered_map> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "base/macros.h" | |
| 17 #include "base/memory/weak_ptr.h" | |
| 18 #include "build/build_config.h" | |
| 19 #include "third_party/WebKit/public/platform/WebDragData.h" | |
| 20 #include "third_party/WebKit/public/platform/WebDragOperation.h" | |
| 21 #include "third_party/WebKit/public/platform/WebInputEvent.h" | |
| 22 #include "third_party/WebKit/public/platform/WebInputEventResult.h" | |
| 23 #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" | |
| 24 #include "third_party/WebKit/public/platform/WebPoint.h" | |
| 25 #include "third_party/WebKit/public/platform/WebTouchPoint.h" | |
| 26 | |
| 27 namespace blink { | |
| 28 class WebFrameWidget; | |
| 29 class WebLocalFrame; | |
| 30 class WebView; | |
| 31 class WebWidget; | |
| 32 struct WebContextMenuData; | |
| 33 } | |
| 34 | |
| 35 namespace gin { | |
| 36 class Arguments; | |
| 37 } | |
| 38 | |
| 39 namespace test_runner { | |
| 40 | |
| 41 class TestInterfaces; | |
| 42 class WebWidgetTestProxyBase; | |
| 43 class WebTestDelegate; | |
| 44 | |
| 45 // Key event location code introduced in DOM Level 3. | |
| 46 // See also: http://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents | |
| 47 enum KeyLocationCode { | |
| 48 DOMKeyLocationStandard = 0x00, | |
| 49 DOMKeyLocationLeft = 0x01, | |
| 50 DOMKeyLocationRight = 0x02, | |
| 51 DOMKeyLocationNumpad = 0x03 | |
| 52 }; | |
| 53 | |
| 54 class EventSender { | |
| 55 public: | |
| 56 explicit EventSender(WebWidgetTestProxyBase*); | |
| 57 virtual ~EventSender(); | |
| 58 | |
| 59 void Reset(); | |
| 60 void Install(blink::WebLocalFrame*); | |
| 61 | |
| 62 void SetContextMenuData(const blink::WebContextMenuData&); | |
| 63 | |
| 64 void DoDragDrop(const blink::WebDragData&, blink::WebDragOperationsMask); | |
| 65 | |
| 66 private: | |
| 67 friend class EventSenderBindings; | |
| 68 | |
| 69 void MouseDown(int button_number, int modifiers); | |
| 70 void MouseUp(int button_number, int modifiers); | |
| 71 void PointerDown(int button_number, | |
| 72 int modifiers, | |
| 73 blink::WebPointerProperties::PointerType, | |
| 74 int pointerId, | |
| 75 float pressure, | |
| 76 int tiltX, | |
| 77 int tiltY); | |
| 78 void PointerUp(int button_number, | |
| 79 int modifiers, | |
| 80 blink::WebPointerProperties::PointerType, | |
| 81 int pointerId, | |
| 82 float pressure, | |
| 83 int tiltX, | |
| 84 int tiltY); | |
| 85 void SetMouseButtonState(int button_number, int modifiers); | |
| 86 | |
| 87 void KeyDown(const std::string& code_str, | |
| 88 int modifiers, | |
| 89 KeyLocationCode location); | |
| 90 | |
| 91 struct SavedEvent { | |
| 92 enum SavedEventType { | |
| 93 TYPE_UNSPECIFIED, | |
| 94 TYPE_MOUSE_UP, | |
| 95 TYPE_MOUSE_MOVE, | |
| 96 TYPE_LEAP_FORWARD | |
| 97 }; | |
| 98 | |
| 99 SavedEvent(); | |
| 100 | |
| 101 SavedEventType type; | |
| 102 blink::WebMouseEvent::Button button_type; // For MouseUp. | |
| 103 blink::WebPoint pos; // For MouseMove. | |
| 104 int milliseconds; // For LeapForward. | |
| 105 int modifiers; | |
| 106 }; | |
| 107 | |
| 108 enum class MouseScrollType { PIXEL, TICK }; | |
| 109 | |
| 110 void EnableDOMUIEventLogging(); | |
| 111 void FireKeyboardEventsToElement(); | |
| 112 void ClearKillRing(); | |
| 113 | |
| 114 std::vector<std::string> ContextClick(); | |
| 115 | |
| 116 void TextZoomIn(); | |
| 117 void TextZoomOut(); | |
| 118 | |
| 119 void ZoomPageIn(); | |
| 120 void ZoomPageOut(); | |
| 121 void SetPageZoomFactor(double zoom_factor); | |
| 122 | |
| 123 void ClearTouchPoints(); | |
| 124 void ReleaseTouchPoint(unsigned index); | |
| 125 void UpdateTouchPoint(unsigned index, float x, float y, gin::Arguments* args); | |
| 126 void CancelTouchPoint(unsigned index); | |
| 127 void SetTouchModifier(const std::string& key_name, bool set_mask); | |
| 128 void SetTouchCancelable(bool cancelable); | |
| 129 void ThrowTouchPointError(); | |
| 130 | |
| 131 void DumpFilenameBeingDragged(); | |
| 132 | |
| 133 void GestureFlingCancel(); | |
| 134 void GestureFlingStart(float x, | |
| 135 float y, | |
| 136 float velocity_x, | |
| 137 float velocity_y, | |
| 138 gin::Arguments* args); | |
| 139 bool IsFlinging() const; | |
| 140 void GestureScrollFirstPoint(int x, int y); | |
| 141 | |
| 142 void TouchStart(gin::Arguments* args); | |
| 143 void TouchMove(gin::Arguments* args); | |
| 144 void TouchCancel(gin::Arguments* args); | |
| 145 void TouchEnd(gin::Arguments* args); | |
| 146 void NotifyStartOfTouchScroll(); | |
| 147 | |
| 148 void LeapForward(int milliseconds); | |
| 149 | |
| 150 void BeginDragWithFiles(const std::vector<std::string>& files); | |
| 151 | |
| 152 void AddTouchPoint(float x, float y, gin::Arguments* args); | |
| 153 | |
| 154 void GestureScrollBegin(gin::Arguments* args); | |
| 155 void GestureScrollEnd(gin::Arguments* args); | |
| 156 void GestureScrollUpdate(gin::Arguments* args); | |
| 157 void GesturePinchBegin(gin::Arguments* args); | |
| 158 void GesturePinchEnd(gin::Arguments* args); | |
| 159 void GesturePinchUpdate(gin::Arguments* args); | |
| 160 void GestureTap(gin::Arguments* args); | |
| 161 void GestureTapDown(gin::Arguments* args); | |
| 162 void GestureShowPress(gin::Arguments* args); | |
| 163 void GestureTapCancel(gin::Arguments* args); | |
| 164 void GestureLongPress(gin::Arguments* args); | |
| 165 void GestureLongTap(gin::Arguments* args); | |
| 166 void GestureTwoFingerTap(gin::Arguments* args); | |
| 167 | |
| 168 void MouseScrollBy(gin::Arguments* args, MouseScrollType scroll_type); | |
| 169 void MouseMoveTo(gin::Arguments* args); | |
| 170 void MouseLeave(); | |
| 171 void ScheduleAsynchronousClick(int button_number, int modifiers); | |
| 172 void ScheduleAsynchronousKeyDown(const std::string& code_str, | |
| 173 int modifiers, | |
| 174 KeyLocationCode location); | |
| 175 | |
| 176 double GetCurrentEventTimeSec(); | |
| 177 | |
| 178 void DoLeapForward(int milliseconds); | |
| 179 | |
| 180 uint32_t GetUniqueTouchEventId(gin::Arguments* args); | |
| 181 void SendCurrentTouchEvent(blink::WebInputEvent::Type, gin::Arguments* args); | |
| 182 | |
| 183 void GestureEvent(blink::WebInputEvent::Type, | |
| 184 gin::Arguments*); | |
| 185 | |
| 186 void UpdateClickCountForButton(blink::WebMouseEvent::Button); | |
| 187 | |
| 188 blink::WebMouseWheelEvent GetMouseWheelEvent(gin::Arguments* args, | |
| 189 MouseScrollType scroll_type, | |
| 190 bool* send_gestures); | |
| 191 void InitPointerProperties(gin::Arguments* args, | |
| 192 blink::WebPointerProperties* e, | |
| 193 float* radius_x, | |
| 194 float* radius_y); | |
| 195 | |
| 196 void FinishDragAndDrop(const blink::WebMouseEvent&, blink::WebDragOperation); | |
| 197 | |
| 198 int ModifiersForPointer(int pointer_id); | |
| 199 void DoDragAfterMouseUp(const blink::WebMouseEvent&); | |
| 200 void DoDragAfterMouseMove(const blink::WebMouseEvent&); | |
| 201 void ReplaySavedEvents(); | |
| 202 blink::WebInputEventResult HandleInputEventOnViewOrPopup( | |
| 203 const blink::WebInputEvent& event); | |
| 204 | |
| 205 void SendGesturesForMouseWheelEvent( | |
| 206 const blink::WebMouseWheelEvent wheel_event); | |
| 207 | |
| 208 std::unique_ptr<blink::WebInputEvent> TransformScreenToWidgetCoordinates( | |
| 209 const blink::WebInputEvent& event); | |
| 210 | |
| 211 double last_event_timestamp() { return last_event_timestamp_; } | |
| 212 | |
| 213 bool force_layout_on_events() const { return force_layout_on_events_; } | |
| 214 void set_force_layout_on_events(bool force) { | |
| 215 force_layout_on_events_ = force; | |
| 216 } | |
| 217 void DoLayoutIfForceLayoutOnEventsRequested(); | |
| 218 | |
| 219 bool is_drag_mode() const { return is_drag_mode_; } | |
| 220 void set_is_drag_mode(bool drag_mode) { is_drag_mode_ = drag_mode; } | |
| 221 | |
| 222 #if defined(OS_WIN) | |
| 223 int wm_key_down() const { return wm_key_down_; } | |
| 224 void set_wm_key_down(int key_down) { wm_key_down_ = key_down; } | |
| 225 | |
| 226 int wm_key_up() const { return wm_key_up_; } | |
| 227 void set_wm_key_up(int key_up) { wm_key_up_ = key_up; } | |
| 228 | |
| 229 int wm_char() const { return wm_char_; } | |
| 230 void set_wm_char(int wm_char) { wm_char_ = wm_char; } | |
| 231 | |
| 232 int wm_dead_char() const { return wm_dead_char_; } | |
| 233 void set_wm_dead_char(int dead_char) { | |
| 234 wm_dead_char_ = dead_char; | |
| 235 } | |
| 236 | |
| 237 int wm_sys_key_down() const { return wm_sys_key_down_; } | |
| 238 void set_wm_sys_key_down(int key_down) { wm_sys_key_down_ = key_down; } | |
| 239 | |
| 240 int wm_sys_key_up() const { return wm_sys_key_up_; } | |
| 241 void set_wm_sys_key_up(int key_up) { wm_sys_key_up_ = key_up; } | |
| 242 | |
| 243 int wm_sys_char() const { return wm_sys_char_; } | |
| 244 void set_wm_sys_char(int sys_char) { wm_sys_char_ = sys_char; } | |
| 245 | |
| 246 int wm_sys_dead_char() const { return wm_sys_dead_char_; } | |
| 247 void set_wm_sys_dead_char(int sys_dead_char) { | |
| 248 wm_sys_dead_char_ = sys_dead_char; | |
| 249 } | |
| 250 | |
| 251 int wm_key_down_; | |
| 252 int wm_key_up_; | |
| 253 int wm_char_; | |
| 254 int wm_dead_char_; | |
| 255 int wm_sys_key_down_; | |
| 256 int wm_sys_key_up_; | |
| 257 int wm_sys_char_; | |
| 258 int wm_sys_dead_char_; | |
| 259 #endif | |
| 260 | |
| 261 WebWidgetTestProxyBase* web_widget_test_proxy_base_; | |
| 262 TestInterfaces* interfaces(); | |
| 263 WebTestDelegate* delegate(); | |
| 264 const blink::WebView* view() const; | |
| 265 blink::WebView* view(); | |
| 266 blink::WebWidget* widget(); | |
| 267 blink::WebFrameWidget* mainFrameWidget(); | |
| 268 | |
| 269 bool force_layout_on_events_; | |
| 270 | |
| 271 // When set to true (the default value), we batch mouse move and mouse up | |
| 272 // events so we can simulate drag & drop. | |
| 273 bool is_drag_mode_; | |
| 274 | |
| 275 int touch_modifiers_; | |
| 276 bool touch_cancelable_; | |
| 277 std::vector<blink::WebTouchPoint> touch_points_; | |
| 278 | |
| 279 std::unique_ptr<blink::WebContextMenuData> last_context_menu_data_; | |
| 280 | |
| 281 blink::WebDragData current_drag_data_; | |
| 282 | |
| 283 // Location of the touch point that initiated a gesture. | |
| 284 blink::WebPoint current_gesture_location_; | |
| 285 | |
| 286 // Mouse-like pointer properties. | |
| 287 struct PointerState { | |
| 288 // Last pressed button (Left/Right/Middle or None). | |
| 289 blink::WebMouseEvent::Button pressed_button_; | |
| 290 | |
| 291 // A bitwise OR of the WebMouseEvent::*ButtonDown values corresponding to | |
| 292 // currently pressed buttons of the pointer (e.g. pen or mouse). | |
| 293 int current_buttons_; | |
| 294 | |
| 295 // Location of last mouseMoveTo event of this pointer. | |
| 296 blink::WebPoint last_pos_; | |
| 297 | |
| 298 int modifiers_; | |
| 299 | |
| 300 PointerState() | |
| 301 : pressed_button_(blink::WebMouseEvent::Button::NoButton) | |
| 302 , current_buttons_(0) | |
| 303 , last_pos_(blink::WebPoint(0, 0)) | |
| 304 , modifiers_(0) { } | |
| 305 }; | |
| 306 typedef std::unordered_map<int, PointerState> PointerStateMap; | |
| 307 PointerStateMap current_pointer_state_; | |
| 308 | |
| 309 bool replaying_saved_events_; | |
| 310 | |
| 311 std::deque<SavedEvent> mouse_event_queue_; | |
| 312 | |
| 313 blink::WebDragOperationsMask current_drag_effects_allowed_; | |
| 314 | |
| 315 // Time and place of the last mouse up event. | |
| 316 double last_click_time_sec_; | |
| 317 blink::WebPoint last_click_pos_; | |
| 318 | |
| 319 // The last button number passed to mouseDown and mouseUp. | |
| 320 // Used to determine whether the click count continues to increment or not. | |
| 321 static blink::WebMouseEvent::Button last_button_type_; | |
| 322 | |
| 323 blink::WebDragOperation current_drag_effect_; | |
| 324 | |
| 325 uint32_t time_offset_ms_; | |
| 326 int click_count_; | |
| 327 // Timestamp (in seconds) of the last event that was dispatched | |
| 328 double last_event_timestamp_; | |
| 329 | |
| 330 base::WeakPtrFactory<EventSender> weak_factory_; | |
| 331 | |
| 332 DISALLOW_COPY_AND_ASSIGN(EventSender); | |
| 333 }; | |
| 334 | |
| 335 } // namespace test_runner | |
| 336 | |
| 337 #endif // COMPONENTS_TEST_RUNNER_EVENT_SENDER_H_ | |
| OLD | NEW |