2009-05-18 01:35:21 -07:00
|
|
|
/**
|
|
|
|
* Test table indexes.
|
|
|
|
*
|
|
|
|
* @param aIdentifier [in] table accessible identifier
|
2009-06-29 03:54:26 -07:00
|
|
|
* @param aIdxes [in] two dimensional array of cell indexes
|
2009-05-18 01:35:21 -07:00
|
|
|
*/
|
2009-06-29 03:54:26 -07:00
|
|
|
function testTableIndexes(aIdentifier, aIdxes)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
var tableAcc = getAccessible(aIdentifier, [nsIAccessibleTable]);
|
|
|
|
if (!tableAcc)
|
|
|
|
return;
|
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
var obtainedRowIdx, obtainedColIdx, obtainedIdx;
|
2009-05-18 01:35:21 -07:00
|
|
|
var cellAcc;
|
|
|
|
|
|
|
|
var id = prettyName(aIdentifier);
|
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
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];
|
|
|
|
if (idx != - 1) {
|
|
|
|
// getRowAtIndex
|
|
|
|
var origRowIdx = rowIdx;
|
|
|
|
while (origRowIdx > 0 &&
|
|
|
|
aIdxes[rowIdx][colIdx] == aIdxes[origRowIdx - 1][colIdx])
|
|
|
|
origRowIdx--;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
try {
|
|
|
|
obtainedRowIdx = tableAcc.getRowAtIndex(idx);
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, id + ": can't get row index for cell index " + idx + "," + e);
|
|
|
|
}
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
is(obtainedRowIdx, origRowIdx,
|
|
|
|
id + ": row for index " + idx +" is not correct");
|
|
|
|
|
|
|
|
// getColumnAtIndex
|
|
|
|
var origColIdx = colIdx;
|
|
|
|
while (origColIdx > 0 &&
|
|
|
|
aIdxes[rowIdx][colIdx] == aIdxes[rowIdx][origColIdx - 1])
|
|
|
|
origColIdx--;
|
|
|
|
|
|
|
|
try {
|
|
|
|
obtainedColIdx = tableAcc.getColumnAtIndex(idx);
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, id + ": can't get column index for cell index " + idx + "," + e);
|
|
|
|
}
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
is(obtainedColIdx, origColIdx,
|
|
|
|
id + ": column for index " + idx +" is not correct");
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
// cellRefAt
|
|
|
|
try {
|
|
|
|
cellAcc = null;
|
|
|
|
cellAcc = tableAcc.cellRefAt(rowIdx, colIdx);
|
|
|
|
} catch (e) { }
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
ok(cellAcc,
|
|
|
|
id + ": Can't get cell accessible at row = " + rowIdx + ", column = " + colIdx);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
// 'table-cell-index' attribute
|
|
|
|
if (cellAcc) {
|
|
|
|
var attrs = cellAcc.attributes;
|
|
|
|
var strIdx = "";
|
|
|
|
try {
|
|
|
|
strIdx = attrs.getStringProperty("table-cell-index");
|
|
|
|
} catch (e) {
|
|
|
|
ok(false,
|
|
|
|
id + ": no cell index from object attributes on the cell accessible at index " + idx + ".");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strIdx) {
|
|
|
|
is (parseInt(strIdx), idx,
|
|
|
|
id + ": cell index from object attributes of cell accessible isn't corrent.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getIndexAt
|
2009-05-18 01:35:21 -07:00
|
|
|
try {
|
2009-06-29 03:54:26 -07:00
|
|
|
obtainedIdx = tableAcc.getIndexAt(rowIdx, colIdx);
|
2009-05-18 01:35:21 -07:00
|
|
|
} catch (e) {
|
2009-06-29 03:54:26 -07:00
|
|
|
obtainedIdx = -1;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2009-06-29 03:54:26 -07:00
|
|
|
is(obtainedIdx, idx,
|
|
|
|
id + ": row " + rowIdx + " /column " + colIdx + " and index " + obtainedIdx + " aren't inconsistent.");
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test table getters selection methods.
|
|
|
|
*
|
|
|
|
* @param aIdentifier [in] table accessible identifier
|
|
|
|
* @param aCellsArray [in] two dimensional array (row X columns) of selected
|
|
|
|
* cells states.
|
|
|
|
* @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 rowsCount = aCellsArray.length;
|
|
|
|
var colsCount = aCellsArray[0].length;
|
|
|
|
|
|
|
|
// Columns selection tests.
|
|
|
|
var selCols = new Array();
|
|
|
|
|
|
|
|
// isColumnSelected test
|
|
|
|
for (var colIdx = 0; colIdx < colsCount; colIdx++) {
|
|
|
|
var isColSelected = true;
|
|
|
|
for (var rowIdx = 0; rowIdx < rowsCount; rowIdx++) {
|
|
|
|
if (!aCellsArray[rowIdx][colIdx]) {
|
|
|
|
isColSelected = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
is(acc.isColumnSelected(colIdx), isColSelected,
|
|
|
|
msg + "Wrong selection state of " + colIdx + " column for " +
|
|
|
|
prettyName(aIdentifier));
|
|
|
|
|
|
|
|
if (isColSelected)
|
|
|
|
selCols.push(colIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// selectedColsCount test
|
|
|
|
is(acc.selectedColumnsCount, selCols.length,
|
|
|
|
msg + "Wrong count of selected columns for " + prettyName(aIdentifier));
|
|
|
|
|
|
|
|
// getSelectedColumns test
|
|
|
|
var actualSelColsCountObj = { value: null };
|
|
|
|
var actualSelCols = acc.getSelectedColumns(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.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rows selection tests.
|
|
|
|
var selRows = new Array();
|
|
|
|
|
|
|
|
// isRowSelected test
|
|
|
|
var selRowsCount = 0;
|
|
|
|
for (var rowIdx = 0; rowIdx < rowsCount; rowIdx++) {
|
|
|
|
var isRowSelected = true;
|
|
|
|
for (var colIdx = 0; colIdx < colsCount; colIdx++) {
|
|
|
|
if (!aCellsArray[rowIdx][colIdx]) {
|
|
|
|
isRowSelected = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
is(acc.isRowSelected(rowIdx), isRowSelected,
|
|
|
|
msg + "Wrong selection state of " + rowIdx + " row for " +
|
|
|
|
prettyName(aIdentifier));
|
|
|
|
|
|
|
|
if (isRowSelected)
|
|
|
|
selRows.push(rowIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// selectedRowsCount test
|
|
|
|
is(acc.selectedRowsCount, selRows.length,
|
|
|
|
msg + "Wrong count of selected rows for " + prettyName(aIdentifier));
|
|
|
|
|
|
|
|
// getSelectedRows test
|
|
|
|
var actualSelRowsCountObj = { value: null };
|
|
|
|
var actualSelRows = acc.getSelectedRows(actualSelRowsCountObj);
|
|
|
|
|
|
|
|
var actualSelRowsCount = actualSelRowsCountObj.value;
|
|
|
|
is (actualSelRowsCount, selRows.length,
|
|
|
|
msg + "Wrong count of selected rows for " + prettyName(aIdentifier) +
|
|
|
|
"from getSelectedRows.");
|
|
|
|
|
|
|
|
for (var i = 0; i < actualSelRowsCount; i++) {
|
|
|
|
is (actualSelRows[i], selRows[i],
|
|
|
|
msg + "Row at index " + selRows[i] + " should be selected.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cells selection tests.
|
|
|
|
var selCells = new Array();
|
|
|
|
|
|
|
|
// isCellSelected test
|
|
|
|
for (var rowIdx = 0; rowIdx < rowsCount; rowIdx++) {
|
|
|
|
for (var colIdx = 0; colIdx < colsCount; colIdx++) {
|
|
|
|
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.getIndexAt(rowIdx, colIdx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// selectedCellsCount tests
|
|
|
|
is(acc.selectedCellsCount, selCells.length,
|
|
|
|
msg + "Wrong count of selected cells for " + prettyName(aIdentifier));
|
|
|
|
|
|
|
|
// getSelectedCells test
|
|
|
|
var actualSelCellsCountObj = { value: null };
|
|
|
|
var actualSelCells = acc.getSelectedCells(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 + "Cell at index " + selCells[i] + " should be selected.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test unselectColumn method of accessible table.
|
|
|
|
*/
|
|
|
|
function testUnselectTableColumn(aIdentifier, aColIdx, aCellsArray)
|
|
|
|
{
|
|
|
|
var acc = getAccessible(aIdentifier, [nsIAccessibleTable]);
|
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var rowsCount = aCellsArray.length;
|
|
|
|
for (var rowIdx = 0; rowIdx < rowsCount; rowIdx++)
|
|
|
|
aCellsArray[rowIdx][aColIdx] = false;
|
|
|
|
|
|
|
|
acc.unselectColumn(aColIdx);
|
|
|
|
testTableSelection(aIdentifier, aCellsArray,
|
|
|
|
"Unselect " + aColIdx + " column: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test selectColumn method of accessible table.
|
|
|
|
*/
|
|
|
|
function testSelectTableColumn(aIdentifier, aColIdx, aCellsArray)
|
|
|
|
{
|
|
|
|
var acc = getAccessible(aIdentifier, [nsIAccessibleTable]);
|
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var rowsCount = aCellsArray.length;
|
|
|
|
var colsCount = aCellsArray[0].length;
|
|
|
|
|
|
|
|
for (var rowIdx = 0; rowIdx < rowsCount; rowIdx++) {
|
|
|
|
for (var colIdx = 0; colIdx < colsCount; colIdx++)
|
|
|
|
aCellsArray[rowIdx][colIdx] = (colIdx == aColIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
acc.selectColumn(aColIdx);
|
|
|
|
testTableSelection(aIdentifier, aCellsArray,
|
|
|
|
"Select " + aColIdx + " column: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test unselectRow method of accessible table.
|
|
|
|
*/
|
|
|
|
function testUnselectTableRow(aIdentifier, aRowIdx, aCellsArray)
|
|
|
|
{
|
|
|
|
var acc = getAccessible(aIdentifier, [nsIAccessibleTable]);
|
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var colsCount = aCellsArray[0].length;
|
|
|
|
for (var colIdx = 0; colIdx < colsCount; colIdx++)
|
|
|
|
aCellsArray[aRowIdx][colIdx] = false;
|
|
|
|
|
|
|
|
acc.unselectRow(aRowIdx);
|
|
|
|
testTableSelection(aIdentifier, aCellsArray,
|
|
|
|
"Unselect " + aRowIdx + " row: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test selectRow method of accessible table.
|
|
|
|
*/
|
|
|
|
function testSelectTableRow(aIdentifier, aRowIdx, aCellsArray)
|
|
|
|
{
|
|
|
|
var acc = getAccessible(aIdentifier, [nsIAccessibleTable]);
|
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var rowsCount = aCellsArray.length;
|
|
|
|
var colsCount = aCellsArray[0].length;
|
|
|
|
|
|
|
|
for (var rowIdx = 0; rowIdx < rowsCount; rowIdx++) {
|
|
|
|
for (var colIdx = 0; colIdx < colsCount; colIdx++)
|
|
|
|
aCellsArray[rowIdx][colIdx] = (rowIdx == aRowIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
acc.selectRow(aRowIdx);
|
|
|
|
testTableSelection(aIdentifier, aCellsArray,
|
|
|
|
"Select " + aRowIdx + " row: ");
|
|
|
|
}
|