Skip to content

Commit

Permalink
Use credit card name for full name when adding new autofill profiles …
Browse files Browse the repository at this point in the history
…with requestAutocomplete dialog.

BUG=235275

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196820 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
estade@chromium.org committed Apr 26, 2013
1 parent 68046af commit 3c69316
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
25 changes: 22 additions & 3 deletions chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs,
for (DetailOutputMap::const_iterator iter = detail_outputs.begin();
iter != detail_outputs.end(); ++iter) {
if (!iter->second.empty()) {
if (iter->first->type == ADDRESS_HOME_COUNTRY ||
iter->first->type == ADDRESS_BILLING_COUNTRY) {
form_group->SetInfo(iter->first->type,
AutofillFieldType type = iter->first->type;
if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) {
form_group->SetInfo(type,
iter->second,
g_browser_process->GetApplicationLocale());
} else {
Expand Down Expand Up @@ -1894,6 +1894,10 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
AutofillProfile profile;
FillFormGroupFromOutputs(output, &profile);

// For billing, the profile name has to come from the CC section.
if (section == SECTION_BILLING)
profile.SetRawInfo(NAME_FULL, GetCcName());

if (ShouldSaveDetailsLocally())
GetManager()->SaveImportedProfile(profile);

Expand Down Expand Up @@ -1936,6 +1940,21 @@ void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) {
}
}

string16 AutofillDialogControllerImpl::GetCcName() {
DCHECK(SectionIsActive(SECTION_CC));

CreditCard card;
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(SECTION_CC);
if (!wrapper) {
DetailOutputMap output;
view_->GetUserInput(SECTION_CC, &output);
FillFormGroupFromOutputs(output, &card);
wrapper.reset(new AutofillCreditCardWrapper(&card));
}

return wrapper->GetInfo(CREDIT_CARD_NAME);
}

SuggestionsMenuModel* AutofillDialogControllerImpl::
SuggestionsMenuModelForSection(DialogSection section) {
switch (section) {
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/autofill/autofill_dialog_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ class AutofillDialogControllerImpl : public AutofillDialogController,
// Sets the CVC result on |form_structure_| to the value in |cvc|.
void SetCvcResult(const string16& cvc);

// Gets the name from SECTION_CC (if that section is active). This might
// come from manual user input or the active suggestion.
string16 GetCcName();

// Gets the SuggestionsMenuModel for |section|.
SuggestionsMenuModel* SuggestionsMenuModelForSection(DialogSection section);
const SuggestionsMenuModel* SuggestionsMenuModelForSection(
Expand Down
48 changes: 48 additions & 0 deletions chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,54 @@ TEST_F(AutofillDialogControllerTest, EditAutofillProfile) {
}
}

// Tests that adding an autofill profile and then submitting works.
TEST_F(AutofillDialogControllerTest, AddAutofillProfile) {
EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);

AutofillProfile full_profile(test::GetFullProfile());
controller()->GetTestingManager()->AddTestingProfile(&full_profile);

ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING);
// Activate the "Add billing address" menu item.
model->ActivatedAt(model->GetItemCount() - 2);

// Fill in the inputs from the profile.
DetailOutputMap outputs;
const DetailInputs& inputs =
controller()->RequestedFieldsForSection(SECTION_BILLING);
AutofillProfile full_profile2(test::GetFullProfile2());
for (size_t i = 0; i < inputs.size(); ++i) {
const DetailInput& input = inputs[i];
outputs[&input] = full_profile2.GetInfo(input.type, "en-US");
}
controller()->GetView()->SetUserInput(SECTION_BILLING, outputs);

// Fill in some CC info. The name field will be used to fill in the billing
// address name in the newly minted AutofillProfile.
DetailOutputMap cc_outputs;
const DetailInputs& cc_inputs =
controller()->RequestedFieldsForSection(SECTION_CC);
for (size_t i = 0; i < cc_inputs.size(); ++i) {
cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NAME ?
ASCIIToUTF16("Bill Money") : ASCIIToUTF16("111");
}
controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs);

controller()->OnAccept();
const AutofillProfile& added_profile =
controller()->GetTestingManager()->imported_profile();

const DetailInputs& shipping_inputs =
controller()->RequestedFieldsForSection(SECTION_SHIPPING);
for (size_t i = 0; i < shipping_inputs.size(); ++i) {
const DetailInput& input = shipping_inputs[i];
string16 expected = input.type == NAME_FULL ?
ASCIIToUTF16("Bill Money") :
full_profile2.GetInfo(input.type, "en-US");
EXPECT_EQ(expected, added_profile.GetInfo(input.type, "en-US"));
}
}

TEST_F(AutofillDialogControllerTest, VerifyCvv) {
SetUpWallet();

Expand Down
17 changes: 17 additions & 0 deletions components/autofill/browser/autofill_common_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ AutofillProfile GetFullProfile() {
return profile;
}

AutofillProfile GetFullProfile2() {
AutofillProfile profile(base::GenerateGUID());
SetProfileInfo(&profile,
"Jane",
"A.",
"Smith",
"jsmith@example.com",
"ACME",
"123 Main Street",
"Unit 1",
"Greensdale", "MI",
"48838",
"US",
"13105557889");
return profile;
}

void SetProfileInfo(AutofillProfile* profile,
const char* first_name, const char* middle_name,
const char* last_name, const char* email, const char* company,
Expand Down
3 changes: 3 additions & 0 deletions components/autofill/browser/autofill_common_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ void CreateTestFormField(const char* label,
// Returns a profile full of dummy info.
AutofillProfile GetFullProfile();

// Returns a profile full of dummy info, different to the above.
AutofillProfile GetFullProfile2();

// A unit testing utility that is common to a number of the Autofill unit
// tests. |SetProfileInfo| provides a quick way to populate a profile with
// c-strings.
Expand Down

0 comments on commit 3c69316

Please sign in to comment.