Bug 1990785: Verify text attributes exist before adding to them r=Jamie, a=RyanVM DONTBUILD

Differential Revision: https://phabricator.services.mozilla.com/D266937
This commit is contained in:
Morgan Rae Reschenberg
2025-10-01 17:48:11 +00:00
committed by rvandermeulen@mozilla.com
parent 7253f21762
commit 48ff0757ca
2 changed files with 39 additions and 0 deletions

View File

@@ -429,6 +429,13 @@ static void AppendTextToAttributedString(
static RefPtr<AccAttributes> GetTextAttributes(TextLeafPoint aPoint) { static RefPtr<AccAttributes> GetTextAttributes(TextLeafPoint aPoint) {
RefPtr<AccAttributes> attrs = aPoint.GetTextAttributes(); RefPtr<AccAttributes> attrs = aPoint.GetTextAttributes();
if (!attrs) {
// If we can't fetch text attributes for the given point, return null.
// We avoid creating a new AccAttributes here because our AttributedText()
// code below relies on this null return value to indicate we're dealing
// with a non-text control.
return nullptr;
}
// Mac expects some object properties to be exposed as text attributes. We // Mac expects some object properties to be exposed as text attributes. We
// add these here rather than in utils::StringAttributesFromAccAttributes so // add these here rather than in utils::StringAttributesFromAccAttributes so
// we can use AccAttributes::Equal to determine whether we need to start a new // we can use AccAttributes::Equal to determine whether we need to start a new

View File

@@ -276,3 +276,35 @@ addAccessibleTask(
ok(!attributedText[2].AXHighlight); ok(!attributedText[2].AXHighlight);
} }
); );
// Test the <mark> element, in conjunction with content that will
// prevent the creation of a text attributes object.
addAccessibleTask(
`<mark>a<button></button>b</mark>`,
async function testMarkNoAttributes(browser, accDoc) {
const macDoc = accDoc.nativeInterface.QueryInterface(
Ci.nsIAccessibleMacInterface
);
const range = macDoc.getParameterizedAttributeValue(
"AXTextMarkerRangeForUnorderedTextMarkers",
[
macDoc.getAttributeValue("AXStartTextMarker"),
macDoc.getAttributeValue("AXEndTextMarker"),
]
);
const attributedText = macDoc.getParameterizedAttributeValue(
"AXAttributedStringForTextMarkerRange",
range
);
ok(attributedText, "Document has attributed text");
is(attributedText.length, 3, "3 pieces of attributed text exist");
ok(attributedText[0].AXHighlight, "0th pos text has highlight");
is(attributedText[0].string, "a", "0th pos text is string `a`");
ok(!attributedText[1].AXHighlight, "1st pos text has no highlight");
ok(attributedText[2].AXHighlight, "2nd pos text has highlight");
is(attributedText[2].string, "b", "2nd pos text is string `b`");
}
);