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 342389 9180c0406c2c1ee51f8fe48b9c09fb1cfe6f4403
parent 342388 004286546df533a571a4d3e474f61b7eff5b617d
child 342390 019699b3498f7b8564f6d72a2bdc80730ffe1747
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1255955
milestone49.0
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;