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

Side by Side Diff: chrome/browser/autofill/form_structure_unittest.cc

Issue 7576001: Refactor webkit_glue::FormField to remove hacky methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright header Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/form_structure.h" 8 #include "chrome/browser/autofill/form_structure.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
12 #include "webkit/glue/form_data.h" 12 #include "webkit/glue/form_data.h"
13 #include "webkit/glue/form_field.h" 13 #include "webkit/glue/form_field.h"
14 14
15 using webkit_glue::FormData; 15 using webkit_glue::FormData;
16 using webkit_glue::FormField;
16 using WebKit::WebInputElement; 17 using WebKit::WebInputElement;
17 18
18 namespace webkit_glue { 19 namespace webkit_glue {
19 20
20 std::ostream& operator<<(std::ostream& os, const FormData& form) { 21 std::ostream& operator<<(std::ostream& os, const FormData& form) {
21 os << UTF16ToUTF8(form.name) 22 os << UTF16ToUTF8(form.name)
22 << " " 23 << " "
23 << UTF16ToUTF8(form.method) 24 << UTF16ToUTF8(form.method)
24 << " " 25 << " "
25 << form.origin.spec() 26 << form.origin.spec()
(...skipping 18 matching lines...) Expand all
44 static std::string Hash64Bit(const std::string& str) { 45 static std::string Hash64Bit(const std::string& str) {
45 return FormStructure::Hash64Bit(str); 46 return FormStructure::Hash64Bit(str);
46 } 47 }
47 }; 48 };
48 49
49 namespace { 50 namespace {
50 51
51 TEST(FormStructureTest, FieldCount) { 52 TEST(FormStructureTest, FieldCount) {
52 FormData form; 53 FormData form;
53 form.method = ASCIIToUTF16("post"); 54 form.method = ASCIIToUTF16("post");
54 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), 55
55 ASCIIToUTF16("username"), 56 FormField field;
56 string16(), 57 field.label = ASCIIToUTF16("username");
57 ASCIIToUTF16("text"), 58 field.name = ASCIIToUTF16("username");
58 0, 59 field.form_control_type = ASCIIToUTF16("text");
59 false)); 60 form.fields.push_back(field);
60 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), 61
61 ASCIIToUTF16("password"), 62 field.label = ASCIIToUTF16("password");
62 string16(), 63 field.name = ASCIIToUTF16("password");
63 ASCIIToUTF16("password"), 64 field.form_control_type = ASCIIToUTF16("password");
64 0, 65 form.fields.push_back(field);
65 false)); 66
66 form.fields.push_back(webkit_glue::FormField(string16(), 67 field.label = string16();
67 ASCIIToUTF16("Submit"), 68 field.name = ASCIIToUTF16("Submit");
68 string16(), 69 field.form_control_type = ASCIIToUTF16("submit");
69 ASCIIToUTF16("submit"), 70 form.fields.push_back(field);
70 0, 71
71 false));
72 FormStructure form_structure(form); 72 FormStructure form_structure(form);
73 73
74 // All fields are counted. 74 // All fields are counted.
75 EXPECT_EQ(3U, form_structure.field_count()); 75 EXPECT_EQ(3U, form_structure.field_count());
76 } 76 }
77 77
78 TEST(FormStructureTest, AutofillCount) { 78 TEST(FormStructureTest, AutofillCount) {
79 FormData form; 79 FormData form;
80 form.method = ASCIIToUTF16("post"); 80 form.method = ASCIIToUTF16("post");
81 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), 81
82 ASCIIToUTF16("username"), 82 FormField field;
83 string16(), 83 field.label = ASCIIToUTF16("username");
84 ASCIIToUTF16("text"), 84 field.name = ASCIIToUTF16("username");
85 0, 85 field.form_control_type = ASCIIToUTF16("text");
86 false)); 86 form.fields.push_back(field);
87 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), 87
88 ASCIIToUTF16("password"), 88 field.label = ASCIIToUTF16("password");
89 string16(), 89 field.name = ASCIIToUTF16("password");
90 ASCIIToUTF16("password"), 90 field.form_control_type = ASCIIToUTF16("password");
91 0, 91 form.fields.push_back(field);
92 false)); 92
93 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("state"), 93 field.label = ASCIIToUTF16("state");
94 ASCIIToUTF16("state"), 94 field.name = ASCIIToUTF16("state");
95 string16(), 95 field.form_control_type = ASCIIToUTF16("select-one");
96 ASCIIToUTF16("select-one"), 96 form.fields.push_back(field);
97 0, 97
98 false)); 98 field.label = string16();
99 form.fields.push_back(webkit_glue::FormField(string16(), 99 field.name = ASCIIToUTF16("Submit");
100 ASCIIToUTF16("Submit"), 100 field.form_control_type = ASCIIToUTF16("submit");
101 string16(), 101 form.fields.push_back(field);
102 ASCIIToUTF16("submit"), 102
103 0,
104 false));
105 FormStructure form_structure(form); 103 FormStructure form_structure(form);
106 form_structure.DetermineHeuristicTypes(); 104 form_structure.DetermineHeuristicTypes();
107 105
108 // Only text and select fields that are heuristically matched are counted. 106 // Only text and select fields that are heuristically matched are counted.
109 EXPECT_EQ(1U, form_structure.autofill_count()); 107 EXPECT_EQ(1U, form_structure.autofill_count());
110 } 108 }
111 109
112 TEST(FormStructureTest, SourceURL) { 110 TEST(FormStructureTest, SourceURL) {
113 FormData form; 111 FormData form;
114 form.origin = GURL("http://www.foo.com/"); 112 form.origin = GURL("http://www.foo.com/");
115 form.method = ASCIIToUTF16("post"); 113 form.method = ASCIIToUTF16("post");
116 FormStructure form_structure(form); 114 FormStructure form_structure(form);
117 115
118 EXPECT_EQ(form.origin, form_structure.source_url()); 116 EXPECT_EQ(form.origin, form_structure.source_url());
119 } 117 }
120 118
121 TEST(FormStructureTest, IsAutofillable) { 119 TEST(FormStructureTest, IsAutofillable) {
122 scoped_ptr<FormStructure> form_structure; 120 scoped_ptr<FormStructure> form_structure;
123 FormData form; 121 FormData form;
124 122
125 // We need at least three text fields to be auto-fillable. 123 // We need at least three text fields to be auto-fillable.
126 form.method = ASCIIToUTF16("post"); 124 form.method = ASCIIToUTF16("post");
127 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), 125
128 ASCIIToUTF16("username"), 126 FormField field;
129 string16(), 127 field.label = ASCIIToUTF16("username");
130 ASCIIToUTF16("text"), 128 field.name = ASCIIToUTF16("username");
131 0, 129 field.form_control_type = ASCIIToUTF16("text");
132 false)); 130 form.fields.push_back(field);
133 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), 131
134 ASCIIToUTF16("password"), 132 field.label = ASCIIToUTF16("password");
135 string16(), 133 field.name = ASCIIToUTF16("password");
136 ASCIIToUTF16("password"), 134 field.form_control_type = ASCIIToUTF16("password");
137 0, 135 form.fields.push_back(field);
138 false)); 136
139 form.fields.push_back(webkit_glue::FormField(string16(), 137 field.label = string16();
140 ASCIIToUTF16("Submit"), 138 field.name = ASCIIToUTF16("Submit");
141 string16(), 139 field.form_control_type = ASCIIToUTF16("submit");
142 ASCIIToUTF16("submit"), 140 form.fields.push_back(field);
143 0, 141
144 false));
145 form_structure.reset(new FormStructure(form)); 142 form_structure.reset(new FormStructure(form));
146 form_structure->DetermineHeuristicTypes(); 143 form_structure->DetermineHeuristicTypes();
147 EXPECT_FALSE(form_structure->IsAutofillable(true)); 144 EXPECT_FALSE(form_structure->IsAutofillable(true));
148 145
149 // We now have three text fields, but only two auto-fillable fields. 146 // We now have three text fields, but only two auto-fillable fields.
150 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 147 field.label = ASCIIToUTF16("First Name");
151 ASCIIToUTF16("firstname"), 148 field.name = ASCIIToUTF16("firstname");
152 string16(), 149 field.form_control_type = ASCIIToUTF16("text");
153 ASCIIToUTF16("text"), 150 form.fields.push_back(field);
154 0, 151
155 false)); 152 field.label = ASCIIToUTF16("Last Name");
156 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 153 field.name = ASCIIToUTF16("lastname");
157 ASCIIToUTF16("lastname"), 154 field.form_control_type = ASCIIToUTF16("text");
158 string16(), 155 form.fields.push_back(field);
159 ASCIIToUTF16("text"), 156
160 0,
161 false));
162 form_structure.reset(new FormStructure(form)); 157 form_structure.reset(new FormStructure(form));
163 form_structure->DetermineHeuristicTypes(); 158 form_structure->DetermineHeuristicTypes();
164 EXPECT_FALSE(form_structure->IsAutofillable(true)); 159 EXPECT_FALSE(form_structure->IsAutofillable(true));
165 160
166 // We now have three auto-fillable fields. 161 // We now have three auto-fillable fields.
167 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Email"), 162 field.label = ASCIIToUTF16("Email");
168 ASCIIToUTF16("email"), 163 field.name = ASCIIToUTF16("email");
169 string16(), 164 field.form_control_type = ASCIIToUTF16("email");
170 ASCIIToUTF16("text"), 165 form.fields.push_back(field);
171 0, 166
172 false));
173 form_structure.reset(new FormStructure(form)); 167 form_structure.reset(new FormStructure(form));
174 form_structure->DetermineHeuristicTypes(); 168 form_structure->DetermineHeuristicTypes();
175 EXPECT_TRUE(form_structure->IsAutofillable(true)); 169 EXPECT_TRUE(form_structure->IsAutofillable(true));
176 170
177 // The method must be 'post', though we can intentionally ignore this 171 // The method must be 'post', though we can intentionally ignore this
178 // criterion for the sake of providing a helpful warning message to the user. 172 // criterion for the sake of providing a helpful warning message to the user.
179 form.method = ASCIIToUTF16("get"); 173 form.method = ASCIIToUTF16("get");
180 form_structure.reset(new FormStructure(form)); 174 form_structure.reset(new FormStructure(form));
181 form_structure->DetermineHeuristicTypes(); 175 form_structure->DetermineHeuristicTypes();
182 EXPECT_FALSE(form_structure->IsAutofillable(true)); 176 EXPECT_FALSE(form_structure->IsAutofillable(true));
(...skipping 12 matching lines...) Expand all
195 form_structure->DetermineHeuristicTypes(); 189 form_structure->DetermineHeuristicTypes();
196 EXPECT_TRUE(form_structure->IsAutofillable(true)); 190 EXPECT_TRUE(form_structure->IsAutofillable(true));
197 } 191 }
198 192
199 TEST(FormStructureTest, ShouldBeParsed) { 193 TEST(FormStructureTest, ShouldBeParsed) {
200 scoped_ptr<FormStructure> form_structure; 194 scoped_ptr<FormStructure> form_structure;
201 FormData form; 195 FormData form;
202 196
203 // We need at least three text fields to be parseable. 197 // We need at least three text fields to be parseable.
204 form.method = ASCIIToUTF16("post"); 198 form.method = ASCIIToUTF16("post");
205 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), 199
206 ASCIIToUTF16("username"), 200 FormField field;
207 string16(), 201 field.label = ASCIIToUTF16("username");
208 ASCIIToUTF16("text"), 202 field.name = ASCIIToUTF16("username");
209 0, 203 field.form_control_type = ASCIIToUTF16("text");
210 false)); 204 form.fields.push_back(field);
205
211 form_structure.reset(new FormStructure(form)); 206 form_structure.reset(new FormStructure(form));
212 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 207 EXPECT_FALSE(form_structure->ShouldBeParsed(true));
213 208
214 // We now have three text fields, though only two are auto-fillable. 209 // We now have three text fields, though only two are auto-fillable.
215 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 210 field.label = ASCIIToUTF16("First Name");
216 ASCIIToUTF16("firstname"), 211 field.name = ASCIIToUTF16("firstname");
217 string16(), 212 field.form_control_type = ASCIIToUTF16("text");
218 ASCIIToUTF16("text"), 213 form.fields.push_back(field);
219 0, 214
220 false)); 215 field.label = ASCIIToUTF16("Last Name");
221 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 216 field.name = ASCIIToUTF16("lastname");
222 ASCIIToUTF16("lastname"), 217 field.form_control_type = ASCIIToUTF16("text");
223 string16(), 218 form.fields.push_back(field);
224 ASCIIToUTF16("text"), 219
225 0,
226 false));
227 form_structure.reset(new FormStructure(form)); 220 form_structure.reset(new FormStructure(form));
228 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); 221 EXPECT_TRUE(form_structure->ShouldBeParsed(true));
229 222
230 // The method must be 'post', though we can intentionally ignore this 223 // The method must be 'post', though we can intentionally ignore this
231 // criterion for the sake of providing a helpful warning message to the user. 224 // criterion for the sake of providing a helpful warning message to the user.
232 form.method = ASCIIToUTF16("get"); 225 form.method = ASCIIToUTF16("get");
233 form_structure.reset(new FormStructure(form)); 226 form_structure.reset(new FormStructure(form));
234 EXPECT_FALSE(form_structure->IsAutofillable(true)); 227 EXPECT_FALSE(form_structure->IsAutofillable(true));
235 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); 228 EXPECT_TRUE(form_structure->ShouldBeParsed(false));
236 229
237 // The target cannot include http(s)://*/search... 230 // The target cannot include http(s)://*/search...
238 form.method = ASCIIToUTF16("post"); 231 form.method = ASCIIToUTF16("post");
239 form.action = GURL("http://google.com/search?q=hello"); 232 form.action = GURL("http://google.com/search?q=hello");
240 form_structure.reset(new FormStructure(form)); 233 form_structure.reset(new FormStructure(form));
241 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 234 EXPECT_FALSE(form_structure->ShouldBeParsed(true));
242 235
243 // But search can be in the URL. 236 // But search can be in the URL.
244 form.action = GURL("http://search.com/?q=hello"); 237 form.action = GURL("http://search.com/?q=hello");
245 form_structure.reset(new FormStructure(form)); 238 form_structure.reset(new FormStructure(form));
246 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); 239 EXPECT_TRUE(form_structure->ShouldBeParsed(true));
247 240
248 // The form need only have three fields, but at least one must be a text 241 // The form need only have three fields, but at least one must be a text
249 // field. 242 // field.
250 form.fields.clear(); 243 form.fields.clear();
251 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Email"), 244
252 ASCIIToUTF16("email"), 245 field.label = ASCIIToUTF16("Email");
253 string16(), 246 field.name = ASCIIToUTF16("email");
254 ASCIIToUTF16("email"), 247 field.form_control_type = ASCIIToUTF16("email");
255 0, 248 form.fields.push_back(field);
256 false)); 249
257 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("State"), 250 field.label = ASCIIToUTF16("State");
258 ASCIIToUTF16("state"), 251 field.name = ASCIIToUTF16("state");
259 string16(), 252 field.form_control_type = ASCIIToUTF16("select-one");
260 ASCIIToUTF16("select-one"), 253 form.fields.push_back(field);
261 0, 254
262 false)); 255 field.label = ASCIIToUTF16("Country");
263 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Country"), 256 field.name = ASCIIToUTF16("country");
264 ASCIIToUTF16("country"), 257 field.form_control_type = ASCIIToUTF16("select-one");
265 string16(), 258 form.fields.push_back(field);
266 ASCIIToUTF16("select-one"), 259
267 0,
268 false));
269 form_structure.reset(new FormStructure(form)); 260 form_structure.reset(new FormStructure(form));
270 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); 261 EXPECT_TRUE(form_structure->ShouldBeParsed(true));
271 262
272 form.fields[0].form_control_type = ASCIIToUTF16("select-one"); 263 form.fields[0].form_control_type = ASCIIToUTF16("select-one");
273 form_structure.reset(new FormStructure(form)); 264 form_structure.reset(new FormStructure(form));
274 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 265 EXPECT_FALSE(form_structure->ShouldBeParsed(true));
275 } 266 }
276 267
277 TEST(FormStructureTest, HeuristicsContactInfo) { 268 TEST(FormStructureTest, HeuristicsContactInfo) {
278 scoped_ptr<FormStructure> form_structure; 269 scoped_ptr<FormStructure> form_structure;
279 FormData form; 270 FormData form;
271 form.method = ASCIIToUTF16("post");
280 272
281 form.method = ASCIIToUTF16("post"); 273 FormField field;
282 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 274 field.form_control_type = ASCIIToUTF16("text");
283 ASCIIToUTF16("firstname"), 275
284 string16(), 276 field.label = ASCIIToUTF16("First Name");
285 ASCIIToUTF16("text"), 277 field.name = ASCIIToUTF16("firstname");
286 0, 278 form.fields.push_back(field);
287 false)); 279
288 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 280 field.label = ASCIIToUTF16("Last Name");
289 ASCIIToUTF16("lastname"), 281 field.name = ASCIIToUTF16("lastname");
290 string16(), 282 form.fields.push_back(field);
291 ASCIIToUTF16("text"), 283
292 0, 284 field.label = ASCIIToUTF16("Email");
293 false)); 285 field.name = ASCIIToUTF16("email");
294 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), 286 form.fields.push_back(field);
295 ASCIIToUTF16("email"), 287
296 string16(), 288 field.label = ASCIIToUTF16("Phone");
297 ASCIIToUTF16("text"), 289 field.name = ASCIIToUTF16("phone");
298 0, 290 form.fields.push_back(field);
299 false)); 291
300 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), 292 field.label = ASCIIToUTF16("Fax");
301 ASCIIToUTF16("phone"), 293 field.name = ASCIIToUTF16("fax");
302 string16(), 294 form.fields.push_back(field);
303 ASCIIToUTF16("text"), 295
304 0, 296 field.label = ASCIIToUTF16("Address");
305 false)); 297 field.name = ASCIIToUTF16("address");
306 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), 298 form.fields.push_back(field);
307 ASCIIToUTF16("fax"), 299
308 string16(), 300 field.label = ASCIIToUTF16("City");
309 ASCIIToUTF16("text"), 301 field.name = ASCIIToUTF16("city");
310 0, 302 form.fields.push_back(field);
311 false)); 303
312 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 304 field.label = ASCIIToUTF16("Zip code");
313 ASCIIToUTF16("address"), 305 field.name = ASCIIToUTF16("zipcode");
314 string16(), 306 form.fields.push_back(field);
315 ASCIIToUTF16("text"), 307
316 0, 308 field.label = string16();
317 false)); 309 field.name = ASCIIToUTF16("Submit");
318 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("City"), 310 field.form_control_type = ASCIIToUTF16("submit");
319 ASCIIToUTF16("city"), 311 form.fields.push_back(field);
320 string16(), 312
321 ASCIIToUTF16("text"),
322 0,
323 false));
324 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"),
325 ASCIIToUTF16("zipcode"),
326 string16(),
327 ASCIIToUTF16("text"),
328 0,
329 false));
330 form.fields.push_back(webkit_glue::FormField(string16(),
331 ASCIIToUTF16("Submit"),
332 string16(),
333 ASCIIToUTF16("submit"),
334 0,
335 false));
336 form_structure.reset(new FormStructure(form)); 313 form_structure.reset(new FormStructure(form));
337 form_structure->DetermineHeuristicTypes(); 314 form_structure->DetermineHeuristicTypes();
338 EXPECT_TRUE(form_structure->IsAutofillable(true)); 315 EXPECT_TRUE(form_structure->IsAutofillable(true));
339 316
340 // Expect the correct number of fields. 317 // Expect the correct number of fields.
341 ASSERT_EQ(9U, form_structure->field_count()); 318 ASSERT_EQ(9U, form_structure->field_count());
342 ASSERT_EQ(8U, form_structure->autofill_count()); 319 ASSERT_EQ(8U, form_structure->autofill_count());
343 320
344 // First name. 321 // First name.
345 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 322 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
(...skipping 12 matching lines...) Expand all
358 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(6)->heuristic_type()); 335 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(6)->heuristic_type());
359 // Zip. 336 // Zip.
360 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type()); 337 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type());
361 // Submit. 338 // Submit.
362 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type()); 339 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type());
363 } 340 }
364 341
365 TEST(FormStructureTest, HeuristicsSample8) { 342 TEST(FormStructureTest, HeuristicsSample8) {
366 scoped_ptr<FormStructure> form_structure; 343 scoped_ptr<FormStructure> form_structure;
367 FormData form; 344 FormData form;
345 form.method = ASCIIToUTF16("post");
368 346
369 form.method = ASCIIToUTF16("post"); 347 FormField field;
370 form.fields.push_back( 348 field.form_control_type = ASCIIToUTF16("text");
371 webkit_glue::FormField(ASCIIToUTF16("Your First Name:"), 349
372 ASCIIToUTF16("bill.first"), 350 field.label = ASCIIToUTF16("Your First Name:");
373 string16(), 351 field.name = ASCIIToUTF16("bill.first");
374 ASCIIToUTF16("text"), 352 form.fields.push_back(field);
375 0, 353
376 false)); 354 field.label = ASCIIToUTF16("Your Last Name:");
377 form.fields.push_back( 355 field.name = ASCIIToUTF16("bill.last");
378 webkit_glue::FormField(ASCIIToUTF16("Your Last Name:"), 356 form.fields.push_back(field);
379 ASCIIToUTF16("bill.last"), 357
380 string16(), 358 field.label = ASCIIToUTF16("Street Address Line 1:");
381 ASCIIToUTF16("text"), 359 field.name = ASCIIToUTF16("bill.street1");
382 0, 360 form.fields.push_back(field);
383 false)); 361
384 form.fields.push_back( 362 field.label = ASCIIToUTF16("Street Address Line 2:");
385 webkit_glue::FormField(ASCIIToUTF16("Street Address Line 1:"), 363 field.name = ASCIIToUTF16("bill.street2");
386 ASCIIToUTF16("bill.street1"), 364 form.fields.push_back(field);
387 string16(), 365
388 ASCIIToUTF16("text"), 366 field.label = ASCIIToUTF16("City");
389 0, 367 field.name = ASCIIToUTF16("bill.city");
390 false)); 368 form.fields.push_back(field);
391 form.fields.push_back( 369
392 webkit_glue::FormField(ASCIIToUTF16("Street Address Line 2:"), 370 field.label = ASCIIToUTF16("State (U.S.):");
393 ASCIIToUTF16("bill.street2"), 371 field.name = ASCIIToUTF16("bill.state");
394 string16(), 372 form.fields.push_back(field);
395 ASCIIToUTF16("text"), 373
396 0, 374 field.label = ASCIIToUTF16("Zip/Postal Code:");
397 false)); 375 field.name = ASCIIToUTF16("BillTo.PostalCode");
398 form.fields.push_back( 376 form.fields.push_back(field);
399 webkit_glue::FormField(ASCIIToUTF16("City:"), 377
400 ASCIIToUTF16("bill.city"), 378 field.label = ASCIIToUTF16("Country:");
401 string16(), 379 field.name = ASCIIToUTF16("bill.country");
402 ASCIIToUTF16("text"), 380 form.fields.push_back(field);
403 0, 381
404 false)); 382 field.label = ASCIIToUTF16("Phone Number:");
405 form.fields.push_back( 383 field.name = ASCIIToUTF16("BillTo.Phone");
406 webkit_glue::FormField(ASCIIToUTF16("State (U.S.):"), 384 form.fields.push_back(field);
407 ASCIIToUTF16("bill.state"), 385
408 string16(), 386 field.label = string16();
409 ASCIIToUTF16("text"), 387 field.name = ASCIIToUTF16("Submit");
410 0, 388 field.form_control_type = ASCIIToUTF16("submit");
411 false)); 389 form.fields.push_back(field);
412 form.fields.push_back( 390
413 webkit_glue::FormField(ASCIIToUTF16("Zip/Postal Code:"),
414 ASCIIToUTF16("BillTo.PostalCode"),
415 string16(),
416 ASCIIToUTF16("text"),
417 0,
418 false));
419 form.fields.push_back(
420 webkit_glue::FormField(ASCIIToUTF16("Country:"),
421 ASCIIToUTF16("bill.country"),
422 string16(),
423 ASCIIToUTF16("text"),
424 0,
425 false));
426 form.fields.push_back(
427 webkit_glue::FormField(ASCIIToUTF16("Phone Number:"),
428 ASCIIToUTF16("BillTo.Phone"),
429 string16(),
430 ASCIIToUTF16("text"),
431 0,
432 false));
433 form.fields.push_back(
434 webkit_glue::FormField(string16(),
435 ASCIIToUTF16("Submit"),
436 string16(),
437 ASCIIToUTF16("submit"),
438 0,
439 false));
440 form_structure.reset(new FormStructure(form)); 391 form_structure.reset(new FormStructure(form));
441 form_structure->DetermineHeuristicTypes(); 392 form_structure->DetermineHeuristicTypes();
442 EXPECT_TRUE(form_structure->IsAutofillable(true)); 393 EXPECT_TRUE(form_structure->IsAutofillable(true));
443 ASSERT_EQ(10U, form_structure->field_count()); 394 ASSERT_EQ(10U, form_structure->field_count());
444 ASSERT_EQ(9U, form_structure->autofill_count()); 395 ASSERT_EQ(9U, form_structure->autofill_count());
445 396
446 // First name. 397 // First name.
447 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 398 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
448 // Last name. 399 // Last name.
449 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 400 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
(...skipping 13 matching lines...) Expand all
463 // Phone. 414 // Phone.
464 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 415 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
465 form_structure->field(8)->heuristic_type()); 416 form_structure->field(8)->heuristic_type());
466 // Submit. 417 // Submit.
467 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); 418 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type());
468 } 419 }
469 420
470 TEST(FormStructureTest, HeuristicsSample6) { 421 TEST(FormStructureTest, HeuristicsSample6) {
471 scoped_ptr<FormStructure> form_structure; 422 scoped_ptr<FormStructure> form_structure;
472 FormData form; 423 FormData form;
424 form.method = ASCIIToUTF16("post");
473 425
474 form.method = ASCIIToUTF16("post"); 426 FormField field;
475 form.fields.push_back( 427 field.form_control_type = ASCIIToUTF16("text");
476 webkit_glue::FormField(ASCIIToUTF16("E-mail address"), 428
477 ASCIIToUTF16("email"), 429 field.label = ASCIIToUTF16("E-mail address");
478 string16(), 430 field.name = ASCIIToUTF16("email");
479 ASCIIToUTF16("text"), 431 form.fields.push_back(field);
480 0, 432
481 false)); 433 field.label = ASCIIToUTF16("Full name");
482 form.fields.push_back( 434 field.name = ASCIIToUTF16("name");
483 webkit_glue::FormField(ASCIIToUTF16("Full name"), 435 form.fields.push_back(field);
484 ASCIIToUTF16("name"), 436
485 string16(), 437 field.label = ASCIIToUTF16("Company");
486 ASCIIToUTF16("text"), 438 field.name = ASCIIToUTF16("company");
487 0, 439 form.fields.push_back(field);
488 false)); 440
489 form.fields.push_back( 441 field.label = ASCIIToUTF16("Address");
490 webkit_glue::FormField(ASCIIToUTF16("Company"), 442 field.name = ASCIIToUTF16("address");
491 ASCIIToUTF16("company"), 443 form.fields.push_back(field);
492 string16(), 444
493 ASCIIToUTF16("text"), 445 field.label = ASCIIToUTF16("City");
494 0, 446 field.name = ASCIIToUTF16("city");
495 false)); 447 form.fields.push_back(field);
496 form.fields.push_back( 448
497 webkit_glue::FormField(ASCIIToUTF16("Address"), 449 field.label = ASCIIToUTF16("Zip Code");
498 ASCIIToUTF16("address"), 450 field.name = ASCIIToUTF16("Home.PostalCode");
499 string16(), 451 form.fields.push_back(field);
500 ASCIIToUTF16("text"), 452
501 0, 453 field.label = string16();
502 false)); 454 field.name = ASCIIToUTF16("Submit");
503 form.fields.push_back( 455 field.value = ASCIIToUTF16("continue");
504 webkit_glue::FormField(ASCIIToUTF16("City"), 456 field.form_control_type = ASCIIToUTF16("submit");
505 ASCIIToUTF16("city"), 457 form.fields.push_back(field);
506 string16(), 458
507 ASCIIToUTF16("text"),
508 0,
509 false));
510 // TODO(jhawkins): Add state select control.
511 form.fields.push_back(
512 webkit_glue::FormField(ASCIIToUTF16("Zip Code"),
513 ASCIIToUTF16("Home.PostalCode"),
514 string16(),
515 ASCIIToUTF16("text"),
516 0,
517 false));
518 // TODO(jhawkins): Phone number.
519 form.fields.push_back(
520 webkit_glue::FormField(string16(),
521 ASCIIToUTF16("Submit"),
522 ASCIIToUTF16("continue"),
523 ASCIIToUTF16("submit"),
524 0,
525 false));
526 form_structure.reset(new FormStructure(form)); 459 form_structure.reset(new FormStructure(form));
527 form_structure->DetermineHeuristicTypes(); 460 form_structure->DetermineHeuristicTypes();
528 EXPECT_TRUE(form_structure->IsAutofillable(true)); 461 EXPECT_TRUE(form_structure->IsAutofillable(true));
529 ASSERT_EQ(7U, form_structure->field_count()); 462 ASSERT_EQ(7U, form_structure->field_count());
530 ASSERT_EQ(6U, form_structure->autofill_count()); 463 ASSERT_EQ(6U, form_structure->autofill_count());
531 464
532 // Email. 465 // Email.
533 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); 466 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type());
534 // Full name. 467 // Full name.
535 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); 468 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type());
536 // Company 469 // Company
537 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); 470 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type());
538 // Address. 471 // Address.
539 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type()); 472 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type());
540 // City. 473 // City.
541 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); 474 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
542 // Zip. 475 // Zip.
543 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type()); 476 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type());
544 // Submit. 477 // Submit.
545 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 478 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
546 } 479 }
547 480
548 // Tests a sequence of FormFields where only labels are supplied to heuristics 481 // Tests a sequence of FormFields where only labels are supplied to heuristics
549 // for matching. This works because FormField labels are matched in the case 482 // for matching. This works because FormField labels are matched in the case
550 // that input element ids (or |name| fields) are missing. 483 // that input element ids (or |name| fields) are missing.
551 TEST(FormStructureTest, HeuristicsLabelsOnly) { 484 TEST(FormStructureTest, HeuristicsLabelsOnly) {
552 scoped_ptr<FormStructure> form_structure; 485 scoped_ptr<FormStructure> form_structure;
553 FormData form; 486 FormData form;
487 form.method = ASCIIToUTF16("post");
554 488
555 form.method = ASCIIToUTF16("post"); 489 FormField field;
556 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 490 field.form_control_type = ASCIIToUTF16("text");
557 string16(), 491
558 string16(), 492 field.label = ASCIIToUTF16("First Name");
559 ASCIIToUTF16("text"), 493 field.name = string16();
560 0, 494 form.fields.push_back(field);
561 false)); 495
562 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 496 field.label = ASCIIToUTF16("Last Name");
563 string16(), 497 field.name = string16();
564 string16(), 498 form.fields.push_back(field);
565 ASCIIToUTF16("text"), 499
566 0, 500 field.label = ASCIIToUTF16("Email");
567 false)); 501 field.name = string16();
568 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), 502 form.fields.push_back(field);
569 string16(), 503
570 string16(), 504 field.label = ASCIIToUTF16("Phone");
571 ASCIIToUTF16("text"), 505 field.name = string16();
572 0, 506 form.fields.push_back(field);
573 false)); 507
574 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), 508 field.label = ASCIIToUTF16("Fax");
575 string16(), 509 field.name = string16();
576 string16(), 510 form.fields.push_back(field);
577 ASCIIToUTF16("text"), 511
578 0, 512 field.label = ASCIIToUTF16("Address");
579 false)); 513 field.name = string16();
580 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), 514 form.fields.push_back(field);
581 string16(), 515
582 string16(), 516 field.label = ASCIIToUTF16("Address");
583 ASCIIToUTF16("text"), 517 field.name = string16();
584 0, 518 form.fields.push_back(field);
585 false)); 519
586 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 520 field.label = ASCIIToUTF16("Zip code");
587 string16(), 521 field.name = string16();
588 string16(), 522 form.fields.push_back(field);
589 ASCIIToUTF16("text"), 523
590 0, 524 field.label = string16();
591 false)); 525 field.name = ASCIIToUTF16("Submit");
592 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 526 field.form_control_type = ASCIIToUTF16("submit");
593 string16(), 527 form.fields.push_back(field);
594 string16(), 528
595 ASCIIToUTF16("text"),
596 0,
597 false));
598 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"),
599 string16(),
600 string16(),
601 ASCIIToUTF16("text"),
602 0,
603 false));
604 form.fields.push_back(webkit_glue::FormField(string16(),
605 ASCIIToUTF16("Submit"),
606 string16(),
607 ASCIIToUTF16("submit"),
608 0,
609 false));
610 form_structure.reset(new FormStructure(form)); 529 form_structure.reset(new FormStructure(form));
611 form_structure->DetermineHeuristicTypes(); 530 form_structure->DetermineHeuristicTypes();
612 EXPECT_TRUE(form_structure->IsAutofillable(true)); 531 EXPECT_TRUE(form_structure->IsAutofillable(true));
613 ASSERT_EQ(9U, form_structure->field_count()); 532 ASSERT_EQ(9U, form_structure->field_count());
614 ASSERT_EQ(8U, form_structure->autofill_count()); 533 ASSERT_EQ(8U, form_structure->autofill_count());
615 534
616 // First name. 535 // First name.
617 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 536 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
618 // Last name. 537 // Last name.
619 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 538 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
(...skipping 10 matching lines...) Expand all
630 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(6)->heuristic_type()); 549 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(6)->heuristic_type());
631 // Zip. 550 // Zip.
632 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type()); 551 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type());
633 // Submit. 552 // Submit.
634 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type()); 553 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type());
635 } 554 }
636 555
637 TEST(FormStructureTest, HeuristicsCreditCardInfo) { 556 TEST(FormStructureTest, HeuristicsCreditCardInfo) {
638 scoped_ptr<FormStructure> form_structure; 557 scoped_ptr<FormStructure> form_structure;
639 FormData form; 558 FormData form;
559 form.method = ASCIIToUTF16("post");
640 560
641 form.method = ASCIIToUTF16("post"); 561 FormField field;
642 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), 562 field.form_control_type = ASCIIToUTF16("text");
643 ASCIIToUTF16("name on card"), 563
644 string16(), 564 field.label = ASCIIToUTF16("Name on Card");
645 ASCIIToUTF16("text"), 565 field.name = ASCIIToUTF16("name_on_card");
646 0, 566 form.fields.push_back(field);
647 false)); 567
648 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), 568 field.label = ASCIIToUTF16("Card Number");
649 ASCIIToUTF16("card_number"), 569 field.name = ASCIIToUTF16("card_number");
650 string16(), 570 form.fields.push_back(field);
651 ASCIIToUTF16("text"), 571
652 0, 572 field.label = ASCIIToUTF16("Exp Month");
653 false)); 573 field.name = ASCIIToUTF16("ccmonth");
654 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), 574 form.fields.push_back(field);
655 ASCIIToUTF16("ccmonth"), 575
656 string16(), 576 field.label = ASCIIToUTF16("Exp Year");
657 ASCIIToUTF16("text"), 577 field.name = ASCIIToUTF16("ccyear");
658 0, 578 form.fields.push_back(field);
659 false)); 579
660 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), 580 field.label = ASCIIToUTF16("Verification");
661 ASCIIToUTF16("ccyear"), 581 field.name = ASCIIToUTF16("verification");
662 string16(), 582 form.fields.push_back(field);
663 ASCIIToUTF16("text"), 583
664 0, 584 field.label = string16();
665 false)); 585 field.name = ASCIIToUTF16("Submit");
666 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), 586 field.form_control_type = ASCIIToUTF16("submit");
667 ASCIIToUTF16("verification"), 587 form.fields.push_back(field);
668 string16(), 588
669 ASCIIToUTF16("text"),
670 0,
671 false));
672 form.fields.push_back(webkit_glue::FormField(string16(),
673 ASCIIToUTF16("Submit"),
674 string16(),
675 ASCIIToUTF16("submit"),
676 0,
677 false));
678 form_structure.reset(new FormStructure(form)); 589 form_structure.reset(new FormStructure(form));
679 form_structure->DetermineHeuristicTypes(); 590 form_structure->DetermineHeuristicTypes();
680 EXPECT_TRUE(form_structure->IsAutofillable(true)); 591 EXPECT_TRUE(form_structure->IsAutofillable(true));
681 ASSERT_EQ(6U, form_structure->field_count()); 592 ASSERT_EQ(6U, form_structure->field_count());
682 ASSERT_EQ(4U, form_structure->autofill_count()); 593 ASSERT_EQ(4U, form_structure->autofill_count());
683 594
684 // Credit card name. 595 // Credit card name.
685 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); 596 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
686 // Credit card number. 597 // Credit card number.
687 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); 598 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type());
688 // Credit card expiration month. 599 // Credit card expiration month.
689 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(2)->heuristic_type()); 600 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(2)->heuristic_type());
690 // Credit card expiration year. 601 // Credit card expiration year.
691 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 602 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
692 form_structure->field(3)->heuristic_type()); 603 form_structure->field(3)->heuristic_type());
693 // We don't determine CVV. 604 // We don't determine CVV.
694 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(4)->heuristic_type()); 605 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(4)->heuristic_type());
695 // Submit. 606 // Submit.
696 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 607 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
697 } 608 }
698 609
699 TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { 610 TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) {
700 scoped_ptr<FormStructure> form_structure; 611 scoped_ptr<FormStructure> form_structure;
701 FormData form; 612 FormData form;
613 form.method = ASCIIToUTF16("post");
702 614
703 form.method = ASCIIToUTF16("post"); 615 FormField field;
704 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), 616 field.form_control_type = ASCIIToUTF16("text");
705 ASCIIToUTF16("name on card"), 617
706 string16(), 618 field.label = ASCIIToUTF16("Name on Card");
707 ASCIIToUTF16("text"), 619 field.name = ASCIIToUTF16("name_on_card");
708 0, 620 form.fields.push_back(field);
709 false)); 621
710 // This is not a field we know how to process. But we should skip over it 622 // This is not a field we know how to process. But we should skip over it
711 // and process the other fields in the card block. 623 // and process the other fields in the card block.
712 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Type"), 624 field.label = ASCIIToUTF16("Card Type");
713 ASCIIToUTF16("card_type"), 625 field.name = ASCIIToUTF16("card_type");
714 string16(), 626 form.fields.push_back(field);
715 ASCIIToUTF16("text"), 627
716 0, 628 field.label = ASCIIToUTF16("Card Number");
717 false)); 629 field.name = ASCIIToUTF16("card_number");
718 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), 630 form.fields.push_back(field);
719 ASCIIToUTF16("card_number"), 631
720 string16(), 632 field.label = ASCIIToUTF16("Exp Month");
721 ASCIIToUTF16("text"), 633 field.name = ASCIIToUTF16("ccmonth");
722 0, 634 form.fields.push_back(field);
723 false)); 635
724 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), 636 field.label = ASCIIToUTF16("Exp Year");
725 ASCIIToUTF16("ccmonth"), 637 field.name = ASCIIToUTF16("ccyear");
726 string16(), 638 form.fields.push_back(field);
727 ASCIIToUTF16("text"), 639
728 0, 640 field.label = ASCIIToUTF16("Verification");
729 false)); 641 field.name = ASCIIToUTF16("verification");
730 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), 642 form.fields.push_back(field);
731 ASCIIToUTF16("ccyear"), 643
732 string16(), 644 field.label = string16();
733 ASCIIToUTF16("text"), 645 field.name = ASCIIToUTF16("Submit");
734 0, 646 field.form_control_type = ASCIIToUTF16("submit");
735 false)); 647 form.fields.push_back(field);
736 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), 648
737 ASCIIToUTF16("verification"),
738 string16(),
739 ASCIIToUTF16("text"),
740 0,
741 false));
742 form.fields.push_back(webkit_glue::FormField(string16(),
743 ASCIIToUTF16("Submit"),
744 string16(),
745 ASCIIToUTF16("submit"),
746 0,
747 false));
748 form_structure.reset(new FormStructure(form)); 649 form_structure.reset(new FormStructure(form));
749 form_structure->DetermineHeuristicTypes(); 650 form_structure->DetermineHeuristicTypes();
750 EXPECT_TRUE(form_structure->IsAutofillable(true)); 651 EXPECT_TRUE(form_structure->IsAutofillable(true));
751 ASSERT_EQ(7U, form_structure->field_count()); 652 ASSERT_EQ(7U, form_structure->field_count());
752 ASSERT_EQ(4U, form_structure->autofill_count()); 653 ASSERT_EQ(4U, form_structure->autofill_count());
753 654
754 // Credit card name. 655 // Credit card name.
755 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); 656 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
756 // Credit card type. This is an unknown type but related to the credit card. 657 // Credit card type. This is an unknown type but related to the credit card.
757 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 658 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
758 // Credit card number. 659 // Credit card number.
759 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); 660 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type());
760 // Credit card expiration month. 661 // Credit card expiration month.
761 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); 662 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
762 // Credit card expiration year. 663 // Credit card expiration year.
763 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 664 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
764 form_structure->field(4)->heuristic_type()); 665 form_structure->field(4)->heuristic_type());
765 // We don't determine CVV. 666 // We don't determine CVV.
766 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 667 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
767 // Submit. 668 // Submit.
768 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 669 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
769 } 670 }
770 671
771 TEST(FormStructureTest, ThreeAddressLines) { 672 TEST(FormStructureTest, ThreeAddressLines) {
772 scoped_ptr<FormStructure> form_structure; 673 scoped_ptr<FormStructure> form_structure;
773 FormData form; 674 FormData form;
675 form.method = ASCIIToUTF16("post");
774 676
775 form.method = ASCIIToUTF16("post"); 677 FormField field;
776 form.fields.push_back( 678 field.form_control_type = ASCIIToUTF16("text");
777 webkit_glue::FormField(ASCIIToUTF16("Address Line1"), 679
778 ASCIIToUTF16("Address"), 680 field.label = ASCIIToUTF16("Address Line1");
779 string16(), 681 field.name = ASCIIToUTF16("Address");
780 ASCIIToUTF16("text"), 682 form.fields.push_back(field);
781 0, 683
782 false)); 684 field.label = ASCIIToUTF16("Address Line2");
783 form.fields.push_back( 685 field.name = ASCIIToUTF16("Address");
784 webkit_glue::FormField(ASCIIToUTF16("Address Line2"), 686 form.fields.push_back(field);
785 ASCIIToUTF16("Address"), 687
786 string16(), 688 field.label = ASCIIToUTF16("Address Line3");
787 ASCIIToUTF16("text"), 689 field.name = ASCIIToUTF16("Address");
788 0, 690 form.fields.push_back(field);
789 false)); 691
790 form.fields.push_back( 692 field.label = ASCIIToUTF16("City");
791 webkit_glue::FormField(ASCIIToUTF16("Address Line3"), 693 field.name = ASCIIToUTF16("city");
792 ASCIIToUTF16("Address"), 694 form.fields.push_back(field);
793 string16(), 695
794 ASCIIToUTF16("text"),
795 0,
796 false));
797 form.fields.push_back(
798 webkit_glue::FormField(ASCIIToUTF16("City"),
799 ASCIIToUTF16("city"),
800 string16(),
801 ASCIIToUTF16("text"),
802 0,
803 false));
804 form_structure.reset(new FormStructure(form)); 696 form_structure.reset(new FormStructure(form));
805 form_structure->DetermineHeuristicTypes(); 697 form_structure->DetermineHeuristicTypes();
806 EXPECT_TRUE(form_structure->IsAutofillable(true)); 698 EXPECT_TRUE(form_structure->IsAutofillable(true));
807 ASSERT_EQ(4U, form_structure->field_count()); 699 ASSERT_EQ(4U, form_structure->field_count());
808 ASSERT_EQ(3U, form_structure->autofill_count()); 700 ASSERT_EQ(3U, form_structure->autofill_count());
809 701
810 // Address Line 1. 702 // Address Line 1.
811 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 703 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
812 // Address Line 2. 704 // Address Line 2.
813 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 705 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
814 // Address Line 3. 706 // Address Line 3.
815 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 707 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
816 // City. 708 // City.
817 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); 709 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type());
818 } 710 }
819 711
820 // This test verifies that "addressLine1" and "addressLine2" matches heuristics. 712 // This test verifies that "addressLine1" and "addressLine2" matches heuristics.
821 // This occured in https://www.gorillaclothing.com/. http://crbug.com/52126. 713 // This occured in https://www.gorillaclothing.com/. http://crbug.com/52126.
822 TEST(FormStructureTest, BillingAndShippingAddresses) { 714 TEST(FormStructureTest, BillingAndShippingAddresses) {
823 scoped_ptr<FormStructure> form_structure; 715 scoped_ptr<FormStructure> form_structure;
824 FormData form; 716 FormData form;
717 form.method = ASCIIToUTF16("post");
825 718
826 form.method = ASCIIToUTF16("post"); 719 FormField field;
827 form.fields.push_back( 720 field.form_control_type = ASCIIToUTF16("text");
828 webkit_glue::FormField(ASCIIToUTF16("Address Line1"), 721
829 ASCIIToUTF16("shipping.address.addressLine1"), 722 field.label = ASCIIToUTF16("Address Line1");
830 string16(), 723 field.name = ASCIIToUTF16("shipping.address.addressLine1");
831 ASCIIToUTF16("text"), 724 form.fields.push_back(field);
832 0, 725
833 false)); 726 field.label = ASCIIToUTF16("Address Line2");
834 form.fields.push_back( 727 field.name = ASCIIToUTF16("shipping.address.addressLine2");
835 webkit_glue::FormField(ASCIIToUTF16("Address Line2"), 728 form.fields.push_back(field);
836 ASCIIToUTF16("shipping.address.addressLine2"), 729
837 string16(), 730 field.label = ASCIIToUTF16("Address Line1");
838 ASCIIToUTF16("text"), 731 field.name = ASCIIToUTF16("billing.address.addressLine1");
839 0, 732 form.fields.push_back(field);
840 false)); 733
841 form.fields.push_back( 734 field.label = ASCIIToUTF16("Address Line2");
842 webkit_glue::FormField(ASCIIToUTF16("Address Line1"), 735 field.name = ASCIIToUTF16("billing.address.addressLine2");
843 ASCIIToUTF16("billing.address.addressLine1"), 736 form.fields.push_back(field);
844 string16(), 737
845 ASCIIToUTF16("text"),
846 0,
847 false));
848 form.fields.push_back(
849 webkit_glue::FormField(ASCIIToUTF16("Address Line2"),
850 ASCIIToUTF16("billing.address.addressLine2"),
851 string16(),
852 ASCIIToUTF16("text"),
853 0,
854 false));
855 form_structure.reset(new FormStructure(form)); 738 form_structure.reset(new FormStructure(form));
856 form_structure->DetermineHeuristicTypes(); 739 form_structure->DetermineHeuristicTypes();
857 EXPECT_TRUE(form_structure->IsAutofillable(true)); 740 EXPECT_TRUE(form_structure->IsAutofillable(true));
858 ASSERT_EQ(4U, form_structure->field_count()); 741 ASSERT_EQ(4U, form_structure->field_count());
859 ASSERT_EQ(4U, form_structure->autofill_count()); 742 ASSERT_EQ(4U, form_structure->autofill_count());
860 743
861 // Address Line 1. 744 // Address Line 1.
862 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 745 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
863 // Address Line 2. 746 // Address Line 2.
864 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 747 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
865 // Address Line 1. 748 // Address Line 1.
866 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type()); 749 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type());
867 // Address Line 2. 750 // Address Line 2.
868 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type()); 751 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type());
869 } 752 }
870 753
871 754
872 // This example comes from expedia.com where they use a "Suite" label to 755 // This example comes from expedia.com where they use a "Suite" label to
873 // indicate a suite or apartment number. We interpret this as address line 2. 756 // indicate a suite or apartment number. We interpret this as address line 2.
874 // And the following "Street address second line" we interpret as address line 757 // And the following "Street address second line" we interpret as address line
875 // 3 and discard. 758 // 3 and discard.
876 // See http://crbug.com/48197 for details. 759 // See http://crbug.com/48197 for details.
877 TEST(FormStructureTest, ThreeAddressLinesExpedia) { 760 TEST(FormStructureTest, ThreeAddressLinesExpedia) {
878 scoped_ptr<FormStructure> form_structure; 761 scoped_ptr<FormStructure> form_structure;
879 FormData form; 762 FormData form;
763 form.method = ASCIIToUTF16("post");
880 764
881 form.method = ASCIIToUTF16("post"); 765 FormField field;
882 form.fields.push_back( 766 field.form_control_type = ASCIIToUTF16("text");
883 webkit_glue::FormField(ASCIIToUTF16("Street:"), 767
884 ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1"), 768 field.label = ASCIIToUTF16("Street:");
885 string16(), 769 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1");
886 ASCIIToUTF16("text"), 770 form.fields.push_back(field);
887 0, 771
888 false)); 772 field.label = ASCIIToUTF16("Suite or Apt:");
889 form.fields.push_back( 773 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adap");
890 webkit_glue::FormField(ASCIIToUTF16("Suite or Apt:"), 774 form.fields.push_back(field);
891 ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adap"), 775
892 string16(), 776 field.label = ASCIIToUTF16("Street address second line");
893 ASCIIToUTF16("text"), 777 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2");
894 0, 778 form.fields.push_back(field);
895 false)); 779
896 form.fields.push_back( 780 field.label = ASCIIToUTF16("City:");
897 webkit_glue::FormField(ASCIIToUTF16("Street address second line"), 781 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct");
898 ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"), 782 form.fields.push_back(field);
899 string16(), 783
900 ASCIIToUTF16("text"),
901 0,
902 false));
903 form.fields.push_back(
904 webkit_glue::FormField(ASCIIToUTF16("City:"),
905 ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"),
906 string16(),
907 ASCIIToUTF16("text"),
908 0,
909 false));
910 form_structure.reset(new FormStructure(form)); 784 form_structure.reset(new FormStructure(form));
911 form_structure->DetermineHeuristicTypes(); 785 form_structure->DetermineHeuristicTypes();
912 EXPECT_TRUE(form_structure->IsAutofillable(true)); 786 EXPECT_TRUE(form_structure->IsAutofillable(true));
913 ASSERT_EQ(4U, form_structure->field_count()); 787 ASSERT_EQ(4U, form_structure->field_count());
914 EXPECT_EQ(3U, form_structure->autofill_count()); 788 EXPECT_EQ(3U, form_structure->autofill_count());
915 789
916 // Address Line 1. 790 // Address Line 1.
917 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 791 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
918 // Suite / Apt. 792 // Suite / Apt.
919 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 793 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
920 // Address Line 3. 794 // Address Line 3.
921 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 795 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
922 // City. 796 // City.
923 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); 797 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type());
924 } 798 }
925 799
926 // This example comes from ebay.com where the word "suite" appears in the label 800 // This example comes from ebay.com where the word "suite" appears in the label
927 // and the name "address2" clearly indicates that this is the address line 2. 801 // and the name "address2" clearly indicates that this is the address line 2.
928 // See http://crbug.com/48197 for details. 802 // See http://crbug.com/48197 for details.
929 TEST(FormStructureTest, TwoAddressLinesEbay) { 803 TEST(FormStructureTest, TwoAddressLinesEbay) {
930 scoped_ptr<FormStructure> form_structure; 804 scoped_ptr<FormStructure> form_structure;
931 FormData form; 805 FormData form;
806 form.method = ASCIIToUTF16("post");
932 807
933 form.method = ASCIIToUTF16("post"); 808 FormField field;
934 form.fields.push_back( 809 field.form_control_type = ASCIIToUTF16("text");
935 webkit_glue::FormField(ASCIIToUTF16("Address Line1"), 810
936 ASCIIToUTF16("address1"), 811 field.label = ASCIIToUTF16("Address Line1");
937 string16(), 812 field.name = ASCIIToUTF16("address1");
938 ASCIIToUTF16("text"), 813 form.fields.push_back(field);
939 0, 814
940 false)); 815 field.label = ASCIIToUTF16("Floor number, suite number, etc");
941 form.fields.push_back( 816 field.name = ASCIIToUTF16("address2");
942 webkit_glue::FormField(ASCIIToUTF16("Floor number, suite number, etc"), 817 form.fields.push_back(field);
943 ASCIIToUTF16("address2"), 818
944 string16(), 819 field.label = ASCIIToUTF16("City:");
945 ASCIIToUTF16("text"), 820 field.name = ASCIIToUTF16("city");
946 0, 821 form.fields.push_back(field);
947 false)); 822
948 form.fields.push_back(
949 webkit_glue::FormField(ASCIIToUTF16("City"),
950 ASCIIToUTF16("city"),
951 string16(),
952 ASCIIToUTF16("text"),
953 0,
954 false));
955 form_structure.reset(new FormStructure(form)); 823 form_structure.reset(new FormStructure(form));
956 form_structure->DetermineHeuristicTypes(); 824 form_structure->DetermineHeuristicTypes();
957 EXPECT_TRUE(form_structure->IsAutofillable(true)); 825 EXPECT_TRUE(form_structure->IsAutofillable(true));
958 ASSERT_EQ(3U, form_structure->field_count()); 826 ASSERT_EQ(3U, form_structure->field_count());
959 ASSERT_EQ(3U, form_structure->autofill_count()); 827 ASSERT_EQ(3U, form_structure->autofill_count());
960 828
961 // Address Line 1. 829 // Address Line 1.
962 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 830 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
963 // Address Line 2. 831 // Address Line 2.
964 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 832 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
965 // City. 833 // City.
966 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type()); 834 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type());
967 } 835 }
968 836
969 TEST(FormStructureTest, HeuristicsStateWithProvince) { 837 TEST(FormStructureTest, HeuristicsStateWithProvince) {
970 scoped_ptr<FormStructure> form_structure; 838 scoped_ptr<FormStructure> form_structure;
971 FormData form; 839 FormData form;
840 form.method = ASCIIToUTF16("post");
972 841
973 form.method = ASCIIToUTF16("post"); 842 FormField field;
974 form.fields.push_back( 843 field.form_control_type = ASCIIToUTF16("text");
975 webkit_glue::FormField(ASCIIToUTF16("Address Line1"), 844
976 ASCIIToUTF16("Address"), 845 field.label = ASCIIToUTF16("Address Line1");
977 string16(), 846 field.name = ASCIIToUTF16("Address");
978 ASCIIToUTF16("text"), 847 form.fields.push_back(field);
979 0, 848
980 false)); 849 field.label = ASCIIToUTF16("Address Line2");
981 form.fields.push_back( 850 field.name = ASCIIToUTF16("Address");
982 webkit_glue::FormField(ASCIIToUTF16("Address Line2"), 851 form.fields.push_back(field);
983 ASCIIToUTF16("Address"), 852
984 string16(), 853 field.label = ASCIIToUTF16("State/Province/Region");
985 ASCIIToUTF16("text"), 854 field.name = ASCIIToUTF16("State");
986 0, 855 form.fields.push_back(field);
987 false)); 856
988 form.fields.push_back(
989 webkit_glue::FormField(ASCIIToUTF16("State/Province/Region"),
990 ASCIIToUTF16("State"),
991 string16(),
992 ASCIIToUTF16("text"),
993 0,
994 false));
995 form_structure.reset(new FormStructure(form)); 857 form_structure.reset(new FormStructure(form));
996 form_structure->DetermineHeuristicTypes(); 858 form_structure->DetermineHeuristicTypes();
997 EXPECT_TRUE(form_structure->IsAutofillable(true)); 859 EXPECT_TRUE(form_structure->IsAutofillable(true));
998 ASSERT_EQ(3U, form_structure->field_count()); 860 ASSERT_EQ(3U, form_structure->field_count());
999 ASSERT_EQ(3U, form_structure->autofill_count()); 861 ASSERT_EQ(3U, form_structure->autofill_count());
1000 862
1001 // Address Line 1. 863 // Address Line 1.
1002 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 864 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
1003 // Address Line 2. 865 // Address Line 2.
1004 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 866 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1005 // State. 867 // State.
1006 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type()); 868 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type());
1007 } 869 }
1008 870
1009 // This example comes from lego.com's checkout page. 871 // This example comes from lego.com's checkout page.
1010 TEST(FormStructureTest, HeuristicsWithBilling) { 872 TEST(FormStructureTest, HeuristicsWithBilling) {
1011 scoped_ptr<FormStructure> form_structure; 873 scoped_ptr<FormStructure> form_structure;
1012 FormData form; 874 FormData form;
875 form.method = ASCIIToUTF16("post");
1013 876
1014 form.method = ASCIIToUTF16("post"); 877 FormField field;
1015 form.fields.push_back( 878 field.form_control_type = ASCIIToUTF16("text");
1016 webkit_glue::FormField(ASCIIToUTF16("First Name*:"), 879
1017 ASCIIToUTF16("editBillingAddress$firstNameBox"), 880 field.label = ASCIIToUTF16("First Name*:");
1018 string16(), 881 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox");
1019 ASCIIToUTF16("text"), 882 form.fields.push_back(field);
1020 0, 883
1021 false)); 884 field.label = ASCIIToUTF16("Last Name*:");
1022 form.fields.push_back( 885 field.name = ASCIIToUTF16("editBillingAddress$lastNameBox");
1023 webkit_glue::FormField(ASCIIToUTF16("Last Name*:"), 886 form.fields.push_back(field);
1024 ASCIIToUTF16("editBillingAddress$lastNameBox"), 887
1025 string16(), 888 field.label = ASCIIToUTF16("Company Name:");
1026 ASCIIToUTF16("text"), 889 field.name = ASCIIToUTF16("editBillingAddress$companyBox");
1027 0, 890 form.fields.push_back(field);
1028 false)); 891
1029 form.fields.push_back( 892 field.label = ASCIIToUTF16("Address*:");
1030 webkit_glue::FormField(ASCIIToUTF16("Company Name:"), 893 field.name = ASCIIToUTF16("editBillingAddress$addressLine1Box");
1031 ASCIIToUTF16("editBillingAddress$companyBox"), 894 form.fields.push_back(field);
1032 string16(), 895
1033 ASCIIToUTF16("text"), 896 field.label = ASCIIToUTF16("Apt/Suite :");
1034 0, 897 field.name = ASCIIToUTF16("editBillingAddress$addressLine2Box");
1035 false)); 898 form.fields.push_back(field);
1036 form.fields.push_back( 899
1037 webkit_glue::FormField(ASCIIToUTF16("Address*:"), 900 field.label = ASCIIToUTF16("City*:");
1038 ASCIIToUTF16("editBillingAddress$addressLine1Box"), 901 field.name = ASCIIToUTF16("editBillingAddress$cityBox");
1039 string16(), 902 form.fields.push_back(field);
1040 ASCIIToUTF16("text"), 903
1041 0, 904 field.label = ASCIIToUTF16("State/Province*:");
1042 false)); 905 field.name = ASCIIToUTF16("editBillingAddress$stateDropDown");
1043 form.fields.push_back( 906 form.fields.push_back(field);
1044 webkit_glue::FormField(ASCIIToUTF16("Apt/Suite :"), 907
1045 ASCIIToUTF16("editBillingAddress$addressLine2Box"), 908 field.label = ASCIIToUTF16("Country*:");
1046 string16(), 909 field.name = ASCIIToUTF16("editBillingAddress$countryDropDown");
1047 ASCIIToUTF16("text"), 910 form.fields.push_back(field);
1048 0, 911
1049 false)); 912 field.label = ASCIIToUTF16("Postal Code*:");
1050 form.fields.push_back( 913 field.name = ASCIIToUTF16("editBillingAddress$zipCodeBox");
1051 webkit_glue::FormField(ASCIIToUTF16("City*:"), 914 form.fields.push_back(field);
1052 ASCIIToUTF16("editBillingAddress$cityBox"), 915
1053 string16(), 916 field.label = ASCIIToUTF16("Phone*:");
1054 ASCIIToUTF16("text"), 917 field.name = ASCIIToUTF16("editBillingAddress$phoneBox");
1055 0, 918 form.fields.push_back(field);
1056 false)); 919
1057 form.fields.push_back( 920 field.label = ASCIIToUTF16("Email Address*:");
1058 webkit_glue::FormField(ASCIIToUTF16("State/Province*:"), 921 field.name = ASCIIToUTF16("email$emailBox");
1059 ASCIIToUTF16("editBillingAddress$stateDropDown"), 922 form.fields.push_back(field);
1060 string16(), 923
1061 ASCIIToUTF16("text"),
1062 0,
1063 false));
1064 form.fields.push_back(
1065 webkit_glue::FormField(ASCIIToUTF16("Country*:"),
1066 ASCIIToUTF16("editBillingAddress$countryDropDown"),
1067 string16(),
1068 ASCIIToUTF16("text"),
1069 0,
1070 false));
1071 form.fields.push_back(
1072 webkit_glue::FormField(ASCIIToUTF16("Postal Code*:"),
1073 ASCIIToUTF16("editBillingAddress$zipCodeBox"),
1074 string16(),
1075 ASCIIToUTF16("text"),
1076 0,
1077 false));
1078 form.fields.push_back(
1079 webkit_glue::FormField(ASCIIToUTF16("Phone*:"),
1080 ASCIIToUTF16("editBillingAddress$phoneBox"),
1081 string16(),
1082 ASCIIToUTF16("text"),
1083 0,
1084 false));
1085 form.fields.push_back(
1086 webkit_glue::FormField(ASCIIToUTF16("Email Address*:"),
1087 ASCIIToUTF16("email$emailBox"),
1088 string16(),
1089 ASCIIToUTF16("text"),
1090 0,
1091 false));
1092 form_structure.reset(new FormStructure(form)); 924 form_structure.reset(new FormStructure(form));
1093 form_structure->DetermineHeuristicTypes(); 925 form_structure->DetermineHeuristicTypes();
1094 EXPECT_TRUE(form_structure->IsAutofillable(true)); 926 EXPECT_TRUE(form_structure->IsAutofillable(true));
1095 ASSERT_EQ(11U, form_structure->field_count()); 927 ASSERT_EQ(11U, form_structure->field_count());
1096 ASSERT_EQ(11U, form_structure->autofill_count()); 928 ASSERT_EQ(11U, form_structure->autofill_count());
1097 929
1098 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 930 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
1099 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 931 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
1100 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); 932 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type());
1101 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type()); 933 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type());
1102 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type()); 934 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type());
1103 EXPECT_EQ(ADDRESS_BILLING_CITY, form_structure->field(5)->heuristic_type()); 935 EXPECT_EQ(ADDRESS_BILLING_CITY, form_structure->field(5)->heuristic_type());
1104 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure->field(6)->heuristic_type()); 936 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure->field(6)->heuristic_type());
1105 EXPECT_EQ(ADDRESS_BILLING_COUNTRY, 937 EXPECT_EQ(ADDRESS_BILLING_COUNTRY,
1106 form_structure->field(7)->heuristic_type()); 938 form_structure->field(7)->heuristic_type());
1107 EXPECT_EQ(ADDRESS_BILLING_ZIP, form_structure->field(8)->heuristic_type()); 939 EXPECT_EQ(ADDRESS_BILLING_ZIP, form_structure->field(8)->heuristic_type());
1108 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 940 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1109 form_structure->field(9)->heuristic_type()); 941 form_structure->field(9)->heuristic_type());
1110 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type()); 942 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type());
1111 } 943 }
1112 944
1113 TEST(FormStructureTest, ThreePartPhoneNumber) { 945 TEST(FormStructureTest, ThreePartPhoneNumber) {
1114 scoped_ptr<FormStructure> form_structure; 946 scoped_ptr<FormStructure> form_structure;
1115 FormData form; 947 FormData form;
948 form.method = ASCIIToUTF16("post");
1116 949
1117 form.method = ASCIIToUTF16("post"); 950 FormField field;
1118 form.fields.push_back( 951 field.form_control_type = ASCIIToUTF16("text");
1119 webkit_glue::FormField(ASCIIToUTF16("Phone:"), 952
1120 ASCIIToUTF16("dayphone1"), 953 field.label = ASCIIToUTF16("Phone:");
1121 string16(), 954 field.name = ASCIIToUTF16("dayphone1");
1122 ASCIIToUTF16("text"), 955 field.max_length = 0;
1123 0, 956 form.fields.push_back(field);
1124 false)); 957
1125 form.fields.push_back( 958 field.label = ASCIIToUTF16("-");
1126 webkit_glue::FormField(ASCIIToUTF16("-"), 959 field.name = ASCIIToUTF16("dayphone2");
1127 ASCIIToUTF16("dayphone2"), 960 field.max_length = 3; // Size of prefix is 3.
1128 string16(), 961 form.fields.push_back(field);
1129 ASCIIToUTF16("text"), 962
1130 3, // Size of prefix is 3. 963 field.label = ASCIIToUTF16("-");
1131 false)); 964 field.name = ASCIIToUTF16("dayphone3");
1132 form.fields.push_back( 965 field.max_length = 4; // Size of suffix is 4. If unlimited size is
1133 webkit_glue::FormField(ASCIIToUTF16("-"), 966 // passed, phone will be parsed as
1134 ASCIIToUTF16("dayphone3"), 967 // <country code> - <area code> - <phone>.
1135 string16(), 968 form.fields.push_back(field);
1136 ASCIIToUTF16("text"), 969
1137 4, // Size of suffix is 4. If unlimited size is 970 field.label = ASCIIToUTF16("ext.:");
1138 // passed, phone will be parsed as 971 field.name = ASCIIToUTF16("dayphone4");
1139 // <country code> - <area code> - <phone>. 972 field.max_length = 0;
1140 false)); 973 form.fields.push_back(field);
1141 form.fields.push_back( 974
1142 webkit_glue::FormField(ASCIIToUTF16("ext.:"),
1143 ASCIIToUTF16("dayphone4"),
1144 string16(),
1145 ASCIIToUTF16("text"),
1146 0,
1147 false));
1148 form_structure.reset(new FormStructure(form)); 975 form_structure.reset(new FormStructure(form));
1149 form_structure->DetermineHeuristicTypes(); 976 form_structure->DetermineHeuristicTypes();
1150 EXPECT_TRUE(form_structure->IsAutofillable(true)); 977 EXPECT_TRUE(form_structure->IsAutofillable(true));
1151 ASSERT_EQ(4U, form_structure->field_count()); 978 ASSERT_EQ(4U, form_structure->field_count());
1152 ASSERT_EQ(3U, form_structure->autofill_count()); 979 ASSERT_EQ(3U, form_structure->autofill_count());
1153 980
1154 // Area code. 981 // Area code.
1155 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); 982 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type());
1156 // Phone number suffix. 983 // Phone number suffix.
1157 EXPECT_EQ(PHONE_HOME_NUMBER, 984 EXPECT_EQ(PHONE_HOME_NUMBER,
1158 form_structure->field(1)->heuristic_type()); 985 form_structure->field(1)->heuristic_type());
1159 // Phone number suffix. 986 // Phone number suffix.
1160 EXPECT_EQ(PHONE_HOME_NUMBER, 987 EXPECT_EQ(PHONE_HOME_NUMBER,
1161 form_structure->field(2)->heuristic_type()); 988 form_structure->field(2)->heuristic_type());
1162 // Unknown. 989 // Unknown.
1163 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); 990 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type());
1164 } 991 }
1165 992
1166 TEST(FormStructureTest, HeuristicsInfernoCC) { 993 TEST(FormStructureTest, HeuristicsInfernoCC) {
1167 scoped_ptr<FormStructure> form_structure; 994 scoped_ptr<FormStructure> form_structure;
1168 FormData form; 995 FormData form;
1169 form.method = ASCIIToUTF16("post"); 996 form.method = ASCIIToUTF16("post");
1170 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), 997
1171 ASCIIToUTF16("name_on_card"), 998 FormField field;
1172 string16(), 999 field.form_control_type = ASCIIToUTF16("text");
1173 ASCIIToUTF16("text"), 1000
1174 0, 1001 field.label = ASCIIToUTF16("Name on Card");
1175 false)); 1002 field.name = ASCIIToUTF16("name_on_card");
1176 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1003 form.fields.push_back(field);
1177 ASCIIToUTF16("billing_address"), 1004
1178 string16(), 1005 field.label = ASCIIToUTF16("Address");
1179 ASCIIToUTF16("text"), 1006 field.name = ASCIIToUTF16("billing_address");
1180 0, 1007 form.fields.push_back(field);
1181 false)); 1008
1182 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), 1009 field.label = ASCIIToUTF16("Card Number");
1183 ASCIIToUTF16("card_number"), 1010 field.name = ASCIIToUTF16("card_number");
1184 string16(), 1011 form.fields.push_back(field);
1185 ASCIIToUTF16("text"), 1012
1186 0, 1013 field.label = ASCIIToUTF16("Expiration Date");
1187 false)); 1014 field.name = ASCIIToUTF16("expiration_month");
1188 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Date"), 1015 form.fields.push_back(field);
1189 ASCIIToUTF16("expiration_month"), 1016
1190 string16(), 1017 field.label = ASCIIToUTF16("Expiration Year");
1191 ASCIIToUTF16("text"), 1018 field.name = ASCIIToUTF16("expiration_year");
1192 0, 1019 form.fields.push_back(field);
1193 false)); 1020
1194 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Year"),
1195 ASCIIToUTF16("expiration_year"),
1196 string16(),
1197 ASCIIToUTF16("text"),
1198 0,
1199 false));
1200 form_structure.reset(new FormStructure(form)); 1021 form_structure.reset(new FormStructure(form));
1201 form_structure->DetermineHeuristicTypes(); 1022 form_structure->DetermineHeuristicTypes();
1202 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1023 EXPECT_TRUE(form_structure->IsAutofillable(true));
1203 1024
1204 // Expect the correct number of fields. 1025 // Expect the correct number of fields.
1205 ASSERT_EQ(5U, form_structure->field_count()); 1026 ASSERT_EQ(5U, form_structure->field_count());
1206 EXPECT_EQ(5U, form_structure->autofill_count()); 1027 EXPECT_EQ(5U, form_structure->autofill_count());
1207 1028
1208 // Name on Card. 1029 // Name on Card.
1209 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); 1030 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
1210 // Address. 1031 // Address.
1211 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(1)->heuristic_type()); 1032 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(1)->heuristic_type());
1212 // Card Number. 1033 // Card Number.
1213 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); 1034 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type());
1214 // Expiration Date. 1035 // Expiration Date.
1215 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); 1036 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
1216 // Expiration Year. 1037 // Expiration Year.
1217 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1038 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1218 form_structure->field(4)->heuristic_type()); 1039 form_structure->field(4)->heuristic_type());
1219 } 1040 }
1220 1041
1221 TEST(FormStructureTest, CVCCodeClash) { 1042 TEST(FormStructureTest, CVCCodeClash) {
1222 scoped_ptr<FormStructure> form_structure; 1043 scoped_ptr<FormStructure> form_structure;
1223 FormData form; 1044 FormData form;
1224 form.method = ASCIIToUTF16("post"); 1045 form.method = ASCIIToUTF16("post");
1225 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card number"), 1046
1226 ASCIIToUTF16("ccnumber"), 1047 FormField field;
1227 string16(), 1048 field.form_control_type = ASCIIToUTF16("text");
1228 ASCIIToUTF16("text"), 1049
1229 0, 1050 field.label = ASCIIToUTF16("Card number");
1230 false)); 1051 field.name = ASCIIToUTF16("ccnumber");
1231 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First name"), 1052 form.fields.push_back(field);
1232 ASCIIToUTF16("first_name"), 1053
1233 string16(), 1054 field.label = ASCIIToUTF16("First name");
1234 ASCIIToUTF16("text"), 1055 field.name = ASCIIToUTF16("first_name");
1235 0, 1056 form.fields.push_back(field);
1236 false)); 1057
1237 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last name"), 1058 field.label = ASCIIToUTF16("Last name");
1238 ASCIIToUTF16("last_name"), 1059 field.name = ASCIIToUTF16("last_name");
1239 string16(), 1060 form.fields.push_back(field);
1240 ASCIIToUTF16("text"), 1061
1241 0, 1062 field.label = ASCIIToUTF16("Expiration date");
1242 false)); 1063 field.name = ASCIIToUTF16("ccexpiresmonth");
1243 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration date"), 1064 form.fields.push_back(field);
1244 ASCIIToUTF16("ccexpiresmonth"), 1065
1245 string16(), 1066 field.label = string16();
1246 ASCIIToUTF16("text"), 1067 field.name = ASCIIToUTF16("ccexpiresyear");
1247 0, 1068 form.fields.push_back(field);
1248 false)); 1069
1249 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16(""), 1070 field.label = ASCIIToUTF16("cvc number");
1250 ASCIIToUTF16("ccexpiresyear"), 1071 field.name = ASCIIToUTF16("csc");
1251 string16(), 1072 form.fields.push_back(field);
1252 ASCIIToUTF16("text"), 1073
1253 0,
1254 false));
1255 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("cvc number"),
1256 ASCIIToUTF16("csc"),
1257 string16(),
1258 ASCIIToUTF16("text"),
1259 0,
1260 false));
1261 form_structure.reset(new FormStructure(form)); 1074 form_structure.reset(new FormStructure(form));
1262 form_structure->DetermineHeuristicTypes(); 1075 form_structure->DetermineHeuristicTypes();
1263 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1076 EXPECT_TRUE(form_structure->IsAutofillable(true));
1264 1077
1265 // Expect the correct number of fields. 1078 // Expect the correct number of fields.
1266 ASSERT_EQ(6U, form_structure->field_count()); 1079 ASSERT_EQ(6U, form_structure->field_count());
1267 ASSERT_EQ(4U, form_structure->autofill_count()); 1080 ASSERT_EQ(4U, form_structure->autofill_count());
1268 1081
1269 // Card Number. 1082 // Card Number.
1270 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); 1083 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type());
1271 // First name, taken as name on card. 1084 // First name, taken as name on card.
1272 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(1)->heuristic_type()); 1085 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(1)->heuristic_type());
1273 // Last name is not merged. 1086 // Last name is not merged.
1274 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 1087 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
1275 // Expiration Date. 1088 // Expiration Date.
1276 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); 1089 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
1277 // Expiration Year. 1090 // Expiration Year.
1278 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1091 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1279 form_structure->field(4)->heuristic_type()); 1092 form_structure->field(4)->heuristic_type());
1280 // CVC code should not match. 1093 // CVC code should not match.
1281 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 1094 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
1282 } 1095 }
1283 1096
1284 TEST(FormStructureTest, EncodeQueryRequest) { 1097 TEST(FormStructureTest, EncodeQueryRequest) {
1285 FormData form; 1098 FormData form;
1286 form.method = ASCIIToUTF16("post"); 1099 form.method = ASCIIToUTF16("post");
1287 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), 1100
1288 ASCIIToUTF16("name_on_card"), 1101 FormField field;
1289 string16(), 1102 field.form_control_type = ASCIIToUTF16("text");
1290 ASCIIToUTF16("text"), 1103
1291 0, 1104 field.label = ASCIIToUTF16("Name on Card");
1292 false)); 1105 field.name = ASCIIToUTF16("name_on_card");
1293 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1106 form.fields.push_back(field);
1294 ASCIIToUTF16("billing_address"), 1107
1295 string16(), 1108 field.label = ASCIIToUTF16("Address");
1296 ASCIIToUTF16("text"), 1109 field.name = ASCIIToUTF16("billing_address");
1297 0, 1110 form.fields.push_back(field);
1298 false)); 1111
1299 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), 1112 field.label = ASCIIToUTF16("Card Number");
1300 ASCIIToUTF16("card_number"), 1113 field.name = ASCIIToUTF16("card_number");
1301 string16(), 1114 form.fields.push_back(field);
1302 ASCIIToUTF16("text"), 1115
1303 0, 1116 field.label = ASCIIToUTF16("Expiration Date");
1304 false)); 1117 field.name = ASCIIToUTF16("expiration_month");
1305 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Date"), 1118 form.fields.push_back(field);
1306 ASCIIToUTF16("expiration_month"), 1119
1307 string16(), 1120 field.label = ASCIIToUTF16("Expiration Year");
1308 ASCIIToUTF16("text"), 1121 field.name = ASCIIToUTF16("expiration_year");
1309 0, 1122 form.fields.push_back(field);
1310 false)); 1123
1311 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Year"),
1312 ASCIIToUTF16("expiration_year"),
1313 string16(),
1314 ASCIIToUTF16("text"),
1315 0,
1316 false));
1317 ScopedVector<FormStructure> forms; 1124 ScopedVector<FormStructure> forms;
1318 forms.push_back(new FormStructure(form)); 1125 forms.push_back(new FormStructure(form));
1319 std::vector<std::string> encoded_signatures; 1126 std::vector<std::string> encoded_signatures;
1320 std::string encoded_xml; 1127 std::string encoded_xml;
1321 const char * const kSignature1 = "11337937696949187602"; 1128 const char * const kSignature1 = "11337937696949187602";
1322 const char * const kResponse1 = 1129 const char * const kResponse1 =
1323 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " 1130 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery "
1324 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " 1131 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form "
1325 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" 1132 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>"
1326 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" 1133 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>"
1327 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" 1134 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>"
1328 "</autofillquery>"; 1135 "</autofillquery>";
1329 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures, 1136 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
1330 &encoded_xml)); 1137 &encoded_xml));
1331 ASSERT_EQ(1U, encoded_signatures.size()); 1138 ASSERT_EQ(1U, encoded_signatures.size());
1332 EXPECT_EQ(kSignature1, encoded_signatures[0]); 1139 EXPECT_EQ(kSignature1, encoded_signatures[0]);
1333 EXPECT_EQ(kResponse1, encoded_xml); 1140 EXPECT_EQ(kResponse1, encoded_xml);
1334 1141
1335 // Add the same form, only one will be encoded, so EncodeQueryRequest() should 1142 // Add the same form, only one will be encoded, so EncodeQueryRequest() should
1336 // return the same data. 1143 // return the same data.
1337 forms.push_back(new FormStructure(form)); 1144 forms.push_back(new FormStructure(form));
1338 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures, 1145 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
1339 &encoded_xml)); 1146 &encoded_xml));
1340 ASSERT_EQ(1U, encoded_signatures.size()); 1147 ASSERT_EQ(1U, encoded_signatures.size());
1341 EXPECT_EQ(kSignature1, encoded_signatures[0]); 1148 EXPECT_EQ(kSignature1, encoded_signatures[0]);
1342 EXPECT_EQ(kResponse1, encoded_xml); 1149 EXPECT_EQ(kResponse1, encoded_xml);
1343 // Add 5 address fields - this should be still a valid form. 1150 // Add 5 address fields - this should be still a valid form.
1344 for (size_t i = 0; i < 5; ++i) { 1151 for (size_t i = 0; i < 5; ++i) {
1345 form.fields.push_back( 1152 field.label = ASCIIToUTF16("Address");
1346 webkit_glue::FormField(ASCIIToUTF16("Address"), 1153 field.name = ASCIIToUTF16("address");
1347 ASCIIToUTF16("address"), 1154 form.fields.push_back(field);
1348 string16(),
1349 ASCIIToUTF16("text"),
1350 0,
1351 false));
1352 } 1155 }
1353 1156
1354 forms.push_back(new FormStructure(form)); 1157 forms.push_back(new FormStructure(form));
1355 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures, 1158 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
1356 &encoded_xml)); 1159 &encoded_xml));
1357 ASSERT_EQ(2U, encoded_signatures.size()); 1160 ASSERT_EQ(2U, encoded_signatures.size());
1358 EXPECT_EQ(kSignature1, encoded_signatures[0]); 1161 EXPECT_EQ(kSignature1, encoded_signatures[0]);
1359 const char * const kSignature2 = "8308881815906226214"; 1162 const char * const kSignature2 = "8308881815906226214";
1360 EXPECT_EQ(kSignature2, encoded_signatures[1]); 1163 EXPECT_EQ(kSignature2, encoded_signatures[1]);
1361 const char * const kResponse2 = 1164 const char * const kResponse2 =
1362 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " 1165 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery "
1363 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " 1166 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form "
1364 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" 1167 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>"
1365 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" 1168 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>"
1366 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" 1169 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>"
1367 "<form signature=\"8308881815906226214\"><field signature=\"412125936\"/>" 1170 "<form signature=\"8308881815906226214\"><field signature=\"412125936\"/>"
1368 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" 1171 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>"
1369 "<field signature=\"747221617\"/><field signature=\"4108155786\"/><field " 1172 "<field signature=\"747221617\"/><field signature=\"4108155786\"/><field "
1370 "signature=\"509334676\"/><field signature=\"509334676\"/><field " 1173 "signature=\"509334676\"/><field signature=\"509334676\"/><field "
1371 "signature=\"509334676\"/><field signature=\"509334676\"/><field " 1174 "signature=\"509334676\"/><field signature=\"509334676\"/><field "
1372 "signature=\"509334676\"/></form></autofillquery>"; 1175 "signature=\"509334676\"/></form></autofillquery>";
1373 EXPECT_EQ(kResponse2, encoded_xml); 1176 EXPECT_EQ(kResponse2, encoded_xml);
1374 1177
1375 // Add 50 address fields - the form is not valid anymore, but previous ones 1178 // Add 50 address fields - the form is not valid anymore, but previous ones
1376 // are. The result should be the same as in previous test. 1179 // are. The result should be the same as in previous test.
1377 for (size_t i = 0; i < 50; ++i) { 1180 for (size_t i = 0; i < 50; ++i) {
1378 form.fields.push_back( 1181 field.label = ASCIIToUTF16("Address");
1379 webkit_glue::FormField(ASCIIToUTF16("Address"), 1182 field.name = ASCIIToUTF16("address");
1380 ASCIIToUTF16("address"), 1183 form.fields.push_back(field);
1381 string16(),
1382 ASCIIToUTF16("text"),
1383 0,
1384 false));
1385 } 1184 }
1386 1185
1387 forms.push_back(new FormStructure(form)); 1186 forms.push_back(new FormStructure(form));
1388 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures, 1187 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
1389 &encoded_xml)); 1188 &encoded_xml));
1390 ASSERT_EQ(2U, encoded_signatures.size()); 1189 ASSERT_EQ(2U, encoded_signatures.size());
1391 EXPECT_EQ(kSignature1, encoded_signatures[0]); 1190 EXPECT_EQ(kSignature1, encoded_signatures[0]);
1392 EXPECT_EQ(kSignature2, encoded_signatures[1]); 1191 EXPECT_EQ(kSignature2, encoded_signatures[1]);
1393 EXPECT_EQ(kResponse2, encoded_xml); 1192 EXPECT_EQ(kResponse2, encoded_xml);
1394 1193
1395 // Check that we fail if there are only bad form(s). 1194 // Check that we fail if there are only bad form(s).
1396 ScopedVector<FormStructure> bad_forms; 1195 ScopedVector<FormStructure> bad_forms;
1397 bad_forms.push_back(new FormStructure(form)); 1196 bad_forms.push_back(new FormStructure(form));
1398 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms, &encoded_signatures, 1197 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms, &encoded_signatures,
1399 &encoded_xml)); 1198 &encoded_xml));
1400 EXPECT_EQ(0U, encoded_signatures.size()); 1199 EXPECT_EQ(0U, encoded_signatures.size());
1401 EXPECT_EQ("", encoded_xml); 1200 EXPECT_EQ("", encoded_xml);
1402 } 1201 }
1403 1202
1404 TEST(FormStructureTest, EncodeUploadRequest) { 1203 TEST(FormStructureTest, EncodeUploadRequest) {
1405 scoped_ptr<FormStructure> form_structure; 1204 scoped_ptr<FormStructure> form_structure;
1406 std::vector<FieldTypeSet> possible_field_types; 1205 std::vector<FieldTypeSet> possible_field_types;
1407 FormData form; 1206 FormData form;
1408 form.method = ASCIIToUTF16("post"); 1207 form.method = ASCIIToUTF16("post");
1409 form_structure.reset(new FormStructure(form)); 1208 form_structure.reset(new FormStructure(form));
1410 form_structure->DetermineHeuristicTypes(); 1209 form_structure->DetermineHeuristicTypes();
1411 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 1210
1412 ASCIIToUTF16("firstname"), 1211 FormField field;
1413 string16(), 1212 field.form_control_type = ASCIIToUTF16("text");
1414 ASCIIToUTF16("text"), 1213
1415 0, 1214 field.label = ASCIIToUTF16("First Name");
1416 false)); 1215 field.name = ASCIIToUTF16("firstname");
1216 form.fields.push_back(field);
1417 possible_field_types.push_back(FieldTypeSet()); 1217 possible_field_types.push_back(FieldTypeSet());
1418 possible_field_types.back().insert(NAME_FIRST); 1218 possible_field_types.back().insert(NAME_FIRST);
1419 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 1219
1420 ASCIIToUTF16("lastname"), 1220 field.label = ASCIIToUTF16("Last Name");
1421 string16(), 1221 field.name = ASCIIToUTF16("lastname");
1422 ASCIIToUTF16("text"), 1222 form.fields.push_back(field);
1423 0,
1424 false));
1425 possible_field_types.push_back(FieldTypeSet()); 1223 possible_field_types.push_back(FieldTypeSet());
1426 possible_field_types.back().insert(NAME_LAST); 1224 possible_field_types.back().insert(NAME_LAST);
1427 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), 1225
1428 ASCIIToUTF16("email"), 1226 field.label = ASCIIToUTF16("Email");
1429 string16(), 1227 field.name = ASCIIToUTF16("email");
1430 ASCIIToUTF16("email"), 1228 field.form_control_type = ASCIIToUTF16("email");
1431 0, 1229 form.fields.push_back(field);
1432 false));
1433 possible_field_types.push_back(FieldTypeSet()); 1230 possible_field_types.push_back(FieldTypeSet());
1434 possible_field_types.back().insert(EMAIL_ADDRESS); 1231 possible_field_types.back().insert(EMAIL_ADDRESS);
1435 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), 1232
1436 ASCIIToUTF16("phone"), 1233 field.label = ASCIIToUTF16("Phone");
1437 string16(), 1234 field.name = ASCIIToUTF16("phone");
1438 ASCIIToUTF16("number"), 1235 field.form_control_type = ASCIIToUTF16("number");
1439 0, 1236 form.fields.push_back(field);
1440 false));
1441 possible_field_types.push_back(FieldTypeSet()); 1237 possible_field_types.push_back(FieldTypeSet());
1442 possible_field_types.back().insert(PHONE_HOME_WHOLE_NUMBER); 1238 possible_field_types.back().insert(PHONE_HOME_WHOLE_NUMBER);
1443 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Country"), 1239
1444 ASCIIToUTF16("country"), 1240 field.label = ASCIIToUTF16("Country");
1445 string16(), 1241 field.name = ASCIIToUTF16("country");
1446 ASCIIToUTF16("select-one"), 1242 field.form_control_type = ASCIIToUTF16("select-one");
1447 0, 1243 form.fields.push_back(field);
1448 false));
1449 possible_field_types.push_back(FieldTypeSet()); 1244 possible_field_types.push_back(FieldTypeSet());
1450 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); 1245 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY);
1451 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), 1246
1452 ASCIIToUTF16("fax"), 1247 field.label = ASCIIToUTF16("Fax");
1453 string16(), 1248 field.name = ASCIIToUTF16("fax");
1454 ASCIIToUTF16("tel"), 1249 field.form_control_type = ASCIIToUTF16("tel");
1455 0, 1250 form.fields.push_back(field);
1456 false));
1457 possible_field_types.push_back(FieldTypeSet()); 1251 possible_field_types.push_back(FieldTypeSet());
1458 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER); 1252 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER);
1459 form_structure.reset(new FormStructure(form)); 1253 form_structure.reset(new FormStructure(form));
1460 1254
1461 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1255 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1462 for (size_t i = 0; i < form_structure->field_count(); ++i) 1256 for (size_t i = 0; i < form_structure->field_count(); ++i)
1463 form_structure->set_possible_types(i, possible_field_types[i]); 1257 form_structure->set_possible_types(i, possible_field_types[i]);
1464 1258
1465 FieldTypeSet available_field_types; 1259 FieldTypeSet available_field_types;
1466 available_field_types.insert(NAME_FIRST); 1260 available_field_types.insert(NAME_FIRST);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 "<field signature=\"3494530716\" autofilltype=\"5\"/>" 1293 "<field signature=\"3494530716\" autofilltype=\"5\"/>"
1500 "<field signature=\"1029417091\" autofilltype=\"9\"/>" 1294 "<field signature=\"1029417091\" autofilltype=\"9\"/>"
1501 "<field signature=\"466116101\" autofilltype=\"14\"/>" 1295 "<field signature=\"466116101\" autofilltype=\"14\"/>"
1502 "<field signature=\"2799270304\" autofilltype=\"36\"/>" 1296 "<field signature=\"2799270304\" autofilltype=\"36\"/>"
1503 "<field signature=\"1876771436\" autofilltype=\"24\"/>" 1297 "<field signature=\"1876771436\" autofilltype=\"24\"/>"
1504 "</autofillupload>", 1298 "</autofillupload>",
1505 encoded_xml); 1299 encoded_xml);
1506 1300
1507 // Add 2 address fields - this should be still a valid form. 1301 // Add 2 address fields - this should be still a valid form.
1508 for (size_t i = 0; i < 2; ++i) { 1302 for (size_t i = 0; i < 2; ++i) {
1509 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1303 field.label = ASCIIToUTF16("Address");
1510 ASCIIToUTF16("address"), 1304 field.name = ASCIIToUTF16("address");
1511 string16(), 1305 field.form_control_type = ASCIIToUTF16("text");
1512 ASCIIToUTF16("text"), 1306 form.fields.push_back(field);
1513 0,
1514 false));
1515 possible_field_types.push_back(FieldTypeSet()); 1307 possible_field_types.push_back(FieldTypeSet());
1516 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1308 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1517 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1309 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1518 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1310 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1519 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1311 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1520 } 1312 }
1521 1313
1522 form_structure.reset(new FormStructure(form)); 1314 form_structure.reset(new FormStructure(form));
1523 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1315 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1524 for (size_t i = 0; i < form_structure->field_count(); ++i) 1316 for (size_t i = 0; i < form_structure->field_count(); ++i)
(...skipping 17 matching lines...) Expand all
1542 "<field signature=\"509334676\" autofilltype=\"38\"/>" 1334 "<field signature=\"509334676\" autofilltype=\"38\"/>"
1543 "<field signature=\"509334676\" autofilltype=\"30\"/>" 1335 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1544 "<field signature=\"509334676\" autofilltype=\"31\"/>" 1336 "<field signature=\"509334676\" autofilltype=\"31\"/>"
1545 "<field signature=\"509334676\" autofilltype=\"37\"/>" 1337 "<field signature=\"509334676\" autofilltype=\"37\"/>"
1546 "<field signature=\"509334676\" autofilltype=\"38\"/>" 1338 "<field signature=\"509334676\" autofilltype=\"38\"/>"
1547 "</autofillupload>", 1339 "</autofillupload>",
1548 encoded_xml); 1340 encoded_xml);
1549 1341
1550 // Add 50 address fields - now the form is invalid, as it has too many fields. 1342 // Add 50 address fields - now the form is invalid, as it has too many fields.
1551 for (size_t i = 0; i < 50; ++i) { 1343 for (size_t i = 0; i < 50; ++i) {
1552 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1344 field.label = ASCIIToUTF16("Address");
1553 ASCIIToUTF16("address"), 1345 field.name = ASCIIToUTF16("address");
1554 string16(), 1346 field.form_control_type = ASCIIToUTF16("text");
1555 ASCIIToUTF16("text"), 1347 form.fields.push_back(field);
1556 0,
1557 false));
1558 possible_field_types.push_back(FieldTypeSet()); 1348 possible_field_types.push_back(FieldTypeSet());
1559 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1349 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1560 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1350 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1561 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1351 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1562 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1352 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1563 } 1353 }
1564 form_structure.reset(new FormStructure(form)); 1354 form_structure.reset(new FormStructure(form));
1565 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1355 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1566 for (size_t i = 0; i < form_structure->field_count(); ++i) 1356 for (size_t i = 0; i < form_structure->field_count(); ++i)
1567 form_structure->set_possible_types(i, possible_field_types[i]); 1357 form_structure->set_possible_types(i, possible_field_types[i]);
1568 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, 1358 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false,
1569 &encoded_xml)); 1359 &encoded_xml));
1570 } 1360 }
1571 1361
1572 // Check that we compute the "datapresent" string correctly for the given 1362 // Check that we compute the "datapresent" string correctly for the given
1573 // |available_types|. 1363 // |available_types|.
1574 TEST(FormStructureTest, CheckDataPresence) { 1364 TEST(FormStructureTest, CheckDataPresence) {
1575 FormData form; 1365 FormData form;
1576 form.method = ASCIIToUTF16("post"); 1366 form.method = ASCIIToUTF16("post");
1577 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 1367
1578 ASCIIToUTF16("first"), 1368 FormField field;
1579 string16(), 1369 field.form_control_type = ASCIIToUTF16("text");
1580 ASCIIToUTF16("text"), 1370
1581 0, 1371 field.label = ASCIIToUTF16("First Name");
1582 false)); 1372 field.name = ASCIIToUTF16("first");
1583 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 1373 form.fields.push_back(field);
1584 ASCIIToUTF16("last"), 1374
1585 string16(), 1375 field.label = ASCIIToUTF16("Last Name");
1586 ASCIIToUTF16("text"), 1376 field.name = ASCIIToUTF16("last");
1587 0, 1377 form.fields.push_back(field);
1588 false)); 1378
1589 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 1379 field.label = ASCIIToUTF16("Email");
1590 ASCIIToUTF16("email"), 1380 field.name = ASCIIToUTF16("email");
1591 string16(), 1381 form.fields.push_back(field);
1592 ASCIIToUTF16("text"),
1593 0,
1594 false));
1595 1382
1596 FormStructure form_structure(form); 1383 FormStructure form_structure(form);
1597 1384
1598 FieldTypeSet unknown_type; 1385 FieldTypeSet unknown_type;
1599 unknown_type.insert(UNKNOWN_TYPE); 1386 unknown_type.insert(UNKNOWN_TYPE);
1600 for (size_t i = 0; i < form_structure.field_count(); ++i) 1387 for (size_t i = 0; i < form_structure.field_count(); ++i)
1601 form_structure.set_possible_types(i, unknown_type); 1388 form_structure.set_possible_types(i, unknown_type);
1602 1389
1603 // No available types. 1390 // No available types.
1604 // datapresent should be "" == trimmmed(0x0000000000000000) == 1391 // datapresent should be "" == trimmmed(0x0000000000000000) ==
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 available_field_types.insert(ADDRESS_HOME_LINE2); 1631 available_field_types.insert(ADDRESS_HOME_LINE2);
1845 available_field_types.insert(ADDRESS_HOME_CITY); 1632 available_field_types.insert(ADDRESS_HOME_CITY);
1846 available_field_types.insert(ADDRESS_HOME_STATE); 1633 available_field_types.insert(ADDRESS_HOME_STATE);
1847 available_field_types.insert(COMPANY_NAME); 1634 available_field_types.insert(COMPANY_NAME);
1848 1635
1849 // Check that multiple types for the field are processed correctly. 1636 // Check that multiple types for the field are processed correctly.
1850 scoped_ptr<FormStructure> form_structure; 1637 scoped_ptr<FormStructure> form_structure;
1851 std::vector<FieldTypeSet> possible_field_types; 1638 std::vector<FieldTypeSet> possible_field_types;
1852 FormData form; 1639 FormData form;
1853 form.method = ASCIIToUTF16("post"); 1640 form.method = ASCIIToUTF16("post");
1854 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 1641
1855 ASCIIToUTF16("email"), 1642 FormField field;
1856 string16(), 1643 field.form_control_type = ASCIIToUTF16("text");
1857 ASCIIToUTF16("text"), 1644
1858 0, 1645 field.label = ASCIIToUTF16("email");
1859 false)); 1646 field.name = ASCIIToUTF16("email");
1647 form.fields.push_back(field);
1860 possible_field_types.push_back(FieldTypeSet()); 1648 possible_field_types.push_back(FieldTypeSet());
1861 possible_field_types.back().insert(EMAIL_ADDRESS); 1649 possible_field_types.back().insert(EMAIL_ADDRESS);
1862 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 1650
1863 ASCIIToUTF16("first"), 1651 field.label = ASCIIToUTF16("First Name");
1864 string16(), 1652 field.name = ASCIIToUTF16("first");
1865 ASCIIToUTF16("text"), 1653 form.fields.push_back(field);
1866 0,
1867 false));
1868 possible_field_types.push_back(FieldTypeSet()); 1654 possible_field_types.push_back(FieldTypeSet());
1869 possible_field_types.back().insert(NAME_FIRST); 1655 possible_field_types.back().insert(NAME_FIRST);
1870 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 1656
1871 ASCIIToUTF16("last"), 1657 field.label = ASCIIToUTF16("Last Name");
1872 string16(), 1658 field.name = ASCIIToUTF16("last");
1873 ASCIIToUTF16("text"), 1659 form.fields.push_back(field);
1874 0,
1875 false));
1876 possible_field_types.push_back(FieldTypeSet()); 1660 possible_field_types.push_back(FieldTypeSet());
1877 possible_field_types.back().insert(NAME_LAST); 1661 possible_field_types.back().insert(NAME_LAST);
1878 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1662
1879 ASCIIToUTF16("address"), 1663 field.label = ASCIIToUTF16("Address");
1880 string16(), 1664 field.name = ASCIIToUTF16("address");
1881 ASCIIToUTF16("text"), 1665 form.fields.push_back(field);
1882 0,
1883 false));
1884 possible_field_types.push_back(FieldTypeSet()); 1666 possible_field_types.push_back(FieldTypeSet());
1885 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1667 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1668
1886 form_structure.reset(new FormStructure(form)); 1669 form_structure.reset(new FormStructure(form));
1887 1670
1888 for (size_t i = 0; i < form_structure->field_count(); ++i) 1671 for (size_t i = 0; i < form_structure->field_count(); ++i)
1889 form_structure->set_possible_types(i, possible_field_types[i]); 1672 form_structure->set_possible_types(i, possible_field_types[i]);
1890 std::string encoded_xml; 1673 std::string encoded_xml;
1891 1674
1892 // Now we matched both fields singularly. 1675 // Now we matched both fields singularly.
1893 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1676 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1894 &encoded_xml)); 1677 &encoded_xml));
1895 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1678 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 "<field signature=\"509334676\" autofilltype=\"60\"/>" 1739 "<field signature=\"509334676\" autofilltype=\"60\"/>"
1957 "</autofillupload>", 1740 "</autofillupload>",
1958 encoded_xml); 1741 encoded_xml);
1959 } 1742 }
1960 1743
1961 TEST(FormStructureTest, CheckFormSignature) { 1744 TEST(FormStructureTest, CheckFormSignature) {
1962 // Check that form signature is created correctly. 1745 // Check that form signature is created correctly.
1963 scoped_ptr<FormStructure> form_structure; 1746 scoped_ptr<FormStructure> form_structure;
1964 FormData form; 1747 FormData form;
1965 form.method = ASCIIToUTF16("post"); 1748 form.method = ASCIIToUTF16("post");
1966 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 1749
1967 ASCIIToUTF16("email"), 1750 FormField field;
1968 string16(), 1751 field.form_control_type = ASCIIToUTF16("text");
1969 ASCIIToUTF16("text"), 1752
1970 0, 1753 field.label = ASCIIToUTF16("email");
1971 false)); 1754 field.name = ASCIIToUTF16("email");
1972 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 1755 form.fields.push_back(field);
1973 ASCIIToUTF16("first"), 1756
1974 string16(), 1757 field.label = ASCIIToUTF16("First Name");
1975 ASCIIToUTF16("text"), 1758 field.name = ASCIIToUTF16("first");
1976 0, 1759 form.fields.push_back(field);
1977 false)); 1760
1978 form_structure.reset(new FormStructure(form)); 1761 form_structure.reset(new FormStructure(form));
1979 1762
1980 EXPECT_EQ(FormStructureTest::Hash64Bit( 1763 EXPECT_EQ(FormStructureTest::Hash64Bit(
1981 std::string("://&&email&first")), 1764 std::string("://&&email&first")),
1982 form_structure->FormSignature()); 1765 form_structure->FormSignature());
1983 1766
1984 form.origin = GURL(std::string("http://www.facebook.com")); 1767 form.origin = GURL(std::string("http://www.facebook.com"));
1985 form_structure.reset(new FormStructure(form)); 1768 form_structure.reset(new FormStructure(form));
1986 EXPECT_EQ(FormStructureTest::Hash64Bit( 1769 EXPECT_EQ(FormStructureTest::Hash64Bit(
1987 std::string("http://www.facebook.com&&email&first")), 1770 std::string("http://www.facebook.com&&email&first")),
1988 form_structure->FormSignature()); 1771 form_structure->FormSignature());
1989 1772
1990 form.action = GURL(std::string("https://login.facebook.com/path")); 1773 form.action = GURL(std::string("https://login.facebook.com/path"));
1991 form_structure.reset(new FormStructure(form)); 1774 form_structure.reset(new FormStructure(form));
1992 EXPECT_EQ(FormStructureTest::Hash64Bit( 1775 EXPECT_EQ(FormStructureTest::Hash64Bit(
1993 std::string("https://login.facebook.com&&email&first")), 1776 std::string("https://login.facebook.com&&email&first")),
1994 form_structure->FormSignature()); 1777 form_structure->FormSignature());
1995 1778
1996 form.name = ASCIIToUTF16("login_form"); 1779 form.name = ASCIIToUTF16("login_form");
1997 form_structure.reset(new FormStructure(form)); 1780 form_structure.reset(new FormStructure(form));
1998 EXPECT_EQ(FormStructureTest::Hash64Bit( 1781 EXPECT_EQ(FormStructureTest::Hash64Bit(
1999 std::string("https://login.facebook.com&login_form&email&first")), 1782 std::string("https://login.facebook.com&login_form&email&first")),
2000 form_structure->FormSignature()); 1783 form_structure->FormSignature());
2001 } 1784 }
2002 1785
2003 } // namespace 1786 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/autofill/credit_card_field_unittest.cc ('k') | chrome/browser/autofill/name_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698