diff --git a/accessible/mac/GeckoTextMarker.mm b/accessible/mac/GeckoTextMarker.mm index 8d89384cf847..39c2a3018631 100644 --- a/accessible/mac/GeckoTextMarker.mm +++ b/accessible/mac/GeckoTextMarker.mm @@ -429,6 +429,13 @@ static void AppendTextToAttributedString( static RefPtr GetTextAttributes(TextLeafPoint aPoint) { RefPtr 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 // add these here rather than in utils::StringAttributesFromAccAttributes so // we can use AccAttributes::Equal to determine whether we need to start a new diff --git a/accessible/tests/browser/mac/browser_attributed_text.js b/accessible/tests/browser/mac/browser_attributed_text.js index 02a8d29f4fdd..eaa5d3fd66b6 100644 --- a/accessible/tests/browser/mac/browser_attributed_text.js +++ b/accessible/tests/browser/mac/browser_attributed_text.js @@ -276,3 +276,35 @@ addAccessibleTask( ok(!attributedText[2].AXHighlight); } ); + +// Test the element, in conjunction with content that will +// prevent the creation of a text attributes object. +addAccessibleTask( + `ab`, + 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`"); + } +);