OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 311 } |
312 EXPECT_TRUE(filled_form.user_submitted); | 312 EXPECT_TRUE(filled_form.user_submitted); |
313 | 313 |
314 size_t form_size = 0; | 314 size_t form_size = 0; |
315 if (has_address_fields) | 315 if (has_address_fields) |
316 form_size += kAddressFormSize; | 316 form_size += kAddressFormSize; |
317 if (has_credit_card_fields) | 317 if (has_credit_card_fields) |
318 form_size += kCreditCardFormSize; | 318 form_size += kCreditCardFormSize; |
319 ASSERT_EQ(form_size, filled_form.fields.size()); | 319 ASSERT_EQ(form_size, filled_form.fields.size()); |
320 | 320 |
321 FormField field; | |
322 if (has_address_fields) { | 321 if (has_address_fields) { |
323 ExpectFilledField("First Name", "firstname", first, "text", | 322 ExpectFilledField("First Name", "firstname", first, "text", |
324 filled_form.fields[0]); | 323 filled_form.fields[0]); |
325 ExpectFilledField("Middle Name", "middlename", middle, "text", | 324 ExpectFilledField("Middle Name", "middlename", middle, "text", |
326 filled_form.fields[1]); | 325 filled_form.fields[1]); |
327 ExpectFilledField("Last Name", "lastname", last, "text", | 326 ExpectFilledField("Last Name", "lastname", last, "text", |
328 filled_form.fields[2]); | 327 filled_form.fields[2]); |
329 ExpectFilledField("Address Line 1", "addr1", address1, "text", | 328 ExpectFilledField("Address Line 1", "addr1", address1, "text", |
330 filled_form.fields[3]); | 329 filled_form.fields[3]); |
331 ExpectFilledField("Address Line 2", "addr2", address2, "text", | 330 ExpectFilledField("Address Line 2", "addr2", address2, "text", |
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 for (size_t i = 0; i < kAddressFormSize; ++i) { | 1836 for (size_t i = 0; i < kAddressFormSize; ++i) { |
1838 // Restore the expected field names. | 1837 // Restore the expected field names. |
1839 string16 name = secondSection.fields[i].name; | 1838 string16 name = secondSection.fields[i].name; |
1840 string16 original_name = name.substr(0, name.size() - 1); | 1839 string16 original_name = name.substr(0, name.size() - 1); |
1841 secondSection.fields[i].name = original_name; | 1840 secondSection.fields[i].name = original_name; |
1842 } | 1841 } |
1843 ExpectFilledAddressFormElvis(page_id, secondSection, kPageID2, false); | 1842 ExpectFilledAddressFormElvis(page_id, secondSection, kPageID2, false); |
1844 } | 1843 } |
1845 } | 1844 } |
1846 | 1845 |
| 1846 // Test that we correctly fill a form that has author-specified sections, which |
| 1847 // might not match our expected section breakdown. |
| 1848 TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) { |
| 1849 // Create a form with a billing section and an unnamed section, interleaved. |
| 1850 // The billing section includes both address and credit card fields. |
| 1851 FormData form; |
| 1852 form.name = ASCIIToUTF16("MyForm"); |
| 1853 form.method = ASCIIToUTF16("POST"); |
| 1854 form.origin = GURL("https://myform.com/form.html"); |
| 1855 form.action = GURL("https://myform.com/submit.html"); |
| 1856 form.user_submitted = true; |
| 1857 |
| 1858 FormField field; |
| 1859 |
| 1860 autofill_test::CreateTestFormField("", "country", "", "text", &field); |
| 1861 field.autocomplete_type = ASCIIToUTF16("section-billing country"); |
| 1862 form.fields.push_back(field); |
| 1863 |
| 1864 autofill_test::CreateTestFormField("", "firstname", "", "text", &field); |
| 1865 field.autocomplete_type = ASCIIToUTF16("given-name"); |
| 1866 form.fields.push_back(field); |
| 1867 |
| 1868 autofill_test::CreateTestFormField("", "lastname", "", "text", &field); |
| 1869 field.autocomplete_type = ASCIIToUTF16("surname"); |
| 1870 form.fields.push_back(field); |
| 1871 |
| 1872 autofill_test::CreateTestFormField("", "address", "", "text", &field); |
| 1873 field.autocomplete_type = ASCIIToUTF16("section-billing street-address"); |
| 1874 form.fields.push_back(field); |
| 1875 |
| 1876 autofill_test::CreateTestFormField("", "city", "", "text", &field); |
| 1877 field.autocomplete_type = ASCIIToUTF16("section-billing locality"); |
| 1878 form.fields.push_back(field); |
| 1879 |
| 1880 autofill_test::CreateTestFormField("", "state", "", "text", &field); |
| 1881 field.autocomplete_type = ASCIIToUTF16("section-billing administrative-area"); |
| 1882 form.fields.push_back(field); |
| 1883 |
| 1884 autofill_test::CreateTestFormField("", "zip", "", "text", &field); |
| 1885 field.autocomplete_type = ASCIIToUTF16("section-billing postal-code"); |
| 1886 form.fields.push_back(field); |
| 1887 |
| 1888 autofill_test::CreateTestFormField("", "ccname", "", "text", &field); |
| 1889 field.autocomplete_type = ASCIIToUTF16("section-billing cc-full-name"); |
| 1890 form.fields.push_back(field); |
| 1891 |
| 1892 autofill_test::CreateTestFormField("", "ccnumber", "", "text", &field); |
| 1893 field.autocomplete_type = ASCIIToUTF16("section-billing cc-number"); |
| 1894 form.fields.push_back(field); |
| 1895 |
| 1896 autofill_test::CreateTestFormField("", "ccexp", "", "text", &field); |
| 1897 field.autocomplete_type = ASCIIToUTF16("section-billing cc-exp"); |
| 1898 form.fields.push_back(field); |
| 1899 |
| 1900 autofill_test::CreateTestFormField("", "email", "", "text", &field); |
| 1901 field.autocomplete_type = ASCIIToUTF16("email"); |
| 1902 form.fields.push_back(field); |
| 1903 |
| 1904 std::vector<FormData> forms(1, form); |
| 1905 FormsSeen(forms); |
| 1906 |
| 1907 // Fill the unnamed section. |
| 1908 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 1909 GUIDPair empty(std::string(), 0); |
| 1910 FillAutofillFormData(kDefaultPageID, form, form.fields[1], |
| 1911 autofill_manager_->PackGUIDs(empty, guid)); |
| 1912 |
| 1913 int page_id = 0; |
| 1914 FormData results; |
| 1915 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
| 1916 { |
| 1917 SCOPED_TRACE("Unnamed section"); |
| 1918 EXPECT_EQ(kDefaultPageID, page_id); |
| 1919 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
| 1920 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
| 1921 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); |
| 1922 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); |
| 1923 EXPECT_TRUE(results.user_submitted); |
| 1924 ASSERT_EQ(11U, results.fields.size()); |
| 1925 |
| 1926 ExpectFilledField("", "country", "", "text", results.fields[0]); |
| 1927 ExpectFilledField("", "firstname", "Elvis", "text", results.fields[1]); |
| 1928 ExpectFilledField("", "lastname", "Presley", "text", results.fields[2]); |
| 1929 ExpectFilledField("", "address", "", "text", results.fields[3]); |
| 1930 ExpectFilledField("", "city", "", "text", results.fields[4]); |
| 1931 ExpectFilledField("", "state", "", "text", results.fields[5]); |
| 1932 ExpectFilledField("", "zip", "", "text", results.fields[6]); |
| 1933 ExpectFilledField("", "ccname", "", "text", results.fields[7]); |
| 1934 ExpectFilledField("", "ccnumber", "", "text", results.fields[8]); |
| 1935 ExpectFilledField("", "ccexp", "", "text", results.fields[9]); |
| 1936 ExpectFilledField("", "email", "theking@gmail.com", "text", |
| 1937 results.fields[10]); |
| 1938 } |
| 1939 |
| 1940 // Fill the address portion of the billing section. |
| 1941 const int kPageID2 = 2; |
| 1942 GUIDPair guid2("00000000-0000-0000-0000-000000000001", 0); |
| 1943 FillAutofillFormData(kPageID2, form, form.fields[0], |
| 1944 autofill_manager_->PackGUIDs(empty, guid2)); |
| 1945 |
| 1946 page_id = 0; |
| 1947 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
| 1948 { |
| 1949 SCOPED_TRACE("Billing address"); |
| 1950 EXPECT_EQ(kPageID2, page_id); |
| 1951 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
| 1952 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
| 1953 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); |
| 1954 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); |
| 1955 EXPECT_TRUE(results.user_submitted); |
| 1956 ASSERT_EQ(11U, results.fields.size()); |
| 1957 |
| 1958 ExpectFilledField("", "country", "United States", "text", |
| 1959 results.fields[0]); |
| 1960 ExpectFilledField("", "firstname", "", "text", results.fields[1]); |
| 1961 ExpectFilledField("", "lastname", "", "text", results.fields[2]); |
| 1962 ExpectFilledField("", "address", "3734 Elvis Presley Blvd.", "text", |
| 1963 results.fields[3]); |
| 1964 ExpectFilledField("", "city", "Memphis", "text", results.fields[4]); |
| 1965 ExpectFilledField("", "state", "Tennessee", "text", results.fields[5]); |
| 1966 ExpectFilledField("", "zip", "38116", "text", results.fields[6]); |
| 1967 ExpectFilledField("", "ccname", "", "text", results.fields[7]); |
| 1968 ExpectFilledField("", "ccnumber", "", "text", results.fields[8]); |
| 1969 ExpectFilledField("", "ccexp", "", "text", results.fields[9]); |
| 1970 ExpectFilledField("", "email", "", "text", results.fields[10]); |
| 1971 } |
| 1972 |
| 1973 // Fill the credit card portion of the billing section. |
| 1974 const int kPageID3 = 3; |
| 1975 GUIDPair guid3("00000000-0000-0000-0000-000000000004", 0); |
| 1976 FillAutofillFormData(kPageID3, form, form.fields[form.fields.size() - 2], |
| 1977 autofill_manager_->PackGUIDs(guid3, empty)); |
| 1978 |
| 1979 page_id = 0; |
| 1980 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
| 1981 { |
| 1982 SCOPED_TRACE("Credit card"); |
| 1983 EXPECT_EQ(kPageID3, page_id); |
| 1984 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
| 1985 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
| 1986 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); |
| 1987 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); |
| 1988 EXPECT_TRUE(results.user_submitted); |
| 1989 ASSERT_EQ(11U, results.fields.size()); |
| 1990 |
| 1991 ExpectFilledField("", "country", "", "text", results.fields[0]); |
| 1992 ExpectFilledField("", "firstname", "", "text", results.fields[1]); |
| 1993 ExpectFilledField("", "lastname", "", "text", results.fields[2]); |
| 1994 ExpectFilledField("", "address", "", "text", results.fields[3]); |
| 1995 ExpectFilledField("", "city", "", "text", results.fields[4]); |
| 1996 ExpectFilledField("", "state", "", "text", results.fields[5]); |
| 1997 ExpectFilledField("", "zip", "", "text", results.fields[6]); |
| 1998 ExpectFilledField("", "ccname", "Elvis Presley", "text", results.fields[7]); |
| 1999 ExpectFilledField("", "ccnumber", "4234567890123456", "text", |
| 2000 results.fields[8]); |
| 2001 ExpectFilledField("", "ccexp", "04/2012", "text", results.fields[9]); |
| 2002 ExpectFilledField("", "email", "", "text", results.fields[10]); |
| 2003 } |
| 2004 } |
| 2005 |
1847 // Test that we correctly fill a form that has a single logical section with | 2006 // Test that we correctly fill a form that has a single logical section with |
1848 // multiple email address fields. | 2007 // multiple email address fields. |
1849 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { | 2008 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { |
1850 // Set up our form data. | 2009 // Set up our form data. |
1851 FormData form; | 2010 FormData form; |
1852 CreateTestAddressFormData(&form); | 2011 CreateTestAddressFormData(&form); |
1853 FormField field; | 2012 FormField field; |
1854 autofill_test::CreateTestFormField( | 2013 autofill_test::CreateTestFormField( |
1855 "Confirm email", "email2", "", "text", &field); | 2014 "Confirm email", "email2", "", "text", &field); |
1856 form.fields.push_back(field); | 2015 form.fields.push_back(field); |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2557 const FieldTypeSet& possible_types1 = | 2716 const FieldTypeSet& possible_types1 = |
2558 form_structure.field(1)->possible_types(); | 2717 form_structure.field(1)->possible_types(); |
2559 EXPECT_EQ(1U, possible_types1.size()); | 2718 EXPECT_EQ(1U, possible_types1.size()); |
2560 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); | 2719 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); |
2561 const FieldTypeSet& possible_types2 = | 2720 const FieldTypeSet& possible_types2 = |
2562 form_structure.field(2)->possible_types(); | 2721 form_structure.field(2)->possible_types(); |
2563 EXPECT_EQ(1U, possible_types2.size()); | 2722 EXPECT_EQ(1U, possible_types2.size()); |
2564 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != | 2723 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != |
2565 possible_types2.end()); | 2724 possible_types2.end()); |
2566 } | 2725 } |
OLD | NEW |