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

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

Issue 2534413006: [Credit Card] Uses 4 dots in ellipsis (Closed)
Patch Set: Updates Java tests with new format for masked card numbers 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 using testing::AtLeast; 65 using testing::AtLeast;
66 using testing::Return; 66 using testing::Return;
67 using testing::SaveArg; 67 using testing::SaveArg;
68 68
69 namespace autofill { 69 namespace autofill {
70 70
71 namespace { 71 namespace {
72 72
73 const int kDefaultPageID = 137; 73 const int kDefaultPageID = 137;
74 74
75 const std::string kUTF8MidlineEllipsis =
76 " "
77 "\xE2\x80\xA2\xE2\x80\x86"
78 "\xE2\x80\xA2\xE2\x80\x86"
79 "\xE2\x80\xA2\xE2\x80\x86"
80 "\xE2\x80\xA2\xE2\x80\x86";
81
75 class MockAutofillClient : public TestAutofillClient { 82 class MockAutofillClient : public TestAutofillClient {
76 public: 83 public:
77 MockAutofillClient() {} 84 MockAutofillClient() {}
78 85
79 ~MockAutofillClient() override {} 86 ~MockAutofillClient() override {}
80 87
81 MOCK_METHOD2(ConfirmSaveCreditCardLocally, 88 MOCK_METHOD2(ConfirmSaveCreditCardLocally,
82 void(const CreditCard& card, const base::Closure& callback)); 89 void(const CreditCard& card, const base::Closure& callback));
83 90
84 MOCK_METHOD0(ShouldShowSigninPromo, bool()); 91 MOCK_METHOD0(ShouldShowSigninPromo, bool());
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 FormData form; 1439 FormData form;
1433 CreateTestCreditCardFormData(&form, true, false); 1440 CreateTestCreditCardFormData(&form, true, false);
1434 std::vector<FormData> forms(1, form); 1441 std::vector<FormData> forms(1, form);
1435 FormsSeen(forms); 1442 FormsSeen(forms);
1436 1443
1437 FormFieldData field = form.fields[1]; 1444 FormFieldData field = form.fields[1];
1438 GetAutofillSuggestions(form, field); 1445 GetAutofillSuggestions(form, field);
1439 1446
1440 // Test that we sent the right values to the external delegate. 1447 // Test that we sent the right values to the external delegate.
1441 external_delegate_->CheckSuggestions( 1448 external_delegate_->CheckSuggestions(
1442 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1449 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1443 "3456",
1444 "04/99", kVisaCard, 1450 "04/99", kVisaCard,
1445 autofill_manager_->GetPackedCreditCardID(4)), 1451 autofill_manager_->GetPackedCreditCardID(4)),
1446 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1452 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1447 "8765", 1453 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
1448 "10/98", kMasterCard,
1449 autofill_manager_->GetPackedCreditCardID(5)));
1450 } 1454 }
1451 1455
1452 // Test that we return all credit card profile suggestions when the triggering 1456 // Test that we return all credit card profile suggestions when the triggering
1453 // field has whitespace in it. 1457 // field has whitespace in it.
1454 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) { 1458 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) {
1455 // Set up our form data. 1459 // Set up our form data.
1456 FormData form; 1460 FormData form;
1457 CreateTestCreditCardFormData(&form, true, false); 1461 CreateTestCreditCardFormData(&form, true, false);
1458 std::vector<FormData> forms(1, form); 1462 std::vector<FormData> forms(1, form);
1459 FormsSeen(forms); 1463 FormsSeen(forms);
1460 1464
1461 FormFieldData field = form.fields[1]; 1465 FormFieldData field = form.fields[1];
1462 field.value = ASCIIToUTF16(" "); 1466 field.value = ASCIIToUTF16(" ");
1463 GetAutofillSuggestions(form, field); 1467 GetAutofillSuggestions(form, field);
1464 1468
1465 // Test that we sent the right values to the external delegate. 1469 // Test that we sent the right values to the external delegate.
1466 external_delegate_->CheckSuggestions( 1470 external_delegate_->CheckSuggestions(
1467 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1471 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1468 "3456",
1469 "04/99", kVisaCard, 1472 "04/99", kVisaCard,
1470 autofill_manager_->GetPackedCreditCardID(4)), 1473 autofill_manager_->GetPackedCreditCardID(4)),
1471 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1474 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1472 "8765", 1475 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
1473 "10/98", kMasterCard,
1474 autofill_manager_->GetPackedCreditCardID(5)));
1475 } 1476 }
1476 1477
1477 // Test that we return all credit card profile suggestions when the triggering 1478 // Test that we return all credit card profile suggestions when the triggering
1478 // field has stop characters in it, which should be removed. 1479 // field has stop characters in it, which should be removed.
1479 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { 1480 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) {
1480 // Set up our form data. 1481 // Set up our form data.
1481 FormData form; 1482 FormData form;
1482 CreateTestCreditCardFormData(&form, true, false); 1483 CreateTestCreditCardFormData(&form, true, false);
1483 std::vector<FormData> forms(1, form); 1484 std::vector<FormData> forms(1, form);
1484 FormsSeen(forms); 1485 FormsSeen(forms);
1485 1486
1486 FormFieldData field = form.fields[1]; 1487 FormFieldData field = form.fields[1];
1487 field.value = ASCIIToUTF16("____-____-____-____"); 1488 field.value = ASCIIToUTF16("____-____-____-____");
1488 GetAutofillSuggestions(form, field); 1489 GetAutofillSuggestions(form, field);
1489 1490
1490 // Test that we sent the right values to the external delegate. 1491 // Test that we sent the right values to the external delegate.
1491 external_delegate_->CheckSuggestions( 1492 external_delegate_->CheckSuggestions(
1492 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1493 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1493 "3456",
1494 "04/99", kVisaCard, 1494 "04/99", kVisaCard,
1495 autofill_manager_->GetPackedCreditCardID(4)), 1495 autofill_manager_->GetPackedCreditCardID(4)),
1496 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1496 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1497 "8765", 1497 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
1498 "10/98", kMasterCard,
1499 autofill_manager_->GetPackedCreditCardID(5)));
1500 } 1498 }
1501 1499
1502 // Test that we return all credit card profile suggestions when the triggering 1500 // Test that we return all credit card profile suggestions when the triggering
1503 // field has stop characters in it and some input. 1501 // field has stop characters in it and some input.
1504 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { 1502 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) {
1505 // Add a credit card with particular numbers that we will attempt to recall. 1503 // Add a credit card with particular numbers that we will attempt to recall.
1506 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 1504 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
1507 test::SetCreditCardInfo(credit_card.get(), "John Smith", 1505 test::SetCreditCardInfo(credit_card.get(), "John Smith",
1508 "5255667890123123", // Mastercard 1506 "5255667890123123", // Mastercard
1509 "08", "2017"); 1507 "08", "2017");
1510 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 1508 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
1511 autofill_manager_->AddCreditCard(std::move(credit_card)); 1509 autofill_manager_->AddCreditCard(std::move(credit_card));
1512 1510
1513 // Set up our form data. 1511 // Set up our form data.
1514 FormData form; 1512 FormData form;
1515 CreateTestCreditCardFormData(&form, true, false); 1513 CreateTestCreditCardFormData(&form, true, false);
1516 std::vector<FormData> forms(1, form); 1514 std::vector<FormData> forms(1, form);
1517 FormsSeen(forms); 1515 FormsSeen(forms);
1518 1516
1519 FormFieldData field = form.fields[1]; 1517 FormFieldData field = form.fields[1];
1520 1518
1521 field.value = ASCIIToUTF16("5255-66__-____-____"); 1519 field.value = ASCIIToUTF16("5255-66__-____-____");
1522 GetAutofillSuggestions(form, field); 1520 GetAutofillSuggestions(form, field);
1523 1521
1524 // Test that we sent the right value to the external delegate. 1522 // Test that we sent the right value to the external delegate.
1525 external_delegate_->CheckSuggestions( 1523 external_delegate_->CheckSuggestions(
1526 kDefaultPageID, Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1524 kDefaultPageID, Suggestion("MasterCard" + kUTF8MidlineEllipsis + "3123",
1527 "3123",
1528 "08/17", kMasterCard, 1525 "08/17", kMasterCard,
1529 autofill_manager_->GetPackedCreditCardID(7))); 1526 autofill_manager_->GetPackedCreditCardID(7)));
1530 } 1527 }
1531 1528
1532 // Test that we return only matching credit card profile suggestions when the 1529 // Test that we return only matching credit card profile suggestions when the
1533 // selected form field has been partially filled out. 1530 // selected form field has been partially filled out.
1534 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_MatchCharacter) { 1531 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_MatchCharacter) {
1535 // Set up our form data. 1532 // Set up our form data.
1536 FormData form; 1533 FormData form;
1537 CreateTestCreditCardFormData(&form, true, false); 1534 CreateTestCreditCardFormData(&form, true, false);
1538 std::vector<FormData> forms(1, form); 1535 std::vector<FormData> forms(1, form);
1539 FormsSeen(forms); 1536 FormsSeen(forms);
1540 1537
1541 FormFieldData field; 1538 FormFieldData field;
1542 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); 1539 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field);
1543 GetAutofillSuggestions(form, field); 1540 GetAutofillSuggestions(form, field);
1544 1541
1545 // Test that we sent the right values to the external delegate. 1542 // Test that we sent the right values to the external delegate.
1546 external_delegate_->CheckSuggestions( 1543 external_delegate_->CheckSuggestions(
1547 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1544 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1548 "3456",
1549 "04/99", kVisaCard, 1545 "04/99", kVisaCard,
1550 autofill_manager_->GetPackedCreditCardID(4))); 1546 autofill_manager_->GetPackedCreditCardID(4)));
1551 } 1547 }
1552 1548
1553 // Test that we return credit card profile suggestions when the selected form 1549 // Test that we return credit card profile suggestions when the selected form
1554 // field is not the credit card number field. 1550 // field is not the credit card number field.
1555 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) { 1551 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) {
1556 // Set up our form data. 1552 // Set up our form data.
1557 FormData form; 1553 FormData form;
1558 CreateTestCreditCardFormData(&form, true, false); 1554 CreateTestCreditCardFormData(&form, true, false);
1559 std::vector<FormData> forms(1, form); 1555 std::vector<FormData> forms(1, form);
1560 FormsSeen(forms); 1556 FormsSeen(forms);
1561 1557
1562 const FormFieldData& field = form.fields[0]; 1558 const FormFieldData& field = form.fields[0];
1563 GetAutofillSuggestions(form, field); 1559 GetAutofillSuggestions(form, field);
1564 1560
1565 #if defined(OS_ANDROID) 1561 #if defined(OS_ANDROID)
1566 static const char* kVisaSuggestion = 1562 static const std::string kVisaSuggestion =
1567 "Visa\xC2\xA0\xE2\x8B\xAF" 1563 "Visa" + kUTF8MidlineEllipsis + "3456";
1568 "3456"; 1564 static const std::string kMcSuggestion =
1569 static const char* kMcSuggestion = 1565 "MasterCard" + kUTF8MidlineEllipsis + "8765";
1570 "MasterCard\xC2\xA0\xE2\x8B\xAF"
1571 "8765";
1572 #else 1566 #else
1573 static const char* kVisaSuggestion = "*3456"; 1567 static const std::string kVisaSuggestion = "*3456";
1574 static const char* kMcSuggestion = "*8765"; 1568 static const std::string kMcSuggestion = "*8765";
1575 #endif 1569 #endif
1576 1570
1577 // Test that we sent the right values to the external delegate. 1571 // Test that we sent the right values to the external delegate.
1578 external_delegate_->CheckSuggestions( 1572 external_delegate_->CheckSuggestions(
1579 kDefaultPageID, 1573 kDefaultPageID,
1580 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, 1574 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard,
1581 autofill_manager_->GetPackedCreditCardID(4)), 1575 autofill_manager_->GetPackedCreditCardID(4)),
1582 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, 1576 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard,
1583 autofill_manager_->GetPackedCreditCardID(5))); 1577 autofill_manager_->GetPackedCreditCardID(5)));
1584 } 1578 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 FormData form; 1646 FormData form;
1653 CreateTestCreditCardFormData(&form, /* is_https */ true, false); 1647 CreateTestCreditCardFormData(&form, /* is_https */ true, false);
1654 std::vector<FormData> forms(1, form); 1648 std::vector<FormData> forms(1, form);
1655 FormsSeen(forms); 1649 FormsSeen(forms);
1656 1650
1657 FormFieldData field = form.fields[1]; 1651 FormFieldData field = form.fields[1];
1658 GetAutofillSuggestions(form, field); 1652 GetAutofillSuggestions(form, field);
1659 1653
1660 // Test that we sent the right values to the external delegate. 1654 // Test that we sent the right values to the external delegate.
1661 external_delegate_->CheckSuggestions( 1655 external_delegate_->CheckSuggestions(
1662 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1656 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1663 "3456",
1664 "04/99", kVisaCard, 1657 "04/99", kVisaCard,
1665 autofill_manager_->GetPackedCreditCardID(4)), 1658 autofill_manager_->GetPackedCreditCardID(4)),
1666 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1659 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1667 "8765", 1660 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
1668 "10/98", kMasterCard,
1669 autofill_manager_->GetPackedCreditCardID(5)));
1670 } 1661 }
1671 1662
1672 // Test that we will eventually return the credit card signin promo when there 1663 // 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 1664 // are no credit card suggestions and the promo is active. See the tests in
1674 // AutofillExternalDelegateTest that test whether the promo is added. 1665 // AutofillExternalDelegateTest that test whether the promo is added.
1675 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { 1666 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) {
1676 // Enable the signin promo feature with no impression limit. 1667 // Enable the signin promo feature with no impression limit.
1677 EnableCreditCardSigninPromoFeatureWithLimit(0); 1668 EnableCreditCardSigninPromoFeatureWithLimit(0);
1678 1669
1679 // Make sure there are no credit cards. 1670 // Make sure there are no credit cards.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 // Clear the form action. 1734 // Clear the form action.
1744 form.action = GURL(); 1735 form.action = GURL();
1745 std::vector<FormData> forms(1, form); 1736 std::vector<FormData> forms(1, form);
1746 FormsSeen(forms); 1737 FormsSeen(forms);
1747 1738
1748 FormFieldData field = form.fields[1]; 1739 FormFieldData field = form.fields[1];
1749 GetAutofillSuggestions(form, field); 1740 GetAutofillSuggestions(form, field);
1750 1741
1751 // Test that we sent the right values to the external delegate. 1742 // Test that we sent the right values to the external delegate.
1752 external_delegate_->CheckSuggestions( 1743 external_delegate_->CheckSuggestions(
1753 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1744 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1754 "3456",
1755 "04/99", kVisaCard, 1745 "04/99", kVisaCard,
1756 autofill_manager_->GetPackedCreditCardID(4)), 1746 autofill_manager_->GetPackedCreditCardID(4)),
1757 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1747 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1758 "8765", 1748 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
1759 "10/98", kMasterCard,
1760 autofill_manager_->GetPackedCreditCardID(5)));
1761 } 1749 }
1762 1750
1763 // Test that we return credit card suggestions for secure pages that have a 1751 // Test that we return credit card suggestions for secure pages that have a
1764 // form action set to "javascript:something". 1752 // form action set to "javascript:something".
1765 TEST_F(AutofillManagerTest, 1753 TEST_F(AutofillManagerTest,
1766 GetCreditCardSuggestions_SecureContext_JavascriptFormAction) { 1754 GetCreditCardSuggestions_SecureContext_JavascriptFormAction) {
1767 // Set up our form data. 1755 // Set up our form data.
1768 FormData form; 1756 FormData form;
1769 CreateTestCreditCardFormData(&form, true, false); 1757 CreateTestCreditCardFormData(&form, true, false);
1770 // Have the form action be a javascript function (which is a valid URL). 1758 // Have the form action be a javascript function (which is a valid URL).
1771 form.action = GURL("javascript:alert('Hello');"); 1759 form.action = GURL("javascript:alert('Hello');");
1772 std::vector<FormData> forms(1, form); 1760 std::vector<FormData> forms(1, form);
1773 FormsSeen(forms); 1761 FormsSeen(forms);
1774 1762
1775 FormFieldData field = form.fields[1]; 1763 FormFieldData field = form.fields[1];
1776 GetAutofillSuggestions(form, field); 1764 GetAutofillSuggestions(form, field);
1777 1765
1778 // Test that we sent the right values to the external delegate. 1766 // Test that we sent the right values to the external delegate.
1779 external_delegate_->CheckSuggestions( 1767 external_delegate_->CheckSuggestions(
1780 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1768 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1781 "3456",
1782 "04/99", kVisaCard, 1769 "04/99", kVisaCard,
1783 autofill_manager_->GetPackedCreditCardID(4)), 1770 autofill_manager_->GetPackedCreditCardID(4)),
1784 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1771 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1785 "8765", 1772 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
1786 "10/98", kMasterCard,
1787 autofill_manager_->GetPackedCreditCardID(5)));
1788 } 1773 }
1789 1774
1790 // Test that we return all credit card suggestions in the case that two cards 1775 // Test that we return all credit card suggestions in the case that two cards
1791 // have the same obfuscated number. 1776 // have the same obfuscated number.
1792 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { 1777 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) {
1793 // Add a credit card with the same obfuscated number as Elvis's. 1778 // Add a credit card with the same obfuscated number as Elvis's.
1794 // |credit_card| will be owned by the mock PersonalDataManager. 1779 // |credit_card| will be owned by the mock PersonalDataManager.
1795 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 1780 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
1796 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 1781 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
1797 "5231567890123456", // Mastercard 1782 "5231567890123456", // Mastercard
1798 "05", "2999"); 1783 "05", "2999");
1799 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 1784 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
1800 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); 1785 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
1801 autofill_manager_->AddCreditCard(std::move(credit_card)); 1786 autofill_manager_->AddCreditCard(std::move(credit_card));
1802 1787
1803 // Set up our form data. 1788 // Set up our form data.
1804 FormData form; 1789 FormData form;
1805 CreateTestCreditCardFormData(&form, true, false); 1790 CreateTestCreditCardFormData(&form, true, false);
1806 std::vector<FormData> forms(1, form); 1791 std::vector<FormData> forms(1, form);
1807 FormsSeen(forms); 1792 FormsSeen(forms);
1808 1793
1809 FormFieldData field = form.fields[1]; 1794 FormFieldData field = form.fields[1];
1810 GetAutofillSuggestions(form, field); 1795 GetAutofillSuggestions(form, field);
1811 1796
1812 // Test that we sent the right values to the external delegate. 1797 // Test that we sent the right values to the external delegate.
1813 external_delegate_->CheckSuggestions( 1798 external_delegate_->CheckSuggestions(
1814 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1799 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1815 "3456",
1816 "04/99", kVisaCard, 1800 "04/99", kVisaCard,
1817 autofill_manager_->GetPackedCreditCardID(4)), 1801 autofill_manager_->GetPackedCreditCardID(4)),
1818 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1802 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1819 "8765", 1803 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)),
1820 "10/98", kMasterCard, 1804 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "3456", "05/99",
1821 autofill_manager_->GetPackedCreditCardID(5)), 1805 kMasterCard, autofill_manager_->GetPackedCreditCardID(7)));
1822 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF"
1823 "3456",
1824 "05/99", kMasterCard,
1825 autofill_manager_->GetPackedCreditCardID(7)));
1826 } 1806 }
1827 1807
1828 // Test that we return profile and credit card suggestions for combined forms. 1808 // Test that we return profile and credit card suggestions for combined forms.
1829 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { 1809 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) {
1830 // Set up our form data. 1810 // Set up our form data.
1831 FormData form; 1811 FormData form;
1832 test::CreateTestAddressFormData(&form); 1812 test::CreateTestAddressFormData(&form);
1833 CreateTestCreditCardFormData(&form, true, false); 1813 CreateTestCreditCardFormData(&form, true, false);
1834 std::vector<FormData> forms(1, form); 1814 std::vector<FormData> forms(1, form);
1835 FormsSeen(forms); 1815 FormsSeen(forms);
1836 1816
1837 FormFieldData field = form.fields[0]; 1817 FormFieldData field = form.fields[0];
1838 GetAutofillSuggestions(form, field); 1818 GetAutofillSuggestions(form, field);
1839 1819
1840 // Test that we sent the right address suggestions to the external delegate. 1820 // Test that we sent the right address suggestions to the external delegate.
1841 external_delegate_->CheckSuggestions( 1821 external_delegate_->CheckSuggestions(
1842 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), 1822 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1),
1843 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); 1823 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2));
1844 1824
1845 const int kPageID2 = 2; 1825 const int kPageID2 = 2;
1846 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); 1826 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
1847 GetAutofillSuggestions(kPageID2, form, field); 1827 GetAutofillSuggestions(kPageID2, form, field);
1848 1828
1849 // Test that we sent the credit card suggestions to the external delegate. 1829 // Test that we sent the credit card suggestions to the external delegate.
1850 external_delegate_->CheckSuggestions( 1830 external_delegate_->CheckSuggestions(
1851 kPageID2, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 1831 kPageID2, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
1852 "3456",
1853 "04/99", kVisaCard, 1832 "04/99", kVisaCard,
1854 autofill_manager_->GetPackedCreditCardID(4)), 1833 autofill_manager_->GetPackedCreditCardID(4)),
1855 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" 1834 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98",
1856 "8765", 1835 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
1857 "10/98", kMasterCard,
1858 autofill_manager_->GetPackedCreditCardID(5)));
1859 } 1836 }
1860 1837
1861 // Test that for non-https forms with both address and credit card fields, we 1838 // 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 1839 // only return address suggestions. Instead of credit card suggestions, we
1863 // should return a warning explaining that credit card profile suggestions are 1840 // should return a warning explaining that credit card profile suggestions are
1864 // unavailable when the form is not https. 1841 // unavailable when the form is not https.
1865 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { 1842 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
1866 // Set up our form data. 1843 // Set up our form data.
1867 FormData form; 1844 FormData form;
1868 test::CreateTestAddressFormData(&form); 1845 test::CreateTestAddressFormData(&form);
(...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after
4391 4368
4392 // Verify whether suggestions are populated correctly for one of the middle 4369 // Verify whether suggestions are populated correctly for one of the middle
4393 // credit card number fields when filled partially. 4370 // credit card number fields when filled partially.
4394 FormFieldData number_field = form.fields[3]; 4371 FormFieldData number_field = form.fields[3];
4395 number_field.value = ASCIIToUTF16("901"); 4372 number_field.value = ASCIIToUTF16("901");
4396 4373
4397 // Get the suggestions for already filled credit card |number_field|. 4374 // Get the suggestions for already filled credit card |number_field|.
4398 GetAutofillSuggestions(form, number_field); 4375 GetAutofillSuggestions(form, number_field);
4399 4376
4400 external_delegate_->CheckSuggestions( 4377 external_delegate_->CheckSuggestions(
4401 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" 4378 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456",
4402 "3456",
4403 "04/99", kVisaCard, 4379 "04/99", kVisaCard,
4404 autofill_manager_->GetPackedCreditCardID(4))); 4380 autofill_manager_->GetPackedCreditCardID(4)));
4405 } 4381 }
4406 4382
4407 // Test that inputs detected to be CVC inputs are forced to 4383 // Test that inputs detected to be CVC inputs are forced to
4408 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. 4384 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm.
4409 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { 4385 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) {
4410 FormData form_seen_by_ahm; 4386 FormData form_seen_by_ahm;
4411 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); 4387 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager();
4412 EXPECT_CALL(*m, OnWillSubmitForm(_)).WillOnce(SaveArg<0>(&form_seen_by_ahm)); 4388 EXPECT_CALL(*m, OnWillSubmitForm(_)).WillOnce(SaveArg<0>(&form_seen_by_ahm));
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
5176 CreateTestCreditCardFormData(&form, true, false); 5152 CreateTestCreditCardFormData(&form, true, false);
5177 std::vector<FormData> forms(1, form); 5153 std::vector<FormData> forms(1, form);
5178 FormsSeen(forms); 5154 FormsSeen(forms);
5179 5155
5180 FormFieldData field; 5156 FormFieldData field;
5181 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", 5157 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text",
5182 &field); 5158 &field);
5183 GetAutofillSuggestions(form, field); 5159 GetAutofillSuggestions(form, field);
5184 5160
5185 #if defined(OS_ANDROID) 5161 #if defined(OS_ANDROID)
5186 static const char* kVisaSuggestion = 5162 static const std::string kVisaSuggestion =
5187 "Visa\xC2\xA0\xE2\x8B\xAF" 5163 "Visa" + kUTF8MidlineEllipsis + "3456";
5188 "3456";
5189 #else 5164 #else
5190 static const char* kVisaSuggestion = "*3456"; 5165 static const std::string kVisaSuggestion = "*3456";
5191 #endif 5166 #endif
5192 5167
5193 external_delegate_->CheckSuggestions( 5168 external_delegate_->CheckSuggestions(
5194 kDefaultPageID, Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, 5169 kDefaultPageID, Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard,
5195 autofill_manager_->GetPackedCreditCardID(4))); 5170 autofill_manager_->GetPackedCreditCardID(4)));
5196 } 5171 }
5197 5172
5198 // Verify that typing "lvis" will not match any of the credit card name when 5173 // Verify that typing "lvis" will not match any of the credit card name when
5199 // substring matching is enabled. 5174 // substring matching is enabled.
5200 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) { 5175 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) {
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
5554 5529
5555 // The driver should always be notified. 5530 // The driver should always be notified.
5556 for (const FormFieldData& field : form.fields) { 5531 for (const FormFieldData& field : form.fields) {
5557 GetAutofillSuggestions(form, field); 5532 GetAutofillSuggestions(form, field);
5558 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); 5533 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5559 autofill_driver_->ClearDidInteractWithCreditCardForm(); 5534 autofill_driver_->ClearDidInteractWithCreditCardForm();
5560 } 5535 }
5561 } 5536 }
5562 5537
5563 } // namespace autofill 5538 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698