blob: 54bf391599ef4c0de9f5f2d17446e390913fc68c [file] [edit]
<!DOCTYPE html>
<html>
<head>
<script src="../resources/accessibility-helper.js"></script>
<script src="../resources/js-test.js"></script>
</head>
<body>
<div id="content">
<span id="externalLabel">External label</span>
<!-- 1: plain table + caption. -->
<table id="plain">
<caption id="plainCaption">Quarterly results</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<!-- 2: table with no caption. -->
<table id="noCaption">
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<!-- 3: table with a caption and aria-labelledby. aria-labelledby wins. -->
<table id="captionAndLabelledby" aria-labelledby="externalLabel">
<caption id="captionAndLabelledbyCaption">Caption loses</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<!-- 4: table with a caption and aria-label. The aria-label names the table, so the caption does not. -->
<table id="captionAndAriaLabel" aria-label="ARIA label">
<caption id="captionAndAriaLabelCaption">Caption loses</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<!-- 5: two captions. The first one wins. -->
<table id="twoCaptions">
<caption id="firstCaption">First</caption>
<caption id="secondCaption">Second</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<!-- 6: display: none caption. -->
<table id="displayNoneCaption">
<caption id="displayNoneCaptionCaption" style="display: none;">Display none</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<!-- 7: role="grid" table with a caption. -->
<table id="grid" role="grid">
<caption id="gridCaption">Grid caption</caption>
<tr role="row"><th role="columnheader">Quarter</th><th role="columnheader">Revenue</th></tr><tr role="row"><td role="gridcell">Q1</td><td role="gridcell">100</td></tr>
</table>
<!-- 8: an inner table's caption belongs to the inner table, not the outer one. -->
<table id="outerTable">
<thead><tr><th>Outer</th></tr></thead>
<tr><td>
<table id="innerTable">
<caption id="innerCaption">Inner</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
</td></tr>
</table>
<!-- Dynamic cases. -->
<table id="captionAdded">
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<table id="captionRemoved">
<caption id="captionRemovedCaption">Removed</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<table id="captionTextChanged">
<caption id="captionTextChangedCaption">Before</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<table id="captionChildAdded">
<caption id="captionChildAddedCaption">Child</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<table id="captionShown">
<caption id="captionShownCaption" style="display: none;">Shown</caption>
<thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr>
</table>
<div id="tableContainer"></div>
</div>
<script>
var output = "This tests that a table's title UI element is its caption.\n\n";
function titleUIElementIdentifier(id) {
var element = accessibilityController.accessibleElementById(id);
if (!element)
return "(no AX object for #" + id + ")";
var titleUIElement = element.titleUIElement();
if (!titleUIElement)
return "null";
var identifier = titleUIElement.domIdentifier;
return identifier ? "#" + identifier : "(unidentified " + titleUIElement.role + ")";
}
if (window.accessibilityController) {
window.jsTestIsAsync = true;
var tableIds = [
"plain",
"noCaption",
"captionAndLabelledby",
"captionAndAriaLabel",
"twoCaptions",
"displayNoneCaption",
"grid",
"outerTable",
"innerTable",
];
setTimeout(async function() {
for (var tableId of tableIds)
output += `#${tableId} titleUIElement: ${titleUIElementIdentifier(tableId)}\n`;
output += expect("accessibilityController.accessibleElementById('plain').title", "'AXTitle: Quarterly results'");
output += "\nAdding a caption.\n";
var caption = document.createElement("caption");
caption.id = "captionAddedCaption";
caption.textContent = "Added";
document.getElementById("captionAdded").prepend(caption);
output += await expectAsync("titleUIElementIdentifier('captionAdded')", "'#captionAddedCaption'");
output += "\nRemoving a caption.\n";
document.getElementById("captionRemovedCaption").remove();
output += await expectAsync("titleUIElementIdentifier('captionRemoved')", "'null'");
output += "\nChanging a caption's text.\n";
output += await expectAsync("titleUIElementIdentifier('captionTextChanged')", "'#captionTextChangedCaption'");
document.getElementById("captionTextChangedCaption").firstChild.data = "After";
output += await expectAsync("accessibilityController.accessibleElementById('captionTextChanged').title", "'AXTitle: After'");
output += expect("titleUIElementIdentifier('captionTextChanged')", "'#captionTextChangedCaption'");
output += "\nAdding an element to a caption.\n";
output += await expectAsync("titleUIElementIdentifier('captionChildAdded')", "'#captionChildAddedCaption'");
var bold = document.createElement("b");
bold.textContent = " added";
document.getElementById("captionChildAddedCaption").appendChild(bold);
output += await expectAsync("accessibilityController.accessibleElementById('captionChildAdded').title", "'AXTitle: Child added'");
output += expect("titleUIElementIdentifier('captionChildAdded')", "'#captionChildAddedCaption'");
output += "\nShowing a display: none caption.\n";
document.getElementById("captionShownCaption").style.display = "table-caption";
output += await expectAsync("titleUIElementIdentifier('captionShown')", "'#captionShownCaption'");
output += "\nHiding the caption again.\n";
document.getElementById("captionShownCaption").style.display = "none";
output += await expectAsync("titleUIElementIdentifier('captionShown')", "'null'");
output += "\nInserting a wrapper containing a captioned table.\n";
document.getElementById("tableContainer").innerHTML = `<div><table id="insertedTable"><caption id="insertedCaption">Inserted</caption><thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tr><td>Q1</td><td>100</td></tr></table></div>`;
output += await expectAsync("titleUIElementIdentifier('insertedTable')", "'#insertedCaption'");
output += "\nAdding aria-label to a captioned table.\n";
document.getElementById("plain").setAttribute("aria-label", "ARIA label");
output += await expectAsync("titleUIElementIdentifier('plain')", "'null'");
output += "\nRemoving the aria-label again.\n";
document.getElementById("plain").removeAttribute("aria-label");
output += await expectAsync("titleUIElementIdentifier('plain')", "'#plainCaption'");
document.getElementById("content").style.visibility = "hidden";
debug(output);
finishJSTest();
}, 0);
}
</script>
</body>
</html>