B2G/gecko/testing/peptest/peptest/extension/resource/mozmill/stdlib/EventUtils.js
/**
 * Emulate a dragstart event.
 *  element - element to fire the dragstart event on
 *  expectedDragData - the data you expect the data transfer to contain afterwards
 *                      This data is in the format:
 *                         [ [ {type: value, data: value, test: function}, ... ], ... ]
 *                     can be null
 *  aWindow - optional; defaults to the current window object.
 *  x - optional; initial x coordinate
 *  y - optional; initial y coordinate
 * Returns null if data matches.
 * Returns the event.dataTransfer if data does not match
 *
 * eqTest is an optional function if comparison can't be done with x == y;
 *   function (actualData, expectedData) {return boolean}
 *   @param actualData from dataTransfer
 *   @param expectedData from expectedDragData
 * see bug 462172 for example of use
 *
 */
Emulate a dragstart event.
element - element to fire the dragstart event on
expectedDragData - the data you expect the data transfer to contain afterwards
This data is in the format:
[ [ {type: value, data: value, test: function}, ...

eqTest is an optional function if comparison can't be done with x == y;
function (actualData, expectedData) {return boolean}
@param actualData from dataTransfer
@param expectedData from expectedDragData
see bug 462172 for example of use
Emulate a dragstart event . element - element to fire the dragstart event on expectedDragData - the data you expect the data transfer to contain afterwards This data is in the format : [ [ { type : value data : value test : function } ... eqTest is an optional function if comparison can ' t be done with x == y ; function ( actualData expectedData ) { return boolean } @param actualData from dataTransfer @param expectedData from expectedDragData see bug 462172 for example of use
function synthesizeDragStart(element, expectedDragData, aWindow, x, y)
{
  if (!aWindow)
    aWindow = window;
  x = x || 2;
  y = y || 2;
  const step = 9;
  var result = "trapDrag was not called";
  var trapDrag = function(event) {
    try {
      var dataTransfer = event.dataTransfer;
      result = null;
      if (!dataTransfer)
        throw "no dataTransfer";
      if (expectedDragData == null ||
          dataTransfer.mozItemCount != expectedDragData.length)
        throw dataTransfer;
      for (var i = 0; i < dataTransfer.mozItemCount; i++) {
        var dtTypes = dataTransfer.mozTypesAt(i);
        if (dtTypes.length != expectedDragData[i].length)
          throw dataTransfer;
        for (var j = 0; j < dtTypes.length; j++) {
          if (dtTypes[j] != expectedDragData[i][j].type)
            throw dataTransfer;
          var dtData = dataTransfer.mozGetDataAt(dtTypes[j],i);
          if (expectedDragData[i][j].eqTest) {
            if (!expectedDragData[i][j].eqTest(dtData, expectedDragData[i][j].data))
              throw dataTransfer;
          }
          else if (expectedDragData[i][j].data != dtData)
            throw dataTransfer;
        }
      }
    } catch(ex) {
      result = ex;
    }
    event.preventDefault();
    event.stopPropagation();
  }
  aWindow.addEventListener("dragstart", trapDrag, false);
  synthesizeMouse(element, x, y, { type: "mousedown" }, aWindow);
  x += step; y += step;
  synthesizeMouse(element, x, y, { type: "mousemove" }, aWindow);
  x += step; y += step;
  synthesizeMouse(element, x, y, { type: "mousemove" }, aWindow);
  aWindow.removeEventListener("dragstart", trapDrag, false);
  synthesizeMouse(element, x, y, { type: "mouseup" }, aWindow);
  return result;
}
function synthesizeDragStart ( element , expectedDragData , aWindow , x , y ) { if ( ! aWindow ) aWindow = window ; x = x || 2 ; y = y || 2 ; const step = 9 ; var result = "trapDrag was not called" ; var trapDrag = function ( event ) { try { var dataTransfer = event . dataTransfer ; result = null ; if ( ! dataTransfer ) throw "no dataTransfer" ; if ( expectedDragData == null || dataTransfer . mozItemCount != expectedDragData . length ) throw dataTransfer ; for ( var i = 0 ; i < dataTransfer . mozItemCount ; i ++ ) { var dtTypes = dataTransfer . mozTypesAt ( i ) ; if ( dtTypes . length != expectedDragData [ i ] . length ) throw dataTransfer ; for ( var j = 0 ; j < dtTypes . length ; j ++ ) { if ( dtTypes [ j ] != expectedDragData [ i ] [ j ] . type ) throw dataTransfer ; var dtData = dataTransfer . mozGetDataAt ( dtTypes [ j ] , i ) ; if ( expectedDragData [ i ] [ j ] . eqTest ) { if ( ! expectedDragData [ i ] [ j ] . eqTest ( dtData , expectedDragData [ i ] [ j ] . data ) ) throw dataTransfer ; } else if ( expectedDragData [ i ] [ j ] . data != dtData ) throw dataTransfer ; } } } catch ( ex ) { result = ex ; } event . preventDefault ( ) ; event . stopPropagation ( ) ; } aWindow . addEventListener ( "dragstart" , trapDrag , false ) ; synthesizeMouse ( element , x , y , { type : "mousedown" } , aWindow ) ; x += step ; y += step ; synthesizeMouse ( element , x , y , { type : "mousemove" } , aWindow ) ; x += step ; y += step ; synthesizeMouse ( element , x , y , { type : "mousemove" } , aWindow ) ; aWindow . removeEventListener ( "dragstart" , trapDrag , false ) ; synthesizeMouse ( element , x , y , { type : "mouseup" } , aWindow ) ; return result ; }
Emulate a dragstart event.
Emulate a dragstart event .