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 "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 "chrome/common/form_data.h" | 9 #include "chrome/common/form_data.h" |
10 #include "chrome/common/form_field_data.h" | 10 #include "chrome/common/form_field_data.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 // Address. | 322 // Address. |
323 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); | 323 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); |
324 // City. | 324 // City. |
325 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); | 325 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); |
326 // Zip. | 326 // Zip. |
327 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); | 327 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); |
328 // Submit. | 328 // Submit. |
329 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); | 329 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); |
330 } | 330 } |
331 | 331 |
332 // Verify that we can correctly process the |autocompletetype| attribute. | 332 // Verify that we can correctly process the |autocomplete| attribute. |
333 TEST(FormStructureTest, HeuristicsAutocompletetype) { | 333 TEST(FormStructureTest, HeuristicsAutocompleteAttribute) { |
334 scoped_ptr<FormStructure> form_structure; | 334 scoped_ptr<FormStructure> form_structure; |
335 FormData form; | 335 FormData form; |
336 form.method = ASCIIToUTF16("post"); | 336 form.method = ASCIIToUTF16("post"); |
337 | 337 |
338 FormFieldData field; | 338 FormFieldData field; |
339 field.form_control_type = ASCIIToUTF16("text"); | 339 field.form_control_type = ASCIIToUTF16("text"); |
340 | 340 |
341 field.label = string16(); | 341 field.label = string16(); |
342 field.name = ASCIIToUTF16("field1"); | 342 field.name = ASCIIToUTF16("field1"); |
343 field.autocomplete_type = ASCIIToUTF16("given-name"); | 343 field.autocomplete_attribute = ASCIIToUTF16("given-name"); |
344 form.fields.push_back(field); | 344 form.fields.push_back(field); |
345 | 345 |
346 field.label = string16(); | 346 field.label = string16(); |
347 field.name = ASCIIToUTF16("field2"); | 347 field.name = ASCIIToUTF16("field2"); |
348 field.autocomplete_type = ASCIIToUTF16("surname"); | 348 field.autocomplete_attribute = ASCIIToUTF16("family-name"); |
349 form.fields.push_back(field); | 349 form.fields.push_back(field); |
350 | 350 |
351 field.label = string16(); | 351 field.label = string16(); |
352 field.name = ASCIIToUTF16("field3"); | 352 field.name = ASCIIToUTF16("field3"); |
353 field.autocomplete_type = ASCIIToUTF16("email"); | 353 field.autocomplete_attribute = ASCIIToUTF16("email"); |
354 form.fields.push_back(field); | 354 form.fields.push_back(field); |
355 | 355 |
356 form_structure.reset(new FormStructure(form)); | 356 form_structure.reset(new FormStructure(form)); |
357 form_structure->DetermineHeuristicTypes(); | 357 form_structure->DetermineHeuristicTypes(); |
358 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 358 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
359 | 359 |
360 // Expect the correct number of fields. | 360 // Expect the correct number of fields. |
361 ASSERT_EQ(3U, form_structure->field_count()); | 361 ASSERT_EQ(3U, form_structure->field_count()); |
362 ASSERT_EQ(3U, form_structure->autofill_count()); | 362 ASSERT_EQ(3U, form_structure->autofill_count()); |
363 | 363 |
364 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 364 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
365 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 365 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
366 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 366 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
367 } | 367 } |
368 | 368 |
369 // Verify that we can correctly process the |autocompletetype| attribute for | 369 // Verify that we can correctly process the 'autocomplete' attribute for phone |
370 // phone number types (especially phone prefixes and suffixes). | 370 // number types (especially phone prefixes and suffixes). |
371 TEST(FormStructureTest, HeuristicsAutocompletetypePhones) { | 371 TEST(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { |
372 scoped_ptr<FormStructure> form_structure; | 372 scoped_ptr<FormStructure> form_structure; |
373 FormData form; | 373 FormData form; |
374 form.method = ASCIIToUTF16("post"); | 374 form.method = ASCIIToUTF16("post"); |
375 | 375 |
376 FormFieldData field; | 376 FormFieldData field; |
377 field.form_control_type = ASCIIToUTF16("text"); | 377 field.form_control_type = ASCIIToUTF16("text"); |
378 | 378 |
379 field.label = string16(); | 379 field.label = string16(); |
380 field.name = ASCIIToUTF16("field1"); | 380 field.name = ASCIIToUTF16("field1"); |
381 field.autocomplete_type = ASCIIToUTF16("phone-local"); | 381 field.autocomplete_attribute = ASCIIToUTF16("tel-local"); |
382 form.fields.push_back(field); | 382 form.fields.push_back(field); |
383 | 383 |
384 field.label = string16(); | 384 field.label = string16(); |
385 field.name = ASCIIToUTF16("field2"); | 385 field.name = ASCIIToUTF16("field2"); |
386 field.autocomplete_type = ASCIIToUTF16("phone-local-prefix"); | 386 field.autocomplete_attribute = ASCIIToUTF16("tel-local-prefix"); |
387 form.fields.push_back(field); | 387 form.fields.push_back(field); |
388 | 388 |
389 field.label = string16(); | 389 field.label = string16(); |
390 field.name = ASCIIToUTF16("field3"); | 390 field.name = ASCIIToUTF16("field3"); |
391 field.autocomplete_type = ASCIIToUTF16("phone-local-suffix"); | 391 field.autocomplete_attribute = ASCIIToUTF16("tel-local-suffix"); |
392 form.fields.push_back(field); | 392 form.fields.push_back(field); |
393 | 393 |
394 form_structure.reset(new FormStructure(form)); | 394 form_structure.reset(new FormStructure(form)); |
395 form_structure->DetermineHeuristicTypes(); | 395 form_structure->DetermineHeuristicTypes(); |
396 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 396 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
397 | 397 |
398 // Expect the correct number of fields. | 398 // Expect the correct number of fields. |
399 ASSERT_EQ(3U, form_structure->field_count()); | 399 ASSERT_EQ(3U, form_structure->field_count()); |
400 EXPECT_EQ(3U, form_structure->autofill_count()); | 400 EXPECT_EQ(3U, form_structure->autofill_count()); |
401 | 401 |
402 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(0)->heuristic_type()); | 402 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(0)->heuristic_type()); |
403 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); | 403 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); |
404 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(1)->heuristic_type()); | 404 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(1)->heuristic_type()); |
405 EXPECT_EQ(AutofillField::PHONE_PREFIX, | 405 EXPECT_EQ(AutofillField::PHONE_PREFIX, |
406 form_structure->field(1)->phone_part()); | 406 form_structure->field(1)->phone_part()); |
407 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(2)->heuristic_type()); | 407 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(2)->heuristic_type()); |
408 EXPECT_EQ(AutofillField::PHONE_SUFFIX, | 408 EXPECT_EQ(AutofillField::PHONE_SUFFIX, |
409 form_structure->field(2)->phone_part()); | 409 form_structure->field(2)->phone_part()); |
410 } | 410 } |
411 | 411 |
412 // If at least one field includes the |autocompletetype| attribute, we should | 412 // If at least one field includes type hints in the 'autocomplete' attribute, we |
413 // not try to apply any other heuristics. | 413 // should not try to apply any other heuristics. |
414 TEST(FormStructureTest, AutocompletetypeOverridesOtherHeuristics) { | 414 TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) { |
415 scoped_ptr<FormStructure> form_structure; | 415 scoped_ptr<FormStructure> form_structure; |
416 FormData form; | 416 FormData form; |
417 form.method = ASCIIToUTF16("post"); | 417 form.method = ASCIIToUTF16("post"); |
418 | 418 |
419 // Start with a regular contact form. | 419 // Start with a regular contact form. |
420 FormFieldData field; | 420 FormFieldData field; |
421 field.form_control_type = ASCIIToUTF16("text"); | 421 field.form_control_type = ASCIIToUTF16("text"); |
422 | 422 |
423 field.label = ASCIIToUTF16("First Name"); | 423 field.label = ASCIIToUTF16("First Name"); |
424 field.name = ASCIIToUTF16("firstname"); | 424 field.name = ASCIIToUTF16("firstname"); |
(...skipping 12 matching lines...) Expand all Loading... |
437 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 437 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
438 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); | 438 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); |
439 | 439 |
440 ASSERT_EQ(3U, form_structure->field_count()); | 440 ASSERT_EQ(3U, form_structure->field_count()); |
441 ASSERT_EQ(3U, form_structure->autofill_count()); | 441 ASSERT_EQ(3U, form_structure->autofill_count()); |
442 | 442 |
443 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 443 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
444 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 444 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
445 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 445 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
446 | 446 |
447 // Now update the first form field to include an 'autocompletetype' attribute. | 447 // Now update the first form field to include an 'autocomplete' attribute. |
448 form.fields.front().autocomplete_type = ASCIIToUTF16("x-other"); | 448 form.fields.front().autocomplete_attribute = ASCIIToUTF16("x-other"); |
449 form_structure.reset(new FormStructure(form)); | 449 form_structure.reset(new FormStructure(form)); |
450 form_structure->DetermineHeuristicTypes(); | 450 form_structure->DetermineHeuristicTypes(); |
451 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 451 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
452 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); | 452 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); |
453 | 453 |
454 ASSERT_EQ(3U, form_structure->field_count()); | 454 ASSERT_EQ(3U, form_structure->field_count()); |
455 ASSERT_EQ(0U, form_structure->autofill_count()); | 455 ASSERT_EQ(0U, form_structure->autofill_count()); |
456 | 456 |
457 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | 457 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
458 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 458 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
459 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 459 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
460 } | 460 } |
461 | 461 |
462 // Verify that we can correctly process sections listed in the |autocomplete| | 462 // Verify that we can correctly process sections listed in the |autocomplete| |
463 // attribute. | 463 // attribute. |
464 TEST(FormStructureTest, HeuristicsAutocompletetypeWithSections) { | 464 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { |
465 scoped_ptr<FormStructure> form_structure; | |
466 FormData form; | 465 FormData form; |
467 form.method = ASCIIToUTF16("post"); | 466 form.method = ASCIIToUTF16("post"); |
468 | 467 |
469 FormFieldData field; | 468 FormFieldData field; |
470 field.form_control_type = ASCIIToUTF16("text"); | 469 field.form_control_type = ASCIIToUTF16("text"); |
471 | 470 |
472 // We expect "shipping" and "billing" to be the most common sections. | 471 // Some fields will have no section specified. These fall into the default |
473 field.label = string16(); | 472 // section. |
474 field.name = ASCIIToUTF16("field1"); | 473 field.autocomplete_attribute = ASCIIToUTF16("email"); |
475 field.autocomplete_type = ASCIIToUTF16("section-shipping given-name"); | |
476 form.fields.push_back(field); | |
477 | |
478 // Some field will have no section specified. These fall into the default | |
479 // section, with an empty name. | |
480 field.label = string16(); | |
481 field.name = ASCIIToUTF16("field2"); | |
482 field.autocomplete_type = ASCIIToUTF16("surname"); | |
483 form.fields.push_back(field); | 474 form.fields.push_back(field); |
484 | 475 |
485 // We allow arbitrary section names. | 476 // We allow arbitrary section names. |
486 field.label = string16(); | 477 field.autocomplete_attribute = ASCIIToUTF16("section-foo email"); |
487 field.name = ASCIIToUTF16("field3"); | |
488 field.autocomplete_type = ASCIIToUTF16("section-foo address-line1"); | |
489 form.fields.push_back(field); | 478 form.fields.push_back(field); |
490 | 479 |
491 // Specifying "section-" is equivalent to not specifying a section. | 480 // "shipping" and "billing" are special section tokens that don't require the |
492 field.label = string16(); | 481 // "section-" prefix. |
493 field.name = ASCIIToUTF16("field4"); | 482 field.autocomplete_attribute = ASCIIToUTF16("shipping email"); |
494 field.autocomplete_type = ASCIIToUTF16("section- address-line2"); | 483 form.fields.push_back(field); |
| 484 field.autocomplete_attribute = ASCIIToUTF16("billing email"); |
| 485 form.fields.push_back(field); |
| 486 |
| 487 // "shipping" and "billing" can be combined with other section names. |
| 488 field.autocomplete_attribute = ASCIIToUTF16("section-foo shipping email"); |
| 489 form.fields.push_back(field); |
| 490 field.autocomplete_attribute = ASCIIToUTF16("section-foo billing email"); |
495 form.fields.push_back(field); | 491 form.fields.push_back(field); |
496 | 492 |
497 // We don't do anything clever to try to coalesce sections; it's up to site | 493 // We don't do anything clever to try to coalesce sections; it's up to site |
498 // authors to avoid typos. | 494 // authors to avoid typos. |
499 field.label = string16(); | 495 field.autocomplete_attribute = ASCIIToUTF16("section--foo email"); |
500 field.name = ASCIIToUTF16("field5"); | 496 form.fields.push_back(field); |
501 field.autocomplete_type = ASCIIToUTF16("section--shipping locality"); | 497 |
| 498 // "shipping email" and "section--shipping" email should be parsed as |
| 499 // different sections. This is only an interesting test due to how we |
| 500 // implement implicit section names from attributes like "shipping email"; see |
| 501 // the implementation for more details. |
| 502 field.autocomplete_attribute = ASCIIToUTF16("section--shipping email"); |
502 form.fields.push_back(field); | 503 form.fields.push_back(field); |
503 | 504 |
504 // Credit card fields are implicitly in a separate section from other fields. | 505 // Credit card fields are implicitly in a separate section from other fields. |
505 field.label = string16(); | 506 field.autocomplete_attribute = ASCIIToUTF16("section-foo cc-number"); |
506 field.name = ASCIIToUTF16("field6"); | |
507 field.autocomplete_type = ASCIIToUTF16("section-shipping cc-number"); | |
508 form.fields.push_back(field); | 507 form.fields.push_back(field); |
509 | 508 |
510 form_structure.reset(new FormStructure(form)); | 509 FormStructure form_structure(form); |
511 form_structure->DetermineHeuristicTypes(); | 510 form_structure.DetermineHeuristicTypes(); |
512 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 511 EXPECT_TRUE(form_structure.IsAutofillable(true)); |
513 | 512 |
514 // Expect the correct number of fields. | 513 // Expect the correct number of fields. |
515 ASSERT_EQ(6U, form_structure->field_count()); | 514 ASSERT_EQ(9U, form_structure.field_count()); |
516 ASSERT_EQ(6U, form_structure->autofill_count()); | 515 EXPECT_EQ(9U, form_structure.autofill_count()); |
517 | 516 |
518 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 517 // All of the fields in this form should be parsed as belonging to different |
519 EXPECT_EQ(ASCIIToUTF16("shipping-default"), | 518 // sections. |
520 form_structure->field(0)->section()); | 519 std::set<string16> section_names; |
521 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 520 for (size_t i = 0; i < 9; ++i) { |
522 EXPECT_EQ(ASCIIToUTF16("-default"), form_structure->field(1)->section()); | 521 section_names.insert(form_structure.field(i)->section()); |
523 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(2)->heuristic_type()); | 522 } |
524 EXPECT_EQ(ASCIIToUTF16("foo-default"), form_structure->field(2)->section()); | 523 EXPECT_EQ(9U, section_names.size()); |
525 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(3)->heuristic_type()); | |
526 EXPECT_EQ(ASCIIToUTF16("-default"), form_structure->field(3)->section()); | |
527 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); | |
528 EXPECT_EQ(ASCIIToUTF16("-shipping-default"), | |
529 form_structure->field(4)->section()); | |
530 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(5)->heuristic_type()); | |
531 EXPECT_EQ(ASCIIToUTF16("shipping-cc"), form_structure->field(5)->section()); | |
532 } | 524 } |
533 | 525 |
534 // Verify that we can correctly process fallback types listed in the | 526 // Verify that we can correctly process a degenerate section listed in the |
535 // |autocompletetype| attribute. | 527 // |autocomplete| attribute. |
536 TEST(FormStructureTest, HeuristicsAutocompletetypeWithFallbacks) { | 528 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsDegenerate) { |
537 scoped_ptr<FormStructure> form_structure; | |
538 FormData form; | 529 FormData form; |
539 form.method = ASCIIToUTF16("post"); | 530 form.method = ASCIIToUTF16("post"); |
540 | 531 |
541 FormFieldData field; | 532 FormFieldData field; |
542 field.form_control_type = ASCIIToUTF16("text"); | 533 field.form_control_type = ASCIIToUTF16("text"); |
543 | 534 |
544 // Skip over any sections and "x"-prefixed types. | 535 // Some fields will have no section specified. These fall into the default |
545 field.label = string16(); | 536 // section. |
546 field.name = ASCIIToUTF16("field1"); | 537 field.autocomplete_attribute = ASCIIToUTF16("email"); |
547 field.autocomplete_type = | |
548 ASCIIToUTF16("section-full-name x-given-name-initial given-name"); | |
549 form.fields.push_back(field); | 538 form.fields.push_back(field); |
550 | 539 |
551 // Stop processing once we see a known type. | 540 // Specifying "section-" is equivalent to not specifying a section. |
552 field.label = string16(); | 541 field.autocomplete_attribute = ASCIIToUTF16("section- email"); |
553 field.name = ASCIIToUTF16("field2"); | |
554 field.autocomplete_type = ASCIIToUTF16("section-full-name surname full-name"); | |
555 form.fields.push_back(field); | 542 form.fields.push_back(field); |
556 | 543 |
557 // Skip over unknown types even if they are not prefixed with "x-". | 544 FormStructure form_structure(form); |
558 field.label = string16(); | 545 form_structure.DetermineHeuristicTypes(); |
559 field.name = ASCIIToUTF16("field3"); | 546 |
560 field.autocomplete_type = | 547 // Expect the correct number of fields. |
561 ASCIIToUTF16("section-shipping mobile-phone-full phone-full"); | 548 ASSERT_EQ(2U, form_structure.field_count()); |
| 549 EXPECT_EQ(2U, form_structure.autofill_count()); |
| 550 |
| 551 // All of the fields in this form should be parsed as belonging to the same |
| 552 // sections. |
| 553 std::set<string16> section_names; |
| 554 for (size_t i = 0; i < 2; ++i) { |
| 555 section_names.insert(form_structure.field(i)->section()); |
| 556 } |
| 557 EXPECT_EQ(1U, section_names.size()); |
| 558 } |
| 559 |
| 560 // Verify that we can correctly process repeated sections listed in the |
| 561 // |autocomplete| attribute. |
| 562 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { |
| 563 FormData form; |
| 564 form.method = ASCIIToUTF16("post"); |
| 565 |
| 566 FormFieldData field; |
| 567 field.form_control_type = ASCIIToUTF16("text"); |
| 568 |
| 569 field.autocomplete_attribute = ASCIIToUTF16("section-foo email"); |
| 570 form.fields.push_back(field); |
| 571 field.autocomplete_attribute = ASCIIToUTF16("section-foo street-address"); |
562 form.fields.push_back(field); | 572 form.fields.push_back(field); |
563 | 573 |
564 form_structure.reset(new FormStructure(form)); | 574 FormStructure form_structure(form); |
565 form_structure->DetermineHeuristicTypes(); | 575 form_structure.DetermineHeuristicTypes(); |
566 EXPECT_TRUE(form_structure->IsAutofillable(true)); | |
567 | 576 |
568 // Expect the correct number of fields. | 577 // Expect the correct number of fields. |
569 ASSERT_EQ(3U, form_structure->field_count()); | 578 ASSERT_EQ(2U, form_structure.field_count()); |
570 ASSERT_EQ(3U, form_structure->autofill_count()); | 579 EXPECT_EQ(2U, form_structure.autofill_count()); |
571 | 580 |
572 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 581 // All of the fields in this form should be parsed as belonging to the same |
573 EXPECT_EQ(ASCIIToUTF16("full-name-default"), | 582 // sections. |
574 form_structure->field(0)->section()); | 583 std::set<string16> section_names; |
575 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 584 for (size_t i = 0; i < 2; ++i) { |
576 EXPECT_EQ(ASCIIToUTF16("full-name-default"), | 585 section_names.insert(form_structure.field(i)->section()); |
577 form_structure->field(1)->section()); | 586 } |
578 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, | 587 EXPECT_EQ(1U, section_names.size()); |
579 form_structure->field(2)->heuristic_type()); | 588 } |
580 EXPECT_EQ(ASCIIToUTF16("shipping-default"), | 589 |
581 form_structure->field(2)->section()); | 590 // Verify that we do not override the author-specified sections from a form with |
| 591 // local heuristics. |
| 592 TEST(FormStructureTest, HeuristicsDontOverrideAutocompleteAttributeSections) { |
| 593 FormData form; |
| 594 form.method = ASCIIToUTF16("post"); |
| 595 |
| 596 FormFieldData field; |
| 597 field.form_control_type = ASCIIToUTF16("text"); |
| 598 |
| 599 field.name = ASCIIToUTF16("one"); |
| 600 field.autocomplete_attribute = ASCIIToUTF16("street-address"); |
| 601 form.fields.push_back(field); |
| 602 field.name = string16(); |
| 603 field.autocomplete_attribute = ASCIIToUTF16("section-foo email"); |
| 604 form.fields.push_back(field); |
| 605 field.name = string16(); |
| 606 field.autocomplete_attribute = ASCIIToUTF16("name"); |
| 607 form.fields.push_back(field); |
| 608 field.name = ASCIIToUTF16("two"); |
| 609 field.autocomplete_attribute = ASCIIToUTF16("street-address"); |
| 610 form.fields.push_back(field); |
| 611 |
| 612 FormStructure form_structure(form); |
| 613 form_structure.DetermineHeuristicTypes(); |
| 614 |
| 615 // Expect the correct number of fields. |
| 616 ASSERT_EQ(4U, form_structure.field_count()); |
| 617 EXPECT_EQ(4U, form_structure.autofill_count()); |
| 618 |
| 619 // Normally, the two separate address fields would cause us to detect two |
| 620 // separate sections; but because there is an author-specified section in this |
| 621 // form, we do not apply these usual heuristics. |
| 622 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); |
| 623 EXPECT_EQ(ASCIIToUTF16("two"), form_structure.field(3)->name); |
| 624 EXPECT_EQ(form_structure.field(0)->section(), |
| 625 form_structure.field(3)->section()); |
582 } | 626 } |
583 | 627 |
584 TEST(FormStructureTest, HeuristicsSample8) { | 628 TEST(FormStructureTest, HeuristicsSample8) { |
585 scoped_ptr<FormStructure> form_structure; | 629 scoped_ptr<FormStructure> form_structure; |
586 FormData form; | 630 FormData form; |
587 form.method = ASCIIToUTF16("post"); | 631 form.method = ASCIIToUTF16("post"); |
588 | 632 |
589 FormFieldData field; | 633 FormFieldData field; |
590 field.form_control_type = ASCIIToUTF16("text"); | 634 field.form_control_type = ASCIIToUTF16("text"); |
591 | 635 |
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1983 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2027 EXPECT_EQ(FormStructureTest::Hash64Bit( |
1984 std::string("https://login.facebook.com&&email&first")), | 2028 std::string("https://login.facebook.com&&email&first")), |
1985 form_structure->FormSignature()); | 2029 form_structure->FormSignature()); |
1986 | 2030 |
1987 form.name = ASCIIToUTF16("login_form"); | 2031 form.name = ASCIIToUTF16("login_form"); |
1988 form_structure.reset(new FormStructure(form)); | 2032 form_structure.reset(new FormStructure(form)); |
1989 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2033 EXPECT_EQ(FormStructureTest::Hash64Bit( |
1990 std::string("https://login.facebook.com&login_form&email&first")), | 2034 std::string("https://login.facebook.com&login_form&email&first")), |
1991 form_structure->FormSignature()); | 2035 form_structure->FormSignature()); |
1992 } | 2036 } |
OLD | NEW |