| 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 13 matching lines...) Expand all Loading... |
| 24 #include "components/autofill/core/browser/autofill_download_manager.h" | 24 #include "components/autofill/core/browser/autofill_download_manager.h" |
| 25 #include "components/autofill/core/browser/autofill_manager.h" | 25 #include "components/autofill/core/browser/autofill_manager.h" |
| 26 #include "components/autofill/core/browser/autofill_profile.h" | 26 #include "components/autofill/core/browser/autofill_profile.h" |
| 27 #include "components/autofill/core/browser/autofill_test_utils.h" | 27 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 28 #include "components/autofill/core/browser/credit_card.h" | 28 #include "components/autofill/core/browser/credit_card.h" |
| 29 #include "components/autofill/core/browser/personal_data_manager.h" | 29 #include "components/autofill/core/browser/personal_data_manager.h" |
| 30 #include "components/autofill/core/browser/popup_item_ids.h" | 30 #include "components/autofill/core/browser/popup_item_ids.h" |
| 31 #include "components/autofill/core/browser/test_autofill_client.h" | 31 #include "components/autofill/core/browser/test_autofill_client.h" |
| 32 #include "components/autofill/core/browser/test_autofill_driver.h" | 32 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 33 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 33 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| 34 #include "components/autofill/core/browser/validation.h" |
| 34 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 35 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 35 #include "components/autofill/core/common/autofill_pref_names.h" | 36 #include "components/autofill/core/common/autofill_pref_names.h" |
| 36 #include "components/autofill/core/common/autofill_switches.h" | 37 #include "components/autofill/core/common/autofill_switches.h" |
| 37 #include "components/autofill/core/common/form_data.h" | 38 #include "components/autofill/core/common/form_data.h" |
| 38 #include "components/autofill/core/common/form_field_data.h" | 39 #include "components/autofill/core/common/form_field_data.h" |
| 39 #include "grit/components_strings.h" | 40 #include "grit/components_strings.h" |
| 40 #include "net/url_request/url_request_test_util.h" | 41 #include "net/url_request/url_request_test_util.h" |
| 41 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 143 } |
| 143 | 144 |
| 144 void ClearAutofillProfiles() { | 145 void ClearAutofillProfiles() { |
| 145 web_profiles_.clear(); | 146 web_profiles_.clear(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void ClearCreditCards() { | 149 void ClearCreditCards() { |
| 149 local_credit_cards_.clear(); | 150 local_credit_cards_.clear(); |
| 150 } | 151 } |
| 151 | 152 |
| 153 // Create Elvis card with whitespace in the credit card number. |
| 154 void CreateTestCreditCardWithWhitespace() { |
| 155 ClearCreditCards(); |
| 156 CreditCard* credit_card = new CreditCard; |
| 157 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 158 "4234 5678 9012 3456", // Visa |
| 159 "04", "2012"); |
| 160 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); |
| 161 local_credit_cards_.push_back(credit_card); |
| 162 } |
| 163 |
| 164 // Create Elvis card with separator characters in the credit card number. |
| 165 void CreateTestCreditCardWithSeparators() { |
| 166 ClearCreditCards(); |
| 167 CreditCard* credit_card = new CreditCard; |
| 168 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 169 "4234-5678-9012-3456", // Visa |
| 170 "04", "2012"); |
| 171 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); |
| 172 local_credit_cards_.push_back(credit_card); |
| 173 } |
| 174 |
| 152 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { | 175 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { |
| 153 ClearCreditCards(); | 176 ClearCreditCards(); |
| 154 CreditCard* credit_card = new CreditCard; | 177 CreditCard* credit_card = new CreditCard; |
| 155 test::SetCreditCardInfo(credit_card, "Miku Hatsune", | 178 test::SetCreditCardInfo(credit_card, "Miku Hatsune", |
| 156 "4234567890654321", // Visa | 179 "4234567890654321", // Visa |
| 157 month, year); | 180 month, year); |
| 158 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 181 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 159 local_credit_cards_.push_back(credit_card); | 182 local_credit_cards_.push_back(credit_card); |
| 160 } | 183 } |
| 161 | 184 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 179 profile = new AutofillProfile; | 202 profile = new AutofillProfile; |
| 180 test::SetProfileInfo( | 203 test::SetProfileInfo( |
| 181 profile, "", "", "", "", "", "", "", "", "", "", "", ""); | 204 profile, "", "", "", "", "", "", "", "", "", "", "", ""); |
| 182 profile->set_guid("00000000-0000-0000-0000-000000000003"); | 205 profile->set_guid("00000000-0000-0000-0000-000000000003"); |
| 183 profiles->push_back(profile); | 206 profiles->push_back(profile); |
| 184 } | 207 } |
| 185 | 208 |
| 186 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { | 209 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { |
| 187 CreditCard* credit_card = new CreditCard; | 210 CreditCard* credit_card = new CreditCard; |
| 188 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 211 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 189 "4234 5678 9012 3456", // Visa | 212 "4234567890123456", // Visa |
| 190 "04", "2012"); | 213 "04", "2012"); |
| 191 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); | 214 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| 192 credit_cards->push_back(credit_card); | 215 credit_cards->push_back(credit_card); |
| 193 | 216 |
| 194 credit_card = new CreditCard; | 217 credit_card = new CreditCard; |
| 195 test::SetCreditCardInfo(credit_card, "Buddy Holly", | 218 test::SetCreditCardInfo(credit_card, "Buddy Holly", |
| 196 "5187654321098765", // Mastercard | 219 "5187654321098765", // Mastercard |
| 197 "10", "2014"); | 220 "10", "2014"); |
| 198 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 221 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| 199 credit_cards->push_back(credit_card); | 222 credit_cards->push_back(credit_card); |
| (...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 const char guid[] = "00000000-0000-0000-0000-000000000004"; | 1555 const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| 1533 int response_page_id = 0; | 1556 int response_page_id = 0; |
| 1534 FormData response_data; | 1557 FormData response_data; |
| 1535 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1558 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1536 MakeFrontendID(guid, std::string()), | 1559 MakeFrontendID(guid, std::string()), |
| 1537 &response_page_id, &response_data); | 1560 &response_page_id, &response_data); |
| 1538 ExpectFilledCreditCardFormElvis( | 1561 ExpectFilledCreditCardFormElvis( |
| 1539 response_page_id, response_data, kDefaultPageID, false); | 1562 response_page_id, response_data, kDefaultPageID, false); |
| 1540 } | 1563 } |
| 1541 | 1564 |
| 1565 // Test that whitespace is stripped from the credit card number. |
| 1566 TEST_F(AutofillManagerTest, FillCreditCardFormStripCardNumberWhitespace) { |
| 1567 // Same as the SetUp(), but generate Elvis card with whitespace in credit |
| 1568 // card number. |
| 1569 personal_data_.CreateTestCreditCardWithWhitespace(); |
| 1570 // Set up our form data. |
| 1571 FormData form; |
| 1572 CreateTestCreditCardFormData(&form, true, false); |
| 1573 std::vector<FormData> forms(1, form); |
| 1574 FormsSeen(forms); |
| 1575 |
| 1576 const char guid[] = "00000000-0000-0000-0000-000000000008"; |
| 1577 int response_page_id = 0; |
| 1578 FormData response_data; |
| 1579 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1580 MakeFrontendID(guid, std::string()), |
| 1581 &response_page_id, &response_data); |
| 1582 ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| 1583 kDefaultPageID, false); |
| 1584 } |
| 1585 |
| 1586 // Test that separator characters are stripped from the credit card number. |
| 1587 TEST_F(AutofillManagerTest, FillCreditCardFormStripCardNumberSeparators) { |
| 1588 // Same as the SetUp(), but generate Elvis card with separator characters in |
| 1589 // credit card number. |
| 1590 personal_data_.CreateTestCreditCardWithSeparators(); |
| 1591 // Set up our form data. |
| 1592 FormData form; |
| 1593 CreateTestCreditCardFormData(&form, true, false); |
| 1594 std::vector<FormData> forms(1, form); |
| 1595 FormsSeen(forms); |
| 1596 |
| 1597 const char guid[] = "00000000-0000-0000-0000-000000000009"; |
| 1598 int response_page_id = 0; |
| 1599 FormData response_data; |
| 1600 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1601 MakeFrontendID(guid, std::string()), |
| 1602 &response_page_id, &response_data); |
| 1603 ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| 1604 kDefaultPageID, false); |
| 1605 } |
| 1606 |
| 1542 // Test that we correctly fill a credit card form with month input type. | 1607 // Test that we correctly fill a credit card form with month input type. |
| 1543 // 1. year empty, month empty | 1608 // 1. year empty, month empty |
| 1544 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { | 1609 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { |
| 1545 // Same as the SetUp(), but generate 4 credit cards with year month | 1610 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1546 // combination. | 1611 // combination. |
| 1547 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); | 1612 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); |
| 1548 // Set up our form data. | 1613 // Set up our form data. |
| 1549 FormData form; | 1614 FormData form; |
| 1550 CreateTestCreditCardFormData(&form, true, true); | 1615 CreateTestCreditCardFormData(&form, true, true); |
| 1551 std::vector<FormData> forms(1, form); | 1616 std::vector<FormData> forms(1, form); |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 // Tests that credit card data are saved for forms on https | 2661 // Tests that credit card data are saved for forms on https |
| 2597 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTPS) { | 2662 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTPS) { |
| 2598 TestSaveCreditCards(true); | 2663 TestSaveCreditCards(true); |
| 2599 } | 2664 } |
| 2600 | 2665 |
| 2601 // Tests that credit card data are saved for forms on http | 2666 // Tests that credit card data are saved for forms on http |
| 2602 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTP) { | 2667 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTP) { |
| 2603 TestSaveCreditCards(false); | 2668 TestSaveCreditCards(false); |
| 2604 } | 2669 } |
| 2605 | 2670 |
| 2671 // Tests that credit card data are saved when autocomplete=off for CC field. |
| 2672 TEST_F(AutofillManagerTest, CreditCardSavedWhenAutocompleteOff) { |
| 2673 // Set up our form data. |
| 2674 FormData form; |
| 2675 CreateTestCreditCardFormData(&form, false, false); |
| 2676 |
| 2677 // Set "autocomplete=off" for cardnumber field. |
| 2678 form.fields[1].should_autocomplete = false; |
| 2679 |
| 2680 std::vector<FormData> forms(1, form); |
| 2681 FormsSeen(forms); |
| 2682 |
| 2683 // Edit the data, and submit |
| 2684 form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 2685 form.fields[2].value = ASCIIToUTF16("11"); |
| 2686 form.fields[3].value = ASCIIToUTF16("2017"); |
| 2687 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(1); |
| 2688 FormSubmitted(form); |
| 2689 } |
| 2690 |
| 2691 // Tests that credit card data are not saved when CC number does not pass the |
| 2692 // Luhn test. |
| 2693 TEST_F(AutofillManagerTest, InvalidCreditCardNumberIsNotSaved) { |
| 2694 // Set up our form data. |
| 2695 FormData form; |
| 2696 CreateTestCreditCardFormData(&form, true, false); |
| 2697 std::vector<FormData> forms(1, form); |
| 2698 FormsSeen(forms); |
| 2699 |
| 2700 // Edit the data, and submit. |
| 2701 std::string card("4408041234567890"); |
| 2702 ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card))); |
| 2703 form.fields[1].value = ASCIIToUTF16(card); |
| 2704 form.fields[2].value = ASCIIToUTF16("11"); |
| 2705 form.fields[3].value = ASCIIToUTF16("2017"); |
| 2706 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(0); |
| 2707 FormSubmitted(form); |
| 2708 } |
| 2709 |
| 2606 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { | 2710 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { |
| 2607 FormData form; | 2711 FormData form; |
| 2608 form.name = ASCIIToUTF16("MyForm"); | 2712 form.name = ASCIIToUTF16("MyForm"); |
| 2609 form.origin = GURL("http://myform.com/form.html"); | 2713 form.origin = GURL("http://myform.com/form.html"); |
| 2610 form.action = GURL("http://myform.com/submit.html"); | 2714 form.action = GURL("http://myform.com/submit.html"); |
| 2611 | 2715 |
| 2612 std::vector<ServerFieldTypeSet> expected_types; | 2716 std::vector<ServerFieldTypeSet> expected_types; |
| 2613 std::vector<base::string16> expected_values; | 2717 std::vector<base::string16> expected_values; |
| 2614 | 2718 |
| 2615 // These fields should all match. | 2719 // These fields should all match. |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3308 | 3412 |
| 3309 external_delegate_->CheckSuggestions( | 3413 external_delegate_->CheckSuggestions( |
| 3310 kDefaultPageID, | 3414 kDefaultPageID, |
| 3311 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", | 3415 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", |
| 3312 1), | 3416 1), |
| 3313 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", | 3417 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", |
| 3314 2)); | 3418 2)); |
| 3315 } | 3419 } |
| 3316 | 3420 |
| 3317 } // namespace autofill | 3421 } // namespace autofill |
| OLD | NEW |