Commit ddb26fef authored by groby@chromium.org's avatar groby@chromium.org

[rAC] Display Autofill popups vertically compact.

If an autofill popup is supposed to display a multi-line address,
the address needs to be converted into a single-line format with
separators.

BUG=362373
R=estade@chromium.org
TBR=isherman@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282710 0039d316-1c4b-4281-b951-d872f2087c98
parent c14a6807
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#include "components/autofill/core/browser/phone_number_i18n.h" #include "components/autofill/core/browser/phone_number_i18n.h"
#include "components/autofill/core/browser/validation.h" #include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_pref_names.h" #include "components/autofill/core/common/autofill_pref_names.h"
#include "third_party/libaddressinput/chromium/cpp/src/region_data_constants.h"
using ::i18n::addressinput::RegionDataConstants;
namespace autofill { namespace autofill {
namespace { namespace {
...@@ -566,7 +569,18 @@ void PersonalDataManager::GetProfileSuggestions( ...@@ -566,7 +569,18 @@ void PersonalDataManager::GetProfileSuggestions(
std::vector<base::string16> multi_values; std::vector<base::string16> multi_values;
profile->GetMultiInfo(type, app_locale_, &multi_values); profile->GetMultiInfo(type, app_locale_, &multi_values);
// Names need to be in vertically compact form - i.e. a single line. Join
// multi-line addresses into a single line, using a separator.
// The separator is locale-specific.
base::string16 compact_separator =
base::UTF8ToUTF16(RegionDataConstants::GetLanguageCompactLineSeparator(
profile->language_code()));
for (size_t i = 0; i < multi_values.size(); ++i) { for (size_t i = 0; i < multi_values.size(); ++i) {
// Create vertically compact form.
base::ReplaceChars(multi_values[i],
base::ASCIIToUTF16("\n"),
compact_separator,
&multi_values[i]);
if (!field_is_autofilled) { if (!field_is_autofilled) {
// Suggest data that starts with what the user has typed. // Suggest data that starts with what the user has typed.
if (!multi_values[i].empty() && if (!multi_values[i].empty() &&
......
...@@ -34,6 +34,8 @@ namespace { ...@@ -34,6 +34,8 @@ namespace {
enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO };
bool ReturnTrue(const AutofillProfile&) { return true; }
ACTION(QuitMainMessageLoop) { base::MessageLoop::current()->Quit(); } ACTION(QuitMainMessageLoop) { base::MessageLoop::current()->Quit(); }
class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver {
...@@ -2564,4 +2566,33 @@ TEST_F(PersonalDataManagerTest, UpdateLanguageCodeInProfile) { ...@@ -2564,4 +2566,33 @@ TEST_F(PersonalDataManagerTest, UpdateLanguageCodeInProfile) {
EXPECT_EQ("en", results[0]->language_code()); EXPECT_EQ("en", results[0]->language_code());
} }
TEST_F(PersonalDataManagerTest, GetProfileSuggestions) {
AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
test::SetProfileInfo(&profile,
"Marion", "Mitchell", "Morrison",
"johnwayne@me.xyz", "Fox",
"123 Zoo St.\nSecond Line\nThird line", "unit 5", "Hollywood", "CA",
"91601", "US", "12345678910");
personal_data_->AddProfile(profile);
ResetPersonalDataManager(USER_MODE_NORMAL);
std::vector<base::string16> values;
std::vector<base::string16> labels;
std::vector<base::string16> icons;
std::vector<PersonalDataManager::GUIDPair> guid_pairs;
personal_data_->GetProfileSuggestions(
AutofillType(ADDRESS_HOME_STREET_ADDRESS),
base::UTF8ToUTF16("123"),
false,
std::vector<ServerFieldType>(),
base::Bind(ReturnTrue),
&values,
&labels,
&icons,
&guid_pairs);
ASSERT_FALSE(values.empty());
EXPECT_EQ(values[0],
base::UTF8ToUTF16("123 Zoo St., Second Line, Third line, unit 5"));
}
} // namespace autofill } // namespace autofill
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