Bug 1255955 - Fix event.sendMouseEvent to work in privileged space; r=automatedtester, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 05 Aug 2016 18:05:14 +0100
changeset 349840 b8d43d25038b267df410a18a50987ee0bf7428af
parent 349839 4371df1f298aaf24ea09459e9df22bea04fdef91
child 349841 5a591a1a98cd19e8e92c86676d65b85828a9338e
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1255955
milestone50.0a2
Bug 1255955 - Fix event.sendMouseEvent to work in privileged space; r=automatedtester, a=test-only Also fixes assumptions about permitted mouse events. MozReview-Commit-ID: 33MKL60cKXi
testing/marionette/event.js
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -53,31 +53,37 @@ event.Modifiers = {
   metaKey: 3,
 };
 
 /**
  * Sends a mouse event to given target.
  *
  * @param {nsIDOMMouseEvent} mouseEvent
  *     Event to send.
- * @param {(Element|string)} target
- *     Target of event.  Can either be an Element or the ID of an element.
+ * @param {(DOMElement|string)} target
+ *     Target of event.  Can either be an element or the ID of an element.
  * @param {Window=} window
  *     Window object.  Defaults to the current window.
  *
  * @throws {TypeError}
  *     If the event is unsupported.
  */
 event.sendMouseEvent = function(mouseEvent, target, window = undefined) {
-  if (event.MouseEvents.hasOwnProperty(mouseEvent.type)) {
+  if (!event.MouseEvents.hasOwnProperty(mouseEvent.type)) {
     throw new TypeError("Unsupported event type: " + mouseEvent.type);
   }
 
-  if (!(target instanceof Element)) {
+  if (!target.nodeType && typeof target != "string") {
+    throw new TypeError("Target can only be a DOM element or a string: " + target);
+  }
+
+  if (!target.nodeType) {
     target = window.document.getElementById(target);
+  } else {
+    window = window || target.ownerDocument.defaultView;
   }
 
   let ev = window.document.createEvent("MouseEvent");
 
   let type = mouseEvent.type;
   let view = window;
 
   let detail = mouseEvent.detail;