Commit 3772282d authored by estade@chromium.org's avatar estade@chromium.org

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
parent d8e7d60e
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/autofill/autofill_dialog_common.h" #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_field.h"
#include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/autofill_type.h"
#include "grit/chromium_strings.h" #include "grit/chromium_strings.h"
...@@ -176,5 +178,14 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( ...@@ -176,5 +178,14 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent(
return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 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 common
} // namespace autofill } // namespace autofill
...@@ -46,6 +46,10 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( ...@@ -46,6 +46,10 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent(
AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent(
DialogSection section); 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 common
} // namespace autofill } // namespace autofill
......
...@@ -498,6 +498,64 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { ...@@ -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 // This test makes sure that picking a profile variant in the Autofill
// popup works as expected. // popup works as expected.
IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
......
...@@ -1176,7 +1176,7 @@ void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { ...@@ -1176,7 +1176,7 @@ void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) {
DetailInputs* inputs = MutableRequestedFieldsForSection(section); DetailInputs* inputs = MutableRequestedFieldsForSection(section);
for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) {
it->initial_value.clear(); it->initial_value = common::GetHardcodedValueForType(it->type);
} }
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.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 "chrome/browser/ui/autofill/autofill_dialog_models.h"
#include "components/autofill/content/browser/wallet/full_wallet.h" #include "components/autofill/content/browser/wallet/full_wallet.h"
#include "components/autofill/content/browser/wallet/wallet_address.h" #include "components/autofill/content/browser/wallet/wallet_address.h"
...@@ -27,7 +28,10 @@ DataModelWrapper::~DataModelWrapper() {} ...@@ -27,7 +28,10 @@ DataModelWrapper::~DataModelWrapper() {}
void DataModelWrapper::FillInputs(DetailInputs* inputs) { void DataModelWrapper::FillInputs(DetailInputs* inputs) {
for (size_t i = 0; i < inputs->size(); ++i) { 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));
} }
} }
......
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