/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* import-globals-from ../../mochitest/role.js */
/* import-globals-from ../../mochitest/states.js */
loadScripts(
{ name: "role.js", dir: MOCHITESTS_DIR },
{ name: "states.js", dir: MOCHITESTS_DIR }
);
/**
* Test different HTML elements for their roles and subroles
*/
function testRoleAndSubRole(accDoc, id, axRole, axSubRole, axRoleDescription) {
let el = getNativeInterface(accDoc, id);
if (axRole) {
is(
el.getAttributeValue("AXRole"),
axRole,
"AXRole for " + id + " is " + axRole
);
}
if (axSubRole) {
is(
el.getAttributeValue("AXSubrole"),
axSubRole,
"Subrole for " + id + " is " + axSubRole
);
}
if (axRoleDescription) {
is(
el.getAttributeValue("AXRoleDescription"),
axRoleDescription,
"Subrole for " + id + " is " + axRoleDescription
);
}
}
addAccessibleTask(
`
Deleted text
term
definition
Inserted text
meter text heresub text heresup text here
`,
(browser, accDoc) => {
// WAI-ARIA landmark subroles, regardless of AXRole
testRoleAndSubRole(accDoc, "application", null, "AXLandmarkApplication");
testRoleAndSubRole(accDoc, "banner", null, "AXLandmarkBanner");
testRoleAndSubRole(
accDoc,
"complementary",
null,
"AXLandmarkComplementary"
);
testRoleAndSubRole(accDoc, "contentinfo", null, "AXLandmarkContentInfo");
testRoleAndSubRole(accDoc, "form", null, "AXApplicationGroup");
testRoleAndSubRole(accDoc, "form_label", null, "AXLandmarkForm");
testRoleAndSubRole(accDoc, "main", null, "AXLandmarkMain");
testRoleAndSubRole(accDoc, "navigation", null, "AXLandmarkNavigation");
testRoleAndSubRole(accDoc, "search", null, "AXLandmarkSearch");
testRoleAndSubRole(accDoc, "searchbox", null, "AXSearchField");
// DPub roles map into two categories, sample one of each
testRoleAndSubRole(
accDoc,
"dPubNavigation",
"AXGroup",
"AXLandmarkNavigation"
);
testRoleAndSubRole(accDoc, "dPubRegion", "AXGroup", "AXLandmarkRegion");
// ARIA widget roles
testRoleAndSubRole(accDoc, "alert", null, "AXApplicationAlert");
testRoleAndSubRole(
accDoc,
"alertdialog",
"AXGroup",
"AXApplicationAlertDialog",
"alert dialog"
);
testRoleAndSubRole(accDoc, "article", null, "AXDocumentArticle");
testRoleAndSubRole(accDoc, "code", "AXGroup", "AXCodeStyleGroup");
testRoleAndSubRole(accDoc, "dialog", null, "AXApplicationDialog", "dialog");
testRoleAndSubRole(accDoc, "ariaDocument", null, "AXDocument");
testRoleAndSubRole(accDoc, "log", null, "AXApplicationLog");
testRoleAndSubRole(accDoc, "marquee", null, "AXApplicationMarquee");
testRoleAndSubRole(accDoc, "ariaMath", null, "AXDocumentMath");
testRoleAndSubRole(accDoc, "note", null, "AXDocumentNote");
testRoleAndSubRole(accDoc, "ariaRegion", null, "AXLandmarkRegion");
testRoleAndSubRole(accDoc, "ariaStatus", "AXGroup", "AXApplicationStatus");
testRoleAndSubRole(accDoc, "switch", "AXCheckBox", "AXSwitch");
testRoleAndSubRole(accDoc, "timer", null, "AXApplicationTimer");
testRoleAndSubRole(accDoc, "tooltip", "AXGroup", "AXUserInterfaceTooltip");
testRoleAndSubRole(accDoc, "menuitemradio", "AXMenuItem", null);
testRoleAndSubRole(accDoc, "menuitemcheckbox", "AXMenuItem", null);
testRoleAndSubRole(accDoc, "datetime", "AXGroup", null);
// XXX for datetime elements, we spoof the role via the title, since
// providing the correct role results in the internal elements being
// unreachable by VO
is(
getNativeInterface(accDoc, "datetime").getAttributeValue("AXTitle"),
"date field"
);
// Text boxes
testRoleAndSubRole(accDoc, "textbox_multiline", "AXTextArea");
testRoleAndSubRole(accDoc, "textbox_singleline", "AXTextField");
testRoleAndSubRole(accDoc, "textArea", "AXTextArea");
testRoleAndSubRole(accDoc, "textInput", "AXTextField");
// True HTML5 search field
testRoleAndSubRole(accDoc, "htmlSearch", "AXTextField", "AXSearchField");
// A button morphed into a toggle by ARIA
testRoleAndSubRole(accDoc, "toggle", "AXCheckBox", "AXToggle");
// A banana button
testRoleAndSubRole(accDoc, "banana", "AXButton", null, "banana");
// Other elements
testRoleAndSubRole(accDoc, "deletion", "AXGroup", "AXDeleteStyleGroup");
testRoleAndSubRole(accDoc, "dl", "AXList", "AXDescriptionList");
testRoleAndSubRole(accDoc, "dt", "AXGroup", "AXTerm");
testRoleAndSubRole(accDoc, "dd", "AXGroup", "AXDescription");
testRoleAndSubRole(accDoc, "hr", "AXSplitter", "AXContentSeparator");
testRoleAndSubRole(accDoc, "insertion", "AXGroup", "AXInsertStyleGroup");
testRoleAndSubRole(
accDoc,
"meter",
"AXLevelIndicator",
"AXMeter",
"level indicator"
);
testRoleAndSubRole(accDoc, "sub", "AXGroup", "AXSubscriptStyleGroup");
testRoleAndSubRole(accDoc, "sup", "AXGroup", "AXSuperscriptStyleGroup");
// Some SVG stuff
testRoleAndSubRole(accDoc, "svg", "AXImage");
testRoleAndSubRole(accDoc, "g", "AXGroup");
testRoleAndSubRole(accDoc, "rect", "AXImage");
testRoleAndSubRole(accDoc, "circle", "AXImage");
testRoleAndSubRole(accDoc, "ellipse", "AXImage");
testRoleAndSubRole(accDoc, "line", "AXImage");
testRoleAndSubRole(accDoc, "polygon", "AXImage");
testRoleAndSubRole(accDoc, "polyline", "AXImage");
testRoleAndSubRole(accDoc, "path", "AXImage");
testRoleAndSubRole(accDoc, "image", "AXImage");
}
);
addAccessibleTask(
`
`,
(browser, accDoc) => {
let figure = getNativeInterface(accDoc, "figure");
ok(!figure.getAttributeValue("AXTitle"), "Figure should not have a title");
is(
figure.getAttributeValue("AXDescription"),
"Old Mozilla logo",
"Correct figure label"
);
is(figure.getAttributeValue("AXRole"), "AXGroup", "Correct figure role");
is(
figure.getAttributeValue("AXRoleDescription"),
"figure",
"Correct figure role description"
);
let img = getNativeInterface(accDoc, "img");
ok(!img.getAttributeValue("AXTitle"), "img should not have a title");
is(img.getAttributeValue("AXDescription"), "Logo", "Correct img label");
is(img.getAttributeValue("AXRole"), "AXImage", "Correct img role");
is(
img.getAttributeValue("AXRoleDescription"),
"image",
"Correct img role description"
);
let figcaption = getNativeInterface(accDoc, "figcaption");
ok(
!figcaption.getAttributeValue("AXTitle"),
"figcaption should not have a title"
);
ok(
!figcaption.getAttributeValue("AXDescription"),
"figcaption should not have a label"
);
is(
figcaption.getAttributeValue("AXRole"),
"AXGroup",
"Correct figcaption role"
);
is(
figcaption.getAttributeValue("AXRoleDescription"),
"group",
"Correct figcaption role description"
);
}
);
addAccessibleTask(``, async (browser, accDoc) => {
const webArea = accDoc.nativeInterface.QueryInterface(
Ci.nsIAccessibleMacInterface
);
is(
webArea.getAttributeValue("AXRole"),
"AXWebArea",
"web area should be an AXWebArea"
);
ok(
!webArea.attributeNames.includes("AXSubrole"),
"AXWebArea should not have a subrole"
);
let roleChanged = waitForMacEvent("AXMozRoleChanged");
await SpecialPowers.spawn(browser, [], () => {
content.document.body.setAttribute("role", "application");
});
await roleChanged;
is(
webArea.getAttributeValue("AXRole"),
"AXWebArea",
"web area should retain AXWebArea role"
);
ok(
!webArea.attributeNames.includes("AXSubrole"),
"AXWebArea should not have a subrole"
);
let rootGroup = webArea.getAttributeValue("AXChildren")[0];
is(rootGroup.getAttributeValue("AXRole"), "AXGroup");
is(rootGroup.getAttributeValue("AXSubrole"), "AXLandmarkApplication");
});