Bug 1255955 - Fix event.sendMouseEvent to work in privileged space; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 05 Aug 2016 18:05:14 +0100
changeset 400455 e8294130ca59acb8fd173b9b9313b823e81ba360
parent 400454 7ff15853131bb796277e2843a4f56ad26973a615
child 400456 41156432832680f6edb37cb996d0b53530309d7f
push id26147
push userbmo:ato@mozilla.com
push dateSat, 13 Aug 2016 19:00:38 +0000
reviewersautomatedtester
bugs1255955
milestone51.0a1
Bug 1255955 - Fix event.sendMouseEvent to work in privileged space; r?automatedtester 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;