Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 2534413006: [Credit Card] Uses 4 dots in ellipsis (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 FormData form; 1432 FormData form;
1433 CreateTestCreditCardFormData(&form, true, false); 1433 CreateTestCreditCardFormData(&form, true, false);
1434 std::vector<FormData> forms(1, form); 1434 std::vector<FormData> forms(1, form);
1435 FormsSeen(forms); 1435 FormsSeen(forms);
1436 1436
1437 FormFieldData field = form.fields[1]; 1437 FormFieldData field = form.fields[1];
1438 GetAutofillSuggestions(form, field); 1438 GetAutofillSuggestions(form, field);
1439 1439
1440 // Test that we sent the right values to the external delegate. 1440 // Test that we sent the right values to the external delegate.
1441 external_delegate_->CheckSuggestions( 1441 external_delegate_->CheckSuggestions(
1442 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1442 kDefaultPageID, Suggestion("Visa "
1443 "\xE2\x80\xA2\xE2\x80\x86"
1444 "\xE2\x80\xA2\xE2\x80\x86"
1445 "\xE2\x80\xA2\xE2\x80\x86"
1446 "\xE2\x80\xA2\xE2\x80\x86"
1443 "3456", 1447 "3456",
1444 "04/99", kVisaCard, 1448 "04/99", kVisaCard,
1445 autofill_manager_->GetPackedCreditCardID(4)), 1449 autofill_manager_->GetPackedCreditCardID(4)),
1446 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1450 Suggestion("MasterCard "
1451 "\xE2\x80\xA2\xE2\x80\x86"
1452 "\xE2\x80\xA2\xE2\x80\x86"
1453 "\xE2\x80\xA2\xE2\x80\x86"
1454 "\xE2\x80\xA2\xE2\x80\x86"
1447 "8765", 1455 "8765",
1448 "10/98", kMasterCard, 1456 "10/98", kMasterCard,
1449 autofill_manager_->GetPackedCreditCardID(5))); 1457 autofill_manager_->GetPackedCreditCardID(5)));
1450 } 1458 }
1451 1459
1452 // Test that we return all credit card profile suggestions when the triggering 1460 // Test that we return all credit card profile suggestions when the triggering
1453 // field has whitespace in it. 1461 // field has whitespace in it.
1454 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) { 1462 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) {
1455 // Set up our form data. 1463 // Set up our form data.
1456 FormData form; 1464 FormData form;
1457 CreateTestCreditCardFormData(&form, true, false); 1465 CreateTestCreditCardFormData(&form, true, false);
1458 std::vector<FormData> forms(1, form); 1466 std::vector<FormData> forms(1, form);
1459 FormsSeen(forms); 1467 FormsSeen(forms);
1460 1468
1461 FormFieldData field = form.fields[1]; 1469 FormFieldData field = form.fields[1];
1462 field.value = ASCIIToUTF16(" "); 1470 field.value = ASCIIToUTF16(" ");
1463 GetAutofillSuggestions(form, field); 1471 GetAutofillSuggestions(form, field);
1464 1472
1465 // Test that we sent the right values to the external delegate. 1473 // Test that we sent the right values to the external delegate.
1466 external_delegate_->CheckSuggestions( 1474 external_delegate_->CheckSuggestions(
1467 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1475 kDefaultPageID, Suggestion("Visa "
1476 "\xE2\x80\xA2\xE2\x80\x86"
1477 "\xE2\x80\xA2\xE2\x80\x86"
1478 "\xE2\x80\xA2\xE2\x80\x86"
1479 "\xE2\x80\xA2\xE2\x80\x86"
1468 "3456", 1480 "3456",
1469 "04/99", kVisaCard, 1481 "04/99", kVisaCard,
1470 autofill_manager_->GetPackedCreditCardID(4)), 1482 autofill_manager_->GetPackedCreditCardID(4)),
1471 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1483 Suggestion("MasterCard "
1484 "\xE2\x80\xA2\xE2\x80\x86"
1485 "\xE2\x80\xA2\xE2\x80\x86"
1486 "\xE2\x80\xA2\xE2\x80\x86"
1487 "\xE2\x80\xA2\xE2\x80\x86"
1472 "8765", 1488 "8765",
1473 "10/98", kMasterCard, 1489 "10/98", kMasterCard,
1474 autofill_manager_->GetPackedCreditCardID(5))); 1490 autofill_manager_->GetPackedCreditCardID(5)));
1475 } 1491 }
1476 1492
1477 // Test that we return all credit card profile suggestions when the triggering 1493 // Test that we return all credit card profile suggestions when the triggering
1478 // field has stop characters in it, which should be removed. 1494 // field has stop characters in it, which should be removed.
1479 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { 1495 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) {
1480 // Set up our form data. 1496 // Set up our form data.
1481 FormData form; 1497 FormData form;
1482 CreateTestCreditCardFormData(&form, true, false); 1498 CreateTestCreditCardFormData(&form, true, false);
1483 std::vector<FormData> forms(1, form); 1499 std::vector<FormData> forms(1, form);
1484 FormsSeen(forms); 1500 FormsSeen(forms);
1485 1501
1486 FormFieldData field = form.fields[1]; 1502 FormFieldData field = form.fields[1];
1487 field.value = ASCIIToUTF16("____-____-____-____"); 1503 field.value = ASCIIToUTF16("____-____-____-____");
1488 GetAutofillSuggestions(form, field); 1504 GetAutofillSuggestions(form, field);
1489 1505
1490 // Test that we sent the right values to the external delegate. 1506 // Test that we sent the right values to the external delegate.
1491 external_delegate_->CheckSuggestions( 1507 external_delegate_->CheckSuggestions(
1492 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1508 kDefaultPageID, Suggestion("Visa "
1509 "\xE2\x80\xA2\xE2\x80\x86"
1510 "\xE2\x80\xA2\xE2\x80\x86"
1511 "\xE2\x80\xA2\xE2\x80\x86"
1512 "\xE2\x80\xA2\xE2\x80\x86"
1493 "3456", 1513 "3456",
1494 "04/99", kVisaCard, 1514 "04/99", kVisaCard,
1495 autofill_manager_->GetPackedCreditCardID(4)), 1515 autofill_manager_->GetPackedCreditCardID(4)),
1496 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1516 Suggestion("MasterCard "
1517 "\xE2\x80\xA2\xE2\x80\x86"
1518 "\xE2\x80\xA2\xE2\x80\x86"
1519 "\xE2\x80\xA2\xE2\x80\x86"
1520 "\xE2\x80\xA2\xE2\x80\x86"
1497 "8765", 1521 "8765",
1498 "10/98", kMasterCard, 1522 "10/98", kMasterCard,
1499 autofill_manager_->GetPackedCreditCardID(5))); 1523 autofill_manager_->GetPackedCreditCardID(5)));
1500 } 1524 }
1501 1525
1502 // Test that we return all credit card profile suggestions when the triggering 1526 // Test that we return all credit card profile suggestions when the triggering
1503 // field has stop characters in it and some input. 1527 // field has stop characters in it and some input.
1504 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { 1528 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) {
1505 // Add a credit card with particular numbers that we will attempt to recall. 1529 // Add a credit card with particular numbers that we will attempt to recall.
1506 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 1530 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
1507 test::SetCreditCardInfo(credit_card.get(), "John Smith", 1531 test::SetCreditCardInfo(credit_card.get(), "John Smith",
1508 "5255667890123123", // Mastercard 1532 "5255667890123123", // Mastercard
1509 "08", "2017"); 1533 "08", "2017");
1510 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 1534 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
1511 autofill_manager_->AddCreditCard(std::move(credit_card)); 1535 autofill_manager_->AddCreditCard(std::move(credit_card));
1512 1536
1513 // Set up our form data. 1537 // Set up our form data.
1514 FormData form; 1538 FormData form;
1515 CreateTestCreditCardFormData(&form, true, false); 1539 CreateTestCreditCardFormData(&form, true, false);
1516 std::vector<FormData> forms(1, form); 1540 std::vector<FormData> forms(1, form);
1517 FormsSeen(forms); 1541 FormsSeen(forms);
1518 1542
1519 FormFieldData field = form.fields[1]; 1543 FormFieldData field = form.fields[1];
1520 1544
1521 field.value = ASCIIToUTF16("5255-66__-____-____"); 1545 field.value = ASCIIToUTF16("5255-66__-____-____");
1522 GetAutofillSuggestions(form, field); 1546 GetAutofillSuggestions(form, field);
1523 1547
1524 // Test that we sent the right value to the external delegate. 1548 // Test that we sent the right value to the external delegate.
1525 external_delegate_->CheckSuggestions( 1549 external_delegate_->CheckSuggestions(
1526 kDefaultPageID, Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1550 kDefaultPageID, Suggestion("MasterCard "
1551 "\xE2\x80\xA2\xE2\x80\x86"
1552 "\xE2\x80\xA2\xE2\x80\x86"
1553 "\xE2\x80\xA2\xE2\x80\x86"
1554 "\xE2\x80\xA2\xE2\x80\x86"
1527 "3123", 1555 "3123",
1528 "08/17", kMasterCard, 1556 "08/17", kMasterCard,
1529 autofill_manager_->GetPackedCreditCardID(7))); 1557 autofill_manager_->GetPackedCreditCardID(7)));
1530 } 1558 }
1531 1559
1532 // Test that we return only matching credit card profile suggestions when the 1560 // Test that we return only matching credit card profile suggestions when the
1533 // selected form field has been partially filled out. 1561 // selected form field has been partially filled out.
1534 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_MatchCharacter) { 1562 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_MatchCharacter) {
1535 // Set up our form data. 1563 // Set up our form data.
1536 FormData form; 1564 FormData form;
1537 CreateTestCreditCardFormData(&form, true, false); 1565 CreateTestCreditCardFormData(&form, true, false);
1538 std::vector<FormData> forms(1, form); 1566 std::vector<FormData> forms(1, form);
1539 FormsSeen(forms); 1567 FormsSeen(forms);
1540 1568
1541 FormFieldData field; 1569 FormFieldData field;
1542 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); 1570 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field);
1543 GetAutofillSuggestions(form, field); 1571 GetAutofillSuggestions(form, field);
1544 1572
1545 // Test that we sent the right values to the external delegate. 1573 // Test that we sent the right values to the external delegate.
1546 external_delegate_->CheckSuggestions( 1574 external_delegate_->CheckSuggestions(
1547 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1575 kDefaultPageID, Suggestion("Visa "
1576 "\xE2\x80\xA2\xE2\x80\x86"
1577 "\xE2\x80\xA2\xE2\x80\x86"
1578 "\xE2\x80\xA2\xE2\x80\x86"
1579 "\xE2\x80\xA2\xE2\x80\x86"
1548 "3456", 1580 "3456",
1549 "04/99", kVisaCard, 1581 "04/99", kVisaCard,
1550 autofill_manager_->GetPackedCreditCardID(4))); 1582 autofill_manager_->GetPackedCreditCardID(4)));
1551 } 1583 }
1552 1584
1553 // Test that we return credit card profile suggestions when the selected form 1585 // Test that we return credit card profile suggestions when the selected form
1554 // field is not the credit card number field. 1586 // field is not the credit card number field.
1555 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) { 1587 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) {
1556 // Set up our form data. 1588 // Set up our form data.
1557 FormData form; 1589 FormData form;
1558 CreateTestCreditCardFormData(&form, true, false); 1590 CreateTestCreditCardFormData(&form, true, false);
1559 std::vector<FormData> forms(1, form); 1591 std::vector<FormData> forms(1, form);
1560 FormsSeen(forms); 1592 FormsSeen(forms);
1561 1593
1562 const FormFieldData& field = form.fields[0]; 1594 const FormFieldData& field = form.fields[0];
1563 GetAutofillSuggestions(form, field); 1595 GetAutofillSuggestions(form, field);
1564 1596
1565 #if defined(OS_ANDROID) 1597 #if defined(OS_ANDROID)
1566 static const char* kVisaSuggestion = 1598 static const char* kVisaSuggestion =
1567 "Visa\xC2\xA0\xE2\x8B\xAF" 1599 "Visa "
1600 "\xE2\x80\xA2\xE2\x80\x86"
1601 "\xE2\x80\xA2\xE2\x80\x86"
1602 "\xE2\x80\xA2\xE2\x80\x86"
1603 "\xE2\x80\xA2\xE2\x80\x86"
1568 "3456"; 1604 "3456";
1569 static const char* kMcSuggestion = 1605 static const char* kMcSuggestion =
1570 "MasterCard\xC2\xA0\xE2\x8B\xAF" 1606 "MasterCard "
1607 "\xE2\x80\xA2\xE2\x80\x86"
1608 "\xE2\x80\xA2\xE2\x80\x86"
1609 "\xE2\x80\xA2\xE2\x80\x86"
1610 "\xE2\x80\xA2\xE2\x80\x86"
1571 "8765"; 1611 "8765";
1572 #else 1612 #else
1573 static const char* kVisaSuggestion = "*3456"; 1613 static const char* kVisaSuggestion = "*3456";
1574 static const char* kMcSuggestion = "*8765"; 1614 static const char* kMcSuggestion = "*8765";
1575 #endif 1615 #endif
1576 1616
1577 // Test that we sent the right values to the external delegate. 1617 // Test that we sent the right values to the external delegate.
1578 external_delegate_->CheckSuggestions( 1618 external_delegate_->CheckSuggestions(
1579 kDefaultPageID, 1619 kDefaultPageID,
1580 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, 1620 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 FormData form; 1692 FormData form;
1653 CreateTestCreditCardFormData(&form, /* is_https */ true, false); 1693 CreateTestCreditCardFormData(&form, /* is_https */ true, false);
1654 std::vector<FormData> forms(1, form); 1694 std::vector<FormData> forms(1, form);
1655 FormsSeen(forms); 1695 FormsSeen(forms);
1656 1696
1657 FormFieldData field = form.fields[1]; 1697 FormFieldData field = form.fields[1];
1658 GetAutofillSuggestions(form, field); 1698 GetAutofillSuggestions(form, field);
1659 1699
1660 // Test that we sent the right values to the external delegate. 1700 // Test that we sent the right values to the external delegate.
1661 external_delegate_->CheckSuggestions( 1701 external_delegate_->CheckSuggestions(
1662 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1702 kDefaultPageID, Suggestion("Visa "
1703 "\xE2\x80\xA2\xE2\x80\x86"
1704 "\xE2\x80\xA2\xE2\x80\x86"
1705 "\xE2\x80\xA2\xE2\x80\x86"
1706 "\xE2\x80\xA2\xE2\x80\x86"
1663 "3456", 1707 "3456",
1664 "04/99", kVisaCard, 1708 "04/99", kVisaCard,
1665 autofill_manager_->GetPackedCreditCardID(4)), 1709 autofill_manager_->GetPackedCreditCardID(4)),
1666 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1710 Suggestion("MasterCard "
1711 "\xE2\x80\xA2\xE2\x80\x86"
1712 "\xE2\x80\xA2\xE2\x80\x86"
1713 "\xE2\x80\xA2\xE2\x80\x86"
1714 "\xE2\x80\xA2\xE2\x80\x86"
1667 "8765", 1715 "8765",
1668 "10/98", kMasterCard, 1716 "10/98", kMasterCard,
1669 autofill_manager_->GetPackedCreditCardID(5))); 1717 autofill_manager_->GetPackedCreditCardID(5)));
1670 } 1718 }
1671 1719
1672 // Test that we will eventually return the credit card signin promo when there 1720 // Test that we will eventually return the credit card signin promo when there
1673 // are no credit card suggestions and the promo is active. See the tests in 1721 // are no credit card suggestions and the promo is active. See the tests in
1674 // AutofillExternalDelegateTest that test whether the promo is added. 1722 // AutofillExternalDelegateTest that test whether the promo is added.
1675 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { 1723 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) {
1676 // Enable the signin promo feature with no impression limit. 1724 // Enable the signin promo feature with no impression limit.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 // Clear the form action. 1791 // Clear the form action.
1744 form.action = GURL(); 1792 form.action = GURL();
1745 std::vector<FormData> forms(1, form); 1793 std::vector<FormData> forms(1, form);
1746 FormsSeen(forms); 1794 FormsSeen(forms);
1747 1795
1748 FormFieldData field = form.fields[1]; 1796 FormFieldData field = form.fields[1];
1749 GetAutofillSuggestions(form, field); 1797 GetAutofillSuggestions(form, field);
1750 1798
1751 // Test that we sent the right values to the external delegate. 1799 // Test that we sent the right values to the external delegate.
1752 external_delegate_->CheckSuggestions( 1800 external_delegate_->CheckSuggestions(
1753 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1801 kDefaultPageID, Suggestion("Visa "
1802 "\xE2\x80\xA2\xE2\x80\x86"
1803 "\xE2\x80\xA2\xE2\x80\x86"
1804 "\xE2\x80\xA2\xE2\x80\x86"
1805 "\xE2\x80\xA2\xE2\x80\x86"
1754 "3456", 1806 "3456",
1755 "04/99", kVisaCard, 1807 "04/99", kVisaCard,
1756 autofill_manager_->GetPackedCreditCardID(4)), 1808 autofill_manager_->GetPackedCreditCardID(4)),
1757 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1809 Suggestion("MasterCard "
1810 "\xE2\x80\xA2\xE2\x80\x86"
1811 "\xE2\x80\xA2\xE2\x80\x86"
1812 "\xE2\x80\xA2\xE2\x80\x86"
1813 "\xE2\x80\xA2\xE2\x80\x86"
1758 "8765", 1814 "8765",
1759 "10/98", kMasterCard, 1815 "10/98", kMasterCard,
1760 autofill_manager_->GetPackedCreditCardID(5))); 1816 autofill_manager_->GetPackedCreditCardID(5)));
1761 } 1817 }
1762 1818
1763 // Test that we return credit card suggestions for secure pages that have a 1819 // Test that we return credit card suggestions for secure pages that have a
1764 // form action set to "javascript:something". 1820 // form action set to "javascript:something".
1765 TEST_F(AutofillManagerTest, 1821 TEST_F(AutofillManagerTest,
1766 GetCreditCardSuggestions_SecureContext_JavascriptFormAction) { 1822 GetCreditCardSuggestions_SecureContext_JavascriptFormAction) {
1767 // Set up our form data. 1823 // Set up our form data.
1768 FormData form; 1824 FormData form;
1769 CreateTestCreditCardFormData(&form, true, false); 1825 CreateTestCreditCardFormData(&form, true, false);
1770 // Have the form action be a javascript function (which is a valid URL). 1826 // Have the form action be a javascript function (which is a valid URL).
1771 form.action = GURL("javascript:alert('Hello');"); 1827 form.action = GURL("javascript:alert('Hello');");
1772 std::vector<FormData> forms(1, form); 1828 std::vector<FormData> forms(1, form);
1773 FormsSeen(forms); 1829 FormsSeen(forms);
1774 1830
1775 FormFieldData field = form.fields[1]; 1831 FormFieldData field = form.fields[1];
1776 GetAutofillSuggestions(form, field); 1832 GetAutofillSuggestions(form, field);
1777 1833
1778 // Test that we sent the right values to the external delegate. 1834 // Test that we sent the right values to the external delegate.
1779 external_delegate_->CheckSuggestions( 1835 external_delegate_->CheckSuggestions(
1780 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1836 kDefaultPageID, Suggestion("Visa "
1837 "\xE2\x80\xA2\xE2\x80\x86"
1838 "\xE2\x80\xA2\xE2\x80\x86"
1839 "\xE2\x80\xA2\xE2\x80\x86"
1840 "\xE2\x80\xA2\xE2\x80\x86"
1781 "3456", 1841 "3456",
1782 "04/99", kVisaCard, 1842 "04/99", kVisaCard,
1783 autofill_manager_->GetPackedCreditCardID(4)), 1843 autofill_manager_->GetPackedCreditCardID(4)),
1784 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1844 Suggestion("MasterCard "
1845 "\xE2\x80\xA2\xE2\x80\x86"
1846 "\xE2\x80\xA2\xE2\x80\x86"
1847 "\xE2\x80\xA2\xE2\x80\x86"
1848 "\xE2\x80\xA2\xE2\x80\x86"
1785 "8765", 1849 "8765",
1786 "10/98", kMasterCard, 1850 "10/98", kMasterCard,
1787 autofill_manager_->GetPackedCreditCardID(5))); 1851 autofill_manager_->GetPackedCreditCardID(5)));
1788 } 1852 }
1789 1853
1790 // Test that we return all credit card suggestions in the case that two cards 1854 // Test that we return all credit card suggestions in the case that two cards
1791 // have the same obfuscated number. 1855 // have the same obfuscated number.
1792 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { 1856 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) {
1793 // Add a credit card with the same obfuscated number as Elvis's. 1857 // Add a credit card with the same obfuscated number as Elvis's.
1794 // |credit_card| will be owned by the mock PersonalDataManager. 1858 // |credit_card| will be owned by the mock PersonalDataManager.
1795 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 1859 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
1796 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 1860 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
1797 "5231567890123456", // Mastercard 1861 "5231567890123456", // Mastercard
1798 "05", "2999"); 1862 "05", "2999");
1799 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 1863 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
1800 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); 1864 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
1801 autofill_manager_->AddCreditCard(std::move(credit_card)); 1865 autofill_manager_->AddCreditCard(std::move(credit_card));
1802 1866
1803 // Set up our form data. 1867 // Set up our form data.
1804 FormData form; 1868 FormData form;
1805 CreateTestCreditCardFormData(&form, true, false); 1869 CreateTestCreditCardFormData(&form, true, false);
1806 std::vector<FormData> forms(1, form); 1870 std::vector<FormData> forms(1, form);
1807 FormsSeen(forms); 1871 FormsSeen(forms);
1808 1872
1809 FormFieldData field = form.fields[1]; 1873 FormFieldData field = form.fields[1];
1810 GetAutofillSuggestions(form, field); 1874 GetAutofillSuggestions(form, field);
1811 1875
1812 // Test that we sent the right values to the external delegate. 1876 // Test that we sent the right values to the external delegate.
1813 external_delegate_->CheckSuggestions( 1877 external_delegate_->CheckSuggestions(
1814 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1878 kDefaultPageID, Suggestion("Visa "
1879 "\xE2\x80\xA2\xE2\x80\x86"
1880 "\xE2\x80\xA2\xE2\x80\x86"
1881 "\xE2\x80\xA2\xE2\x80\x86"
1882 "\xE2\x80\xA2\xE2\x80\x86"
1815 "3456", 1883 "3456",
1816 "04/99", kVisaCard, 1884 "04/99", kVisaCard,
1817 autofill_manager_->GetPackedCreditCardID(4)), 1885 autofill_manager_->GetPackedCreditCardID(4)),
1818 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1886 Suggestion("MasterCard "
1887 "\xE2\x80\xA2\xE2\x80\x86"
1888 "\xE2\x80\xA2\xE2\x80\x86"
1889 "\xE2\x80\xA2\xE2\x80\x86"
1890 "\xE2\x80\xA2\xE2\x80\x86"
1819 "8765", 1891 "8765",
1820 "10/98", kMasterCard, 1892 "10/98", kMasterCard,
1821 autofill_manager_->GetPackedCreditCardID(5)), 1893 autofill_manager_->GetPackedCreditCardID(5)),
1822 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1894 Suggestion("MasterCard "
1895 "\xE2\x80\xA2\xE2\x80\x86"
1896 "\xE2\x80\xA2\xE2\x80\x86"
1897 "\xE2\x80\xA2\xE2\x80\x86"
1898 "\xE2\x80\xA2\xE2\x80\x86"
1823 "3456", 1899 "3456",
1824 "05/99", kMasterCard, 1900 "05/99", kMasterCard,
1825 autofill_manager_->GetPackedCreditCardID(7))); 1901 autofill_manager_->GetPackedCreditCardID(7)));
1826 } 1902 }
1827 1903
1828 // Test that we return profile and credit card suggestions for combined forms. 1904 // Test that we return profile and credit card suggestions for combined forms.
1829 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { 1905 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) {
1830 // Set up our form data. 1906 // Set up our form data.
1831 FormData form; 1907 FormData form;
1832 test::CreateTestAddressFormData(&form); 1908 test::CreateTestAddressFormData(&form);
1833 CreateTestCreditCardFormData(&form, true, false); 1909 CreateTestCreditCardFormData(&form, true, false);
1834 std::vector<FormData> forms(1, form); 1910 std::vector<FormData> forms(1, form);
1835 FormsSeen(forms); 1911 FormsSeen(forms);
1836 1912
1837 FormFieldData field = form.fields[0]; 1913 FormFieldData field = form.fields[0];
1838 GetAutofillSuggestions(form, field); 1914 GetAutofillSuggestions(form, field);
1839 1915
1840 // Test that we sent the right address suggestions to the external delegate. 1916 // Test that we sent the right address suggestions to the external delegate.
1841 external_delegate_->CheckSuggestions( 1917 external_delegate_->CheckSuggestions(
1842 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), 1918 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1),
1843 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); 1919 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2));
1844 1920
1845 const int kPageID2 = 2; 1921 const int kPageID2 = 2;
1846 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); 1922 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
1847 GetAutofillSuggestions(kPageID2, form, field); 1923 GetAutofillSuggestions(kPageID2, form, field);
1848 1924
1849 // Test that we sent the credit card suggestions to the external delegate. 1925 // Test that we sent the credit card suggestions to the external delegate.
1850 external_delegate_->CheckSuggestions( 1926 external_delegate_->CheckSuggestions(
1851 kPageID2, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1927 kPageID2, Suggestion("Visa "
1928 "\xE2\x80\xA2\xE2\x80\x86"
1929 "\xE2\x80\xA2\xE2\x80\x86"
1930 "\xE2\x80\xA2\xE2\x80\x86"
1931 "\xE2\x80\xA2\xE2\x80\x86"
1852 "3456", 1932 "3456",
1853 "04/99", kVisaCard, 1933 "04/99", kVisaCard,
1854 autofill_manager_->GetPackedCreditCardID(4)), 1934 autofill_manager_->GetPackedCreditCardID(4)),
1855 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1935 Suggestion("MasterCard "
1936 "\xE2\x80\xA2\xE2\x80\x86"
1937 "\xE2\x80\xA2\xE2\x80\x86"
1938 "\xE2\x80\xA2\xE2\x80\x86"
1939 "\xE2\x80\xA2\xE2\x80\x86"
1856 "8765", 1940 "8765",
1857 "10/98", kMasterCard, 1941 "10/98", kMasterCard,
1858 autofill_manager_->GetPackedCreditCardID(5))); 1942 autofill_manager_->GetPackedCreditCardID(5)));
1859 } 1943 }
1860 1944
1861 // Test that for non-https forms with both address and credit card fields, we 1945 // Test that for non-https forms with both address and credit card fields, we
1862 // only return address suggestions. Instead of credit card suggestions, we 1946 // only return address suggestions. Instead of credit card suggestions, we
1863 // should return a warning explaining that credit card profile suggestions are 1947 // should return a warning explaining that credit card profile suggestions are
1864 // unavailable when the form is not https. 1948 // unavailable when the form is not https.
1865 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { 1949 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
(...skipping 2525 matching lines...) Expand 10 before | Expand all | Expand 10 after
4391 4475
4392 // Verify whether suggestions are populated correctly for one of the middle 4476 // Verify whether suggestions are populated correctly for one of the middle
4393 // credit card number fields when filled partially. 4477 // credit card number fields when filled partially.
4394 FormFieldData number_field = form.fields[3]; 4478 FormFieldData number_field = form.fields[3];
4395 number_field.value = ASCIIToUTF16("901"); 4479 number_field.value = ASCIIToUTF16("901");
4396 4480
4397 // Get the suggestions for already filled credit card |number_field|. 4481 // Get the suggestions for already filled credit card |number_field|.
4398 GetAutofillSuggestions(form, number_field); 4482 GetAutofillSuggestions(form, number_field);
4399 4483
4400 external_delegate_->CheckSuggestions( 4484 external_delegate_->CheckSuggestions(
4401 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 4485 kDefaultPageID, Suggestion("Visa "
4486 "\xE2\x80\xA2\xE2\x80\x86"
4487 "\xE2\x80\xA2\xE2\x80\x86"
4488 "\xE2\x80\xA2\xE2\x80\x86"
4489 "\xE2\x80\xA2\xE2\x80\x86"
4402 "3456", 4490 "3456",
4403 "04/99", kVisaCard, 4491 "04/99", kVisaCard,
4404 autofill_manager_->GetPackedCreditCardID(4))); 4492 autofill_manager_->GetPackedCreditCardID(4)));
4405 } 4493 }
4406 4494
4407 // Test that inputs detected to be CVC inputs are forced to 4495 // Test that inputs detected to be CVC inputs are forced to
4408 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. 4496 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm.
4409 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { 4497 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) {
4410 FormData form_seen_by_ahm; 4498 FormData form_seen_by_ahm;
4411 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); 4499 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager();
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
5177 std::vector<FormData> forms(1, form); 5265 std::vector<FormData> forms(1, form);
5178 FormsSeen(forms); 5266 FormsSeen(forms);
5179 5267
5180 FormFieldData field; 5268 FormFieldData field;
5181 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", 5269 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text",
5182 &field); 5270 &field);
5183 GetAutofillSuggestions(form, field); 5271 GetAutofillSuggestions(form, field);
5184 5272
5185 #if defined(OS_ANDROID) 5273 #if defined(OS_ANDROID)
5186 static const char* kVisaSuggestion = 5274 static const char* kVisaSuggestion =
5187 "Visa\xC2\xA0\xE2\x8B\xAF" 5275 "Visa "
5276 "\xE2\x80\xA2\xE2\x80\x86"
5277 "\xE2\x80\xA2\xE2\x80\x86"
5278 "\xE2\x80\xA2\xE2\x80\x86"
5279 "\xE2\x80\xA2\xE2\x80\x86"
5188 "3456"; 5280 "3456";
5189 #else 5281 #else
5190 static const char* kVisaSuggestion = "*3456"; 5282 static const char* kVisaSuggestion = "*3456";
5191 #endif 5283 #endif
5192 5284
5193 external_delegate_->CheckSuggestions( 5285 external_delegate_->CheckSuggestions(
5194 kDefaultPageID, Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, 5286 kDefaultPageID, Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard,
5195 autofill_manager_->GetPackedCreditCardID(4))); 5287 autofill_manager_->GetPackedCreditCardID(4)));
5196 } 5288 }
5197 5289
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
5554 5646
5555 // The driver should always be notified. 5647 // The driver should always be notified.
5556 for (const FormFieldData& field : form.fields) { 5648 for (const FormFieldData& field : form.fields) {
5557 GetAutofillSuggestions(form, field); 5649 GetAutofillSuggestions(form, field);
5558 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); 5650 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5559 autofill_driver_->ClearDidInteractWithCreditCardForm(); 5651 autofill_driver_->ClearDidInteractWithCreditCardForm();
5560 } 5652 }
5561 } 5653 }
5562 5654
5563 } // namespace autofill 5655 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698