| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/form_structure.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autofill/autofill_metrics.h" | 10 #include "chrome/browser/autofill/autofill_metrics.h" |
| 12 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/form_data.h" | 12 #include "chrome/common/form_data.h" |
| 14 #include "chrome/common/form_field_data.h" | 13 #include "chrome/common/form_field_data.h" |
| 15 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 field.label = ASCIIToUTF16("password"); | 82 field.label = ASCIIToUTF16("password"); |
| 84 field.name = ASCIIToUTF16("password"); | 83 field.name = ASCIIToUTF16("password"); |
| 85 field.form_control_type = "password"; | 84 field.form_control_type = "password"; |
| 86 form.fields.push_back(field); | 85 form.fields.push_back(field); |
| 87 | 86 |
| 88 field.label = string16(); | 87 field.label = string16(); |
| 89 field.name = ASCIIToUTF16("Submit"); | 88 field.name = ASCIIToUTF16("Submit"); |
| 90 field.form_control_type = "submit"; | 89 field.form_control_type = "submit"; |
| 91 form.fields.push_back(field); | 90 form.fields.push_back(field); |
| 92 | 91 |
| 93 FormStructure form_structure(form); | 92 FormStructure form_structure(form, false); |
| 94 | 93 |
| 95 // All fields are counted. | 94 // All fields are counted. |
| 96 EXPECT_EQ(3U, form_structure.field_count()); | 95 EXPECT_EQ(3U, form_structure.field_count()); |
| 97 } | 96 } |
| 98 | 97 |
| 99 TEST(FormStructureTest, AutofillFlowInfo) { | 98 TEST(FormStructureTest, AutofillFlowInfo) { |
| 100 FormData form; | 99 FormData form; |
| 101 form.method = ASCIIToUTF16("post"); | 100 form.method = ASCIIToUTF16("post"); |
| 102 | 101 |
| 103 FormFieldData field; | 102 FormFieldData field; |
| 104 field.label = ASCIIToUTF16("username"); | 103 field.label = ASCIIToUTF16("username"); |
| 105 field.name = ASCIIToUTF16("username"); | 104 field.name = ASCIIToUTF16("username"); |
| 106 field.form_control_type = "text"; | 105 field.form_control_type = "text"; |
| 107 form.fields.push_back(field); | 106 form.fields.push_back(field); |
| 108 | 107 |
| 109 FormStructure form_structure(form); | 108 FormStructure form_structure(form, false); |
| 110 EXPECT_FALSE(form_structure.IsStartOfAutofillableFlow()); | 109 EXPECT_FALSE(form_structure.IsStartOfAutofillableFlow()); |
| 111 EXPECT_FALSE(form_structure.IsInAutofillableFlow()); | 110 EXPECT_FALSE(form_structure.IsInAutofillableFlow()); |
| 112 | 111 |
| 113 FormStructureTest::SetPageDetails(&form_structure, -1, 0); | 112 FormStructureTest::SetPageDetails(&form_structure, -1, 0); |
| 114 EXPECT_FALSE(form_structure.IsStartOfAutofillableFlow()); | 113 EXPECT_FALSE(form_structure.IsStartOfAutofillableFlow()); |
| 115 EXPECT_FALSE(form_structure.IsInAutofillableFlow()); | 114 EXPECT_FALSE(form_structure.IsInAutofillableFlow()); |
| 116 | 115 |
| 117 FormStructureTest::SetPageDetails(&form_structure, 0, 0); | 116 FormStructureTest::SetPageDetails(&form_structure, 0, 0); |
| 118 EXPECT_FALSE(form_structure.IsStartOfAutofillableFlow()); | 117 EXPECT_FALSE(form_structure.IsStartOfAutofillableFlow()); |
| 119 EXPECT_FALSE(form_structure.IsInAutofillableFlow()); | 118 EXPECT_FALSE(form_structure.IsInAutofillableFlow()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 149 field.label = ASCIIToUTF16("state"); | 148 field.label = ASCIIToUTF16("state"); |
| 150 field.name = ASCIIToUTF16("state"); | 149 field.name = ASCIIToUTF16("state"); |
| 151 field.form_control_type = "select-one"; | 150 field.form_control_type = "select-one"; |
| 152 form.fields.push_back(field); | 151 form.fields.push_back(field); |
| 153 | 152 |
| 154 field.label = string16(); | 153 field.label = string16(); |
| 155 field.name = ASCIIToUTF16("Submit"); | 154 field.name = ASCIIToUTF16("Submit"); |
| 156 field.form_control_type = "submit"; | 155 field.form_control_type = "submit"; |
| 157 form.fields.push_back(field); | 156 form.fields.push_back(field); |
| 158 | 157 |
| 159 FormStructure form_structure(form); | 158 FormStructure form_structure(form, false); |
| 160 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 159 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 161 | 160 |
| 162 // Only text and select fields that are heuristically matched are counted. | 161 // Only text and select fields that are heuristically matched are counted. |
| 163 EXPECT_EQ(1U, form_structure.autofill_count()); | 162 EXPECT_EQ(1U, form_structure.autofill_count()); |
| 164 } | 163 } |
| 165 | 164 |
| 166 TEST(FormStructureTest, SourceURL) { | 165 TEST(FormStructureTest, SourceURL) { |
| 167 FormData form; | 166 FormData form; |
| 168 form.origin = GURL("http://www.foo.com/"); | 167 form.origin = GURL("http://www.foo.com/"); |
| 169 form.method = ASCIIToUTF16("post"); | 168 form.method = ASCIIToUTF16("post"); |
| 170 FormStructure form_structure(form); | 169 FormStructure form_structure(form, false); |
| 171 | 170 |
| 172 EXPECT_EQ(form.origin, form_structure.source_url()); | 171 EXPECT_EQ(form.origin, form_structure.source_url()); |
| 173 } | 172 } |
| 174 | 173 |
| 175 TEST(FormStructureTest, IsAutofillable) { | 174 TEST(FormStructureTest, IsAutofillable) { |
| 176 scoped_ptr<FormStructure> form_structure; | 175 scoped_ptr<FormStructure> form_structure; |
| 177 FormData form; | 176 FormData form; |
| 178 | 177 |
| 179 // We need at least three text fields to be auto-fillable. | 178 // We need at least three text fields to be auto-fillable. |
| 180 form.method = ASCIIToUTF16("post"); | 179 form.method = ASCIIToUTF16("post"); |
| 181 | 180 |
| 182 FormFieldData field; | 181 FormFieldData field; |
| 183 field.label = ASCIIToUTF16("username"); | 182 field.label = ASCIIToUTF16("username"); |
| 184 field.name = ASCIIToUTF16("username"); | 183 field.name = ASCIIToUTF16("username"); |
| 185 field.form_control_type = "text"; | 184 field.form_control_type = "text"; |
| 186 form.fields.push_back(field); | 185 form.fields.push_back(field); |
| 187 | 186 |
| 188 field.label = ASCIIToUTF16("password"); | 187 field.label = ASCIIToUTF16("password"); |
| 189 field.name = ASCIIToUTF16("password"); | 188 field.name = ASCIIToUTF16("password"); |
| 190 field.form_control_type = "password"; | 189 field.form_control_type = "password"; |
| 191 form.fields.push_back(field); | 190 form.fields.push_back(field); |
| 192 | 191 |
| 193 field.label = string16(); | 192 field.label = string16(); |
| 194 field.name = ASCIIToUTF16("Submit"); | 193 field.name = ASCIIToUTF16("Submit"); |
| 195 field.form_control_type = "submit"; | 194 field.form_control_type = "submit"; |
| 196 form.fields.push_back(field); | 195 form.fields.push_back(field); |
| 197 | 196 |
| 198 form_structure.reset(new FormStructure(form)); | 197 form_structure.reset(new FormStructure(form, false)); |
| 199 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 198 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 200 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 199 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 201 | 200 |
| 202 // We now have three text fields, but only two auto-fillable fields. | 201 // We now have three text fields, but only two auto-fillable fields. |
| 203 field.label = ASCIIToUTF16("First Name"); | 202 field.label = ASCIIToUTF16("First Name"); |
| 204 field.name = ASCIIToUTF16("firstname"); | 203 field.name = ASCIIToUTF16("firstname"); |
| 205 field.form_control_type = "text"; | 204 field.form_control_type = "text"; |
| 206 form.fields.push_back(field); | 205 form.fields.push_back(field); |
| 207 | 206 |
| 208 field.label = ASCIIToUTF16("Last Name"); | 207 field.label = ASCIIToUTF16("Last Name"); |
| 209 field.name = ASCIIToUTF16("lastname"); | 208 field.name = ASCIIToUTF16("lastname"); |
| 210 field.form_control_type = "text"; | 209 field.form_control_type = "text"; |
| 211 form.fields.push_back(field); | 210 form.fields.push_back(field); |
| 212 | 211 |
| 213 form_structure.reset(new FormStructure(form)); | 212 form_structure.reset(new FormStructure(form, false)); |
| 214 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 213 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 215 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 214 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 216 | 215 |
| 217 // We now have three auto-fillable fields. | 216 // We now have three auto-fillable fields. |
| 218 field.label = ASCIIToUTF16("Email"); | 217 field.label = ASCIIToUTF16("Email"); |
| 219 field.name = ASCIIToUTF16("email"); | 218 field.name = ASCIIToUTF16("email"); |
| 220 field.form_control_type = "email"; | 219 field.form_control_type = "email"; |
| 221 form.fields.push_back(field); | 220 form.fields.push_back(field); |
| 222 | 221 |
| 223 form_structure.reset(new FormStructure(form)); | 222 form_structure.reset(new FormStructure(form, false)); |
| 224 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 223 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 225 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 224 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 226 | 225 |
| 227 // The method must be 'post', though we can intentionally ignore this | 226 // The method must be 'post', though we can intentionally ignore this |
| 228 // criterion for the sake of providing a helpful warning message to the user. | 227 // criterion for the sake of providing a helpful warning message to the user. |
| 229 form.method = ASCIIToUTF16("get"); | 228 form.method = ASCIIToUTF16("get"); |
| 230 form_structure.reset(new FormStructure(form)); | 229 form_structure.reset(new FormStructure(form, false)); |
| 231 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 230 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 232 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 231 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 233 EXPECT_TRUE(form_structure->IsAutofillable(false)); | 232 EXPECT_TRUE(form_structure->IsAutofillable(false)); |
| 234 | 233 |
| 235 // The target cannot include http(s)://*/search... | 234 // The target cannot include http(s)://*/search... |
| 236 form.method = ASCIIToUTF16("post"); | 235 form.method = ASCIIToUTF16("post"); |
| 237 form.action = GURL("http://google.com/search?q=hello"); | 236 form.action = GURL("http://google.com/search?q=hello"); |
| 238 form_structure.reset(new FormStructure(form)); | 237 form_structure.reset(new FormStructure(form, false)); |
| 239 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 238 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 240 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 239 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 241 | 240 |
| 242 // But search can be in the URL. | 241 // But search can be in the URL. |
| 243 form.action = GURL("http://search.com/?q=hello"); | 242 form.action = GURL("http://search.com/?q=hello"); |
| 244 form_structure.reset(new FormStructure(form)); | 243 form_structure.reset(new FormStructure(form, false)); |
| 245 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 244 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 246 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 245 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 247 } | 246 } |
| 248 | 247 |
| 249 TEST(FormStructureTest, ShouldBeParsed) { | 248 TEST(FormStructureTest, ShouldBeParsed) { |
| 250 scoped_ptr<FormStructure> form_structure; | 249 scoped_ptr<FormStructure> form_structure; |
| 251 FormData form; | 250 FormData form; |
| 252 | 251 |
| 253 // We need at least three text fields to be parseable. | 252 // We need at least three text fields to be parseable. |
| 254 form.method = ASCIIToUTF16("post"); | 253 form.method = ASCIIToUTF16("post"); |
| 255 | 254 |
| 256 FormFieldData field; | 255 FormFieldData field; |
| 257 field.label = ASCIIToUTF16("username"); | 256 field.label = ASCIIToUTF16("username"); |
| 258 field.name = ASCIIToUTF16("username"); | 257 field.name = ASCIIToUTF16("username"); |
| 259 field.form_control_type = "text"; | 258 field.form_control_type = "text"; |
| 260 form.fields.push_back(field); | 259 form.fields.push_back(field); |
| 261 | 260 |
| 262 FormFieldData checkable_field; | 261 FormFieldData checkable_field; |
| 263 checkable_field.is_checkable = true; | 262 checkable_field.is_checkable = true; |
| 264 checkable_field.name = ASCIIToUTF16("radiobtn"); | 263 checkable_field.name = ASCIIToUTF16("radiobtn"); |
| 265 checkable_field.form_control_type = "radio"; | 264 checkable_field.form_control_type = "radio"; |
| 266 form.fields.push_back(checkable_field); | 265 form.fields.push_back(checkable_field); |
| 267 | 266 |
| 268 checkable_field.name = ASCIIToUTF16("checkbox"); | 267 checkable_field.name = ASCIIToUTF16("checkbox"); |
| 269 checkable_field.form_control_type = "checkbox"; | 268 checkable_field.form_control_type = "checkbox"; |
| 270 form.fields.push_back(checkable_field); | 269 form.fields.push_back(checkable_field); |
| 271 | 270 |
| 272 form_structure.reset(new FormStructure(form)); | 271 form_structure.reset(new FormStructure(form, false)); |
| 273 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 272 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
| 274 | 273 |
| 275 // We now have three text fields, though only two are auto-fillable. | 274 // We now have three text fields, though only two are auto-fillable. |
| 276 field.label = ASCIIToUTF16("First Name"); | 275 field.label = ASCIIToUTF16("First Name"); |
| 277 field.name = ASCIIToUTF16("firstname"); | 276 field.name = ASCIIToUTF16("firstname"); |
| 278 field.form_control_type = "text"; | 277 field.form_control_type = "text"; |
| 279 form.fields.push_back(field); | 278 form.fields.push_back(field); |
| 280 | 279 |
| 281 field.label = ASCIIToUTF16("Last Name"); | 280 field.label = ASCIIToUTF16("Last Name"); |
| 282 field.name = ASCIIToUTF16("lastname"); | 281 field.name = ASCIIToUTF16("lastname"); |
| 283 field.form_control_type = "text"; | 282 field.form_control_type = "text"; |
| 284 form.fields.push_back(field); | 283 form.fields.push_back(field); |
| 285 | 284 |
| 286 form_structure.reset(new FormStructure(form)); | 285 form_structure.reset(new FormStructure(form, false)); |
| 287 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 286 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
| 288 | 287 |
| 289 // The method must be 'post', though we can intentionally ignore this | 288 // The method must be 'post', though we can intentionally ignore this |
| 290 // criterion for the sake of providing a helpful warning message to the user. | 289 // criterion for the sake of providing a helpful warning message to the user. |
| 291 form.method = ASCIIToUTF16("get"); | 290 form.method = ASCIIToUTF16("get"); |
| 292 form_structure.reset(new FormStructure(form)); | 291 form_structure.reset(new FormStructure(form, false)); |
| 293 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 292 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 294 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); | 293 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); |
| 295 | 294 |
| 296 // The target cannot include http(s)://*/search... | 295 // The target cannot include http(s)://*/search... |
| 297 form.method = ASCIIToUTF16("post"); | 296 form.method = ASCIIToUTF16("post"); |
| 298 form.action = GURL("http://google.com/search?q=hello"); | 297 form.action = GURL("http://google.com/search?q=hello"); |
| 299 form_structure.reset(new FormStructure(form)); | 298 form_structure.reset(new FormStructure(form, false)); |
| 300 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 299 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
| 301 | 300 |
| 302 // But search can be in the URL. | 301 // But search can be in the URL. |
| 303 form.action = GURL("http://search.com/?q=hello"); | 302 form.action = GURL("http://search.com/?q=hello"); |
| 304 form_structure.reset(new FormStructure(form)); | 303 form_structure.reset(new FormStructure(form, false)); |
| 305 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 304 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
| 306 | 305 |
| 307 // The form need only have three fields, but at least one must be a text | 306 // The form need only have three fields, but at least one must be a text |
| 308 // field. | 307 // field. |
| 309 form.fields.clear(); | 308 form.fields.clear(); |
| 310 | 309 |
| 311 field.label = ASCIIToUTF16("Email"); | 310 field.label = ASCIIToUTF16("Email"); |
| 312 field.name = ASCIIToUTF16("email"); | 311 field.name = ASCIIToUTF16("email"); |
| 313 field.form_control_type = "email"; | 312 field.form_control_type = "email"; |
| 314 form.fields.push_back(field); | 313 form.fields.push_back(field); |
| 315 | 314 |
| 316 field.label = ASCIIToUTF16("State"); | 315 field.label = ASCIIToUTF16("State"); |
| 317 field.name = ASCIIToUTF16("state"); | 316 field.name = ASCIIToUTF16("state"); |
| 318 field.form_control_type = "select-one"; | 317 field.form_control_type = "select-one"; |
| 319 form.fields.push_back(field); | 318 form.fields.push_back(field); |
| 320 | 319 |
| 321 field.label = ASCIIToUTF16("Country"); | 320 field.label = ASCIIToUTF16("Country"); |
| 322 field.name = ASCIIToUTF16("country"); | 321 field.name = ASCIIToUTF16("country"); |
| 323 field.form_control_type = "select-one"; | 322 field.form_control_type = "select-one"; |
| 324 form.fields.push_back(field); | 323 form.fields.push_back(field); |
| 325 | 324 |
| 326 form_structure.reset(new FormStructure(form)); | 325 form_structure.reset(new FormStructure(form, false)); |
| 327 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 326 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
| 328 | 327 |
| 329 form.fields[0].form_control_type = "select-one"; | 328 form.fields[0].form_control_type = "select-one"; |
| 330 form_structure.reset(new FormStructure(form)); | 329 form_structure.reset(new FormStructure(form, false)); |
| 331 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 330 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
| 332 } | 331 } |
| 333 | 332 |
| 334 TEST(FormStructureTest, HeuristicsContactInfo) { | 333 TEST(FormStructureTest, HeuristicsContactInfo) { |
| 335 scoped_ptr<FormStructure> form_structure; | 334 scoped_ptr<FormStructure> form_structure; |
| 336 FormData form; | 335 FormData form; |
| 337 form.method = ASCIIToUTF16("post"); | 336 form.method = ASCIIToUTF16("post"); |
| 338 | 337 |
| 339 FormFieldData field; | 338 FormFieldData field; |
| 340 field.form_control_type = "text"; | 339 field.form_control_type = "text"; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 365 | 364 |
| 366 field.label = ASCIIToUTF16("Zip code"); | 365 field.label = ASCIIToUTF16("Zip code"); |
| 367 field.name = ASCIIToUTF16("zipcode"); | 366 field.name = ASCIIToUTF16("zipcode"); |
| 368 form.fields.push_back(field); | 367 form.fields.push_back(field); |
| 369 | 368 |
| 370 field.label = string16(); | 369 field.label = string16(); |
| 371 field.name = ASCIIToUTF16("Submit"); | 370 field.name = ASCIIToUTF16("Submit"); |
| 372 field.form_control_type = "submit"; | 371 field.form_control_type = "submit"; |
| 373 form.fields.push_back(field); | 372 form.fields.push_back(field); |
| 374 | 373 |
| 375 form_structure.reset(new FormStructure(form)); | 374 form_structure.reset(new FormStructure(form, false)); |
| 376 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 375 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 377 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 376 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 378 | 377 |
| 379 // Expect the correct number of fields. | 378 // Expect the correct number of fields. |
| 380 ASSERT_EQ(8U, form_structure->field_count()); | 379 ASSERT_EQ(8U, form_structure->field_count()); |
| 381 ASSERT_EQ(7U, form_structure->autofill_count()); | 380 ASSERT_EQ(7U, form_structure->autofill_count()); |
| 382 | 381 |
| 383 // First name. | 382 // First name. |
| 384 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 383 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 385 // Last name. | 384 // Last name. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 416 field.label = string16(); | 415 field.label = string16(); |
| 417 field.name = ASCIIToUTF16("field2"); | 416 field.name = ASCIIToUTF16("field2"); |
| 418 field.autocomplete_attribute = "family-name"; | 417 field.autocomplete_attribute = "family-name"; |
| 419 form.fields.push_back(field); | 418 form.fields.push_back(field); |
| 420 | 419 |
| 421 field.label = string16(); | 420 field.label = string16(); |
| 422 field.name = ASCIIToUTF16("field3"); | 421 field.name = ASCIIToUTF16("field3"); |
| 423 field.autocomplete_attribute = "email"; | 422 field.autocomplete_attribute = "email"; |
| 424 form.fields.push_back(field); | 423 form.fields.push_back(field); |
| 425 | 424 |
| 426 form_structure.reset(new FormStructure(form)); | 425 form_structure.reset(new FormStructure(form, false)); |
| 427 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 426 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 428 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 427 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 429 | 428 |
| 430 // Expect the correct number of fields. | 429 // Expect the correct number of fields. |
| 431 ASSERT_EQ(3U, form_structure->field_count()); | 430 ASSERT_EQ(3U, form_structure->field_count()); |
| 432 ASSERT_EQ(3U, form_structure->autofill_count()); | 431 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 433 | 432 |
| 434 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 433 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 435 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 434 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 436 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 435 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 454 field.label = string16(); | 453 field.label = string16(); |
| 455 field.name = ASCIIToUTF16("field2"); | 454 field.name = ASCIIToUTF16("field2"); |
| 456 field.autocomplete_attribute = "tel-local-prefix"; | 455 field.autocomplete_attribute = "tel-local-prefix"; |
| 457 form.fields.push_back(field); | 456 form.fields.push_back(field); |
| 458 | 457 |
| 459 field.label = string16(); | 458 field.label = string16(); |
| 460 field.name = ASCIIToUTF16("field3"); | 459 field.name = ASCIIToUTF16("field3"); |
| 461 field.autocomplete_attribute = "tel-local-suffix"; | 460 field.autocomplete_attribute = "tel-local-suffix"; |
| 462 form.fields.push_back(field); | 461 form.fields.push_back(field); |
| 463 | 462 |
| 464 form_structure.reset(new FormStructure(form)); | 463 form_structure.reset(new FormStructure(form, false)); |
| 465 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 464 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 466 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 465 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 467 | 466 |
| 468 // Expect the correct number of fields. | 467 // Expect the correct number of fields. |
| 469 ASSERT_EQ(3U, form_structure->field_count()); | 468 ASSERT_EQ(3U, form_structure->field_count()); |
| 470 EXPECT_EQ(3U, form_structure->autofill_count()); | 469 EXPECT_EQ(3U, form_structure->autofill_count()); |
| 471 | 470 |
| 472 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(0)->heuristic_type()); | 471 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(0)->heuristic_type()); |
| 473 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); | 472 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); |
| 474 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(1)->heuristic_type()); | 473 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(1)->heuristic_type()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 495 form.fields.push_back(field); | 494 form.fields.push_back(field); |
| 496 | 495 |
| 497 field.label = ASCIIToUTF16("Last Name"); | 496 field.label = ASCIIToUTF16("Last Name"); |
| 498 field.name = ASCIIToUTF16("lastname"); | 497 field.name = ASCIIToUTF16("lastname"); |
| 499 form.fields.push_back(field); | 498 form.fields.push_back(field); |
| 500 | 499 |
| 501 field.label = ASCIIToUTF16("Email"); | 500 field.label = ASCIIToUTF16("Email"); |
| 502 field.name = ASCIIToUTF16("email"); | 501 field.name = ASCIIToUTF16("email"); |
| 503 form.fields.push_back(field); | 502 form.fields.push_back(field); |
| 504 | 503 |
| 505 form_structure.reset(new FormStructure(form)); | 504 form_structure.reset(new FormStructure(form, false)); |
| 506 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 505 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 507 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 506 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 508 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); | 507 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); |
| 509 | 508 |
| 510 ASSERT_EQ(3U, form_structure->field_count()); | 509 ASSERT_EQ(3U, form_structure->field_count()); |
| 511 ASSERT_EQ(3U, form_structure->autofill_count()); | 510 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 512 | 511 |
| 513 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 512 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 514 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 513 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 515 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 514 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
| 516 | 515 |
| 517 // Now update the first form field to include an 'autocomplete' attribute. | 516 // Now update the first form field to include an 'autocomplete' attribute. |
| 518 form.fields.front().autocomplete_attribute = "x-other"; | 517 form.fields.front().autocomplete_attribute = "x-other"; |
| 519 form_structure.reset(new FormStructure(form)); | 518 form_structure.reset(new FormStructure(form, false)); |
| 520 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 519 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 521 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 520 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 522 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); | 521 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); |
| 523 | 522 |
| 524 ASSERT_EQ(3U, form_structure->field_count()); | 523 ASSERT_EQ(3U, form_structure->field_count()); |
| 525 ASSERT_EQ(0U, form_structure->autofill_count()); | 524 ASSERT_EQ(0U, form_structure->autofill_count()); |
| 526 | 525 |
| 527 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | 526 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
| 528 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 527 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 529 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 528 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 // different sections. This is only an interesting test due to how we | 568 // different sections. This is only an interesting test due to how we |
| 570 // implement implicit section names from attributes like "shipping email"; see | 569 // implement implicit section names from attributes like "shipping email"; see |
| 571 // the implementation for more details. | 570 // the implementation for more details. |
| 572 field.autocomplete_attribute = "section--shipping email"; | 571 field.autocomplete_attribute = "section--shipping email"; |
| 573 form.fields.push_back(field); | 572 form.fields.push_back(field); |
| 574 | 573 |
| 575 // Credit card fields are implicitly in a separate section from other fields. | 574 // Credit card fields are implicitly in a separate section from other fields. |
| 576 field.autocomplete_attribute = "section-foo cc-number"; | 575 field.autocomplete_attribute = "section-foo cc-number"; |
| 577 form.fields.push_back(field); | 576 form.fields.push_back(field); |
| 578 | 577 |
| 579 FormStructure form_structure(form); | 578 FormStructure form_structure(form, false); |
| 580 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 579 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 581 EXPECT_TRUE(form_structure.IsAutofillable(true)); | 580 EXPECT_TRUE(form_structure.IsAutofillable(true)); |
| 582 | 581 |
| 583 // Expect the correct number of fields. | 582 // Expect the correct number of fields. |
| 584 ASSERT_EQ(9U, form_structure.field_count()); | 583 ASSERT_EQ(9U, form_structure.field_count()); |
| 585 EXPECT_EQ(9U, form_structure.autofill_count()); | 584 EXPECT_EQ(9U, form_structure.autofill_count()); |
| 586 | 585 |
| 587 // All of the fields in this form should be parsed as belonging to different | 586 // All of the fields in this form should be parsed as belonging to different |
| 588 // sections. | 587 // sections. |
| 589 std::set<std::string> section_names; | 588 std::set<std::string> section_names; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 614 // Invalid tokens should prevent us from setting a section name. | 613 // Invalid tokens should prevent us from setting a section name. |
| 615 field.autocomplete_attribute = "garbage section-foo email"; | 614 field.autocomplete_attribute = "garbage section-foo email"; |
| 616 form.fields.push_back(field); | 615 form.fields.push_back(field); |
| 617 field.autocomplete_attribute = "garbage section-bar email"; | 616 field.autocomplete_attribute = "garbage section-bar email"; |
| 618 form.fields.push_back(field); | 617 form.fields.push_back(field); |
| 619 field.autocomplete_attribute = "garbage shipping email"; | 618 field.autocomplete_attribute = "garbage shipping email"; |
| 620 form.fields.push_back(field); | 619 form.fields.push_back(field); |
| 621 field.autocomplete_attribute = "garbage billing email"; | 620 field.autocomplete_attribute = "garbage billing email"; |
| 622 form.fields.push_back(field); | 621 form.fields.push_back(field); |
| 623 | 622 |
| 624 FormStructure form_structure(form); | 623 FormStructure form_structure(form, false); |
| 625 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 624 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 626 | 625 |
| 627 // Expect the correct number of fields. | 626 // Expect the correct number of fields. |
| 628 ASSERT_EQ(6U, form_structure.field_count()); | 627 ASSERT_EQ(6U, form_structure.field_count()); |
| 629 EXPECT_EQ(2U, form_structure.autofill_count()); | 628 EXPECT_EQ(2U, form_structure.autofill_count()); |
| 630 | 629 |
| 631 // All of the fields in this form should be parsed as belonging to the same | 630 // All of the fields in this form should be parsed as belonging to the same |
| 632 // section. | 631 // section. |
| 633 std::set<std::string> section_names; | 632 std::set<std::string> section_names; |
| 634 for (size_t i = 0; i < 6; ++i) { | 633 for (size_t i = 0; i < 6; ++i) { |
| 635 section_names.insert(form_structure.field(i)->section()); | 634 section_names.insert(form_structure.field(i)->section()); |
| 636 } | 635 } |
| 637 EXPECT_EQ(1U, section_names.size()); | 636 EXPECT_EQ(1U, section_names.size()); |
| 638 } | 637 } |
| 639 | 638 |
| 640 // Verify that we can correctly process repeated sections listed in the | 639 // Verify that we can correctly process repeated sections listed in the |
| 641 // |autocomplete| attribute. | 640 // |autocomplete| attribute. |
| 642 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { | 641 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { |
| 643 FormData form; | 642 FormData form; |
| 644 form.method = ASCIIToUTF16("post"); | 643 form.method = ASCIIToUTF16("post"); |
| 645 | 644 |
| 646 FormFieldData field; | 645 FormFieldData field; |
| 647 field.form_control_type = "text"; | 646 field.form_control_type = "text"; |
| 648 | 647 |
| 649 field.autocomplete_attribute = "section-foo email"; | 648 field.autocomplete_attribute = "section-foo email"; |
| 650 form.fields.push_back(field); | 649 form.fields.push_back(field); |
| 651 field.autocomplete_attribute = "section-foo street-address"; | 650 field.autocomplete_attribute = "section-foo street-address"; |
| 652 form.fields.push_back(field); | 651 form.fields.push_back(field); |
| 653 | 652 |
| 654 FormStructure form_structure(form); | 653 FormStructure form_structure(form, false); |
| 655 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 654 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 656 | 655 |
| 657 // Expect the correct number of fields. | 656 // Expect the correct number of fields. |
| 658 ASSERT_EQ(2U, form_structure.field_count()); | 657 ASSERT_EQ(2U, form_structure.field_count()); |
| 659 EXPECT_EQ(2U, form_structure.autofill_count()); | 658 EXPECT_EQ(2U, form_structure.autofill_count()); |
| 660 | 659 |
| 661 // All of the fields in this form should be parsed as belonging to the same | 660 // All of the fields in this form should be parsed as belonging to the same |
| 662 // section. | 661 // section. |
| 663 std::set<std::string> section_names; | 662 std::set<std::string> section_names; |
| 664 for (size_t i = 0; i < 2; ++i) { | 663 for (size_t i = 0; i < 2; ++i) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 682 field.name = string16(); | 681 field.name = string16(); |
| 683 field.autocomplete_attribute = "section-foo email"; | 682 field.autocomplete_attribute = "section-foo email"; |
| 684 form.fields.push_back(field); | 683 form.fields.push_back(field); |
| 685 field.name = string16(); | 684 field.name = string16(); |
| 686 field.autocomplete_attribute = "name"; | 685 field.autocomplete_attribute = "name"; |
| 687 form.fields.push_back(field); | 686 form.fields.push_back(field); |
| 688 field.name = ASCIIToUTF16("two"); | 687 field.name = ASCIIToUTF16("two"); |
| 689 field.autocomplete_attribute = "street-address"; | 688 field.autocomplete_attribute = "street-address"; |
| 690 form.fields.push_back(field); | 689 form.fields.push_back(field); |
| 691 | 690 |
| 692 FormStructure form_structure(form); | 691 FormStructure form_structure(form, false); |
| 693 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 692 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 694 | 693 |
| 695 // Expect the correct number of fields. | 694 // Expect the correct number of fields. |
| 696 ASSERT_EQ(4U, form_structure.field_count()); | 695 ASSERT_EQ(4U, form_structure.field_count()); |
| 697 EXPECT_EQ(4U, form_structure.autofill_count()); | 696 EXPECT_EQ(4U, form_structure.autofill_count()); |
| 698 | 697 |
| 699 // Normally, the two separate address fields would cause us to detect two | 698 // Normally, the two separate address fields would cause us to detect two |
| 700 // separate sections; but because there is an author-specified section in this | 699 // separate sections; but because there is an author-specified section in this |
| 701 // form, we do not apply these usual heuristics. | 700 // form, we do not apply these usual heuristics. |
| 702 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); | 701 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 746 |
| 748 field.label = ASCIIToUTF16("Phone Number:"); | 747 field.label = ASCIIToUTF16("Phone Number:"); |
| 749 field.name = ASCIIToUTF16("BillTo.Phone"); | 748 field.name = ASCIIToUTF16("BillTo.Phone"); |
| 750 form.fields.push_back(field); | 749 form.fields.push_back(field); |
| 751 | 750 |
| 752 field.label = string16(); | 751 field.label = string16(); |
| 753 field.name = ASCIIToUTF16("Submit"); | 752 field.name = ASCIIToUTF16("Submit"); |
| 754 field.form_control_type = "submit"; | 753 field.form_control_type = "submit"; |
| 755 form.fields.push_back(field); | 754 form.fields.push_back(field); |
| 756 | 755 |
| 757 form_structure.reset(new FormStructure(form)); | 756 form_structure.reset(new FormStructure(form, false)); |
| 758 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 757 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 759 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 758 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 760 ASSERT_EQ(10U, form_structure->field_count()); | 759 ASSERT_EQ(10U, form_structure->field_count()); |
| 761 ASSERT_EQ(9U, form_structure->autofill_count()); | 760 ASSERT_EQ(9U, form_structure->autofill_count()); |
| 762 | 761 |
| 763 // First name. | 762 // First name. |
| 764 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 763 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 765 // Last name. | 764 // Last name. |
| 766 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 765 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 767 // Address. | 766 // Address. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 field.label = ASCIIToUTF16("Zip Code"); | 814 field.label = ASCIIToUTF16("Zip Code"); |
| 816 field.name = ASCIIToUTF16("Home.PostalCode"); | 815 field.name = ASCIIToUTF16("Home.PostalCode"); |
| 817 form.fields.push_back(field); | 816 form.fields.push_back(field); |
| 818 | 817 |
| 819 field.label = string16(); | 818 field.label = string16(); |
| 820 field.name = ASCIIToUTF16("Submit"); | 819 field.name = ASCIIToUTF16("Submit"); |
| 821 field.value = ASCIIToUTF16("continue"); | 820 field.value = ASCIIToUTF16("continue"); |
| 822 field.form_control_type = "submit"; | 821 field.form_control_type = "submit"; |
| 823 form.fields.push_back(field); | 822 form.fields.push_back(field); |
| 824 | 823 |
| 825 form_structure.reset(new FormStructure(form)); | 824 form_structure.reset(new FormStructure(form, false)); |
| 826 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 825 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 827 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 826 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 828 ASSERT_EQ(7U, form_structure->field_count()); | 827 ASSERT_EQ(7U, form_structure->field_count()); |
| 829 ASSERT_EQ(6U, form_structure->autofill_count()); | 828 ASSERT_EQ(6U, form_structure->autofill_count()); |
| 830 | 829 |
| 831 // Email. | 830 // Email. |
| 832 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); | 831 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); |
| 833 // Full name. | 832 // Full name. |
| 834 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); | 833 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); |
| 835 // Company | 834 // Company |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 880 |
| 882 field.label = ASCIIToUTF16("Zip code"); | 881 field.label = ASCIIToUTF16("Zip code"); |
| 883 field.name = string16(); | 882 field.name = string16(); |
| 884 form.fields.push_back(field); | 883 form.fields.push_back(field); |
| 885 | 884 |
| 886 field.label = string16(); | 885 field.label = string16(); |
| 887 field.name = ASCIIToUTF16("Submit"); | 886 field.name = ASCIIToUTF16("Submit"); |
| 888 field.form_control_type = "submit"; | 887 field.form_control_type = "submit"; |
| 889 form.fields.push_back(field); | 888 form.fields.push_back(field); |
| 890 | 889 |
| 891 form_structure.reset(new FormStructure(form)); | 890 form_structure.reset(new FormStructure(form, false)); |
| 892 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 891 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 893 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 892 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 894 ASSERT_EQ(8U, form_structure->field_count()); | 893 ASSERT_EQ(8U, form_structure->field_count()); |
| 895 ASSERT_EQ(7U, form_structure->autofill_count()); | 894 ASSERT_EQ(7U, form_structure->autofill_count()); |
| 896 | 895 |
| 897 // First name. | 896 // First name. |
| 898 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 897 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 899 // Last name. | 898 // Last name. |
| 900 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 899 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 901 // Email. | 900 // Email. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 | 938 |
| 940 field.label = ASCIIToUTF16("Verification"); | 939 field.label = ASCIIToUTF16("Verification"); |
| 941 field.name = ASCIIToUTF16("verification"); | 940 field.name = ASCIIToUTF16("verification"); |
| 942 form.fields.push_back(field); | 941 form.fields.push_back(field); |
| 943 | 942 |
| 944 field.label = string16(); | 943 field.label = string16(); |
| 945 field.name = ASCIIToUTF16("Submit"); | 944 field.name = ASCIIToUTF16("Submit"); |
| 946 field.form_control_type = "submit"; | 945 field.form_control_type = "submit"; |
| 947 form.fields.push_back(field); | 946 form.fields.push_back(field); |
| 948 | 947 |
| 949 form_structure.reset(new FormStructure(form)); | 948 form_structure.reset(new FormStructure(form, false)); |
| 950 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 949 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 951 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 950 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 952 ASSERT_EQ(6U, form_structure->field_count()); | 951 ASSERT_EQ(6U, form_structure->field_count()); |
| 953 ASSERT_EQ(5U, form_structure->autofill_count()); | 952 ASSERT_EQ(5U, form_structure->autofill_count()); |
| 954 | 953 |
| 955 // Credit card name. | 954 // Credit card name. |
| 956 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 955 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
| 957 // Credit card number. | 956 // Credit card number. |
| 958 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); | 957 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); |
| 959 // Credit card expiration month. | 958 // Credit card expiration month. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 999 |
| 1001 field.label = ASCIIToUTF16("Verification"); | 1000 field.label = ASCIIToUTF16("Verification"); |
| 1002 field.name = ASCIIToUTF16("verification"); | 1001 field.name = ASCIIToUTF16("verification"); |
| 1003 form.fields.push_back(field); | 1002 form.fields.push_back(field); |
| 1004 | 1003 |
| 1005 field.label = string16(); | 1004 field.label = string16(); |
| 1006 field.name = ASCIIToUTF16("Submit"); | 1005 field.name = ASCIIToUTF16("Submit"); |
| 1007 field.form_control_type = "submit"; | 1006 field.form_control_type = "submit"; |
| 1008 form.fields.push_back(field); | 1007 form.fields.push_back(field); |
| 1009 | 1008 |
| 1010 form_structure.reset(new FormStructure(form)); | 1009 form_structure.reset(new FormStructure(form, false)); |
| 1011 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1010 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1012 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1011 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1013 ASSERT_EQ(7U, form_structure->field_count()); | 1012 ASSERT_EQ(7U, form_structure->field_count()); |
| 1014 ASSERT_EQ(5U, form_structure->autofill_count()); | 1013 ASSERT_EQ(5U, form_structure->autofill_count()); |
| 1015 | 1014 |
| 1016 // Credit card name. | 1015 // Credit card name. |
| 1017 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 1016 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
| 1018 // Credit card type. This is an unknown type but related to the credit card. | 1017 // Credit card type. This is an unknown type but related to the credit card. |
| 1019 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 1018 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 1020 // Credit card number. | 1019 // Credit card number. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1048 form.fields.push_back(field); | 1047 form.fields.push_back(field); |
| 1049 | 1048 |
| 1050 field.label = ASCIIToUTF16("Address Line3"); | 1049 field.label = ASCIIToUTF16("Address Line3"); |
| 1051 field.name = ASCIIToUTF16("Address"); | 1050 field.name = ASCIIToUTF16("Address"); |
| 1052 form.fields.push_back(field); | 1051 form.fields.push_back(field); |
| 1053 | 1052 |
| 1054 field.label = ASCIIToUTF16("City"); | 1053 field.label = ASCIIToUTF16("City"); |
| 1055 field.name = ASCIIToUTF16("city"); | 1054 field.name = ASCIIToUTF16("city"); |
| 1056 form.fields.push_back(field); | 1055 form.fields.push_back(field); |
| 1057 | 1056 |
| 1058 form_structure.reset(new FormStructure(form)); | 1057 form_structure.reset(new FormStructure(form, false)); |
| 1059 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1058 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1060 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1059 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1061 ASSERT_EQ(4U, form_structure->field_count()); | 1060 ASSERT_EQ(4U, form_structure->field_count()); |
| 1062 ASSERT_EQ(3U, form_structure->autofill_count()); | 1061 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1063 | 1062 |
| 1064 // Address Line 1. | 1063 // Address Line 1. |
| 1065 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1064 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1066 // Address Line 2. | 1065 // Address Line 2. |
| 1067 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1066 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1068 // Address Line 3. | 1067 // Address Line 3. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1090 form.fields.push_back(field); | 1089 form.fields.push_back(field); |
| 1091 | 1090 |
| 1092 field.label = ASCIIToUTF16("Address Line1"); | 1091 field.label = ASCIIToUTF16("Address Line1"); |
| 1093 field.name = ASCIIToUTF16("billing.address.addressLine1"); | 1092 field.name = ASCIIToUTF16("billing.address.addressLine1"); |
| 1094 form.fields.push_back(field); | 1093 form.fields.push_back(field); |
| 1095 | 1094 |
| 1096 field.label = ASCIIToUTF16("Address Line2"); | 1095 field.label = ASCIIToUTF16("Address Line2"); |
| 1097 field.name = ASCIIToUTF16("billing.address.addressLine2"); | 1096 field.name = ASCIIToUTF16("billing.address.addressLine2"); |
| 1098 form.fields.push_back(field); | 1097 form.fields.push_back(field); |
| 1099 | 1098 |
| 1100 form_structure.reset(new FormStructure(form)); | 1099 form_structure.reset(new FormStructure(form, false)); |
| 1101 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1100 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1102 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1101 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1103 ASSERT_EQ(4U, form_structure->field_count()); | 1102 ASSERT_EQ(4U, form_structure->field_count()); |
| 1104 ASSERT_EQ(4U, form_structure->autofill_count()); | 1103 ASSERT_EQ(4U, form_structure->autofill_count()); |
| 1105 | 1104 |
| 1106 // Address Line 1. | 1105 // Address Line 1. |
| 1107 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1106 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1108 // Address Line 2. | 1107 // Address Line 2. |
| 1109 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1108 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1110 // Address Line 1. | 1109 // Address Line 1. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1136 form.fields.push_back(field); | 1135 form.fields.push_back(field); |
| 1137 | 1136 |
| 1138 field.label = ASCIIToUTF16("Street address second line"); | 1137 field.label = ASCIIToUTF16("Street address second line"); |
| 1139 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"); | 1138 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"); |
| 1140 form.fields.push_back(field); | 1139 form.fields.push_back(field); |
| 1141 | 1140 |
| 1142 field.label = ASCIIToUTF16("City:"); | 1141 field.label = ASCIIToUTF16("City:"); |
| 1143 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"); | 1142 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"); |
| 1144 form.fields.push_back(field); | 1143 form.fields.push_back(field); |
| 1145 | 1144 |
| 1146 form_structure.reset(new FormStructure(form)); | 1145 form_structure.reset(new FormStructure(form, false)); |
| 1147 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1146 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1148 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1147 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1149 ASSERT_EQ(4U, form_structure->field_count()); | 1148 ASSERT_EQ(4U, form_structure->field_count()); |
| 1150 EXPECT_EQ(3U, form_structure->autofill_count()); | 1149 EXPECT_EQ(3U, form_structure->autofill_count()); |
| 1151 | 1150 |
| 1152 // Address Line 1. | 1151 // Address Line 1. |
| 1153 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1152 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1154 // Suite / Apt. | 1153 // Suite / Apt. |
| 1155 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1154 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1156 // Address Line 3. | 1155 // Address Line 3. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1175 form.fields.push_back(field); | 1174 form.fields.push_back(field); |
| 1176 | 1175 |
| 1177 field.label = ASCIIToUTF16("Floor number, suite number, etc"); | 1176 field.label = ASCIIToUTF16("Floor number, suite number, etc"); |
| 1178 field.name = ASCIIToUTF16("address2"); | 1177 field.name = ASCIIToUTF16("address2"); |
| 1179 form.fields.push_back(field); | 1178 form.fields.push_back(field); |
| 1180 | 1179 |
| 1181 field.label = ASCIIToUTF16("City:"); | 1180 field.label = ASCIIToUTF16("City:"); |
| 1182 field.name = ASCIIToUTF16("city"); | 1181 field.name = ASCIIToUTF16("city"); |
| 1183 form.fields.push_back(field); | 1182 form.fields.push_back(field); |
| 1184 | 1183 |
| 1185 form_structure.reset(new FormStructure(form)); | 1184 form_structure.reset(new FormStructure(form, false)); |
| 1186 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1185 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1187 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1186 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1188 ASSERT_EQ(3U, form_structure->field_count()); | 1187 ASSERT_EQ(3U, form_structure->field_count()); |
| 1189 ASSERT_EQ(3U, form_structure->autofill_count()); | 1188 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1190 | 1189 |
| 1191 // Address Line 1. | 1190 // Address Line 1. |
| 1192 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1191 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1193 // Address Line 2. | 1192 // Address Line 2. |
| 1194 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1193 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1195 // City. | 1194 // City. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1209 form.fields.push_back(field); | 1208 form.fields.push_back(field); |
| 1210 | 1209 |
| 1211 field.label = ASCIIToUTF16("Address Line2"); | 1210 field.label = ASCIIToUTF16("Address Line2"); |
| 1212 field.name = ASCIIToUTF16("Address"); | 1211 field.name = ASCIIToUTF16("Address"); |
| 1213 form.fields.push_back(field); | 1212 form.fields.push_back(field); |
| 1214 | 1213 |
| 1215 field.label = ASCIIToUTF16("State/Province/Region"); | 1214 field.label = ASCIIToUTF16("State/Province/Region"); |
| 1216 field.name = ASCIIToUTF16("State"); | 1215 field.name = ASCIIToUTF16("State"); |
| 1217 form.fields.push_back(field); | 1216 form.fields.push_back(field); |
| 1218 | 1217 |
| 1219 form_structure.reset(new FormStructure(form)); | 1218 form_structure.reset(new FormStructure(form, false)); |
| 1220 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1219 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1221 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1220 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1222 ASSERT_EQ(3U, form_structure->field_count()); | 1221 ASSERT_EQ(3U, form_structure->field_count()); |
| 1223 ASSERT_EQ(3U, form_structure->autofill_count()); | 1222 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1224 | 1223 |
| 1225 // Address Line 1. | 1224 // Address Line 1. |
| 1226 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1225 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1227 // Address Line 2. | 1226 // Address Line 2. |
| 1228 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1227 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1229 // State. | 1228 // State. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 form.fields.push_back(field); | 1275 form.fields.push_back(field); |
| 1277 | 1276 |
| 1278 field.label = ASCIIToUTF16("Phone*:"); | 1277 field.label = ASCIIToUTF16("Phone*:"); |
| 1279 field.name = ASCIIToUTF16("editBillingAddress$phoneBox"); | 1278 field.name = ASCIIToUTF16("editBillingAddress$phoneBox"); |
| 1280 form.fields.push_back(field); | 1279 form.fields.push_back(field); |
| 1281 | 1280 |
| 1282 field.label = ASCIIToUTF16("Email Address*:"); | 1281 field.label = ASCIIToUTF16("Email Address*:"); |
| 1283 field.name = ASCIIToUTF16("email$emailBox"); | 1282 field.name = ASCIIToUTF16("email$emailBox"); |
| 1284 form.fields.push_back(field); | 1283 form.fields.push_back(field); |
| 1285 | 1284 |
| 1286 form_structure.reset(new FormStructure(form)); | 1285 form_structure.reset(new FormStructure(form, false)); |
| 1287 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1286 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1288 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1287 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1289 ASSERT_EQ(11U, form_structure->field_count()); | 1288 ASSERT_EQ(11U, form_structure->field_count()); |
| 1290 ASSERT_EQ(11U, form_structure->autofill_count()); | 1289 ASSERT_EQ(11U, form_structure->autofill_count()); |
| 1291 | 1290 |
| 1292 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 1291 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 1293 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 1292 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 1294 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); | 1293 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); |
| 1295 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type()); | 1294 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type()); |
| 1296 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type()); | 1295 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1327 field.max_length = 4; // Size of suffix is 4. If unlimited size is | 1326 field.max_length = 4; // Size of suffix is 4. If unlimited size is |
| 1328 // passed, phone will be parsed as | 1327 // passed, phone will be parsed as |
| 1329 // <country code> - <area code> - <phone>. | 1328 // <country code> - <area code> - <phone>. |
| 1330 form.fields.push_back(field); | 1329 form.fields.push_back(field); |
| 1331 | 1330 |
| 1332 field.label = ASCIIToUTF16("ext.:"); | 1331 field.label = ASCIIToUTF16("ext.:"); |
| 1333 field.name = ASCIIToUTF16("dayphone4"); | 1332 field.name = ASCIIToUTF16("dayphone4"); |
| 1334 field.max_length = 0; | 1333 field.max_length = 0; |
| 1335 form.fields.push_back(field); | 1334 form.fields.push_back(field); |
| 1336 | 1335 |
| 1337 form_structure.reset(new FormStructure(form)); | 1336 form_structure.reset(new FormStructure(form, false)); |
| 1338 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1337 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1339 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1338 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1340 ASSERT_EQ(4U, form_structure->field_count()); | 1339 ASSERT_EQ(4U, form_structure->field_count()); |
| 1341 ASSERT_EQ(3U, form_structure->autofill_count()); | 1340 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1342 | 1341 |
| 1343 // Area code. | 1342 // Area code. |
| 1344 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); | 1343 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); |
| 1345 // Phone number suffix. | 1344 // Phone number suffix. |
| 1346 EXPECT_EQ(PHONE_HOME_NUMBER, | 1345 EXPECT_EQ(PHONE_HOME_NUMBER, |
| 1347 form_structure->field(1)->heuristic_type()); | 1346 form_structure->field(1)->heuristic_type()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1373 form.fields.push_back(field); | 1372 form.fields.push_back(field); |
| 1374 | 1373 |
| 1375 field.label = ASCIIToUTF16("Expiration Date"); | 1374 field.label = ASCIIToUTF16("Expiration Date"); |
| 1376 field.name = ASCIIToUTF16("expiration_month"); | 1375 field.name = ASCIIToUTF16("expiration_month"); |
| 1377 form.fields.push_back(field); | 1376 form.fields.push_back(field); |
| 1378 | 1377 |
| 1379 field.label = ASCIIToUTF16("Expiration Year"); | 1378 field.label = ASCIIToUTF16("Expiration Year"); |
| 1380 field.name = ASCIIToUTF16("expiration_year"); | 1379 field.name = ASCIIToUTF16("expiration_year"); |
| 1381 form.fields.push_back(field); | 1380 form.fields.push_back(field); |
| 1382 | 1381 |
| 1383 form_structure.reset(new FormStructure(form)); | 1382 form_structure.reset(new FormStructure(form, false)); |
| 1384 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1383 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1385 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1384 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1386 | 1385 |
| 1387 // Expect the correct number of fields. | 1386 // Expect the correct number of fields. |
| 1388 ASSERT_EQ(5U, form_structure->field_count()); | 1387 ASSERT_EQ(5U, form_structure->field_count()); |
| 1389 EXPECT_EQ(5U, form_structure->autofill_count()); | 1388 EXPECT_EQ(5U, form_structure->autofill_count()); |
| 1390 | 1389 |
| 1391 // Name on Card. | 1390 // Name on Card. |
| 1392 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 1391 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
| 1393 // Address. | 1392 // Address. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 form.fields.push_back(field); | 1425 form.fields.push_back(field); |
| 1427 | 1426 |
| 1428 field.label = string16(); | 1427 field.label = string16(); |
| 1429 field.name = ASCIIToUTF16("ccexpiresyear"); | 1428 field.name = ASCIIToUTF16("ccexpiresyear"); |
| 1430 form.fields.push_back(field); | 1429 form.fields.push_back(field); |
| 1431 | 1430 |
| 1432 field.label = ASCIIToUTF16("cvc number"); | 1431 field.label = ASCIIToUTF16("cvc number"); |
| 1433 field.name = ASCIIToUTF16("csc"); | 1432 field.name = ASCIIToUTF16("csc"); |
| 1434 form.fields.push_back(field); | 1433 form.fields.push_back(field); |
| 1435 | 1434 |
| 1436 form_structure.reset(new FormStructure(form)); | 1435 form_structure.reset(new FormStructure(form, false)); |
| 1437 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1436 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1438 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1437 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1439 | 1438 |
| 1440 // Expect the correct number of fields. | 1439 // Expect the correct number of fields. |
| 1441 ASSERT_EQ(6U, form_structure->field_count()); | 1440 ASSERT_EQ(6U, form_structure->field_count()); |
| 1442 ASSERT_EQ(5U, form_structure->autofill_count()); | 1441 ASSERT_EQ(5U, form_structure->autofill_count()); |
| 1443 | 1442 |
| 1444 // Card Number. | 1443 // Card Number. |
| 1445 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); | 1444 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); |
| 1446 // First name, taken as name on card. | 1445 // First name, taken as name on card. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 form.fields.push_back(field); | 1484 form.fields.push_back(field); |
| 1486 | 1485 |
| 1487 // Add checkable field. | 1486 // Add checkable field. |
| 1488 FormFieldData checkable_field; | 1487 FormFieldData checkable_field; |
| 1489 checkable_field.is_checkable = true; | 1488 checkable_field.is_checkable = true; |
| 1490 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1489 checkable_field.label = ASCIIToUTF16("Checkable1"); |
| 1491 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1490 checkable_field.name = ASCIIToUTF16("Checkable1"); |
| 1492 form.fields.push_back(checkable_field); | 1491 form.fields.push_back(checkable_field); |
| 1493 | 1492 |
| 1494 ScopedVector<FormStructure> forms; | 1493 ScopedVector<FormStructure> forms; |
| 1495 forms.push_back(new FormStructure(form)); | 1494 forms.push_back(new FormStructure(form, false)); |
| 1496 std::vector<std::string> encoded_signatures; | 1495 std::vector<std::string> encoded_signatures; |
| 1497 std::string encoded_xml; | 1496 std::string encoded_xml; |
| 1498 const char * const kSignature1 = "11337937696949187602"; | 1497 const char * const kSignature1 = "11337937696949187602"; |
| 1499 const char * const kResponse1 = | 1498 const char * const kResponse1 = |
| 1500 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " | 1499 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " |
| 1501 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 1500 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
| 1502 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" | 1501 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" |
| 1503 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" | 1502 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" |
| 1504 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" | 1503 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" |
| 1505 "</autofillquery>"; | 1504 "</autofillquery>"; |
| 1506 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1505 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1507 &encoded_signatures, | 1506 &encoded_signatures, |
| 1508 &encoded_xml)); | 1507 &encoded_xml)); |
| 1509 ASSERT_EQ(1U, encoded_signatures.size()); | 1508 ASSERT_EQ(1U, encoded_signatures.size()); |
| 1510 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1509 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1511 EXPECT_EQ(kResponse1, encoded_xml); | 1510 EXPECT_EQ(kResponse1, encoded_xml); |
| 1512 | 1511 |
| 1513 // Add the same form, only one will be encoded, so EncodeQueryRequest() should | 1512 // Add the same form, only one will be encoded, so EncodeQueryRequest() should |
| 1514 // return the same data. | 1513 // return the same data. |
| 1515 forms.push_back(new FormStructure(form)); | 1514 forms.push_back(new FormStructure(form, false)); |
| 1516 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1515 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1517 &encoded_signatures, | 1516 &encoded_signatures, |
| 1518 &encoded_xml)); | 1517 &encoded_xml)); |
| 1519 ASSERT_EQ(1U, encoded_signatures.size()); | 1518 ASSERT_EQ(1U, encoded_signatures.size()); |
| 1520 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1519 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1521 EXPECT_EQ(kResponse1, encoded_xml); | 1520 EXPECT_EQ(kResponse1, encoded_xml); |
| 1522 // Add 5 address fields - this should be still a valid form. | 1521 // Add 5 address fields - this should be still a valid form. |
| 1523 for (size_t i = 0; i < 5; ++i) { | 1522 for (size_t i = 0; i < 5; ++i) { |
| 1524 field.label = ASCIIToUTF16("Address"); | 1523 field.label = ASCIIToUTF16("Address"); |
| 1525 field.name = ASCIIToUTF16("address"); | 1524 field.name = ASCIIToUTF16("address"); |
| 1526 form.fields.push_back(field); | 1525 form.fields.push_back(field); |
| 1527 } | 1526 } |
| 1528 | 1527 |
| 1529 forms.push_back(new FormStructure(form)); | 1528 forms.push_back(new FormStructure(form, false)); |
| 1530 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1529 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1531 &encoded_signatures, | 1530 &encoded_signatures, |
| 1532 &encoded_xml)); | 1531 &encoded_xml)); |
| 1533 ASSERT_EQ(2U, encoded_signatures.size()); | 1532 ASSERT_EQ(2U, encoded_signatures.size()); |
| 1534 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1533 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1535 const char * const kSignature2 = "8308881815906226214"; | 1534 const char * const kSignature2 = "8308881815906226214"; |
| 1536 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1535 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
| 1537 const char * const kResponse2 = | 1536 const char * const kResponse2 = |
| 1538 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " | 1537 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " |
| 1539 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 1538 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1550 | 1549 |
| 1551 FormData malformed_form(form); | 1550 FormData malformed_form(form); |
| 1552 // Add 50 address fields - the form is not valid anymore, but previous ones | 1551 // Add 50 address fields - the form is not valid anymore, but previous ones |
| 1553 // are. The result should be the same as in previous test. | 1552 // are. The result should be the same as in previous test. |
| 1554 for (size_t i = 0; i < 50; ++i) { | 1553 for (size_t i = 0; i < 50; ++i) { |
| 1555 field.label = ASCIIToUTF16("Address"); | 1554 field.label = ASCIIToUTF16("Address"); |
| 1556 field.name = ASCIIToUTF16("address"); | 1555 field.name = ASCIIToUTF16("address"); |
| 1557 malformed_form.fields.push_back(field); | 1556 malformed_form.fields.push_back(field); |
| 1558 } | 1557 } |
| 1559 | 1558 |
| 1560 forms.push_back(new FormStructure(malformed_form)); | 1559 forms.push_back(new FormStructure(malformed_form, false)); |
| 1561 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1560 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1562 &encoded_signatures, | 1561 &encoded_signatures, |
| 1563 &encoded_xml)); | 1562 &encoded_xml)); |
| 1564 ASSERT_EQ(2U, encoded_signatures.size()); | 1563 ASSERT_EQ(2U, encoded_signatures.size()); |
| 1565 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1564 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1566 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1565 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
| 1567 EXPECT_EQ(kResponse2, encoded_xml); | 1566 EXPECT_EQ(kResponse2, encoded_xml); |
| 1568 | 1567 |
| 1569 // Check that we fail if there are only bad form(s). | 1568 // Check that we fail if there are only bad form(s). |
| 1570 ScopedVector<FormStructure> bad_forms; | 1569 ScopedVector<FormStructure> bad_forms; |
| 1571 bad_forms.push_back(new FormStructure(malformed_form)); | 1570 bad_forms.push_back(new FormStructure(malformed_form, false)); |
| 1572 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), | 1571 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), |
| 1573 &encoded_signatures, | 1572 &encoded_signatures, |
| 1574 &encoded_xml)); | 1573 &encoded_xml)); |
| 1575 EXPECT_EQ(0U, encoded_signatures.size()); | 1574 EXPECT_EQ(0U, encoded_signatures.size()); |
| 1576 EXPECT_EQ("", encoded_xml); | 1575 EXPECT_EQ("", encoded_xml); |
| 1577 | 1576 |
| 1578 // Check the behaviour with kEnableExperimentalFormFilling switch on. | 1577 // Check the behaviour with kEnableExperimentalFormFilling switch on. |
| 1579 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1580 switches::kEnableExperimentalFormFilling); | |
| 1581 // Add the previous form but with flag set. | 1578 // Add the previous form but with flag set. |
| 1582 ScopedVector<FormStructure> checkable_forms; | 1579 ScopedVector<FormStructure> checkable_forms; |
| 1583 checkable_forms.push_back(new FormStructure(form)); | 1580 checkable_forms.push_back(new FormStructure(form, true)); |
| 1584 | 1581 |
| 1585 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), | 1582 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), |
| 1586 &encoded_signatures, | 1583 &encoded_signatures, |
| 1587 &encoded_xml)); | 1584 &encoded_xml)); |
| 1588 const char * const kSignature3 = "7747357776717901584"; | 1585 const char * const kSignature3 = "7747357776717901584"; |
| 1589 const char * const kResponse3 = | 1586 const char * const kResponse3 = |
| 1590 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " | 1587 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " |
| 1591 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\">" | 1588 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\">" |
| 1592 "<form signature=\"7747357776717901584\"><field signature=\"412125936\"/>" | 1589 "<form signature=\"7747357776717901584\"><field signature=\"412125936\"/>" |
| 1593 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" | 1590 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" |
| 1594 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " | 1591 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " |
| 1595 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " | 1592 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " |
| 1596 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | 1593 "signature=\"509334676\"/><field signature=\"509334676\"/><field " |
| 1597 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" | 1594 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" |
| 1598 "</autofillquery>"; | 1595 "</autofillquery>"; |
| 1599 ASSERT_EQ(1U, encoded_signatures.size()); | 1596 ASSERT_EQ(1U, encoded_signatures.size()); |
| 1600 EXPECT_EQ(kSignature3, encoded_signatures[0]); | 1597 EXPECT_EQ(kSignature3, encoded_signatures[0]); |
| 1601 EXPECT_EQ(kResponse3, encoded_xml); | 1598 EXPECT_EQ(kResponse3, encoded_xml); |
| 1602 } | 1599 } |
| 1603 | 1600 |
| 1604 TEST(FormStructureTest, EncodeUploadRequest) { | 1601 TEST(FormStructureTest, EncodeUploadRequest) { |
| 1605 scoped_ptr<FormStructure> form_structure; | 1602 scoped_ptr<FormStructure> form_structure; |
| 1606 std::vector<FieldTypeSet> possible_field_types; | 1603 std::vector<FieldTypeSet> possible_field_types; |
| 1607 FormData form; | 1604 FormData form; |
| 1608 form.method = ASCIIToUTF16("post"); | 1605 form.method = ASCIIToUTF16("post"); |
| 1609 form_structure.reset(new FormStructure(form)); | 1606 form_structure.reset(new FormStructure(form, false)); |
| 1610 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1607 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1611 | 1608 |
| 1612 FormFieldData field; | 1609 FormFieldData field; |
| 1613 field.form_control_type = "text"; | 1610 field.form_control_type = "text"; |
| 1614 | 1611 |
| 1615 field.label = ASCIIToUTF16("First Name"); | 1612 field.label = ASCIIToUTF16("First Name"); |
| 1616 field.name = ASCIIToUTF16("firstname"); | 1613 field.name = ASCIIToUTF16("firstname"); |
| 1617 form.fields.push_back(field); | 1614 form.fields.push_back(field); |
| 1618 possible_field_types.push_back(FieldTypeSet()); | 1615 possible_field_types.push_back(FieldTypeSet()); |
| 1619 possible_field_types.back().insert(NAME_FIRST); | 1616 possible_field_types.back().insert(NAME_FIRST); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1647 | 1644 |
| 1648 // Add checkable field. | 1645 // Add checkable field. |
| 1649 FormFieldData checkable_field; | 1646 FormFieldData checkable_field; |
| 1650 checkable_field.is_checkable = true; | 1647 checkable_field.is_checkable = true; |
| 1651 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1648 checkable_field.label = ASCIIToUTF16("Checkable1"); |
| 1652 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1649 checkable_field.name = ASCIIToUTF16("Checkable1"); |
| 1653 form.fields.push_back(checkable_field); | 1650 form.fields.push_back(checkable_field); |
| 1654 possible_field_types.push_back(FieldTypeSet()); | 1651 possible_field_types.push_back(FieldTypeSet()); |
| 1655 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); | 1652 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); |
| 1656 | 1653 |
| 1657 form_structure.reset(new FormStructure(form)); | 1654 form_structure.reset(new FormStructure(form, false)); |
| 1658 | 1655 |
| 1659 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1656 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1660 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1657 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1661 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1658 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1662 | 1659 |
| 1663 FieldTypeSet available_field_types; | 1660 FieldTypeSet available_field_types; |
| 1664 available_field_types.insert(NAME_FIRST); | 1661 available_field_types.insert(NAME_FIRST); |
| 1665 available_field_types.insert(NAME_LAST); | 1662 available_field_types.insert(NAME_LAST); |
| 1666 available_field_types.insert(ADDRESS_HOME_LINE1); | 1663 available_field_types.insert(ADDRESS_HOME_LINE1); |
| 1667 available_field_types.insert(ADDRESS_HOME_LINE2); | 1664 available_field_types.insert(ADDRESS_HOME_LINE2); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 field.name = ASCIIToUTF16("address"); | 1702 field.name = ASCIIToUTF16("address"); |
| 1706 field.form_control_type = "text"; | 1703 field.form_control_type = "text"; |
| 1707 form.fields.push_back(field); | 1704 form.fields.push_back(field); |
| 1708 possible_field_types.push_back(FieldTypeSet()); | 1705 possible_field_types.push_back(FieldTypeSet()); |
| 1709 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 1706 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| 1710 possible_field_types.back().insert(ADDRESS_HOME_LINE2); | 1707 possible_field_types.back().insert(ADDRESS_HOME_LINE2); |
| 1711 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); | 1708 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); |
| 1712 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1709 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
| 1713 } | 1710 } |
| 1714 | 1711 |
| 1715 form_structure.reset(new FormStructure(form)); | 1712 form_structure.reset(new FormStructure(form, false)); |
| 1716 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1713 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1717 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1714 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1718 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1715 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1719 | 1716 |
| 1720 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, | 1717 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, |
| 1721 &encoded_xml)); | 1718 &encoded_xml)); |
| 1722 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" | 1719 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" |
| 1723 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " | 1720 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " |
| 1724 "formsignature=\"7816485729218079147\" autofillused=\"false\" " | 1721 "formsignature=\"7816485729218079147\" autofillused=\"false\" " |
| 1725 "datapresent=\"144200030e\">" | 1722 "datapresent=\"144200030e\">" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1744 field.label = ASCIIToUTF16("Address"); | 1741 field.label = ASCIIToUTF16("Address"); |
| 1745 field.name = ASCIIToUTF16("address"); | 1742 field.name = ASCIIToUTF16("address"); |
| 1746 field.form_control_type = "text"; | 1743 field.form_control_type = "text"; |
| 1747 form.fields.push_back(field); | 1744 form.fields.push_back(field); |
| 1748 possible_field_types.push_back(FieldTypeSet()); | 1745 possible_field_types.push_back(FieldTypeSet()); |
| 1749 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 1746 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| 1750 possible_field_types.back().insert(ADDRESS_HOME_LINE2); | 1747 possible_field_types.back().insert(ADDRESS_HOME_LINE2); |
| 1751 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); | 1748 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); |
| 1752 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1749 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
| 1753 } | 1750 } |
| 1754 form_structure.reset(new FormStructure(form)); | 1751 form_structure.reset(new FormStructure(form, false)); |
| 1755 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1752 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1756 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1753 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1757 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1754 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1758 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, | 1755 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, |
| 1759 &encoded_xml)); | 1756 &encoded_xml)); |
| 1760 } | 1757 } |
| 1761 | 1758 |
| 1762 // Check that we compute the "datapresent" string correctly for the given | 1759 // Check that we compute the "datapresent" string correctly for the given |
| 1763 // |available_types|. | 1760 // |available_types|. |
| 1764 TEST(FormStructureTest, CheckDataPresence) { | 1761 TEST(FormStructureTest, CheckDataPresence) { |
| 1765 FormData form; | 1762 FormData form; |
| 1766 form.method = ASCIIToUTF16("post"); | 1763 form.method = ASCIIToUTF16("post"); |
| 1767 | 1764 |
| 1768 FormFieldData field; | 1765 FormFieldData field; |
| 1769 field.form_control_type = "text"; | 1766 field.form_control_type = "text"; |
| 1770 | 1767 |
| 1771 field.label = ASCIIToUTF16("First Name"); | 1768 field.label = ASCIIToUTF16("First Name"); |
| 1772 field.name = ASCIIToUTF16("first"); | 1769 field.name = ASCIIToUTF16("first"); |
| 1773 form.fields.push_back(field); | 1770 form.fields.push_back(field); |
| 1774 | 1771 |
| 1775 field.label = ASCIIToUTF16("Last Name"); | 1772 field.label = ASCIIToUTF16("Last Name"); |
| 1776 field.name = ASCIIToUTF16("last"); | 1773 field.name = ASCIIToUTF16("last"); |
| 1777 form.fields.push_back(field); | 1774 form.fields.push_back(field); |
| 1778 | 1775 |
| 1779 field.label = ASCIIToUTF16("Email"); | 1776 field.label = ASCIIToUTF16("Email"); |
| 1780 field.name = ASCIIToUTF16("email"); | 1777 field.name = ASCIIToUTF16("email"); |
| 1781 form.fields.push_back(field); | 1778 form.fields.push_back(field); |
| 1782 | 1779 |
| 1783 FormStructure form_structure(form); | 1780 FormStructure form_structure(form, false); |
| 1784 | 1781 |
| 1785 FieldTypeSet unknown_type; | 1782 FieldTypeSet unknown_type; |
| 1786 unknown_type.insert(UNKNOWN_TYPE); | 1783 unknown_type.insert(UNKNOWN_TYPE); |
| 1787 for (size_t i = 0; i < form_structure.field_count(); ++i) | 1784 for (size_t i = 0; i < form_structure.field_count(); ++i) |
| 1788 form_structure.field(i)->set_possible_types(unknown_type); | 1785 form_structure.field(i)->set_possible_types(unknown_type); |
| 1789 | 1786 |
| 1790 // No available types. | 1787 // No available types. |
| 1791 // datapresent should be "" == trimmmed(0x0000000000000000) == | 1788 // datapresent should be "" == trimmmed(0x0000000000000000) == |
| 1792 // 0b0000000000000000000000000000000000000000000000000000000000000000 | 1789 // 0b0000000000000000000000000000000000000000000000000000000000000000 |
| 1793 FieldTypeSet available_field_types; | 1790 FieldTypeSet available_field_types; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 form.fields.push_back(field); | 2036 form.fields.push_back(field); |
| 2040 possible_field_types.push_back(FieldTypeSet()); | 2037 possible_field_types.push_back(FieldTypeSet()); |
| 2041 possible_field_types.back().insert(NAME_LAST); | 2038 possible_field_types.back().insert(NAME_LAST); |
| 2042 | 2039 |
| 2043 field.label = ASCIIToUTF16("Address"); | 2040 field.label = ASCIIToUTF16("Address"); |
| 2044 field.name = ASCIIToUTF16("address"); | 2041 field.name = ASCIIToUTF16("address"); |
| 2045 form.fields.push_back(field); | 2042 form.fields.push_back(field); |
| 2046 possible_field_types.push_back(FieldTypeSet()); | 2043 possible_field_types.push_back(FieldTypeSet()); |
| 2047 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 2044 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| 2048 | 2045 |
| 2049 form_structure.reset(new FormStructure(form)); | 2046 form_structure.reset(new FormStructure(form, false)); |
| 2050 | 2047 |
| 2051 for (size_t i = 0; i < form_structure->field_count(); ++i) | 2048 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 2052 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 2049 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 2053 std::string encoded_xml; | 2050 std::string encoded_xml; |
| 2054 | 2051 |
| 2055 // Now we matched both fields singularly. | 2052 // Now we matched both fields singularly. |
| 2056 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, | 2053 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, |
| 2057 &encoded_xml)); | 2054 &encoded_xml)); |
| 2058 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" | 2055 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" |
| 2059 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" | 2056 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 field.form_control_type = "text"; | 2126 field.form_control_type = "text"; |
| 2130 | 2127 |
| 2131 field.label = ASCIIToUTF16("email"); | 2128 field.label = ASCIIToUTF16("email"); |
| 2132 field.name = ASCIIToUTF16("email"); | 2129 field.name = ASCIIToUTF16("email"); |
| 2133 form.fields.push_back(field); | 2130 form.fields.push_back(field); |
| 2134 | 2131 |
| 2135 field.label = ASCIIToUTF16("First Name"); | 2132 field.label = ASCIIToUTF16("First Name"); |
| 2136 field.name = ASCIIToUTF16("first"); | 2133 field.name = ASCIIToUTF16("first"); |
| 2137 form.fields.push_back(field); | 2134 form.fields.push_back(field); |
| 2138 | 2135 |
| 2139 form_structure.reset(new FormStructure(form)); | 2136 form_structure.reset(new FormStructure(form, false)); |
| 2140 | 2137 |
| 2141 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2138 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2142 std::string("://&&email&first")), | 2139 std::string("://&&email&first")), |
| 2143 form_structure->FormSignature()); | 2140 form_structure->FormSignature()); |
| 2144 | 2141 |
| 2145 form.origin = GURL(std::string("http://www.facebook.com")); | 2142 form.origin = GURL(std::string("http://www.facebook.com")); |
| 2146 form_structure.reset(new FormStructure(form)); | 2143 form_structure.reset(new FormStructure(form, false)); |
| 2147 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2144 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2148 std::string("http://www.facebook.com&&email&first")), | 2145 std::string("http://www.facebook.com&&email&first")), |
| 2149 form_structure->FormSignature()); | 2146 form_structure->FormSignature()); |
| 2150 | 2147 |
| 2151 form.action = GURL(std::string("https://login.facebook.com/path")); | 2148 form.action = GURL(std::string("https://login.facebook.com/path")); |
| 2152 form_structure.reset(new FormStructure(form)); | 2149 form_structure.reset(new FormStructure(form, false)); |
| 2153 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2150 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2154 std::string("https://login.facebook.com&&email&first")), | 2151 std::string("https://login.facebook.com&&email&first")), |
| 2155 form_structure->FormSignature()); | 2152 form_structure->FormSignature()); |
| 2156 | 2153 |
| 2157 form.name = ASCIIToUTF16("login_form"); | 2154 form.name = ASCIIToUTF16("login_form"); |
| 2158 form_structure.reset(new FormStructure(form)); | 2155 form_structure.reset(new FormStructure(form, false)); |
| 2159 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2156 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2160 std::string("https://login.facebook.com&login_form&email&first")), | 2157 std::string("https://login.facebook.com&login_form&email&first")), |
| 2161 form_structure->FormSignature()); | 2158 form_structure->FormSignature()); |
| 2162 } | 2159 } |
| 2163 | 2160 |
| 2164 TEST(FormStructureTest, ToFormData) { | 2161 TEST(FormStructureTest, ToFormData) { |
| 2165 FormData form; | 2162 FormData form; |
| 2166 form.name = ASCIIToUTF16("the-name"); | 2163 form.name = ASCIIToUTF16("the-name"); |
| 2167 form.method = ASCIIToUTF16("POST"); | 2164 form.method = ASCIIToUTF16("POST"); |
| 2168 form.origin = GURL("http://cool.com"); | 2165 form.origin = GURL("http://cool.com"); |
| 2169 form.action = form.origin.Resolve("/login"); | 2166 form.action = form.origin.Resolve("/login"); |
| 2170 | 2167 |
| 2171 FormFieldData field; | 2168 FormFieldData field; |
| 2172 field.label = ASCIIToUTF16("username"); | 2169 field.label = ASCIIToUTF16("username"); |
| 2173 field.name = ASCIIToUTF16("username"); | 2170 field.name = ASCIIToUTF16("username"); |
| 2174 field.form_control_type = "text"; | 2171 field.form_control_type = "text"; |
| 2175 form.fields.push_back(field); | 2172 form.fields.push_back(field); |
| 2176 | 2173 |
| 2177 field.label = ASCIIToUTF16("password"); | 2174 field.label = ASCIIToUTF16("password"); |
| 2178 field.name = ASCIIToUTF16("password"); | 2175 field.name = ASCIIToUTF16("password"); |
| 2179 field.form_control_type = "password"; | 2176 field.form_control_type = "password"; |
| 2180 form.fields.push_back(field); | 2177 form.fields.push_back(field); |
| 2181 | 2178 |
| 2182 field.label = string16(); | 2179 field.label = string16(); |
| 2183 field.name = ASCIIToUTF16("Submit"); | 2180 field.name = ASCIIToUTF16("Submit"); |
| 2184 field.form_control_type = "submit"; | 2181 field.form_control_type = "submit"; |
| 2185 form.fields.push_back(field); | 2182 form.fields.push_back(field); |
| 2186 | 2183 |
| 2187 EXPECT_EQ(form, FormStructure(form).ToFormData()); | 2184 EXPECT_EQ(form, FormStructure(form, false).ToFormData()); |
| 2188 | 2185 |
| 2189 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always | 2186 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always |
| 2190 // false. This forces a future author that changes this to update this test. | 2187 // false. This forces a future author that changes this to update this test. |
| 2191 form.user_submitted = true; | 2188 form.user_submitted = true; |
| 2192 EXPECT_NE(form, FormStructure(form).ToFormData()); | 2189 EXPECT_NE(form, FormStructure(form, false).ToFormData()); |
| 2193 } | 2190 } |
| OLD | NEW |