Bug 1742915 part 2: Cache the tag attribute. r=morgan

Differential Revision: https://phabricator.services.mozilla.com/D132653
This commit is contained in:
James Teh 2021-12-07 03:37:03 +00:00
parent 6309a094fe
commit e649b5b5cd
3 changed files with 47 additions and 1 deletions

View File

@ -3256,6 +3256,14 @@ already_AddRefed<AccAttributes> LocalAccessible::BundleFieldsForCache(
fields->SetAttribute(nsGkAtoms::state, state);
}
if (aUpdateType == CacheUpdateType::Initial) {
// Add fields which never change and thus only need to be included in the
// initial cache push.
if (mContent->IsElement()) {
fields->SetAttribute(nsGkAtoms::tag, mContent->NodeInfo()->NameAtom());
}
}
return fields.forget();
}

View File

@ -470,6 +470,14 @@ uint64_t RemoteAccessibleBase<Derived>::State() {
template <class Derived>
already_AddRefed<AccAttributes> RemoteAccessibleBase<Derived>::Attributes() {
RefPtr<AccAttributes> attributes = new AccAttributes();
if (mCachedFields) {
// We use GetAttribute instead of GetAttributeRefPtr because we need
// nsAtom, not const nsAtom.
if (auto tag =
mCachedFields->GetAttribute<RefPtr<nsAtom>>(nsGkAtoms::tag)) {
attributes->SetAttribute(nsGkAtoms::tag, *tag);
}
}
return attributes.forget();
}

View File

@ -7,6 +7,11 @@
/* import-globals-from ../../mochitest/attributes.js */
loadScripts({ name: "attributes.js", dir: MOCHITESTS_DIR });
const isCacheEnabled = Services.prefs.getBoolPref(
"accessibility.cache.enabled",
false
);
/**
* Default textbox accessible attributes.
*/
@ -130,5 +135,30 @@ addAccessibleTask(
testAbsentAttrs(textbox, unexpected);
}
},
{ iframe: true, remoteIframe: true }
{
// These tests don't work yet with the parent process cache enabled.
topLevel: !isCacheEnabled,
iframe: !isCacheEnabled,
remoteIframe: !isCacheEnabled,
}
);
/**
* Test caching of the tag attribute.
*/
addAccessibleTask(
`
<p id="p">text</p>
<textarea id="textarea"></textarea>
`,
async function(browser, docAcc) {
testAttrs(docAcc, { tag: "body" }, true);
const p = findAccessibleChildByID(docAcc, "p");
testAttrs(p, { tag: "p" }, true);
const textLeaf = p.firstChild;
testAbsentAttrs(textLeaf, { tag: "" });
const textarea = findAccessibleChildByID(docAcc, "textarea");
testAttrs(textarea, { tag: "textarea" }, true);
},
{ chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);