Commit ee381778 authored by Alexander Surkov's avatar Alexander Surkov Committed by Commit Bot

DumpAccTree testing: convert utf16 to utf8 in PropertyNode

Bug: 1115489
Change-Id: I4dfe7402cf80863a33bc36f48817e9b20705436c
AX-Relnotes: n/a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351954Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Alexander Surkov <asurkov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#798470}
parent ca242391
...@@ -43,21 +43,23 @@ PropertyNode PropertyNode::FromPropertyFilter( ...@@ -43,21 +43,23 @@ PropertyNode PropertyNode::FromPropertyFilter(
// Property invocation: property_str expected format is // Property invocation: property_str expected format is
// prop_name or prop_name(arg1, ... argN). // prop_name or prop_name(arg1, ... argN).
PropertyNode root; PropertyNode root;
Parse(&root, filter.property_str.begin(), filter.property_str.end()); std::string property_str = base::UTF16ToUTF8(filter.property_str);
Parse(&root, property_str.begin(), property_str.end());
PropertyNode* node = &root.parameters[0]; PropertyNode* node = &root.parameters[0];
// Expel a trailing wildcard if any. // Expel a trailing wildcard if any.
node->original_property = node->original_property =
filter.property_str.substr(0, filter.property_str.find_last_of('*')); property_str.substr(0, property_str.find_last_of('*'));
// Line indexes filter: filter_str expected format is // Line indexes filter: filter_str expected format is
// :line_num_1, ... :line_num_N, a comma separated list of line indexes // :line_num_1, ... :line_num_N, a comma separated list of line indexes
// the property should be queried for. For example, ":1,:5,:7" indicates that // the property should be queried for. For example, ":1,:5,:7" indicates that
// the property should called for objects placed on 1, 5 and 7 lines only. // the property should called for objects placed on 1, 5 and 7 lines only.
if (!filter.filter_str.empty()) { std::string filter_str = base::UTF16ToUTF8(filter.filter_str);
if (!filter_str.empty()) {
node->line_indexes = node->line_indexes =
base::SplitString(filter.filter_str, base::string16(1, ','), base::SplitString(filter_str, std::string(1, ','),
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
} }
...@@ -86,7 +88,7 @@ PropertyNode::operator bool() const { ...@@ -86,7 +88,7 @@ PropertyNode::operator bool() const {
return !name_or_value.empty(); return !name_or_value.empty();
} }
bool PropertyNode::IsMatching(const base::string16& pattern) const { bool PropertyNode::IsMatching(const std::string& pattern) const {
// Looking for exact property match. Expel a trailing whildcard from // Looking for exact property match. Expel a trailing whildcard from
// the property filter to handle filters like AXRole*. // the property filter to handle filters like AXRole*.
return name_or_value.compare(0, name_or_value.find_last_of('*'), pattern) == return name_or_value.compare(0, name_or_value.find_last_of('*'), pattern) ==
...@@ -94,11 +96,11 @@ bool PropertyNode::IsMatching(const base::string16& pattern) const { ...@@ -94,11 +96,11 @@ bool PropertyNode::IsMatching(const base::string16& pattern) const {
} }
bool PropertyNode::IsArray() const { bool PropertyNode::IsArray() const {
return name_or_value == base::ASCIIToUTF16("[]"); return name_or_value == "[]";
} }
bool PropertyNode::IsDict() const { bool PropertyNode::IsDict() const {
return name_or_value == base::ASCIIToUTF16("{}"); return name_or_value == "{}";
} }
base::Optional<int> PropertyNode::AsInt() const { base::Optional<int> PropertyNode::AsInt() const {
...@@ -111,17 +113,17 @@ base::Optional<int> PropertyNode::AsInt() const { ...@@ -111,17 +113,17 @@ base::Optional<int> PropertyNode::AsInt() const {
const PropertyNode* PropertyNode::FindKey(const char* refkey) const { const PropertyNode* PropertyNode::FindKey(const char* refkey) const {
for (const auto& param : parameters) { for (const auto& param : parameters) {
if (param.key == base::ASCIIToUTF16(refkey)) { if (param.key == refkey) {
return &param; return &param;
} }
} }
return nullptr; return nullptr;
} }
base::Optional<base::string16> PropertyNode::FindStringKey( base::Optional<std::string> PropertyNode::FindStringKey(
const char* refkey) const { const char* refkey) const {
for (const auto& param : parameters) { for (const auto& param : parameters) {
if (param.key == base::ASCIIToUTF16(refkey)) { if (param.key == refkey) {
return param.name_or_value; return param.name_or_value;
} }
} }
...@@ -130,7 +132,7 @@ base::Optional<base::string16> PropertyNode::FindStringKey( ...@@ -130,7 +132,7 @@ base::Optional<base::string16> PropertyNode::FindStringKey(
base::Optional<int> PropertyNode::FindIntKey(const char* refkey) const { base::Optional<int> PropertyNode::FindIntKey(const char* refkey) const {
for (const auto& param : parameters) { for (const auto& param : parameters) {
if (param.key == base::ASCIIToUTF16(refkey)) { if (param.key == refkey) {
return param.AsInt(); return param.AsInt();
} }
} }
...@@ -143,16 +145,16 @@ std::string PropertyNode::ToString() const { ...@@ -143,16 +145,16 @@ std::string PropertyNode::ToString() const {
if (!out.empty()) { if (!out.empty()) {
out += ','; out += ',';
} }
out += base::UTF16ToUTF8(index); out += index;
} }
if (!out.empty()) { if (!out.empty()) {
out += ';'; out += ';';
} }
if (!key.empty()) { if (!key.empty()) {
out += base::UTF16ToUTF8(key) + ": "; out += key + ": ";
} }
out += base::UTF16ToUTF8(name_or_value); out += name_or_value;
if (parameters.size()) { if (parameters.size()) {
out += '('; out += '(';
for (size_t i = 0; i < parameters.size(); i++) { for (size_t i = 0; i < parameters.size(); i++) {
...@@ -169,7 +171,7 @@ std::string PropertyNode::ToString() const { ...@@ -169,7 +171,7 @@ std::string PropertyNode::ToString() const {
// private // private
PropertyNode::PropertyNode(PropertyNode::iterator key_begin, PropertyNode::PropertyNode(PropertyNode::iterator key_begin,
PropertyNode::iterator key_end, PropertyNode::iterator key_end,
const base::string16& name_or_value) const std::string& name_or_value)
: key(key_begin, key_end), name_or_value(name_or_value) {} : key(key_begin, key_end), name_or_value(name_or_value) {}
PropertyNode::PropertyNode(PropertyNode::iterator begin, PropertyNode::PropertyNode(PropertyNode::iterator begin,
PropertyNode::iterator end) PropertyNode::iterator end)
...@@ -199,8 +201,7 @@ PropertyNode::iterator PropertyNode::Parse(PropertyNode* node, ...@@ -199,8 +201,7 @@ PropertyNode::iterator PropertyNode::Parse(PropertyNode* node,
// Subnode begins: a special case for arrays, which have [arg1, ..., argN] // Subnode begins: a special case for arrays, which have [arg1, ..., argN]
// form. // form.
if (*iter == '[') { if (*iter == '[') {
node->parameters.push_back( node->parameters.push_back(PropertyNode(key_begin, key_end, "[]"));
PropertyNode(key_begin, key_end, base::UTF8ToUTF16("[]")));
key_begin = key_end = end; key_begin = key_end = end;
begin = iter = Parse(&node->parameters.back(), ++iter, end); begin = iter = Parse(&node->parameters.back(), ++iter, end);
continue; continue;
...@@ -209,8 +210,7 @@ PropertyNode::iterator PropertyNode::Parse(PropertyNode* node, ...@@ -209,8 +210,7 @@ PropertyNode::iterator PropertyNode::Parse(PropertyNode* node,
// Subnode begins: a special case for dictionaries of {key1: value1, ..., // Subnode begins: a special case for dictionaries of {key1: value1, ...,
// key2: value2} form. // key2: value2} form.
if (*iter == '{') { if (*iter == '{') {
node->parameters.push_back( node->parameters.push_back(PropertyNode(key_begin, key_end, "{}"));
PropertyNode(key_begin, key_end, base::UTF8ToUTF16("{}")));
key_begin = key_end = end; key_begin = key_end = end;
begin = iter = Parse(&node->parameters.back(), ++iter, end); begin = iter = Parse(&node->parameters.back(), ++iter, end);
continue; continue;
...@@ -451,7 +451,7 @@ AccessibilityTreeFormatterBase::GetVersionSpecificExpectedFileSuffix() { ...@@ -451,7 +451,7 @@ AccessibilityTreeFormatterBase::GetVersionSpecificExpectedFileSuffix() {
std::vector<PropertyNode> std::vector<PropertyNode>
AccessibilityTreeFormatterBase::PropertyFilterNodesFor( AccessibilityTreeFormatterBase::PropertyFilterNodesFor(
const base::string16& line_index) const { const std::string& line_index) const {
std::vector<PropertyNode> list; std::vector<PropertyNode> list;
for (const auto& filter : property_filters_) { for (const auto& filter : property_filters_) {
PropertyNode property_node = PropertyNode::FromPropertyFilter(filter); PropertyNode property_node = PropertyNode::FromPropertyFilter(filter);
......
...@@ -48,10 +48,10 @@ class CONTENT_EXPORT PropertyNode final { ...@@ -48,10 +48,10 @@ class CONTENT_EXPORT PropertyNode final {
explicit operator bool() const; explicit operator bool() const;
// Key name in case of { key: value } dictionary. // Key name in case of { key: value } dictionary.
base::string16 key; std::string key;
// Value or a property name, for example 3 or AXLineForIndex // Value or a property name, for example 3 or AXLineForIndex
base::string16 name_or_value; std::string name_or_value;
// Parameters if it's a property, for example, it is a vector of a single // Parameters if it's a property, for example, it is a vector of a single
// value 3 in case of AXLineForIndex(3) // value 3 in case of AXLineForIndex(3)
...@@ -59,30 +59,30 @@ class CONTENT_EXPORT PropertyNode final { ...@@ -59,30 +59,30 @@ class CONTENT_EXPORT PropertyNode final {
// Used to store the origianl unparsed property including invocation // Used to store the origianl unparsed property including invocation
// parameters if any. // parameters if any.
base::string16 original_property; std::string original_property;
// The list of line indexes of accessible objects the property is allowed to // The list of line indexes of accessible objects the property is allowed to
// be called for. // be called for.
std::vector<base::string16> line_indexes; std::vector<std::string> line_indexes;
bool IsMatching(const base::string16& pattern) const; bool IsMatching(const std::string& pattern) const;
// Argument conversion methods. // Argument conversion methods.
bool IsArray() const; bool IsArray() const;
bool IsDict() const; bool IsDict() const;
base::Optional<int> AsInt() const; base::Optional<int> AsInt() const;
const PropertyNode* FindKey(const char* refkey) const; const PropertyNode* FindKey(const char* refkey) const;
base::Optional<base::string16> FindStringKey(const char* refkey) const; base::Optional<std::string> FindStringKey(const char* refkey) const;
base::Optional<int> FindIntKey(const char* key) const; base::Optional<int> FindIntKey(const char* key) const;
std::string ToString() const; std::string ToString() const;
private: private:
using iterator = base::string16::const_iterator; using iterator = std::string::const_iterator;
explicit PropertyNode(iterator key_begin, explicit PropertyNode(iterator key_begin,
iterator key_end, iterator key_end,
const base::string16&); const std::string&);
PropertyNode(iterator begin, iterator end); PropertyNode(iterator begin, iterator end);
PropertyNode(iterator key_begin, PropertyNode(iterator key_begin,
iterator key_end, iterator key_end,
...@@ -156,7 +156,7 @@ class CONTENT_EXPORT AccessibilityTreeFormatterBase ...@@ -156,7 +156,7 @@ class CONTENT_EXPORT AccessibilityTreeFormatterBase
// Returns property nodes complying to the line index filter for all // Returns property nodes complying to the line index filter for all
// allow/allow_empty property filters. // allow/allow_empty property filters.
std::vector<PropertyNode> PropertyFilterNodesFor( std::vector<PropertyNode> PropertyFilterNodesFor(
const base::string16& line_index) const; const std::string& line_index) const;
// Return true if match-all filter is present. // Return true if match-all filter is present.
bool HasMatchAllPropertyFilter() const; bool HasMatchAllPropertyFilter() const;
......
...@@ -92,10 +92,10 @@ TEST_F(AccessibilityTreeFormatterBaseTest, ParseProperty) { ...@@ -92,10 +92,10 @@ TEST_F(AccessibilityTreeFormatterBaseTest, ParseProperty) {
// Dict: FindStringKey // Dict: FindStringKey
EXPECT_EQ( EXPECT_EQ(
GetArgumentNode("Text({start: :1, dir: forward})").FindStringKey("start"), GetArgumentNode("Text({start: :1, dir: forward})").FindStringKey("start"),
base::ASCIIToUTF16(":1")); ":1");
EXPECT_EQ( EXPECT_EQ(
GetArgumentNode("Text({start: :1, dir: forward})").FindStringKey("dir"), GetArgumentNode("Text({start: :1, dir: forward})").FindStringKey("dir"),
base::ASCIIToUTF16("forward")); "forward");
EXPECT_EQ(GetArgumentNode("Text({start: :1, dir: forward})") EXPECT_EQ(GetArgumentNode("Text({start: :1, dir: forward})")
.FindStringKey("notexists"), .FindStringKey("notexists"),
base::nullopt); base::nullopt);
......
...@@ -216,9 +216,7 @@ void AccessibilityTreeFormatterMac::AddProperties( ...@@ -216,9 +216,7 @@ void AccessibilityTreeFormatterMac::AddProperties(
} }
// Otherwise dump attributes matching allow filters only. // Otherwise dump attributes matching allow filters only.
base::string16 line_index = std::string line_index = line_indexes_map.IndexBy(cocoa_node);
base::UTF8ToUTF16(line_indexes_map.IndexBy(cocoa_node));
for (const PropertyNode& property_node : PropertyFilterNodesFor(line_index)) { for (const PropertyNode& property_node : PropertyFilterNodesFor(line_index)) {
AttributeInvoker invoker(cocoa_node, line_indexes_map); AttributeInvoker invoker(cocoa_node, line_indexes_map);
OptionalNSObject value = invoker.Invoke(property_node); OptionalNSObject value = invoker.Invoke(property_node);
...@@ -226,11 +224,11 @@ void AccessibilityTreeFormatterMac::AddProperties( ...@@ -226,11 +224,11 @@ void AccessibilityTreeFormatterMac::AddProperties(
continue; continue;
} }
if (value.IsError()) { if (value.IsError()) {
dict->SetPath(base::UTF16ToUTF8(property_node.original_property), dict->SetPath(property_node.original_property,
base::Value(kFailedToParseArgsError)); base::Value(kFailedToParseArgsError));
continue; continue;
} }
dict->SetPath(base::UTF16ToUTF8(property_node.original_property), dict->SetPath(property_node.original_property,
PopulateObject(*value, line_indexes_map)); PopulateObject(*value, line_indexes_map));
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
using base::SysNSStringToUTF16; using base::SysNSStringToUTF8;
namespace content { namespace content {
namespace a11y { namespace a11y {
...@@ -99,7 +99,7 @@ OptionalNSObject AttributeInvoker::Invoke( ...@@ -99,7 +99,7 @@ OptionalNSObject AttributeInvoker::Invoke(
const PropertyNode& property_node) const { const PropertyNode& property_node) const {
// Attributes // Attributes
for (NSString* attribute : attributes) { for (NSString* attribute : attributes) {
if (property_node.IsMatching(SysNSStringToUTF16(attribute))) { if (property_node.IsMatching(SysNSStringToUTF8(attribute))) {
return OptionalNSObject::NotNullOrNotApplicable( return OptionalNSObject::NotNullOrNotApplicable(
[cocoa_node accessibilityAttributeValue:attribute]); [cocoa_node accessibilityAttributeValue:attribute]);
} }
...@@ -107,7 +107,7 @@ OptionalNSObject AttributeInvoker::Invoke( ...@@ -107,7 +107,7 @@ OptionalNSObject AttributeInvoker::Invoke(
// Parameterized attributes // Parameterized attributes
for (NSString* attribute : parameterized_attributes) { for (NSString* attribute : parameterized_attributes) {
if (property_node.IsMatching(SysNSStringToUTF16(attribute))) { if (property_node.IsMatching(SysNSStringToUTF8(attribute))) {
OptionalNSObject param = ParamByPropertyNode(property_node); OptionalNSObject param = ParamByPropertyNode(property_node);
if (param.IsNotNil()) { if (param.IsNotNil()) {
return OptionalNSObject([cocoa_node return OptionalNSObject([cocoa_node
...@@ -138,8 +138,7 @@ OptionalNSObject AttributeInvoker::ParamByPropertyNode( ...@@ -138,8 +138,7 @@ OptionalNSObject AttributeInvoker::ParamByPropertyNode(
} }
// Otherwise parse argument node value. // Otherwise parse argument node value.
std::string property_name = base::UTF16ToASCII(property_node.name_or_value); const std::string& property_name = property_node.name_or_value;
if (property_name == "AXLineForIndex" || if (property_name == "AXLineForIndex" ||
property_name == "AXTextMarkerForIndex") { // Int property_name == "AXTextMarkerForIndex") { // Int
return OptionalNSObject::NotNilOrError(PropertyNodeToInt(arg_node)); return OptionalNSObject::NotNilOrError(PropertyNodeToInt(arg_node));
...@@ -177,7 +176,7 @@ NSNumber* AttributeInvoker::PropertyNodeToInt( ...@@ -177,7 +176,7 @@ NSNumber* AttributeInvoker::PropertyNodeToInt(
// NSArray of two NSNumber. Format: [integer, integer]. // NSArray of two NSNumber. Format: [integer, integer].
NSArray* AttributeInvoker::PropertyNodeToIntArray( NSArray* AttributeInvoker::PropertyNodeToIntArray(
const PropertyNode& arraynode) const { const PropertyNode& arraynode) const {
if (arraynode.name_or_value != base::ASCIIToUTF16("[]")) { if (arraynode.name_or_value != "[]") {
INTARRAY_FAIL(arraynode, "not array") INTARRAY_FAIL(arraynode, "not array")
} }
...@@ -186,8 +185,7 @@ NSArray* AttributeInvoker::PropertyNodeToIntArray( ...@@ -186,8 +185,7 @@ NSArray* AttributeInvoker::PropertyNodeToIntArray(
for (const auto& paramnode : arraynode.parameters) { for (const auto& paramnode : arraynode.parameters) {
base::Optional<int> param = paramnode.AsInt(); base::Optional<int> param = paramnode.AsInt();
if (!param) { if (!param) {
INTARRAY_FAIL(arraynode, paramnode.name_or_value + INTARRAY_FAIL(arraynode, paramnode.name_or_value + " is not a number")
base::UTF8ToUTF16(" is not a number"))
} }
[array addObject:@(*param)]; [array addObject:@(*param)];
} }
...@@ -218,7 +216,7 @@ NSValue* AttributeInvoker::PropertyNodeToRange( ...@@ -218,7 +216,7 @@ NSValue* AttributeInvoker::PropertyNodeToRange(
gfx::NativeViewAccessible AttributeInvoker::PropertyNodeToUIElement( gfx::NativeViewAccessible AttributeInvoker::PropertyNodeToUIElement(
const PropertyNode& uielement_node) const { const PropertyNode& uielement_node) const {
gfx::NativeViewAccessible uielement = gfx::NativeViewAccessible uielement =
line_indexes_map.NodeBy(base::UTF16ToUTF8(uielement_node.name_or_value)); line_indexes_map.NodeBy(uielement_node.name_or_value);
if (!uielement) { if (!uielement) {
UIELEMENT_FAIL(uielement_node, UIELEMENT_FAIL(uielement_node,
"no corresponding UIElement was found in the tree") "no corresponding UIElement was found in the tree")
...@@ -234,8 +232,8 @@ id AttributeInvoker::DictNodeToTextMarker(const PropertyNode& dictnode) const { ...@@ -234,8 +232,8 @@ id AttributeInvoker::DictNodeToTextMarker(const PropertyNode& dictnode) const {
TEXTMARKER_FAIL(dictnode, "wrong number of dictionary elements") TEXTMARKER_FAIL(dictnode, "wrong number of dictionary elements")
} }
BrowserAccessibilityCocoa* anchor_cocoa = line_indexes_map.NodeBy( BrowserAccessibilityCocoa* anchor_cocoa =
base::UTF16ToUTF8(dictnode.parameters[0].name_or_value)); line_indexes_map.NodeBy(dictnode.parameters[0].name_or_value);
if (!anchor_cocoa) { if (!anchor_cocoa) {
TEXTMARKER_FAIL(dictnode, "1st argument: wrong anchor") TEXTMARKER_FAIL(dictnode, "1st argument: wrong anchor")
} }
...@@ -246,12 +244,12 @@ id AttributeInvoker::DictNodeToTextMarker(const PropertyNode& dictnode) const { ...@@ -246,12 +244,12 @@ id AttributeInvoker::DictNodeToTextMarker(const PropertyNode& dictnode) const {
} }
ax::mojom::TextAffinity affinity; ax::mojom::TextAffinity affinity;
const base::string16& affinity_str = dictnode.parameters[2].name_or_value; const std::string& affinity_str = dictnode.parameters[2].name_or_value;
if (affinity_str == base::UTF8ToUTF16("none")) { if (affinity_str == "none") {
affinity = ax::mojom::TextAffinity::kNone; affinity = ax::mojom::TextAffinity::kNone;
} else if (affinity_str == base::UTF8ToUTF16("down")) { } else if (affinity_str == "down") {
affinity = ax::mojom::TextAffinity::kDownstream; affinity = ax::mojom::TextAffinity::kDownstream;
} else if (affinity_str == base::UTF8ToUTF16("up")) { } else if (affinity_str == "up") {
affinity = ax::mojom::TextAffinity::kUpstream; affinity = ax::mojom::TextAffinity::kUpstream;
} else { } else {
TEXTMARKER_FAIL(dictnode, "3rd argument: wrong affinity") TEXTMARKER_FAIL(dictnode, "3rd argument: wrong affinity")
......
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