From cf92f63f8529e5692c1bab91eb9069e2d135c6eb Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Fri, 5 Aug 2016 18:07:12 +0100 Subject: [PATCH] Bug 1255955 - Add shorthands for generating common DOM events; r=automatedtester MozReview-Commit-ID: K5p1SyYMofQ --HG-- extra : rebase_source : 687d4a15858a6934343c368a8de498afb6be98fc --- testing/marionette/event.js | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/testing/marionette/event.js b/testing/marionette/event.js index b2d676f04ae8..9b77d1ef7765 100644 --- a/testing/marionette/event.js +++ b/testing/marionette/event.js @@ -1294,3 +1294,41 @@ event.sendEvent = function(eventType, el, modifiers = {}, opts = {}) { ev.initEvent(eventType, opts.canBubble, true); el.dispatchEvent(ev); }; + +event.focus = function(el, opts = {}) { + opts.canBubble = opts.canBubble || true; + let doc = el.ownerDocument || el.document; + let win = doc.defaultView; + + let ev = new win.FocusEvent(el); + ev.initEvent("focus", opts.canBubble, true); + el.dispatchEvent(ev); +}; + +event.mouseover = function(el, modifiers = {}, opts = {}) { + return event.sendEvent({type: "mouseover"}, el, modifiers, opts); +}; + +event.mousemove = function(el, modifiers = {}, opts = {}) { + return event.sendEvent({type: "mousemove"}, el, modifiers, opts); +}; + +event.mousedown = function(el, modifiers = {}, opts = {}) { + return event.sendEvent({type: "mousedown"}, el, modifiers, opts); +}; + +event.mouseup = function(el, modifiers = {}, opts = {}) { + return event.sendEvent({type: "mouseup"}, el, modifiers, opts); +}; + +event.click = function(el, modifiers = {}, opts = {}) { + return event.sendEvent({type: "click"}, el, modifiers, opts); +}; + +event.change = function(el, modifiers = {}, opts = {}) { + return event.sendEvent({type: "change"}, el, modifiers, opts); +}; + +event.input = function(el, modifiers = {}, opts = {}) { + return event.sendEvent({type: "input"}, el, modifiers, opts); +};