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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), | 704 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), |
705 testing::SaveArg<2>(response_data)))); | 705 testing::SaveArg<2>(response_data)))); |
706 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); | 706 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); |
707 } | 707 } |
708 | 708 |
709 int MakeFrontendID(const SuggestionBackendID& cc_sid, | 709 int MakeFrontendID(const SuggestionBackendID& cc_sid, |
710 const SuggestionBackendID& profile_sid) const { | 710 const SuggestionBackendID& profile_sid) const { |
711 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); | 711 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); |
712 } | 712 } |
713 | 713 |
| 714 bool WillFillCreditCardNumber(const FormData& form, |
| 715 const FormFieldData& field) { |
| 716 return autofill_manager_->WillFillCreditCardNumber(form, field); |
| 717 } |
| 718 |
714 protected: | 719 protected: |
715 base::MessageLoop message_loop_; | 720 base::MessageLoop message_loop_; |
716 TestAutofillClient autofill_client_; | 721 TestAutofillClient autofill_client_; |
717 scoped_ptr<MockAutofillDriver> autofill_driver_; | 722 scoped_ptr<MockAutofillDriver> autofill_driver_; |
718 scoped_ptr<TestAutofillManager> autofill_manager_; | 723 scoped_ptr<TestAutofillManager> autofill_manager_; |
719 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; | 724 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; |
720 TestPersonalDataManager personal_data_; | 725 TestPersonalDataManager personal_data_; |
721 }; | 726 }; |
722 | 727 |
723 class TestFormStructure : public FormStructure { | 728 class TestFormStructure : public FormStructure { |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1470 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
1466 MakeFrontendID(card_id, profile_id), | 1471 MakeFrontendID(card_id, profile_id), |
1467 &response_page_id, &response_data); | 1472 &response_page_id, &response_data); |
1468 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, | 1473 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, |
1469 false, true); | 1474 false, true); |
1470 | 1475 |
1471 EXPECT_EQ(1U, profile->use_count()); | 1476 EXPECT_EQ(1U, profile->use_count()); |
1472 EXPECT_NE(base::Time(), profile->use_date()); | 1477 EXPECT_NE(base::Time(), profile->use_date()); |
1473 } | 1478 } |
1474 | 1479 |
| 1480 TEST_F(AutofillManagerTest, WillFillCreditCardNumber) { |
| 1481 // Set up our form data. |
| 1482 FormData form; |
| 1483 CreateTestCreditCardFormData(&form, true, false); |
| 1484 std::vector<FormData> forms(1, form); |
| 1485 FormsSeen(forms); |
| 1486 |
| 1487 FormFieldData* number_field = nullptr; |
| 1488 FormFieldData* name_field = nullptr; |
| 1489 FormFieldData* month_field = nullptr; |
| 1490 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 1491 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) |
| 1492 number_field = &form.fields[i]; |
| 1493 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) |
| 1494 name_field = &form.fields[i]; |
| 1495 else if (form.fields[i].name == ASCIIToUTF16("ccmonth")) |
| 1496 month_field = &form.fields[i]; |
| 1497 } |
| 1498 |
| 1499 // Empty form - whole form is Autofilled. |
| 1500 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
| 1501 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); |
| 1502 // If the user has entered a value, it won't be overridden. |
| 1503 number_field->value = ASCIIToUTF16("gibberish"); |
| 1504 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
| 1505 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); |
| 1506 number_field->value.clear(); |
| 1507 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); |
| 1508 |
| 1509 // When part of the section is Autofilled, only fill the initiating field. |
| 1510 month_field->is_autofilled = true; |
| 1511 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); |
| 1512 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
| 1513 } |
| 1514 |
1475 // Test that we correctly fill an address form from an auxiliary profile. | 1515 // Test that we correctly fill an address form from an auxiliary profile. |
1476 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { | 1516 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { |
1477 personal_data_.ClearAutofillProfiles(); | 1517 personal_data_.ClearAutofillProfiles(); |
1478 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1518 #if defined(OS_MACOSX) && !defined(OS_IOS) |
1479 autofill_client_.GetPrefs()->SetBoolean( | 1519 autofill_client_.GetPrefs()->SetBoolean( |
1480 ::autofill::prefs::kAutofillUseMacAddressBook, true); | 1520 ::autofill::prefs::kAutofillUseMacAddressBook, true); |
1481 #else | 1521 #else |
1482 autofill_client_.GetPrefs()->SetBoolean( | 1522 autofill_client_.GetPrefs()->SetBoolean( |
1483 ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); | 1523 ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); |
1484 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1524 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3130 | 3170 |
3131 external_delegate_->CheckSuggestions( | 3171 external_delegate_->CheckSuggestions( |
3132 kDefaultPageID, | 3172 kDefaultPageID, |
3133 Suggestion( | 3173 Suggestion( |
3134 "Visa \xE2\x8B\xAF" | 3174 "Visa \xE2\x8B\xAF" |
3135 "3456", | 3175 "3456", |
3136 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); | 3176 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); |
3137 } | 3177 } |
3138 | 3178 |
3139 } // namespace autofill | 3179 } // namespace autofill |
OLD | NEW |