Bug 1841216: Fire a11y description change event when aria-description is changed. r=nlapre

Differential Revision: https://phabricator.services.mozilla.com/D182544
This commit is contained in:
James Teh 2023-07-06 01:32:56 +00:00
parent 0266d92dba
commit e343609eb8
2 changed files with 38 additions and 0 deletions

View File

@ -1340,6 +1340,17 @@ void LocalAccessible::DOMAttributeChanged(int32_t aNameSpaceID,
return;
}
if (aAttribute == nsGkAtoms::aria_description) {
// A valid aria-describedby would take precedence so an aria-description
// change won't change the description.
IDRefsIterator iter(mDoc, elm, nsGkAtoms::aria_describedby);
if (!iter.NextElem()) {
mDoc->FireDelayedEvent(nsIAccessibleEvent::EVENT_DESCRIPTION_CHANGE,
this);
}
return;
}
if (aAttribute == nsGkAtoms::aria_describedby) {
mDoc->QueueCacheUpdate(this, CacheDomain::Relations);
mDoc->FireDelayedEvent(nsIAccessibleEvent::EVENT_DESCRIPTION_CHANGE, this);

View File

@ -251,3 +251,30 @@ addAccessibleTask(
},
{ chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);
/**
* Test aria-description, including mutations.
*/
addAccessibleTask(
`<button id="button" aria-description="a">button</button>`,
async function (browser, docAcc) {
const button = findAccessibleChildByID(docAcc, "button");
testDescr(button, "a");
info("Changing aria-description");
let changed = waitForEvent(EVENT_DESCRIPTION_CHANGE, button);
await invokeSetAttribute(browser, "button", "aria-description", "b");
await changed;
testDescr(button, "b");
info("Removing aria-description");
changed = waitForEvent(EVENT_DESCRIPTION_CHANGE, button);
await invokeSetAttribute(browser, "button", "aria-description");
await changed;
testDescr(button, "");
info("Setting aria-description");
changed = waitForEvent(EVENT_DESCRIPTION_CHANGE, button);
await invokeSetAttribute(browser, "button", "aria-description", "c");
await changed;
testDescr(button, "c");
},
{ chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);