Bug 720095. (Av1a-mochitest) Fix some strict warnings and nits. r=ted.mielczarek.
authorSerge Gautherie <sgautherie.bz@free.fr>
Tue, 24 Jan 2012 17:38:46 +0100
changeset 86409 ed9d9eb609ba4cc61af9f27853ae3ff88f6c1d15
parent 86408 1982c882af0ff513c528196d6e14365ff9829bcf
child 86419 c3643d492d6825c5858dd9b76877745d3413bbe6
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs720095
milestone12.0a1
Bug 720095. (Av1a-mochitest) Fix some strict warnings and nits. r=ted.mielczarek.
testing/mochitest/tests/SimpleTest/EventUtils.js
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -28,17 +28,17 @@ function getElement(id) {
   return ((typeof(id) == "string") ?
     document.getElementById(id) : id); 
 };   
 
 this.$ = this.getElement;
 
 function sendMouseEvent(aEvent, aTarget, aWindow) {
   if (['click', 'mousedown', 'mouseup', 'mouseover', 'mouseout'].indexOf(aEvent.type) == -1) {
-    throw new Error("sendMouseEvent doesn't know about event type '"+aEvent.type+"'");
+    throw new Error("sendMouseEvent doesn't know about event type '" + aEvent.type + "'");
   }
 
   if (!aWindow) {
     aWindow = window;
   }
 
   if (!(aTarget instanceof Element)) {
     aTarget = aWindow.document.getElementById(aTarget);
@@ -94,19 +94,20 @@ function sendChar(aChar, aWindow) {
  */
 function sendString(aStr, aWindow) {
   for (var i = 0; i < aStr.length; ++i) {
     sendChar(aStr.charAt(i), aWindow);
   }
 }
 
 /**
- * Send the non-character key aKey to the focused node.  The name of the key
- * should be a lowercase version of the part that comes after "DOM_VK_" in the
- * KeyEvent constant name for this key.  No modifiers are handled at this point.
+ * Send the non-character key aKey to the focused node.
+ * The name of the key should be the part that comes after "DOM_VK_" in the
+ *   KeyEvent constant name for this key.
+ * No modifiers are handled at this point.
  */
 function sendKey(aKey, aWindow) {
   var keyName = "VK_" + aKey.toUpperCase();
   synthesizeKey(keyName, { shiftKey: false }, aWindow);
 }
 
 /**
  * Parse the key modifier flags from aEvent. Used to share code between
@@ -166,17 +167,17 @@ function synthesizeMouseAtPoint(left, to
 {
   var utils = _getDOMWindowUtils(aWindow);
 
   if (utils) {
     var button = aEvent.button || 0;
     var clickCount = aEvent.clickCount || 1;
     var modifiers = _parseModifiers(aEvent);
 
-    if (aEvent.type) {
+    if (("type" in aEvent) && aEvent.type) {
       utils.sendMouseEvent(aEvent.type, left, top, button, clickCount, modifiers);
     }
     else {
       utils.sendMouseEvent("mousedown", left, top, button, clickCount, modifiers);
       utils.sendMouseEvent("mouseup", left, top, button, clickCount, modifiers);
     }
   }
 }
@@ -226,17 +227,17 @@ function synthesizeMouseScroll(aTarget, 
     var button = aEvent.button || 0;
     var modifiers = _parseModifiers(aEvent);
 
     var rect = aTarget.getBoundingClientRect();
 
     var left = rect.left;
     var top = rect.top;
 
-    var type = aEvent.type || "DOMMouseScroll";
+    var type = (("type" in aEvent) && aEvent.type) || "DOMMouseScroll";
     var axis = aEvent.axis || "vertical";
     var scrollFlags = (axis == "horizontal") ? kIsHorizontal : kIsVertical;
     if (aEvent.hasPixels) {
       scrollFlags |= kHasPixels;
     }
     if (aEvent.isMomentum) {
       scrollFlags |= kIsMomentum;
     }
@@ -381,29 +382,32 @@ function synthesizeKey(aKey, aEvent, aWi
       }
     } else {
       charCode = aKey.charCodeAt(0);
       keyCode = _computeKeyCodeFromChar(aKey.charAt(0));
     }
 
     var modifiers = _parseModifiers(aEvent);
 
-    if (aEvent.type == "keypress") {
-      utils.sendKeyEvent(aEvent.type, charCode ? 0 : keyCode,
-                         charCode, modifiers);
-    } else if (aEvent.type) {
-      utils.sendKeyEvent(aEvent.type, keyCode, 0, modifiers);
-    } else {
+    if (!("type" in aEvent) || !aEvent.type) {
+      // Send keydown + (optional) keypress + keyup events.
       var keyDownDefaultHappened =
           utils.sendKeyEvent("keydown", keyCode, 0, modifiers);
       if (isKeypressFiredKey(keyCode)) {
         utils.sendKeyEvent("keypress", charCode ? 0 : keyCode, charCode,
                            modifiers, !keyDownDefaultHappened);
       }
       utils.sendKeyEvent("keyup", keyCode, 0, modifiers);
+    } else if (aEvent.type == "keypress") {
+      // Send standalone keypress event.
+      utils.sendKeyEvent(aEvent.type, charCode ? 0 : keyCode,
+                         charCode, modifiers);
+    } else {
+      // Send other standalone event than keypress.
+      utils.sendKeyEvent(aEvent.type, keyCode, 0, modifiers);
     }
   }
 }
 
 var _gSeenEvent = false;
 
 /**
  * Indicate that an event with an original target of aExpectedTarget and
@@ -506,17 +510,18 @@ function _getDOMWindowUtils(aWindow)
   }
 
   // we need parent.SpecialPowers for:
   //  layout/base/tests/test_reftests_with_caret.html
   //  chrome: toolkit/content/tests/chrome/test_findbar.xul
   //  chrome: toolkit/content/tests/chrome/test_popup_anchor.xul
   if ("SpecialPowers" in window && window.SpecialPowers != undefined) {
     return SpecialPowers.getDOMWindowUtils(aWindow);
-  } else if ("SpecialPowers" in parent && parent.SpecialPowers != undefined) {
+  }
+  if ("SpecialPowers" in parent && parent.SpecialPowers != undefined) {
     return parent.SpecialPowers.getDOMWindowUtils(aWindow);
   }
 
   //TODO: this is assuming we are in chrome space
   return aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
                                getInterface(Components.interfaces.nsIDOMWindowUtils);
 }
 
@@ -637,14 +642,13 @@ function synthesizeText(aEvent, aWindow)
  * @param aWindow  Optional (If null, current |window| will be used)
  * @return         An nsIQueryContentEventResult object.  If this failed,
  *                 the result might be null.
  */
 function synthesizeQuerySelectedText(aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
-    return nsnull;
+    return null;
   }
+
   return utils.sendQueryContentEvent(utils.QUERY_SELECTED_TEXT, 0, 0, 0, 0);
 }
-
-