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 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 external_delegate_->CheckSuggestions( | 1569 external_delegate_->CheckSuggestions( |
1570 kDefaultPageID, | 1570 kDefaultPageID, |
1571 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, | 1571 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, |
1572 autofill_manager_->GetPackedCreditCardID(4)), | 1572 autofill_manager_->GetPackedCreditCardID(4)), |
1573 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, | 1573 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, |
1574 autofill_manager_->GetPackedCreditCardID(5))); | 1574 autofill_manager_->GetPackedCreditCardID(5))); |
1575 } | 1575 } |
1576 | 1576 |
1577 // Test that we return a warning explaining that credit card profile suggestions | 1577 // Test that we return a warning explaining that credit card profile suggestions |
1578 // are unavailable when the page and the form target URL are not secure. | 1578 // are unavailable when the page and the form target URL are not secure. |
1579 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonHTTPS) { | 1579 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonSecureContext) { |
1580 // Set up our form data. | 1580 // Set up our form data. |
1581 FormData form; | 1581 FormData form; |
1582 CreateTestCreditCardFormData(&form, false, false); | 1582 CreateTestCreditCardFormData(&form, /* is_https */ false, false); |
1583 std::vector<FormData> forms(1, form); | 1583 std::vector<FormData> forms(1, form); |
1584 FormsSeen(forms); | 1584 FormsSeen(forms); |
1585 | 1585 |
1586 const FormFieldData& field = form.fields[0]; | 1586 const FormFieldData& field = form.fields[0]; |
1587 GetAutofillSuggestions(form, field); | 1587 GetAutofillSuggestions(form, field); |
1588 | 1588 |
1589 // Test that we sent the right values to the external delegate. | 1589 // Test that we sent the right values to the external delegate. |
1590 external_delegate_->CheckSuggestions( | 1590 external_delegate_->CheckSuggestions( |
1591 kDefaultPageID, | 1591 kDefaultPageID, |
1592 Suggestion( | 1592 Suggestion( |
1593 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | 1593 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
1594 "", "", -1)); | 1594 "", "", -1)); |
1595 | 1595 |
1596 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1596 // Clear the test credit cards and try again -- we shouldn't return a warning. |
1597 personal_data_.ClearCreditCards(); | 1597 personal_data_.ClearCreditCards(); |
1598 GetAutofillSuggestions(form, field); | 1598 GetAutofillSuggestions(form, field); |
1599 // Autocomplete suggestions are queried, but not Autofill. | 1599 // Autocomplete suggestions are queried, but not Autofill. |
1600 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1600 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
1601 } | 1601 } |
1602 | 1602 |
1603 // Test that we return a warning explaining that credit card profile suggestions | 1603 // Test that we return a warning explaining that credit card profile suggestions |
1604 // are unavailable when the page is secure, but the form target URL is not | 1604 // are unavailable when the page is secure, but the form action URL is valid but |
1605 // secure. | 1605 // not secure. |
1606 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_TargetURLNonHTTPS) { | 1606 TEST_F(AutofillManagerTest, |
| 1607 GetCreditCardSuggestions_SecureContext_FormActionNotHTTPS) { |
1607 // Set up our form data. | 1608 // Set up our form data. |
1608 FormData form; | 1609 FormData form; |
1609 CreateTestCreditCardFormData(&form, /* is_https= */ true, false); | 1610 CreateTestCreditCardFormData(&form, /* is_https= */ true, false); |
1610 // However we set the action (target URL) to be HTTP after all. | 1611 // However we set the action (target URL) to be HTTP after all. |
1611 form.action = GURL("http://myform.com/submit.html"); | 1612 form.action = GURL("http://myform.com/submit.html"); |
1612 std::vector<FormData> forms(1, form); | 1613 std::vector<FormData> forms(1, form); |
1613 FormsSeen(forms); | 1614 FormsSeen(forms); |
1614 | 1615 |
1615 const FormFieldData& field = form.fields[0]; | 1616 const FormFieldData& field = form.fields[0]; |
1616 GetAutofillSuggestions(form, field); | 1617 GetAutofillSuggestions(form, field); |
1617 | 1618 |
1618 // Test that we sent the right values to the external delegate. | 1619 // Test that we sent the right values to the external delegate. |
1619 external_delegate_->CheckSuggestions( | 1620 external_delegate_->CheckSuggestions( |
1620 kDefaultPageID, Suggestion(l10n_util::GetStringUTF8( | 1621 kDefaultPageID, Suggestion(l10n_util::GetStringUTF8( |
1621 IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | 1622 IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
1622 "", "", -1)); | 1623 "", "", -1)); |
1623 | 1624 |
1624 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1625 // Clear the test credit cards and try again -- we shouldn't return a warning. |
1625 personal_data_.ClearCreditCards(); | 1626 personal_data_.ClearCreditCards(); |
1626 GetAutofillSuggestions(form, field); | 1627 GetAutofillSuggestions(form, field); |
1627 // Autocomplete suggestions are queried, but not Autofill. | 1628 // Autocomplete suggestions are queried, but not Autofill. |
1628 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1629 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
1629 } | 1630 } |
1630 | 1631 |
| 1632 // Test that we return credit card suggestions for secure pages that have an |
| 1633 // empty form action target URL. |
| 1634 TEST_F(AutofillManagerTest, |
| 1635 GetCreditCardSuggestions_SecureContext_EmptyFormAction) { |
| 1636 // Set up our form data. |
| 1637 FormData form; |
| 1638 CreateTestCreditCardFormData(&form, true, false); |
| 1639 // Clear the form action. |
| 1640 form.action = GURL(); |
| 1641 std::vector<FormData> forms(1, form); |
| 1642 FormsSeen(forms); |
| 1643 |
| 1644 FormFieldData field = form.fields[1]; |
| 1645 GetAutofillSuggestions(form, field); |
| 1646 |
| 1647 // Test that we sent the right values to the external delegate. |
| 1648 external_delegate_->CheckSuggestions( |
| 1649 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1650 "3456", |
| 1651 "04/99", kVisaCard, |
| 1652 autofill_manager_->GetPackedCreditCardID(4)), |
| 1653 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1654 "8765", |
| 1655 "10/98", kMasterCard, |
| 1656 autofill_manager_->GetPackedCreditCardID(5))); |
| 1657 } |
| 1658 |
| 1659 // Test that we return credit card suggestions for secure pages that have a |
| 1660 // form action set to "javascript:something". |
| 1661 TEST_F(AutofillManagerTest, |
| 1662 GetCreditCardSuggestions_SecureContext_JavascriptFormAction) { |
| 1663 // Set up our form data. |
| 1664 FormData form; |
| 1665 CreateTestCreditCardFormData(&form, true, false); |
| 1666 // Have the form action be a javascript function (which is a valid URL). |
| 1667 form.action = GURL("javascript:alert('Hello');"); |
| 1668 std::vector<FormData> forms(1, form); |
| 1669 FormsSeen(forms); |
| 1670 |
| 1671 FormFieldData field = form.fields[1]; |
| 1672 GetAutofillSuggestions(form, field); |
| 1673 |
| 1674 // Test that we sent the right values to the external delegate. |
| 1675 external_delegate_->CheckSuggestions( |
| 1676 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1677 "3456", |
| 1678 "04/99", kVisaCard, |
| 1679 autofill_manager_->GetPackedCreditCardID(4)), |
| 1680 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1681 "8765", |
| 1682 "10/98", kMasterCard, |
| 1683 autofill_manager_->GetPackedCreditCardID(5))); |
| 1684 } |
| 1685 |
1631 // Test that we return all credit card suggestions in the case that two cards | 1686 // Test that we return all credit card suggestions in the case that two cards |
1632 // have the same obfuscated number. | 1687 // have the same obfuscated number. |
1633 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1688 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
1634 // Add a credit card with the same obfuscated number as Elvis's. | 1689 // Add a credit card with the same obfuscated number as Elvis's. |
1635 // |credit_card| will be owned by the mock PersonalDataManager. | 1690 // |credit_card| will be owned by the mock PersonalDataManager. |
1636 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 1691 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
1637 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 1692 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
1638 "5231567890123456", // Mastercard | 1693 "5231567890123456", // Mastercard |
1639 "05", "2999"); | 1694 "05", "2999"); |
1640 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1695 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
(...skipping 3660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5301 | 5356 |
5302 // The driver should always be notified. | 5357 // The driver should always be notified. |
5303 for (const FormFieldData& field : form.fields) { | 5358 for (const FormFieldData& field : form.fields) { |
5304 GetAutofillSuggestions(form, field); | 5359 GetAutofillSuggestions(form, field); |
5305 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); | 5360 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); |
5306 autofill_driver_->ClearDidInteractWithCreditCardForm(); | 5361 autofill_driver_->ClearDidInteractWithCreditCardForm(); |
5307 } | 5362 } |
5308 } | 5363 } |
5309 | 5364 |
5310 } // namespace autofill | 5365 } // namespace autofill |
OLD | NEW |