diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-07 00:19:46 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-07 00:19:46 +0000 |
commit | 3772282de897cfc2a66bc95c3bd06d0c2a3fd65f (patch) | |
tree | 0e7be213a5f9072feb8ff6b2191c41bc3cc1cccc | |
parent | d8e7d60e8ef81622efb32ffa24cb90fd9d4a5146 (diff) | |
download | chromium_src-3772282de897cfc2a66bc95c3bd06d0c2a3fd65f.zip chromium_src-3772282de897cfc2a66bc95c3bd06d0c2a3fd65f.tar.gz chromium_src-3772282de897cfc2a66bc95c3bd06d0c2a3fd65f.tar.bz2 |
rAc: fix validation logic when autofill completion sets country
BUG=314842
R=dbeam@chromium.org
Review URL: https://codereview.chromium.org/58683002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233430 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 79 insertions, 2 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.cc b/chrome/browser/ui/autofill/autofill_dialog_common.cc index ecffc7d..4391a6b 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_common.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_common.cc @@ -4,6 +4,8 @@ #include "chrome/browser/ui/autofill/autofill_dialog_common.h" +#include "chrome/browser/browser_process.h" +#include "components/autofill/core/browser/autofill_country.h" #include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_type.h" #include "grit/chromium_strings.h" @@ -176,5 +178,14 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( return AutofillMetrics::NUM_DIALOG_UI_EVENTS; } +string16 GetHardcodedValueForType(ServerFieldType type) { + if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { + AutofillCountry country("US", g_browser_process->GetApplicationLocale()); + return country.name(); + } + + return string16(); +} + } // namespace common } // namespace autofill diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.h b/chrome/browser/ui/autofill/autofill_dialog_common.h index 641bed5..91ce21c 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_common.h +++ b/chrome/browser/ui/autofill/autofill_dialog_common.h @@ -46,6 +46,10 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( DialogSection section); +// We hardcode some values. In particular, we don't yet allow the user to change +// the country: http://crbug.com/247518 +string16 GetHardcodedValueForType(ServerFieldType type); + } // namespace common } // namespace autofill diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc index b38fb91..6707815 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc @@ -498,6 +498,64 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { } } +// For now, no matter what, the country must always be US. See +// http://crbug.com/247518 +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, + FillInputFromForeignProfile) { + AutofillProfile full_profile(test::GetFullProfile()); + full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), + ASCIIToUTF16("France"), "en-US"); + controller()->GetTestingManager()->AddTestingProfile(&full_profile); + + const DetailInputs& inputs = + controller()->RequestedFieldsForSection(SECTION_SHIPPING); + const DetailInput& triggering_input = inputs[0]; + string16 value = full_profile.GetRawInfo(triggering_input.type); + TestableAutofillDialogView* view = controller()->GetTestableView(); + view->SetTextContentsOfInput(triggering_input, + value.substr(0, value.size() / 2)); + view->ActivateInput(triggering_input); + + ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); + controller()->DidAcceptSuggestion(string16(), 0); + + // All inputs should be filled. + AutofillProfileWrapper wrapper(&full_profile); + for (size_t i = 0; i < inputs.size(); ++i) { + string16 expectation = + AutofillType(inputs[i].type).GetStorableType() == ADDRESS_HOME_COUNTRY ? + ASCIIToUTF16("United States") : + wrapper.GetInfo(AutofillType(inputs[i].type)); + EXPECT_EQ(expectation, view->GetTextContentsOfInput(inputs[i])); + } + + // Now simulate some user edits and try again. + std::vector<string16> expectations; + for (size_t i = 0; i < inputs.size(); ++i) { + string16 users_input = i % 2 == 0 ? string16() : ASCIIToUTF16("dummy"); + view->SetTextContentsOfInput(inputs[i], users_input); + // Empty inputs should be filled, others should be left alone. + string16 expectation = + &inputs[i] == &triggering_input || users_input.empty() ? + wrapper.GetInfo(AutofillType(inputs[i].type)) : + users_input; + if (AutofillType(inputs[i].type).GetStorableType() == ADDRESS_HOME_COUNTRY) + expectation = ASCIIToUTF16("United States"); + + expectations.push_back(expectation); + } + + view->SetTextContentsOfInput(triggering_input, + value.substr(0, value.size() / 2)); + view->ActivateInput(triggering_input); + ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); + controller()->DidAcceptSuggestion(string16(), 0); + + for (size_t i = 0; i < inputs.size(); ++i) { + EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i])); + } +} + // This test makes sure that picking a profile variant in the Autofill // popup works as expected. IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index 97af1ca..fcad66f 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -1176,7 +1176,7 @@ void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { DetailInputs* inputs = MutableRequestedFieldsForSection(section); for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { - it->initial_value.clear(); + it->initial_value = common::GetHardcodedValueForType(it->type); } } diff --git a/chrome/browser/ui/autofill/data_model_wrapper.cc b/chrome/browser/ui/autofill/data_model_wrapper.cc index 2272654..dd136ec 100644 --- a/chrome/browser/ui/autofill/data_model_wrapper.cc +++ b/chrome/browser/ui/autofill/data_model_wrapper.cc @@ -8,6 +8,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/ui/autofill/autofill_dialog_common.h" #include "chrome/browser/ui/autofill/autofill_dialog_models.h" #include "components/autofill/content/browser/wallet/full_wallet.h" #include "components/autofill/content/browser/wallet/wallet_address.h" @@ -27,7 +28,10 @@ DataModelWrapper::~DataModelWrapper() {} void DataModelWrapper::FillInputs(DetailInputs* inputs) { for (size_t i = 0; i < inputs->size(); ++i) { - (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type)); + DetailInput* input = &(*inputs)[i]; + input->initial_value = common::GetHardcodedValueForType(input->type); + if (input->initial_value.empty()) + input->initial_value = GetInfo(AutofillType(input->type)); } } |