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

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

Issue 1842693003: [Autofill] Fill fields where the value equals the placeholder attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 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 | components/autofill/content/common/autofill_messages.h » ('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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 1053
1054 expected.name = ASCIIToUTF16("cantelope"); 1054 expected.name = ASCIIToUTF16("cantelope");
1055 expected.value = ASCIIToUTF16("Also Yellow"); 1055 expected.value = ASCIIToUTF16("Also Yellow");
1056 expected.is_autofilled = true; 1056 expected.is_autofilled = true;
1057 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 2]); 1057 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 2]);
1058 } 1058 }
1059 1059
1060 void TestFillFormNonEmptyField(const char* html, 1060 void TestFillFormNonEmptyField(const char* html,
1061 bool unowned, 1061 bool unowned,
1062 const char* initial_lastname, 1062 const char* initial_lastname,
1063 const char* initial_email) { 1063 const char* initial_email,
1064 const char* placeholder_firstname,
1065 const char* placeholder_lastname,
1066 const char* placeholder_email) {
1064 LoadHTML(html); 1067 LoadHTML(html);
1065 WebFrame* web_frame = GetMainFrame(); 1068 WebFrame* web_frame = GetMainFrame();
1066 ASSERT_NE(nullptr, web_frame); 1069 ASSERT_NE(nullptr, web_frame);
1067 1070
1068 FormCache form_cache(*web_frame); 1071 FormCache form_cache(*web_frame);
1069 std::vector<FormData> forms = form_cache.ExtractNewForms(); 1072 std::vector<FormData> forms = form_cache.ExtractNewForms();
1070 ASSERT_EQ(1U, forms.size()); 1073 ASSERT_EQ(1U, forms.size());
1071 1074
1072 // Get the input element we want to find. 1075 // Get the input element we want to find.
1073 WebInputElement input_element = GetInputElementById("firstname"); 1076 WebInputElement input_element = GetInputElementById("firstname");
(...skipping 15 matching lines...) Expand all
1089 1092
1090 const std::vector<FormFieldData>& fields = form.fields; 1093 const std::vector<FormFieldData>& fields = form.fields;
1091 ASSERT_EQ(3U, fields.size()); 1094 ASSERT_EQ(3U, fields.size());
1092 1095
1093 FormFieldData expected; 1096 FormFieldData expected;
1094 expected.form_control_type = "text"; 1097 expected.form_control_type = "text";
1095 expected.max_length = WebInputElement::defaultMaxLength(); 1098 expected.max_length = WebInputElement::defaultMaxLength();
1096 1099
1097 expected.name = ASCIIToUTF16("firstname"); 1100 expected.name = ASCIIToUTF16("firstname");
1098 expected.value = ASCIIToUTF16("Wy"); 1101 expected.value = ASCIIToUTF16("Wy");
1102 if (placeholder_firstname) {
1103 expected.label = ASCIIToUTF16(placeholder_firstname);
1104 expected.placeholder = ASCIIToUTF16(placeholder_firstname);
1105 }
1099 expected.is_autofilled = false; 1106 expected.is_autofilled = false;
1100 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); 1107 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
1101 1108
1102 expected.name = ASCIIToUTF16("lastname"); 1109 expected.name = ASCIIToUTF16("lastname");
1103 if (initial_lastname) { 1110 if (initial_lastname) {
1104 expected.label = ASCIIToUTF16(initial_lastname); 1111 expected.label = ASCIIToUTF16(initial_lastname);
1105 expected.value = ASCIIToUTF16(initial_lastname); 1112 expected.value = ASCIIToUTF16(initial_lastname);
1113 } else if (placeholder_lastname) {
1114 expected.label = ASCIIToUTF16(placeholder_lastname);
1115 expected.placeholder = ASCIIToUTF16(placeholder_lastname);
1116 expected.value = ASCIIToUTF16(placeholder_lastname);
1106 } else { 1117 } else {
1107 expected.label.clear(); 1118 expected.label.clear();
1108 expected.value.clear(); 1119 expected.value.clear();
1109 } 1120 }
1110 expected.is_autofilled = false; 1121 expected.is_autofilled = false;
1111 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 1122 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
1112 1123
1113 expected.name = ASCIIToUTF16("email"); 1124 expected.name = ASCIIToUTF16("email");
1114 if (initial_email) { 1125 if (initial_email) {
1115 expected.label = ASCIIToUTF16(initial_email); 1126 expected.label = ASCIIToUTF16(initial_email);
1116 expected.value = ASCIIToUTF16(initial_email); 1127 expected.value = ASCIIToUTF16(initial_email);
1128 } else if (placeholder_email) {
1129 expected.label = ASCIIToUTF16(placeholder_email);
1130 expected.placeholder = ASCIIToUTF16(placeholder_email);
1131 expected.value = ASCIIToUTF16(placeholder_email);
1117 } else { 1132 } else {
1118 expected.label.clear(); 1133 expected.label.clear();
1119 expected.value.clear(); 1134 expected.value.clear();
1120 } 1135 }
1121 expected.is_autofilled = false; 1136 expected.is_autofilled = false;
1122 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 1137 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
1123 1138
1124 // Preview the form and verify that the cursor position has been updated. 1139 // Preview the form and verify that the cursor position has been updated.
1125 form.fields[0].value = ASCIIToUTF16("Wyatt"); 1140 form.fields[0].value = ASCIIToUTF16("Wyatt");
1126 form.fields[1].value = ASCIIToUTF16("Earp"); 1141 form.fields[1].value = ASCIIToUTF16("Earp");
(...skipping 18 matching lines...) Expand all
1145 if (!unowned) { 1160 if (!unowned) {
1146 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1161 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1147 EXPECT_EQ(GURL("http://abc.com"), form2.action); 1162 EXPECT_EQ(GURL("http://abc.com"), form2.action);
1148 } 1163 }
1149 1164
1150 const std::vector<FormFieldData>& fields2 = form2.fields; 1165 const std::vector<FormFieldData>& fields2 = form2.fields;
1151 ASSERT_EQ(3U, fields2.size()); 1166 ASSERT_EQ(3U, fields2.size());
1152 1167
1153 expected.name = ASCIIToUTF16("firstname"); 1168 expected.name = ASCIIToUTF16("firstname");
1154 expected.value = ASCIIToUTF16("Wyatt"); 1169 expected.value = ASCIIToUTF16("Wyatt");
1155 expected.label.clear(); 1170 if (placeholder_firstname) {
1171 expected.label = ASCIIToUTF16(placeholder_firstname);
1172 expected.placeholder = ASCIIToUTF16(placeholder_firstname);
1173 } else {
1174 expected.label.clear();
1175 expected.placeholder.clear();
1176 }
1156 expected.is_autofilled = true; 1177 expected.is_autofilled = true;
1157 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); 1178 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
1158 1179
1159 expected.name = ASCIIToUTF16("lastname"); 1180 expected.name = ASCIIToUTF16("lastname");
1160 expected.value = ASCIIToUTF16("Earp"); 1181 expected.value = ASCIIToUTF16("Earp");
1161 expected.label.clear(); 1182 if (placeholder_lastname) {
1183 expected.label = ASCIIToUTF16(placeholder_lastname);
1184 expected.placeholder = ASCIIToUTF16(placeholder_lastname);
1185 } else {
1186 expected.label.clear();
1187 expected.placeholder.clear();
1188 }
1162 expected.is_autofilled = true; 1189 expected.is_autofilled = true;
1163 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); 1190 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
1164 1191
1165 expected.name = ASCIIToUTF16("email"); 1192 expected.name = ASCIIToUTF16("email");
1166 expected.value = ASCIIToUTF16("wyatt@example.com"); 1193 expected.value = ASCIIToUTF16("wyatt@example.com");
1167 expected.label.clear(); 1194 if (placeholder_email) {
1195 expected.label = ASCIIToUTF16(placeholder_email);
1196 expected.placeholder = ASCIIToUTF16(placeholder_email);
1197 } else {
1198 expected.label.clear();
1199 expected.placeholder.clear();
1200 }
1168 expected.is_autofilled = true; 1201 expected.is_autofilled = true;
1169 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); 1202 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
1170 1203
1171 // Verify that the cursor position has been updated. 1204 // Verify that the cursor position has been updated.
1172 EXPECT_EQ(5, input_element.selectionStart()); 1205 EXPECT_EQ(5, input_element.selectionStart());
1173 EXPECT_EQ(5, input_element.selectionEnd()); 1206 EXPECT_EQ(5, input_element.selectionEnd());
1174 } 1207 }
1175 1208
1176 void TestClearFormWithNode(const char* html, bool unowned) { 1209 void TestClearFormWithNode(const char* html, bool unowned) {
1177 LoadHTML(html); 1210 LoadHTML(html);
(...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after
3970 // profile from the Autofill suggestions popup. The field that is being typed 4003 // profile from the Autofill suggestions popup. The field that is being typed
3971 // into should be filled even though it's not technically empty. 4004 // into should be filled even though it's not technically empty.
3972 TEST_F(FormAutofillTest, FillFormNonEmptyField) { 4005 TEST_F(FormAutofillTest, FillFormNonEmptyField) {
3973 TestFillFormNonEmptyField( 4006 TestFillFormNonEmptyField(
3974 "<FORM name='TestForm' action='http://abc.com' method='post'>" 4007 "<FORM name='TestForm' action='http://abc.com' method='post'>"
3975 " <INPUT type='text' id='firstname'/>" 4008 " <INPUT type='text' id='firstname'/>"
3976 " <INPUT type='text' id='lastname'/>" 4009 " <INPUT type='text' id='lastname'/>"
3977 " <INPUT type='text' id='email'/>" 4010 " <INPUT type='text' id='email'/>"
3978 " <INPUT type='submit' value='Send'/>" 4011 " <INPUT type='submit' value='Send'/>"
3979 "</FORM>", 4012 "</FORM>",
3980 false, nullptr, nullptr); 4013 false, nullptr, nullptr, nullptr, nullptr, nullptr);
3981 } 4014 }
3982 4015
3983 TEST_F(FormAutofillTest, FillFormNonEmptyFieldsWithDefaultValues) { 4016 TEST_F(FormAutofillTest, FillFormNonEmptyFieldsWithDefaultValues) {
3984 TestFillFormNonEmptyField( 4017 TestFillFormNonEmptyField(
3985 "<FORM name='TestForm' action='http://abc.com' method='post'>" 4018 "<FORM name='TestForm' action='http://abc.com' method='post'>"
3986 " <INPUT type='text' id='firstname' value='Enter first name'/>" 4019 " <INPUT type='text' id='firstname' value='Enter first name'/>"
3987 " <INPUT type='text' id='lastname' value='Enter last name'/>" 4020 " <INPUT type='text' id='lastname' value='Enter last name'/>"
3988 " <INPUT type='text' id='email' value='Enter email'/>" 4021 " <INPUT type='text' id='email' value='Enter email'/>"
3989 " <INPUT type='submit' value='Send'/>" 4022 " <INPUT type='submit' value='Send'/>"
3990 "</FORM>", 4023 "</FORM>",
3991 false, "Enter last name", "Enter email"); 4024 false, "Enter last name", "Enter email", nullptr, nullptr, nullptr);
4025 }
4026
4027 TEST_F(FormAutofillTest, FillFormNonEmptyFieldsWithPlaceholderValues) {
4028 TestFillFormNonEmptyField(
4029 "<FORM name='TestForm' action='http://abc.com' method='post'>"
4030 " <INPUT type='text' id='firstname' placeholder='First Name' "
4031 "value='First Name'/>"
4032 " <INPUT type='text' id='lastname' placeholder='Last Name' value='Last "
4033 "Name'/>"
4034 " <INPUT type='text' id='email' placeholder='Email' value='Email'/>"
4035 " <INPUT type='submit' value='Send'/>"
4036 "</FORM>",
4037 false, nullptr, nullptr, "First Name", "Last Name", "Email");
3992 } 4038 }
3993 4039
3994 TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) { 4040 TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) {
3995 TestFillFormNonEmptyField( 4041 TestFillFormNonEmptyField(
3996 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>" 4042 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>"
3997 "<INPUT type='text' id='firstname'/>" 4043 "<INPUT type='text' id='firstname'/>"
3998 "<INPUT type='text' id='lastname'/>" 4044 "<INPUT type='text' id='lastname'/>"
3999 "<INPUT type='text' id='email'/>" 4045 "<INPUT type='text' id='email'/>"
4000 "<INPUT type='submit' value='Send'/>", 4046 "<INPUT type='submit' value='Send'/>",
4001 true, nullptr, nullptr); 4047 true, nullptr, nullptr, nullptr, nullptr, nullptr);
4002 } 4048 }
4003 4049
4004 TEST_F(FormAutofillTest, ClearFormWithNode) { 4050 TEST_F(FormAutofillTest, ClearFormWithNode) {
4005 TestClearFormWithNode( 4051 TestClearFormWithNode(
4006 "<FORM name='TestForm' action='http://abc.com' method='post'>" 4052 "<FORM name='TestForm' action='http://abc.com' method='post'>"
4007 " <INPUT type='text' id='firstname' value='Wyatt'/>" 4053 " <INPUT type='text' id='firstname' value='Wyatt'/>"
4008 " <INPUT type='text' id='lastname' value='Earp'/>" 4054 " <INPUT type='text' id='lastname' value='Earp'/>"
4009 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" 4055 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>"
4010 " <INPUT type='text' id='notenabled' disabled='disabled'>" 4056 " <INPUT type='text' id='notenabled' disabled='disabled'>"
4011 " <INPUT type='month' id='month' value='2012-11'>" 4057 " <INPUT type='month' id='month' value='2012-11'>"
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
4531 4577
4532 if (test_case.has_extracted_form) { 4578 if (test_case.has_extracted_form) {
4533 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); 4579 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag);
4534 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); 4580 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout);
4535 } 4581 }
4536 } 4582 }
4537 } 4583 }
4538 4584
4539 } // namespace form_util 4585 } // namespace form_util
4540 } // namespace autofill 4586 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698