diff options
author | estade <estade@chromium.org> | 2015-05-03 15:03:28 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-03 22:03:57 +0000 |
commit | f452b25283d9e3669a63b40b12d41457d5798d46 (patch) | |
tree | 1d792655d0b8a60b5ed31f9d05a01eb8dda82c58 /components | |
parent | 644cae313fdda0d849ae84fd812274e6cea2dfb5 (diff) | |
download | chromium_src-f452b25283d9e3669a63b40b12d41457d5798d46.zip chromium_src-f452b25283d9e3669a63b40b12d41457d5798d46.tar.gz chromium_src-f452b25283d9e3669a63b40b12d41457d5798d46.tar.bz2 |
Fix crash in Autofill introduced in 8949a8b27dfb
and add a unit test to verify
BUG=483602
Review URL: https://codereview.chromium.org/1121883002
Cr-Commit-Position: refs/heads/master@{#328082}
Diffstat (limited to 'components')
-rw-r--r-- | components/autofill/core/browser/autofill_manager.cc | 21 | ||||
-rw-r--r-- | components/autofill/core/browser/autofill_manager_unittest.cc | 35 |
2 files changed, 45 insertions, 11 deletions
diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc index c0a5bff..5df3ca1 100644 --- a/components/autofill/core/browser/autofill_manager.cc +++ b/components/autofill/core/browser/autofill_manager.cc @@ -821,20 +821,19 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) { if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) return; - // Don't offer to save any cards that were recently unmasked. - if (recently_unmasked_cards_.end() != - std::find_if(recently_unmasked_cards_.begin(), - recently_unmasked_cards_.end(), - [&imported_credit_card](const CreditCard& unmasked) -> bool { - return unmasked.TypeAndLastFourDigits() == - imported_credit_card->TypeAndLastFourDigits(); - })) { - return; - } - // If credit card information was submitted, we need to confirm whether to // save it. if (imported_credit_card) { + // Don't offer to save any cards that were recently unmasked. + if (recently_unmasked_cards_.end() != + std::find_if( + recently_unmasked_cards_.begin(), recently_unmasked_cards_.end(), + [&imported_credit_card](const CreditCard& unmasked) -> bool { + return unmasked.TypeAndLastFourDigits() == + imported_credit_card->TypeAndLastFourDigits(); + })) { + return; + } client_->ConfirmSaveCreditCard( base::Bind( base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard), diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc index cc04eb0..b8466a9 100644 --- a/components/autofill/core/browser/autofill_manager_unittest.cc +++ b/components/autofill/core/browser/autofill_manager_unittest.cc @@ -3216,6 +3216,41 @@ TEST_F(AutofillManagerTest, DontOfferToSaveWalletCard) { autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, "4012888888881881"); autofill_manager_->OnFormSubmitted(form); + + // The rest of this test is a regression test for http://crbug.com/483602. + // The goal is not to crash. + EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)); + for (size_t i = 0; i < form.fields.size(); ++i) { + form.fields[i].value.clear(); + } + autofill_manager_->FillOrPreviewCreditCardForm( + AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, form, + form.fields[0], card, 0); + autofill_manager_->OnUnmaskResponse(response); + autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, + "4012888888881881"); + + form = FormData(); + test::CreateTestAddressFormData(&form); + forms[0] = form; + FormsSeen(forms); + for (size_t i = 0; i < form.fields.size(); ++i) { + if (form.fields[i].name == ASCIIToUTF16("firstname")) + form.fields[i].value = ASCIIToUTF16("Flo"); + else if (form.fields[i].name == ASCIIToUTF16("lastname")) + form.fields[i].value = ASCIIToUTF16("Master"); + else if (form.fields[i].name == ASCIIToUTF16("addr1")) + form.fields[i].value = ASCIIToUTF16("123 Maple"); + else if (form.fields[i].name == ASCIIToUTF16("city")) + form.fields[i].value = ASCIIToUTF16("Dallas"); + else if (form.fields[i].name == ASCIIToUTF16("state")) + form.fields[i].value = ASCIIToUTF16("Texas"); + else if (form.fields[i].name == ASCIIToUTF16("zipcode")) + form.fields[i].value = ASCIIToUTF16("77401"); + else if (form.fields[i].name == ASCIIToUTF16("country")) + form.fields[i].value = ASCIIToUTF16("US"); + } + autofill_manager_->OnFormSubmitted(form); } } // namespace autofill |