B2G/gecko/testing/peptest/peptest/extension/resource/mozmill/stdlib/EventUtils.js
/**
 * Send a mouse event to the node aTarget (aTarget can be an id, or an
 * actual node) . The "event" passed in to aEvent is just a JavaScript
 * object with the properties set that the real mouse event object should
 * have. This includes the type of the mouse event.
 * E.g. to send an click event to the node with id 'node' you might do this:
 *
 * sendMouseEvent({type:'click'}, 'node');
 */
Send a mouse event to the node aTarget (aTarget can be an id, or an
actual node) . The "event" passed in to aEvent is just a JavaScript
object with the properties set that the real mouse event object should
have. This includes the type of the mouse event.


Send a mouse event to the node aTarget ( aTarget can be an id or an actual node ) . The " event " passed in to aEvent is just a JavaScript object with the properties set that the real mouse event object should have . This includes the type of the mouse event .
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 + "'");
  }
  if (!aWindow) {
    aWindow = window;
  }
  if (!(aTarget instanceof Element)) {
    aTarget = aWindow.document.getElementById(aTarget);
  }
  var event = aWindow.document.createEvent('MouseEvent');
  var typeArg          = aEvent.type;
  var canBubbleArg     = true;
  var cancelableArg    = true;
  var viewArg          = aWindow;
  var detailArg        = aEvent.detail        || (aEvent.type == 'click'     ||
                                                  aEvent.type == 'mousedown' ||
                                                  aEvent.type == 'mouseup' ? 1 : 0);
  var screenXArg       = aEvent.screenX       || 0;
  var screenYArg       = aEvent.screenY       || 0;
  var clientXArg       = aEvent.clientX       || 0;
  var clientYArg       = aEvent.clientY       || 0;
  var ctrlKeyArg       = aEvent.ctrlKey       || false;
  var altKeyArg        = aEvent.altKey        || false;
  var shiftKeyArg      = aEvent.shiftKey      || false;
  var metaKeyArg       = aEvent.metaKey       || false;
  var buttonArg        = aEvent.button        || 0;
  var relatedTargetArg = aEvent.relatedTarget || null;
  event.initMouseEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg,
                       screenXArg, screenYArg, clientXArg, clientYArg,
                       ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
                       buttonArg, relatedTargetArg);
  aTarget.dispatchEvent(event);
}
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 + "'" ) ; } if ( ! aWindow ) { aWindow = window ; } if ( ! ( aTarget instanceof Element ) ) { aTarget = aWindow . document . getElementById ( aTarget ) ; } var event = aWindow . document . createEvent ( 'MouseEvent' ) ; var typeArg = aEvent . type ; var canBubbleArg = true ; var cancelableArg = true ; var viewArg = aWindow ; var detailArg = aEvent . detail || ( aEvent . type == 'click' || aEvent . type == 'mousedown' || aEvent . type == 'mouseup' ? 1 : 0 ) ; var screenXArg = aEvent . screenX || 0 ; var screenYArg = aEvent . screenY || 0 ; var clientXArg = aEvent . clientX || 0 ; var clientYArg = aEvent . clientY || 0 ; var ctrlKeyArg = aEvent . ctrlKey || false ; var altKeyArg = aEvent . altKey || false ; var shiftKeyArg = aEvent . shiftKey || false ; var metaKeyArg = aEvent . metaKey || false ; var buttonArg = aEvent . button || 0 ; var relatedTargetArg = aEvent . relatedTarget || null ; event . initMouseEvent ( typeArg , canBubbleArg , cancelableArg , viewArg , detailArg , screenXArg , screenYArg , clientXArg , clientYArg , ctrlKeyArg , altKeyArg , shiftKeyArg , metaKeyArg , buttonArg , relatedTargetArg ) ; aTarget . dispatchEvent ( event ) ; }
Send a mouse event to the node aTarget (aTarget can be an id, or an
 actual node) .
Send a mouse event to the node aTarget ( aTarget can be an id or an actual node ) .