B2G/gecko/testing/peptest/peptest/extension/resource/mozmill/stdlib/EventUtils.js
/**
 * Emulate a drop by emulating a dragstart and firing events dragenter, dragover, and drop.
 *  srcElement - the element to use to start the drag, usually the same as destElement
 *               but if destElement isn't suitable to start a drag on pass a suitable
 *               element for srcElement
 *  destElement - the element to fire the dragover, dragleave and drop events
 *  dragData - the data to supply for the data transfer
 *                     This data is in the format:
 *                       [ [ {type: value, data: value}, ...], ... ]
 *  dropEffect - the drop effect to set during the dragstart event, or 'move' if null
 *  aWindow - optional; defaults to the current window object.
 *
 * Returns the drop effect that was desired.
 */
Emulate a drop by emulating a dragstart and firing events dragenter, dragover, and drop.
srcElement - the element to use to start the drag, usually the same as destElement
but if destElement isn't suitable to start a drag on pass a suitable
element for srcElement
destElement - the element to fire the dragover, dragleave and drop events
dragData - the data to supply for the data transfer
This data is in the format:
[ [ {type: value, data: value}, ...], ... ]
dropEffect - the drop effect to set during the dragstart event, or 'move' if null
aWindow - optional; defaults to the current window object.

Returns the drop effect that was desired.
Emulate a drop by emulating a dragstart and firing events dragenter dragover and drop . srcElement - the element to use to start the drag usually the same as destElement but if destElement isn ' t suitable to start a drag on pass a suitable element for srcElement destElement - the element to fire the dragover dragleave and drop events dragData - the data to supply for the data transfer This data is in the format : [ [ { type : value data : value } ... ] ... ] dropEffect - the drop effect to set during the dragstart event or ' move ' if null aWindow - optional ; defaults to the current window object . Returns the drop effect that was desired .
function synthesizeDrop(srcElement, destElement, dragData, dropEffect, aWindow)
{
  if (!aWindow)
    aWindow = window;
  var dataTransfer;
  var trapDrag = function(event) {
    dataTransfer = event.dataTransfer;
    for (var i = 0; i < dragData.length; i++) {
      var item = dragData[i];
      for (var j = 0; j < item.length; j++) {
        dataTransfer.mozSetDataAt(item[j].type, item[j].data, i);
      }
    }
    dataTransfer.dropEffect = dropEffect || "move";
    event.preventDefault();
    event.stopPropagation();
  }
  aWindow.addEventListener("dragstart", trapDrag, true);
  synthesizeMouse(srcElement, 2, 2, { type: "mousedown" }, aWindow);
  synthesizeMouse(srcElement, 11, 11, { type: "mousemove" }, aWindow);
  synthesizeMouse(srcElement, 20, 20, { type: "mousemove" }, aWindow);
  aWindow.removeEventListener("dragstart", trapDrag, true);
  event = aWindow.document.createEvent("DragEvents");
  event.initDragEvent("dragenter", true, true, aWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
  destElement.dispatchEvent(event);
  var event = aWindow.document.createEvent("DragEvents");
  event.initDragEvent("dragover", true, true, aWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
  if (destElement.dispatchEvent(event)) {
    synthesizeMouse(destElement, 20, 20, { type: "mouseup" }, aWindow);
    return "none";
  }
  if (dataTransfer.dropEffect != "none") {
    event = aWindow.document.createEvent("DragEvents");
    event.initDragEvent("drop", true, true, aWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
    destElement.dispatchEvent(event);
  }
  synthesizeMouse(destElement, 20, 20, { type: "mouseup" }, aWindow);
  return dataTransfer.dropEffect;
}
function synthesizeDrop ( srcElement , destElement , dragData , dropEffect , aWindow ) { if ( ! aWindow ) aWindow = window ; var dataTransfer ; var trapDrag = function ( event ) { dataTransfer = event . dataTransfer ; for ( var i = 0 ; i < dragData . length ; i ++ ) { var item = dragData [ i ] ; for ( var j = 0 ; j < item . length ; j ++ ) { dataTransfer . mozSetDataAt ( item [ j ] . type , item [ j ] . data , i ) ; } } dataTransfer . dropEffect = dropEffect || "move" ; event . preventDefault ( ) ; event . stopPropagation ( ) ; } aWindow . addEventListener ( "dragstart" , trapDrag , true ) ; synthesizeMouse ( srcElement , 2 , 2 , { type : "mousedown" } , aWindow ) ; synthesizeMouse ( srcElement , 11 , 11 , { type : "mousemove" } , aWindow ) ; synthesizeMouse ( srcElement , 20 , 20 , { type : "mousemove" } , aWindow ) ; aWindow . removeEventListener ( "dragstart" , trapDrag , true ) ; event = aWindow . document . createEvent ( "DragEvents" ) ; event . initDragEvent ( "dragenter" , true , true , aWindow , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null , dataTransfer ) ; destElement . dispatchEvent ( event ) ; var event = aWindow . document . createEvent ( "DragEvents" ) ; event . initDragEvent ( "dragover" , true , true , aWindow , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null , dataTransfer ) ; if ( destElement . dispatchEvent ( event ) ) { synthesizeMouse ( destElement , 20 , 20 , { type : "mouseup" } , aWindow ) ; return "none" ; } if ( dataTransfer . dropEffect != "none" ) { event = aWindow . document . createEvent ( "DragEvents" ) ; event . initDragEvent ( "drop" , true , true , aWindow , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null , dataTransfer ) ; destElement . dispatchEvent ( event ) ; } synthesizeMouse ( destElement , 20 , 20 , { type : "mouseup" } , aWindow ) ; return dataTransfer . dropEffect ; }
Emulate a drop by emulating a dragstart and firing events dragenter, dragover, and drop.
Emulate a drop by emulating a dragstart and firing events dragenter dragover and drop .
// need to use real mouse action