Bug 1800060: Avoid computing LINKS_TO for links with no anchor r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D161826
This commit is contained in:
Morgan Rae Reschenberg 2022-11-11 00:03:29 +00:00
Родитель 19483cce77
Коммит 1d82cef271
2 изменённых файлов: 26 добавлений и 14 удалений

Просмотреть файл

@ -695,18 +695,10 @@ Relation RemoteAccessibleBase<Derived>::RelationByType(
Pivot p = Pivot(mDoc);
nsString href;
Value(href);
if (!href.IsEmpty()) {
// `Value` will give us the entire URL, we're only interested in the ID
// after the hash. Split that part out.
for (auto s : href.Split('#')) {
href = s;
}
if (href.IsEmpty()) {
// This can happen if we encounter a link with an empty anchor:
// ie. <a href="#">hi</a>
return Relation();
}
int32_t i = href.FindChar('#');
int32_t len = static_cast<int32_t>(href.Length());
if (i != -1 && i < (len - 1)) {
nsDependentSubstring anchorName = Substring(href, i + 1, len);
MustPruneSameDocRule rule;
Accessible* nameMatch = nullptr;
for (Accessible* match = p.Next(mDoc, rule); match;
@ -714,12 +706,12 @@ Relation RemoteAccessibleBase<Derived>::RelationByType(
nsString currID;
match->DOMNodeID(currID);
MOZ_ASSERT(match->IsRemote());
if (href.Equals(currID)) {
if (anchorName.Equals(currID)) {
return Relation(match->AsRemote());
}
if (!nameMatch) {
nsString currName = match->AsRemote()->GetCachedHTMLNameAttribute();
if (match->TagName() == nsGkAtoms::a && href.Equals(currName)) {
if (match->TagName() == nsGkAtoms::a && anchorName.Equals(currName)) {
// If we find an element with a matching ID, we should return
// that, but if we don't we should return the first anchor with
// a matching name. To avoid doing two traversals, store the first

Просмотреть файл

@ -81,3 +81,23 @@ addAccessibleTask(
remoteIframe: true,
}
);
/*
* Test LINKS_TO relation caching an anchor with multiple hashes
*/
addAccessibleTask(
`
<a id="link" href="#foo#bar">Origin</a><br>
<a id="anchor" name="foo#bar">Destination`,
async function(browser, accDoc) {
const link = findAccessibleChildByID(accDoc, "link");
const anchor = findAccessibleChildByID(accDoc, "anchor");
await testCachedRelation(link, RELATION_LINKS_TO, anchor);
},
{
chrome: true,
iframe: true,
remoteIframe: true,
}
);