| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 #include <memory> | 10 #include <memory> | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 177   } | 177   } | 
| 178 | 178 | 
| 179   void AddCreditCard(const CreditCard& credit_card) override { | 179   void AddCreditCard(const CreditCard& credit_card) override { | 
| 180     std::unique_ptr<CreditCard> local_credit_card = | 180     std::unique_ptr<CreditCard> local_credit_card = | 
| 181         base::MakeUnique<CreditCard>(credit_card); | 181         base::MakeUnique<CreditCard>(credit_card); | 
| 182     local_credit_card->set_modification_date(base::Time::Now()); | 182     local_credit_card->set_modification_date(base::Time::Now()); | 
| 183     local_credit_cards_.push_back(std::move(local_credit_card)); | 183     local_credit_cards_.push_back(std::move(local_credit_card)); | 
| 184   } | 184   } | 
| 185 | 185 | 
| 186   void AddFullServerCreditCard(const CreditCard& credit_card) override { | 186   void AddFullServerCreditCard(const CreditCard& credit_card) override { | 
| 187     std::unique_ptr<CreditCard> server_credit_card = | 187     AddServerCreditCard(credit_card); | 
| 188         base::MakeUnique<CreditCard>(credit_card); |  | 
| 189     server_credit_card->set_modification_date(base::Time::Now()); |  | 
| 190     server_credit_cards_.push_back(std::move(server_credit_card)); |  | 
| 191   } | 188   } | 
| 192 | 189 | 
| 193   void RecordUseOf(const AutofillDataModel& data_model) override { | 190   void RecordUseOf(const AutofillDataModel& data_model) override { | 
| 194     CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); | 191     CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); | 
| 195     if (credit_card) | 192     if (credit_card) | 
| 196       credit_card->RecordAndLogUse(); | 193       credit_card->RecordAndLogUse(); | 
| 197 | 194 | 
| 198     AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); | 195     AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); | 
| 199     if (profile) | 196     if (profile) | 
| 200       profile->RecordAndLogUse(); | 197       profile->RecordAndLogUse(); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 220     } | 217     } | 
| 221   } | 218   } | 
| 222 | 219 | 
| 223   void ClearAutofillProfiles() { web_profiles_.clear(); } | 220   void ClearAutofillProfiles() { web_profiles_.clear(); } | 
| 224 | 221 | 
| 225   void ClearCreditCards() { | 222   void ClearCreditCards() { | 
| 226     local_credit_cards_.clear(); | 223     local_credit_cards_.clear(); | 
| 227     server_credit_cards_.clear(); | 224     server_credit_cards_.clear(); | 
| 228   } | 225   } | 
| 229 | 226 | 
|  | 227   void AddServerCreditCard(const CreditCard& credit_card) { | 
|  | 228     std::unique_ptr<CreditCard> server_credit_card = | 
|  | 229         base::MakeUnique<CreditCard>(credit_card); | 
|  | 230     server_credit_card->set_modification_date(base::Time::Now()); | 
|  | 231     server_credit_cards_.push_back(std::move(server_credit_card)); | 
|  | 232   } | 
|  | 233 | 
| 230   // Create Elvis card with whitespace in the credit card number. | 234   // Create Elvis card with whitespace in the credit card number. | 
| 231   void CreateTestCreditCardWithWhitespace() { | 235   void CreateTestCreditCardWithWhitespace() { | 
| 232     ClearCreditCards(); | 236     ClearCreditCards(); | 
| 233     std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 237     std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 
| 234     test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 238     test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 
| 235                             "4234 5678 9012 3456",  // Visa | 239                             "4234 5678 9012 3456",  // Visa | 
| 236                             "04", "2999"); | 240                             "04", "2999"); | 
| 237     credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | 241     credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | 
| 238     local_credit_cards_.push_back(std::move(credit_card)); | 242     local_credit_cards_.push_back(std::move(credit_card)); | 
| 239   } | 243   } | 
| (...skipping 4389 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4629 | 4633 | 
| 4630   // Edit the data, and submit. | 4634   // Edit the data, and submit. | 
| 4631   credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); | 4635   credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); | 
| 4632   credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 4636   credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 
| 4633   credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 4637   credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 
| 4634   credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 4638   credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 
| 4635   credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 4639   credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 
| 4636 | 4640 | 
| 4637   base::HistogramTester histogram_tester; | 4641   base::HistogramTester histogram_tester; | 
| 4638 | 4642 | 
|  | 4643   EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 
| 4639   FormSubmitted(credit_card_form); | 4644   FormSubmitted(credit_card_form); | 
| 4640   EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 4645   EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 
| 4641 | 4646 | 
| 4642   // Server did not send a server_id, expect copy of card is not stored. | 4647   // Server did not send a server_id, expect copy of card is not stored. | 
| 4643   EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); | 4648   EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); | 
| 4644 | 4649 | 
| 4645   // Verify that the correct histogram entry (and only that) was logged. | 4650   // Verify that the correct histogram entry (and only that) was logged. | 
| 4646   histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", | 4651   histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", | 
| 4647                                       AutofillMetrics::UPLOAD_OFFERED, 1); | 4652                                       AutofillMetrics::UPLOAD_OFFERED, 1); | 
| 4648   // Verify that the correct UKM was logged. | 4653   // Verify that the correct UKM was logged. | 
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5574 | 5579 | 
| 5575   // Verify that the correct histogram entry (and only that) was logged. | 5580   // Verify that the correct histogram entry (and only that) was logged. | 
| 5576   histogram_tester.ExpectUniqueSample( | 5581   histogram_tester.ExpectUniqueSample( | 
| 5577       "Autofill.CardUploadDecisionExpanded", | 5582       "Autofill.CardUploadDecisionExpanded", | 
| 5578       AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED, 1); | 5583       AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED, 1); | 
| 5579   // Verify that the correct UKM was logged. | 5584   // Verify that the correct UKM was logged. | 
| 5580   ExpectCardUploadDecisionUkm( | 5585   ExpectCardUploadDecisionUkm( | 
| 5581       AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); | 5586       AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); | 
| 5582 } | 5587 } | 
| 5583 | 5588 | 
|  | 5589 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 
|  | 5590 #if defined(OS_ANDROID) | 
|  | 5591 #define MAYBE_DuplicateMaskedCreditCard DISABLED_DuplicatedMaskedCreditCard | 
|  | 5592 #else | 
|  | 5593 #define MAYBE_DuplicateMaskedCreditCard DuplicateMaskedCreditCard | 
|  | 5594 #endif | 
|  | 5595 TEST_F(AutofillManagerTest, MAYBE_DuplicateMaskedCreditCard) { | 
|  | 5596   personal_data_.ClearAutofillProfiles(); | 
|  | 5597   autofill_manager_->set_credit_card_upload_enabled(true); | 
|  | 5598   autofill_manager_->set_app_locale("en-US"); | 
|  | 5599 | 
|  | 5600   // Create, fill and submit an address form in order to establish a recent | 
|  | 5601   // profile which can be selected for the upload request. | 
|  | 5602   FormData address_form; | 
|  | 5603   test::CreateTestAddressFormData(&address_form); | 
|  | 5604   FormsSeen(std::vector<FormData>(1, address_form)); | 
|  | 5605   ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); | 
|  | 5606   FormSubmitted(address_form); | 
|  | 5607 | 
|  | 5608   // Add a masked credit card whose |TypeAndLastFourDigits| matches what we will | 
|  | 5609   // below. | 
|  | 5610   CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 
|  | 5611   test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", "2017"); | 
|  | 5612   credit_card.SetNetworkForMaskedCard(kVisaCard); | 
|  | 5613   personal_data_.AddServerCreditCard(credit_card); | 
|  | 5614 | 
|  | 5615   // Set up our credit card form data. | 
|  | 5616   FormData credit_card_form; | 
|  | 5617   CreateTestCreditCardFormData(&credit_card_form, true, false); | 
|  | 5618   FormsSeen(std::vector<FormData>(1, credit_card_form)); | 
|  | 5619 | 
|  | 5620   // Edit the data, and submit. | 
|  | 5621   credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); | 
|  | 5622   credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 
|  | 5623   credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 
|  | 5624   credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 
|  | 5625   credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 
|  | 5626 | 
|  | 5627   // The save prompt should be shown. | 
|  | 5628   EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)); | 
|  | 5629   FormSubmitted(credit_card_form); | 
|  | 5630   EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 
|  | 5631 } | 
|  | 5632 | 
| 5584 // Verify that typing "gmail" will match "theking@gmail.com" and | 5633 // Verify that typing "gmail" will match "theking@gmail.com" and | 
| 5585 // "buddy@gmail.com" when substring matching is enabled. | 5634 // "buddy@gmail.com" when substring matching is enabled. | 
| 5586 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { | 5635 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { | 
| 5587   // Token matching is currently behind a flag. | 5636   // Token matching is currently behind a flag. | 
| 5588   base::CommandLine::ForCurrentProcess()->AppendSwitch( | 5637   base::CommandLine::ForCurrentProcess()->AppendSwitch( | 
| 5589       switches::kEnableSuggestionsWithSubstringMatch); | 5638       switches::kEnableSuggestionsWithSubstringMatch); | 
| 5590 | 5639 | 
| 5591   // Set up our form data. | 5640   // Set up our form data. | 
| 5592   FormData form; | 5641   FormData form; | 
| 5593   test::CreateTestAddressFormData(&form); | 5642   test::CreateTestAddressFormData(&form); | 
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6190 | 6239 | 
| 6191   // Wait for upload to complete (will check expected types as well). | 6240   // Wait for upload to complete (will check expected types as well). | 
| 6192   autofill_manager_->WaitForAsyncUploadProcess(); | 6241   autofill_manager_->WaitForAsyncUploadProcess(); | 
| 6193 | 6242 | 
| 6194   EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6243   EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 
| 6195   EXPECT_NE(uploaded_available_types.end(), | 6244   EXPECT_NE(uploaded_available_types.end(), | 
| 6196             uploaded_available_types.find(autofill::PASSWORD)); | 6245             uploaded_available_types.find(autofill::PASSWORD)); | 
| 6197 } | 6246 } | 
| 6198 | 6247 | 
| 6199 }  // namespace autofill | 6248 }  // namespace autofill | 
| OLD | NEW | 
|---|