| 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 5489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5500 | 5500 |
| 5501 // Verify that the correct histogram entry (and only that) was logged. | 5501 // Verify that the correct histogram entry (and only that) was logged. |
| 5502 ExpectUniqueCardUploadDecision( | 5502 ExpectUniqueCardUploadDecision( |
| 5503 histogram_tester, AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); | 5503 histogram_tester, AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); |
| 5504 // Verify that the correct UKM was logged. | 5504 // Verify that the correct UKM was logged. |
| 5505 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); | 5505 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); |
| 5506 } | 5506 } |
| 5507 | 5507 |
| 5508 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5508 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5509 #if defined(OS_ANDROID) | 5509 #if defined(OS_ANDROID) |
| 5510 #define MAYBE_UploadCreditCard_NamesMatchLoosely \ | 5510 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleInitial \ |
| 5511 DISABLED_UploadCreditCard_NamesMatchLoosely | 5511 DISABLED_UploadCreditCard_CreditCardFormHasMiddleInitial |
| 5512 #else | 5512 #else |
| 5513 #define MAYBE_UploadCreditCard_NamesMatchLoosely \ | 5513 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleInitial \ |
| 5514 UploadCreditCard_NamesMatchLoosely | 5514 UploadCreditCard_CreditCardFormHasMiddleInitial |
| 5515 #endif | 5515 #endif |
| 5516 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesMatchLoosely) { | 5516 TEST_F(AutofillManagerTest, |
| 5517 MAYBE_UploadCreditCard_CreditCardFormHasMiddleInitial) { |
| 5517 EnableUkmLogging(); | 5518 EnableUkmLogging(); |
| 5518 personal_data_.ClearAutofillProfiles(); | 5519 personal_data_.ClearAutofillProfiles(); |
| 5519 autofill_manager_->set_credit_card_upload_enabled(true); | 5520 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5520 | 5521 |
| 5521 // Create, fill and submit two address forms with different names. | 5522 // Create, fill and submit two address forms with different names. |
| 5522 FormData address_form1, address_form2; | 5523 FormData address_form1, address_form2; |
| 5523 test::CreateTestAddressFormData(&address_form1); | 5524 test::CreateTestAddressFormData(&address_form1); |
| 5524 test::CreateTestAddressFormData(&address_form2); | 5525 test::CreateTestAddressFormData(&address_form2); |
| 5525 | 5526 FormsSeen({address_form1, address_form2}); |
| 5526 std::vector<FormData> address_forms; | |
| 5527 address_forms.push_back(address_form1); | |
| 5528 address_forms.push_back(address_form2); | |
| 5529 FormsSeen(address_forms); | |
| 5530 | 5527 |
| 5531 // Names can be different case. | 5528 // Names can be different case. |
| 5532 ManuallyFillAddressForm("flo", "master", "77401", "US", &address_form1); | 5529 ManuallyFillAddressForm("flo", "master", "77401", "US", &address_form1); |
| 5533 FormSubmitted(address_form1); | 5530 FormSubmitted(address_form1); |
| 5534 | 5531 |
| 5535 // And they can have a middle initial even if the other names don't. | 5532 // And they can have a middle initial even if the other names don't. |
| 5536 ManuallyFillAddressForm("Flo W", "Master", "77401", "US", &address_form2); | 5533 ManuallyFillAddressForm("Flo W", "Master", "77401", "US", &address_form2); |
| 5537 FormSubmitted(address_form2); | 5534 FormSubmitted(address_form2); |
| 5538 | 5535 |
| 5539 // Set up our credit card form data. | 5536 // Set up our credit card form data. |
| 5540 FormData credit_card_form; | 5537 FormData credit_card_form; |
| 5541 CreateTestCreditCardFormData(&credit_card_form, true, false); | 5538 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5542 FormsSeen(std::vector<FormData>(1, credit_card_form)); | 5539 FormsSeen({credit_card_form}); |
| 5543 | 5540 |
| 5544 // Edit the data, but use the name with a middle initial *and* period, and | 5541 // Edit the data, but use the name with a middle initial *and* period, and |
| 5545 // submit. | 5542 // submit. |
| 5546 credit_card_form.fields[0].value = ASCIIToUTF16("Flo W. Master"); | 5543 credit_card_form.fields[0].value = ASCIIToUTF16("Flo W. Master"); |
| 5547 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 5544 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5548 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 5545 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5549 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 5546 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5550 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 5547 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5551 | 5548 |
| 5552 base::HistogramTester histogram_tester; | 5549 base::HistogramTester histogram_tester; |
| 5553 | 5550 |
| 5554 // Names match loosely, upload should happen. | 5551 // Names match loosely, upload should happen. |
| 5555 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 5552 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5556 FormSubmitted(credit_card_form); | 5553 FormSubmitted(credit_card_form); |
| 5557 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 5554 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5558 | 5555 |
| 5559 // Verify that the correct histogram entry (and only that) was logged. | 5556 // Verify that the correct histogram entry (and only that) was logged. |
| 5560 ExpectUniqueCardUploadDecision(histogram_tester, | 5557 ExpectUniqueCardUploadDecision(histogram_tester, |
| 5561 AutofillMetrics::UPLOAD_OFFERED); | 5558 AutofillMetrics::UPLOAD_OFFERED); |
| 5562 // Verify that the correct UKM was logged. | 5559 // Verify that the correct UKM was logged. |
| 5563 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 5560 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 5564 } | 5561 } |
| 5565 | 5562 |
| 5566 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5563 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5567 #if defined(OS_ANDROID) | 5564 #if defined(OS_ANDROID) |
| 5565 #define MAYBE_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial \ |
| 5566 DISABLED_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial |
| 5567 #else |
| 5568 #define MAYBE_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial \ |
| 5569 UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial |
| 5570 #endif |
| 5571 TEST_F(AutofillManagerTest, |
| 5572 MAYBE_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial) { |
| 5573 EnableUkmLogging(); |
| 5574 personal_data_.ClearAutofillProfiles(); |
| 5575 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5576 |
| 5577 // Create, fill and submit two address forms with different names. |
| 5578 FormData address_form1, address_form2; |
| 5579 test::CreateTestAddressFormData(&address_form1); |
| 5580 test::CreateTestAddressFormData(&address_form2); |
| 5581 FormsSeen({address_form1, address_form2}); |
| 5582 |
| 5583 // Names can have different variations of middle initials. |
| 5584 ManuallyFillAddressForm("flo w.", "master", "77401", "US", &address_form1); |
| 5585 FormSubmitted(address_form1); |
| 5586 ManuallyFillAddressForm("Flo W", "Master", "77401", "US", &address_form2); |
| 5587 FormSubmitted(address_form2); |
| 5588 |
| 5589 // Set up our credit card form data. |
| 5590 FormData credit_card_form; |
| 5591 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5592 FormsSeen({credit_card_form}); |
| 5593 |
| 5594 // Edit the data, but do not use middle initial. |
| 5595 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
| 5596 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5597 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5598 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5599 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5600 |
| 5601 base::HistogramTester histogram_tester; |
| 5602 |
| 5603 // Names match loosely, upload should happen. |
| 5604 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5605 FormSubmitted(credit_card_form); |
| 5606 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5607 |
| 5608 // Verify that the correct histogram entry (and only that) was logged. |
| 5609 ExpectUniqueCardUploadDecision(histogram_tester, |
| 5610 AutofillMetrics::UPLOAD_OFFERED); |
| 5611 // Verify that the correct UKM was logged. |
| 5612 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 5613 } |
| 5614 |
| 5615 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5616 #if defined(OS_ANDROID) |
| 5617 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleName \ |
| 5618 DISABLED_UploadCreditCard_CreditCardFormHasMiddleName |
| 5619 #else |
| 5620 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleName \ |
| 5621 UploadCreditCard_CreditCardFormHasMiddleName |
| 5622 #endif |
| 5623 TEST_F(AutofillManagerTest, |
| 5624 MAYBE_UploadCreditCard_CreditCardFormHasMiddleName) { |
| 5625 EnableUkmLogging(); |
| 5626 personal_data_.ClearAutofillProfiles(); |
| 5627 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5628 |
| 5629 // Create, fill and submit address form without middle name. |
| 5630 FormData address_form; |
| 5631 test::CreateTestAddressFormData(&address_form); |
| 5632 FormsSeen({address_form}); |
| 5633 ManuallyFillAddressForm("John", "Adams", "77401", "US", &address_form); |
| 5634 FormSubmitted(address_form); |
| 5635 |
| 5636 // Set up our credit card form data. |
| 5637 FormData credit_card_form; |
| 5638 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5639 FormsSeen({credit_card_form}); |
| 5640 |
| 5641 // Edit the name by adding a middle name. |
| 5642 credit_card_form.fields[0].value = ASCIIToUTF16("John Quincy Adams"); |
| 5643 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5644 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5645 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5646 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5647 |
| 5648 base::HistogramTester histogram_tester; |
| 5649 |
| 5650 // Names match loosely, upload should happen. |
| 5651 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5652 FormSubmitted(credit_card_form); |
| 5653 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5654 |
| 5655 // Verify that the correct histogram entry (and only that) was logged. |
| 5656 ExpectUniqueCardUploadDecision(histogram_tester, |
| 5657 AutofillMetrics::UPLOAD_OFFERED); |
| 5658 // Verify that the correct UKM was logged. |
| 5659 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 5660 } |
| 5661 |
| 5662 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5663 #if defined(OS_ANDROID) |
| 5664 #define MAYBE_UploadCreditCard_CreditCardFormRemovesMiddleName \ |
| 5665 DISABLED_UploadCreditCard_CreditCardFormRemovesMiddleName |
| 5666 #else |
| 5667 #define MAYBE_UploadCreditCard_CreditCardFormRemovesMiddleName \ |
| 5668 UploadCreditCard_CreditCardFormRemovesMiddleName |
| 5669 #endif |
| 5670 TEST_F(AutofillManagerTest, |
| 5671 MAYBE_UploadCreditCard_CreditCardFormRemovesMiddleName) { |
| 5672 EnableUkmLogging(); |
| 5673 personal_data_.ClearAutofillProfiles(); |
| 5674 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5675 |
| 5676 // Create, fill and submit address form with middle name. |
| 5677 FormData address_form; |
| 5678 test::CreateTestAddressFormData(&address_form); |
| 5679 FormsSeen({address_form}); |
| 5680 ManuallyFillAddressForm("John Quincy", "Adams", "77401", "US", &address_form); |
| 5681 FormSubmitted(address_form); |
| 5682 |
| 5683 // Set up our credit card form data. |
| 5684 FormData credit_card_form; |
| 5685 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5686 FormsSeen({credit_card_form}); |
| 5687 |
| 5688 // Edit the name by removing middle name. |
| 5689 credit_card_form.fields[0].value = ASCIIToUTF16("John Adams"); |
| 5690 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5691 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5692 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5693 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5694 |
| 5695 base::HistogramTester histogram_tester; |
| 5696 |
| 5697 // Names match loosely, upload should happen. |
| 5698 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5699 FormSubmitted(credit_card_form); |
| 5700 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5701 |
| 5702 // Verify that the correct histogram entry (and only that) was logged. |
| 5703 ExpectUniqueCardUploadDecision(histogram_tester, |
| 5704 AutofillMetrics::UPLOAD_OFFERED); |
| 5705 // Verify that the correct UKM was logged. |
| 5706 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 5707 } |
| 5708 |
| 5709 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5710 #if defined(OS_ANDROID) |
| 5568 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ | 5711 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ |
| 5569 DISABLED_UploadCreditCard_NamesHaveToMatch | 5712 DISABLED_UploadCreditCard_NamesHaveToMatch |
| 5570 #else | 5713 #else |
| 5571 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ | 5714 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ |
| 5572 UploadCreditCard_NamesHaveToMatch | 5715 UploadCreditCard_NamesHaveToMatch |
| 5573 #endif | 5716 #endif |
| 5574 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) { | 5717 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) { |
| 5575 EnableUkmLogging(); | 5718 EnableUkmLogging(); |
| 5576 personal_data_.ClearAutofillProfiles(); | 5719 personal_data_.ClearAutofillProfiles(); |
| 5577 autofill_manager_->set_credit_card_upload_enabled(true); | 5720 autofill_manager_->set_credit_card_upload_enabled(true); |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6335 | 6478 |
| 6336 // Wait for upload to complete (will check expected types as well). | 6479 // Wait for upload to complete (will check expected types as well). |
| 6337 autofill_manager_->WaitForAsyncUploadProcess(); | 6480 autofill_manager_->WaitForAsyncUploadProcess(); |
| 6338 | 6481 |
| 6339 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6482 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 6340 EXPECT_NE(uploaded_available_types.end(), | 6483 EXPECT_NE(uploaded_available_types.end(), |
| 6341 uploaded_available_types.find(autofill::PASSWORD)); | 6484 uploaded_available_types.find(autofill::PASSWORD)); |
| 6342 } | 6485 } |
| 6343 | 6486 |
| 6344 } // namespace autofill | 6487 } // namespace autofill |
| OLD | NEW |