B2G/gecko/accessible/tests/mochitest/table.js
/**
 * Test table structure and related methods.
 *
 * @param  aIdentifier     [in] table accessible identifier
 * @param  aCellsArray     [in] two dimensional array (row X columns) of
 *                          cell types (see constants defined above).
 * @param  aColHeaderType  [in] specifies wether column header cells are
 *                          arranged into the list.
 * @param  aCaption        [in] caption text if any
 * @param  aSummary        [in] summary text if any
 * @param  aIsTreeTable    [in] specifies whether given table is tree table
 */
Test table structure and related methods.
@param  aIdentifier     [in] table accessible identifier
@param  aCellsArray     [in] two dimensional array (row X columns) of
cell types .
@param  aColHeaderType  [in] specifies wether column header cells are
arranged into the list.
@param  aCaption        [in] caption text if any
@param  aSummary        [in] summary text if any
@param  aIsTreeTable    [in] specifies whether given table is tree table
Test table structure and related methods . @param aIdentifier [ in ] table accessible identifier @param aCellsArray [ in ] two dimensional array ( row X columns ) of cell types . @param aColHeaderType [ in ] specifies wether column header cells are arranged into the list . @param aCaption [ in ] caption text if any @param aSummary [ in ] summary text if any @param aIsTreeTable [ in ] specifies whether given table is tree table
function testTableStruct(aIdentifier, aCellsArray, aColHeaderType,
                         aCaption, aSummary, aIsTreeTable)
{
  var tableNode = getNode(aIdentifier);
  var isGrid = tableNode.getAttribute("role") == "grid" ||
    tableNode.getAttribute("role") == "treegrid" ||
    tableNode.localName == "tree";
  var rowCount = aCellsArray.length;
  var colsCount = aCellsArray[0] ? aCellsArray[0].length : 0;
  var tableObj = {
    role: aIsTreeTable ? ROLE_TREE_TABLE : ROLE_TABLE,
    children: []
  };
  if (aCaption) {
    var captionObj = {
      role: ROLE_CAPTION,
      children: [
        {
          role: ROLE_TEXT_LEAF,
          name: aCaption
        }
      ]
    };
    tableObj.children.push(captionObj);
  }
  if (aColHeaderType) {
    var headersObj = {
      role: ROLE_LIST,
      children: []
    };
    for (var idx = 0; idx < colsCount; idx++) {
      var headerCellObj = {
        role: ROLE_COLUMNHEADER
      };
      headersObj.children.push(headerCellObj);
    }
    if (aColHeaderType == kTreeColumnHeader) {
      var columnPickerObj = {
        role: ROLE_PUSHBUTTON
      };
      headersObj.children.push(columnPickerObj);
    }
    tableObj.children.push(headersObj);
  }
  for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
    var rowObj = {
      role: ROLE_ROW,
      children: []
    };
    for (var colIdx = 0; colIdx < colsCount; colIdx++) {
      var celltype = aCellsArray[rowIdx][colIdx];
      var role = ROLE_NOTHING;
      switch (celltype) {
        case kDataCell:
          role = (isGrid ? ROLE_GRID_CELL : ROLE_CELL);
          break;
        case kRowHeaderCell:
          role = ROLE_ROWHEADER;
          break;
        case kColHeaderCell:
          role = ROLE_COLUMNHEADER;
          break;
      }
      if (role != ROLE_NOTHING) {
        var cellObj = {
          role: role
        };
        rowObj.children.push(cellObj);
      }
    }
    tableObj.children.push(rowObj);
  }
  testAccessibleTree(aIdentifier, tableObj);
  var table = getAccessible(aIdentifier, [nsIAccessibleTable]);
  if (aSummary)
    is(table.summary, aSummary,
       "Wrong summary of the table " + prettyName(aIdentifier));
  is(table.rowCount, rowCount,
     "Wrong rows count of " + prettyName(aIdentifier));
  is(table.columnCount, colsCount,
     "Wrong columns count of " + prettyName(aIdentifier));
  for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
    for (var colIdx = 0; colIdx < colsCount; colIdx++) {
      var celltype = aCellsArray[rowIdx][colIdx];
      if (celltype & kOrigin) {
        var rowExtent = table.getRowExtentAt(rowIdx, colIdx);
        for (var idx = rowIdx + 1;
             idx < rowCount && (aCellsArray[idx][colIdx] & kRowSpanned);
             idx++);
        var expectedRowExtent = idx - rowIdx;
        is(rowExtent, expectedRowExtent,
           "getRowExtentAt: Wrong number of spanned rows at (" + rowIdx + ", " +
           colIdx + ") for " + prettyName(aIdentifier));
        var colExtent = table.getColumnExtentAt(rowIdx, colIdx);
        for (var idx = colIdx + 1;
             idx < colsCount && (aCellsArray[rowIdx][idx] & kColSpanned);
             idx++);
        var expectedColExtent = idx - colIdx;
        is(colExtent, expectedColExtent,
           "getColumnExtentAt: Wrong number of spanned columns at (" + rowIdx +
           ", " + colIdx + ") for " + prettyName(aIdentifier));
        var cell = getAccessible(table.getCellAt(rowIdx, colIdx),
                                 [nsIAccessibleTableCell]);
        is(cell.rowExtent, expectedRowExtent,
           "rowExtent: Wrong number of spanned rows at (" + rowIdx + ", " +
           colIdx + ") for " + prettyName(aIdentifier));
        is(cell.columnExtent, expectedColExtent,
           "columnExtent: Wrong number of spanned column at (" + rowIdx + ", " +
           colIdx + ") for " + prettyName(aIdentifier));
      }
    }
  }
}
function testTableStruct ( aIdentifier , aCellsArray , aColHeaderType , aCaption , aSummary , aIsTreeTable ) { var tableNode = getNode ( aIdentifier ) ; var isGrid = tableNode . getAttribute ( "role" ) == "grid" || tableNode . getAttribute ( "role" ) == "treegrid" || tableNode . localName == "tree" ; var rowCount = aCellsArray . length ; var colsCount = aCellsArray [ 0 ] ? aCellsArray [ 0 ] . length : 0 ; var tableObj = { role : aIsTreeTable ? ROLE_TREE_TABLE : ROLE_TABLE , children : [ ] } ; if ( aCaption ) { var captionObj = { role : ROLE_CAPTION , children : [ { role : ROLE_TEXT_LEAF , name : aCaption } ] } ; tableObj . children . push ( captionObj ) ; } if ( aColHeaderType ) { var headersObj = { role : ROLE_LIST , children : [ ] } ; for ( var idx = 0 ; idx < colsCount ; idx ++ ) { var headerCellObj = { role : ROLE_COLUMNHEADER } ; headersObj . children . push ( headerCellObj ) ; } if ( aColHeaderType == kTreeColumnHeader ) { var columnPickerObj = { role : ROLE_PUSHBUTTON } ; headersObj . children . push ( columnPickerObj ) ; } tableObj . children . push ( headersObj ) ; } for ( var rowIdx = 0 ; rowIdx < rowCount ; rowIdx ++ ) { var rowObj = { role : ROLE_ROW , children : [ ] } ; for ( var colIdx = 0 ; colIdx < colsCount ; colIdx ++ ) { var celltype = aCellsArray [ rowIdx ] [ colIdx ] ; var role = ROLE_NOTHING ; switch ( celltype ) { case kDataCell : role = ( isGrid ? ROLE_GRID_CELL : ROLE_CELL ) ; break ; case kRowHeaderCell : role = ROLE_ROWHEADER ; break ; case kColHeaderCell : role = ROLE_COLUMNHEADER ; break ; } if ( role != ROLE_NOTHING ) { var cellObj = { role : role } ; rowObj . children . push ( cellObj ) ; } } tableObj . children . push ( rowObj ) ; } testAccessibleTree ( aIdentifier , tableObj ) ; var table = getAccessible ( aIdentifier , [ nsIAccessibleTable ] ) ; if ( aSummary ) is ( table . summary , aSummary , "Wrong summary of the table " + prettyName ( aIdentifier ) ) ; is ( table . rowCount , rowCount , "Wrong rows count of " + prettyName ( aIdentifier ) ) ; is ( table . columnCount , colsCount , "Wrong columns count of " + prettyName ( aIdentifier ) ) ; for ( var rowIdx = 0 ; rowIdx < rowCount ; rowIdx ++ ) { for ( var colIdx = 0 ; colIdx < colsCount ; colIdx ++ ) { var celltype = aCellsArray [ rowIdx ] [ colIdx ] ; if ( celltype & kOrigin ) { var rowExtent = table . getRowExtentAt ( rowIdx , colIdx ) ; for ( var idx = rowIdx + 1 ; idx < rowCount && ( aCellsArray [ idx ] [ colIdx ] & kRowSpanned ) ; idx ++ ) ; var expectedRowExtent = idx - rowIdx ; is ( rowExtent , expectedRowExtent , "getRowExtentAt: Wrong number of spanned rows at (" + rowIdx + ", " + colIdx + ") for " + prettyName ( aIdentifier ) ) ; var colExtent = table . getColumnExtentAt ( rowIdx , colIdx ) ; for ( var idx = colIdx + 1 ; idx < colsCount && ( aCellsArray [ rowIdx ] [ idx ] & kColSpanned ) ; idx ++ ) ; var expectedColExtent = idx - colIdx ; is ( colExtent , expectedColExtent , "getColumnExtentAt: Wrong number of spanned columns at (" + rowIdx + ", " + colIdx + ") for " + prettyName ( aIdentifier ) ) ; var cell = getAccessible ( table . getCellAt ( rowIdx , colIdx ) , [ nsIAccessibleTableCell ] ) ; is ( cell . rowExtent , expectedRowExtent , "rowExtent: Wrong number of spanned rows at (" + rowIdx + ", " + colIdx + ") for " + prettyName ( aIdentifier ) ) ; is ( cell . columnExtent , expectedColExtent , "columnExtent: Wrong number of spanned column at (" + rowIdx + ", " + colIdx + ") for " + prettyName ( aIdentifier ) ) ; } } } }
Test table structure and related methods.
Test table structure and related methods .
// Test table accessible tree. // caption accessible handling // special types of column headers handling // rows and cells accessibles // Test table table interface. // summary // rowCount and columnCount // rows and columns extents // table getRowExtentAt // table getColumnExtentAt // cell rowExtent and columnExtent