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

Side by Side Diff: chrome/browser/autofill/form_structure_unittest.cc

Issue 6213002: Propagate correct data to the Toolbar servers (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/form_structure.h" 8 #include "chrome/browser/autofill/form_structure.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1668 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1669 form_structure.reset(new FormStructure(form)); 1669 form_structure.reset(new FormStructure(form));
1670 std::string encoded_xml; 1670 std::string encoded_xml;
1671 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1671 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1672 for (size_t i = 0; i < form_structure->field_count(); ++i) 1672 for (size_t i = 0; i < form_structure->field_count(); ++i)
1673 form_structure->set_possible_types(i, possible_field_types[i]); 1673 form_structure->set_possible_types(i, possible_field_types[i]);
1674 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1674 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1675 EXPECT_EQ(encoded_xml, 1675 EXPECT_EQ(encoded_xml,
1676 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1676 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1677 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1677 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1678 "8269229441054798720\" autofillused=\"false\" datapresent=\"\"><field " 1678 "8269229441054798720\" autofillused=\"false\" datapresent=\"1442008208\">"
1679 "signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" 1679 "<field signature=\"3763331450\" autofilltype=\"3\"/><field signature=\""
1680 "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" " 1680 "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" "
1681 "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype=" 1681 "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype="
1682 "\"14\"/><field signature=\"2799270304\" autofilltype=\"36\"/><field " 1682 "\"14\"/><field signature=\"2799270304\" autofilltype=\"36\"/><field "
1683 "signature=\"1876771436\" autofilltype=\"24\"/><field signature=" 1683 "signature=\"1876771436\" autofilltype=\"24\"/><field signature="
1684 "\"263446779\" autofilltype=\"30\"/></autofillupload>"); 1684 "\"263446779\" autofilltype=\"30\"/></autofillupload>");
1685 EXPECT_TRUE(form_structure->EncodeUploadRequest(true, &encoded_xml)); 1685 EXPECT_TRUE(form_structure->EncodeUploadRequest(true, &encoded_xml));
1686 EXPECT_EQ(encoded_xml, 1686 EXPECT_EQ(encoded_xml,
1687 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1687 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1688 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1688 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1689 "8269229441054798720\" autofillused=\"true\" datapresent=\"\"><field " 1689 "8269229441054798720\" autofillused=\"true\" datapresent=\"1442008208\">"
1690 "signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" 1690 "<field signature=\"3763331450\" autofilltype=\"3\"/><field signature=\""
1691 "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" " 1691 "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" "
1692 "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype=" 1692 "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype="
1693 "\"14\"/><field signature=\"2799270304\" autofilltype=\"36\"/><field " 1693 "\"14\"/><field signature=\"2799270304\" autofilltype=\"36\"/><field "
1694 "signature=\"1876771436\" autofilltype=\"24\"/><field signature=" 1694 "signature=\"1876771436\" autofilltype=\"24\"/><field signature="
1695 "\"263446779\" autofilltype=\"30\"/></autofillupload>"); 1695 "\"263446779\" autofilltype=\"30\"/></autofillupload>");
1696 // Add 5 address fields - this should be still a valid form. 1696 // Add 5 address fields - this should be still a valid form.
1697 for (size_t i = 0; i < 5; ++i) { 1697 for (size_t i = 0; i < 5; ++i) {
1698 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1698 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
1699 ASCIIToUTF16("address"), 1699 ASCIIToUTF16("address"),
1700 string16(), 1700 string16(),
1701 ASCIIToUTF16("text"), 1701 ASCIIToUTF16("text"),
1702 0, 1702 0,
1703 false)); 1703 false));
1704 possible_field_types.push_back(FieldTypeSet()); 1704 possible_field_types.push_back(FieldTypeSet());
1705 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1705 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1706 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1706 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1707 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1707 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1708 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1708 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1709 } 1709 }
1710 form_structure.reset(new FormStructure(form)); 1710 form_structure.reset(new FormStructure(form));
1711 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1711 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1712 for (size_t i = 0; i < form_structure->field_count(); ++i) 1712 for (size_t i = 0; i < form_structure->field_count(); ++i)
1713 form_structure->set_possible_types(i, possible_field_types[i]); 1713 form_structure->set_possible_types(i, possible_field_types[i]);
1714 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1714 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1715 EXPECT_EQ(encoded_xml, 1715 EXPECT_EQ(encoded_xml,
1716 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1716 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1717 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1717 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1718 "2027360543766157144\" autofillused=\"false\" datapresent=\"\"><field " 1718 "2027360543766157144\" autofillused=\"false\" datapresent=\"5442008208\">"
1719 "signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" 1719 "<field signature=\"3763331450\" autofilltype=\"3\"/><field signature=\""
1720 "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" " 1720 "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" "
1721 "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype=\"14\"/>" 1721 "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype=\"14\"/>"
1722 "<field signature=\"2799270304\" autofilltype=\"36\"/><field signature=\"" 1722 "<field signature=\"2799270304\" autofilltype=\"36\"/><field signature=\""
1723 "1876771436\" autofilltype=\"24\"/><field signature=\"263446779\" " 1723 "1876771436\" autofilltype=\"24\"/><field signature=\"263446779\" "
1724 "autofilltype=\"30\"/><field signature=\"509334676\" autofilltype=" 1724 "autofilltype=\"30\"/><field signature=\"509334676\" autofilltype=\"1\"/>"
1725 "\"30\"/><field signature=\"509334676\" autofilltype=\"31\"/><field " 1725 "<field signature=\"509334676\" autofilltype=\"1\"/><field signature=\""
1726 "signature=\"509334676\" autofilltype=\"37\"/><field signature=" 1726 "509334676\" autofilltype=\"1\"/><field signature=\"509334676\" "
1727 "\"509334676\" autofilltype=\"38\"/><field signature=\"509334676\" " 1727 "autofilltype=\"1\"/><field signature=\"509334676\" autofilltype=\"1\"/>"
1728 "autofilltype=\"30\"/><field signature=\"509334676\" autofilltype=" 1728 "</autofillupload>");
1729 "\"31\"/><field signature=\"509334676\" autofilltype=\"37\"/><field "
1730 "signature=\"509334676\" autofilltype=\"38\"/><field signature=\""
1731 "509334676\" autofilltype=\"30\"/><field signature=\"509334676\" "
1732 "autofilltype=\"31\"/><field signature=\"509334676\" "
1733 "autofilltype=\"37\"/><field signature=\"509334676\" autofilltype="
1734 "\"38\"/><field signature=\"509334676\" autofilltype=\"30\"/><field "
1735 "signature=\"509334676\" autofilltype=\"31\"/><field signature="
1736 "\"509334676\" autofilltype=\"37\"/><field signature=\"509334676\" "
1737 "autofilltype=\"38\"/><field signature=\"509334676\" autofilltype="
1738 "\"30\"/><field signature=\"509334676\" autofilltype=\"31\"/><field "
1739 "signature=\"509334676\" autofilltype=\"37\"/><field signature="
1740 "\"509334676\" autofilltype=\"38\"/></autofillupload>");
1741 // Add 50 address fields - now the form is invalid. 1729 // Add 50 address fields - now the form is invalid.
1742 for (size_t i = 0; i < 50; ++i) { 1730 for (size_t i = 0; i < 50; ++i) {
1743 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1731 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
1744 ASCIIToUTF16("address"), 1732 ASCIIToUTF16("address"),
1745 string16(), 1733 string16(),
1746 ASCIIToUTF16("text"), 1734 ASCIIToUTF16("text"),
1747 0, 1735 0,
1748 false)); 1736 false));
1749 possible_field_types.push_back(FieldTypeSet()); 1737 possible_field_types.push_back(FieldTypeSet());
1750 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1738 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1751 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1739 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1752 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1740 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1753 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1741 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1754 } 1742 }
1755 form_structure.reset(new FormStructure(form)); 1743 form_structure.reset(new FormStructure(form));
1756 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1744 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1757 for (size_t i = 0; i < form_structure->field_count(); ++i) 1745 for (size_t i = 0; i < form_structure->field_count(); ++i)
1758 form_structure->set_possible_types(i, possible_field_types[i]); 1746 form_structure->set_possible_types(i, possible_field_types[i]);
1759 EXPECT_FALSE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1747 EXPECT_FALSE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1760 EXPECT_EQ(encoded_xml, ""); 1748 EXPECT_EQ(encoded_xml, "");
1761 } 1749 }
1762 1750
1751 TEST(FormStructureTest, CheckDataPresence) {
1752 scoped_ptr<FormStructure> form_structure;
1753 std::vector<FieldTypeSet> possible_field_types;
1754 FormData form;
1755 form.method = ASCIIToUTF16("post");
1756 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"),
1757 ASCIIToUTF16("first"),
1758 string16(),
1759 ASCIIToUTF16("text"),
1760 0,
1761 false));
1762 possible_field_types.push_back(FieldTypeSet());
1763 possible_field_types.back().insert(NAME_FIRST);
1764 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
1765 ASCIIToUTF16("last"),
1766 string16(),
1767 ASCIIToUTF16("text"),
1768 0,
1769 false));
1770 possible_field_types.push_back(FieldTypeSet());
1771 possible_field_types.back().insert(NAME_LAST);
1772 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"),
1773 ASCIIToUTF16("email"),
1774 string16(),
1775 ASCIIToUTF16("text"),
1776 0,
1777 false));
1778 possible_field_types.push_back(FieldTypeSet());
1779 possible_field_types.back().insert(EMAIL_ADDRESS);
1780 form_structure.reset(new FormStructure(form));
1781 for (size_t i = 0; i < form_structure->field_count(); ++i)
1782 form_structure->set_possible_types(i, possible_field_types[i]);
1783 std::string encoded_xml;
1784 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1785 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1786 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1787 "6402244543831589061\" autofillused=\"false\" "
1788 "datapresent=\"1440\"><field signature=\"1089846351\" ",
1789 encoded_xml.substr(0, 200));
1790
1791 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
1792 ASCIIToUTF16("address"),
1793 string16(),
1794 ASCIIToUTF16("text"),
1795 0,
1796 false));
1797 possible_field_types.push_back(FieldTypeSet());
1798 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1799 form_structure.reset(new FormStructure(form));
1800 for (size_t i = 0; i < form_structure->field_count(); ++i)
1801 form_structure->set_possible_types(i, possible_field_types[i]);
1802 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1803 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1804 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1805 "11817937699000629499\" autofillused=\"false\" "
1806 "datapresent=\"14400002\"><field signature=\"1089846",
1807 encoded_xml.substr(0, 200));
1808
1809 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("F4"),
1810 ASCIIToUTF16("f4"),
1811 string16(),
1812 ASCIIToUTF16("text"),
1813 0,
1814 false));
1815 possible_field_types.push_back(FieldTypeSet());
1816 possible_field_types.back().insert(CREDIT_CARD_TYPE);
1817 form_structure.reset(new FormStructure(form));
1818 for (size_t i = 0; i < form_structure->field_count(); ++i)
1819 form_structure->set_possible_types(i, possible_field_types[i]);
1820 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1821 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1822 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1823 "15126663683491865216\" autofillused=\"false\" "
1824 "datapresent=\"1440000200000020\"><field signature=",
1825 encoded_xml.substr(0, 200));
1826 }
1827
1828 TEST(FormStructureTest, CheckMultipleTypes) {
1829 // Let's imagine user entered 'George' 'Washington' in first and second fields
1830 // and there are two profiles: for George Washington and Washington Irving.
1831 // As Washington will match both first and last name in two profiles we are
1832 // not sure which one it is, so we will not poison crowd sourced data.
1833 scoped_ptr<FormStructure> form_structure;
1834 std::vector<FieldTypeSet> possible_field_types;
1835 FormData form;
1836 form.method = ASCIIToUTF16("post");
1837 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"),
1838 ASCIIToUTF16("email"),
1839 string16(),
1840 ASCIIToUTF16("text"),
1841 0,
1842 false));
1843 possible_field_types.push_back(FieldTypeSet());
1844 possible_field_types.back().insert(EMAIL_ADDRESS);
1845 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"),
1846 ASCIIToUTF16("first"),
1847 string16(),
1848 ASCIIToUTF16("text"),
1849 0,
1850 false));
1851 possible_field_types.push_back(FieldTypeSet());
1852 possible_field_types.back().insert(NAME_FIRST);
1853 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
1854 ASCIIToUTF16("last"),
1855 string16(),
1856 ASCIIToUTF16("text"),
1857 0,
1858 false));
1859 possible_field_types.push_back(FieldTypeSet());
1860 possible_field_types.back().insert(NAME_LAST);
1861 form_structure.reset(new FormStructure(form));
1862 for (size_t i = 0; i < form_structure->field_count(); ++i)
1863 form_structure->set_possible_types(i, possible_field_types[i]);
1864 std::string encoded_xml;
1865 // Now we matched both fields singularly.
1866 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1867 // datapresent=1440 == 0001010001000000b set bits are:
1868 // #3 == NAME_FIRST
1869 // #5 == NAME_LAST
1870 // #9 == EMAIL_ADDRESS
1871 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1872 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1873 "12278868829735447139\" autofillused=\"false\" "
1874 "datapresent=\"1440\"><field signature=\"420638584\" autofilltype="
1875 "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field "
1876 "signature=\"2404144663\" autofilltype=\"5\"/></autofillupload>",
1877 encoded_xml);
1878 // Match second field as both first and last.
dhollowa 2011/01/21 17:17:05 s/second/third/
GeorgeY 2011/01/21 17:32:37 Done.
1879 possible_field_types.back().insert(NAME_FIRST);
1880 form_structure->set_possible_types(
1881 form_structure->field_count() - 1,
1882 possible_field_types[form_structure->field_count() - 1]);
1883 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml));
1884 // datapresent=5040 == 0101010001000000b set bits are:
1885 // #1 == UNKNOWN_TYPE
dhollowa 2011/01/21 16:44:57 Why would we set UNKNOWN_TYPE in datapresent? It
GeorgeY 2011/01/21 17:32:37 I do not want to special case some of the types, a
1886 // #3 == NAME_FIRST
1887 // #9 == EMAIL_ADDRESS
1888 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload "
1889 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\""
1890 "12278868829735447139\" autofillused=\"false\" "
1891 "datapresent=\"5040\"><field signature=\"420638584\" autofilltype="
1892 "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field "
1893 "signature=\"2404144663\" autofilltype=\"1\"/></autofillupload>",
1894 encoded_xml);
1895 }
1896
1763 } // namespace 1897 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698