Commit 167fb404 authored by rouslan@chromium.org's avatar rouslan@chromium.org

Reland "Use language-specific street address line separators."

This patch fixes a past-the-end iterator and relands
https://crrev.com/284335, which was reverted in
https://crrev.com/284340.

TBR=estade@chromium.org,aruslan@chromium.org
BUG=270261

Review URL: https://codereview.chromium.org/403923003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284354 0039d316-1c4b-4281-b951-d872f2087c98
parent f278a931
...@@ -40,7 +40,7 @@ vars = { ...@@ -40,7 +40,7 @@ vars = {
# to update other nacl_*_revision's. # to update other nacl_*_revision's.
"nacl_tools_revision": "13077", # native_client/DEPS: tools_rev "nacl_tools_revision": "13077", # native_client/DEPS: tools_rev
"google_toolbox_for_mac_revision": "662", "google_toolbox_for_mac_revision": "662",
"libaddressinput_revision": "305", "libaddressinput_revision": "310",
"libphonenumber_revision": "621", "libphonenumber_revision": "621",
"libvpx_revision": "282874", "libvpx_revision": "282874",
"lss_revision": "26", "lss_revision": "26",
......
...@@ -115,9 +115,13 @@ void FillOutputForSectionWithComparator( ...@@ -115,9 +115,13 @@ void FillOutputForSectionWithComparator(
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); std::vector<ServerFieldType> types = common::TypesFromInputs(inputs);
form_structure.FillFields(types, form_structure.FillFields(
types,
compare, compare,
get_info, get_info,
section == SECTION_CC_BILLING
? full_wallet->billing_address()->language_code()
: full_wallet->shipping_address()->language_code(),
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
} }
...@@ -345,6 +349,7 @@ void AutofillDialogControllerAndroid::Show() { ...@@ -345,6 +349,7 @@ void AutofillDialogControllerAndroid::Show() {
common::TypesFromInputs(inputs), common::TypesFromInputs(inputs),
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
base::Bind(NullGetInfo), base::Bind(NullGetInfo),
std::string(),
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
} }
......
...@@ -839,6 +839,7 @@ void AutofillDialogControllerImpl::Show() { ...@@ -839,6 +839,7 @@ void AutofillDialogControllerImpl::Show() {
RequestedTypesForSection(SECTION_SHIPPING), RequestedTypesForSection(SECTION_SHIPPING),
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
base::Bind(NullGetInfo), base::Bind(NullGetInfo),
std::string(),
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
transaction_amount_ = form_structure_.GetUniqueValue( transaction_amount_ = form_structure_.GetUniqueValue(
......
...@@ -91,6 +91,7 @@ bool DataModelWrapper::FillFormStructure( ...@@ -91,6 +91,7 @@ bool DataModelWrapper::FillFormStructure(
types, types,
compare, compare,
base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
GetLanguageCode(),
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
} }
......
...@@ -15,8 +15,12 @@ ...@@ -15,8 +15,12 @@
#include "components/autofill/core/browser/phone_number.h" #include "components/autofill/core/browser/phone_number.h"
#include "components/autofill/core/browser/state_names.h" #include "components/autofill/core/browser/state_names.h"
#include "grit/components_strings.h" #include "grit/components_strings.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
using ::i18n::addressinput::AddressData;
using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine;
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using base::StringToInt; using base::StringToInt;
...@@ -356,16 +360,21 @@ bool FillMonthControl(const base::string16& value, FormFieldData* field) { ...@@ -356,16 +360,21 @@ bool FillMonthControl(const base::string16& value, FormFieldData* field) {
// Fills |field| with the street address in |value|. Translates newlines into // Fills |field| with the street address in |value|. Translates newlines into
// equivalent separators when necessary, i.e. when filling a single-line field. // equivalent separators when necessary, i.e. when filling a single-line field.
// The separators depend on |address_language_code|.
void FillStreetAddress(const base::string16& value, void FillStreetAddress(const base::string16& value,
const std::string& address_language_code,
FormFieldData* field) { FormFieldData* field) {
if (field->form_control_type == "textarea") { if (field->form_control_type == "textarea") {
field->value = value; field->value = value;
return; return;
} }
const base::string16& separator = AddressData address_data;
l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_SEPARATOR); address_data.language_code = address_language_code;
base::ReplaceChars(value, base::ASCIIToUTF16("\n"), separator, &field->value); base::SplitString(base::UTF16ToUTF8(value), '\n', &address_data.address_line);
std::string line;
GetStreetAddressLinesAsSingleLine(address_data, &line);
field->value = base::UTF8ToUTF16(line);
} }
std::string Hash32Bit(const std::string& str) { std::string Hash32Bit(const std::string& str) {
...@@ -462,6 +471,7 @@ bool AutofillField::IsFieldFillable() const { ...@@ -462,6 +471,7 @@ bool AutofillField::IsFieldFillable() const {
// static // static
bool AutofillField::FillFormField(const AutofillField& field, bool AutofillField::FillFormField(const AutofillField& field,
const base::string16& value, const base::string16& value,
const std::string& address_language_code,
const std::string& app_locale, const std::string& app_locale,
FormFieldData* field_data) { FormFieldData* field_data) {
AutofillType type = field.Type(); AutofillType type = field.Type();
...@@ -474,7 +484,7 @@ bool AutofillField::FillFormField(const AutofillField& field, ...@@ -474,7 +484,7 @@ bool AutofillField::FillFormField(const AutofillField& field,
} else if (field_data->form_control_type == "month") { } else if (field_data->form_control_type == "month") {
return FillMonthControl(value, field_data); return FillMonthControl(value, field_data);
} else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
FillStreetAddress(value, field_data); FillStreetAddress(value, address_language_code, field_data);
return true; return true;
} }
......
...@@ -65,11 +65,13 @@ class AutofillField : public FormFieldData { ...@@ -65,11 +65,13 @@ class AutofillField : public FormFieldData {
void set_default_value(const std::string& value) { default_value_ = value; } void set_default_value(const std::string& value) { default_value_ = value; }
const std::string& default_value() const { return default_value_; } const std::string& default_value() const { return default_value_; }
// Set |field_data|'s value to |value|. Uses |field| and |app_locale| as // Set |field_data|'s value to |value|. Uses |field|, |address_language_code|,
// hints when filling exceptional cases like phone number values and <select> // and |app_locale| as hints when filling exceptional cases like phone number
// fields. Returns |true| if the field has been filled, |false| otherwise. // values and <select> fields. Returns |true| if the field has been filled,
// |false| otherwise.
static bool FillFormField(const AutofillField& field, static bool FillFormField(const AutofillField& field,
const base::string16& value, const base::string16& value,
const std::string& address_language_code,
const std::string& app_locale, const std::string& app_locale,
FormFieldData* field_data); FormFieldData* field_data);
......
...@@ -2,16 +2,18 @@ ...@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/autofill/core/browser/autofill_field.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/field_types.h" #include "components/autofill/core/browser/field_types.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using base::UTF8ToUTF16;
namespace autofill { namespace autofill {
namespace { namespace {
...@@ -124,11 +126,13 @@ TEST(AutofillFieldTest, FillPhoneNumber) { ...@@ -124,11 +126,13 @@ TEST(AutofillFieldTest, FillPhoneNumber) {
field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode());
// Fill with a non-phone number; should fill normally. // Fill with a non-phone number; should fill normally.
AutofillField::FillFormField(field, ASCIIToUTF16("Oh hai"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value); EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value);
// Fill with a phone number; should fill just the prefix. // Fill with a phone number; should fill just the prefix.
AutofillField::FillFormField(field, ASCIIToUTF16("5551234"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("555"), field.value); EXPECT_EQ(ASCIIToUTF16("555"), field.value);
// Now reset the type, and set a max-length instead. // Now reset the type, and set a max-length instead.
...@@ -137,7 +141,8 @@ TEST(AutofillFieldTest, FillPhoneNumber) { ...@@ -137,7 +141,8 @@ TEST(AutofillFieldTest, FillPhoneNumber) {
field.max_length = 4; field.max_length = 4;
// Fill with a phone-number; should fill just the suffix. // Fill with a phone-number; should fill just the suffix.
AutofillField::FillFormField(field, ASCIIToUTF16("5551234"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("1234"), field.value); EXPECT_EQ(ASCIIToUTF16("1234"), field.value);
} }
...@@ -155,8 +160,8 @@ TEST(AutofillFieldTest, FillSelectControlByValue) { ...@@ -155,8 +160,8 @@ TEST(AutofillFieldTest, FillSelectControlByValue) {
field.option_contents[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i)); field.option_contents[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i));
} }
AutofillField::FillFormField(field, ASCIIToUTF16("Meenie"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("Meenie"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("Meenie"), field.value); EXPECT_EQ(ASCIIToUTF16("Meenie"), field.value);
} }
...@@ -174,8 +179,8 @@ TEST(AutofillFieldTest, FillSelectControlByContents) { ...@@ -174,8 +179,8 @@ TEST(AutofillFieldTest, FillSelectControlByContents) {
field.option_values[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i)); field.option_values[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i));
} }
AutofillField::FillFormField(field, ASCIIToUTF16("Miney"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("Miney"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("2"), field.value); // Corresponds to "Miney". EXPECT_EQ(ASCIIToUTF16("2"), field.value); // Corresponds to "Miney".
} }
...@@ -188,7 +193,8 @@ TEST(AutofillFieldTest, FillSelectControlWithFullCountryNames) { ...@@ -188,7 +193,8 @@ TEST(AutofillFieldTest, FillSelectControlWithFullCountryNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_COUNTRY); field.set_heuristic_type(ADDRESS_HOME_COUNTRY);
AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("CA"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); EXPECT_EQ(ASCIIToUTF16("Canada"), field.value);
} }
...@@ -201,7 +207,8 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedCountryNames) { ...@@ -201,7 +207,8 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedCountryNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_COUNTRY); field.set_heuristic_type(ADDRESS_HOME_COUNTRY);
AutofillField::FillFormField(field, ASCIIToUTF16("Canada"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("Canada"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("CA"), field.value); EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
} }
...@@ -214,7 +221,8 @@ TEST(AutofillFieldTest, FillSelectControlWithFullStateNames) { ...@@ -214,7 +221,8 @@ TEST(AutofillFieldTest, FillSelectControlWithFullStateNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("CA"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("California"), field.value); EXPECT_EQ(ASCIIToUTF16("California"), field.value);
} }
...@@ -227,8 +235,8 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviateStateNames) { ...@@ -227,8 +235,8 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviateStateNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("California"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("CA"), field.value); EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
} }
...@@ -242,8 +250,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { ...@@ -242,8 +250,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("California"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value); EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value);
} }
...@@ -257,8 +265,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { ...@@ -257,8 +265,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("Virginia"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("VA - Virginia"), field.value); EXPECT_EQ(ASCIIToUTF16("VA - Virginia"), field.value);
} }
...@@ -274,8 +282,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { ...@@ -274,8 +282,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("Virginia"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("WV - West Virginia"), field.value); EXPECT_EQ(ASCIIToUTF16("WV - West Virginia"), field.value);
} }
...@@ -291,8 +299,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { ...@@ -291,8 +299,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("North Carolina"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("North Carolina"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("North Carolina."), field.value); EXPECT_EQ(ASCIIToUTF16("North Carolina."), field.value);
} }
} }
...@@ -307,8 +315,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) { ...@@ -307,8 +315,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("CA"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value); EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value);
} }
...@@ -321,8 +329,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) { ...@@ -321,8 +329,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) {
base::string16()); base::string16());
field.set_heuristic_type(ADDRESS_HOME_STATE); field.set_heuristic_type(ADDRESS_HOME_STATE);
AutofillField::FillFormField(field, ASCIIToUTF16("NC"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("NC"), "en-US", "en-US", &field);
EXPECT_EQ(base::string16(), field.value); EXPECT_EQ(base::string16(), field.value);
} }
} }
...@@ -337,15 +345,18 @@ TEST(AutofillFieldTest, FillSelectControlWithNumericMonth) { ...@@ -337,15 +345,18 @@ TEST(AutofillFieldTest, FillSelectControlWithNumericMonth) {
field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
// Try with a leading zero. // Try with a leading zero.
AutofillField::FillFormField(field, ASCIIToUTF16("03"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("03"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("03"), field.value); EXPECT_EQ(ASCIIToUTF16("03"), field.value);
// Try without a leading zero. // Try without a leading zero.
AutofillField::FillFormField(field, ASCIIToUTF16("4"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("4"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("04"), field.value); EXPECT_EQ(ASCIIToUTF16("04"), field.value);
// Try a two-digit month. // Try a two-digit month.
AutofillField::FillFormField(field, ASCIIToUTF16("11"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("11"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("11"), field.value); EXPECT_EQ(ASCIIToUTF16("11"), field.value);
} }
...@@ -360,13 +371,14 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedMonthName) { ...@@ -360,13 +371,14 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedMonthName) {
base::string16()); base::string16());
field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
AutofillField::FillFormField(field, ASCIIToUTF16("04"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("04"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("Apr"), field.value); EXPECT_EQ(ASCIIToUTF16("Apr"), field.value);
} }
TEST(AutofillFieldTest, FillSelectControlWithFullMonthName) { TEST(AutofillFieldTest, FillSelectControlWithFullMonthName) {
const char* const kMonthsFull[] = { const char* const kMonthsFull[] = {
"January", "February", "March", "April", "May", "June", "January","February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December", "July", "August", "September", "October", "November", "December",
}; };
AutofillField field( AutofillField field(
...@@ -374,7 +386,8 @@ TEST(AutofillFieldTest, FillSelectControlWithFullMonthName) { ...@@ -374,7 +386,8 @@ TEST(AutofillFieldTest, FillSelectControlWithFullMonthName) {
base::string16()); base::string16());
field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
AutofillField::FillFormField(field, ASCIIToUTF16("04"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("04"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("April"), field.value); EXPECT_EQ(ASCIIToUTF16("April"), field.value);
} }
...@@ -387,7 +400,8 @@ TEST(AutofillFieldTest, FillSelectControlWithNumericMonthSansLeadingZero) { ...@@ -387,7 +400,8 @@ TEST(AutofillFieldTest, FillSelectControlWithNumericMonthSansLeadingZero) {
base::string16()); base::string16());
field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
AutofillField::FillFormField(field, ASCIIToUTF16("04"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("04"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("4"), field.value); EXPECT_EQ(ASCIIToUTF16("4"), field.value);
} }
...@@ -399,7 +413,8 @@ TEST(AutofillFieldTest, FillSelectControlWithTwoDigitCreditCardYear) { ...@@ -399,7 +413,8 @@ TEST(AutofillFieldTest, FillSelectControlWithTwoDigitCreditCardYear) {
base::string16()); base::string16());
field.set_heuristic_type(CREDIT_CARD_EXP_2_DIGIT_YEAR); field.set_heuristic_type(CREDIT_CARD_EXP_2_DIGIT_YEAR);
AutofillField::FillFormField(field, ASCIIToUTF16("2017"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("2017"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("17"), field.value); EXPECT_EQ(ASCIIToUTF16("17"), field.value);
} }
...@@ -414,22 +429,23 @@ TEST(AutofillFieldTest, FillSelectControlWithCreditCardType) { ...@@ -414,22 +429,23 @@ TEST(AutofillFieldTest, FillSelectControlWithCreditCardType) {
field.set_heuristic_type(CREDIT_CARD_TYPE); field.set_heuristic_type(CREDIT_CARD_TYPE);
// Normal case: // Normal case:
AutofillField::FillFormField(field, ASCIIToUTF16("Visa"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("Visa"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("Visa"), field.value); EXPECT_EQ(ASCIIToUTF16("Visa"), field.value);
// Filling should be able to handle intervening whitespace: // Filling should be able to handle intervening whitespace:
AutofillField::FillFormField(field, ASCIIToUTF16("MasterCard"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("MasterCard"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("Master Card"), field.value); EXPECT_EQ(ASCIIToUTF16("Master Card"), field.value);
// American Express is sometimes abbreviated as AmEx: // American Express is sometimes abbreviated as AmEx:
AutofillField::FillFormField(field, ASCIIToUTF16("American Express"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("American Express"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("AmEx"), field.value); EXPECT_EQ(ASCIIToUTF16("AmEx"), field.value);
// Case insensitivity: // Case insensitivity:
AutofillField::FillFormField(field, ASCIIToUTF16("Discover"), "en-US", AutofillField::FillFormField(
&field); field, ASCIIToUTF16("Discover"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("discover"), field.value); EXPECT_EQ(ASCIIToUTF16("discover"), field.value);
} }
...@@ -438,15 +454,18 @@ TEST(AutofillFieldTest, FillMonthControl) { ...@@ -438,15 +454,18 @@ TEST(AutofillFieldTest, FillMonthControl) {
field.form_control_type = "month"; field.form_control_type = "month";
// Try a month with two digits. // Try a month with two digits.
AutofillField::FillFormField(field, ASCIIToUTF16("12/2017"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("12/2017"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("2017-12"), field.value); EXPECT_EQ(ASCIIToUTF16("2017-12"), field.value);
// Try a month with a leading zero. // Try a month with a leading zero.
AutofillField::FillFormField(field, ASCIIToUTF16("03/2019"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("03/2019"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("2019-03"), field.value); EXPECT_EQ(ASCIIToUTF16("2019-03"), field.value);
// Try a month without a leading zero. // Try a month without a leading zero.
AutofillField::FillFormField(field, ASCIIToUTF16("4/2018"), "en-US", &field); AutofillField::FillFormField(
field, ASCIIToUTF16("4/2018"), "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("2018-04"), field.value); EXPECT_EQ(ASCIIToUTF16("2018-04"), field.value);
} }
...@@ -456,8 +475,13 @@ TEST(AutofillFieldTest, FillStreetAddressTextArea) { ...@@ -456,8 +475,13 @@ TEST(AutofillFieldTest, FillStreetAddressTextArea) {
base::string16 value = ASCIIToUTF16("123 Fake St.\n" base::string16 value = ASCIIToUTF16("123 Fake St.\n"
"Apt. 42"); "Apt. 42");
AutofillField::FillFormField(field, value, "en-US", &field); AutofillField::FillFormField(field, value, "en-US", "en-US", &field);
EXPECT_EQ(value, field.value); EXPECT_EQ(value, field.value);
base::string16 ja_value = UTF8ToUTF16("桜丘町26-1\n"
"セルリアンタワー6階");
AutofillField::FillFormField(field, ja_value, "ja-JP", "en-US", &field);
EXPECT_EQ(ja_value, field.value);
} }
TEST(AutofillFieldTest, FillStreetAddressTextField) { TEST(AutofillFieldTest, FillStreetAddressTextField) {
...@@ -467,8 +491,16 @@ TEST(AutofillFieldTest, FillStreetAddressTextField) { ...@@ -467,8 +491,16 @@ TEST(AutofillFieldTest, FillStreetAddressTextField) {
base::string16 value = ASCIIToUTF16("123 Fake St.\n" base::string16 value = ASCIIToUTF16("123 Fake St.\n"
"Apt. 42"); "Apt. 42");
AutofillField::FillFormField(field, value, "en-US", &field); AutofillField::FillFormField(field, value, "en-US", "en-US", &field);
EXPECT_EQ(ASCIIToUTF16("123 Fake St., Apt. 42"), field.value); EXPECT_EQ(ASCIIToUTF16("123 Fake St., Apt. 42"), field.value);
AutofillField::FillFormField(field,
UTF8ToUTF16("桜丘町26-1\n"
"セルリアンタワー6階"),
"ja-JP",
"en-US",
&field);
EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value);
} }
} // namespace } // namespace
......
...@@ -550,9 +550,12 @@ void AutofillManager::FillOrPreviewForm( ...@@ -550,9 +550,12 @@ void AutofillManager::FillOrPreviewForm(
FormData result = form; FormData result = form;
base::string16 profile_full_name; base::string16 profile_full_name;
std::string profile_language_code;
if (!is_credit_card) { if (!is_credit_card) {
profile_full_name = data_model->GetInfo( profile_full_name = data_model->GetInfo(
AutofillType(NAME_FULL), app_locale_); AutofillType(NAME_FULL), app_locale_);
profile_language_code =
static_cast<const AutofillProfile*>(data_model)->language_code();
} }
// If the relevant section is auto-filled, we should fill |field| but not the // If the relevant section is auto-filled, we should fill |field| but not the
...@@ -563,8 +566,11 @@ void AutofillManager::FillOrPreviewForm( ...@@ -563,8 +566,11 @@ void AutofillManager::FillOrPreviewForm(
if ((*iter) == field) { if ((*iter) == field) {
base::string16 value = data_model->GetInfoForVariant( base::string16 value = data_model->GetInfoForVariant(
autofill_field->Type(), variant, app_locale_); autofill_field->Type(), variant, app_locale_);
if (AutofillField::FillFormField( if (AutofillField::FillFormField(*autofill_field,
*autofill_field, value, app_locale_, &(*iter))) { value,
profile_language_code,
app_locale_,
&(*iter))) {
// Mark the cached field as autofilled, so that we can detect when a // Mark the cached field as autofilled, so that we can detect when a
// user edits an autofilled field (for metrics). // user edits an autofilled field (for metrics).
autofill_field->is_autofilled = true; autofill_field->is_autofilled = true;
...@@ -620,8 +626,11 @@ void AutofillManager::FillOrPreviewForm( ...@@ -620,8 +626,11 @@ void AutofillManager::FillOrPreviewForm(
(result.fields[i] == field || (result.fields[i] == field ||
result.fields[i].form_control_type == "select-one" || result.fields[i].form_control_type == "select-one" ||
result.fields[i].value.empty()); result.fields[i].value.empty());
if (AutofillField::FillFormField( if (AutofillField::FillFormField(*cached_field,
*cached_field, value, app_locale_, &result.fields[i])) { value,
profile_language_code,
app_locale_,
&result.fields[i])) {
// Mark the cached field as autofilled, so that we can detect when a // Mark the cached field as autofilled, so that we can detect when a
// user edits an autofilled field (for metrics). // user edits an autofilled field (for metrics).
form_structure->field(i)->is_autofilled = true; form_structure->field(i)->is_autofilled = true;
......
...@@ -1107,6 +1107,7 @@ bool FormStructure::FillFields( ...@@ -1107,6 +1107,7 @@ bool FormStructure::FillFields(
const std::vector<ServerFieldType>& types, const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches, const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& get_info, const base::Callback<base::string16(const AutofillType&)>& get_info,
const std::string& address_language_code,
const std::string& app_locale) { const std::string& app_locale) {
bool filled_something = false; bool filled_something = false;
for (size_t i = 0; i < field_count(); ++i) { for (size_t i = 0; i < field_count(); ++i) {
...@@ -1114,6 +1115,7 @@ bool FormStructure::FillFields( ...@@ -1114,6 +1115,7 @@ bool FormStructure::FillFields(
if (matches.Run(types[j], *field(i))) { if (matches.Run(types[j], *field(i))) {
AutofillField::FillFormField(*field(i), AutofillField::FillFormField(*field(i),
get_info.Run(field(i)->Type()), get_info.Run(field(i)->Type()),
address_language_code,
app_locale, app_locale,
field(i)); field(i));
filled_something = true; filled_something = true;
......
...@@ -137,11 +137,13 @@ class FormStructure { ...@@ -137,11 +137,13 @@ class FormStructure {
InputFieldComparator; InputFieldComparator;
// Fills in |fields_| that match |types| (via |matches|) with info from // Fills in |fields_| that match |types| (via |matches|) with info from
// |get_info|. // |get_info|. Uses |address_language_code| to determine line separators when
// collapsing street address lines into a single-line input text field.
bool FillFields( bool FillFields(
const std::vector<ServerFieldType>& types, const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches, const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& get_info, const base::Callback<base::string16(const AutofillType&)>& get_info,
const std::string& address_language_code,
const std::string& app_locale); const std::string& app_locale);
// Returns the values that can be filled into the form structure for the // Returns the values that can be filled into the form structure for the
......
...@@ -2,8 +2,8 @@ Name: The library to input, validate, and display addresses. ...@@ -2,8 +2,8 @@ Name: The library to input, validate, and display addresses.
Short Name: libaddressinput Short Name: libaddressinput
URL: https://code.google.com/p/libaddressinput/ URL: https://code.google.com/p/libaddressinput/
Version: 0 Version: 0
Date: 11 July 2014 Date: 19 July 2014
Revision: 305 Revision: 310
License: Apache 2.0 License: Apache 2.0
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
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