| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| <html> |
| <head> |
| <script src="../resources/accessibility-helper.js"></script> |
| <script src="../resources/js-test.js"></script> |
| </head> |
| <body> |
| |
| <table id="table"> |
| <tr> |
| <td id="cellOne">x</td> |
| <td>x</td> |
| </tr> |
| </table> |
| |
| <script> |
| var testOutput = `This test ensures a table's "exposed" state (whether it is an accessibility data table, vs. just a layout table) updates in response to dynamic page changes.\n\n`; |
| |
| function createCell() { |
| const cell = document.createElement("td"); |
| cell.appendChild(document.createTextNode("Text inside cell")); |
| return cell; |
| } |
| |
| function roleById(id) { |
| const axElement = accessibilityController.accessibleElementById(id); |
| if (!axElement) |
| return "AXRole: null AXUIElement"; |
| return axElement.role; |
| } |
| |
| async function verifyAttributeChange(targetId, attributeName, newValue) { |
| // We clean up at the end of this function by removing the attribute, so ensure it didn't exist to start with. |
| if (document.getElementById(targetId).hasAttribute(attributeName)) |
| debug(`FAIL: #${targetId} already had attribute ${attributeName}`); |
| |
| const initialTableRole = roleById("table"); |
| const initialCellRole = roleById("cellOne"); |
| testOutput += `\nBefore updating attribute ${attributeName} of #${targetId} to ${newValue}, #table ${initialTableRole}, #cellOne ${initialCellRole}.\n`; |
| document.getElementById(targetId).setAttribute(attributeName, newValue); |
| await waitFor(() => roleById("table") !== initialTableRole && roleById("cellOne") !== initialCellRole); |
| testOutput += `After updating attribute ${attributeName} of #${targetId} to ${newValue}, #table ${roleById("table")}, #cellOne ${roleById("cellOne")}.\n`; |
| |
| document.getElementById(targetId).removeAttribute(attributeName); |
| await waitFor(() => roleById("table") === initialTableRole && roleById("cellOne") === initialCellRole); |
| } |
| |
| if (window.accessibilityController) { |
| window.jsTestIsAsync = true; |
| |
| setTimeout(async function() { |
| await verifyAttributeChange("table", "aria-rowcount", "1"); |
| await verifyAttributeChange("table", "aria-colcount", "10"); |
| await verifyAttributeChange("cellOne", "aria-colindex", "1"); |
| await verifyAttributeChange("cellOne", "aria-rowindex", "1"); |
| await verifyAttributeChange("cellOne", "aria-colspan", "1"); |
| await verifyAttributeChange("cellOne", "aria-rowspan", "1"); |
| |
| testOutput += `\nBefore adding 20 rows, state is #table ${roleById("table")} #cellOne ${roleById("cellOne")}.\n`; |
| for (let i = 0; i < 20; i++) { |
| const row = document.getElementById("table").insertRow(-1); |
| row.appendChild(createCell()); |
| row.appendChild(createCell()); |
| } |
| |
| await waitFor(() => { |
| const table = accessibilityController.accessibleElementById("table"); |
| return table && |
| table.childrenCount >= 20 && |
| roleById("cellOne").includes("Cell") && |
| roleById("table").includes("Table"); |
| }); |
| testOutput += `After adding 20 rows, state is #table ${roleById("table")} #cellOne ${roleById("cellOne")}.\n`; |
| |
| document.getElementById("table").style.visibility = "hidden"; |
| debug(testOutput); |
| finishJSTest(); |
| }, 0); |
| } |
| </script> |
| </body> |
| </html> |
| |