Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /** |
michael@0 | 2 | * This file provides set of helper functions to test nsIAccessibleTable |
michael@0 | 3 | * interface. |
michael@0 | 4 | * |
michael@0 | 5 | * Required: |
michael@0 | 6 | * common.js |
michael@0 | 7 | * role.js |
michael@0 | 8 | * states.js |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * Constants used to describe cells array. |
michael@0 | 13 | */ |
michael@0 | 14 | const kDataCell = 1; // Indicates the cell is origin data cell |
michael@0 | 15 | const kRowHeaderCell = 2; // Indicates the cell is row header cell |
michael@0 | 16 | const kColHeaderCell = 4; // Indicated the cell is column header cell |
michael@0 | 17 | const kOrigin = kDataCell | kRowHeaderCell | kColHeaderCell; |
michael@0 | 18 | |
michael@0 | 19 | const kRowSpanned = 8; // Indicates the cell is not origin and row spanned |
michael@0 | 20 | const kColSpanned = 16; // Indicates the cell is not origin and column spanned |
michael@0 | 21 | const kSpanned = kRowSpanned | kColSpanned; |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Constants to define column header type. |
michael@0 | 25 | */ |
michael@0 | 26 | const kNoColumnHeader = 0; |
michael@0 | 27 | const kListboxColumnHeader = 1; |
michael@0 | 28 | const kTreeColumnHeader = 2; |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Test table structure and related methods. |
michael@0 | 32 | * |
michael@0 | 33 | * @param aIdentifier [in] table accessible identifier |
michael@0 | 34 | * @param aCellsArray [in] two dimensional array (row X columns) of |
michael@0 | 35 | * cell types (see constants defined above). |
michael@0 | 36 | * @param aColHeaderType [in] specifies wether column header cells are |
michael@0 | 37 | * arranged into the list. |
michael@0 | 38 | * @param aCaption [in] caption text if any |
michael@0 | 39 | * @param aSummary [in] summary text if any |
michael@0 | 40 | * @param aIsTreeTable [in] specifies whether given table is tree table |
michael@0 | 41 | */ |
michael@0 | 42 | function testTableStruct(aIdentifier, aCellsArray, aColHeaderType, |
michael@0 | 43 | aCaption, aSummary, aIsTreeTable) |
michael@0 | 44 | { |
michael@0 | 45 | var tableNode = getNode(aIdentifier); |
michael@0 | 46 | var isGrid = tableNode.getAttribute("role") == "grid" || |
michael@0 | 47 | tableNode.getAttribute("role") == "treegrid" || |
michael@0 | 48 | tableNode.localName == "tree"; |
michael@0 | 49 | |
michael@0 | 50 | var rowCount = aCellsArray.length; |
michael@0 | 51 | var colsCount = aCellsArray[0] ? aCellsArray[0].length : 0; |
michael@0 | 52 | |
michael@0 | 53 | // Test table accessible tree. |
michael@0 | 54 | var tableObj = { |
michael@0 | 55 | role: aIsTreeTable ? ROLE_TREE_TABLE : ROLE_TABLE, |
michael@0 | 56 | children: [] |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | // caption accessible handling |
michael@0 | 60 | if (aCaption) { |
michael@0 | 61 | var captionObj = { |
michael@0 | 62 | role: ROLE_CAPTION, |
michael@0 | 63 | children: [ |
michael@0 | 64 | { |
michael@0 | 65 | role: ROLE_TEXT_LEAF, |
michael@0 | 66 | name: aCaption |
michael@0 | 67 | } |
michael@0 | 68 | ] |
michael@0 | 69 | }; |
michael@0 | 70 | |
michael@0 | 71 | tableObj.children.push(captionObj); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | // special types of column headers handling |
michael@0 | 75 | if (aColHeaderType) { |
michael@0 | 76 | var headersObj = { |
michael@0 | 77 | role: ROLE_LIST, |
michael@0 | 78 | children: [] |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | for (var idx = 0; idx < colsCount; idx++) { |
michael@0 | 82 | var headerCellObj = { |
michael@0 | 83 | role: ROLE_COLUMNHEADER |
michael@0 | 84 | }; |
michael@0 | 85 | headersObj.children.push(headerCellObj); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | if (aColHeaderType == kTreeColumnHeader) { |
michael@0 | 89 | var columnPickerObj = { |
michael@0 | 90 | role: ROLE_PUSHBUTTON |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | headersObj.children.push(columnPickerObj); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | tableObj.children.push(headersObj); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | // rows and cells accessibles |
michael@0 | 100 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 101 | var rowObj = { |
michael@0 | 102 | role: ROLE_ROW, |
michael@0 | 103 | children: [] |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 107 | var celltype = aCellsArray[rowIdx][colIdx]; |
michael@0 | 108 | |
michael@0 | 109 | var role = ROLE_NOTHING; |
michael@0 | 110 | switch (celltype) { |
michael@0 | 111 | case kDataCell: |
michael@0 | 112 | role = (isGrid ? ROLE_GRID_CELL : ROLE_CELL); |
michael@0 | 113 | break; |
michael@0 | 114 | case kRowHeaderCell: |
michael@0 | 115 | role = ROLE_ROWHEADER; |
michael@0 | 116 | break; |
michael@0 | 117 | case kColHeaderCell: |
michael@0 | 118 | role = ROLE_COLUMNHEADER; |
michael@0 | 119 | break; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | if (role != ROLE_NOTHING) { |
michael@0 | 123 | var cellObj = { |
michael@0 | 124 | role: role |
michael@0 | 125 | }; |
michael@0 | 126 | rowObj.children.push(cellObj); |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | tableObj.children.push(rowObj); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | testAccessibleTree(aIdentifier, tableObj); |
michael@0 | 134 | |
michael@0 | 135 | // Test table table interface. |
michael@0 | 136 | var table = getAccessible(aIdentifier, [nsIAccessibleTable]); |
michael@0 | 137 | |
michael@0 | 138 | // summary |
michael@0 | 139 | if (aSummary) |
michael@0 | 140 | is(table.summary, aSummary, |
michael@0 | 141 | "Wrong summary of the table " + prettyName(aIdentifier)); |
michael@0 | 142 | |
michael@0 | 143 | // rowCount and columnCount |
michael@0 | 144 | is(table.rowCount, rowCount, |
michael@0 | 145 | "Wrong rows count of " + prettyName(aIdentifier)); |
michael@0 | 146 | is(table.columnCount, colsCount, |
michael@0 | 147 | "Wrong columns count of " + prettyName(aIdentifier)); |
michael@0 | 148 | |
michael@0 | 149 | // rows and columns extents |
michael@0 | 150 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 151 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 152 | var celltype = aCellsArray[rowIdx][colIdx]; |
michael@0 | 153 | if (celltype & kOrigin) { |
michael@0 | 154 | |
michael@0 | 155 | // table getRowExtentAt |
michael@0 | 156 | var rowExtent = table.getRowExtentAt(rowIdx, colIdx); |
michael@0 | 157 | for (var idx = rowIdx + 1; |
michael@0 | 158 | idx < rowCount && (aCellsArray[idx][colIdx] & kRowSpanned); |
michael@0 | 159 | idx++); |
michael@0 | 160 | |
michael@0 | 161 | var expectedRowExtent = idx - rowIdx; |
michael@0 | 162 | is(rowExtent, expectedRowExtent, |
michael@0 | 163 | "getRowExtentAt: Wrong number of spanned rows at (" + rowIdx + ", " + |
michael@0 | 164 | colIdx + ") for " + prettyName(aIdentifier)); |
michael@0 | 165 | |
michael@0 | 166 | // table getColumnExtentAt |
michael@0 | 167 | var colExtent = table.getColumnExtentAt(rowIdx, colIdx); |
michael@0 | 168 | for (var idx = colIdx + 1; |
michael@0 | 169 | idx < colsCount && (aCellsArray[rowIdx][idx] & kColSpanned); |
michael@0 | 170 | idx++); |
michael@0 | 171 | |
michael@0 | 172 | var expectedColExtent = idx - colIdx; |
michael@0 | 173 | is(colExtent, expectedColExtent, |
michael@0 | 174 | "getColumnExtentAt: Wrong number of spanned columns at (" + rowIdx + |
michael@0 | 175 | ", " + colIdx + ") for " + prettyName(aIdentifier)); |
michael@0 | 176 | |
michael@0 | 177 | // cell rowExtent and columnExtent |
michael@0 | 178 | var cell = getAccessible(table.getCellAt(rowIdx, colIdx), |
michael@0 | 179 | [nsIAccessibleTableCell]); |
michael@0 | 180 | |
michael@0 | 181 | is(cell.rowExtent, expectedRowExtent, |
michael@0 | 182 | "rowExtent: Wrong number of spanned rows at (" + rowIdx + ", " + |
michael@0 | 183 | colIdx + ") for " + prettyName(aIdentifier)); |
michael@0 | 184 | |
michael@0 | 185 | is(cell.columnExtent, expectedColExtent, |
michael@0 | 186 | "columnExtent: Wrong number of spanned column at (" + rowIdx + ", " + |
michael@0 | 187 | colIdx + ") for " + prettyName(aIdentifier)); |
michael@0 | 188 | } |
michael@0 | 189 | } |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | /** |
michael@0 | 194 | * Test table indexes. |
michael@0 | 195 | * |
michael@0 | 196 | * @param aIdentifier [in] table accessible identifier |
michael@0 | 197 | * @param aIdxes [in] two dimensional array of cell indexes |
michael@0 | 198 | */ |
michael@0 | 199 | function testTableIndexes(aIdentifier, aIdxes) |
michael@0 | 200 | { |
michael@0 | 201 | var tableAcc = getAccessible(aIdentifier, [nsIAccessibleTable]); |
michael@0 | 202 | if (!tableAcc) |
michael@0 | 203 | return; |
michael@0 | 204 | |
michael@0 | 205 | var obtainedRowIdx, obtainedColIdx, obtainedIdx; |
michael@0 | 206 | var cellAcc; |
michael@0 | 207 | |
michael@0 | 208 | var id = prettyName(aIdentifier); |
michael@0 | 209 | |
michael@0 | 210 | var rowCount = aIdxes.length; |
michael@0 | 211 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 212 | var colCount = aIdxes[rowIdx].length; |
michael@0 | 213 | for (var colIdx = 0; colIdx < colCount; colIdx++) { |
michael@0 | 214 | var idx = aIdxes[rowIdx][colIdx]; |
michael@0 | 215 | |
michael@0 | 216 | // getCellAt |
michael@0 | 217 | try { |
michael@0 | 218 | cellAcc = null; |
michael@0 | 219 | cellAcc = tableAcc.getCellAt(rowIdx, colIdx); |
michael@0 | 220 | } catch (e) { } |
michael@0 | 221 | |
michael@0 | 222 | ok(idx != -1 && cellAcc || idx == -1 && !cellAcc, |
michael@0 | 223 | id + ": Can't get cell accessible at row = " + rowIdx + ", column = " + colIdx); |
michael@0 | 224 | |
michael@0 | 225 | if (idx != - 1) { |
michael@0 | 226 | |
michael@0 | 227 | // getRowIndexAt |
michael@0 | 228 | var origRowIdx = rowIdx; |
michael@0 | 229 | while (origRowIdx > 0 && |
michael@0 | 230 | aIdxes[rowIdx][colIdx] == aIdxes[origRowIdx - 1][colIdx]) |
michael@0 | 231 | origRowIdx--; |
michael@0 | 232 | |
michael@0 | 233 | try { |
michael@0 | 234 | obtainedRowIdx = tableAcc.getRowIndexAt(idx); |
michael@0 | 235 | } catch (e) { |
michael@0 | 236 | ok(false, id + ": can't get row index for cell index " + idx + "," + e); |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | is(obtainedRowIdx, origRowIdx, |
michael@0 | 240 | id + ": row for index " + idx + " is not correct (getRowIndexAt)"); |
michael@0 | 241 | |
michael@0 | 242 | // getColumnIndexAt |
michael@0 | 243 | var origColIdx = colIdx; |
michael@0 | 244 | while (origColIdx > 0 && |
michael@0 | 245 | aIdxes[rowIdx][colIdx] == aIdxes[rowIdx][origColIdx - 1]) |
michael@0 | 246 | origColIdx--; |
michael@0 | 247 | |
michael@0 | 248 | try { |
michael@0 | 249 | obtainedColIdx = tableAcc.getColumnIndexAt(idx); |
michael@0 | 250 | } catch (e) { |
michael@0 | 251 | ok(false, id + ": can't get column index for cell index " + idx + "," + e); |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | is(obtainedColIdx, origColIdx, |
michael@0 | 255 | id + ": column for index " + idx + " is not correct (getColumnIndexAt)"); |
michael@0 | 256 | |
michael@0 | 257 | // getRowAndColumnIndicesAt |
michael@0 | 258 | var obtainedRowIdxObj = { }, obtainedColIdxObj = { }; |
michael@0 | 259 | try { |
michael@0 | 260 | tableAcc.getRowAndColumnIndicesAt(idx, obtainedRowIdxObj, |
michael@0 | 261 | obtainedColIdxObj); |
michael@0 | 262 | } catch (e) { |
michael@0 | 263 | ok(false, id + ": can't get row and column indices for cell index " + idx + "," + e); |
michael@0 | 264 | } |
michael@0 | 265 | |
michael@0 | 266 | is(obtainedRowIdxObj.value, origRowIdx, |
michael@0 | 267 | id + ": row for index " + idx + " is not correct (getRowAndColumnIndicesAt)"); |
michael@0 | 268 | is(obtainedColIdxObj.value, origColIdx, |
michael@0 | 269 | id + ": column for index " + idx + " is not correct (getRowAndColumnIndicesAt)"); |
michael@0 | 270 | |
michael@0 | 271 | if (cellAcc) { |
michael@0 | 272 | |
michael@0 | 273 | var cellId = prettyName(cellAcc); |
michael@0 | 274 | cellAcc = getAccessible(cellAcc, [nsIAccessibleTableCell]); |
michael@0 | 275 | |
michael@0 | 276 | // cell: 'table-cell-index' attribute |
michael@0 | 277 | var attrs = cellAcc.attributes; |
michael@0 | 278 | var strIdx = ""; |
michael@0 | 279 | try { |
michael@0 | 280 | strIdx = attrs.getStringProperty("table-cell-index"); |
michael@0 | 281 | } catch (e) { |
michael@0 | 282 | ok(false, |
michael@0 | 283 | cellId + ": no cell index from object attributes on the cell accessible at index " + idx + "."); |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | if (strIdx) { |
michael@0 | 287 | is (parseInt(strIdx), idx, |
michael@0 | 288 | cellId + ": cell index from object attributes of cell accessible isn't corrent."); |
michael@0 | 289 | } |
michael@0 | 290 | |
michael@0 | 291 | // cell: table |
michael@0 | 292 | try { |
michael@0 | 293 | is(cellAcc.table, tableAcc, |
michael@0 | 294 | cellId + ": wrong table accessible for the cell."); |
michael@0 | 295 | |
michael@0 | 296 | } catch (e) { |
michael@0 | 297 | ok(false, |
michael@0 | 298 | cellId + ": can't get table accessible from the cell."); |
michael@0 | 299 | } |
michael@0 | 300 | |
michael@0 | 301 | // cell: getRowIndex |
michael@0 | 302 | try { |
michael@0 | 303 | obtainedRowIdx = cellAcc.rowIndex; |
michael@0 | 304 | } catch (e) { |
michael@0 | 305 | ok(false, |
michael@0 | 306 | cellId + ": can't get row index of the cell at index " + idx + "," + e); |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | is(obtainedRowIdx, origRowIdx, |
michael@0 | 310 | cellId + ": row for the cell at index " + idx +" is not correct"); |
michael@0 | 311 | |
michael@0 | 312 | // cell: getColumnIndex |
michael@0 | 313 | try { |
michael@0 | 314 | obtainedColIdx = cellAcc.columnIndex; |
michael@0 | 315 | } catch (e) { |
michael@0 | 316 | ok(false, |
michael@0 | 317 | cellId + ": can't get column index of the cell at index " + idx + "," + e); |
michael@0 | 318 | } |
michael@0 | 319 | |
michael@0 | 320 | is(obtainedColIdx, origColIdx, |
michael@0 | 321 | id + ": column for the cell at index " + idx +" is not correct"); |
michael@0 | 322 | } |
michael@0 | 323 | } |
michael@0 | 324 | |
michael@0 | 325 | // getCellIndexAt |
michael@0 | 326 | try { |
michael@0 | 327 | obtainedIdx = tableAcc.getCellIndexAt(rowIdx, colIdx); |
michael@0 | 328 | } catch (e) { |
michael@0 | 329 | obtainedIdx = -1; |
michael@0 | 330 | } |
michael@0 | 331 | |
michael@0 | 332 | is(obtainedIdx, idx, |
michael@0 | 333 | id + ": row " + rowIdx + " /column " + colIdx + " and index " + obtainedIdx + " aren't inconsistent."); |
michael@0 | 334 | } |
michael@0 | 335 | } |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | /** |
michael@0 | 339 | * Test table getters selection methods. |
michael@0 | 340 | * |
michael@0 | 341 | * @param aIdentifier [in] table accessible identifier |
michael@0 | 342 | * @param aCellsArray [in] two dimensional array (row X columns) of cells |
michael@0 | 343 | * states (either boolean (selected/unselected) if cell is |
michael@0 | 344 | * origin, otherwise kRowSpanned or kColSpanned constant). |
michael@0 | 345 | * @param aMsg [in] text appended before every message |
michael@0 | 346 | */ |
michael@0 | 347 | function testTableSelection(aIdentifier, aCellsArray, aMsg) |
michael@0 | 348 | { |
michael@0 | 349 | var msg = aMsg ? aMsg : ""; |
michael@0 | 350 | var acc = getAccessible(aIdentifier, [nsIAccessibleTable]); |
michael@0 | 351 | if (!acc) |
michael@0 | 352 | return; |
michael@0 | 353 | |
michael@0 | 354 | var rowCount = aCellsArray.length; |
michael@0 | 355 | var colsCount = aCellsArray[0].length; |
michael@0 | 356 | |
michael@0 | 357 | // Columns selection tests. |
michael@0 | 358 | var selCols = new Array(); |
michael@0 | 359 | |
michael@0 | 360 | // isColumnSelected test |
michael@0 | 361 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 362 | var isColSelected = true; |
michael@0 | 363 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 364 | if (aCellsArray[rowIdx][colIdx] == false || |
michael@0 | 365 | aCellsArray[rowIdx][colIdx] == undefined) { |
michael@0 | 366 | isColSelected = false; |
michael@0 | 367 | break; |
michael@0 | 368 | } |
michael@0 | 369 | } |
michael@0 | 370 | |
michael@0 | 371 | is(acc.isColumnSelected(colIdx), isColSelected, |
michael@0 | 372 | msg + "Wrong selection state of " + colIdx + " column for " + |
michael@0 | 373 | prettyName(aIdentifier)); |
michael@0 | 374 | |
michael@0 | 375 | if (isColSelected) |
michael@0 | 376 | selCols.push(colIdx); |
michael@0 | 377 | } |
michael@0 | 378 | |
michael@0 | 379 | // selectedColsCount test |
michael@0 | 380 | is(acc.selectedColumnCount, selCols.length, |
michael@0 | 381 | msg + "Wrong count of selected columns for " + prettyName(aIdentifier)); |
michael@0 | 382 | |
michael@0 | 383 | // getSelectedColumns test |
michael@0 | 384 | var actualSelColsCountObj = { value: null }; |
michael@0 | 385 | var actualSelCols = acc.getSelectedColumnIndices(actualSelColsCountObj); |
michael@0 | 386 | |
michael@0 | 387 | var actualSelColsCount = actualSelColsCountObj.value; |
michael@0 | 388 | is (actualSelColsCount, selCols.length, |
michael@0 | 389 | msg + "Wrong count of selected columns for " + prettyName(aIdentifier) + |
michael@0 | 390 | "from getSelectedColumns."); |
michael@0 | 391 | |
michael@0 | 392 | for (var i = 0; i < actualSelColsCount; i++) { |
michael@0 | 393 | is (actualSelCols[i], selCols[i], |
michael@0 | 394 | msg + "Column at index " + selCols[i] + " should be selected."); |
michael@0 | 395 | } |
michael@0 | 396 | |
michael@0 | 397 | // Rows selection tests. |
michael@0 | 398 | var selRows = new Array(); |
michael@0 | 399 | |
michael@0 | 400 | // isRowSelected test |
michael@0 | 401 | var selrowCount = 0; |
michael@0 | 402 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 403 | var isRowSelected = true; |
michael@0 | 404 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 405 | if (aCellsArray[rowIdx][colIdx] == false || |
michael@0 | 406 | aCellsArray[rowIdx][colIdx] == undefined) { |
michael@0 | 407 | isRowSelected = false; |
michael@0 | 408 | break; |
michael@0 | 409 | } |
michael@0 | 410 | } |
michael@0 | 411 | |
michael@0 | 412 | is(acc.isRowSelected(rowIdx), isRowSelected, |
michael@0 | 413 | msg + "Wrong selection state of " + rowIdx + " row for " + |
michael@0 | 414 | prettyName(aIdentifier)); |
michael@0 | 415 | |
michael@0 | 416 | if (isRowSelected) |
michael@0 | 417 | selRows.push(rowIdx); |
michael@0 | 418 | } |
michael@0 | 419 | |
michael@0 | 420 | // selectedRowCount test |
michael@0 | 421 | is(acc.selectedRowCount, selRows.length, |
michael@0 | 422 | msg + "Wrong count of selected rows for " + prettyName(aIdentifier)); |
michael@0 | 423 | |
michael@0 | 424 | // getSelectedRows test |
michael@0 | 425 | var actualSelrowCountObj = { value: null }; |
michael@0 | 426 | var actualSelRows = acc.getSelectedRowIndices(actualSelrowCountObj); |
michael@0 | 427 | |
michael@0 | 428 | var actualSelrowCount = actualSelrowCountObj.value; |
michael@0 | 429 | is (actualSelrowCount, selRows.length, |
michael@0 | 430 | msg + "Wrong count of selected rows for " + prettyName(aIdentifier) + |
michael@0 | 431 | "from getSelectedRows."); |
michael@0 | 432 | |
michael@0 | 433 | for (var i = 0; i < actualSelrowCount; i++) { |
michael@0 | 434 | is (actualSelRows[i], selRows[i], |
michael@0 | 435 | msg + "Row at index " + selRows[i] + " should be selected."); |
michael@0 | 436 | } |
michael@0 | 437 | |
michael@0 | 438 | // Cells selection tests. |
michael@0 | 439 | var selCells = new Array(); |
michael@0 | 440 | |
michael@0 | 441 | // isCellSelected test |
michael@0 | 442 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 443 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 444 | if (aCellsArray[rowIdx][colIdx] & kSpanned) |
michael@0 | 445 | continue; |
michael@0 | 446 | |
michael@0 | 447 | var isSelected = aCellsArray[rowIdx][colIdx] == true; |
michael@0 | 448 | is(acc.isCellSelected(rowIdx, colIdx), isSelected, |
michael@0 | 449 | msg + "Wrong selection state of cell at " + rowIdx + " row and " + |
michael@0 | 450 | colIdx + " column for " + prettyName(aIdentifier)); |
michael@0 | 451 | |
michael@0 | 452 | if (aCellsArray[rowIdx][colIdx]) |
michael@0 | 453 | selCells.push(acc.getCellIndexAt(rowIdx, colIdx)); |
michael@0 | 454 | } |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | // selectedCellCount tests |
michael@0 | 458 | is(acc.selectedCellCount, selCells.length, |
michael@0 | 459 | msg + "Wrong count of selected cells for " + prettyName(aIdentifier)); |
michael@0 | 460 | |
michael@0 | 461 | // getSelectedCellIndices test |
michael@0 | 462 | var actualSelCellsCountObj = { value: null }; |
michael@0 | 463 | var actualSelCells = acc.getSelectedCellIndices(actualSelCellsCountObj); |
michael@0 | 464 | |
michael@0 | 465 | var actualSelCellsCount = actualSelCellsCountObj.value; |
michael@0 | 466 | is(actualSelCellsCount, selCells.length, |
michael@0 | 467 | msg + "Wrong count of selected cells for " + prettyName(aIdentifier) + |
michael@0 | 468 | "from getSelectedCells."); |
michael@0 | 469 | |
michael@0 | 470 | for (var i = 0; i < actualSelCellsCount; i++) { |
michael@0 | 471 | is(actualSelCells[i], selCells[i], |
michael@0 | 472 | msg + "getSelectedCellIndices: Cell at index " + selCells[i] + |
michael@0 | 473 | " should be selected."); |
michael@0 | 474 | } |
michael@0 | 475 | |
michael@0 | 476 | // selectedCells and isSelected tests |
michael@0 | 477 | var actualSelCellsArray = acc.selectedCells; |
michael@0 | 478 | for (var i = 0; i < actualSelCellsCount; i++) { |
michael@0 | 479 | var actualSelCellAccessible = |
michael@0 | 480 | actualSelCellsArray.queryElementAt(i, nsIAccessibleTableCell); |
michael@0 | 481 | |
michael@0 | 482 | var colIdx = acc.getColumnIndexAt(selCells[i]); |
michael@0 | 483 | var rowIdx = acc.getRowIndexAt(selCells[i]); |
michael@0 | 484 | var expectedSelCellAccessible = acc.getCellAt(rowIdx, colIdx); |
michael@0 | 485 | |
michael@0 | 486 | ok(actualSelCellAccessible, expectedSelCellAccessible, |
michael@0 | 487 | msg + "getSelectedCells: Cell at index " + selCells[i] + |
michael@0 | 488 | " should be selected."); |
michael@0 | 489 | |
michael@0 | 490 | ok(actualSelCellAccessible.isSelected(), |
michael@0 | 491 | "isSelected: Cell at index " + selCells[i] + " should be selected."); |
michael@0 | 492 | } |
michael@0 | 493 | |
michael@0 | 494 | // selected states tests |
michael@0 | 495 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 496 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 497 | if (aCellsArray[rowIdx][colIdx] & kSpanned) |
michael@0 | 498 | continue; |
michael@0 | 499 | |
michael@0 | 500 | var cell = acc.getCellAt(rowIdx, colIdx); |
michael@0 | 501 | var isSel = aCellsArray[rowIdx][colIdx]; |
michael@0 | 502 | if (isSel == undefined) |
michael@0 | 503 | testStates(cell, 0, 0, STATE_SELECTABLE | STATE_SELECTED); |
michael@0 | 504 | else if (isSel == true) |
michael@0 | 505 | testStates(cell, STATE_SELECTED); |
michael@0 | 506 | else |
michael@0 | 507 | testStates(cell, STATE_SELECTABLE, 0, STATE_SELECTED); |
michael@0 | 508 | } |
michael@0 | 509 | } |
michael@0 | 510 | } |
michael@0 | 511 | |
michael@0 | 512 | /** |
michael@0 | 513 | * Test unselectColumn method of accessible table. |
michael@0 | 514 | */ |
michael@0 | 515 | function testUnselectTableColumn(aIdentifier, aColIdx, aCellsArray) |
michael@0 | 516 | { |
michael@0 | 517 | var acc = getAccessible(aIdentifier, [nsIAccessibleTable]); |
michael@0 | 518 | if (!acc) |
michael@0 | 519 | return; |
michael@0 | 520 | |
michael@0 | 521 | var rowCount = aCellsArray.length; |
michael@0 | 522 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 523 | var cellState = aCellsArray[rowIdx][aColIdx]; |
michael@0 | 524 | // Unselect origin cell. |
michael@0 | 525 | var [origRowIdx, origColIdx] = |
michael@0 | 526 | getOrigRowAndColumn(aCellsArray, rowIdx, aColIdx); |
michael@0 | 527 | aCellsArray[origRowIdx][origColIdx] = false; |
michael@0 | 528 | } |
michael@0 | 529 | |
michael@0 | 530 | acc.unselectColumn(aColIdx); |
michael@0 | 531 | testTableSelection(aIdentifier, aCellsArray, |
michael@0 | 532 | "Unselect " + aColIdx + " column: "); |
michael@0 | 533 | } |
michael@0 | 534 | |
michael@0 | 535 | /** |
michael@0 | 536 | * Test selectColumn method of accessible table. |
michael@0 | 537 | */ |
michael@0 | 538 | function testSelectTableColumn(aIdentifier, aColIdx, aCellsArray) |
michael@0 | 539 | { |
michael@0 | 540 | var acc = getAccessible(aIdentifier, [nsIAccessibleTable]); |
michael@0 | 541 | if (!acc) |
michael@0 | 542 | return; |
michael@0 | 543 | |
michael@0 | 544 | var rowCount = aCellsArray.length; |
michael@0 | 545 | var colsCount = aCellsArray[0].length; |
michael@0 | 546 | |
michael@0 | 547 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 548 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 549 | var cellState = aCellsArray[rowIdx][colIdx]; |
michael@0 | 550 | |
michael@0 | 551 | if (colIdx == aColIdx) { // select target column |
michael@0 | 552 | if (!(cellState & kSpanned)) { |
michael@0 | 553 | // Select the cell if it is origin. |
michael@0 | 554 | aCellsArray[rowIdx][colIdx] = true; |
michael@0 | 555 | |
michael@0 | 556 | } else { |
michael@0 | 557 | // If the cell is spanned then search origin cell and select it. |
michael@0 | 558 | var [origRowIdx, origColIdx] = getOrigRowAndColumn(aCellsArray, |
michael@0 | 559 | rowIdx, colIdx); |
michael@0 | 560 | aCellsArray[origRowIdx][origColIdx] = true; |
michael@0 | 561 | } |
michael@0 | 562 | |
michael@0 | 563 | } else if (!(cellState & kSpanned)) { // unselect other columns |
michael@0 | 564 | if (colIdx > aColIdx) { |
michael@0 | 565 | // Unselect the cell if traversed column index is greater than column |
michael@0 | 566 | // index of target cell. |
michael@0 | 567 | aCellsArray[rowIdx][colIdx] = false; |
michael@0 | 568 | |
michael@0 | 569 | } else if (!(aCellsArray[rowIdx][aColIdx] & kColSpanned)) { |
michael@0 | 570 | // Unselect the cell if the target cell is not row spanned. |
michael@0 | 571 | aCellsArray[rowIdx][colIdx] = false; |
michael@0 | 572 | |
michael@0 | 573 | } else { |
michael@0 | 574 | // Unselect the cell if it is not spanned to the target cell. |
michael@0 | 575 | for (var spannedColIdx = colIdx + 1; spannedColIdx < aColIdx; |
michael@0 | 576 | spannedColIdx++) { |
michael@0 | 577 | var spannedCellState = aCellsArray[rowIdx][spannedColIdx]; |
michael@0 | 578 | if (!(spannedCellState & kRowSpanned)) { |
michael@0 | 579 | aCellsArray[rowIdx][colIdx] = false; |
michael@0 | 580 | break; |
michael@0 | 581 | } |
michael@0 | 582 | } |
michael@0 | 583 | } |
michael@0 | 584 | } |
michael@0 | 585 | } |
michael@0 | 586 | } |
michael@0 | 587 | |
michael@0 | 588 | acc.selectColumn(aColIdx); |
michael@0 | 589 | testTableSelection(aIdentifier, aCellsArray, |
michael@0 | 590 | "Select " + aColIdx + " column: "); |
michael@0 | 591 | } |
michael@0 | 592 | |
michael@0 | 593 | /** |
michael@0 | 594 | * Test unselectRow method of accessible table. |
michael@0 | 595 | */ |
michael@0 | 596 | function testUnselectTableRow(aIdentifier, aRowIdx, aCellsArray) |
michael@0 | 597 | { |
michael@0 | 598 | var acc = getAccessible(aIdentifier, [nsIAccessibleTable]); |
michael@0 | 599 | if (!acc) |
michael@0 | 600 | return; |
michael@0 | 601 | |
michael@0 | 602 | var colsCount = aCellsArray[0].length; |
michael@0 | 603 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 604 | // Unselect origin cell. |
michael@0 | 605 | var [origRowIdx, origColIdx] = getOrigRowAndColumn(aCellsArray, |
michael@0 | 606 | aRowIdx, colIdx); |
michael@0 | 607 | aCellsArray[origRowIdx][origColIdx] = false; |
michael@0 | 608 | } |
michael@0 | 609 | |
michael@0 | 610 | acc.unselectRow(aRowIdx); |
michael@0 | 611 | testTableSelection(aIdentifier, aCellsArray, |
michael@0 | 612 | "Unselect " + aRowIdx + " row: "); |
michael@0 | 613 | } |
michael@0 | 614 | |
michael@0 | 615 | /** |
michael@0 | 616 | * Test selectRow method of accessible table. |
michael@0 | 617 | */ |
michael@0 | 618 | function testSelectTableRow(aIdentifier, aRowIdx, aCellsArray) |
michael@0 | 619 | { |
michael@0 | 620 | var acc = getAccessible(aIdentifier, [nsIAccessibleTable]); |
michael@0 | 621 | if (!acc) |
michael@0 | 622 | return; |
michael@0 | 623 | |
michael@0 | 624 | var rowCount = aCellsArray.length; |
michael@0 | 625 | var colsCount = aCellsArray[0].length; |
michael@0 | 626 | |
michael@0 | 627 | for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { |
michael@0 | 628 | for (var colIdx = 0; colIdx < colsCount; colIdx++) { |
michael@0 | 629 | var cellState = aCellsArray[rowIdx][colIdx]; |
michael@0 | 630 | |
michael@0 | 631 | if (rowIdx == aRowIdx) { // select the given row |
michael@0 | 632 | if (!(cellState & kSpanned)) { |
michael@0 | 633 | // Select the cell if it is origin. |
michael@0 | 634 | aCellsArray[rowIdx][colIdx] = true; |
michael@0 | 635 | |
michael@0 | 636 | } else { |
michael@0 | 637 | // If the cell is spanned then search origin cell and select it. |
michael@0 | 638 | var [origRowIdx, origColIdx] = getOrigRowAndColumn(aCellsArray, |
michael@0 | 639 | rowIdx, colIdx); |
michael@0 | 640 | |
michael@0 | 641 | aCellsArray[origRowIdx][origColIdx] = true; |
michael@0 | 642 | } |
michael@0 | 643 | |
michael@0 | 644 | } else if (!(cellState & kSpanned)) { // unselect other rows |
michael@0 | 645 | if (rowIdx > aRowIdx) { |
michael@0 | 646 | // Unselect the cell if traversed row index is greater than row |
michael@0 | 647 | // index of target cell. |
michael@0 | 648 | aCellsArray[rowIdx][colIdx] = false; |
michael@0 | 649 | |
michael@0 | 650 | } else if (!(aCellsArray[aRowIdx][colIdx] & kRowSpanned)) { |
michael@0 | 651 | // Unselect the cell if the target cell is not row spanned. |
michael@0 | 652 | aCellsArray[rowIdx][colIdx] = false; |
michael@0 | 653 | |
michael@0 | 654 | } else { |
michael@0 | 655 | // Unselect the cell if it is not spanned to the target cell. |
michael@0 | 656 | for (var spannedRowIdx = rowIdx + 1; spannedRowIdx < aRowIdx; |
michael@0 | 657 | spannedRowIdx++) { |
michael@0 | 658 | var spannedCellState = aCellsArray[spannedRowIdx][colIdx]; |
michael@0 | 659 | if (!(spannedCellState & kRowSpanned)) { |
michael@0 | 660 | aCellsArray[rowIdx][colIdx] = false; |
michael@0 | 661 | break; |
michael@0 | 662 | } |
michael@0 | 663 | } |
michael@0 | 664 | } |
michael@0 | 665 | } |
michael@0 | 666 | } |
michael@0 | 667 | } |
michael@0 | 668 | |
michael@0 | 669 | acc.selectRow(aRowIdx); |
michael@0 | 670 | testTableSelection(aIdentifier, aCellsArray, |
michael@0 | 671 | "Select " + aRowIdx + " row: "); |
michael@0 | 672 | } |
michael@0 | 673 | |
michael@0 | 674 | /** |
michael@0 | 675 | * Test columnHeaderCells and rowHeaderCells of accessible table. |
michael@0 | 676 | */ |
michael@0 | 677 | function testHeaderCells(aHeaderInfoMap) |
michael@0 | 678 | { |
michael@0 | 679 | for (var testIdx = 0; testIdx < aHeaderInfoMap.length; testIdx++) { |
michael@0 | 680 | var dataCellIdentifier = aHeaderInfoMap[testIdx].cell; |
michael@0 | 681 | var dataCell = getAccessible(dataCellIdentifier, [nsIAccessibleTableCell]); |
michael@0 | 682 | |
michael@0 | 683 | // row header cells |
michael@0 | 684 | var rowHeaderCells = aHeaderInfoMap[testIdx].rowHeaderCells; |
michael@0 | 685 | var rowHeaderCellsCount = rowHeaderCells.length; |
michael@0 | 686 | var actualRowHeaderCells = dataCell.rowHeaderCells; |
michael@0 | 687 | var actualRowHeaderCellsCount = actualRowHeaderCells.length; |
michael@0 | 688 | |
michael@0 | 689 | is(actualRowHeaderCellsCount, rowHeaderCellsCount, |
michael@0 | 690 | "Wrong number of row header cells for the cell " + |
michael@0 | 691 | prettyName(dataCellIdentifier)); |
michael@0 | 692 | |
michael@0 | 693 | if (actualRowHeaderCellsCount == rowHeaderCellsCount) { |
michael@0 | 694 | for (var idx = 0; idx < rowHeaderCellsCount; idx++) { |
michael@0 | 695 | var rowHeaderCell = getAccessible(rowHeaderCells[idx]); |
michael@0 | 696 | var actualRowHeaderCell = |
michael@0 | 697 | actualRowHeaderCells.queryElementAt(idx, nsIAccessible); |
michael@0 | 698 | ok(actualRowHeaderCell, rowHeaderCell, |
michael@0 | 699 | "Wrong row header cell at index " + idx + " for the cell " + |
michael@0 | 700 | prettyName(rowHeaderCells[idx])); |
michael@0 | 701 | } |
michael@0 | 702 | } |
michael@0 | 703 | |
michael@0 | 704 | // column header cells |
michael@0 | 705 | var colHeaderCells = aHeaderInfoMap[testIdx].columnHeaderCells; |
michael@0 | 706 | var colHeaderCellsCount = colHeaderCells.length; |
michael@0 | 707 | var actualColHeaderCells = dataCell.columnHeaderCells; |
michael@0 | 708 | var actualColHeaderCellsCount = actualColHeaderCells.length; |
michael@0 | 709 | |
michael@0 | 710 | is(actualColHeaderCellsCount, colHeaderCellsCount, |
michael@0 | 711 | "Wrong number of column header cells for the cell " + |
michael@0 | 712 | prettyName(dataCellIdentifier)); |
michael@0 | 713 | |
michael@0 | 714 | if (actualColHeaderCellsCount == colHeaderCellsCount) { |
michael@0 | 715 | for (var idx = 0; idx < colHeaderCellsCount; idx++) { |
michael@0 | 716 | var colHeaderCell = getAccessible(colHeaderCells[idx]); |
michael@0 | 717 | var actualColHeaderCell = |
michael@0 | 718 | actualColHeaderCells.queryElementAt(idx, nsIAccessible); |
michael@0 | 719 | ok(actualColHeaderCell, colHeaderCell, |
michael@0 | 720 | "Wrong column header cell at index " + idx + " for the cell " + |
michael@0 | 721 | prettyName(colHeaderCells[idx])); |
michael@0 | 722 | } |
michael@0 | 723 | } |
michael@0 | 724 | } |
michael@0 | 725 | } |
michael@0 | 726 | |
michael@0 | 727 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 728 | // private implementation |
michael@0 | 729 | |
michael@0 | 730 | /** |
michael@0 | 731 | * Return row and column of orig cell for the given spanned cell. |
michael@0 | 732 | */ |
michael@0 | 733 | function getOrigRowAndColumn(aCellsArray, aRowIdx, aColIdx) |
michael@0 | 734 | { |
michael@0 | 735 | var cellState = aCellsArray[aRowIdx][aColIdx]; |
michael@0 | 736 | |
michael@0 | 737 | var origRowIdx = aRowIdx, origColIdx = aColIdx; |
michael@0 | 738 | if (cellState & kRowSpanned) { |
michael@0 | 739 | for (var prevRowIdx = aRowIdx - 1; prevRowIdx >= 0; prevRowIdx--) { |
michael@0 | 740 | var prevCellState = aCellsArray[prevRowIdx][aColIdx]; |
michael@0 | 741 | if (!(prevCellState & kRowSpanned)) { |
michael@0 | 742 | origRowIdx = prevRowIdx; |
michael@0 | 743 | break; |
michael@0 | 744 | } |
michael@0 | 745 | } |
michael@0 | 746 | } |
michael@0 | 747 | |
michael@0 | 748 | if (cellState & kColSpanned) { |
michael@0 | 749 | for (var prevColIdx = aColIdx - 1; prevColIdx >= 0; prevColIdx--) { |
michael@0 | 750 | var prevCellState = aCellsArray[aRowIdx][prevColIdx]; |
michael@0 | 751 | if (!(prevCellState & kColSpanned)) { |
michael@0 | 752 | origColIdx = prevColIdx; |
michael@0 | 753 | break; |
michael@0 | 754 | } |
michael@0 | 755 | } |
michael@0 | 756 | } |
michael@0 | 757 | |
michael@0 | 758 | return [origRowIdx, origColIdx]; |
michael@0 | 759 | } |