diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-13 02:58:20 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-13 02:58:20 +0000 |
commit | 280356aaff018a2b33defe80d0c4c73c81883c44 (patch) | |
tree | b1dc5edc46757eb911d6112acf38284b7f306918 /chrome/browser/autofill/autofill_profile.cc | |
parent | a1aee38539cdd177ce3f034677f55327051e3763 (diff) | |
download | chromium_src-280356aaff018a2b33defe80d0c4c73c81883c44.zip chromium_src-280356aaff018a2b33defe80d0c4c73c81883c44.tar.gz chromium_src-280356aaff018a2b33defe80d0c4c73c81883c44.tar.bz2 |
Adding summary string generation for the AutoFill feature.
Includes a small modification to the generated resources, needed additional whitespace
in credit card summary. Added summary generation to autofill_profile.* and modified
summary generation in credit_card.* to match. credit_card.* modifications were largely
to use string16 instead of std::wstring.
Factored out common unit testing utilities into autofill_common_unittest.*, and added
unit tests for summary string generation for credit_card.* and autofill_profile.*.
BUG=35551
TEST=unit_tests --gtest_filter=AutoFillProfileTest.*:CreditCardTest.*
Review URL: http://codereview.chromium.org/606031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/autofill_profile.cc')
-rw-r--r-- | chrome/browser/autofill/autofill_profile.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc index fc3b30c..a8f0397 100644 --- a/chrome/browser/autofill/autofill_profile.cc +++ b/chrome/browser/autofill/autofill_profile.cc @@ -6,6 +6,7 @@ #include <vector> +#include "app/l10n_util.h" #include "base/stl_util-inl.h" #include "base/string_util.h" #include "chrome/browser/autofill/address.h" @@ -15,6 +16,7 @@ #include "chrome/browser/autofill/fax_number.h" #include "chrome/browser/autofill/home_address.h" #include "chrome/browser/autofill/home_phone_number.h" +#include "grit/generated_resources.h" AutoFillProfile::AutoFillProfile(const string16& label, int unique_id) : label_(label), @@ -109,6 +111,49 @@ FormGroup* AutoFillProfile::Clone() const { return profile; } +string16 AutoFillProfile::PreviewSummary() const { + // Fetch the components of the summary string. Any or all of these + // may be an empty string. + string16 first_name = GetFieldText(AutoFillType(NAME_FIRST)); + string16 last_name = GetFieldText(AutoFillType(NAME_LAST)); + string16 address = GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)); + + // String separators depend (below) on the existence of the various fields. + bool have_first_name = first_name.length() > 0; + bool have_last_name = last_name.length() > 0; + bool have_address = address.length() > 0; + + // Name separator defaults to "". Space if we have first and last name. + string16 name_separator; + if (have_first_name && have_last_name) { + name_separator = l10n_util::GetStringUTF16( + IDS_AUTOFILL_DIALOG_ADDRESS_NAME_SEPARATOR); + } + + // E.g. "John Smith", or "John", or "Smith", or "". + string16 name_format = l10n_util::GetStringFUTF16( + IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_NAME_FORMAT, + first_name, + name_separator, + last_name); + + // Summary separator defaults to "". ", " if we have name and address. + string16 summary_separator; + if ((have_first_name || have_last_name) && have_address) { + summary_separator = l10n_util::GetStringUTF16( + IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_SEPARATOR); + } + + // E.g. "John Smith, 123 Main Street". + string16 summary_format = l10n_util::GetStringFUTF16( + IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_FORMAT, + name_format, + summary_separator, + address); + + return summary_format; +} + void AutoFillProfile::operator=(const AutoFillProfile& source) { label_ = source.label_; unique_id_ = source.unique_id_; |