B2G/gecko/accessible/tests/mochitest/table.js
/**
 * Test table getters selection methods.
 *
 * @param  aIdentifier  [in] table accessible identifier
 * @param  aCellsArray  [in] two dimensional array (row X columns) of cells
 *                       states (either boolean (selected/unselected) if cell is
 *                       origin, otherwise kRowSpanned or kColSpanned constant).
 * @param  aMsg         [in] text appended before every message
 */
Test table getters selection methods.
@param  aIdentifier  [in] table accessible identifier
@param  aCellsArray  [in] two dimensional array (row X columns) of cells
states (either boolean (selected/unselected) if cell is
origin, otherwise kRowSpanned or kColSpanned constant).
@param  aMsg         [in] text appended before every message
Test table getters selection methods . @param aIdentifier [ in ] table accessible identifier @param aCellsArray [ in ] two dimensional array ( row X columns ) of cells states ( either boolean ( selected / unselected ) if cell is origin otherwise kRowSpanned or kColSpanned constant ) . @param aMsg [ in ] text appended before every message
function testTableSelection(aIdentifier, aCellsArray, aMsg)
{
  var msg = aMsg ? aMsg : "";
  var acc = getAccessible(aIdentifier, [nsIAccessibleTable]);
  if (!acc)
    return;
  var rowCount = aCellsArray.length;
  var colsCount = aCellsArray[0].length;
  var selCols = new Array();
  for (var colIdx = 0; colIdx < colsCount; colIdx++) {
    var isColSelected = true;
    for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
      if (aCellsArray[rowIdx][colIdx] == false) {
        isColSelected = false;
        break;
      }
    }
    is(acc.isColumnSelected(colIdx), isColSelected,
       msg + "Wrong selection state of " + colIdx + " column for " +
       prettyName(aIdentifier));
    if (isColSelected)
      selCols.push(colIdx);
  }
  is(acc.selectedColumnCount, selCols.length,
     msg + "Wrong count of selected columns for " + prettyName(aIdentifier));
  var actualSelColsCountObj = { value: null };
  var actualSelCols = acc.getSelectedColumnIndices(actualSelColsCountObj);
  var actualSelColsCount = actualSelColsCountObj.value;
  is (actualSelColsCount, selCols.length,
      msg + "Wrong count of selected columns for " + prettyName(aIdentifier) +
      "from getSelectedColumns.");
  for (var i = 0; i < actualSelColsCount; i++) {
    is (actualSelCols[i], selCols[i],
        msg + "Column at index " + selCols[i] + " should be selected.");
  }
  var selRows = new Array();
  var selrowCount = 0;
  for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
    var isRowSelected = true;
    for (var colIdx = 0; colIdx < colsCount; colIdx++) {
      if (aCellsArray[rowIdx][colIdx] == false) {
        isRowSelected = false;
        break;
      }
    }
    is(acc.isRowSelected(rowIdx), isRowSelected,
       msg + "Wrong selection state of " + rowIdx + " row for " +
       prettyName(aIdentifier));
    if (isRowSelected)
      selRows.push(rowIdx);
  }
  is(acc.selectedRowCount, selRows.length,
     msg + "Wrong count of selected rows for " + prettyName(aIdentifier));
  var actualSelrowCountObj = { value: null };
  var actualSelRows = acc.getSelectedRowIndices(actualSelrowCountObj);
  var actualSelrowCount = actualSelrowCountObj.value;
  is (actualSelrowCount, selRows.length,
      msg + "Wrong count of selected rows for " + prettyName(aIdentifier) +
      "from getSelectedRows.");
  for (var i = 0; i < actualSelrowCount; i++) {
    is (actualSelRows[i], selRows[i],
        msg + "Row at index " + selRows[i] + " should be selected.");
  }
  var selCells = new Array();
  for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
    for (var colIdx = 0; colIdx < colsCount; colIdx++) {
      if (aCellsArray[rowIdx][colIdx] & kSpanned)
        continue;
      is(acc.isCellSelected(rowIdx, colIdx), aCellsArray[rowIdx][colIdx],
         msg + "Wrong selection state of cell at " + rowIdx + " row and " +
         colIdx + " column for " + prettyName(aIdentifier));
      if (aCellsArray[rowIdx][colIdx])
        selCells.push(acc.getCellIndexAt(rowIdx, colIdx));
    }
  }
  is(acc.selectedCellCount, selCells.length,
     msg + "Wrong count of selected cells for " + prettyName(aIdentifier));
  var actualSelCellsCountObj = { value: null };
  var actualSelCells = acc.getSelectedCellIndices(actualSelCellsCountObj);
  var actualSelCellsCount = actualSelCellsCountObj.value;
  is(actualSelCellsCount, selCells.length,
     msg + "Wrong count of selected cells for " + prettyName(aIdentifier) +
     "from getSelectedCells.");
  for (var i = 0; i < actualSelCellsCount; i++) {
    is(actualSelCells[i], selCells[i],
       msg + "getSelectedCellIndices: Cell at index " + selCells[i] +
       " should be selected.");
  }
  var actualSelCellsArray = acc.selectedCells;
  for (var i = 0; i < actualSelCellsCount; i++) {
    var actualSelCellAccessible =
      actualSelCellsArray.queryElementAt(i, nsIAccessibleTableCell);
    var colIdx = acc.getColumnIndexAt(selCells[i]);
    var rowIdx = acc.getRowIndexAt(selCells[i]);
    var expectedSelCellAccessible = acc.getCellAt(rowIdx, colIdx);
    ok(actualSelCellAccessible, expectedSelCellAccessible,
       msg + "getSelectedCells: Cell at index " + selCells[i] +
       " should be selected.");
    ok(actualSelCellAccessible.isSelected(),
       "isSelected: Cell at index " + selCells[i] + " should be selected.");
  }
  for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
    for (var colIdx = 0; colIdx < colsCount; colIdx++) {
      if (aCellsArray[rowIdx][colIdx] & kSpanned)
        continue;
      var cell = acc.getCellAt(rowIdx, colIdx);
      var isSel = aCellsArray[rowIdx][colIdx];
      if (isSel)
        testStates(cell, STATE_SELECTED);
      else
        testStates(cell, STATE_SELECTABLE, 0, STATE_SELECTED);
    }
  }
}
function testTableSelection ( aIdentifier , aCellsArray , aMsg ) { var msg = aMsg ? aMsg : "" ; var acc = getAccessible ( aIdentifier , [ nsIAccessibleTable ] ) ; if ( ! acc ) return ; var rowCount = aCellsArray . length ; var colsCount = aCellsArray [ 0 ] . length ; var selCols = new Array ( ) ; for ( var colIdx = 0 ; colIdx < colsCount ; colIdx ++ ) { var isColSelected = true ; for ( var rowIdx = 0 ; rowIdx < rowCount ; rowIdx ++ ) { if ( aCellsArray [ rowIdx ] [ colIdx ] == false ) { isColSelected = false ; break ; } } is ( acc . isColumnSelected ( colIdx ) , isColSelected , msg + "Wrong selection state of " + colIdx + " column for " + prettyName ( aIdentifier ) ) ; if ( isColSelected ) selCols . push ( colIdx ) ; } is ( acc . selectedColumnCount , selCols . length , msg + "Wrong count of selected columns for " + prettyName ( aIdentifier ) ) ; var actualSelColsCountObj = { value : null } ; var actualSelCols = acc . getSelectedColumnIndices ( actualSelColsCountObj ) ; var actualSelColsCount = actualSelColsCountObj . value ; is ( actualSelColsCount , selCols . length , msg + "Wrong count of selected columns for " + prettyName ( aIdentifier ) + "from getSelectedColumns." ) ; for ( var i = 0 ; i < actualSelColsCount ; i ++ ) { is ( actualSelCols [ i ] , selCols [ i ] , msg + "Column at index " + selCols [ i ] + " should be selected." ) ; } var selRows = new Array ( ) ; var selrowCount = 0 ; for ( var rowIdx = 0 ; rowIdx < rowCount ; rowIdx ++ ) { var isRowSelected = true ; for ( var colIdx = 0 ; colIdx < colsCount ; colIdx ++ ) { if ( aCellsArray [ rowIdx ] [ colIdx ] == false ) { isRowSelected = false ; break ; } } is ( acc . isRowSelected ( rowIdx ) , isRowSelected , msg + "Wrong selection state of " + rowIdx + " row for " + prettyName ( aIdentifier ) ) ; if ( isRowSelected ) selRows . push ( rowIdx ) ; } is ( acc . selectedRowCount , selRows . length , msg + "Wrong count of selected rows for " + prettyName ( aIdentifier ) ) ; var actualSelrowCountObj = { value : null } ; var actualSelRows = acc . getSelectedRowIndices ( actualSelrowCountObj ) ; var actualSelrowCount = actualSelrowCountObj . value ; is ( actualSelrowCount , selRows . length , msg + "Wrong count of selected rows for " + prettyName ( aIdentifier ) + "from getSelectedRows." ) ; for ( var i = 0 ; i < actualSelrowCount ; i ++ ) { is ( actualSelRows [ i ] , selRows [ i ] , msg + "Row at index " + selRows [ i ] + " should be selected." ) ; } var selCells = new Array ( ) ; for ( var rowIdx = 0 ; rowIdx < rowCount ; rowIdx ++ ) { for ( var colIdx = 0 ; colIdx < colsCount ; colIdx ++ ) { if ( aCellsArray [ rowIdx ] [ colIdx ] & kSpanned ) continue ; is ( acc . isCellSelected ( rowIdx , colIdx ) , aCellsArray [ rowIdx ] [ colIdx ] , msg + "Wrong selection state of cell at " + rowIdx + " row and " + colIdx + " column for " + prettyName ( aIdentifier ) ) ; if ( aCellsArray [ rowIdx ] [ colIdx ] ) selCells . push ( acc . getCellIndexAt ( rowIdx , colIdx ) ) ; } } is ( acc . selectedCellCount , selCells . length , msg + "Wrong count of selected cells for " + prettyName ( aIdentifier ) ) ; var actualSelCellsCountObj = { value : null } ; var actualSelCells = acc . getSelectedCellIndices ( actualSelCellsCountObj ) ; var actualSelCellsCount = actualSelCellsCountObj . value ; is ( actualSelCellsCount , selCells . length , msg + "Wrong count of selected cells for " + prettyName ( aIdentifier ) + "from getSelectedCells." ) ; for ( var i = 0 ; i < actualSelCellsCount ; i ++ ) { is ( actualSelCells [ i ] , selCells [ i ] , msg + "getSelectedCellIndices: Cell at index " + selCells [ i ] + " should be selected." ) ; } var actualSelCellsArray = acc . selectedCells ; for ( var i = 0 ; i < actualSelCellsCount ; i ++ ) { var actualSelCellAccessible = actualSelCellsArray . queryElementAt ( i , nsIAccessibleTableCell ) ; var colIdx = acc . getColumnIndexAt ( selCells [ i ] ) ; var rowIdx = acc . getRowIndexAt ( selCells [ i ] ) ; var expectedSelCellAccessible = acc . getCellAt ( rowIdx , colIdx ) ; ok ( actualSelCellAccessible , expectedSelCellAccessible , msg + "getSelectedCells: Cell at index " + selCells [ i ] + " should be selected." ) ; ok ( actualSelCellAccessible . isSelected ( ) , "isSelected: Cell at index " + selCells [ i ] + " should be selected." ) ; } for ( var rowIdx = 0 ; rowIdx < rowCount ; rowIdx ++ ) { for ( var colIdx = 0 ; colIdx < colsCount ; colIdx ++ ) { if ( aCellsArray [ rowIdx ] [ colIdx ] & kSpanned ) continue ; var cell = acc . getCellAt ( rowIdx , colIdx ) ; var isSel = aCellsArray [ rowIdx ] [ colIdx ] ; if ( isSel ) testStates ( cell , STATE_SELECTED ) ; else testStates ( cell , STATE_SELECTABLE , 0 , STATE_SELECTED ) ; } } }
Test table getters selection methods.
Test table getters selection methods .
// Columns selection tests. // isColumnSelected test // selectedColsCount test // getSelectedColumns test // Rows selection tests. // isRowSelected test // selectedRowCount test // getSelectedRows test // Cells selection tests. // isCellSelected test // selectedCellCount tests // getSelectedCellIndices test // selectedCells and isSelected tests // selected states tests