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

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

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