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

Side by Side Diff: chrome/renderer/form_manager_unittest.cc

Issue 1622004: AutoFill: Parse HTMLLabel elements for form control element labels. (Closed)
Patch Set: Update constness. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/form_manager.cc ('k') | chrome/renderer/render_view.cc » ('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 "chrome/renderer/form_manager.h" 5 #include "chrome/renderer/form_manager.h"
6 #include "chrome/test/render_view_test.h" 6 #include "chrome/test/render_view_test.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" 8 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
9 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" 9 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" 10 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 ASSERT_EQ(1U, forms.size()); 415 ASSERT_EQ(1U, forms.size());
416 416
417 // There should be no forms after the call to Reset. 417 // There should be no forms after the call to Reset.
418 form_manager.Reset(); 418 form_manager.Reset();
419 419
420 forms.clear(); 420 forms.clear();
421 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms); 421 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms);
422 ASSERT_EQ(0U, forms.size()); 422 ASSERT_EQ(0U, forms.size());
423 } 423 }
424 424
425 // http://crbug.com/40306 425 TEST_F(FormManagerTest, Labels) {
426 TEST_F(FormManagerTest, DISABLED_Labels) {
427 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 426 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
428 " <LABEL for=\"firstname\"> First name: </LABEL>" 427 " <LABEL for=\"firstname\"> First name: </LABEL>"
429 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 428 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
430 " <LABEL for=\"lastname\"> Last name: </LABEL>" 429 " <LABEL for=\"lastname\"> Last name: </LABEL>"
431 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 430 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
432 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 431 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
433 "</FORM>"); 432 "</FORM>");
434 433
435 WebFrame* web_frame = GetMainFrame(); 434 WebFrame* web_frame = GetMainFrame();
436 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 435 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
(...skipping 22 matching lines...) Expand all
459 ASCIIToUTF16("Smith"), 458 ASCIIToUTF16("Smith"),
460 ASCIIToUTF16("text")), 459 ASCIIToUTF16("text")),
461 fields[1]); 460 fields[1]);
462 EXPECT_EQ(FormField(string16(), 461 EXPECT_EQ(FormField(string16(),
463 ASCIIToUTF16("reply-send"), 462 ASCIIToUTF16("reply-send"),
464 ASCIIToUTF16("Send"), 463 ASCIIToUTF16("Send"),
465 ASCIIToUTF16("submit")), 464 ASCIIToUTF16("submit")),
466 fields[2]); 465 fields[2]);
467 } 466 }
468 467
468 // This test is different from FormManagerTest.Labels in that the label elements
469 // for= attribute is set to the name of the form control element it is a label
470 // for instead of the id of the form control element. This is invalid because
471 // the for= attribute must be set to the id of the form control element.
472 TEST_F(FormManagerTest, InvalidLabels) {
473 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
474 " <LABEL for=\"firstname\"> First name: </LABEL>"
475 " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>"
476 " <LABEL for=\"lastname\"> Last name: </LABEL>"
477 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\"/>"
478 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
479 "</FORM>");
480
481 WebFrame* web_frame = GetMainFrame();
482 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
483
484 FormManager form_manager;
485 form_manager.ExtractForms(web_frame);
486
487 std::vector<FormData> forms;
488 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms);
489 ASSERT_EQ(1U, forms.size());
490
491 const FormData& form = forms[0];
492 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
493 EXPECT_EQ(GURL(web_frame->url()), form.origin);
494 EXPECT_EQ(GURL("http://cnn.com"), form.action);
495
496 const std::vector<FormField>& fields = form.fields;
497 ASSERT_EQ(3U, fields.size());
498 EXPECT_EQ(FormField(string16(),
499 ASCIIToUTF16("firstname"),
500 ASCIIToUTF16("John"),
501 ASCIIToUTF16("text")),
502 fields[0]);
503 EXPECT_EQ(FormField(string16(),
504 ASCIIToUTF16("lastname"),
505 ASCIIToUTF16("Smith"),
506 ASCIIToUTF16("text")),
507 fields[1]);
508 EXPECT_EQ(FormField(string16(),
509 ASCIIToUTF16("reply-send"),
510 ASCIIToUTF16("Send"),
511 ASCIIToUTF16("submit")),
512 fields[2]);
513 }
514
469 // http://crbug.com/40306 515 // http://crbug.com/40306
470 TEST_F(FormManagerTest, DISABLED_LabelsInferredFromText) { 516 TEST_F(FormManagerTest, DISABLED_LabelsInferredFromText) {
471 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 517 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
472 " First name:" 518 " First name:"
473 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 519 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
474 " Last name:" 520 " Last name:"
475 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 521 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
476 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 522 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
477 "</FORM>"); 523 "</FORM>");
478 524
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 ASCIIToUTF16("text")), 649 ASCIIToUTF16("text")),
604 fields[1]); 650 fields[1]);
605 EXPECT_EQ(FormField(string16(), 651 EXPECT_EQ(FormField(string16(),
606 ASCIIToUTF16("reply-send"), 652 ASCIIToUTF16("reply-send"),
607 ASCIIToUTF16("Send"), 653 ASCIIToUTF16("Send"),
608 ASCIIToUTF16("submit")), 654 ASCIIToUTF16("submit")),
609 fields[2]); 655 fields[2]);
610 } 656 }
611 657
612 } // namespace 658 } // namespace
OLDNEW
« no previous file with comments | « chrome/renderer/form_manager.cc ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698