B2G/gecko/accessible/tests/mochitest/table.js
/**
 * Test table indexes.
 *
 * @param  aIdentifier  [in] table accessible identifier
 * @param  aIdxes       [in] two dimensional array of cell indexes
 */
Test table indexes.
@param  aIdentifier  [in] table accessible identifier
@param  aIdxes       [in] two dimensional array of cell indexes
Test table indexes . @param aIdentifier [ in ] table accessible identifier @param aIdxes [ in ] two dimensional array of cell indexes
function testTableIndexes(aIdentifier, aIdxes)
{
  var tableAcc = getAccessible(aIdentifier, [nsIAccessibleTable]);
  if (!tableAcc)
    return;
  var obtainedRowIdx, obtainedColIdx, obtainedIdx;
  var cellAcc;
  var id = prettyName(aIdentifier);
  var rowCount = aIdxes.length;
  for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
    var colCount = aIdxes[rowIdx].length;
    for (var colIdx = 0; colIdx < colCount; colIdx++) {
      var idx = aIdxes[rowIdx][colIdx];
      try {
        cellAcc = null;
        cellAcc = tableAcc.getCellAt(rowIdx, colIdx);
      } catch (e) { }
      ok(idx != -1 && cellAcc || idx == -1 && !cellAcc,
         id + ": Can't get cell accessible at row = " + rowIdx + ", column = " + colIdx);
      if (idx != - 1) {
        var origRowIdx = rowIdx;
        while (origRowIdx > 0 &&
               aIdxes[rowIdx][colIdx] == aIdxes[origRowIdx - 1][colIdx])
          origRowIdx--;
        try {
          obtainedRowIdx = tableAcc.getRowIndexAt(idx);
        } catch (e) {
          ok(false, id + ": can't get row index for cell index " + idx + "," + e);
        }
        is(obtainedRowIdx, origRowIdx,
           id + ": row for index " + idx + " is not correct (getRowIndexAt)");
        var origColIdx = colIdx;
        while (origColIdx > 0 &&
               aIdxes[rowIdx][colIdx] == aIdxes[rowIdx][origColIdx - 1])
          origColIdx--;
        try {
          obtainedColIdx = tableAcc.getColumnIndexAt(idx);
        } catch (e) {
          ok(false, id + ": can't get column index for cell index " + idx + "," + e);
        }
        is(obtainedColIdx, origColIdx,
           id + ": column  for index " + idx + " is not correct (getColumnIndexAt)");
        var obtainedRowIdxObj = { }, obtainedColIdxObj = { };
        try {
          tableAcc.getRowAndColumnIndicesAt(idx, obtainedRowIdxObj,
                                            obtainedColIdxObj);
        } catch (e) {
          ok(false, id + ": can't get row and column indices for cell index " + idx + "," + e);
        }
        is(obtainedRowIdxObj.value, origRowIdx,
           id + ": row for index " + idx + " is not correct (getRowAndColumnIndicesAt)");
        is(obtainedColIdxObj.value, origColIdx,
           id + ": column  for index " + idx + " is not correct (getRowAndColumnIndicesAt)");
        if (cellAcc) {
          var cellId = prettyName(cellAcc);
          cellAcc = getAccessible(cellAcc, [nsIAccessibleTableCell]);
          var attrs = cellAcc.attributes;
          var strIdx = "";
          try {
            strIdx = attrs.getStringProperty("table-cell-index");
          } catch (e) {
            ok(false,
               cellId + ": no cell index from object attributes on the cell accessible at index " + idx + ".");
          }
          if (strIdx) {
            is (parseInt(strIdx), idx,
                cellId + ": cell index from object attributes of cell accessible isn't corrent.");
          }
          try {
            is(cellAcc.table, tableAcc,
               cellId + ": wrong table accessible for the cell.");
          } catch (e) {
            ok(false,
               cellId + ": can't get table accessible from the cell.");
          }
          try {
            obtainedRowIdx = cellAcc.rowIndex;
          } catch (e) {
            ok(false,
               cellId + ": can't get row index of the cell at index " + idx + "," + e);
          }
          is(obtainedRowIdx, origRowIdx,
             cellId + ": row for the cell at index " + idx +" is not correct");
          try {
            obtainedColIdx = cellAcc.columnIndex;
          } catch (e) {
            ok(false,
               cellId + ": can't get column index of the cell at index " + idx + "," + e);
          }
          is(obtainedColIdx, origColIdx,
             id + ": column for the cell at index " + idx +" is not correct");
        }
      }
      try {
        obtainedIdx = tableAcc.getCellIndexAt(rowIdx, colIdx);
      } catch (e) {
        obtainedIdx = -1;
      }
      is(obtainedIdx, idx,
         id + ": row " + rowIdx + " /column " + colIdx + " and index " + obtainedIdx + " aren't inconsistent.");
    }
  }
}
function testTableIndexes ( aIdentifier , aIdxes ) { var tableAcc = getAccessible ( aIdentifier , [ nsIAccessibleTable ] ) ; if ( ! tableAcc ) return ; var obtainedRowIdx , obtainedColIdx , obtainedIdx ; var cellAcc ; var id = prettyName ( aIdentifier ) ; var rowCount = aIdxes . length ; for ( var rowIdx = 0 ; rowIdx < rowCount ; rowIdx ++ ) { var colCount = aIdxes [ rowIdx ] . length ; for ( var colIdx = 0 ; colIdx < colCount ; colIdx ++ ) { var idx = aIdxes [ rowIdx ] [ colIdx ] ; try { cellAcc = null ; cellAcc = tableAcc . getCellAt ( rowIdx , colIdx ) ; } catch ( e ) { } ok ( idx != - 1 && cellAcc || idx == - 1 && ! cellAcc , id + ": Can't get cell accessible at row = " + rowIdx + ", column = " + colIdx ) ; if ( idx != - 1 ) { var origRowIdx = rowIdx ; while ( origRowIdx > 0 && aIdxes [ rowIdx ] [ colIdx ] == aIdxes [ origRowIdx - 1 ] [ colIdx ] ) origRowIdx -- ; try { obtainedRowIdx = tableAcc . getRowIndexAt ( idx ) ; } catch ( e ) { ok ( false , id + ": can't get row index for cell index " + idx + "," + e ) ; } is ( obtainedRowIdx , origRowIdx , id + ": row for index " + idx + " is not correct (getRowIndexAt)" ) ; var origColIdx = colIdx ; while ( origColIdx > 0 && aIdxes [ rowIdx ] [ colIdx ] == aIdxes [ rowIdx ] [ origColIdx - 1 ] ) origColIdx -- ; try { obtainedColIdx = tableAcc . getColumnIndexAt ( idx ) ; } catch ( e ) { ok ( false , id + ": can't get column index for cell index " + idx + "," + e ) ; } is ( obtainedColIdx , origColIdx , id + ": column  for index " + idx + " is not correct (getColumnIndexAt)" ) ; var obtainedRowIdxObj = { } , obtainedColIdxObj = { } ; try { tableAcc . getRowAndColumnIndicesAt ( idx , obtainedRowIdxObj , obtainedColIdxObj ) ; } catch ( e ) { ok ( false , id + ": can't get row and column indices for cell index " + idx + "," + e ) ; } is ( obtainedRowIdxObj . value , origRowIdx , id + ": row for index " + idx + " is not correct (getRowAndColumnIndicesAt)" ) ; is ( obtainedColIdxObj . value , origColIdx , id + ": column  for index " + idx + " is not correct (getRowAndColumnIndicesAt)" ) ; if ( cellAcc ) { var cellId = prettyName ( cellAcc ) ; cellAcc = getAccessible ( cellAcc , [ nsIAccessibleTableCell ] ) ; var attrs = cellAcc . attributes ; var strIdx = "" ; try { strIdx = attrs . getStringProperty ( "table-cell-index" ) ; } catch ( e ) { ok ( false , cellId + ": no cell index from object attributes on the cell accessible at index " + idx + "." ) ; } if ( strIdx ) { is ( parseInt ( strIdx ) , idx , cellId + ": cell index from object attributes of cell accessible isn't corrent." ) ; } try { is ( cellAcc . table , tableAcc , cellId + ": wrong table accessible for the cell." ) ; } catch ( e ) { ok ( false , cellId + ": can't get table accessible from the cell." ) ; } try { obtainedRowIdx = cellAcc . rowIndex ; } catch ( e ) { ok ( false , cellId + ": can't get row index of the cell at index " + idx + "," + e ) ; } is ( obtainedRowIdx , origRowIdx , cellId + ": row for the cell at index " + idx + " is not correct" ) ; try { obtainedColIdx = cellAcc . columnIndex ; } catch ( e ) { ok ( false , cellId + ": can't get column index of the cell at index " + idx + "," + e ) ; } is ( obtainedColIdx , origColIdx , id + ": column for the cell at index " + idx + " is not correct" ) ; } } try { obtainedIdx = tableAcc . getCellIndexAt ( rowIdx , colIdx ) ; } catch ( e ) { obtainedIdx = - 1 ; } is ( obtainedIdx , idx , id + ": row " + rowIdx + " /column " + colIdx + " and index " + obtainedIdx + " aren't inconsistent." ) ; } } }
Test table indexes.
Test table indexes .
// getCellAt // getRowIndexAt // getColumnIndexAt // getRowAndColumnIndicesAt // cell: 'table-cell-index' attribute // cell: table // cell: getRowIndex // cell: getColumnIndex // getCellIndexAt