Commit bf6067e9 authored by estade@chromium.org's avatar estade@chromium.org

rAc: fix international address formatting (mostly)

BUG=337998

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247918 0039d316-1c4b-4281-b951-d872f2087c98
parent d230fb11
...@@ -53,12 +53,18 @@ gfx::Image DataModelWrapper::GetIcon() { ...@@ -53,12 +53,18 @@ gfx::Image DataModelWrapper::GetIcon() {
bool DataModelWrapper::GetDisplayText( bool DataModelWrapper::GetDisplayText(
base::string16* vertically_compact, base::string16* vertically_compact,
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
base::string16 phone =
GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER));
if (phone.empty())
return false;
// Format the address. // Format the address.
::i18n::addressinput::AddressData address_data; ::i18n::addressinput::AddressData address_data;
address_data.recipient = UTF16ToUTF8( address_data.recipient = UTF16ToUTF8(
GetInfoForDisplay(AutofillType(NAME_FULL))); GetInfoForDisplay(AutofillType(NAME_FULL)));
address_data.country_code = UTF16ToUTF8( address_data.country_code = UTF16ToASCII(
GetInfoForDisplay(AutofillType(ADDRESS_HOME_COUNTRY))); GetInfoForDisplay(AutofillType(HTML_TYPE_COUNTRY_CODE,
HTML_MODE_SHIPPING)));
address_data.administrative_area = UTF16ToUTF8( address_data.administrative_area = UTF16ToUTF8(
GetInfoForDisplay(AutofillType(ADDRESS_HOME_STATE))); GetInfoForDisplay(AutofillType(ADDRESS_HOME_STATE)));
address_data.locality = UTF16ToUTF8( address_data.locality = UTF16ToUTF8(
...@@ -85,8 +91,7 @@ bool DataModelWrapper::GetDisplayText( ...@@ -85,8 +91,7 @@ bool DataModelWrapper::GetDisplayText(
if (!email.empty()) if (!email.empty())
non_address_info += ASCIIToUTF16("\n") + email; non_address_info += ASCIIToUTF16("\n") + email;
non_address_info += ASCIIToUTF16("\n") + non_address_info += ASCIIToUTF16("\n") + phone;
GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER));
// The separator is locale-specific. // The separator is locale-specific.
std::string compact_separator = std::string compact_separator =
...@@ -251,10 +256,8 @@ base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type) ...@@ -251,10 +256,8 @@ base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type)
bool WalletAddressWrapper::GetDisplayText( bool WalletAddressWrapper::GetDisplayText(
base::string16* vertically_compact, base::string16* vertically_compact,
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
if (!address_->is_complete_address() || if (!address_->is_complete_address())
GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
return false; return false;
}
return DataModelWrapper::GetDisplayText(vertically_compact, return DataModelWrapper::GetDisplayText(vertically_compact,
horizontally_compact); horizontally_compact);
...@@ -297,12 +300,15 @@ bool WalletInstrumentWrapper::GetDisplayText( ...@@ -297,12 +300,15 @@ bool WalletInstrumentWrapper::GetDisplayText(
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
// TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048
if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED ||
!instrument_->address().is_complete_address() || !instrument_->address().is_complete_address()) {
GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { return false;
}
if (!DataModelWrapper::GetDisplayText(vertically_compact,
horizontally_compact)) {
return false; return false;
} }
DataModelWrapper::GetDisplayText(vertically_compact, horizontally_compact);
// TODO(estade): descriptive_name() is user-provided. Should we use it or // TODO(estade): descriptive_name() is user-provided. Should we use it or
// just type + last 4 digits? // just type + last 4 digits?
base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n"); base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n");
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// 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 "base/guid.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -92,6 +93,67 @@ TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) { ...@@ -92,6 +93,67 @@ TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) {
EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2)); EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2));
} }
TEST(DataModelWrapperTest, GetDisplayText) {
AutofillProfile profile = test::GetFullProfile();
base::string16 vertical, horizontal;
EXPECT_TRUE(
AutofillProfileWrapper(&profile).GetDisplayText(&horizontal, &vertical));
EXPECT_EQ(
ASCIIToUTF16("John H. Doe, 666 Erebus St., Apt 8, Elysium, CA 91111\n"
"johndoe@hades.com\n"
"+1 650-211-1111"),
horizontal);
EXPECT_EQ(
ASCIIToUTF16("John H. Doe\n"
"666 Erebus St.\n"
"Apt 8\n"
"Elysium, CA 91111\n"
"johndoe@hades.com\n"
"+1 650-211-1111"),
vertical);
// A Japanese address.
AutofillProfile foreign_profile(
base::GenerateGUID(), "http://www.example.com/");
foreign_profile.SetRawInfo(
ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP"));
foreign_profile.SetRawInfo(
ADDRESS_HOME_STATE,
base::WideToUTF16(L"\u6771\u4EAC\u90FD"));
foreign_profile.SetRawInfo(
ADDRESS_HOME_CITY,
base::WideToUTF16(L"\u6E0B\u8C37\u533A"));
foreign_profile.SetRawInfo(
ADDRESS_HOME_DEPENDENT_LOCALITY,
base::WideToUTF16(L"\uC911\uAD6C"));
foreign_profile.SetRawInfo(
ADDRESS_HOME_STREET_ADDRESS,
base::WideToUTF16(
L"\u685C\u4E18\u753A26-1\n"
L"\u30BB\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC6\u968E"));
foreign_profile.SetRawInfo(
NAME_FULL,
base::WideToUTF16(L"\u6751\u4E0A \u7F8E\u7D00"));
foreign_profile.SetRawInfo(ADDRESS_HOME_ZIP, base::ASCIIToUTF16("150-8512"));
foreign_profile.SetRawInfo(
PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("+81-3-6384-9000"));
EXPECT_TRUE(AutofillProfileWrapper(&foreign_profile).GetDisplayText(
&horizontal, &vertical));
EXPECT_EQ(
base::WideToUTF16(
L"\u3012150-8512\n"
L"\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\n"
L"\u685C\u4E18\u753A26-1\n"
L"\u30BB\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC6\u968E\n"
L"\u6751\u4E0A \u7F8E\u7D00\n"
L"+81-3-6384-9000"),
vertical);
// TODO(estade): we should also verify that |horizontal| is correct, but right
// now it uses the incorrect address line separator. See:
// http://crbug.com/270261
}
TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) { TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) {
scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument(
wallet::GetTestMaskedInstrument()); wallet::GetTestMaskedInstrument());
......
...@@ -1214,26 +1214,31 @@ const std::string& RegionDataConstants::GetLanguageCompactLineSeparator( ...@@ -1214,26 +1214,31 @@ const std::string& RegionDataConstants::GetLanguageCompactLineSeparator(
language_code == "zh" || language_code == "zh" ||
language_code == "zh-hant" || language_code == "zh-hant" ||
language_code == "zh-hans") { language_code == "zh-hans") {
return kEmptyString; return kEmptyString;
} else if (language_code == "ar" || }
language_code == "cjm" ||
language_code == "doi" || if (language_code == "ar" ||
language_code == "fa" || language_code == "cjm" ||
language_code == "lah" || language_code == "doi" ||
language_code == "prd" || language_code == "fa" ||
language_code == "ps" || language_code == "lah" ||
language_code == "swb" || language_code == "prd" ||
language_code == "ug" || language_code == "ps" ||
language_code == "ur") { language_code == "swb" ||
language_code == "ug" ||
language_code == "ur") {
return kArabicSeparator; return kArabicSeparator;
} else if (language_code == "ko" || }
language_code == "kdt" ||
language_code == "lcp" || if (language_code == "ko" ||
language_code == "lwl" || language_code == "kdt" ||
language_code == "th" || language_code == "lcp" ||
language_code == "tts") { language_code == "lwl" ||
language_code == "th" ||
language_code == "tts") {
return kSpace; return kSpace;
} }
return kCommaAndSpace; return kCommaAndSpace;
} }
......
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