Bug 1255955 - Add function to dispatch events to event library; r=automatedtester, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 05 Aug 2016 18:06:38 +0100
changeset 347772 0e8d2fe2a20582d6dec7980b3937cb6941753802
parent 347771 5a591a1a98cd19e8e92c86676d65b85828a9338e
child 347773 c06be43a960f65d518b5f26cab3275c52f4fe23b
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1255955
milestone50.0a2
Bug 1255955 - Add function to dispatch events to event library; r=automatedtester, a=test-only MozReview-Commit-ID: GBvXy8svoY2
testing/marionette/event.js
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -1274,8 +1274,23 @@ event.sendKeysToElement = function(
       let c = value.charAt(i);
       event.sendSingleKey(c, modifiers, window);
     }
 
   } else {
     throw new ElementNotVisibleError("Element is not visible");
   }
 };
+
+event.sendEvent = function(eventType, el, modifiers = {}, opts = {}) {
+  opts.canBubble = opts.canBubble || true;
+
+  let doc = el.ownerDocument || el.document;
+  let ev = doc.createEvent("Event");
+
+  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);
+};