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

Side by Side Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 2148303005: [Password Generation] Sends the flag whether a field has nonempty user input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes addressed to reviewer comments Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 1606
1607 // We should be able to extract a normal text field. 1607 // We should be able to extract a normal text field.
1608 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { 1608 TEST_F(FormAutofillTest, WebFormControlElementToFormField) {
1609 LoadHTML("<INPUT type='text' id='element' value='value'/>"); 1609 LoadHTML("<INPUT type='text' id='element' value='value'/>");
1610 1610
1611 WebFrame* frame = GetMainFrame(); 1611 WebFrame* frame = GetMainFrame();
1612 ASSERT_NE(nullptr, frame); 1612 ASSERT_NE(nullptr, frame);
1613 1613
1614 WebFormControlElement element = GetFormControlElementById("element"); 1614 WebFormControlElement element = GetFormControlElementById("element");
1615 FormFieldData result1; 1615 FormFieldData result1;
1616 WebFormControlElementToFormField(element, EXTRACT_NONE, &result1); 1616 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, &result1);
1617 1617
1618 FormFieldData expected; 1618 FormFieldData expected;
1619 expected.form_control_type = "text"; 1619 expected.form_control_type = "text";
1620 expected.max_length = WebInputElement::defaultMaxLength(); 1620 expected.max_length = WebInputElement::defaultMaxLength();
1621 1621
1622 expected.name = ASCIIToUTF16("element"); 1622 expected.name = ASCIIToUTF16("element");
1623 expected.value.clear(); 1623 expected.value.clear();
1624 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); 1624 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1);
1625 1625
1626 FormFieldData result2; 1626 FormFieldData result2;
1627 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result2); 1627 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result2);
1628 1628
1629 expected.name = ASCIIToUTF16("element"); 1629 expected.name = ASCIIToUTF16("element");
1630 expected.value = ASCIIToUTF16("value"); 1630 expected.value = ASCIIToUTF16("value");
1631 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); 1631 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2);
1632 } 1632 }
1633 1633
1634 // We should be able to extract a text field with autocomplete="off". 1634 // We should be able to extract a text field with autocomplete="off".
1635 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { 1635 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) {
1636 LoadHTML("<INPUT type='text' id='element' value='value'" 1636 LoadHTML("<INPUT type='text' id='element' value='value'"
1637 " autocomplete='off'/>"); 1637 " autocomplete='off'/>");
1638 1638
1639 WebFrame* frame = GetMainFrame(); 1639 WebFrame* frame = GetMainFrame();
1640 ASSERT_NE(nullptr, frame); 1640 ASSERT_NE(nullptr, frame);
1641 1641
1642 WebFormControlElement element = GetFormControlElementById("element"); 1642 WebFormControlElement element = GetFormControlElementById("element");
1643 FormFieldData result; 1643 FormFieldData result;
1644 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1644 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1645 1645
1646 FormFieldData expected; 1646 FormFieldData expected;
1647 expected.name = ASCIIToUTF16("element"); 1647 expected.name = ASCIIToUTF16("element");
1648 expected.value = ASCIIToUTF16("value"); 1648 expected.value = ASCIIToUTF16("value");
1649 expected.form_control_type = "text"; 1649 expected.form_control_type = "text";
1650 expected.autocomplete_attribute = "off"; 1650 expected.autocomplete_attribute = "off";
1651 expected.max_length = WebInputElement::defaultMaxLength(); 1651 expected.max_length = WebInputElement::defaultMaxLength();
1652 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1652 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1653 } 1653 }
1654 1654
1655 // We should be able to extract a text field with maxlength specified. 1655 // We should be able to extract a text field with maxlength specified.
1656 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { 1656 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) {
1657 LoadHTML("<INPUT type='text' id='element' value='value'" 1657 LoadHTML("<INPUT type='text' id='element' value='value'"
1658 " maxlength='5'/>"); 1658 " maxlength='5'/>");
1659 1659
1660 WebFrame* frame = GetMainFrame(); 1660 WebFrame* frame = GetMainFrame();
1661 ASSERT_NE(nullptr, frame); 1661 ASSERT_NE(nullptr, frame);
1662 1662
1663 WebFormControlElement element = GetFormControlElementById("element"); 1663 WebFormControlElement element = GetFormControlElementById("element");
1664 FormFieldData result; 1664 FormFieldData result;
1665 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1665 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1666 1666
1667 FormFieldData expected; 1667 FormFieldData expected;
1668 expected.name = ASCIIToUTF16("element"); 1668 expected.name = ASCIIToUTF16("element");
1669 expected.value = ASCIIToUTF16("value"); 1669 expected.value = ASCIIToUTF16("value");
1670 expected.form_control_type = "text"; 1670 expected.form_control_type = "text";
1671 expected.max_length = 5; 1671 expected.max_length = 5;
1672 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1672 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1673 } 1673 }
1674 1674
1675 // We should be able to extract a text field that has been autofilled. 1675 // We should be able to extract a text field that has been autofilled.
1676 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { 1676 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) {
1677 LoadHTML("<INPUT type='text' id='element' value='value'/>"); 1677 LoadHTML("<INPUT type='text' id='element' value='value'/>");
1678 1678
1679 WebFrame* frame = GetMainFrame(); 1679 WebFrame* frame = GetMainFrame();
1680 ASSERT_NE(nullptr, frame); 1680 ASSERT_NE(nullptr, frame);
1681 1681
1682 WebInputElement element = GetInputElementById("element"); 1682 WebInputElement element = GetInputElementById("element");
1683 element.setAutofilled(true); 1683 element.setAutofilled(true);
1684 FormFieldData result; 1684 FormFieldData result;
1685 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1685 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1686 1686
1687 FormFieldData expected; 1687 FormFieldData expected;
1688 expected.name = ASCIIToUTF16("element"); 1688 expected.name = ASCIIToUTF16("element");
1689 expected.value = ASCIIToUTF16("value"); 1689 expected.value = ASCIIToUTF16("value");
1690 expected.form_control_type = "text"; 1690 expected.form_control_type = "text";
1691 expected.max_length = WebInputElement::defaultMaxLength(); 1691 expected.max_length = WebInputElement::defaultMaxLength();
1692 expected.is_autofilled = true; 1692 expected.is_autofilled = true;
1693 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1693 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1694 } 1694 }
1695 1695
1696 // We should be able to extract a radio or a checkbox field that has been 1696 // We should be able to extract a radio or a checkbox field that has been
1697 // autofilled. 1697 // autofilled.
1698 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { 1698 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) {
1699 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" 1699 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>"
1700 "<INPUT type='radio' id='radio' value='male'/>"); 1700 "<INPUT type='radio' id='radio' value='male'/>");
1701 1701
1702 WebFrame* frame = GetMainFrame(); 1702 WebFrame* frame = GetMainFrame();
1703 ASSERT_NE(nullptr, frame); 1703 ASSERT_NE(nullptr, frame);
1704 1704
1705 WebInputElement element = GetInputElementById("checkbox"); 1705 WebInputElement element = GetInputElementById("checkbox");
1706 element.setAutofilled(true); 1706 element.setAutofilled(true);
1707 FormFieldData result; 1707 FormFieldData result;
1708 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1708 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1709 1709
1710 FormFieldData expected; 1710 FormFieldData expected;
1711 expected.name = ASCIIToUTF16("checkbox"); 1711 expected.name = ASCIIToUTF16("checkbox");
1712 expected.value = ASCIIToUTF16("mail"); 1712 expected.value = ASCIIToUTF16("mail");
1713 expected.form_control_type = "checkbox"; 1713 expected.form_control_type = "checkbox";
1714 expected.is_autofilled = true; 1714 expected.is_autofilled = true;
1715 expected.check_status = FormFieldData::CHECKED; 1715 expected.check_status = FormFieldData::CHECKED;
1716 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1716 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1717 1717
1718 element = GetInputElementById("radio"); 1718 element = GetInputElementById("radio");
1719 element.setAutofilled(true); 1719 element.setAutofilled(true);
1720 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1720 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1721 expected.name = ASCIIToUTF16("radio"); 1721 expected.name = ASCIIToUTF16("radio");
1722 expected.value = ASCIIToUTF16("male"); 1722 expected.value = ASCIIToUTF16("male");
1723 expected.form_control_type = "radio"; 1723 expected.form_control_type = "radio";
1724 expected.is_autofilled = true; 1724 expected.is_autofilled = true;
1725 expected.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; 1725 expected.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED;
1726 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1726 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1727 } 1727 }
1728 1728
1729 // We should be able to extract a <select> field. 1729 // We should be able to extract a <select> field.
1730 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { 1730 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) {
1731 LoadHTML("<SELECT id='element'/>" 1731 LoadHTML("<SELECT id='element'/>"
1732 " <OPTION value='CA'>California</OPTION>" 1732 " <OPTION value='CA'>California</OPTION>"
1733 " <OPTION value='TX'>Texas</OPTION>" 1733 " <OPTION value='TX'>Texas</OPTION>"
1734 "</SELECT>"); 1734 "</SELECT>");
1735 1735
1736 WebFrame* frame = GetMainFrame(); 1736 WebFrame* frame = GetMainFrame();
1737 ASSERT_NE(nullptr, frame); 1737 ASSERT_NE(nullptr, frame);
1738 1738
1739 WebFormControlElement element = GetFormControlElementById("element"); 1739 WebFormControlElement element = GetFormControlElementById("element");
1740 FormFieldData result1; 1740 FormFieldData result1;
1741 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result1); 1741 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result1);
1742 1742
1743 FormFieldData expected; 1743 FormFieldData expected;
1744 expected.name = ASCIIToUTF16("element"); 1744 expected.name = ASCIIToUTF16("element");
1745 expected.max_length = 0; 1745 expected.max_length = 0;
1746 expected.form_control_type = "select-one"; 1746 expected.form_control_type = "select-one";
1747 1747
1748 expected.value = ASCIIToUTF16("CA"); 1748 expected.value = ASCIIToUTF16("CA");
1749 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); 1749 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1);
1750 1750
1751 FormFieldData result2; 1751 FormFieldData result2;
1752 WebFormControlElementToFormField( 1752 WebFormControlElementToFormField(
1753 element, 1753 element, nullptr,
1754 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), 1754 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), &result2);
1755 &result2);
1756 expected.value = ASCIIToUTF16("California"); 1755 expected.value = ASCIIToUTF16("California");
1757 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); 1756 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2);
1758 1757
1759 FormFieldData result3; 1758 FormFieldData result3;
1760 WebFormControlElementToFormField(element, EXTRACT_OPTIONS, &result3); 1759 WebFormControlElementToFormField(element, nullptr, EXTRACT_OPTIONS, &result3);
1761 expected.value.clear(); 1760 expected.value.clear();
1762 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3); 1761 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3);
1763 1762
1764 ASSERT_EQ(2U, result3.option_values.size()); 1763 ASSERT_EQ(2U, result3.option_values.size());
1765 ASSERT_EQ(2U, result3.option_contents.size()); 1764 ASSERT_EQ(2U, result3.option_contents.size());
1766 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); 1765 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]);
1767 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); 1766 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]);
1768 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); 1767 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]);
1769 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); 1768 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]);
1770 } 1769 }
1771 1770
1772 // We copy extra attributes for the select field. 1771 // We copy extra attributes for the select field.
1773 TEST_F(FormAutofillTest, 1772 TEST_F(FormAutofillTest,
1774 WebFormControlElementToFormFieldSelect_ExtraAttributes) { 1773 WebFormControlElementToFormFieldSelect_ExtraAttributes) {
1775 LoadHTML("<SELECT id='element' autocomplete='off'/>" 1774 LoadHTML("<SELECT id='element' autocomplete='off'/>"
1776 " <OPTION value='CA'>California</OPTION>" 1775 " <OPTION value='CA'>California</OPTION>"
1777 " <OPTION value='TX'>Texas</OPTION>" 1776 " <OPTION value='TX'>Texas</OPTION>"
1778 "</SELECT>"); 1777 "</SELECT>");
1779 1778
1780 WebFrame* frame = GetMainFrame(); 1779 WebFrame* frame = GetMainFrame();
1781 ASSERT_NE(nullptr, frame); 1780 ASSERT_NE(nullptr, frame);
1782 1781
1783 WebFormControlElement element = GetFormControlElementById("element"); 1782 WebFormControlElement element = GetFormControlElementById("element");
1784 element.setAutofilled(true); 1783 element.setAutofilled(true);
1785 1784
1786 FormFieldData result1; 1785 FormFieldData result1;
1787 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result1); 1786 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result1);
1788 1787
1789 FormFieldData expected; 1788 FormFieldData expected;
1790 expected.name = ASCIIToUTF16("element"); 1789 expected.name = ASCIIToUTF16("element");
1791 expected.max_length = 0; 1790 expected.max_length = 0;
1792 expected.form_control_type = "select-one"; 1791 expected.form_control_type = "select-one";
1793 // We check that the extra attributes have been copied to |result1|. 1792 // We check that the extra attributes have been copied to |result1|.
1794 expected.is_autofilled = true; 1793 expected.is_autofilled = true;
1795 expected.autocomplete_attribute = "off"; 1794 expected.autocomplete_attribute = "off";
1796 expected.should_autocomplete = false; 1795 expected.should_autocomplete = false;
1797 expected.is_focusable = true; 1796 expected.is_focusable = true;
(...skipping 12 matching lines...) Expand all
1810 "%" PRIuS "</OPTION>", i, i); 1809 "%" PRIuS "</OPTION>", i, i);
1811 } 1810 }
1812 html += "</SELECT>"; 1811 html += "</SELECT>";
1813 LoadHTML(html.c_str()); 1812 LoadHTML(html.c_str());
1814 1813
1815 WebFrame* frame = GetMainFrame(); 1814 WebFrame* frame = GetMainFrame();
1816 ASSERT_TRUE(frame); 1815 ASSERT_TRUE(frame);
1817 1816
1818 WebFormControlElement element = GetFormControlElementById("element"); 1817 WebFormControlElement element = GetFormControlElementById("element");
1819 FormFieldData result; 1818 FormFieldData result;
1820 WebFormControlElementToFormField(element, EXTRACT_OPTIONS, &result); 1819 WebFormControlElementToFormField(element, nullptr, EXTRACT_OPTIONS, &result);
1821 1820
1822 EXPECT_TRUE(result.option_values.empty()); 1821 EXPECT_TRUE(result.option_values.empty());
1823 EXPECT_TRUE(result.option_contents.empty()); 1822 EXPECT_TRUE(result.option_contents.empty());
1824 } 1823 }
1825 1824
1826 // We should be able to extract a <textarea> field. 1825 // We should be able to extract a <textarea> field.
1827 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { 1826 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) {
1828 LoadHTML("<TEXTAREA id='element'>" 1827 LoadHTML("<TEXTAREA id='element'>"
1829 "This element's value&#10;" 1828 "This element's value&#10;"
1830 "spans multiple lines." 1829 "spans multiple lines."
1831 "</TEXTAREA>"); 1830 "</TEXTAREA>");
1832 1831
1833 WebFrame* frame = GetMainFrame(); 1832 WebFrame* frame = GetMainFrame();
1834 ASSERT_NE(nullptr, frame); 1833 ASSERT_NE(nullptr, frame);
1835 1834
1836 WebFormControlElement element = GetFormControlElementById("element"); 1835 WebFormControlElement element = GetFormControlElementById("element");
1837 FormFieldData result_sans_value; 1836 FormFieldData result_sans_value;
1838 WebFormControlElementToFormField(element, EXTRACT_NONE, &result_sans_value); 1837 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE,
1838 &result_sans_value);
1839 1839
1840 FormFieldData expected; 1840 FormFieldData expected;
1841 expected.name = ASCIIToUTF16("element"); 1841 expected.name = ASCIIToUTF16("element");
1842 expected.max_length = 0; 1842 expected.max_length = 0;
1843 expected.form_control_type = "textarea"; 1843 expected.form_control_type = "textarea";
1844 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); 1844 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value);
1845 1845
1846 FormFieldData result_with_value; 1846 FormFieldData result_with_value;
1847 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result_with_value); 1847 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE,
1848 &result_with_value);
1848 expected.value = ASCIIToUTF16("This element's value\n" 1849 expected.value = ASCIIToUTF16("This element's value\n"
1849 "spans multiple lines."); 1850 "spans multiple lines.");
1850 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); 1851 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value);
1851 } 1852 }
1852 1853
1853 // We should be able to extract an <input type="month"> field. 1854 // We should be able to extract an <input type="month"> field.
1854 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { 1855 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) {
1855 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); 1856 LoadHTML("<INPUT type='month' id='element' value='2011-12'>");
1856 1857
1857 WebFrame* frame = GetMainFrame(); 1858 WebFrame* frame = GetMainFrame();
1858 ASSERT_NE(nullptr, frame); 1859 ASSERT_NE(nullptr, frame);
1859 1860
1860 WebFormControlElement element = GetFormControlElementById("element"); 1861 WebFormControlElement element = GetFormControlElementById("element");
1861 FormFieldData result_sans_value; 1862 FormFieldData result_sans_value;
1862 WebFormControlElementToFormField(element, EXTRACT_NONE, &result_sans_value); 1863 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE,
1864 &result_sans_value);
1863 1865
1864 FormFieldData expected; 1866 FormFieldData expected;
1865 expected.name = ASCIIToUTF16("element"); 1867 expected.name = ASCIIToUTF16("element");
1866 expected.max_length = 0; 1868 expected.max_length = 0;
1867 expected.form_control_type = "month"; 1869 expected.form_control_type = "month";
1868 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); 1870 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value);
1869 1871
1870 FormFieldData result_with_value; 1872 FormFieldData result_with_value;
1871 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result_with_value); 1873 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE,
1874 &result_with_value);
1872 expected.value = ASCIIToUTF16("2011-12"); 1875 expected.value = ASCIIToUTF16("2011-12");
1873 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); 1876 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value);
1874 } 1877 }
1875 1878
1876 // We should not extract the value for non-text and non-select fields. 1879 // We should not extract the value for non-text and non-select fields.
1877 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { 1880 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) {
1878 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" 1881 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
1879 " <INPUT type='hidden' id='hidden' value='apple'/>" 1882 " <INPUT type='hidden' id='hidden' value='apple'/>"
1880 " <INPUT type='submit' id='submit' value='Send'/>" 1883 " <INPUT type='submit' id='submit' value='Send'/>"
1881 "</FORM>"); 1884 "</FORM>");
1882 1885
1883 WebFrame* frame = GetMainFrame(); 1886 WebFrame* frame = GetMainFrame();
1884 ASSERT_NE(nullptr, frame); 1887 ASSERT_NE(nullptr, frame);
1885 1888
1886 WebFormControlElement element = GetFormControlElementById("hidden"); 1889 WebFormControlElement element = GetFormControlElementById("hidden");
1887 FormFieldData result; 1890 FormFieldData result;
1888 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1891 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1889 1892
1890 FormFieldData expected; 1893 FormFieldData expected;
1891 expected.max_length = 0; 1894 expected.max_length = 0;
1892 1895
1893 expected.name = ASCIIToUTF16("hidden"); 1896 expected.name = ASCIIToUTF16("hidden");
1894 expected.form_control_type = "hidden"; 1897 expected.form_control_type = "hidden";
1895 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1898 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1896 1899
1897 element = GetFormControlElementById("submit"); 1900 element = GetFormControlElementById("submit");
1898 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1901 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1899 expected.name = ASCIIToUTF16("submit"); 1902 expected.name = ASCIIToUTF16("submit");
1900 expected.form_control_type = "submit"; 1903 expected.form_control_type = "submit";
1901 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1904 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1902 } 1905 }
1903 1906
1904 // We should be able to extract password fields. 1907 // We should be able to extract password fields.
1905 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { 1908 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) {
1906 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" 1909 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
1907 " <INPUT type='password' id='password' value='secret'/>" 1910 " <INPUT type='password' id='password' value='secret'/>"
1908 "</FORM>"); 1911 "</FORM>");
1909 1912
1910 WebFrame* frame = GetMainFrame(); 1913 WebFrame* frame = GetMainFrame();
1911 ASSERT_NE(nullptr, frame); 1914 ASSERT_NE(nullptr, frame);
1912 1915
1913 WebFormControlElement element = GetFormControlElementById("password"); 1916 WebFormControlElement element = GetFormControlElementById("password");
1914 FormFieldData result; 1917 FormFieldData result;
1915 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 1918 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
1916 1919
1917 FormFieldData expected; 1920 FormFieldData expected;
1918 expected.max_length = WebInputElement::defaultMaxLength(); 1921 expected.max_length = WebInputElement::defaultMaxLength();
1919 expected.name = ASCIIToUTF16("password"); 1922 expected.name = ASCIIToUTF16("password");
1920 expected.form_control_type = "password"; 1923 expected.form_control_type = "password";
1921 expected.value = ASCIIToUTF16("secret"); 1924 expected.value = ASCIIToUTF16("secret");
1922 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 1925 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
1923 } 1926 }
1924 1927
1925 // We should be able to extract the autocompletetype attribute. 1928 // We should be able to extract the autocompletetype attribute.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 // Very long attribute values should be replaced by a default string, to 1983 // Very long attribute values should be replaced by a default string, to
1981 // prevent malicious websites from DOSing the browser process. 1984 // prevent malicious websites from DOSing the browser process.
1982 { "malicious", "text", "x-max-data-length-exceeded" }, 1985 { "malicious", "text", "x-max-data-length-exceeded" },
1983 }; 1986 };
1984 1987
1985 WebDocument document = frame->document(); 1988 WebDocument document = frame->document();
1986 for (size_t i = 0; i < arraysize(test_cases); ++i) { 1989 for (size_t i = 0; i < arraysize(test_cases); ++i) {
1987 WebFormControlElement element = 1990 WebFormControlElement element =
1988 GetFormControlElementById(ASCIIToUTF16(test_cases[i].element_id)); 1991 GetFormControlElementById(ASCIIToUTF16(test_cases[i].element_id));
1989 FormFieldData result; 1992 FormFieldData result;
1990 WebFormControlElementToFormField(element, EXTRACT_NONE, &result); 1993 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, &result);
1991 1994
1992 FormFieldData expected; 1995 FormFieldData expected;
1993 expected.name = ASCIIToUTF16(test_cases[i].element_id); 1996 expected.name = ASCIIToUTF16(test_cases[i].element_id);
1994 expected.form_control_type = test_cases[i].form_control_type; 1997 expected.form_control_type = test_cases[i].form_control_type;
1995 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute; 1998 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute;
1996 if (test_cases[i].form_control_type == "text") 1999 if (test_cases[i].form_control_type == "text")
1997 expected.max_length = WebInputElement::defaultMaxLength(); 2000 expected.max_length = WebInputElement::defaultMaxLength();
1998 else 2001 else
1999 expected.max_length = 0; 2002 expected.max_length = 0;
2000 2003
2001 SCOPED_TRACE(test_cases[i].element_id); 2004 SCOPED_TRACE(test_cases[i].element_id);
2002 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); 2005 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
2003 } 2006 }
2004 } 2007 }
2005 2008
2006 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { 2009 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) {
2007 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" 2010 LoadHTML("<STYLE>input{direction:rtl}</STYLE>"
2008 "<FORM>" 2011 "<FORM>"
2009 " <INPUT type='text' id='element'>" 2012 " <INPUT type='text' id='element'>"
2010 "</FORM>"); 2013 "</FORM>");
2011 2014
2012 WebFrame* frame = GetMainFrame(); 2015 WebFrame* frame = GetMainFrame();
2013 ASSERT_NE(nullptr, frame); 2016 ASSERT_NE(nullptr, frame);
2014 2017
2015 WebFormControlElement element = GetFormControlElementById("element"); 2018 WebFormControlElement element = GetFormControlElementById("element");
2016 2019
2017 FormFieldData result; 2020 FormFieldData result;
2018 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2021 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2019 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); 2022 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
2020 } 2023 }
2021 2024
2022 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { 2025 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) {
2023 LoadHTML("<FORM>" 2026 LoadHTML("<FORM>"
2024 " <INPUT dir='rtl' type='text' id='element'/>" 2027 " <INPUT dir='rtl' type='text' id='element'/>"
2025 "</FORM>"); 2028 "</FORM>");
2026 2029
2027 WebFrame* frame = GetMainFrame(); 2030 WebFrame* frame = GetMainFrame();
2028 ASSERT_NE(nullptr, frame); 2031 ASSERT_NE(nullptr, frame);
2029 2032
2030 WebFormControlElement element = GetFormControlElementById("element"); 2033 WebFormControlElement element = GetFormControlElementById("element");
2031 2034
2032 FormFieldData result; 2035 FormFieldData result;
2033 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2036 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2034 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); 2037 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
2035 } 2038 }
2036 2039
2037 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { 2040 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) {
2038 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" 2041 LoadHTML("<STYLE>form{direction:rtl}</STYLE>"
2039 "<FORM>" 2042 "<FORM>"
2040 " <INPUT type='text' id='element'/>" 2043 " <INPUT type='text' id='element'/>"
2041 "</FORM>"); 2044 "</FORM>");
2042 2045
2043 WebFrame* frame = GetMainFrame(); 2046 WebFrame* frame = GetMainFrame();
2044 ASSERT_NE(nullptr, frame); 2047 ASSERT_NE(nullptr, frame);
2045 2048
2046 WebFormControlElement element = GetFormControlElementById("element"); 2049 WebFormControlElement element = GetFormControlElementById("element");
2047 2050
2048 FormFieldData result; 2051 FormFieldData result;
2049 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2052 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2050 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); 2053 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
2051 } 2054 }
2052 2055
2053 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { 2056 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) {
2054 LoadHTML("<FORM dir='rtl'>" 2057 LoadHTML("<FORM dir='rtl'>"
2055 " <INPUT type='text' id='element'/>" 2058 " <INPUT type='text' id='element'/>"
2056 "</FORM>"); 2059 "</FORM>");
2057 2060
2058 WebFrame* frame = GetMainFrame(); 2061 WebFrame* frame = GetMainFrame();
2059 ASSERT_NE(nullptr, frame); 2062 ASSERT_NE(nullptr, frame);
2060 2063
2061 WebFormControlElement element = GetFormControlElementById("element"); 2064 WebFormControlElement element = GetFormControlElementById("element");
2062 2065
2063 FormFieldData result; 2066 FormFieldData result;
2064 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2067 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2065 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); 2068 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
2066 } 2069 }
2067 2070
2068 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { 2071 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) {
2069 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" 2072 LoadHTML("<STYLE>input{direction:ltr}</STYLE>"
2070 "<FORM dir='rtl'>" 2073 "<FORM dir='rtl'>"
2071 " <INPUT type='text' id='element'/>" 2074 " <INPUT type='text' id='element'/>"
2072 "</FORM>"); 2075 "</FORM>");
2073 2076
2074 WebFrame* frame = GetMainFrame(); 2077 WebFrame* frame = GetMainFrame();
2075 ASSERT_NE(nullptr, frame); 2078 ASSERT_NE(nullptr, frame);
2076 2079
2077 WebFormControlElement element = GetFormControlElementById("element"); 2080 WebFormControlElement element = GetFormControlElementById("element");
2078 2081
2079 FormFieldData result; 2082 FormFieldData result;
2080 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2083 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2081 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); 2084 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction);
2082 } 2085 }
2083 2086
2084 TEST_F(FormAutofillTest, TextAlignOverridesDirection) { 2087 TEST_F(FormAutofillTest, TextAlignOverridesDirection) {
2085 // text-align: right 2088 // text-align: right
2086 LoadHTML("<STYLE>input{direction:ltr;text-align:right}</STYLE>" 2089 LoadHTML("<STYLE>input{direction:ltr;text-align:right}</STYLE>"
2087 "<FORM>" 2090 "<FORM>"
2088 " <INPUT type='text' id='element'/>" 2091 " <INPUT type='text' id='element'/>"
2089 "</FORM>"); 2092 "</FORM>");
2090 2093
2091 WebFrame* frame = GetMainFrame(); 2094 WebFrame* frame = GetMainFrame();
2092 ASSERT_NE(nullptr, frame); 2095 ASSERT_NE(nullptr, frame);
2093 2096
2094 WebFormControlElement element = GetFormControlElementById("element"); 2097 WebFormControlElement element = GetFormControlElementById("element");
2095 2098
2096 FormFieldData result; 2099 FormFieldData result;
2097 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2100 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2098 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); 2101 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
2099 2102
2100 // text-align: left 2103 // text-align: left
2101 LoadHTML("<STYLE>input{direction:rtl;text-align:left}</STYLE>" 2104 LoadHTML("<STYLE>input{direction:rtl;text-align:left}</STYLE>"
2102 "<FORM>" 2105 "<FORM>"
2103 " <INPUT type='text' id='element'/>" 2106 " <INPUT type='text' id='element'/>"
2104 "</FORM>"); 2107 "</FORM>");
2105 2108
2106 frame = GetMainFrame(); 2109 frame = GetMainFrame();
2107 ASSERT_NE(nullptr, frame); 2110 ASSERT_NE(nullptr, frame);
2108 2111
2109 element = GetFormControlElementById("element"); 2112 element = GetFormControlElementById("element");
2110 2113
2111 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2114 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2112 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); 2115 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction);
2113 } 2116 }
2114 2117
2115 TEST_F(FormAutofillTest, 2118 TEST_F(FormAutofillTest,
2116 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { 2119 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) {
2117 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" 2120 LoadHTML("<STYLE>form{direction:ltr}</STYLE>"
2118 "<FORM dir='rtl'>" 2121 "<FORM dir='rtl'>"
2119 " <INPUT type='text' id='element'/>" 2122 " <INPUT type='text' id='element'/>"
2120 "</FORM>"); 2123 "</FORM>");
2121 2124
2122 WebFrame* frame = GetMainFrame(); 2125 WebFrame* frame = GetMainFrame();
2123 ASSERT_NE(nullptr, frame); 2126 ASSERT_NE(nullptr, frame);
2124 2127
2125 WebFormControlElement element = GetFormControlElementById("element"); 2128 WebFormControlElement element = GetFormControlElementById("element");
2126 2129
2127 FormFieldData result; 2130 FormFieldData result;
2128 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2131 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2129 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); 2132 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction);
2130 } 2133 }
2131 2134
2132 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { 2135 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) {
2133 LoadHTML("<FORM style='direction:ltr'>" 2136 LoadHTML("<FORM style='direction:ltr'>"
2134 " <SPAN dir='rtl'>" 2137 " <SPAN dir='rtl'>"
2135 " <INPUT type='text' id='element'/>" 2138 " <INPUT type='text' id='element'/>"
2136 " </SPAN>" 2139 " </SPAN>"
2137 "</FORM>"); 2140 "</FORM>");
2138 2141
2139 WebFrame* frame = GetMainFrame(); 2142 WebFrame* frame = GetMainFrame();
2140 ASSERT_NE(nullptr, frame); 2143 ASSERT_NE(nullptr, frame);
2141 2144
2142 WebFormControlElement element = GetFormControlElementById("element"); 2145 WebFormControlElement element = GetFormControlElementById("element");
2143 2146
2144 FormFieldData result; 2147 FormFieldData result;
2145 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); 2148 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result);
2146 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); 2149 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
2147 } 2150 }
2148 2151
2149 TEST_F(FormAutofillTest, WebFormElementToFormData) { 2152 TEST_F(FormAutofillTest, WebFormElementToFormData) {
2150 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" 2153 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
2151 " <LABEL for='firstname'>First name:</LABEL>" 2154 " <LABEL for='firstname'>First name:</LABEL>"
2152 " <INPUT type='text' id='firstname' value='John'/>" 2155 " <INPUT type='text' id='firstname' value='John'/>"
2153 " <LABEL for='lastname'>Last name:</LABEL>" 2156 " <LABEL for='lastname'>Last name:</LABEL>"
2154 " <INPUT type='text' id='lastname' value='Smith'/>" 2157 " <INPUT type='text' id='lastname' value='Smith'/>"
2155 " <LABEL for='street-address'>Address:</LABEL>" 2158 " <LABEL for='street-address'>Address:</LABEL>"
(...skipping 20 matching lines...) Expand all
2176 ASSERT_NE(nullptr, frame); 2179 ASSERT_NE(nullptr, frame);
2177 2180
2178 WebVector<WebFormElement> forms; 2181 WebVector<WebFormElement> forms;
2179 frame->document().forms(forms); 2182 frame->document().forms(forms);
2180 ASSERT_EQ(1U, forms.size()); 2183 ASSERT_EQ(1U, forms.size());
2181 2184
2182 WebInputElement input_element = GetInputElementById("firstname"); 2185 WebInputElement input_element = GetInputElementById("firstname");
2183 2186
2184 FormData form; 2187 FormData form;
2185 FormFieldData field; 2188 FormFieldData field;
2186 EXPECT_TRUE(WebFormElementToFormData(forms[0], 2189 EXPECT_TRUE(WebFormElementToFormData(forms[0], input_element, nullptr,
2187 input_element, 2190 EXTRACT_VALUE, &form, &field));
2188 EXTRACT_VALUE,
2189 &form,
2190 &field));
2191 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 2191 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2192 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin); 2192 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin);
2193 EXPECT_FALSE(form.origin.is_empty()); 2193 EXPECT_FALSE(form.origin.is_empty());
2194 EXPECT_EQ(GURL("http://cnn.com"), form.action); 2194 EXPECT_EQ(GURL("http://cnn.com"), form.action);
2195 2195
2196 const std::vector<FormFieldData>& fields = form.fields; 2196 const std::vector<FormFieldData>& fields = form.fields;
2197 ASSERT_EQ(6U, fields.size()); 2197 ASSERT_EQ(6U, fields.size());
2198 2198
2199 FormFieldData expected; 2199 FormFieldData expected;
2200 expected.name = ASCIIToUTF16("firstname"); 2200 expected.name = ASCIIToUTF16("firstname");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 2250
2251 WebFrame* frame = GetMainFrame(); 2251 WebFrame* frame = GetMainFrame();
2252 ASSERT_NE(nullptr, frame); 2252 ASSERT_NE(nullptr, frame);
2253 2253
2254 WebFormElement web_form = frame->document().getElementById("form") 2254 WebFormElement web_form = frame->document().getElementById("form")
2255 .to<WebFormElement>(); 2255 .to<WebFormElement>();
2256 ASSERT_FALSE(web_form.isNull()); 2256 ASSERT_FALSE(web_form.isNull());
2257 2257
2258 FormData form; 2258 FormData form;
2259 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), 2259 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(),
2260 EXTRACT_NONE, &form, nullptr)); 2260 nullptr, EXTRACT_NONE, &form, nullptr));
2261 2261
2262 const std::vector<FormFieldData>& fields = form.fields; 2262 const std::vector<FormFieldData>& fields = form.fields;
2263 ASSERT_EQ(1U, fields.size()); 2263 ASSERT_EQ(1U, fields.size());
2264 EXPECT_EQ(ASCIIToUTF16("firstname"), fields[0].name); 2264 EXPECT_EQ(ASCIIToUTF16("firstname"), fields[0].name);
2265 } 2265 }
2266 2266
2267 // TODO(crbug.com/616730) Flaky. 2267 // TODO(crbug.com/616730) Flaky.
2268 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) 2268 #if defined(OS_CHROMEOS) || defined(OS_MACOSX)
2269 #define MAYBE_WebFormElementToFormDataTooManyFields \ 2269 #define MAYBE_WebFormElementToFormDataTooManyFields \
2270 DISABLED_WebFormElementToFormDataTooManyFields 2270 DISABLED_WebFormElementToFormDataTooManyFields
(...skipping 15 matching lines...) Expand all
2286 ASSERT_NE(nullptr, frame); 2286 ASSERT_NE(nullptr, frame);
2287 2287
2288 WebVector<WebFormElement> forms; 2288 WebVector<WebFormElement> forms;
2289 frame->document().forms(forms); 2289 frame->document().forms(forms);
2290 ASSERT_EQ(1U, forms.size()); 2290 ASSERT_EQ(1U, forms.size());
2291 2291
2292 WebInputElement input_element = GetInputElementById("firstname"); 2292 WebInputElement input_element = GetInputElementById("firstname");
2293 2293
2294 FormData form; 2294 FormData form;
2295 FormFieldData field; 2295 FormFieldData field;
2296 EXPECT_FALSE(WebFormElementToFormData(forms[0], 2296 EXPECT_FALSE(WebFormElementToFormData(forms[0], input_element, nullptr,
2297 input_element, 2297 EXTRACT_VALUE, &form, &field));
2298 EXTRACT_VALUE,
2299 &form,
2300 &field));
2301 } 2298 }
2302 2299
2303 // Tests that the |should_autocomplete| is set to false for all the fields when 2300 // Tests that the |should_autocomplete| is set to false for all the fields when
2304 // an autocomplete='off' attribute is set for the form in HTML. 2301 // an autocomplete='off' attribute is set for the form in HTML.
2305 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnForm) { 2302 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnForm) {
2306 LoadHTML( 2303 LoadHTML(
2307 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " 2304 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' "
2308 "autocomplete='off'>" 2305 "autocomplete='off'>"
2309 " <LABEL for='firstname'>First name:</LABEL>" 2306 " <LABEL for='firstname'>First name:</LABEL>"
2310 " <INPUT type='text' id='firstname' value='John'/>" 2307 " <INPUT type='text' id='firstname' value='John'/>"
2311 " <LABEL for='lastname'>Last name:</LABEL>" 2308 " <LABEL for='lastname'>Last name:</LABEL>"
2312 " <INPUT type='text' id='lastname' value='Smith'/>" 2309 " <INPUT type='text' id='lastname' value='Smith'/>"
2313 " <LABEL for='street-address'>Address:</LABEL>" 2310 " <LABEL for='street-address'>Address:</LABEL>"
2314 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" 2311 " <INPUT type='text' id='addressline1' value='123 Test st.'/>"
2315 "</FORM>"); 2312 "</FORM>");
2316 2313
2317 WebFrame* frame = GetMainFrame(); 2314 WebFrame* frame = GetMainFrame();
2318 ASSERT_NE(nullptr, frame); 2315 ASSERT_NE(nullptr, frame);
2319 2316
2320 WebFormElement web_form = 2317 WebFormElement web_form =
2321 frame->document().getElementById("form").to<WebFormElement>(); 2318 frame->document().getElementById("form").to<WebFormElement>();
2322 ASSERT_FALSE(web_form.isNull()); 2319 ASSERT_FALSE(web_form.isNull());
2323 2320
2324 FormData form; 2321 FormData form;
2325 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), 2322 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(),
2326 EXTRACT_NONE, &form, nullptr)); 2323 nullptr, EXTRACT_NONE, &form, nullptr));
2327 2324
2328 for (const FormFieldData& field : form.fields) { 2325 for (const FormFieldData& field : form.fields) {
2329 EXPECT_FALSE(field.should_autocomplete); 2326 EXPECT_FALSE(field.should_autocomplete);
2330 } 2327 }
2331 } 2328 }
2332 2329
2333 // Tests that the |should_autocomplete| is set to false only for the field 2330 // Tests that the |should_autocomplete| is set to false only for the field
2334 // which has an autocomplete='off' attribute set for it in HTML. 2331 // which has an autocomplete='off' attribute set for it in HTML.
2335 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnField) { 2332 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnField) {
2336 LoadHTML( 2333 LoadHTML(
2337 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post'>" 2334 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post'>"
2338 " <LABEL for='firstname'>First name:</LABEL>" 2335 " <LABEL for='firstname'>First name:</LABEL>"
2339 " <INPUT type='text' id='firstname' value='John' autocomplete='off'/>" 2336 " <INPUT type='text' id='firstname' value='John' autocomplete='off'/>"
2340 " <LABEL for='lastname'>Last name:</LABEL>" 2337 " <LABEL for='lastname'>Last name:</LABEL>"
2341 " <INPUT type='text' id='lastname' value='Smith'/>" 2338 " <INPUT type='text' id='lastname' value='Smith'/>"
2342 " <LABEL for='street-address'>Address:</LABEL>" 2339 " <LABEL for='street-address'>Address:</LABEL>"
2343 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" 2340 " <INPUT type='text' id='addressline1' value='123 Test st.'/>"
2344 "</FORM>"); 2341 "</FORM>");
2345 2342
2346 WebFrame* frame = GetMainFrame(); 2343 WebFrame* frame = GetMainFrame();
2347 ASSERT_NE(nullptr, frame); 2344 ASSERT_NE(nullptr, frame);
2348 2345
2349 WebFormElement web_form = 2346 WebFormElement web_form =
2350 frame->document().getElementById("form").to<WebFormElement>(); 2347 frame->document().getElementById("form").to<WebFormElement>();
2351 ASSERT_FALSE(web_form.isNull()); 2348 ASSERT_FALSE(web_form.isNull());
2352 2349
2353 FormData form; 2350 FormData form;
2354 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), 2351 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(),
2355 EXTRACT_NONE, &form, nullptr)); 2352 nullptr, EXTRACT_NONE, &form, nullptr));
2356 2353
2357 ASSERT_EQ(3U, form.fields.size()); 2354 ASSERT_EQ(3U, form.fields.size());
2358 2355
2359 EXPECT_FALSE(form.fields[0].should_autocomplete); 2356 EXPECT_FALSE(form.fields[0].should_autocomplete);
2360 EXPECT_TRUE(form.fields[1].should_autocomplete); 2357 EXPECT_TRUE(form.fields[1].should_autocomplete);
2361 EXPECT_TRUE(form.fields[2].should_autocomplete); 2358 EXPECT_TRUE(form.fields[2].should_autocomplete);
2362 } 2359 }
2363 2360
2364 // Tests CSS classes are set. 2361 // Tests CSS classes are set.
2365 TEST_F(FormAutofillTest, WebFormElementToFormData_CssClasses) { 2362 TEST_F(FormAutofillTest, WebFormElementToFormData_CssClasses) {
2366 LoadHTML( 2363 LoadHTML(
2367 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " 2364 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' "
2368 "autocomplete='off'>" 2365 "autocomplete='off'>"
2369 " <INPUT type='text' id='firstname' class='firstname_field' />" 2366 " <INPUT type='text' id='firstname' class='firstname_field' />"
2370 " <INPUT type='text' id='lastname' class='lastname_field' />" 2367 " <INPUT type='text' id='lastname' class='lastname_field' />"
2371 " <INPUT type='text' id='addressline1' />" 2368 " <INPUT type='text' id='addressline1' />"
2372 "</FORM>"); 2369 "</FORM>");
2373 2370
2374 WebFrame* frame = GetMainFrame(); 2371 WebFrame* frame = GetMainFrame();
2375 ASSERT_NE(nullptr, frame); 2372 ASSERT_NE(nullptr, frame);
2376 2373
2377 WebFormElement web_form = 2374 WebFormElement web_form =
2378 frame->document().getElementById("form").to<WebFormElement>(); 2375 frame->document().getElementById("form").to<WebFormElement>();
2379 ASSERT_FALSE(web_form.isNull()); 2376 ASSERT_FALSE(web_form.isNull());
2380 2377
2381 FormData form; 2378 FormData form;
2382 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), 2379 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(),
2383 EXTRACT_NONE, &form, nullptr)); 2380 nullptr, EXTRACT_NONE, &form, nullptr));
2384 2381
2385 EXPECT_EQ(3U, form.fields.size()); 2382 EXPECT_EQ(3U, form.fields.size());
2386 EXPECT_EQ(ASCIIToUTF16("firstname_field"), form.fields[0].css_classes); 2383 EXPECT_EQ(ASCIIToUTF16("firstname_field"), form.fields[0].css_classes);
2387 EXPECT_EQ(ASCIIToUTF16("lastname_field"), form.fields[1].css_classes); 2384 EXPECT_EQ(ASCIIToUTF16("lastname_field"), form.fields[1].css_classes);
2388 EXPECT_EQ(base::string16(), form.fields[2].css_classes); 2385 EXPECT_EQ(base::string16(), form.fields[2].css_classes);
2389 } 2386 }
2390 2387
2391 TEST_F(FormAutofillTest, ExtractForms) { 2388 TEST_F(FormAutofillTest, ExtractForms) {
2392 ExpectJohnSmithLabels( 2389 ExpectJohnSmithLabels(
2393 "<FORM name='TestForm' action='http://cnn.com' method='post'>" 2390 "<FORM name='TestForm' action='http://cnn.com' method='post'>"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2661 WebFrame* web_frame = GetMainFrame(); 2658 WebFrame* web_frame = GetMainFrame();
2662 ASSERT_NE(nullptr, web_frame); 2659 ASSERT_NE(nullptr, web_frame);
2663 2660
2664 WebVector<WebFormElement> web_forms; 2661 WebVector<WebFormElement> web_forms;
2665 web_frame->document().forms(web_forms); 2662 web_frame->document().forms(web_forms);
2666 ASSERT_EQ(1U, web_forms.size()); 2663 ASSERT_EQ(1U, web_forms.size());
2667 WebFormElement web_form = web_forms[0]; 2664 WebFormElement web_form = web_forms[0];
2668 2665
2669 FormData form; 2666 FormData form;
2670 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), 2667 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(),
2671 EXTRACT_NONE, &form, nullptr)); 2668 nullptr, EXTRACT_NONE, &form,
2669 nullptr));
2672 } 2670 }
2673 } 2671 }
2674 2672
2675 TEST_F(FormAutofillTest, FindFormForInputElement) { 2673 TEST_F(FormAutofillTest, FindFormForInputElement) {
2676 TestFindFormForInputElement( 2674 TestFindFormForInputElement(
2677 "<FORM name='TestForm' action='http://abc.com' method='post'>" 2675 "<FORM name='TestForm' action='http://abc.com' method='post'>"
2678 " <INPUT type='text' id='firstname' value='John'/>" 2676 " <INPUT type='text' id='firstname' value='John'/>"
2679 " <INPUT type='text' id='lastname' value='Smith'/>" 2677 " <INPUT type='text' id='lastname' value='Smith'/>"
2680 " <INPUT type='text' id='email' value='john@example.com'" 2678 " <INPUT type='text' id='email' value='john@example.com'"
2681 "autocomplete='off' />" 2679 "autocomplete='off' />"
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
3948 "</FORM>"); 3946 "</FORM>");
3949 3947
3950 WebFrame* frame = GetMainFrame(); 3948 WebFrame* frame = GetMainFrame();
3951 ASSERT_NE(nullptr, frame); 3949 ASSERT_NE(nullptr, frame);
3952 3950
3953 WebVector<WebFormElement> forms; 3951 WebVector<WebFormElement> forms;
3954 frame->document().forms(forms); 3952 frame->document().forms(forms);
3955 ASSERT_EQ(1U, forms.size()); 3953 ASSERT_EQ(1U, forms.size());
3956 3954
3957 FormData form; 3955 FormData form;
3958 EXPECT_TRUE(WebFormElementToFormData(forms[0], 3956 EXPECT_TRUE(WebFormElementToFormData(forms[0], WebFormControlElement(),
3959 WebFormControlElement(), 3957 nullptr, EXTRACT_VALUE, &form, nullptr));
3960 EXTRACT_VALUE,
3961 &form,
3962 nullptr));
3963 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 3958 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
3964 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin); 3959 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin);
3965 EXPECT_FALSE(form.origin.is_empty()); 3960 EXPECT_FALSE(form.origin.is_empty());
3966 EXPECT_EQ(GURL("http://cnn.com"), form.action); 3961 EXPECT_EQ(GURL("http://cnn.com"), form.action);
3967 3962
3968 const std::vector<FormFieldData>& fields = form.fields; 3963 const std::vector<FormFieldData>& fields = form.fields;
3969 ASSERT_EQ(4U, fields.size()); 3964 ASSERT_EQ(4U, fields.size());
3970 3965
3971 FormFieldData expected; 3966 FormFieldData expected;
3972 expected.form_control_type = "text"; 3967 expected.form_control_type = "text";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
4006 "</FORM>"); 4001 "</FORM>");
4007 4002
4008 WebFrame* frame = GetMainFrame(); 4003 WebFrame* frame = GetMainFrame();
4009 ASSERT_NE(nullptr, frame); 4004 ASSERT_NE(nullptr, frame);
4010 4005
4011 WebVector<WebFormElement> forms; 4006 WebVector<WebFormElement> forms;
4012 frame->document().forms(forms); 4007 frame->document().forms(forms);
4013 ASSERT_EQ(1U, forms.size()); 4008 ASSERT_EQ(1U, forms.size());
4014 4009
4015 FormData form; 4010 FormData form;
4016 EXPECT_TRUE(WebFormElementToFormData(forms[0], 4011 EXPECT_TRUE(WebFormElementToFormData(forms[0], WebFormControlElement(),
4017 WebFormControlElement(), 4012 nullptr, EXTRACT_VALUE, &form, nullptr));
4018 EXTRACT_VALUE,
4019 &form,
4020 nullptr));
4021 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 4013 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
4022 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin); 4014 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin);
4023 EXPECT_EQ(GURL("http://cnn.com"), form.action); 4015 EXPECT_EQ(GURL("http://cnn.com"), form.action);
4024 4016
4025 const std::vector<FormFieldData>& fields = form.fields; 4017 const std::vector<FormFieldData>& fields = form.fields;
4026 ASSERT_EQ(6U, fields.size()); 4018 ASSERT_EQ(6U, fields.size());
4027 4019
4028 FormFieldData expected; 4020 FormFieldData expected;
4029 expected.form_control_type = "text"; 4021 expected.form_control_type = "text";
4030 4022
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
4352 select_element.setValue(WebString::fromUTF8("AL")); 4344 select_element.setValue(WebString::fromUTF8("AL"));
4353 4345
4354 WebVector<WebFormElement> forms; 4346 WebVector<WebFormElement> forms;
4355 frame->document().forms(forms); 4347 frame->document().forms(forms);
4356 ASSERT_EQ(1U, forms.size()); 4348 ASSERT_EQ(1U, forms.size());
4357 4349
4358 FormData form; 4350 FormData form;
4359 4351
4360 // Extract the country select-one value as text. 4352 // Extract the country select-one value as text.
4361 EXPECT_TRUE(WebFormElementToFormData( 4353 EXPECT_TRUE(WebFormElementToFormData(
4362 forms[0], WebFormControlElement(), 4354 forms[0], WebFormControlElement(), nullptr,
4363 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), &form, 4355 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), &form,
4364 nullptr)); 4356 nullptr));
4365 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 4357 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
4366 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin); 4358 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin);
4367 EXPECT_EQ(GURL("http://cnn.com"), form.action); 4359 EXPECT_EQ(GURL("http://cnn.com"), form.action);
4368 4360
4369 const std::vector<FormFieldData>& fields = form.fields; 4361 const std::vector<FormFieldData>& fields = form.fields;
4370 ASSERT_EQ(3U, fields.size()); 4362 ASSERT_EQ(3U, fields.size());
4371 4363
4372 FormFieldData expected; 4364 FormFieldData expected;
(...skipping 14 matching lines...) Expand all
4387 4379
4388 expected.name = ASCIIToUTF16("country"); 4380 expected.name = ASCIIToUTF16("country");
4389 expected.value = ASCIIToUTF16("Albania"); 4381 expected.value = ASCIIToUTF16("Albania");
4390 expected.label.clear(); 4382 expected.label.clear();
4391 expected.form_control_type = "select-one"; 4383 expected.form_control_type = "select-one";
4392 expected.max_length = 0; 4384 expected.max_length = 0;
4393 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 4385 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
4394 4386
4395 form.fields.clear(); 4387 form.fields.clear();
4396 // Extract the country select-one value as value. 4388 // Extract the country select-one value as value.
4397 EXPECT_TRUE(WebFormElementToFormData(forms[0], 4389 EXPECT_TRUE(WebFormElementToFormData(forms[0], WebFormControlElement(),
4398 WebFormControlElement(), 4390 nullptr, EXTRACT_VALUE, &form, nullptr));
4399 EXTRACT_VALUE,
4400 &form,
4401 nullptr));
4402 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 4391 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
4403 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin); 4392 EXPECT_EQ(GetCanonicalOriginForDocument(frame->document()), form.origin);
4404 EXPECT_EQ(GURL("http://cnn.com"), form.action); 4393 EXPECT_EQ(GURL("http://cnn.com"), form.action);
4405 4394
4406 ASSERT_EQ(3U, fields.size()); 4395 ASSERT_EQ(3U, fields.size());
4407 4396
4408 expected.name = ASCIIToUTF16("firstname"); 4397 expected.name = ASCIIToUTF16("firstname");
4409 expected.value = ASCIIToUTF16("John"); 4398 expected.value = ASCIIToUTF16("John");
4410 expected.label = ASCIIToUTF16("John"); 4399 expected.label = ASCIIToUTF16("John");
4411 expected.form_control_type = "text"; 4400 expected.form_control_type = "text";
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
4639 4628
4640 if (test_case.has_extracted_form) { 4629 if (test_case.has_extracted_form) {
4641 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); 4630 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag);
4642 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); 4631 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout);
4643 } 4632 }
4644 } 4633 }
4645 } 4634 }
4646 4635
4647 } // namespace form_util 4636 } // namespace form_util
4648 } // namespace autofill 4637 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698