Commit 927783f5 authored by Alexander Surkov's avatar Alexander Surkov Committed by Commit Bot

DumpAccTree testsuite: utf16 to utf8 conversion, get rid of utf16 version of...

DumpAccTree testsuite: utf16 to utf8 conversion, get rid of utf16 version of AccessibilityTreeFormatterBase::WriteAttribute

Bug: 1115489
Change-Id: Ieeb4bcda323cdcc27e6a645ac3ab9742dc6e41f4
AX-Relnotes: n/a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364018Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Alexander Surkov <asurkov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#803088}
parent ddb1d689
......@@ -279,10 +279,10 @@ base::string16 AccessibilityTreeFormatterAndroid::ProcessTreeForOutput(
if (show_ids()) {
int id_value;
dict.GetInteger("id", &id_value);
WriteAttribute(true, base::NumberToString16(id_value), &line);
WriteAttribute(true, base::NumberToString(id_value), &line);
}
base::string16 class_value;
std::string class_value;
dict.GetString("class", &class_value);
WriteAttribute(true, class_value, &line);
......
......@@ -498,7 +498,7 @@ bool AccessibilityTreeFormatterBase::MatchesNodeFilters(
return AccessibilityTreeFormatter::MatchesNodeFilters(node_filters_, dict);
}
base::string16 AccessibilityTreeFormatterBase::FormatCoordinates(
std::string AccessibilityTreeFormatterBase::FormatCoordinates(
const base::DictionaryValue& value,
const std::string& name,
const std::string& x_name,
......@@ -506,12 +506,10 @@ base::string16 AccessibilityTreeFormatterBase::FormatCoordinates(
int x, y;
value.GetInteger(x_name, &x);
value.GetInteger(y_name, &y);
std::string xy_str(base::StringPrintf("%s=(%d, %d)", name.c_str(), x, y));
return base::UTF8ToUTF16(xy_str);
return base::StringPrintf("%s=(%d, %d)", name.c_str(), x, y);
}
base::string16 AccessibilityTreeFormatterBase::FormatRectangle(
std::string AccessibilityTreeFormatterBase::FormatRectangle(
const base::DictionaryValue& value,
const std::string& name,
const std::string& left_name,
......@@ -523,28 +521,20 @@ base::string16 AccessibilityTreeFormatterBase::FormatRectangle(
value.GetInteger(top_name, &top);
value.GetInteger(width_name, &width);
value.GetInteger(height_name, &height);
std::string rect_str(base::StringPrintf("%s=(%d, %d, %d, %d)", name.c_str(),
left, top, width, height));
return base::UTF8ToUTF16(rect_str);
return base::StringPrintf("%s=(%d, %d, %d, %d)", name.c_str(), left, top,
width, height);
}
bool AccessibilityTreeFormatterBase::WriteAttribute(bool include_by_default,
const std::string& attr,
base::string16* line) {
return WriteAttribute(include_by_default, base::UTF8ToUTF16(attr), line);
}
bool AccessibilityTreeFormatterBase::WriteAttribute(bool include_by_default,
const base::string16& attr,
base::string16* line) {
if (attr.empty())
return false;
if (!MatchesPropertyFilters(base::UTF16ToUTF8(attr), include_by_default))
if (!MatchesPropertyFilters(attr, include_by_default))
return false;
if (!line->empty())
*line += base::ASCIIToUTF16(" ");
*line += attr;
*line += base::UTF8ToUTF16(attr);
return true;
}
......
......@@ -176,24 +176,21 @@ class CONTENT_EXPORT AccessibilityTreeFormatterBase
// Utility functions to be used by each platform.
//
base::string16 FormatCoordinates(const base::DictionaryValue& value,
const std::string& name,
const std::string& x_name,
const std::string& y_name);
base::string16 FormatRectangle(const base::DictionaryValue& value,
const std::string& name,
const std::string& left_name,
const std::string& top_name,
const std::string& width_name,
const std::string& height_name);
std::string FormatCoordinates(const base::DictionaryValue& value,
const std::string& name,
const std::string& x_name,
const std::string& y_name);
std::string FormatRectangle(const base::DictionaryValue& value,
const std::string& name,
const std::string& left_name,
const std::string& top_name,
const std::string& width_name,
const std::string& height_name);
// Writes the given attribute string out to |line| if it matches the property
// filters.
// Returns false if the attribute was filtered out.
bool WriteAttribute(bool include_by_default,
const base::string16& attr,
base::string16* line);
bool WriteAttribute(bool include_by_default,
const std::string& attr,
base::string16* line);
......
......@@ -425,10 +425,10 @@ base::string16 AccessibilityTreeFormatterBlink::ProcessTreeForOutput(
if (show_ids()) {
int id_value;
dict.GetInteger("id", &id_value);
WriteAttribute(true, base::NumberToString16(id_value), &line);
WriteAttribute(true, base::NumberToString(id_value), &line);
}
base::string16 role_value;
std::string role_value;
dict.GetString("internalRole", &role_value);
WriteAttribute(true, role_value, &line);
......
......@@ -1031,7 +1031,7 @@ base::string16 AccessibilityTreeFormatterUia::ProcessTreeForOutput(
base::string16 line;
// Always show control type, and show it first.
base::string16 control_type_value;
std::string control_type_value;
dict.GetString(UiaIdentifierToCondensedString(UIA_ControlTypePropertyId),
&control_type_value);
WriteAttribute(true, control_type_value, &line);
......@@ -1103,12 +1103,11 @@ void AccessibilityTreeFormatterUia::ProcessValueForOutput(
base::DictionaryValue* filtered_result) {
switch (value->type()) {
case base::Value::Type::STRING: {
base::string16 string_value;
std::string string_value;
value->GetAsString(&string_value);
bool did_pass_filters = WriteAttribute(
false,
base::StringPrintf(L"%ls='%ls'", base::UTF8ToUTF16(name).c_str(),
string_value.c_str()),
base::StringPrintf("%s='%s'", name.c_str(), string_value.c_str()),
&line);
if (filtered_result && did_pass_filters)
filtered_result->SetString(name, string_value);
......@@ -1117,11 +1116,11 @@ void AccessibilityTreeFormatterUia::ProcessValueForOutput(
case base::Value::Type::BOOLEAN: {
bool bool_value = 0;
value->GetAsBoolean(&bool_value);
bool did_pass_filters = WriteAttribute(
false,
base::StringPrintf(L"%ls=%ls", base::UTF8ToUTF16(name).c_str(),
(bool_value ? L"true" : L"false")),
&line);
bool did_pass_filters =
WriteAttribute(false,
base::StringPrintf("%s=%s", name.c_str(),
(bool_value ? "true" : "false")),
&line);
if (filtered_result && did_pass_filters)
filtered_result->SetBoolean(name, bool_value);
break;
......@@ -1130,10 +1129,7 @@ void AccessibilityTreeFormatterUia::ProcessValueForOutput(
int int_value = 0;
value->GetAsInteger(&int_value);
bool did_pass_filters = WriteAttribute(
false,
base::StringPrintf(L"%ls=%d", base::UTF8ToUTF16(name).c_str(),
int_value),
&line);
false, base::StringPrintf("%s=%d", name.c_str(), int_value), &line);
if (filtered_result && did_pass_filters)
filtered_result->SetInteger(name, int_value);
break;
......@@ -1142,9 +1138,7 @@ void AccessibilityTreeFormatterUia::ProcessValueForOutput(
double double_value = 0.0;
value->GetAsDouble(&double_value);
bool did_pass_filters = WriteAttribute(
false,
base::StringPrintf(L"%ls=%.2f", base::UTF8ToUTF16(name).c_str(),
double_value),
false, base::StringPrintf("%s=%.2f", name.c_str(), double_value),
&line);
if (filtered_result && did_pass_filters)
filtered_result->SetDouble(name, double_value);
......
......@@ -919,7 +919,7 @@ base::string16 AccessibilityTreeFormatterWin::ProcessTreeForOutput(
base::string16 line;
// Always show role, and show it first.
base::string16 role_value;
std::string role_value;
dict.GetString("role", &role_value);
WriteAttribute(true, role_value, &line);
if (filtered_dict_result)
......@@ -932,13 +932,11 @@ base::string16 AccessibilityTreeFormatterWin::ProcessTreeForOutput(
switch (value->type()) {
case base::Value::Type::STRING: {
base::string16 string_value;
std::string string_value;
value->GetAsString(&string_value);
bool did_pass_filters = WriteAttribute(
false,
base::StringPrintf(L"%ls='%ls'",
base::UTF8ToUTF16(attribute_name).c_str(),
string_value.c_str()),
base::StringPrintf("%s='%s'", attribute_name, string_value.c_str()),
&line);
if (filtered_dict_result && did_pass_filters)
filtered_dict_result->SetString(attribute_name, string_value);
......@@ -948,10 +946,7 @@ base::string16 AccessibilityTreeFormatterWin::ProcessTreeForOutput(
int int_value = 0;
value->GetAsInteger(&int_value);
bool did_pass_filters = WriteAttribute(
false,
base::StringPrintf(L"%ls=%d",
base::UTF8ToUTF16(attribute_name).c_str(),
int_value),
false, base::StringPrintf("%s=%d", attribute_name, int_value),
&line);
if (filtered_dict_result && did_pass_filters)
filtered_dict_result->SetInteger(attribute_name, int_value);
......@@ -961,10 +956,7 @@ base::string16 AccessibilityTreeFormatterWin::ProcessTreeForOutput(
double double_value = 0.0;
value->GetAsDouble(&double_value);
bool did_pass_filters = WriteAttribute(
false,
base::StringPrintf(L"%ls=%.2f",
base::UTF8ToUTF16(attribute_name).c_str(),
double_value),
false, base::StringPrintf("%s=%.2f", attribute_name, double_value),
&line);
if (filtered_dict_result && did_pass_filters)
filtered_dict_result->SetDouble(attribute_name, double_value);
......@@ -979,7 +971,7 @@ base::string16 AccessibilityTreeFormatterWin::ProcessTreeForOutput(
for (base::ListValue::const_iterator it = list_value->begin();
it != list_value->end(); ++it) {
base::string16 string_value;
std::string string_value;
if (it->GetAsString(&string_value))
if (WriteAttribute(false, string_value, &line))
filtered_list->AppendString(string_value);
......
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