Bug 1255955 - Add shorthands for generating common DOM events; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 05 Aug 2016 18:07:12 +0100
changeset 400458 7abc9b79bc239a96f67434b32bbd2e6d75340870
parent 400457 bdf37d39bc80a88207df69ad27a1b601a6e8fca2
child 400459 ccb03a53177cc9dfc95ae2a18aafb35d5463610b
push id26147
push userbmo:ato@mozilla.com
push dateSat, 13 Aug 2016 19:00:38 +0000
reviewersautomatedtester
bugs1255955
milestone51.0a1
Bug 1255955 - Add shorthands for generating common DOM events; r?automatedtester MozReview-Commit-ID: K5p1SyYMofQ
testing/marionette/event.js
--- 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);
+};