Bug 1833079: When notified about a dom::ElementState::INVALID change, let AccStateChangeEvent calculate whether the state is enabled. r=morgan

Previously, we passed true for aIsEnabled, indicating that the state was only ever enabled, never disabled.
We could get the actual enabled value here using dom::ElementState::HasState(), but that wouldn't take aria-invalid into account if present.
Instead, we let AccStateChangeEvent calculate it by calling Accessible::State().

Differential Revision: https://phabricator.services.mozilla.com/D178039
This commit is contained in:
James Teh 2023-05-17 03:36:10 +00:00
parent 8671fdb578
commit 6c26a79a58
2 changed files with 31 additions and 1 deletions

View File

@ -987,7 +987,7 @@ void DocAccessible::ElementStateChanged(dom::Document* aDocument,
if (aStateMask.HasState(dom::ElementState::INVALID)) {
RefPtr<AccEvent> event =
new AccStateChangeEvent(accessible, states::INVALID, true);
new AccStateChangeEvent(accessible, states::INVALID);
FireDelayedEvent(event);
}

View File

@ -452,3 +452,33 @@ addAccessibleTask(
},
{ topLevel: true, iframe: true, remoteIframe: true, chrome: true }
);
/**
* Test invalid state determined via DOM.
*/
addAccessibleTask(
`<input type="email" id="email">`,
async function(browser, docAcc) {
const email = findAccessibleChildByID(docAcc, "email");
info("Focusing email");
let focused = waitForEvent(EVENT_FOCUS, email);
email.takeFocus();
await focused;
info("Typing a");
let invalidChanged = waitForStateChange(email, STATE_INVALID, true);
EventUtils.sendString("a");
await invalidChanged;
testStates(email, STATE_INVALID);
info("Typing @b");
invalidChanged = waitForStateChange(email, STATE_INVALID, false);
EventUtils.sendString("@b");
await invalidChanged;
testStates(email, 0, 0, STATE_INVALID);
info("Typing backspace");
invalidChanged = waitForStateChange(email, STATE_INVALID, true);
EventUtils.synthesizeKey("KEY_Backspace");
await invalidChanged;
testStates(email, STATE_INVALID);
},
{ chrome: true, topLevel: true, remoteIframe: true }
);