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

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

Issue 1380002: Label scraping for AutoFill.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/form_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "chrome/browser/autofill/form_structure.h" 7 #include "chrome/browser/autofill/form_structure.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" 10 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // Company 377 // Company
378 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 378 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
379 // Address. 379 // Address.
380 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type()); 380 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type());
381 // City. 381 // City.
382 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); 382 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
383 // Zip. 383 // Zip.
384 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type()); 384 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type());
385 } 385 }
386 386
387 // Tests a sequence of FormFields where only labels are supplied to heuristics
388 // for matching. This works because FormField labels are matched in the case
389 // that input element ids (or |name| fields) are missing.
390 TEST(FormStructureTest, HeuristicsLabelsOnly) {
391 scoped_ptr<FormStructure> form_structure;
392 webkit_glue::FormFieldValues values;
393
394 values.method = ASCIIToUTF16("post");
395 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"),
396 string16(),
397 string16(),
398 ASCIIToUTF16("text"),
399 WebInputElement::Text));
400 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
401 string16(),
402 string16(),
403 ASCIIToUTF16("text"),
404 WebInputElement::Text));
405 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"),
406 string16(),
407 string16(),
408 ASCIIToUTF16("text"),
409 WebInputElement::Text));
410 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"),
411 string16(),
412 string16(),
413 ASCIIToUTF16("text"),
414 WebInputElement::Text));
415 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"),
416 string16(),
417 string16(),
418 ASCIIToUTF16("text"),
419 WebInputElement::Text));
420 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
421 string16(),
422 string16(),
423 ASCIIToUTF16("text"),
424 WebInputElement::Text));
425 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
426 string16(),
427 string16(),
428 ASCIIToUTF16("text"),
429 WebInputElement::Text));
430 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"),
431 string16(),
432 string16(),
433 ASCIIToUTF16("text"),
434 WebInputElement::Text));
435 values.elements.push_back(webkit_glue::FormField(string16(),
436 ASCIIToUTF16("Submit"),
437 string16(),
438 ASCIIToUTF16("submit"),
439 WebInputElement::Submit));
440 form_structure.reset(new FormStructure(values));
441 EXPECT_TRUE(form_structure->IsAutoFillable());
442
443 // Expect the correct number of fields.
444 ASSERT_EQ(8UL, form_structure->field_count());
445
446 // Check that heuristics are initialized as UNKNOWN_TYPE.
447 std::vector<AutoFillField*>::const_iterator iter;
448 size_t i;
449 for (iter = form_structure->begin(), i = 0;
450 iter != form_structure->end();
451 ++iter, ++i) {
452 // Expect last element to be NULL.
453 if (i == form_structure->field_count()) {
454 ASSERT_EQ(static_cast<AutoFillField*>(NULL), *iter);
455 } else {
456 ASSERT_NE(static_cast<AutoFillField*>(NULL), *iter);
457 EXPECT_EQ(UNKNOWN_TYPE, (*iter)->heuristic_type());
458 }
459 }
460
461 // Compute heuristic types.
462 form_structure->GetHeuristicAutoFillTypes();
463 ASSERT_EQ(8U, form_structure->field_count());
464
465 // Check that heuristics are no longer UNKNOWN_TYPE.
466 // First name.
467 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
468 // Last name.
469 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
470 // Email.
471 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
472 // Phone.
473 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
474 form_structure->field(3)->heuristic_type());
475 // Fax. Note, we don't currently match fax.
476 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(4)->heuristic_type());
477 // Address.
478 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(5)->heuristic_type());
479 // Address Line 2.
480 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(6)->heuristic_type());
481 // Zip.
482 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type());
483 }
484
387 } // namespace 485 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/form_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698