Commit 309e2514 authored by Alexander Surkov's avatar Alexander Surkov Committed by Commit Bot

DumpAccTree mac: support integer parameters for parameterized attributes

Bug: 1094350
Change-Id: Id0f2d6318e5f34d9278a766d5f5cde736b16abd9
AX-Relnotes: n/a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2243259
Commit-Queue: Alexander Surkov <asurkov@igalia.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779983}
parent 19f51b35
...@@ -44,36 +44,7 @@ const char kRangeLenDictAttr[] = "len"; ...@@ -44,36 +44,7 @@ const char kRangeLenDictAttr[] = "len";
const char kSetKeyPrefixDictAttr[] = "_setkey_"; const char kSetKeyPrefixDictAttr[] = "_setkey_";
const char kConstValuePrefix[] = "_const_"; const char kConstValuePrefix[] = "_const_";
const char kNULLValue[] = "_const_NULL"; const char kNULLValue[] = "_const_NULL";
const char kFailedToParseArgsError[] = "_const_ERROR:FAILED_TO_PARSE_ARGS";
NSArray* PropertyNodeToIntArray(const PropertyNode& propnode) {
if (propnode.parameters.size() != 1) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to IntArray: single argument is expected";
return nil;
}
const auto& arraynode = propnode.parameters[0];
if (arraynode.name_or_value != base::ASCIIToUTF16("[]")) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to IntArray: " << arraynode.name_or_value
<< " is not array";
return nil;
}
NSMutableArray* array =
[[NSMutableArray alloc] initWithCapacity:arraynode.parameters.size()];
for (const auto& paramnode : arraynode.parameters) {
int param = 0;
if (!base::StringToInt(paramnode.name_or_value, &param)) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to IntArray: " << paramnode.name_or_value
<< " is not a number";
return nil;
}
[array addObject:@(param)];
}
return array;
}
} // namespace } // namespace
...@@ -139,6 +110,8 @@ class AccessibilityTreeFormatterMac : public AccessibilityTreeFormatterBase { ...@@ -139,6 +110,8 @@ class AccessibilityTreeFormatterMac : public AccessibilityTreeFormatterBase {
}; };
IdOrError ParamByPropertyNode(const PropertyNode&) const; IdOrError ParamByPropertyNode(const PropertyNode&) const;
NSNumber* PropertyNodeToInt(const PropertyNode&) const;
NSArray* PropertyNodeToIntArray(const PropertyNode&) const;
base::Value PopulateSize(const BrowserAccessibilityCocoa*) const; base::Value PopulateSize(const BrowserAccessibilityCocoa*) const;
base::Value PopulatePosition(const BrowserAccessibilityCocoa*) const; base::Value PopulatePosition(const BrowserAccessibilityCocoa*) const;
...@@ -295,7 +268,7 @@ void AccessibilityTreeFormatterMac::AddProperties( ...@@ -295,7 +268,7 @@ void AccessibilityTreeFormatterMac::AddProperties(
IdOrError param = ParamByPropertyNode(propnode); IdOrError param = ParamByPropertyNode(propnode);
if (param.IsError()) { if (param.IsError()) {
dict->SetPath(base::UTF16ToUTF8(propnode.original_property), dict->SetPath(base::UTF16ToUTF8(propnode.original_property),
base::Value("ERROR:FAILED_TO_PARSE_ARGS")); base::Value(kFailedToParseArgsError));
continue; continue;
} }
...@@ -317,12 +290,65 @@ AccessibilityTreeFormatterMac::ParamByPropertyNode( ...@@ -317,12 +290,65 @@ AccessibilityTreeFormatterMac::ParamByPropertyNode(
const PropertyNode& property_node) const { const PropertyNode& property_node) const {
IdOrError param; IdOrError param;
std::string property_name = base::UTF16ToASCII(property_node.name_or_value); std::string property_name = base::UTF16ToASCII(property_node.name_or_value);
if (property_name == "AXCellForColumnAndRow") {
if (property_name == "AXLineForIndex") { // Int
param = PropertyNodeToInt(property_node);
} else if (property_name == "AXCellForColumnAndRow") { // IntArray
param = PropertyNodeToIntArray(property_node); param = PropertyNodeToIntArray(property_node);
} }
return param; return param;
} }
NSNumber* AccessibilityTreeFormatterMac::PropertyNodeToInt(
const PropertyNode& propnode) const {
if (propnode.parameters.size() != 1) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to Int: single argument is expected";
return nil;
}
int param = 0;
const auto& intnode = propnode.parameters[0];
if (!base::StringToInt(intnode.name_or_value, &param)) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to Int: " << intnode.name_or_value << " is not a number";
return nil;
}
return [NSNumber numberWithInt:param];
}
NSArray* AccessibilityTreeFormatterMac::PropertyNodeToIntArray(
const PropertyNode& propnode) const {
if (propnode.parameters.size() != 1) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to IntArray: single argument is expected";
return nil;
}
const auto& arraynode = propnode.parameters[0];
if (arraynode.name_or_value != base::ASCIIToUTF16("[]")) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to IntArray: " << arraynode.name_or_value
<< " is not array";
return nil;
}
NSMutableArray* array =
[[NSMutableArray alloc] initWithCapacity:arraynode.parameters.size()];
for (const auto& paramnode : arraynode.parameters) {
int param = 0;
if (!base::StringToInt(paramnode.name_or_value, &param)) {
LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to IntArray: " << paramnode.name_or_value
<< " is not a number";
return nil;
}
[array addObject:@(param)];
}
return array;
}
base::Value AccessibilityTreeFormatterMac::PopulateSize( base::Value AccessibilityTreeFormatterMac::PopulateSize(
const BrowserAccessibilityCocoa* cocoa_node) const { const BrowserAccessibilityCocoa* cocoa_node) const {
base::Value size(base::Value::Type::DICTIONARY); base::Value size(base::Value::Type::DICTIONARY);
......
...@@ -130,7 +130,27 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -130,7 +130,27 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes) { ParameterizedAttributes_Int) {
TestAndCheck(R"~~(data:text/html,
<p contentEditable='true'>Text</p>)~~",
{":2;AXLineForIndex(0)=*"}, R"~~(AXWebArea
++AXTextArea AXLineForIndex(0)=0 AXValue='Text'
++++AXStaticText AXValue='Text'
)~~");
}
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_Int_WrongArgs) {
TestAndCheck(R"~~(data:text/html,
<p contentEditable='true'>Text</p>)~~",
{":2;AXLineForIndex(NaN)=*"}, R"~~(AXWebArea
++AXTextArea AXLineForIndex(NaN)=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text'
++++AXStaticText AXValue='Text'
)~~");
}
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_IntArray) {
TestAndCheck(R"~~(data:text/html, TestAndCheck(R"~~(data:text/html,
<table role="grid"><tr><td>CELL</td></tr></table>)~~", <table role="grid"><tr><td>CELL</td></tr></table>)~~",
{"AXCellForColumnAndRow([0, 0])=*"}, R"~~(AXWebArea {"AXCellForColumnAndRow([0, 0])=*"}, R"~~(AXWebArea
...@@ -146,11 +166,11 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -146,11 +166,11 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_WrongArgs) { ParameterizedAttributes_IntArray_WrongArgs) {
TestAndCheck(R"~~(data:text/html, TestAndCheck(R"~~(data:text/html,
<table role="grid"><tr><td>CELL</td></tr></table>)~~", <table role="grid"><tr><td>CELL</td></tr></table>)~~",
{"AXCellForColumnAndRow(0, 0)=*"}, R"~~(AXWebArea {"AXCellForColumnAndRow(0, 0)=*"}, R"~~(AXWebArea
++AXTable AXCellForColumnAndRow(0, 0)='ERROR:FAILED_TO_PARSE_ARGS' ++AXTable AXCellForColumnAndRow(0, 0)=ERROR:FAILED_TO_PARSE_ARGS
++++AXRow ++++AXRow
++++++AXCell ++++++AXCell
++++++++AXStaticText AXValue='CELL' ++++++++AXStaticText AXValue='CELL'
...@@ -162,7 +182,7 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -162,7 +182,7 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_NilValue) { ParameterizedAttributes_IntArray_NilValue) {
TestAndCheck(R"~~(data:text/html, TestAndCheck(R"~~(data:text/html,
<table role="grid"></table>)~~", <table role="grid"></table>)~~",
{"AXCellForColumnAndRow([0, 0])=*"}, R"~~(AXWebArea {"AXCellForColumnAndRow([0, 0])=*"}, R"~~(AXWebArea
......
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