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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 }; | 463 }; |
464 | 464 |
465 class TestAutofillManager : public AutofillManager { | 465 class TestAutofillManager : public AutofillManager { |
466 public: | 466 public: |
467 TestAutofillManager(AutofillDriver* driver, | 467 TestAutofillManager(AutofillDriver* driver, |
468 AutofillClient* client, | 468 AutofillClient* client, |
469 TestPersonalDataManager* personal_data) | 469 TestPersonalDataManager* personal_data) |
470 : AutofillManager(driver, client, personal_data), | 470 : AutofillManager(driver, client, personal_data), |
471 personal_data_(personal_data), | 471 personal_data_(personal_data), |
472 autofill_enabled_(true), | 472 autofill_enabled_(true), |
473 credit_card_upload_enabled_(true), | 473 credit_card_upload_enabled_(false), |
474 credit_card_was_uploaded_(false), | 474 credit_card_was_uploaded_(false), |
475 expect_all_unknown_possible_types_(false), | 475 expect_all_unknown_possible_types_(false), |
476 expected_observed_submission_(true) { | 476 expected_observed_submission_(true) { |
477 set_payments_client( | 477 set_payments_client( |
478 new TestPaymentsClient(driver->GetURLRequestContext(), this)); | 478 new TestPaymentsClient(driver->GetURLRequestContext(), this)); |
479 } | 479 } |
480 ~TestAutofillManager() override {} | 480 ~TestAutofillManager() override {} |
481 | 481 |
482 bool IsAutofillEnabled() const override { return autofill_enabled_; } | 482 bool IsAutofillEnabled() const override { return autofill_enabled_; } |
483 | 483 |
(...skipping 3272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3756 | 3756 |
3757 EXPECT_EQ(ASCIIToUTF16("02"), | 3757 EXPECT_EQ(ASCIIToUTF16("02"), |
3758 autofill_manager_->unmask_request_.card.GetRawInfo( | 3758 autofill_manager_->unmask_request_.card.GetRawInfo( |
3759 CREDIT_CARD_EXP_MONTH)); | 3759 CREDIT_CARD_EXP_MONTH)); |
3760 EXPECT_EQ(ASCIIToUTF16("2018"), | 3760 EXPECT_EQ(ASCIIToUTF16("2018"), |
3761 autofill_manager_->unmask_request_.card.GetRawInfo( | 3761 autofill_manager_->unmask_request_.card.GetRawInfo( |
3762 CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 3762 CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
3763 } | 3763 } |
3764 | 3764 |
3765 TEST_F(AutofillManagerTest, UploadCreditCard) { | 3765 TEST_F(AutofillManagerTest, UploadCreditCard) { |
| 3766 autofill_manager_->set_credit_card_upload_enabled(true); |
| 3767 |
3766 // Create, fill and submit an address form in order to establish a recent | 3768 // Create, fill and submit an address form in order to establish a recent |
3767 // profile which can be selected for the upload request. | 3769 // profile which can be selected for the upload request. |
3768 FormData address_form; | 3770 FormData address_form; |
3769 test::CreateTestAddressFormData(&address_form); | 3771 test::CreateTestAddressFormData(&address_form); |
3770 FormsSeen(std::vector<FormData>(1, address_form)); | 3772 FormsSeen(std::vector<FormData>(1, address_form)); |
3771 ManuallyFillAddressForm(&address_form); | 3773 ManuallyFillAddressForm(&address_form); |
3772 FormSubmitted(address_form); | 3774 FormSubmitted(address_form); |
3773 | 3775 |
3774 // Set up our credit card form data. | 3776 // Set up our credit card form data. |
3775 FormData credit_card_form; | 3777 FormData credit_card_form; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3810 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 3812 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
3811 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 3813 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
3812 | 3814 |
3813 // The save prompt should be shown instead of doing an upload. | 3815 // The save prompt should be shown instead of doing an upload. |
3814 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_)).Times(1); | 3816 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_)).Times(1); |
3815 FormSubmitted(credit_card_form); | 3817 FormSubmitted(credit_card_form); |
3816 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 3818 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
3817 } | 3819 } |
3818 | 3820 |
3819 TEST_F(AutofillManagerTest, DontUploadCreditCardIfCvcUnavailable) { | 3821 TEST_F(AutofillManagerTest, DontUploadCreditCardIfCvcUnavailable) { |
| 3822 autofill_manager_->set_credit_card_upload_enabled(true); |
| 3823 |
3820 // Create, fill and submit an address form in order to establish a recent | 3824 // Create, fill and submit an address form in order to establish a recent |
3821 // profile which can be selected for the upload request. | 3825 // profile which can be selected for the upload request. |
3822 FormData address_form; | 3826 FormData address_form; |
3823 test::CreateTestAddressFormData(&address_form); | 3827 test::CreateTestAddressFormData(&address_form); |
3824 FormsSeen(std::vector<FormData>(1, address_form)); | 3828 FormsSeen(std::vector<FormData>(1, address_form)); |
3825 ManuallyFillAddressForm(&address_form); | 3829 ManuallyFillAddressForm(&address_form); |
3826 FormSubmitted(address_form); | 3830 FormSubmitted(address_form); |
3827 | 3831 |
3828 // Set up our credit card form data. | 3832 // Set up our credit card form data. |
3829 FormData credit_card_form; | 3833 FormData credit_card_form; |
3830 CreateTestCreditCardFormData(&credit_card_form, true, false); | 3834 CreateTestCreditCardFormData(&credit_card_form, true, false); |
3831 FormsSeen(std::vector<FormData>(1, credit_card_form)); | 3835 FormsSeen(std::vector<FormData>(1, credit_card_form)); |
3832 | 3836 |
3833 // Edit the data, and submit | 3837 // Edit the data, and submit |
3834 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); | 3838 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
3835 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 3839 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
3836 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 3840 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
3837 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 3841 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
3838 credit_card_form.fields[4].value = ASCIIToUTF16(""); // CVC MISSING | 3842 credit_card_form.fields[4].value = ASCIIToUTF16(""); // CVC MISSING |
3839 | 3843 |
3840 // The save prompt should be shown instead of doing an upload. | 3844 // Neither a local save nor an upload should happen in this case. |
3841 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_)).Times(1); | 3845 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_)).Times(0); |
3842 FormSubmitted(credit_card_form); | 3846 FormSubmitted(credit_card_form); |
3843 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 3847 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
3844 } | 3848 } |
3845 | 3849 |
3846 TEST_F(AutofillManagerTest, DontUploadCreditCardIfNoMatchingProfileAvailable) { | 3850 TEST_F(AutofillManagerTest, DontUploadCreditCardIfNoMatchingProfileAvailable) { |
| 3851 autofill_manager_->set_credit_card_upload_enabled(true); |
| 3852 |
3847 // Create, fill and submit an address form in order to establish a recent | 3853 // Create, fill and submit an address form in order to establish a recent |
3848 // profile which can be selected for the upload request. | 3854 // profile which can be selected for the upload request. |
3849 FormData address_form; | 3855 FormData address_form; |
3850 test::CreateTestAddressFormData(&address_form); | 3856 test::CreateTestAddressFormData(&address_form); |
3851 FormsSeen(std::vector<FormData>(1, address_form)); | 3857 FormsSeen(std::vector<FormData>(1, address_form)); |
3852 ManuallyFillAddressForm(&address_form); | 3858 ManuallyFillAddressForm(&address_form); |
3853 FormSubmitted(address_form); | 3859 FormSubmitted(address_form); |
3854 | 3860 |
3855 // Set up our credit card form data. | 3861 // Set up our credit card form data. |
3856 FormData credit_card_form; | 3862 FormData credit_card_form; |
3857 CreateTestCreditCardFormData(&credit_card_form, true, false); | 3863 CreateTestCreditCardFormData(&credit_card_form, true, false); |
3858 FormsSeen(std::vector<FormData>(1, credit_card_form)); | 3864 FormsSeen(std::vector<FormData>(1, credit_card_form)); |
3859 | 3865 |
3860 // Edit the data, and submit | 3866 // Edit the data, and submit |
3861 // The address form has "Flo Master" but the credit card has "Bob Master". | 3867 // The address form has "Flo Master" but the credit card has "Bob Master". |
3862 credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master"); | 3868 credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master"); |
3863 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 3869 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
3864 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 3870 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
3865 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 3871 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
3866 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 3872 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
3867 | 3873 |
3868 // The save prompt should be shown instead of doing an upload. | 3874 // Neither a local save nor an upload should happen in this case. |
3869 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_)).Times(1); | 3875 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_)).Times(0); |
3870 FormSubmitted(credit_card_form); | 3876 FormSubmitted(credit_card_form); |
3871 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 3877 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
3872 } | 3878 } |
3873 | 3879 |
3874 TEST_F(AutofillManagerTest, DontUploadCreditCardIfUploadDetailsFails) { | 3880 TEST_F(AutofillManagerTest, DontUploadCreditCardIfUploadDetailsFails) { |
| 3881 autofill_manager_->set_credit_card_upload_enabled(true); |
| 3882 |
3875 // Anything other than "en-US" will cause GetUploadDetails to return a failure | 3883 // Anything other than "en-US" will cause GetUploadDetails to return a failure |
3876 // response. | 3884 // response. |
3877 autofill_manager_->set_app_locale("pt-BR"); | 3885 autofill_manager_->set_app_locale("pt-BR"); |
3878 | 3886 |
3879 // Create, fill and submit an address form in order to establish a recent | 3887 // Create, fill and submit an address form in order to establish a recent |
3880 // profile which can be selected for the upload request. | 3888 // profile which can be selected for the upload request. |
3881 FormData address_form; | 3889 FormData address_form; |
3882 test::CreateTestAddressFormData(&address_form); | 3890 test::CreateTestAddressFormData(&address_form); |
3883 FormsSeen(std::vector<FormData>(1, address_form)); | 3891 FormsSeen(std::vector<FormData>(1, address_form)); |
3884 ManuallyFillAddressForm(&address_form); | 3892 ManuallyFillAddressForm(&address_form); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4173 FormsSeen(mixed_forms); | 4181 FormsSeen(mixed_forms); |
4174 | 4182 |
4175 // Suggestions should always be displayed. | 4183 // Suggestions should always be displayed. |
4176 for (const FormFieldData& field : mixed_form.fields) { | 4184 for (const FormFieldData& field : mixed_form.fields) { |
4177 GetAutofillSuggestions(mixed_form, field); | 4185 GetAutofillSuggestions(mixed_form, field); |
4178 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 4186 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
4179 } | 4187 } |
4180 } | 4188 } |
4181 | 4189 |
4182 } // namespace autofill | 4190 } // namespace autofill |
OLD | NEW |