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

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

Issue 2348001: AutoFill: Refactor the code used to fill a form. Don't fill autocomplete=off (Closed)
Patch Set: Fix compile. Created 10 years, 7 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
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"
11 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" 11 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
14 #include "webkit/glue/form_data.h" 14 #include "webkit/glue/form_data.h"
15 15
16 using WebKit::WebDocument;
16 using WebKit::WebElement; 17 using WebKit::WebElement;
17 using WebKit::WebFormElement; 18 using WebKit::WebFormElement;
18 using WebKit::WebFrame; 19 using WebKit::WebFrame;
19 using WebKit::WebInputElement; 20 using WebKit::WebInputElement;
20 using WebKit::WebString; 21 using WebKit::WebString;
21 using WebKit::WebVector; 22 using WebKit::WebVector;
22 23
23 using webkit_glue::FormData; 24 using webkit_glue::FormData;
24 using webkit_glue::FormField; 25 using webkit_glue::FormField;
25 26
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 ASCIIToUTF16("Send"), 331 ASCIIToUTF16("Send"),
331 ASCIIToUTF16("submit"), 332 ASCIIToUTF16("submit"),
332 0), 333 0),
333 fields[2]); 334 fields[2]);
334 } 335 }
335 336
336 TEST_F(FormManagerTest, FillForm) { 337 TEST_F(FormManagerTest, FillForm) {
337 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 338 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
338 " <INPUT type=\"text\" id=\"firstname\"/>" 339 " <INPUT type=\"text\" id=\"firstname\"/>"
339 " <INPUT type=\"text\" id=\"lastname\"/>" 340 " <INPUT type=\"text\" id=\"lastname\"/>"
341 " <INPUT type=\"hidden\" id=\"imhidden\"/>"
342 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>"
343 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>"
340 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 344 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
341 "</FORM>"); 345 "</FORM>");
342 346
343 WebFrame* web_frame = GetMainFrame(); 347 WebFrame* web_frame = GetMainFrame();
344 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 348 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
345 349
346 FormManager form_manager; 350 FormManager form_manager;
347 form_manager.ExtractForms(web_frame); 351 form_manager.ExtractForms(web_frame);
348 352
349 // Verify that we have the form. 353 // Verify that we have the form.
350 std::vector<FormData> forms; 354 std::vector<FormData> forms;
351 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms); 355 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms);
352 ASSERT_EQ(1U, forms.size()); 356 ASSERT_EQ(1U, forms.size());
353 357
354 // Get the input element we want to find. 358 // Get the input element we want to find.
355 WebElement element = web_frame->document().getElementById("firstname"); 359 WebElement element = web_frame->document().getElementById("firstname");
356 WebInputElement input_element = element.to<WebInputElement>(); 360 WebInputElement input_element = element.to<WebInputElement>();
357 361
358 // Find the form that contains the input element. 362 // Find the form that contains the input element.
359 FormData form; 363 FormData form;
360 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 364 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
361 input_element, FormManager::REQUIRE_NONE, &form)); 365 input_element, FormManager::REQUIRE_NONE, &form));
362 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 366 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
363 EXPECT_EQ(GURL(web_frame->url()), form.origin); 367 EXPECT_EQ(GURL(web_frame->url()), form.origin);
364 EXPECT_EQ(GURL("http://buh.com"), form.action); 368 EXPECT_EQ(GURL("http://buh.com"), form.action);
365 369
366 const std::vector<FormField>& fields = form.fields; 370 const std::vector<FormField>& fields = form.fields;
367 ASSERT_EQ(3U, fields.size()); 371 ASSERT_EQ(6U, fields.size());
368 EXPECT_EQ(FormField(string16(), 372 EXPECT_EQ(FormField(string16(),
369 ASCIIToUTF16("firstname"), 373 ASCIIToUTF16("firstname"),
370 string16(), 374 string16(),
371 ASCIIToUTF16("text"), 375 ASCIIToUTF16("text"),
372 20), 376 20),
373 fields[0]); 377 fields[0]);
374 EXPECT_EQ(FormField(string16(), 378 EXPECT_EQ(FormField(string16(),
375 ASCIIToUTF16("lastname"), 379 ASCIIToUTF16("lastname"),
376 string16(), 380 string16(),
377 ASCIIToUTF16("text"), 381 ASCIIToUTF16("text"),
378 20), 382 20),
379 fields[1]); 383 fields[1]);
380 EXPECT_EQ(FormField(string16(), 384 EXPECT_EQ(FormField(string16(),
385 ASCIIToUTF16("imhidden"),
386 string16(),
387 ASCIIToUTF16("hidden"),
388 0),
389 fields[2]);
390 EXPECT_EQ(FormField(string16(),
dhollowa 2010/05/28 02:07:07 These guys need the StrictlyEqualsHack() too I thi
James Hawkins 2010/05/28 02:17:27 Not particularly, since they have no values at thi
391 ASCIIToUTF16("notempty"),
392 ASCIIToUTF16("Hi"),
393 ASCIIToUTF16("text"),
394 20),
395 fields[3]);
396 EXPECT_EQ(FormField(string16(),
397 ASCIIToUTF16("noautocomplete"),
398 string16(),
399 ASCIIToUTF16("text"),
400 20),
401 fields[4]);
402 EXPECT_EQ(FormField(string16(),
381 ASCIIToUTF16("reply-send"), 403 ASCIIToUTF16("reply-send"),
382 ASCIIToUTF16("Send"), 404 ASCIIToUTF16("Send"),
383 ASCIIToUTF16("submit"), 405 ASCIIToUTF16("submit"),
384 0), 406 0),
385 fields[2]); 407 fields[5]);
386 408
387 // Fill the form. 409 // Fill the form.
388 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); 410 form.fields[0].set_value(ASCIIToUTF16("Wyatt"));
389 form.fields[1].set_value(ASCIIToUTF16("Earp")); 411 form.fields[1].set_value(ASCIIToUTF16("Earp"));
412 form.fields[2].set_value(ASCIIToUTF16("Alpha"));
413 form.fields[3].set_value(ASCIIToUTF16("Beta"));
414 form.fields[4].set_value(ASCIIToUTF16("Gamma"));
390 EXPECT_TRUE(form_manager.FillForm(form)); 415 EXPECT_TRUE(form_manager.FillForm(form));
391 416
392 // Find the newly-filled form that contains the input element. 417 // Verify the previewed elements.
393 FormData form2; 418 WebDocument document = web_frame->document();
394 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 419 WebInputElement firstname =
395 input_element, FormManager::REQUIRE_NONE, &form2)); 420 document.getElementById("firstname").to<WebInputElement>();
396 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 421 // TODO(jhawkins): Check firstname.isAutofilled() once support has been added
397 EXPECT_EQ(GURL(web_frame->url()), form2.origin); 422 // in WebKit.
398 EXPECT_EQ(GURL("http://buh.com"), form2.action); 423 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value());
399 424
400 const std::vector<FormField>& fields2 = form2.fields; 425 WebInputElement lastname =
401 ASSERT_EQ(3U, fields2.size()); 426 document.getElementById("lastname").to<WebInputElement>();
402 EXPECT_EQ(FormField(string16(), 427 EXPECT_EQ(ASCIIToUTF16("Earp"), lastname.value());
403 ASCIIToUTF16("firstname"), 428
404 ASCIIToUTF16("Wyatt"), 429 // Hidden fields are not previewed.
405 ASCIIToUTF16("text"), 430 WebInputElement imhidden =
406 20), 431 document.getElementById("imhidden").to<WebInputElement>();
407 fields2[0]); 432 EXPECT_TRUE(imhidden.value().isEmpty());
408 EXPECT_EQ(FormField(string16(), 433
409 ASCIIToUTF16("lastname"), 434 // Non-empty fields are not previewed.
410 ASCIIToUTF16("Earp"), 435 WebInputElement notempty =
411 ASCIIToUTF16("text"), 436 document.getElementById("notempty").to<WebInputElement>();
412 20), 437 EXPECT_EQ(ASCIIToUTF16("Hi"), notempty.value());
413 fields2[1]); 438
414 EXPECT_EQ(FormField(string16(), 439 // autocomplete=off fields are not previewed.
415 ASCIIToUTF16("reply-send"), 440 WebInputElement noautocomplete =
416 ASCIIToUTF16("Send"), 441 document.getElementById("noautocomplete").to<WebInputElement>();
417 ASCIIToUTF16("submit"), 442 EXPECT_TRUE(noautocomplete.value().isEmpty());
418 0),
419 fields2[2]);
420 } 443 }
421 444
422 TEST_F(FormManagerTest, Reset) { 445 TEST_F(FormManagerTest, Reset) {
423 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 446 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
424 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 447 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
425 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 448 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
426 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 449 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
427 "</FORM>"); 450 "</FORM>");
428 451
429 WebFrame* web_frame = GetMainFrame(); 452 WebFrame* web_frame = GetMainFrame();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms); 486 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms);
464 ASSERT_EQ(1U, forms.size()); 487 ASSERT_EQ(1U, forms.size());
465 488
466 const FormData& form = forms[0]; 489 const FormData& form = forms[0];
467 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 490 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
468 EXPECT_EQ(GURL(web_frame->url()), form.origin); 491 EXPECT_EQ(GURL(web_frame->url()), form.origin);
469 EXPECT_EQ(GURL("http://cnn.com"), form.action); 492 EXPECT_EQ(GURL("http://cnn.com"), form.action);
470 493
471 const std::vector<FormField>& fields = form.fields; 494 const std::vector<FormField>& fields = form.fields;
472 ASSERT_EQ(3U, fields.size()); 495 ASSERT_EQ(3U, fields.size());
473 EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), 496 EXPECT_TRUE(fields[0].StrictlyEqualsHack(
474 ASCIIToUTF16("firstname"), 497 FormField(ASCIIToUTF16("First name:"),
475 ASCIIToUTF16("John"), 498 ASCIIToUTF16("firstname"),
476 ASCIIToUTF16("text"), 499 ASCIIToUTF16("John"),
477 20), 500 ASCIIToUTF16("text"),
478 fields[0]); 501 20)));
479 EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), 502 EXPECT_TRUE(fields[1].StrictlyEqualsHack(
480 ASCIIToUTF16("lastname"), 503 FormField(ASCIIToUTF16("Last name:"),
481 ASCIIToUTF16("Smith"), 504 ASCIIToUTF16("lastname"),
482 ASCIIToUTF16("text"), 505 ASCIIToUTF16("Smith"),
483 20), 506 ASCIIToUTF16("text"),
484 fields[1]); 507 20)));
485 EXPECT_EQ(FormField(string16(), 508 EXPECT_TRUE(fields[2].StrictlyEqualsHack(
486 ASCIIToUTF16("reply-send"), 509 FormField(string16(),
487 ASCIIToUTF16("Send"), 510 ASCIIToUTF16("reply-send"),
488 ASCIIToUTF16("submit"), 511 string16(),
489 0), 512 ASCIIToUTF16("submit"),
490 fields[2]); 513 0)));
491 } 514 }
492 515
493 TEST_F(FormManagerTest, LabelsWithSpans) { 516 TEST_F(FormManagerTest, LabelsWithSpans) {
494 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 517 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
495 " <LABEL for=\"firstname\"><span>First name: </span></LABEL>" 518 " <LABEL for=\"firstname\"><span>First name: </span></LABEL>"
496 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 519 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
497 " <LABEL for=\"lastname\"><span>Last name: </span></LABEL>" 520 " <LABEL for=\"lastname\"><span>Last name: </span></LABEL>"
498 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 521 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
499 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 522 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
500 "</FORM>"); 523 "</FORM>");
501 524
502 WebFrame* web_frame = GetMainFrame(); 525 WebFrame* web_frame = GetMainFrame();
503 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 526 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
504 527
505 FormManager form_manager; 528 FormManager form_manager;
506 form_manager.ExtractForms(web_frame); 529 form_manager.ExtractForms(web_frame);
507 530
508 std::vector<FormData> forms; 531 std::vector<FormData> forms;
509 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms); 532 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms);
510 ASSERT_EQ(1U, forms.size()); 533 ASSERT_EQ(1U, forms.size());
511 534
512 const FormData& form = forms[0]; 535 const FormData& form = forms[0];
513 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 536 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
514 EXPECT_EQ(GURL(web_frame->url()), form.origin); 537 EXPECT_EQ(GURL(web_frame->url()), form.origin);
515 EXPECT_EQ(GURL("http://cnn.com"), form.action); 538 EXPECT_EQ(GURL("http://cnn.com"), form.action);
516 539
517 const std::vector<FormField>& fields = form.fields; 540 const std::vector<FormField>& fields = form.fields;
518 ASSERT_EQ(3U, fields.size()); 541 ASSERT_EQ(3U, fields.size());
519 EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), 542 EXPECT_TRUE(fields[0].StrictlyEqualsHack(
520 ASCIIToUTF16("firstname"), 543 FormField(ASCIIToUTF16("First name:"),
521 ASCIIToUTF16("John"), 544 ASCIIToUTF16("firstname"),
522 ASCIIToUTF16("text"), 545 ASCIIToUTF16("John"),
523 20), 546 ASCIIToUTF16("text"),
524 fields[0]); 547 20)));
525 EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), 548 EXPECT_TRUE(fields[1].StrictlyEqualsHack(
526 ASCIIToUTF16("lastname"), 549 FormField(ASCIIToUTF16("Last name:"),
527 ASCIIToUTF16("Smith"), 550 ASCIIToUTF16("lastname"),
528 ASCIIToUTF16("text"), 551 ASCIIToUTF16("Smith"),
529 20), 552 ASCIIToUTF16("text"),
530 fields[1]); 553 20)));
531 EXPECT_EQ(FormField(string16(), 554 EXPECT_TRUE(fields[2].StrictlyEqualsHack(
532 ASCIIToUTF16("reply-send"), 555 FormField(string16(),
533 ASCIIToUTF16("Send"), 556 ASCIIToUTF16("reply-send"),
534 ASCIIToUTF16("submit"), 557 string16(),
535 0), 558 ASCIIToUTF16("submit"),
536 fields[2]); 559 0)));
537 } 560 }
538 561
539 // This test is different from FormManagerTest.Labels in that the label elements 562 // This test is different from FormManagerTest.Labels in that the label elements
540 // for= attribute is set to the name of the form control element it is a label 563 // for= attribute is set to the name of the form control element it is a label
541 // for instead of the id of the form control element. This is invalid because 564 // for instead of the id of the form control element. This is invalid because
542 // the for= attribute must be set to the id of the form control element. 565 // the for= attribute must be set to the id of the form control element.
543 TEST_F(FormManagerTest, InvalidLabels) { 566 TEST_F(FormManagerTest, InvalidLabels) {
544 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 567 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
545 " <LABEL for=\"firstname\"> First name: </LABEL>" 568 " <LABEL for=\"firstname\"> First name: </LABEL>"
546 " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>" 569 " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>"
(...skipping 12 matching lines...) Expand all
559 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms); 582 form_manager.GetForms(FormManager::REQUIRE_NONE, &forms);
560 ASSERT_EQ(1U, forms.size()); 583 ASSERT_EQ(1U, forms.size());
561 584
562 const FormData& form = forms[0]; 585 const FormData& form = forms[0];
563 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 586 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
564 EXPECT_EQ(GURL(web_frame->url()), form.origin); 587 EXPECT_EQ(GURL(web_frame->url()), form.origin);
565 EXPECT_EQ(GURL("http://cnn.com"), form.action); 588 EXPECT_EQ(GURL("http://cnn.com"), form.action);
566 589
567 const std::vector<FormField>& fields = form.fields; 590 const std::vector<FormField>& fields = form.fields;
568 ASSERT_EQ(3U, fields.size()); 591 ASSERT_EQ(3U, fields.size());
569 EXPECT_EQ(FormField(string16(), 592 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
570 ASCIIToUTF16("firstname"), 593 ASCIIToUTF16("firstname"),
571 ASCIIToUTF16("John"), 594 ASCIIToUTF16("John"),
572 ASCIIToUTF16("text"), 595 ASCIIToUTF16("text"),
573 20), 596 20)));
574 fields[0]); 597 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
575 EXPECT_EQ(FormField(string16(), 598 ASCIIToUTF16("lastname"),
576 ASCIIToUTF16("lastname"), 599 ASCIIToUTF16("Smith"),
577 ASCIIToUTF16("Smith"), 600 ASCIIToUTF16("text"),
578 ASCIIToUTF16("text"), 601 20)));
579 20), 602 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
580 fields[1]); 603 ASCIIToUTF16("reply-send"),
581 EXPECT_EQ(FormField(string16(), 604 string16(),
582 ASCIIToUTF16("reply-send"), 605 ASCIIToUTF16("submit"),
583 ASCIIToUTF16("Send"), 606 0)));
584 ASCIIToUTF16("submit"),
585 0),
586 fields[2]);
587 } 607 }
588 608
589 // This test has three form control elements, only one of which has a label 609 // This test has three form control elements, only one of which has a label
590 // element associated with it. The first element is disabled because of the 610 // element associated with it. The first element is disabled because of the
591 // autocomplete=off attribute. 611 // autocomplete=off attribute.
592 TEST_F(FormManagerTest, OneLabelElementFirstControlElementDisabled) { 612 TEST_F(FormManagerTest, OneLabelElementFirstControlElementDisabled) {
593 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 613 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
594 " First name:" 614 " First name:"
595 " <INPUT type=\"text\" id=\"firstname\" autocomplete=\"off\"/>" 615 " <INPUT type=\"text\" id=\"firstname\" autocomplete=\"off\"/>"
596 " <LABEL for=\"middlename\">Middle name: </LABEL>" 616 " <LABEL for=\"middlename\">Middle name: </LABEL>"
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 EXPECT_TRUE(form_manager.FillForm(form)); 1132 EXPECT_TRUE(form_manager.FillForm(form));
1113 1133
1114 // Find the newly-filled form that contains the input element. 1134 // Find the newly-filled form that contains the input element.
1115 FormData form2; 1135 FormData form2;
1116 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 1136 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
1117 input_element, FormManager::REQUIRE_NONE, &form2)); 1137 input_element, FormManager::REQUIRE_NONE, &form2));
1118 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1138 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1119 EXPECT_EQ(GURL(web_frame->url()), form2.origin); 1139 EXPECT_EQ(GURL(web_frame->url()), form2.origin);
1120 EXPECT_EQ(GURL("http://buh.com"), form2.action); 1140 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1121 1141
1122 // TODO(jhawkins): We don't actually compare the value of the field in
1123 // FormField::operator==()!
1124 const std::vector<FormField>& fields2 = form2.fields; 1142 const std::vector<FormField>& fields2 = form2.fields;
1125 EXPECT_EQ(FormField(string16(), 1143 EXPECT_TRUE(fields2[0].StrictlyEqualsHack(
1126 ASCIIToUTF16("firstname"), 1144 FormField(string16(),
1127 ASCIIToUTF16("Broth"), 1145 ASCIIToUTF16("firstname"),
1128 ASCIIToUTF16("text"), 1146 ASCIIToUTF16("Broth"),
1129 20), 1147 ASCIIToUTF16("text"),
1130 fields2[0]); 1148 20)));
1131 EXPECT_EQ(ASCIIToUTF16("Broth"), fields2[0].value()); 1149 EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
1132 EXPECT_EQ(FormField(string16(), 1150 FormField(string16(),
1133 ASCIIToUTF16("lastname"), 1151 ASCIIToUTF16("lastname"),
1134 ASCIIToUTF16("Jonat"), 1152 ASCIIToUTF16("Jonat"),
1135 ASCIIToUTF16("text"), 1153 ASCIIToUTF16("text"),
1136 20), 1154 20)));
1137 fields2[1]); 1155 EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
1138 EXPECT_EQ(ASCIIToUTF16("Jonat"), fields2[1].value()); 1156 FormField(string16(),
1139 EXPECT_EQ(FormField(string16(), 1157 ASCIIToUTF16("reply-send"),
1140 ASCIIToUTF16("reply-send"), 1158 string16(),
1141 ASCIIToUTF16("Send"), 1159 ASCIIToUTF16("submit"),
1142 ASCIIToUTF16("submit"), 1160 0)));
1143 0),
1144 fields2[2]);
1145 } 1161 }
1146 1162
1147 // This test uses negative values of the maxlength attribute for input elements. 1163 // This test uses negative values of the maxlength attribute for input elements.
1148 // In this case, the maxlength of the input elements is set to the default 1164 // In this case, the maxlength of the input elements is set to the default
1149 // maxlength (defined in WebKit.) 1165 // maxlength (defined in WebKit.)
1150 TEST_F(FormManagerTest, FillFormNegativeMaxLength) { 1166 TEST_F(FormManagerTest, FillFormNegativeMaxLength) {
1151 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1167 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1152 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" 1168 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>"
1153 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" 1169 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>"
1154 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1170 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 EXPECT_TRUE(form_manager.FillForm(form)); 1220 EXPECT_TRUE(form_manager.FillForm(form));
1205 1221
1206 // Find the newly-filled form that contains the input element. 1222 // Find the newly-filled form that contains the input element.
1207 FormData form2; 1223 FormData form2;
1208 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 1224 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
1209 input_element, FormManager::REQUIRE_NONE, &form2)); 1225 input_element, FormManager::REQUIRE_NONE, &form2));
1210 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1226 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1211 EXPECT_EQ(GURL(web_frame->url()), form2.origin); 1227 EXPECT_EQ(GURL(web_frame->url()), form2.origin);
1212 EXPECT_EQ(GURL("http://buh.com"), form2.action); 1228 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1213 1229
1214 // TODO(jhawkins): We don't actually compare the value of the field in
1215 // FormField::operator==()!
1216 const std::vector<FormField>& fields2 = form2.fields; 1230 const std::vector<FormField>& fields2 = form2.fields;
1217 ASSERT_EQ(3U, fields2.size()); 1231 ASSERT_EQ(3U, fields2.size());
1218 EXPECT_EQ(FormField(string16(), 1232 EXPECT_TRUE(fields2[0].StrictlyEqualsHack(
1219 ASCIIToUTF16("firstname"), 1233 FormField(string16(),
1220 ASCIIToUTF16("Brother"), 1234 ASCIIToUTF16("firstname"),
1221 ASCIIToUTF16("text"), 1235 ASCIIToUTF16("Brother"),
1222 20), 1236 ASCIIToUTF16("text"),
1223 fields2[0]); 1237 20)));
1224 EXPECT_EQ(ASCIIToUTF16("Brother"), fields2[0].value()); 1238 EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
1225 EXPECT_EQ(FormField(string16(), 1239 FormField(string16(),
1226 ASCIIToUTF16("lastname"), 1240 ASCIIToUTF16("lastname"),
1227 ASCIIToUTF16("Jonathan"), 1241 ASCIIToUTF16("Jonathan"),
1228 ASCIIToUTF16("text"), 1242 ASCIIToUTF16("text"),
1229 20), 1243 20)));
1230 fields2[1]); 1244 EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
1231 EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields2[1].value()); 1245 FormField(string16(),
1232 EXPECT_EQ(FormField(string16(), 1246 ASCIIToUTF16("reply-send"),
1233 ASCIIToUTF16("reply-send"), 1247 string16(),
1234 ASCIIToUTF16("Send"), 1248 ASCIIToUTF16("submit"),
1235 ASCIIToUTF16("submit"), 1249 0)));
1236 0),
1237 fields2[2]);
1238 } 1250 }
1239 1251
1240 // This test sends a FormData object to FillForm with more fields than are in 1252 // This test sends a FormData object to FillForm with more fields than are in
1241 // the cached WebFormElement. In this case, we only fill out the fields that 1253 // the cached WebFormElement. In this case, we only fill out the fields that
1242 // match between the FormData object and the WebFormElement. 1254 // match between the FormData object and the WebFormElement.
1243 TEST_F(FormManagerTest, FillFormMoreFormDataFields) { 1255 TEST_F(FormManagerTest, FillFormMoreFormDataFields) {
1244 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1256 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1245 " <INPUT type=\"text\" id=\"firstname\"/>" 1257 " <INPUT type=\"text\" id=\"firstname\"/>"
1246 " <INPUT type=\"text\" id=\"middlename\"/>" 1258 " <INPUT type=\"text\" id=\"middlename\"/>"
1247 " <INPUT type=\"text\" id=\"lastname\"/>" 1259 " <INPUT type=\"text\" id=\"lastname\"/>"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 WebInputElement input_element = element.to<WebInputElement>(); 1324 WebInputElement input_element = element.to<WebInputElement>();
1313 1325
1314 // Find the newly-filled form that contains the input element. 1326 // Find the newly-filled form that contains the input element.
1315 FormData form2; 1327 FormData form2;
1316 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 1328 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
1317 input_element, FormManager::REQUIRE_NONE, &form2)); 1329 input_element, FormManager::REQUIRE_NONE, &form2));
1318 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1330 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1319 EXPECT_EQ(GURL(web_frame->url()), form2.origin); 1331 EXPECT_EQ(GURL(web_frame->url()), form2.origin);
1320 EXPECT_EQ(GURL("http://buh.com"), form2.action); 1332 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1321 1333
1322 // TODO(jhawkins): We don't actually compare the value of the field in
1323 // FormField::operator==()!
1324 const std::vector<FormField>& fields = form2.fields; 1334 const std::vector<FormField>& fields = form2.fields;
1325 ASSERT_EQ(4U, fields.size()); 1335 ASSERT_EQ(4U, fields.size());
1326 EXPECT_EQ(FormField(string16(), 1336 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
1327 ASCIIToUTF16("firstname"), 1337 ASCIIToUTF16("firstname"),
1328 ASCIIToUTF16("Brother"), 1338 ASCIIToUTF16("Brother"),
1329 ASCIIToUTF16("text"), 1339 ASCIIToUTF16("text"),
1330 20), 1340 20)));
1331 fields[0]); 1341 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
1332 EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value()); 1342 ASCIIToUTF16("middlename"),
1333 EXPECT_EQ(FormField(string16(), 1343 ASCIIToUTF16("Joseph"),
1334 ASCIIToUTF16("middlename"), 1344 ASCIIToUTF16("text"),
1335 ASCIIToUTF16("Joseph"), 1345 20)));
1336 ASCIIToUTF16("text"), 1346 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
1337 20), 1347 ASCIIToUTF16("lastname"),
1338 fields[1]); 1348 ASCIIToUTF16("Jonathan"),
1339 EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value()); 1349 ASCIIToUTF16("text"),
1340 EXPECT_EQ(FormField(string16(), 1350 20)));
1341 ASCIIToUTF16("lastname"), 1351 EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
1342 ASCIIToUTF16("Jonathan"), 1352 ASCIIToUTF16("reply-send"),
1343 ASCIIToUTF16("text"), 1353 string16(),
1344 20), 1354 ASCIIToUTF16("submit"),
1345 fields[2]); 1355 0)));
1346 EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value());
1347 EXPECT_EQ(FormField(string16(),
1348 ASCIIToUTF16("reply-send"),
1349 ASCIIToUTF16("Send"),
1350 ASCIIToUTF16("submit"),
1351 0),
1352 fields[3]);
1353 } 1356 }
1354 1357
1355 // This test sends a FormData object to FillForm with fewer fields than are in 1358 // This test sends a FormData object to FillForm with fewer fields than are in
1356 // the cached WebFormElement. In this case, we only fill out the fields that 1359 // the cached WebFormElement. In this case, we only fill out the fields that
1357 // match between the FormData object and the WebFormElement. 1360 // match between the FormData object and the WebFormElement.
1358 TEST_F(FormManagerTest, FillFormFewerFormDataFields) { 1361 TEST_F(FormManagerTest, FillFormFewerFormDataFields) {
1359 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1362 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1360 " <INPUT type=\"text\" id=\"prefix\"/>" 1363 " <INPUT type=\"text\" id=\"prefix\"/>"
1361 " <INPUT type=\"text\" id=\"firstname\"/>" 1364 " <INPUT type=\"text\" id=\"firstname\"/>"
1362 " <INPUT type=\"text\" id=\"hidden\"/>" 1365 " <INPUT type=\"text\" id=\"hidden\"/>"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 WebInputElement input_element = element.to<WebInputElement>(); 1402 WebInputElement input_element = element.to<WebInputElement>();
1400 1403
1401 // Find the newly-filled form that contains the input element. 1404 // Find the newly-filled form that contains the input element.
1402 FormData form2; 1405 FormData form2;
1403 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 1406 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
1404 input_element, FormManager::REQUIRE_NONE, &form2)); 1407 input_element, FormManager::REQUIRE_NONE, &form2));
1405 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1408 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1406 EXPECT_EQ(GURL(web_frame->url()), form2.origin); 1409 EXPECT_EQ(GURL(web_frame->url()), form2.origin);
1407 EXPECT_EQ(GURL("http://buh.com"), form2.action); 1410 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1408 1411
1409 // TODO(jhawkins): We don't actually compare the value of the field in
1410 // FormField::operator==()!
1411 const std::vector<FormField>& fields = form2.fields; 1412 const std::vector<FormField>& fields = form2.fields;
1412 ASSERT_EQ(8U, fields.size()); 1413 ASSERT_EQ(8U, fields.size());
1413 EXPECT_EQ(FormField(string16(), 1414 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
1414 ASCIIToUTF16("prefix"), 1415 ASCIIToUTF16("prefix"),
1415 string16(), 1416 string16(),
1416 ASCIIToUTF16("text"), 1417 ASCIIToUTF16("text"),
1417 20), 1418 20)));
1418 fields[0]); 1419 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
1419 EXPECT_EQ(string16(), fields[0].value()); 1420 ASCIIToUTF16("firstname"),
1420 EXPECT_EQ(FormField(string16(), 1421 ASCIIToUTF16("Brother"),
1421 ASCIIToUTF16("firstname"), 1422 ASCIIToUTF16("text"),
1422 ASCIIToUTF16("Brother"), 1423 20)));
1423 ASCIIToUTF16("text"), 1424 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
1424 20), 1425 ASCIIToUTF16("hidden"),
1425 fields[1]); 1426 string16(),
1426 EXPECT_EQ(ASCIIToUTF16("Brother"), fields[1].value()); 1427 ASCIIToUTF16("text"),
1427 EXPECT_EQ(FormField(string16(), 1428 20)));
1428 ASCIIToUTF16("hidden"), 1429 EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
1429 string16(), 1430 ASCIIToUTF16("middlename"),
1430 ASCIIToUTF16("text"), 1431 ASCIIToUTF16("Joseph"),
1431 20), 1432 ASCIIToUTF16("text"),
1432 fields[2]); 1433 20)));
1433 EXPECT_EQ(string16(), fields[2].value()); 1434 EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(),
1434 EXPECT_EQ(FormField(string16(), 1435 ASCIIToUTF16("second"),
1435 ASCIIToUTF16("middlename"), 1436 string16(),
1436 ASCIIToUTF16("Joseph"), 1437 ASCIIToUTF16("text"),
1437 ASCIIToUTF16("text"), 1438 20)));
1438 20), 1439 EXPECT_TRUE(fields[5].StrictlyEqualsHack(FormField(string16(),
1439 fields[3]); 1440 ASCIIToUTF16("lastname"),
1440 EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[3].value()); 1441 ASCIIToUTF16("Jonathan"),
1441 EXPECT_EQ(FormField(string16(), 1442 ASCIIToUTF16("text"),
1442 ASCIIToUTF16("second"), 1443 20)));
1443 string16(), 1444 EXPECT_TRUE(fields[6].StrictlyEqualsHack(FormField(string16(),
1444 ASCIIToUTF16("text"), 1445 ASCIIToUTF16("postfix"),
1445 20), 1446 string16(),
1446 fields[4]); 1447 ASCIIToUTF16("text"),
1447 EXPECT_EQ(string16(), fields[4].value()); 1448 20)));
1448 EXPECT_EQ(FormField(string16(), 1449 EXPECT_TRUE(fields[7].StrictlyEqualsHack(FormField(string16(),
1449 ASCIIToUTF16("lastname"), 1450 ASCIIToUTF16("reply-send"),
1450 ASCIIToUTF16("Jonathan"), 1451 string16(),
1451 ASCIIToUTF16("text"), 1452 ASCIIToUTF16("submit"),
1452 20), 1453 0)));
1453 fields[5]);
1454 EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[5].value());
1455 EXPECT_EQ(FormField(string16(),
1456 ASCIIToUTF16("postfix"),
1457 string16(),
1458 ASCIIToUTF16("text"),
1459 20),
1460 fields[6]);
1461 EXPECT_EQ(string16(), fields[6].value());
1462 EXPECT_EQ(FormField(string16(),
1463 ASCIIToUTF16("reply-send"),
1464 ASCIIToUTF16("Send"),
1465 ASCIIToUTF16("submit"),
1466 0),
1467 fields[7]);
1468 } 1454 }
1469 1455
1470 // This test sends a FormData object to FillForm with a field changed from 1456 // This test sends a FormData object to FillForm with a field changed from
1471 // those in the cached WebFormElement. In this case, we only fill out the 1457 // those in the cached WebFormElement. In this case, we only fill out the
1472 // fields that match between the FormData object and the WebFormElement. 1458 // fields that match between the FormData object and the WebFormElement.
1473 TEST_F(FormManagerTest, FillFormChangedFormDataFields) { 1459 TEST_F(FormManagerTest, FillFormChangedFormDataFields) {
1474 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1460 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1475 " <INPUT type=\"text\" id=\"firstname\"/>" 1461 " <INPUT type=\"text\" id=\"firstname\"/>"
1476 " <INPUT type=\"text\" id=\"middlename\"/>" 1462 " <INPUT type=\"text\" id=\"middlename\"/>"
1477 " <INPUT type=\"text\" id=\"lastname\"/>" 1463 " <INPUT type=\"text\" id=\"lastname\"/>"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 WebInputElement input_element = element.to<WebInputElement>(); 1497 WebInputElement input_element = element.to<WebInputElement>();
1512 1498
1513 // Find the newly-filled form that contains the input element. 1499 // Find the newly-filled form that contains the input element.
1514 FormData form2; 1500 FormData form2;
1515 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 1501 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
1516 input_element, FormManager::REQUIRE_NONE, &form2)); 1502 input_element, FormManager::REQUIRE_NONE, &form2));
1517 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1503 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1518 EXPECT_EQ(GURL(web_frame->url()), form2.origin); 1504 EXPECT_EQ(GURL(web_frame->url()), form2.origin);
1519 EXPECT_EQ(GURL("http://buh.com"), form2.action); 1505 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1520 1506
1521 // TODO(jhawkins): We don't actually compare the value of the field in
1522 // FormField::operator==()!
1523 const std::vector<FormField>& fields = form2.fields; 1507 const std::vector<FormField>& fields = form2.fields;
1524 ASSERT_EQ(4U, fields.size()); 1508 ASSERT_EQ(4U, fields.size());
1525 EXPECT_EQ(FormField(string16(), 1509 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
1526 ASCIIToUTF16("firstname"), 1510 ASCIIToUTF16("firstname"),
1527 ASCIIToUTF16("Brother"), 1511 ASCIIToUTF16("Brother"),
1528 ASCIIToUTF16("text"), 1512 ASCIIToUTF16("text"),
1529 20), 1513 20)));
1530 fields[0]); 1514 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
1531 EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value()); 1515 ASCIIToUTF16("middlename"),
1532 EXPECT_EQ(FormField(string16(), 1516 string16(),
1533 ASCIIToUTF16("middlename"), 1517 ASCIIToUTF16("text"),
1534 ASCIIToUTF16("Joseph"), 1518 20)));
1535 ASCIIToUTF16("text"), 1519 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
1536 20), 1520 ASCIIToUTF16("lastname"),
1537 fields[1]); 1521 ASCIIToUTF16("Jonathan"),
1538 EXPECT_EQ(string16(), fields[1].value()); 1522 ASCIIToUTF16("text"),
1539 EXPECT_EQ(FormField(string16(), 1523 20)));
1540 ASCIIToUTF16("lastname"), 1524 EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
1541 ASCIIToUTF16("Jonathan"), 1525 ASCIIToUTF16("reply-send"),
1542 ASCIIToUTF16("text"), 1526 string16(),
1543 20), 1527 ASCIIToUTF16("submit"),
1544 fields[2]); 1528 0)));
1545 EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value());
1546 EXPECT_EQ(FormField(string16(),
1547 ASCIIToUTF16("reply-send"),
1548 ASCIIToUTF16("Send"),
1549 ASCIIToUTF16("submit"),
1550 0),
1551 fields[3]);
1552 } 1529 }
1553 1530
1554 // This test sends a FormData object to FillForm with fewer fields than are in 1531 // This test sends a FormData object to FillForm with fewer fields than are in
1555 // the cached WebFormElement. In this case, we only fill out the fields that 1532 // the cached WebFormElement. In this case, we only fill out the fields that
1556 // match between the FormData object and the WebFormElement. 1533 // match between the FormData object and the WebFormElement.
1557 TEST_F(FormManagerTest, FillFormExtraFieldInCache) { 1534 TEST_F(FormManagerTest, FillFormExtraFieldInCache) {
1558 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1535 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1559 " <INPUT type=\"text\" id=\"firstname\"/>" 1536 " <INPUT type=\"text\" id=\"firstname\"/>"
1560 " <INPUT type=\"text\" id=\"middlename\"/>" 1537 " <INPUT type=\"text\" id=\"middlename\"/>"
1561 " <INPUT type=\"text\" id=\"lastname\"/>" 1538 " <INPUT type=\"text\" id=\"lastname\"/>"
(...skipping 30 matching lines...) Expand all
1592 WebInputElement input_element = element.to<WebInputElement>(); 1569 WebInputElement input_element = element.to<WebInputElement>();
1593 1570
1594 // Find the newly-filled form that contains the input element. 1571 // Find the newly-filled form that contains the input element.
1595 FormData form2; 1572 FormData form2;
1596 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( 1573 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
1597 input_element, FormManager::REQUIRE_NONE, &form2)); 1574 input_element, FormManager::REQUIRE_NONE, &form2));
1598 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1575 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1599 EXPECT_EQ(GURL(web_frame->url()), form2.origin); 1576 EXPECT_EQ(GURL(web_frame->url()), form2.origin);
1600 EXPECT_EQ(GURL("http://buh.com"), form2.action); 1577 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1601 1578
1602 // TODO(jhawkins): We don't actually compare the value of the field in
1603 // FormField::operator==()!
1604 const std::vector<FormField>& fields = form2.fields; 1579 const std::vector<FormField>& fields = form2.fields;
1605 ASSERT_EQ(5U, fields.size()); 1580 ASSERT_EQ(5U, fields.size());
1606 EXPECT_EQ(FormField(string16(), 1581 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
1607 ASCIIToUTF16("firstname"), 1582 ASCIIToUTF16("firstname"),
1608 ASCIIToUTF16("Brother"), 1583 ASCIIToUTF16("Brother"),
1609 ASCIIToUTF16("text"), 1584 ASCIIToUTF16("text"),
1610 20), 1585 20)));
1611 fields[0]); 1586 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
1612 EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value()); 1587 ASCIIToUTF16("middlename"),
1613 EXPECT_EQ(FormField(string16(), 1588 ASCIIToUTF16("Joseph"),
1614 ASCIIToUTF16("middlename"), 1589 ASCIIToUTF16("text"),
1615 ASCIIToUTF16("Joseph"), 1590 20)));
1616 ASCIIToUTF16("text"), 1591 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
1617 20), 1592 ASCIIToUTF16("lastname"),
1618 fields[1]); 1593 ASCIIToUTF16("Jonathan"),
1619 EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value()); 1594 ASCIIToUTF16("text"),
1620 EXPECT_EQ(FormField(string16(), 1595 20)));
1621 ASCIIToUTF16("lastname"), 1596 EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
1622 ASCIIToUTF16("Jonathan"), 1597 ASCIIToUTF16("postfix"),
1623 ASCIIToUTF16("text"), 1598 string16(),
1624 20), 1599 ASCIIToUTF16("text"),
1625 fields[2]); 1600 20)));
1626 EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value()); 1601 EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(),
1627 EXPECT_EQ(FormField(string16(), 1602 ASCIIToUTF16("reply-send"),
1628 ASCIIToUTF16("postfix"), 1603 string16(),
1629 string16(), 1604 ASCIIToUTF16("submit"),
1630 ASCIIToUTF16("text"), 1605 0)));
1631 20),
1632 fields[3]);
1633 EXPECT_EQ(string16(), fields[3].value());
1634 EXPECT_EQ(FormField(string16(),
1635 ASCIIToUTF16("reply-send"),
1636 ASCIIToUTF16("Send"),
1637 ASCIIToUTF16("submit"),
1638 0),
1639 fields[4]);
1640 } 1606 }
1641 1607
1642 TEST_F(FormManagerTest, FillFormEmptyName) { 1608 TEST_F(FormManagerTest, FillFormEmptyName) {
1643 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1609 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1644 " <INPUT type=\"text\" id=\"firstname\"/>" 1610 " <INPUT type=\"text\" id=\"firstname\"/>"
1645 " <INPUT type=\"text\" id=\"lastname\"/>" 1611 " <INPUT type=\"text\" id=\"lastname\"/>"
1646 " <INPUT type=\"submit\" value=\"Send\"/>" 1612 " <INPUT type=\"submit\" value=\"Send\"/>"
1647 "</FORM>"); 1613 "</FORM>");
1648 1614
1649 WebFrame* web_frame = GetMainFrame(); 1615 WebFrame* web_frame = GetMainFrame();
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 fields[5]); 1922 fields[5]);
1957 EXPECT_EQ(FormField(string16(), 1923 EXPECT_EQ(FormField(string16(),
1958 ASCIIToUTF16("reply-send"), 1924 ASCIIToUTF16("reply-send"),
1959 ASCIIToUTF16("Send"), 1925 ASCIIToUTF16("Send"),
1960 ASCIIToUTF16("submit"), 1926 ASCIIToUTF16("submit"),
1961 0), 1927 0),
1962 fields[6]); 1928 fields[6]);
1963 } 1929 }
1964 1930
1965 } // namespace 1931 } // namespace
OLDNEW
« chrome/renderer/form_manager.h ('K') | « chrome/renderer/form_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698