Bug 1255955 - Add shorthands for generating common DOM events; r?automatedtester
MozReview-Commit-ID: K5p1SyYMofQ
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -1289,8 +1289,46 @@ event.sendEvent = function(eventType, el
ev.shiftKey = modifiers["shift"];
ev.metaKey = modifiers["meta"];
ev.altKey = modifiers["alt"];
ev.ctrlKey = modifiers["ctrl"];
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);
+};