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 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); | 916 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); |
917 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", | 917 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", |
918 "2017"); | 918 "2017"); |
919 card->SetTypeForMaskedCard(kVisaCard); | 919 card->SetTypeForMaskedCard(kVisaCard); |
920 | 920 |
921 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) | 921 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) |
922 .Times(AtLeast(1)); | 922 .Times(AtLeast(1)); |
923 autofill_manager_->FillOrPreviewCreditCardForm( | 923 autofill_manager_->FillOrPreviewCreditCardForm( |
924 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, | 924 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, |
925 form->fields[0], *card); | 925 form->fields[0], *card); |
926 | |
927 #if defined(OS_IOS) | |
928 // Filling out the entire form on iOS requires requesting autofill on each | |
929 // of the form fields. | |
930 autofill_manager_->FillOrPreviewCreditCardForm( | |
931 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, | |
932 form->fields[1], *card); | |
933 autofill_manager_->FillOrPreviewCreditCardForm( | |
934 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, | |
935 form->fields[2], *card); | |
936 autofill_manager_->FillOrPreviewCreditCardForm( | |
937 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, | |
938 form->fields[3], *card); | |
939 #endif // defined(OS_IOS) | |
940 } | 926 } |
941 | 927 |
942 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. | 928 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. |
943 CardUnmaskDelegate* full_card_unmask_delegate() { | 929 CardUnmaskDelegate* full_card_unmask_delegate() { |
944 DCHECK(autofill_manager_->full_card_request_); | 930 DCHECK(autofill_manager_->full_card_request_); |
945 return static_cast<CardUnmaskDelegate*>( | 931 return static_cast<CardUnmaskDelegate*>( |
946 autofill_manager_->full_card_request_.get()); | 932 autofill_manager_->full_card_request_.get()); |
947 } | 933 } |
948 | 934 |
949 protected: | 935 protected: |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1820 FormFieldData* month_field = nullptr; | 1806 FormFieldData* month_field = nullptr; |
1821 for (size_t i = 0; i < form.fields.size(); ++i) { | 1807 for (size_t i = 0; i < form.fields.size(); ++i) { |
1822 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) | 1808 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) |
1823 number_field = &form.fields[i]; | 1809 number_field = &form.fields[i]; |
1824 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) | 1810 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) |
1825 name_field = &form.fields[i]; | 1811 name_field = &form.fields[i]; |
1826 else if (form.fields[i].name == ASCIIToUTF16("ccmonth")) | 1812 else if (form.fields[i].name == ASCIIToUTF16("ccmonth")) |
1827 month_field = &form.fields[i]; | 1813 month_field = &form.fields[i]; |
1828 } | 1814 } |
1829 | 1815 |
1830 // Empty form - whole form is Autofilled (except on iOS). | 1816 // Empty form - whole form is Autofilled. |
1831 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); | 1817 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
1832 #if defined(OS_IOS) | |
1833 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); | |
1834 #else | |
1835 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); | 1818 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); |
1836 #endif // defined(OS_IOS) | |
1837 | 1819 |
1838 // If the user has entered a value, it won't be overridden. | 1820 // If the user has entered a value, it won't be overridden. |
1839 number_field->value = ASCIIToUTF16("gibberish"); | 1821 number_field->value = ASCIIToUTF16("gibberish"); |
1840 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); | 1822 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
1841 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); | 1823 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); |
1842 | 1824 |
1843 // But if that value is removed, it will be Autofilled (except on iOS). | 1825 // But if that value is removed, it will be Autofilled. |
1844 number_field->value.clear(); | 1826 number_field->value.clear(); |
1845 #if defined(OS_IOS) | |
1846 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); | |
1847 #else | |
1848 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); | 1827 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); |
1849 #endif // defined(OS_IOS) | |
1850 | 1828 |
1851 // When part of the section is Autofilled, only fill the initiating field. | 1829 // When part of the section is Autofilled, only fill the initiating field. |
1852 month_field->is_autofilled = true; | 1830 month_field->is_autofilled = true; |
1853 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); | 1831 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); |
1854 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); | 1832 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
1855 } | 1833 } |
1856 | 1834 |
1857 // Test that we correctly fill a credit card form. | 1835 // Test that we correctly fill a credit card form. |
1858 TEST_F(AutofillManagerTest, FillCreditCardForm) { | 1836 TEST_F(AutofillManagerTest, FillCreditCardForm) { |
1859 // Set up our form data. | 1837 // Set up our form data. |
(...skipping 3256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5116 FormsSeen(mixed_forms); | 5094 FormsSeen(mixed_forms); |
5117 | 5095 |
5118 // Suggestions should always be displayed. | 5096 // Suggestions should always be displayed. |
5119 for (const FormFieldData& field : mixed_form.fields) { | 5097 for (const FormFieldData& field : mixed_form.fields) { |
5120 GetAutofillSuggestions(mixed_form, field); | 5098 GetAutofillSuggestions(mixed_form, field); |
5121 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5099 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
5122 } | 5100 } |
5123 } | 5101 } |
5124 | 5102 |
5125 } // namespace autofill | 5103 } // namespace autofill |
OLD | NEW |