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

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

Issue 1106313002: Revert of Limit form-less Autofilling to pages that look like checkout pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | chrome/test/data/autofill/autofill_noform_dynamic.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 5 #include <vector>
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 " <SELECT id='select-unchanged'>" 83 " <SELECT id='select-unchanged'>"
84 " <OPTION value='CA' selected>California</OPTION>" 84 " <OPTION value='CA' selected>California</OPTION>"
85 " <OPTION value='TX'>Texas</OPTION>" 85 " <OPTION value='TX'>Texas</OPTION>"
86 " </SELECT>" 86 " </SELECT>"
87 " <TEXTAREA id='textarea'></TEXTAREA>" 87 " <TEXTAREA id='textarea'></TEXTAREA>"
88 " <TEXTAREA id='textarea-nonempty'>Go&#10;away!</TEXTAREA>" 88 " <TEXTAREA id='textarea-nonempty'>Go&#10;away!</TEXTAREA>"
89 " <INPUT type='submit' name='reply-send' value='Send'/>" 89 " <INPUT type='submit' name='reply-send' value='Send'/>"
90 "</FORM>"; 90 "</FORM>";
91 91
92 const char kUnownedFormHtml[] = 92 const char kUnownedFormHtml[] =
93 "<HEAD><TITLE>enter shipping info</TITLE></HEAD>"
94 "<INPUT type='text' id='firstname'/>" 93 "<INPUT type='text' id='firstname'/>"
95 "<INPUT type='text' id='lastname'/>" 94 "<INPUT type='text' id='lastname'/>"
96 "<INPUT type='hidden' id='imhidden'/>" 95 "<INPUT type='hidden' id='imhidden'/>"
97 "<INPUT type='text' id='notempty' value='Hi'/>" 96 "<INPUT type='text' id='notempty' value='Hi'/>"
98 "<INPUT type='text' autocomplete='off' id='noautocomplete'/>" 97 "<INPUT type='text' autocomplete='off' id='noautocomplete'/>"
99 "<INPUT type='text' disabled='disabled' id='notenabled'/>" 98 "<INPUT type='text' disabled='disabled' id='notenabled'/>"
100 "<INPUT type='text' readonly id='readonly'/>" 99 "<INPUT type='text' readonly id='readonly'/>"
101 "<INPUT type='text' style='visibility: hidden'" 100 "<INPUT type='text' style='visibility: hidden'"
102 " id='invisible'/>" 101 " id='invisible'/>"
103 "<INPUT type='text' style='display: none' id='displaynone'/>" 102 "<INPUT type='text' style='display: none' id='displaynone'/>"
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1030
1032 // Verify that the auto-filled attribute has been turned off. 1031 // Verify that the auto-filled attribute has been turned off.
1033 EXPECT_FALSE(firstname.isAutofilled()); 1032 EXPECT_FALSE(firstname.isAutofilled());
1034 1033
1035 // Verify the form is cleared. 1034 // Verify the form is cleared.
1036 FormData form; 1035 FormData form;
1037 FormFieldData field; 1036 FormFieldData field;
1038 EXPECT_TRUE( 1037 EXPECT_TRUE(
1039 FindFormAndFieldForFormControlElement(firstname, &form, &field)); 1038 FindFormAndFieldForFormControlElement(firstname, &form, &field));
1040 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 1039 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
1041 EXPECT_FALSE(form.origin.is_empty());
1042 if (!unowned) { 1040 if (!unowned) {
1043 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 1041 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1044 EXPECT_EQ(GURL("http://buh.com"), form.action); 1042 EXPECT_EQ(GURL("http://buh.com"), form.action);
1045 } 1043 }
1046 1044
1047 const std::vector<FormFieldData>& fields = form.fields; 1045 const std::vector<FormFieldData>& fields = form.fields;
1048 ASSERT_EQ(9U, fields.size()); 1046 ASSERT_EQ(9U, fields.size());
1049 1047
1050 FormFieldData expected; 1048 FormFieldData expected;
1051 expected.form_control_type = "text"; 1049 expected.form_control_type = "text";
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1124
1127 // Verify that the auto-filled attribute has been turned off. 1125 // Verify that the auto-filled attribute has been turned off.
1128 EXPECT_FALSE(firstname.isAutofilled()); 1126 EXPECT_FALSE(firstname.isAutofilled());
1129 1127
1130 // Verify the form is cleared. 1128 // Verify the form is cleared.
1131 FormData form; 1129 FormData form;
1132 FormFieldData field; 1130 FormFieldData field;
1133 EXPECT_TRUE( 1131 EXPECT_TRUE(
1134 FindFormAndFieldForFormControlElement(firstname, &form, &field)); 1132 FindFormAndFieldForFormControlElement(firstname, &form, &field));
1135 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 1133 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
1136 EXPECT_FALSE(form.origin.is_empty());
1137 if (!unowned) { 1134 if (!unowned) {
1138 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 1135 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1139 EXPECT_EQ(GURL("http://buh.com"), form.action); 1136 EXPECT_EQ(GURL("http://buh.com"), form.action);
1140 } 1137 }
1141 1138
1142 const std::vector<FormFieldData>& fields = form.fields; 1139 const std::vector<FormFieldData>& fields = form.fields;
1143 ASSERT_EQ(3U, fields.size()); 1140 ASSERT_EQ(3U, fields.size());
1144 1141
1145 FormFieldData expected; 1142 FormFieldData expected;
1146 1143
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 1911
1915 FormData form; 1912 FormData form;
1916 FormFieldData field; 1913 FormFieldData field;
1917 EXPECT_TRUE(WebFormElementToFormData(forms[0], 1914 EXPECT_TRUE(WebFormElementToFormData(forms[0],
1918 input_element, 1915 input_element,
1919 EXTRACT_VALUE, 1916 EXTRACT_VALUE,
1920 &form, 1917 &form,
1921 &field)); 1918 &field));
1922 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 1919 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1923 EXPECT_EQ(GURL(frame->document().url()), form.origin); 1920 EXPECT_EQ(GURL(frame->document().url()), form.origin);
1924 EXPECT_FALSE(form.origin.is_empty());
1925 EXPECT_EQ(GURL("http://cnn.com"), form.action); 1921 EXPECT_EQ(GURL("http://cnn.com"), form.action);
1926 1922
1927 const std::vector<FormFieldData>& fields = form.fields; 1923 const std::vector<FormFieldData>& fields = form.fields;
1928 ASSERT_EQ(6U, fields.size()); 1924 ASSERT_EQ(6U, fields.size());
1929 1925
1930 FormFieldData expected; 1926 FormFieldData expected;
1931 expected.name = ASCIIToUTF16("firstname"); 1927 expected.name = ASCIIToUTF16("firstname");
1932 expected.value = ASCIIToUTF16("John"); 1928 expected.value = ASCIIToUTF16("John");
1933 expected.label = ASCIIToUTF16("First name:"); 1929 expected.label = ASCIIToUTF16("First name:");
1934 expected.form_control_type = "text"; 1930 expected.form_control_type = "text";
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 ASSERT_NE(nullptr, web_frame); 2023 ASSERT_NE(nullptr, web_frame);
2028 2024
2029 FormCache form_cache(*web_frame); 2025 FormCache form_cache(*web_frame);
2030 std::vector<FormData> forms = form_cache.ExtractNewForms(); 2026 std::vector<FormData> forms = form_cache.ExtractNewForms();
2031 ASSERT_EQ(2U, forms.size()); 2027 ASSERT_EQ(2U, forms.size());
2032 2028
2033 // First form. 2029 // First form.
2034 const FormData& form = forms[0]; 2030 const FormData& form = forms[0];
2035 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 2031 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2036 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 2032 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2037 EXPECT_FALSE(form.origin.is_empty());
2038 EXPECT_EQ(GURL("http://cnn.com"), form.action); 2033 EXPECT_EQ(GURL("http://cnn.com"), form.action);
2039 2034
2040 const std::vector<FormFieldData>& fields = form.fields; 2035 const std::vector<FormFieldData>& fields = form.fields;
2041 ASSERT_EQ(3U, fields.size()); 2036 ASSERT_EQ(3U, fields.size());
2042 2037
2043 FormFieldData expected; 2038 FormFieldData expected;
2044 expected.form_control_type = "text"; 2039 expected.form_control_type = "text";
2045 expected.max_length = WebInputElement::defaultMaxLength(); 2040 expected.max_length = WebInputElement::defaultMaxLength();
2046 2041
2047 expected.name = ASCIIToUTF16("firstname"); 2042 expected.name = ASCIIToUTF16("firstname");
2048 expected.value = ASCIIToUTF16("John"); 2043 expected.value = ASCIIToUTF16("John");
2049 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); 2044 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2050 2045
2051 expected.name = ASCIIToUTF16("lastname"); 2046 expected.name = ASCIIToUTF16("lastname");
2052 expected.value = ASCIIToUTF16("Smith"); 2047 expected.value = ASCIIToUTF16("Smith");
2053 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 2048 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2054 2049
2055 expected.name = ASCIIToUTF16("email"); 2050 expected.name = ASCIIToUTF16("email");
2056 expected.value = ASCIIToUTF16("john@example.com"); 2051 expected.value = ASCIIToUTF16("john@example.com");
2057 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 2052 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2058 2053
2059 // Second form. 2054 // Second form.
2060 const FormData& form2 = forms[1]; 2055 const FormData& form2 = forms[1];
2061 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); 2056 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name);
2062 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 2057 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2063 EXPECT_FALSE(form.origin.is_empty());
2064 EXPECT_EQ(GURL("http://zoo.com"), form2.action); 2058 EXPECT_EQ(GURL("http://zoo.com"), form2.action);
2065 2059
2066 const std::vector<FormFieldData>& fields2 = form2.fields; 2060 const std::vector<FormFieldData>& fields2 = form2.fields;
2067 ASSERT_EQ(3U, fields2.size()); 2061 ASSERT_EQ(3U, fields2.size());
2068 2062
2069 expected.name = ASCIIToUTF16("firstname"); 2063 expected.name = ASCIIToUTF16("firstname");
2070 expected.value = ASCIIToUTF16("Jack"); 2064 expected.value = ASCIIToUTF16("Jack");
2071 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); 2065 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
2072 2066
2073 expected.name = ASCIIToUTF16("lastname"); 2067 expected.name = ASCIIToUTF16("lastname");
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 " <INPUT type='text' id='email' value='john@example.com'" 2270 " <INPUT type='text' id='email' value='john@example.com'"
2277 "autocomplete='off' />" 2271 "autocomplete='off' />"
2278 " <INPUT type='text' id='phone' value='1.800.555.1234'/>" 2272 " <INPUT type='text' id='phone' value='1.800.555.1234'/>"
2279 " <INPUT type='submit' name='reply-send' value='Send'/>" 2273 " <INPUT type='submit' name='reply-send' value='Send'/>"
2280 "</FORM>", 2274 "</FORM>",
2281 false); 2275 false);
2282 } 2276 }
2283 2277
2284 TEST_F(FormAutofillTest, FindFormForInputElementForUnownedForm) { 2278 TEST_F(FormAutofillTest, FindFormForInputElementForUnownedForm) {
2285 TestFindFormForInputElement( 2279 TestFindFormForInputElement(
2286 "<HEAD><TITLE>delivery recipient</TITLE></HEAD>"
2287 "<INPUT type='text' id='firstname' value='John'/>" 2280 "<INPUT type='text' id='firstname' value='John'/>"
2288 "<INPUT type='text' id='lastname' value='Smith'/>" 2281 "<INPUT type='text' id='lastname' value='Smith'/>"
2289 "<INPUT type='text' id='email' value='john@example.com'" 2282 "<INPUT type='text' id='email' value='john@example.com'"
2290 "autocomplete='off' />" 2283 "autocomplete='off' />"
2291 "<INPUT type='text' id='phone' value='1.800.555.1234'/>" 2284 "<INPUT type='text' id='phone' value='1.800.555.1234'/>"
2292 "<INPUT type='submit' name='reply-send' value='Send'/>", 2285 "<INPUT type='submit' name='reply-send' value='Send'/>",
2293 true); 2286 true);
2294 } 2287 }
2295 2288
2296 TEST_F(FormAutofillTest, FindFormForTextAreaElement) { 2289 TEST_F(FormAutofillTest, FindFormForTextAreaElement) {
2297 TestFindFormForTextAreaElement( 2290 TestFindFormForTextAreaElement(
2298 "<FORM name='TestForm' action='http://buh.com' method='post'>" 2291 "<FORM name='TestForm' action='http://buh.com' method='post'>"
2299 " <INPUT type='text' id='firstname' value='John'/>" 2292 " <INPUT type='text' id='firstname' value='John'/>"
2300 " <INPUT type='text' id='lastname' value='Smith'/>" 2293 " <INPUT type='text' id='lastname' value='Smith'/>"
2301 " <INPUT type='text' id='email' value='john@example.com'" 2294 " <INPUT type='text' id='email' value='john@example.com'"
2302 "autocomplete='off' />" 2295 "autocomplete='off' />"
2303 " <TEXTAREA id='street-address'>" 2296 " <TEXTAREA id='street-address'>"
2304 "123 Fantasy Ln.&#10;" 2297 "123 Fantasy Ln.&#10;"
2305 "Apt. 42" 2298 "Apt. 42"
2306 "</TEXTAREA>" 2299 "</TEXTAREA>"
2307 " <INPUT type='submit' name='reply-send' value='Send'/>" 2300 " <INPUT type='submit' name='reply-send' value='Send'/>"
2308 "</FORM>", 2301 "</FORM>",
2309 false); 2302 false);
2310 } 2303 }
2311 2304
2312 TEST_F(FormAutofillTest, FindFormForTextAreaElementForUnownedForm) { 2305 TEST_F(FormAutofillTest, FindFormForTextAreaElementForUnownedForm) {
2313 TestFindFormForTextAreaElement( 2306 TestFindFormForTextAreaElement(
2314 "<HEAD><TITLE>delivery address</TITLE></HEAD>"
2315 "<INPUT type='text' id='firstname' value='John'/>" 2307 "<INPUT type='text' id='firstname' value='John'/>"
2316 "<INPUT type='text' id='lastname' value='Smith'/>" 2308 "<INPUT type='text' id='lastname' value='Smith'/>"
2317 "<INPUT type='text' id='email' value='john@example.com'" 2309 "<INPUT type='text' id='email' value='john@example.com'"
2318 "autocomplete='off' />" 2310 "autocomplete='off' />"
2319 "<TEXTAREA id='street-address'>" 2311 "<TEXTAREA id='street-address'>"
2320 "123 Fantasy Ln.&#10;" 2312 "123 Fantasy Ln.&#10;"
2321 "Apt. 42" 2313 "Apt. 42"
2322 "</TEXTAREA>" 2314 "</TEXTAREA>"
2323 "<INPUT type='submit' name='reply-send' value='Send'/>", 2315 "<INPUT type='submit' name='reply-send' value='Send'/>",
2324 true); 2316 true);
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after
3372 " <INPUT type='text' id='firstname' maxlength='5'/>" 3364 " <INPUT type='text' id='firstname' maxlength='5'/>"
3373 " <INPUT type='text' id='lastname' maxlength='7'/>" 3365 " <INPUT type='text' id='lastname' maxlength='7'/>"
3374 " <INPUT type='text' id='email' maxlength='9'/>" 3366 " <INPUT type='text' id='email' maxlength='9'/>"
3375 " <INPUT type='submit' name='reply-send' value='Send'/>" 3367 " <INPUT type='submit' name='reply-send' value='Send'/>"
3376 "</FORM>", 3368 "</FORM>",
3377 false); 3369 false);
3378 } 3370 }
3379 3371
3380 TEST_F(FormAutofillTest, FillFormMaxLengthForUnownedForm) { 3372 TEST_F(FormAutofillTest, FillFormMaxLengthForUnownedForm) {
3381 TestFillFormMaxLength( 3373 TestFillFormMaxLength(
3382 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>"
3383 "<INPUT type='text' id='firstname' maxlength='5'/>" 3374 "<INPUT type='text' id='firstname' maxlength='5'/>"
3384 "<INPUT type='text' id='lastname' maxlength='7'/>" 3375 "<INPUT type='text' id='lastname' maxlength='7'/>"
3385 "<INPUT type='text' id='email' maxlength='9'/>" 3376 "<INPUT type='text' id='email' maxlength='9'/>"
3386 "<INPUT type='submit' name='reply-send' value='Send'/>", 3377 "<INPUT type='submit' name='reply-send' value='Send'/>",
3387 true); 3378 true);
3388 } 3379 }
3389 3380
3390 // This test uses negative values of the maxlength attribute for input elements. 3381 // This test uses negative values of the maxlength attribute for input elements.
3391 // In this case, the maxlength of the input elements is set to the default 3382 // In this case, the maxlength of the input elements is set to the default
3392 // maxlength (defined in WebKit.) 3383 // maxlength (defined in WebKit.)
3393 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) { 3384 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) {
3394 TestFillFormNegativeMaxLength( 3385 TestFillFormNegativeMaxLength(
3395 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>"
3396 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3386 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3397 " <INPUT type='text' id='firstname' maxlength='-1'/>" 3387 " <INPUT type='text' id='firstname' maxlength='-1'/>"
3398 " <INPUT type='text' id='lastname' maxlength='-10'/>" 3388 " <INPUT type='text' id='lastname' maxlength='-10'/>"
3399 " <INPUT type='text' id='email' maxlength='-13'/>" 3389 " <INPUT type='text' id='email' maxlength='-13'/>"
3400 " <INPUT type='submit' name='reply-send' value='Send'/>" 3390 " <INPUT type='submit' name='reply-send' value='Send'/>"
3401 "</FORM>", 3391 "</FORM>",
3402 false); 3392 false);
3403 } 3393 }
3404 3394
3405 TEST_F(FormAutofillTest, FillFormNegativeMaxLengthForUnownedForm) { 3395 TEST_F(FormAutofillTest, FillFormNegativeMaxLengthForUnownedForm) {
3406 TestFillFormNegativeMaxLength( 3396 TestFillFormNegativeMaxLength(
3407 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>"
3408 "<INPUT type='text' id='firstname' maxlength='-1'/>" 3397 "<INPUT type='text' id='firstname' maxlength='-1'/>"
3409 "<INPUT type='text' id='lastname' maxlength='-10'/>" 3398 "<INPUT type='text' id='lastname' maxlength='-10'/>"
3410 "<INPUT type='text' id='email' maxlength='-13'/>" 3399 "<INPUT type='text' id='email' maxlength='-13'/>"
3411 "<INPUT type='submit' name='reply-send' value='Send'/>", 3400 "<INPUT type='submit' name='reply-send' value='Send'/>",
3412 true); 3401 true);
3413 } 3402 }
3414 3403
3415 TEST_F(FormAutofillTest, FillFormEmptyName) { 3404 TEST_F(FormAutofillTest, FillFormEmptyName) {
3416 TestFillFormEmptyName( 3405 TestFillFormEmptyName(
3417 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3406 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3418 " <INPUT type='text' id='firstname'/>" 3407 " <INPUT type='text' id='firstname'/>"
3419 " <INPUT type='text' id='lastname'/>" 3408 " <INPUT type='text' id='lastname'/>"
3420 " <INPUT type='text' id='email'/>" 3409 " <INPUT type='text' id='email'/>"
3421 " <INPUT type='submit' value='Send'/>" 3410 " <INPUT type='submit' value='Send'/>"
3422 "</FORM>", 3411 "</FORM>",
3423 false); 3412 false);
3424 } 3413 }
3425 3414
3426 TEST_F(FormAutofillTest, FillFormEmptyNameForUnownedForm) { 3415 TEST_F(FormAutofillTest, FillFormEmptyNameForUnownedForm) {
3427 TestFillFormEmptyName( 3416 TestFillFormEmptyName(
3428 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>"
3429 "<INPUT type='text' id='firstname'/>" 3417 "<INPUT type='text' id='firstname'/>"
3430 "<INPUT type='text' id='lastname'/>" 3418 "<INPUT type='text' id='lastname'/>"
3431 "<INPUT type='text' id='email'/>" 3419 "<INPUT type='text' id='email'/>"
3432 "<INPUT type='submit' value='Send'/>", 3420 "<INPUT type='submit' value='Send'/>",
3433 true); 3421 true);
3434 } 3422 }
3435 3423
3436 TEST_F(FormAutofillTest, FillFormEmptyFormNames) { 3424 TEST_F(FormAutofillTest, FillFormEmptyFormNames) {
3437 TestFillFormEmptyFormNames( 3425 TestFillFormEmptyFormNames(
3438 "<FORM action='http://buh.com' method='post'>" 3426 "<FORM action='http://buh.com' method='post'>"
3439 " <INPUT type='text' id='firstname'/>" 3427 " <INPUT type='text' id='firstname'/>"
3440 " <INPUT type='text' id='middlename'/>" 3428 " <INPUT type='text' id='middlename'/>"
3441 " <INPUT type='text' id='lastname'/>" 3429 " <INPUT type='text' id='lastname'/>"
3442 " <INPUT type='submit' value='Send'/>" 3430 " <INPUT type='submit' value='Send'/>"
3443 "</FORM>" 3431 "</FORM>"
3444 "<FORM action='http://abc.com' method='post'>" 3432 "<FORM action='http://abc.com' method='post'>"
3445 " <INPUT type='text' id='apple'/>" 3433 " <INPUT type='text' id='apple'/>"
3446 " <INPUT type='text' id='banana'/>" 3434 " <INPUT type='text' id='banana'/>"
3447 " <INPUT type='text' id='cantelope'/>" 3435 " <INPUT type='text' id='cantelope'/>"
3448 " <INPUT type='submit' value='Send'/>" 3436 " <INPUT type='submit' value='Send'/>"
3449 "</FORM>", 3437 "</FORM>",
3450 false); 3438 false);
3451 } 3439 }
3452 3440
3453 TEST_F(FormAutofillTest, FillFormEmptyFormNamesForUnownedForm) { 3441 TEST_F(FormAutofillTest, FillFormEmptyFormNamesForUnownedForm) {
3454 TestFillFormEmptyFormNames( 3442 TestFillFormEmptyFormNames(
3455 "<HEAD><TITLE>enter delivery preferences</TITLE></HEAD>"
3456 "<INPUT type='text' id='firstname'/>" 3443 "<INPUT type='text' id='firstname'/>"
3457 "<INPUT type='text' id='middlename'/>" 3444 "<INPUT type='text' id='middlename'/>"
3458 "<INPUT type='text' id='lastname'/>" 3445 "<INPUT type='text' id='lastname'/>"
3459 "<INPUT type='text' id='apple'/>" 3446 "<INPUT type='text' id='apple'/>"
3460 "<INPUT type='text' id='banana'/>" 3447 "<INPUT type='text' id='banana'/>"
3461 "<INPUT type='text' id='cantelope'/>" 3448 "<INPUT type='text' id='cantelope'/>"
3462 "<INPUT type='submit' value='Send'/>", 3449 "<INPUT type='submit' value='Send'/>",
3463 true); 3450 true);
3464 } 3451 }
3465 3452
3466 TEST_F(FormAutofillTest, ThreePartPhone) { 3453 TEST_F(FormAutofillTest, ThreePartPhone) {
3467 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" 3454 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
3468 " Phone:" 3455 " Phone:"
3469 " <input type='text' name='dayphone1'>" 3456 " <input type='text' name='dayphone1'>"
3470 " -" 3457 " -"
3471 " <input type='text' name='dayphone2'>" 3458 " <input type='text' name='dayphone2'>"
3472 " -" 3459 " -"
3473 " <input type='text' name='dayphone3'>" 3460 " <input type='text' name='dayphone3'>"
3474 " ext.:" 3461 " ext.:"
3475 " <input type='text' name='dayphone4'>" 3462 " <input type='text' name='dayphone4'>"
3476 " <input type='submit' name='reply-send' value='Send'>" 3463 " <input type='submit' name='reply-send' value='Send'>"
3477 "</FORM>"); 3464 "</FORM>");
3478 3465
3466
3479 WebFrame* frame = GetMainFrame(); 3467 WebFrame* frame = GetMainFrame();
3480 ASSERT_NE(nullptr, frame); 3468 ASSERT_NE(nullptr, frame);
3481 3469
3482 WebVector<WebFormElement> forms; 3470 WebVector<WebFormElement> forms;
3483 frame->document().forms(forms); 3471 frame->document().forms(forms);
3484 ASSERT_EQ(1U, forms.size()); 3472 ASSERT_EQ(1U, forms.size());
3485 3473
3486 FormData form; 3474 FormData form;
3487 EXPECT_TRUE(WebFormElementToFormData(forms[0], 3475 EXPECT_TRUE(WebFormElementToFormData(forms[0],
3488 WebFormControlElement(), 3476 WebFormControlElement(),
3489 EXTRACT_VALUE, 3477 EXTRACT_VALUE,
3490 &form, 3478 &form,
3491 nullptr)); 3479 nullptr));
3492 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 3480 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
3493 EXPECT_EQ(GURL(frame->document().url()), form.origin); 3481 EXPECT_EQ(GURL(frame->document().url()), form.origin);
3494 EXPECT_FALSE(form.origin.is_empty());
3495 EXPECT_EQ(GURL("http://cnn.com"), form.action); 3482 EXPECT_EQ(GURL("http://cnn.com"), form.action);
3496 3483
3497 const std::vector<FormFieldData>& fields = form.fields; 3484 const std::vector<FormFieldData>& fields = form.fields;
3498 ASSERT_EQ(4U, fields.size()); 3485 ASSERT_EQ(4U, fields.size());
3499 3486
3500 FormFieldData expected; 3487 FormFieldData expected;
3501 expected.form_control_type = "text"; 3488 expected.form_control_type = "text";
3502 expected.max_length = WebInputElement::defaultMaxLength(); 3489 expected.max_length = WebInputElement::defaultMaxLength();
3503 3490
3504 expected.label = ASCIIToUTF16("Phone:"); 3491 expected.label = ASCIIToUTF16("Phone:");
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3599 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3586 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3600 " <INPUT type='text' id='firstname'/>" 3587 " <INPUT type='text' id='firstname'/>"
3601 " <INPUT type='text' id='lastname'/>" 3588 " <INPUT type='text' id='lastname'/>"
3602 " <INPUT type='text' id='email'/>" 3589 " <INPUT type='text' id='email'/>"
3603 " <INPUT type='submit' value='Send'/>" 3590 " <INPUT type='submit' value='Send'/>"
3604 "</FORM>", 3591 "</FORM>",
3605 false); 3592 false);
3606 } 3593 }
3607 3594
3608 TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) { 3595 TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) {
3609 TestFillFormNonEmptyField( 3596 TestFillFormNonEmptyField("<INPUT type='text' id='firstname'/>"
3610 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>" 3597 "<INPUT type='text' id='lastname'/>"
3611 "<INPUT type='text' id='firstname'/>" 3598 "<INPUT type='text' id='email'/>"
3612 "<INPUT type='text' id='lastname'/>" 3599 "<INPUT type='submit' value='Send'/>",
3613 "<INPUT type='text' id='email'/>" 3600 true);
3614 "<INPUT type='submit' value='Send'/>",
3615 true);
3616 } 3601 }
3617 3602
3618 TEST_F(FormAutofillTest, ClearFormWithNode) { 3603 TEST_F(FormAutofillTest, ClearFormWithNode) {
3619 TestClearFormWithNode( 3604 TestClearFormWithNode(
3620 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3605 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3621 " <INPUT type='text' id='firstname' value='Wyatt'/>" 3606 " <INPUT type='text' id='firstname' value='Wyatt'/>"
3622 " <INPUT type='text' id='lastname' value='Earp'/>" 3607 " <INPUT type='text' id='lastname' value='Earp'/>"
3623 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" 3608 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>"
3624 " <INPUT type='text' id='notenabled' disabled='disabled'>" 3609 " <INPUT type='text' id='notenabled' disabled='disabled'>"
3625 " <INPUT type='month' id='month' value='2012-11'>" 3610 " <INPUT type='month' id='month' value='2012-11'>"
3626 " <INPUT type='month' id='month-disabled' value='2012-11'" 3611 " <INPUT type='month' id='month-disabled' value='2012-11'"
3627 " disabled='disabled'>" 3612 " disabled='disabled'>"
3628 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>" 3613 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>"
3629 " <TEXTAREA id='textarea-disabled' disabled='disabled'>" 3614 " <TEXTAREA id='textarea-disabled' disabled='disabled'>"
3630 " Banana!" 3615 " Banana!"
3631 " </TEXTAREA>" 3616 " </TEXTAREA>"
3632 " <TEXTAREA id='textarea-noAC' autocomplete='off'>Carrot?</TEXTAREA>" 3617 " <TEXTAREA id='textarea-noAC' autocomplete='off'>Carrot?</TEXTAREA>"
3633 " <INPUT type='submit' value='Send'/>" 3618 " <INPUT type='submit' value='Send'/>"
3634 "</FORM>", 3619 "</FORM>",
3635 false); 3620 false);
3636 } 3621 }
3637 3622
3638 TEST_F(FormAutofillTest, ClearFormWithNodeForUnownedForm) { 3623 TEST_F(FormAutofillTest, ClearFormWithNodeForUnownedForm) {
3639 TestClearFormWithNode( 3624 TestClearFormWithNode(
3640 "<HEAD><TITLE>store checkout</TITLE></HEAD>"
3641 " <!-- Indented on purpose //-->" 3625 " <!-- Indented on purpose //-->"
3642 " <INPUT type='text' id='firstname' value='Wyatt'/>" 3626 " <INPUT type='text' id='firstname' value='Wyatt'/>"
3643 " <INPUT type='text' id='lastname' value='Earp'/>" 3627 " <INPUT type='text' id='lastname' value='Earp'/>"
3644 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" 3628 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>"
3645 " <INPUT type='text' id='notenabled' disabled='disabled'>" 3629 " <INPUT type='text' id='notenabled' disabled='disabled'>"
3646 " <INPUT type='month' id='month' value='2012-11'>" 3630 " <INPUT type='month' id='month' value='2012-11'>"
3647 " <INPUT type='month' id='month-disabled' value='2012-11'" 3631 " <INPUT type='month' id='month-disabled' value='2012-11'"
3648 " disabled='disabled'>" 3632 " disabled='disabled'>"
3649 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>" 3633 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>"
3650 " <TEXTAREA id='textarea-disabled' disabled='disabled'>" 3634 " <TEXTAREA id='textarea-disabled' disabled='disabled'>"
(...skipping 15 matching lines...) Expand all
3666 " <OPTION>AE</OPTION>" 3650 " <OPTION>AE</OPTION>"
3667 " <OPTION>AK</OPTION>" 3651 " <OPTION>AK</OPTION>"
3668 " </SELECT>" 3652 " </SELECT>"
3669 " <INPUT type='submit' value='Send'/>" 3653 " <INPUT type='submit' value='Send'/>"
3670 "</FORM>", 3654 "</FORM>",
3671 false); 3655 false);
3672 } 3656 }
3673 3657
3674 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOneForUnownedForm) { 3658 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOneForUnownedForm) {
3675 TestClearFormWithNodeContainingSelectOne( 3659 TestClearFormWithNodeContainingSelectOne(
3676 "<HEAD><TITLE>store checkout</TITLE></HEAD>"
3677 "<INPUT type='text' id='firstname' value='Wyatt'/>" 3660 "<INPUT type='text' id='firstname' value='Wyatt'/>"
3678 "<INPUT type='text' id='lastname' value='Earp'/>" 3661 "<INPUT type='text' id='lastname' value='Earp'/>"
3679 "<SELECT id='state' name='state'>" 3662 "<SELECT id='state' name='state'>"
3680 " <OPTION selected>?</OPTION>" 3663 " <OPTION selected>?</OPTION>"
3681 " <OPTION>AA</OPTION>" 3664 " <OPTION>AA</OPTION>"
3682 " <OPTION>AE</OPTION>" 3665 " <OPTION>AE</OPTION>"
3683 " <OPTION>AK</OPTION>" 3666 " <OPTION>AK</OPTION>"
3684 "</SELECT>" 3667 "</SELECT>"
3685 "<INPUT type='submit' value='Send'/>", 3668 "<INPUT type='submit' value='Send'/>",
3686 true); 3669 true);
3687 } 3670 }
3688 3671
3689 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { 3672 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) {
3690 TestClearPreviewedFormWithElement( 3673 TestClearPreviewedFormWithElement(
3691 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3674 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3692 " <INPUT type='text' id='firstname' value='Wyatt'/>" 3675 " <INPUT type='text' id='firstname' value='Wyatt'/>"
3693 " <INPUT type='text' id='lastname'/>" 3676 " <INPUT type='text' id='lastname'/>"
3694 " <INPUT type='text' id='email'/>" 3677 " <INPUT type='text' id='email'/>"
3695 " <INPUT type='email' id='email2'/>" 3678 " <INPUT type='email' id='email2'/>"
3696 " <INPUT type='tel' id='phone'/>" 3679 " <INPUT type='tel' id='phone'/>"
3697 " <INPUT type='submit' value='Send'/>" 3680 " <INPUT type='submit' value='Send'/>"
3698 "</FORM>"); 3681 "</FORM>");
3699 } 3682 }
3700 3683
3701 TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) { 3684 TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) {
3702 TestClearPreviewedFormWithElement( 3685 TestClearPreviewedFormWithElement(
3703 "<HEAD><TITLE>store checkout</TITLE></HEAD>"
3704 "<INPUT type='text' id='firstname' value='Wyatt'/>" 3686 "<INPUT type='text' id='firstname' value='Wyatt'/>"
3705 "<INPUT type='text' id='lastname'/>" 3687 "<INPUT type='text' id='lastname'/>"
3706 "<INPUT type='text' id='email'/>" 3688 "<INPUT type='text' id='email'/>"
3707 "<INPUT type='email' id='email2'/>" 3689 "<INPUT type='email' id='email2'/>"
3708 "<INPUT type='tel' id='phone'/>" 3690 "<INPUT type='tel' id='phone'/>"
3709 "<INPUT type='submit' value='Send'/>"); 3691 "<INPUT type='submit' value='Send'/>");
3710 } 3692 }
3711 3693
3712 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { 3694 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) {
3713 TestClearPreviewedFormWithNonEmptyInitiatingNode( 3695 TestClearPreviewedFormWithNonEmptyInitiatingNode(
3714 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3696 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3715 " <INPUT type='text' id='firstname' value='W'/>" 3697 " <INPUT type='text' id='firstname' value='W'/>"
3716 " <INPUT type='text' id='lastname'/>" 3698 " <INPUT type='text' id='lastname'/>"
3717 " <INPUT type='text' id='email'/>" 3699 " <INPUT type='text' id='email'/>"
3718 " <INPUT type='email' id='email2'/>" 3700 " <INPUT type='email' id='email2'/>"
3719 " <INPUT type='tel' id='phone'/>" 3701 " <INPUT type='tel' id='phone'/>"
3720 " <INPUT type='submit' value='Send'/>" 3702 " <INPUT type='submit' value='Send'/>"
3721 "</FORM>"); 3703 "</FORM>");
3722 } 3704 }
3723 3705
3724 TEST_F(FormAutofillTest, 3706 TEST_F(FormAutofillTest,
3725 ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) { 3707 ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) {
3726 TestClearPreviewedFormWithNonEmptyInitiatingNode( 3708 TestClearPreviewedFormWithNonEmptyInitiatingNode(
3727 "<HEAD><TITLE>shipping details</TITLE></HEAD>"
3728 "<INPUT type='text' id='firstname' value='W'/>" 3709 "<INPUT type='text' id='firstname' value='W'/>"
3729 "<INPUT type='text' id='lastname'/>" 3710 "<INPUT type='text' id='lastname'/>"
3730 "<INPUT type='text' id='email'/>" 3711 "<INPUT type='text' id='email'/>"
3731 "<INPUT type='email' id='email2'/>" 3712 "<INPUT type='email' id='email2'/>"
3732 "<INPUT type='tel' id='phone'/>" 3713 "<INPUT type='tel' id='phone'/>"
3733 "<INPUT type='submit' value='Send'/>"); 3714 "<INPUT type='submit' value='Send'/>");
3734 } 3715 }
3735 3716
3736 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { 3717 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) {
3737 TestClearPreviewedFormWithAutofilledInitiatingNode( 3718 TestClearPreviewedFormWithAutofilledInitiatingNode(
3738 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3719 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3739 " <INPUT type='text' id='firstname' value='W'/>" 3720 " <INPUT type='text' id='firstname' value='W'/>"
3740 " <INPUT type='text' id='lastname'/>" 3721 " <INPUT type='text' id='lastname'/>"
3741 " <INPUT type='text' id='email'/>" 3722 " <INPUT type='text' id='email'/>"
3742 " <INPUT type='email' id='email2'/>" 3723 " <INPUT type='email' id='email2'/>"
3743 " <INPUT type='tel' id='phone'/>" 3724 " <INPUT type='tel' id='phone'/>"
3744 " <INPUT type='submit' value='Send'/>" 3725 " <INPUT type='submit' value='Send'/>"
3745 "</FORM>"); 3726 "</FORM>");
3746 } 3727 }
3747 3728
3748 TEST_F(FormAutofillTest, 3729 TEST_F(FormAutofillTest,
3749 ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) { 3730 ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) {
3750 TestClearPreviewedFormWithAutofilledInitiatingNode( 3731 TestClearPreviewedFormWithAutofilledInitiatingNode(
3751 "<HEAD><TITLE>shipping details</TITLE></HEAD>"
3752 "<INPUT type='text' id='firstname' value='W'/>" 3732 "<INPUT type='text' id='firstname' value='W'/>"
3753 "<INPUT type='text' id='lastname'/>" 3733 "<INPUT type='text' id='lastname'/>"
3754 "<INPUT type='text' id='email'/>" 3734 "<INPUT type='text' id='email'/>"
3755 "<INPUT type='email' id='email2'/>" 3735 "<INPUT type='email' id='email2'/>"
3756 "<INPUT type='tel' id='phone'/>" 3736 "<INPUT type='tel' id='phone'/>"
3757 "<INPUT type='submit' value='Send'/>"); 3737 "<INPUT type='submit' value='Send'/>");
3758 } 3738 }
3759 3739
3760 // Autofill's "Clear Form" should clear only autofilled fields 3740 // Autofill's "Clear Form" should clear only autofilled fields
3761 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { 3741 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) {
3762 TestClearOnlyAutofilledFields( 3742 TestClearOnlyAutofilledFields(
3763 "<FORM name='TestForm' action='http://buh.com' method='post'>" 3743 "<FORM name='TestForm' action='http://buh.com' method='post'>"
3764 " <INPUT type='text' id='firstname' value='Wyatt'/>" 3744 " <INPUT type='text' id='firstname' value='Wyatt'/>"
3765 " <INPUT type='text' id='lastname' value='Earp'/>" 3745 " <INPUT type='text' id='lastname' value='Earp'/>"
3766 " <INPUT type='email' id='email' value='wyatt@earp.com'/>" 3746 " <INPUT type='email' id='email' value='wyatt@earp.com'/>"
3767 " <INPUT type='tel' id='phone' value='650-777-9999'/>" 3747 " <INPUT type='tel' id='phone' value='650-777-9999'/>"
3768 " <INPUT type='submit' value='Send'/>" 3748 " <INPUT type='submit' value='Send'/>"
3769 "</FORM>"); 3749 "</FORM>");
3770 } 3750 }
3771 3751
3772 TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) { 3752 TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) {
3773 TestClearOnlyAutofilledFields( 3753 TestClearOnlyAutofilledFields(
3774 "<HEAD><TITLE>shipping details</TITLE></HEAD>"
3775 "<INPUT type='text' id='firstname' value='Wyatt'/>" 3754 "<INPUT type='text' id='firstname' value='Wyatt'/>"
3776 "<INPUT type='text' id='lastname' value='Earp'/>" 3755 "<INPUT type='text' id='lastname' value='Earp'/>"
3777 "<INPUT type='email' id='email' value='wyatt@earp.com'/>" 3756 "<INPUT type='email' id='email' value='wyatt@earp.com'/>"
3778 "<INPUT type='tel' id='phone' value='650-777-9999'/>" 3757 "<INPUT type='tel' id='phone' value='650-777-9999'/>"
3779 "<INPUT type='submit' value='Send'/>"); 3758 "<INPUT type='submit' value='Send'/>");
3780 } 3759 }
3781 3760
3782 // If we have multiple labels per id, the labels concatenated into label string. 3761 // If we have multiple labels per id, the labels concatenated into label string.
3783 TEST_F(FormAutofillTest, MultipleLabelsPerElement) { 3762 TEST_F(FormAutofillTest, MultipleLabelsPerElement) {
3784 std::vector<base::string16> labels, names, values; 3763 std::vector<base::string16> labels, names, values;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3927 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 3906 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3928 } 3907 }
3929 3908
3930 TEST_F(FormAutofillTest, 3909 TEST_F(FormAutofillTest,
3931 UnownedFormElementsAndFieldSetsToFormDataFieldsets) { 3910 UnownedFormElementsAndFieldSetsToFormDataFieldsets) {
3932 std::vector<WebElement> fieldsets; 3911 std::vector<WebElement> fieldsets;
3933 std::vector<WebFormControlElement> control_elements; 3912 std::vector<WebFormControlElement> control_elements;
3934 3913
3935 const ExtractMask extract_mask = 3914 const ExtractMask extract_mask =
3936 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); 3915 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS);
3916 const GURL dummy_origin("http://www.example.com");
3937 3917
3938 LoadHTML("<HEAD><TITLE>delivery info</TITLE></HEAD>" 3918 LoadHTML("<DIV>"
3939 "<DIV>"
3940 " <FIELDSET>" 3919 " <FIELDSET>"
3941 " <LABEL for='firstname'>First name:</LABEL>" 3920 " <LABEL for='firstname'>First name:</LABEL>"
3942 " <LABEL for='lastname'>Last name:</LABEL>" 3921 " <LABEL for='lastname'>Last name:</LABEL>"
3943 " <INPUT type='text' id='firstname' value='John'/>" 3922 " <INPUT type='text' id='firstname' value='John'/>"
3944 " <INPUT type='text' id='lastname' value='Smith'/>" 3923 " <INPUT type='text' id='lastname' value='Smith'/>"
3945 " </FIELDSET>" 3924 " </FIELDSET>"
3946 " <FIELDSET>" 3925 " <FIELDSET>"
3947 " <LABEL for='email'>Email:</LABEL>" 3926 " <LABEL for='email'>Email:</LABEL>"
3948 " <INPUT type='text' id='email' value='john@example.com'/>" 3927 " <INPUT type='text' id='email' value='john@example.com'/>"
3949 " </FIELDSET>" 3928 " </FIELDSET>"
3950 "</DIV>"); 3929 "</DIV>");
3951 3930
3952 WebFrame* frame = GetMainFrame(); 3931 WebFrame* frame = GetMainFrame();
3953 ASSERT_NE(nullptr, frame); 3932 ASSERT_NE(nullptr, frame);
3954 3933
3955 control_elements = GetUnownedAutofillableFormFieldElements( 3934 control_elements = GetUnownedAutofillableFormFieldElements(
3956 frame->document().all(), &fieldsets); 3935 frame->document().all(), &fieldsets);
3957 ASSERT_EQ(3U, control_elements.size()); 3936 ASSERT_EQ(3U, control_elements.size());
3958 ASSERT_EQ(2U, fieldsets.size()); 3937 ASSERT_EQ(2U, fieldsets.size());
3959 3938
3960 FormData form; 3939 FormData form;
3961 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( 3940 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData(
3962 fieldsets, control_elements, nullptr, frame->document(), extract_mask, 3941 fieldsets, control_elements, nullptr, dummy_origin, extract_mask, &form,
3963 &form, nullptr)); 3942 nullptr));
3964 3943
3965 EXPECT_TRUE(form.name.empty()); 3944 EXPECT_TRUE(form.name.empty());
3966 EXPECT_EQ(frame->document().url(), form.origin); 3945 EXPECT_EQ(dummy_origin, form.origin);
3967 EXPECT_FALSE(form.action.is_valid()); 3946 EXPECT_FALSE(form.action.is_valid());
3968 3947
3969 const std::vector<FormFieldData>& fields = form.fields; 3948 const std::vector<FormFieldData>& fields = form.fields;
3970 ASSERT_EQ(3U, fields.size()); 3949 ASSERT_EQ(3U, fields.size());
3971 3950
3972 FormFieldData expected; 3951 FormFieldData expected;
3973 expected.form_control_type = "text"; 3952 expected.form_control_type = "text";
3974 expected.max_length = WebInputElement::defaultMaxLength(); 3953 expected.max_length = WebInputElement::defaultMaxLength();
3975 3954
3976 expected.name = ASCIIToUTF16("firstname"); 3955 expected.name = ASCIIToUTF16("firstname");
(...skipping 12 matching lines...) Expand all
3989 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 3968 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3990 } 3969 }
3991 3970
3992 TEST_F(FormAutofillTest, 3971 TEST_F(FormAutofillTest,
3993 UnownedFormElementsAndFieldSetsToFormDataControlOutsideOfFieldset) { 3972 UnownedFormElementsAndFieldSetsToFormDataControlOutsideOfFieldset) {
3994 std::vector<WebElement> fieldsets; 3973 std::vector<WebElement> fieldsets;
3995 std::vector<WebFormControlElement> control_elements; 3974 std::vector<WebFormControlElement> control_elements;
3996 3975
3997 const ExtractMask extract_mask = 3976 const ExtractMask extract_mask =
3998 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); 3977 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS);
3978 const GURL dummy_origin("http://www.example.com");
3999 3979
4000 LoadHTML("<HEAD><TITLE>shipping details</TITLE></HEAD>" 3980 LoadHTML("<DIV>"
4001 "<DIV>"
4002 " <FIELDSET>" 3981 " <FIELDSET>"
4003 " <LABEL for='firstname'>First name:</LABEL>" 3982 " <LABEL for='firstname'>First name:</LABEL>"
4004 " <LABEL for='lastname'>Last name:</LABEL>" 3983 " <LABEL for='lastname'>Last name:</LABEL>"
4005 " <INPUT type='text' id='firstname' value='John'/>" 3984 " <INPUT type='text' id='firstname' value='John'/>"
4006 " <INPUT type='text' id='lastname' value='Smith'/>" 3985 " <INPUT type='text' id='lastname' value='Smith'/>"
4007 " <LABEL for='email'>Email:</LABEL>" 3986 " <LABEL for='email'>Email:</LABEL>"
4008 " </FIELDSET>" 3987 " </FIELDSET>"
4009 " <INPUT type='text' id='email' value='john@example.com'/>" 3988 " <INPUT type='text' id='email' value='john@example.com'/>"
4010 "</DIV>"); 3989 "</DIV>");
4011 3990
4012 WebFrame* frame = GetMainFrame(); 3991 WebFrame* frame = GetMainFrame();
4013 ASSERT_NE(nullptr, frame); 3992 ASSERT_NE(nullptr, frame);
4014 3993
4015 control_elements = GetUnownedAutofillableFormFieldElements( 3994 control_elements = GetUnownedAutofillableFormFieldElements(
4016 frame->document().all(), &fieldsets); 3995 frame->document().all(), &fieldsets);
4017 ASSERT_EQ(3U, control_elements.size()); 3996 ASSERT_EQ(3U, control_elements.size());
4018 ASSERT_EQ(1U, fieldsets.size()); 3997 ASSERT_EQ(1U, fieldsets.size());
4019 3998
4020 FormData form; 3999 FormData form;
4021 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( 4000 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData(
4022 fieldsets, control_elements, nullptr, frame->document(), extract_mask, 4001 fieldsets, control_elements, nullptr, dummy_origin, extract_mask, &form,
4023 &form, nullptr)); 4002 nullptr));
4024 4003
4025 EXPECT_TRUE(form.name.empty()); 4004 EXPECT_TRUE(form.name.empty());
4026 EXPECT_EQ(frame->document().url(), form.origin); 4005 EXPECT_EQ(dummy_origin, form.origin);
4027 EXPECT_FALSE(form.action.is_valid()); 4006 EXPECT_FALSE(form.action.is_valid());
4028 4007
4029 const std::vector<FormFieldData>& fields = form.fields; 4008 const std::vector<FormFieldData>& fields = form.fields;
4030 ASSERT_EQ(3U, fields.size()); 4009 ASSERT_EQ(3U, fields.size());
4031 4010
4032 FormFieldData expected; 4011 FormFieldData expected;
4033 expected.form_control_type = "text"; 4012 expected.form_control_type = "text";
4034 expected.max_length = WebInputElement::defaultMaxLength(); 4013 expected.max_length = WebInputElement::defaultMaxLength();
4035 4014
4036 expected.name = ASCIIToUTF16("firstname"); 4015 expected.name = ASCIIToUTF16("firstname");
(...skipping 11 matching lines...) Expand all
4048 expected.label = ASCIIToUTF16("Email:"); 4027 expected.label = ASCIIToUTF16("Email:");
4049 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 4028 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
4050 } 4029 }
4051 4030
4052 TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) { 4031 TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) {
4053 std::vector<WebElement> fieldsets; 4032 std::vector<WebElement> fieldsets;
4054 std::vector<WebFormControlElement> control_elements; 4033 std::vector<WebFormControlElement> control_elements;
4055 4034
4056 const ExtractMask extract_mask = 4035 const ExtractMask extract_mask =
4057 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); 4036 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS);
4037 const GURL dummy_origin("http://www.example.com");
4058 4038
4059 LoadHTML(kFormHtml); 4039 LoadHTML(kFormHtml);
4060 4040
4061 WebFrame* frame = GetMainFrame(); 4041 WebFrame* frame = GetMainFrame();
4062 ASSERT_NE(nullptr, frame); 4042 ASSERT_NE(nullptr, frame);
4063 4043
4064 control_elements = GetUnownedAutofillableFormFieldElements( 4044 control_elements = GetUnownedAutofillableFormFieldElements(
4065 frame->document().all(), &fieldsets); 4045 frame->document().all(), &fieldsets);
4066 ASSERT_TRUE(control_elements.empty()); 4046 ASSERT_TRUE(control_elements.empty());
4067 ASSERT_TRUE(fieldsets.empty()); 4047 ASSERT_TRUE(fieldsets.empty());
4068 4048
4069 FormData form; 4049 FormData form;
4070 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( 4050 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData(
4071 fieldsets, control_elements, nullptr, frame->document(), extract_mask, 4051 fieldsets, control_elements, nullptr, dummy_origin, extract_mask, &form,
4072 &form, nullptr)); 4052 nullptr));
4073 } 4053 }
4074 4054
4075 } // namespace autofill 4055 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/autofill/autofill_noform_dynamic.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698