Commit 127d198f authored by Alexander Surkov's avatar Alexander Surkov Committed by Commit Bot

DumpAccTree testing: support UIElement parameters

Bug: 1095619
Change-Id: Ia66fb236b6d1f4d365d8a878066832058ec7ab9f
AX-Relnotes: n/a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2257261Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Alexander Surkov <asurkov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#781581}
parent a48cefd8
......@@ -109,10 +109,14 @@ class AccessibilityTreeFormatterMac : public AccessibilityTreeFormatterBase {
bool error;
};
IdOrError ParamByPropertyNode(const PropertyNode&) const;
IdOrError ParamByPropertyNode(const PropertyNode&,
const LineIndexesMap&) const;
NSNumber* PropertyNodeToInt(const PropertyNode&) const;
NSArray* PropertyNodeToIntArray(const PropertyNode&) const;
NSValue* PropertyNodeToRange(const PropertyNode&) const;
gfx::NativeViewAccessible PropertyNodeToUIElement(
const PropertyNode&,
const LineIndexesMap&) const;
base::Value PopulateSize(const BrowserAccessibilityCocoa*) const;
base::Value PopulatePosition(const BrowserAccessibilityCocoa*) const;
......@@ -266,7 +270,7 @@ void AccessibilityTreeFormatterMac::AddProperties(
[cocoa_node accessibilityParameterizedAttributeNames]) {
auto propnode = GetMatchingPropertyNode(
line_index, SysNSStringToUTF16(supportedAttribute));
IdOrError param = ParamByPropertyNode(propnode);
IdOrError param = ParamByPropertyNode(propnode, line_indexes_map);
if (param.IsError()) {
dict->SetPath(base::UTF16ToUTF8(propnode.original_property),
base::Value(kFailedToParseArgsError));
......@@ -288,7 +292,8 @@ void AccessibilityTreeFormatterMac::AddProperties(
AccessibilityTreeFormatterMac::IdOrError
AccessibilityTreeFormatterMac::ParamByPropertyNode(
const PropertyNode& property_node) const {
const PropertyNode& property_node,
const LineIndexesMap& line_indexes_map) const {
IdOrError param;
std::string property_name = base::UTF16ToASCII(property_node.name_or_value);
......@@ -298,6 +303,8 @@ AccessibilityTreeFormatterMac::ParamByPropertyNode(
param = PropertyNodeToIntArray(property_node);
} else if (property_name == "AXStringForRange") { // NSRange
param = PropertyNodeToRange(property_node);
} else if (property_name == "AXIndexForChildUIElement") { // UIElement
param = PropertyNodeToUIElement(property_node, line_indexes_map);
}
return param;
......@@ -389,6 +396,32 @@ NSValue* AccessibilityTreeFormatterMac::PropertyNodeToRange(
return [NSValue valueWithRange:NSMakeRange(*loc, *len)];
}
// UIElement. Format: :line_num.
gfx::NativeViewAccessible
AccessibilityTreeFormatterMac::PropertyNodeToUIElement(
const PropertyNode& propnode,
const LineIndexesMap& line_indexes_map) const {
if (propnode.parameters.size() != 1) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to UIElement: single argument is expected";
return nil;
}
const auto& uielnode = propnode.parameters[0];
base::string16 line_index = uielnode.name_or_value;
for (std::pair<const gfx::NativeViewAccessible, base::string16> item :
line_indexes_map) {
if (item.second == line_index) {
return item.first;
}
}
LOG(ERROR)
<< "Failed to parse " << propnode.original_property
<< " to UIElement: no corresponding UIElement was found in the tree";
return nil;
}
base::Value AccessibilityTreeFormatterMac::PopulateSize(
const BrowserAccessibilityCocoa* cocoa_node) const {
base::Value size(base::Value::Type::DICTIONARY);
......
......@@ -211,4 +211,24 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
)~~");
}
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_UIElement) {
TestAndCheck(R"~~(data:text/html,
<p contentEditable='true'>Text</p>)~~",
{":2;AXIndexForChildUIElement(:3)=*"}, R"~~(AXWebArea
++AXTextArea AXIndexForChildUIElement(:3)=0 AXValue='Text'
++++AXStaticText AXValue='Text'
)~~");
}
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_UIElement_WrongArgs) {
TestAndCheck(R"~~(data:text/html,
<p contentEditable='true'>Text</p>)~~",
{":2;AXIndexForChildUIElement(:4)=*"}, R"~~(AXWebArea
++AXTextArea AXIndexForChildUIElement(:4)=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text'
++++AXStaticText AXValue='Text'
)~~");
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment