| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const char* const name; | 50 const char* const name; |
| 51 const char* const initial_value; | 51 const char* const initial_value; |
| 52 const char* const autocomplete_attribute; // The autocomplete attribute of | 52 const char* const autocomplete_attribute; // The autocomplete attribute of |
| 53 // the element. | 53 // the element. |
| 54 bool should_be_autofilled; // Whether the filed should be autofilled. | 54 bool should_be_autofilled; // Whether the filed should be autofilled. |
| 55 const char* const autofill_value; // The value being used to fill the field. | 55 const char* const autofill_value; // The value being used to fill the field. |
| 56 const char* const expected_value; // The expected value after Autofill | 56 const char* const expected_value; // The expected value after Autofill |
| 57 // or Preview. | 57 // or Preview. |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 static const char kFormHtml[] = | 60 const char kFormHtml[] = |
| 61 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 61 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 62 " <INPUT type='text' id='firstname'/>" | 62 " <INPUT type='text' id='firstname'/>" |
| 63 " <INPUT type='text' id='lastname'/>" | 63 " <INPUT type='text' id='lastname'/>" |
| 64 " <INPUT type='hidden' id='imhidden'/>" | 64 " <INPUT type='hidden' id='imhidden'/>" |
| 65 " <INPUT type='text' id='notempty' value='Hi'/>" | 65 " <INPUT type='text' id='notempty' value='Hi'/>" |
| 66 " <INPUT type='text' autocomplete='off' id='noautocomplete'/>" | 66 " <INPUT type='text' autocomplete='off' id='noautocomplete'/>" |
| 67 " <INPUT type='text' disabled='disabled' id='notenabled'/>" | 67 " <INPUT type='text' disabled='disabled' id='notenabled'/>" |
| 68 " <INPUT type='text' readonly id='readonly'/>" | 68 " <INPUT type='text' readonly id='readonly'/>" |
| 69 " <INPUT type='text' style='visibility: hidden'" | 69 " <INPUT type='text' style='visibility: hidden'" |
| 70 " id='invisible'/>" | 70 " id='invisible'/>" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 " </SELECT>" | 82 " </SELECT>" |
| 83 " <SELECT id='select-unchanged'>" | 83 " <SELECT id='select-unchanged'>" |
| 84 " <OPTION value='CA' selected>California</OPTION>" | 84 " <OPTION value='CA' selected>California</OPTION>" |
| 85 " <OPTION value='TX'>Texas</OPTION>" | 85 " <OPTION value='TX'>Texas</OPTION>" |
| 86 " </SELECT>" | 86 " </SELECT>" |
| 87 " <TEXTAREA id='textarea'></TEXTAREA>" | 87 " <TEXTAREA id='textarea'></TEXTAREA>" |
| 88 " <TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" | 88 " <TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" |
| 89 " <INPUT type='submit' name='reply-send' value='Send'/>" | 89 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 90 "</FORM>"; | 90 "</FORM>"; |
| 91 | 91 |
| 92 const char kUnownedFormHtml[] = |
| 93 "<INPUT type='text' id='firstname'/>" |
| 94 "<INPUT type='text' id='lastname'/>" |
| 95 "<INPUT type='hidden' id='imhidden'/>" |
| 96 "<INPUT type='text' id='notempty' value='Hi'/>" |
| 97 "<INPUT type='text' autocomplete='off' id='noautocomplete'/>" |
| 98 "<INPUT type='text' disabled='disabled' id='notenabled'/>" |
| 99 "<INPUT type='text' readonly id='readonly'/>" |
| 100 "<INPUT type='text' style='visibility: hidden'" |
| 101 " id='invisible'/>" |
| 102 "<INPUT type='text' style='display: none' id='displaynone'/>" |
| 103 "<INPUT type='month' id='month'/>" |
| 104 "<INPUT type='month' id='month-nonempty' value='2011-12'/>" |
| 105 "<SELECT id='select'>" |
| 106 " <OPTION></OPTION>" |
| 107 " <OPTION value='CA'>California</OPTION>" |
| 108 " <OPTION value='TX'>Texas</OPTION>" |
| 109 "</SELECT>" |
| 110 "<SELECT id='select-nonempty'>" |
| 111 " <OPTION value='CA' selected>California</OPTION>" |
| 112 " <OPTION value='TX'>Texas</OPTION>" |
| 113 "</SELECT>" |
| 114 "<SELECT id='select-unchanged'>" |
| 115 " <OPTION value='CA' selected>California</OPTION>" |
| 116 " <OPTION value='TX'>Texas</OPTION>" |
| 117 "</SELECT>" |
| 118 "<TEXTAREA id='textarea'></TEXTAREA>" |
| 119 "<TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" |
| 120 "<INPUT type='submit' name='reply-send' value='Send'/>"; |
| 121 |
| 92 std::string RetrievalMethodToString( | 122 std::string RetrievalMethodToString( |
| 93 const WebElementDescriptor::RetrievalMethod& method) { | 123 const WebElementDescriptor::RetrievalMethod& method) { |
| 94 switch (method) { | 124 switch (method) { |
| 95 case WebElementDescriptor::CSS_SELECTOR: | 125 case WebElementDescriptor::CSS_SELECTOR: |
| 96 return "CSS_SELECTOR"; | 126 return "CSS_SELECTOR"; |
| 97 case WebElementDescriptor::ID: | 127 case WebElementDescriptor::ID: |
| 98 return "ID"; | 128 return "ID"; |
| 99 case WebElementDescriptor::NONE: | 129 case WebElementDescriptor::NONE: |
| 100 return "NONE"; | 130 return "NONE"; |
| 101 } | 131 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 ExpectLabels(html, labels, names, values); | 238 ExpectLabels(html, labels, names, values); |
| 209 } | 239 } |
| 210 | 240 |
| 211 typedef void (*FillFormFunction)(const FormData& form, | 241 typedef void (*FillFormFunction)(const FormData& form, |
| 212 const WebFormControlElement& element); | 242 const WebFormControlElement& element); |
| 213 | 243 |
| 214 typedef WebString (*GetValueFunction)(WebFormControlElement element); | 244 typedef WebString (*GetValueFunction)(WebFormControlElement element); |
| 215 | 245 |
| 216 // Test FormFillxxx functions. | 246 // Test FormFillxxx functions. |
| 217 void TestFormFillFunctions(const char* html, | 247 void TestFormFillFunctions(const char* html, |
| 248 bool unowned, |
| 218 const AutofillFieldCase* field_cases, | 249 const AutofillFieldCase* field_cases, |
| 219 size_t number_of_field_cases, | 250 size_t number_of_field_cases, |
| 220 FillFormFunction fill_form_function, | 251 FillFormFunction fill_form_function, |
| 221 GetValueFunction get_value_function) { | 252 GetValueFunction get_value_function) { |
| 222 LoadHTML(html); | 253 LoadHTML(html); |
| 223 | 254 |
| 224 WebFrame* web_frame = GetMainFrame(); | 255 WebFrame* web_frame = GetMainFrame(); |
| 225 ASSERT_NE(nullptr, web_frame); | 256 ASSERT_NE(nullptr, web_frame); |
| 226 | 257 |
| 227 FormCache form_cache; | 258 FormCache form_cache; |
| 228 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 259 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 229 ASSERT_EQ(1U, forms.size()); | 260 ASSERT_EQ(1U, forms.size()); |
| 230 | 261 |
| 231 // Get the input element we want to find. | 262 // Get the input element we want to find. |
| 232 WebInputElement input_element = GetInputElementById("firstname"); | 263 WebInputElement input_element = GetInputElementById("firstname"); |
| 233 | 264 |
| 234 // Find the form that contains the input element. | 265 // Find the form that contains the input element. |
| 235 FormData form_data; | 266 FormData form_data; |
| 236 FormFieldData field; | 267 FormFieldData field; |
| 237 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 268 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 238 input_element, &form_data, &field, autofill::REQUIRE_NONE)); | 269 input_element, &form_data, &field, REQUIRE_NONE)); |
| 239 EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name); | 270 if (!unowned) { |
| 240 EXPECT_EQ(GURL(web_frame->document().url()), form_data.origin); | 271 EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name); |
| 241 EXPECT_EQ(GURL("http://buh.com"), form_data.action); | 272 EXPECT_EQ(GURL("http://buh.com"), form_data.action); |
| 273 } |
| 242 | 274 |
| 243 const std::vector<FormFieldData>& fields = form_data.fields; | 275 const std::vector<FormFieldData>& fields = form_data.fields; |
| 244 ASSERT_EQ(number_of_field_cases, fields.size()); | 276 ASSERT_EQ(number_of_field_cases, fields.size()); |
| 245 | 277 |
| 246 FormFieldData expected; | 278 FormFieldData expected; |
| 247 // Verify field's initial value. | 279 // Verify field's initial value. |
| 248 for (size_t i = 0; i < number_of_field_cases; ++i) { | 280 for (size_t i = 0; i < number_of_field_cases; ++i) { |
| 249 SCOPED_TRACE(base::StringPrintf("Verify initial value for field %s", | 281 SCOPED_TRACE(base::StringPrintf("Verify initial value for field %s", |
| 250 field_cases[i].name)); | 282 field_cases[i].name)); |
| 251 expected.form_control_type = field_cases[i].form_control_type; | 283 expected.form_control_type = field_cases[i].form_control_type; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 WebFormControlElement GetFormControlElementById(const WebString& id) { | 332 WebFormControlElement GetFormControlElementById(const WebString& id) { |
| 301 return GetMainFrame()->document().getElementById( | 333 return GetMainFrame()->document().getElementById( |
| 302 id).to<WebFormControlElement>(); | 334 id).to<WebFormControlElement>(); |
| 303 } | 335 } |
| 304 | 336 |
| 305 WebInputElement GetInputElementById(const WebString& id) { | 337 WebInputElement GetInputElementById(const WebString& id) { |
| 306 return GetMainFrame()->document().getElementById( | 338 return GetMainFrame()->document().getElementById( |
| 307 id).to<WebInputElement>(); | 339 id).to<WebInputElement>(); |
| 308 } | 340 } |
| 309 | 341 |
| 342 void TestFillForm(const char* html, bool unowned) { |
| 343 static const AutofillFieldCase field_cases[] = { |
| 344 // fields: form_control_type, name, initial_value, autocomplete_attribute, |
| 345 // should_be_autofilled, autofill_value, expected_value |
| 346 |
| 347 // Regular empty fields (firstname & lastname) should be autofilled. |
| 348 {"text", |
| 349 "firstname", |
| 350 "", |
| 351 "", |
| 352 true, |
| 353 "filled firstname", |
| 354 "filled firstname"}, |
| 355 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, |
| 356 // hidden fields should not be extracted to form_data. |
| 357 // Non empty fields should not be autofilled. |
| 358 {"text", "notempty", "Hi", "", false, "filled notempty", "Hi"}, |
| 359 {"text", |
| 360 "noautocomplete", |
| 361 "", |
| 362 "off", |
| 363 true, |
| 364 "filled noautocomplete", |
| 365 "filled noautocomplete"}, |
| 366 // Disabled fields should not be autofilled. |
| 367 {"text", "notenabled", "", "", false, "filled notenabled", ""}, |
| 368 // Readonly fields should not be autofilled. |
| 369 {"text", "readonly", "", "", false, "filled readonly", ""}, |
| 370 // Fields with "visibility: hidden" should not be autofilled. |
| 371 {"text", "invisible", "", "", false, "filled invisible", ""}, |
| 372 // Fields with "display:none" should not be autofilled. |
| 373 {"text", "displaynone", "", "", false, "filled displaynone", ""}, |
| 374 // Regular <input type="month"> should be autofilled. |
| 375 {"month", "month", "", "", true, "2017-11", "2017-11"}, |
| 376 // Non-empty <input type="month"> should not be autofilled. |
| 377 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"}, |
| 378 // Regular select fields should be autofilled. |
| 379 {"select-one", "select", "", "", true, "TX", "TX"}, |
| 380 // Select fields should be autofilled even if they already have a |
| 381 // non-empty value. |
| 382 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, |
| 383 // Select fields should not be autofilled if no new value is passed from |
| 384 // autofill profile. The existing value should not be overriden. |
| 385 {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"}, |
| 386 // Regular textarea elements should be autofilled. |
| 387 {"textarea", |
| 388 "textarea", |
| 389 "", |
| 390 "", |
| 391 true, |
| 392 "some multi-\nline value", |
| 393 "some multi-\nline value"}, |
| 394 // Non-empty textarea elements should not be autofilled. |
| 395 {"textarea", |
| 396 "textarea-nonempty", |
| 397 "Go\naway!", |
| 398 "", |
| 399 false, |
| 400 "some multi-\nline value", |
| 401 "Go\naway!"}, |
| 402 }; |
| 403 TestFormFillFunctions(html, unowned, field_cases, arraysize(field_cases), |
| 404 FillForm, &GetValueWrapper); |
| 405 // Verify preview selection. |
| 406 WebInputElement firstname = GetInputElementById("firstname"); |
| 407 EXPECT_EQ(16, firstname.selectionStart()); |
| 408 EXPECT_EQ(16, firstname.selectionEnd()); |
| 409 } |
| 410 |
| 411 void TestPreviewForm(const char* html, bool unowned) { |
| 412 static const AutofillFieldCase field_cases[] = { |
| 413 // Normal empty fields should be previewed. |
| 414 {"text", |
| 415 "firstname", |
| 416 "", |
| 417 "", |
| 418 true, |
| 419 "suggested firstname", |
| 420 "suggested firstname"}, |
| 421 {"text", |
| 422 "lastname", |
| 423 "", |
| 424 "", |
| 425 true, |
| 426 "suggested lastname", |
| 427 "suggested lastname"}, |
| 428 // Hidden fields should not be extracted to form_data. |
| 429 // Non empty fields should not be previewed. |
| 430 {"text", "notempty", "Hi", "", false, "suggested notempty", ""}, |
| 431 {"text", |
| 432 "noautocomplete", |
| 433 "", |
| 434 "off", |
| 435 true, |
| 436 "filled noautocomplete", |
| 437 "filled noautocomplete"}, |
| 438 // Disabled fields should not be previewed. |
| 439 {"text", "notenabled", "", "", false, "suggested notenabled", ""}, |
| 440 // Readonly fields should not be previewed. |
| 441 {"text", "readonly", "", "", false, "suggested readonly", ""}, |
| 442 // Fields with "visibility: hidden" should not be previewed. |
| 443 {"text", "invisible", "", "", false, "suggested invisible", ""}, |
| 444 // Fields with "display:none" should not previewed. |
| 445 {"text", "displaynone", "", "", false, "suggested displaynone", ""}, |
| 446 // Regular <input type="month"> should be previewed. |
| 447 {"month", "month", "", "", true, "2017-11", "2017-11"}, |
| 448 // Non-empty <input type="month"> should not be previewed. |
| 449 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, |
| 450 // Regular select fields should be previewed. |
| 451 {"select-one", "select", "", "", true, "TX", "TX"}, |
| 452 // Select fields should be previewed even if they already have a |
| 453 // non-empty value. |
| 454 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, |
| 455 // Select fields should not be previewed if no suggestion is passed from |
| 456 // autofill profile. |
| 457 {"select-one", "select-unchanged", "CA", "", false, "", ""}, |
| 458 // Normal textarea elements should be previewed. |
| 459 {"textarea", |
| 460 "textarea", |
| 461 "", |
| 462 "", |
| 463 true, |
| 464 "suggested multi-\nline value", |
| 465 "suggested multi-\nline value"}, |
| 466 // Nonempty textarea elements should not be previewed. |
| 467 {"textarea", |
| 468 "textarea-nonempty", |
| 469 "Go\naway!", |
| 470 "", |
| 471 false, |
| 472 "suggested multi-\nline value", |
| 473 ""}, |
| 474 }; |
| 475 TestFormFillFunctions(html, unowned, field_cases, arraysize(field_cases), |
| 476 &PreviewForm, &GetSuggestedValueWrapper); |
| 477 |
| 478 // Verify preview selection. |
| 479 WebInputElement firstname = GetInputElementById("firstname"); |
| 480 EXPECT_EQ(0, firstname.selectionStart()); |
| 481 EXPECT_EQ(19, firstname.selectionEnd()); |
| 482 } |
| 483 |
| 484 void TestFindFormForInputElement(const char* html, bool unowned) { |
| 485 LoadHTML(html); |
| 486 WebFrame* web_frame = GetMainFrame(); |
| 487 ASSERT_NE(nullptr, web_frame); |
| 488 |
| 489 FormCache form_cache; |
| 490 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 491 ASSERT_EQ(1U, forms.size()); |
| 492 |
| 493 // Get the input element we want to find. |
| 494 WebInputElement input_element = GetInputElementById("firstname"); |
| 495 |
| 496 // Find the form and verify it's the correct form. |
| 497 FormData form; |
| 498 FormFieldData field; |
| 499 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 500 input_element, &form, &field, REQUIRE_NONE)); |
| 501 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 502 if (!unowned) { |
| 503 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 504 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 505 } |
| 506 |
| 507 const std::vector<FormFieldData>& fields = form.fields; |
| 508 ASSERT_EQ(4U, fields.size()); |
| 509 |
| 510 FormFieldData expected; |
| 511 expected.form_control_type = "text"; |
| 512 expected.max_length = WebInputElement::defaultMaxLength(); |
| 513 |
| 514 expected.name = ASCIIToUTF16("firstname"); |
| 515 expected.value = ASCIIToUTF16("John"); |
| 516 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 517 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 518 |
| 519 expected.name = ASCIIToUTF16("lastname"); |
| 520 expected.value = ASCIIToUTF16("Smith"); |
| 521 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 522 |
| 523 expected.name = ASCIIToUTF16("email"); |
| 524 expected.value = ASCIIToUTF16("john@example.com"); |
| 525 expected.autocomplete_attribute = "off"; |
| 526 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 527 expected.autocomplete_attribute.clear(); |
| 528 |
| 529 expected.name = ASCIIToUTF16("phone"); |
| 530 expected.value = ASCIIToUTF16("1.800.555.1234"); |
| 531 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 532 |
| 533 // Try again, but require autocomplete. |
| 534 FormData form2; |
| 535 FormFieldData field2; |
| 536 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 537 input_element, &form2, &field2, REQUIRE_AUTOCOMPLETE)); |
| 538 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 539 if (!unowned) { |
| 540 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 541 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 542 } |
| 543 |
| 544 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 545 ASSERT_EQ(3U, fields2.size()); |
| 546 |
| 547 expected.form_control_type = "text"; |
| 548 expected.max_length = WebInputElement::defaultMaxLength(); |
| 549 |
| 550 expected.name = ASCIIToUTF16("firstname"); |
| 551 expected.value = ASCIIToUTF16("John"); |
| 552 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 553 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 554 |
| 555 expected.name = ASCIIToUTF16("lastname"); |
| 556 expected.value = ASCIIToUTF16("Smith"); |
| 557 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 558 |
| 559 expected.name = ASCIIToUTF16("phone"); |
| 560 expected.value = ASCIIToUTF16("1.800.555.1234"); |
| 561 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 562 } |
| 563 |
| 564 void TestFindFormForTextAreaElement(const char* html, bool unowned) { |
| 565 LoadHTML(html); |
| 566 WebFrame* web_frame = GetMainFrame(); |
| 567 ASSERT_NE(nullptr, web_frame); |
| 568 |
| 569 FormCache form_cache; |
| 570 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 571 ASSERT_EQ(1U, forms.size()); |
| 572 |
| 573 // Get the textarea element we want to find. |
| 574 WebElement element = web_frame->document().getElementById("street-address"); |
| 575 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); |
| 576 |
| 577 // Find the form and verify it's the correct form. |
| 578 FormData form; |
| 579 FormFieldData field; |
| 580 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 581 textarea_element, &form, &field, REQUIRE_NONE)); |
| 582 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 583 if (!unowned) { |
| 584 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 585 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 586 } |
| 587 |
| 588 const std::vector<FormFieldData>& fields = form.fields; |
| 589 ASSERT_EQ(4U, fields.size()); |
| 590 |
| 591 FormFieldData expected; |
| 592 |
| 593 expected.name = ASCIIToUTF16("firstname"); |
| 594 expected.value = ASCIIToUTF16("John"); |
| 595 expected.form_control_type = "text"; |
| 596 expected.max_length = WebInputElement::defaultMaxLength(); |
| 597 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 598 |
| 599 expected.name = ASCIIToUTF16("lastname"); |
| 600 expected.value = ASCIIToUTF16("Smith"); |
| 601 expected.form_control_type = "text"; |
| 602 expected.max_length = WebInputElement::defaultMaxLength(); |
| 603 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 604 |
| 605 expected.name = ASCIIToUTF16("email"); |
| 606 expected.value = ASCIIToUTF16("john@example.com"); |
| 607 expected.autocomplete_attribute = "off"; |
| 608 expected.form_control_type = "text"; |
| 609 expected.max_length = WebInputElement::defaultMaxLength(); |
| 610 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 611 expected.autocomplete_attribute.clear(); |
| 612 |
| 613 expected.name = ASCIIToUTF16("street-address"); |
| 614 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); |
| 615 expected.form_control_type = "textarea"; |
| 616 expected.max_length = 0; |
| 617 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 618 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 619 |
| 620 // Try again, but require autocomplete. |
| 621 FormData form2; |
| 622 FormFieldData field2; |
| 623 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 624 textarea_element, &form2, &field2, REQUIRE_AUTOCOMPLETE)); |
| 625 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 626 if (!unowned) { |
| 627 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 628 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 629 } |
| 630 |
| 631 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 632 ASSERT_EQ(3U, fields2.size()); |
| 633 |
| 634 expected.name = ASCIIToUTF16("firstname"); |
| 635 expected.value = ASCIIToUTF16("John"); |
| 636 expected.form_control_type = "text"; |
| 637 expected.max_length = WebInputElement::defaultMaxLength(); |
| 638 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 639 |
| 640 expected.name = ASCIIToUTF16("lastname"); |
| 641 expected.value = ASCIIToUTF16("Smith"); |
| 642 expected.form_control_type = "text"; |
| 643 expected.max_length = WebInputElement::defaultMaxLength(); |
| 644 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 645 |
| 646 expected.name = ASCIIToUTF16("street-address"); |
| 647 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); |
| 648 expected.form_control_type = "textarea"; |
| 649 expected.max_length = 0; |
| 650 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 651 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 652 } |
| 653 |
| 654 void TestFillFormMaxLength(const char* html, bool unowned) { |
| 655 LoadHTML(html); |
| 656 WebFrame* web_frame = GetMainFrame(); |
| 657 ASSERT_NE(nullptr, web_frame); |
| 658 |
| 659 FormCache form_cache; |
| 660 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 661 ASSERT_EQ(1U, forms.size()); |
| 662 |
| 663 // Get the input element we want to find. |
| 664 WebInputElement input_element = GetInputElementById("firstname"); |
| 665 |
| 666 // Find the form that contains the input element. |
| 667 FormData form; |
| 668 FormFieldData field; |
| 669 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 670 input_element, &form, &field, REQUIRE_NONE)); |
| 671 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 672 if (!unowned) { |
| 673 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 674 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 675 } |
| 676 |
| 677 const std::vector<FormFieldData>& fields = form.fields; |
| 678 ASSERT_EQ(3U, fields.size()); |
| 679 |
| 680 FormFieldData expected; |
| 681 expected.form_control_type = "text"; |
| 682 |
| 683 expected.name = ASCIIToUTF16("firstname"); |
| 684 expected.max_length = 5; |
| 685 expected.is_autofilled = false; |
| 686 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 687 |
| 688 expected.name = ASCIIToUTF16("lastname"); |
| 689 expected.max_length = 7; |
| 690 expected.is_autofilled = false; |
| 691 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 692 |
| 693 expected.name = ASCIIToUTF16("email"); |
| 694 expected.max_length = 9; |
| 695 expected.is_autofilled = false; |
| 696 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 697 |
| 698 // Fill the form. |
| 699 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 700 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 701 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 702 form.fields[0].is_autofilled = true; |
| 703 form.fields[1].is_autofilled = true; |
| 704 form.fields[2].is_autofilled = true; |
| 705 FillForm(form, input_element); |
| 706 |
| 707 // Find the newly-filled form that contains the input element. |
| 708 FormData form2; |
| 709 FormFieldData field2; |
| 710 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 711 input_element, &form2, &field2, REQUIRE_NONE)); |
| 712 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 713 if (!unowned) { |
| 714 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 715 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 716 } |
| 717 |
| 718 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 719 ASSERT_EQ(3U, fields2.size()); |
| 720 |
| 721 expected.form_control_type = "text"; |
| 722 |
| 723 expected.name = ASCIIToUTF16("firstname"); |
| 724 expected.value = ASCIIToUTF16("Broth"); |
| 725 expected.max_length = 5; |
| 726 expected.is_autofilled = true; |
| 727 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 728 |
| 729 expected.name = ASCIIToUTF16("lastname"); |
| 730 expected.value = ASCIIToUTF16("Jonatha"); |
| 731 expected.max_length = 7; |
| 732 expected.is_autofilled = true; |
| 733 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 734 |
| 735 expected.name = ASCIIToUTF16("email"); |
| 736 expected.value = ASCIIToUTF16("brotherj@"); |
| 737 expected.max_length = 9; |
| 738 expected.is_autofilled = true; |
| 739 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 740 } |
| 741 |
| 742 void TestFillFormNegativeMaxLength(const char* html, bool unowned) { |
| 743 LoadHTML(html); |
| 744 WebFrame* web_frame = GetMainFrame(); |
| 745 ASSERT_NE(nullptr, web_frame); |
| 746 |
| 747 FormCache form_cache; |
| 748 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 749 ASSERT_EQ(1U, forms.size()); |
| 750 |
| 751 // Get the input element we want to find. |
| 752 WebInputElement input_element = GetInputElementById("firstname"); |
| 753 |
| 754 // Find the form that contains the input element. |
| 755 FormData form; |
| 756 FormFieldData field; |
| 757 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 758 input_element, &form, &field, REQUIRE_NONE)); |
| 759 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 760 if (!unowned) { |
| 761 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 762 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 763 } |
| 764 |
| 765 const std::vector<FormFieldData>& fields = form.fields; |
| 766 ASSERT_EQ(3U, fields.size()); |
| 767 |
| 768 FormFieldData expected; |
| 769 expected.form_control_type = "text"; |
| 770 expected.max_length = WebInputElement::defaultMaxLength(); |
| 771 |
| 772 expected.name = ASCIIToUTF16("firstname"); |
| 773 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 774 |
| 775 expected.name = ASCIIToUTF16("lastname"); |
| 776 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 777 |
| 778 expected.name = ASCIIToUTF16("email"); |
| 779 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 780 |
| 781 // Fill the form. |
| 782 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 783 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 784 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 785 FillForm(form, input_element); |
| 786 |
| 787 // Find the newly-filled form that contains the input element. |
| 788 FormData form2; |
| 789 FormFieldData field2; |
| 790 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 791 input_element, &form2, &field2, REQUIRE_NONE)); |
| 792 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 793 if (!unowned) { |
| 794 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 795 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 796 } |
| 797 |
| 798 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 799 ASSERT_EQ(3U, fields2.size()); |
| 800 |
| 801 expected.name = ASCIIToUTF16("firstname"); |
| 802 expected.value = ASCIIToUTF16("Brother"); |
| 803 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 804 |
| 805 expected.name = ASCIIToUTF16("lastname"); |
| 806 expected.value = ASCIIToUTF16("Jonathan"); |
| 807 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 808 |
| 809 expected.name = ASCIIToUTF16("email"); |
| 810 expected.value = ASCIIToUTF16("brotherj@example.com"); |
| 811 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 812 } |
| 813 |
| 814 void TestFillFormEmptyName(const char* html, bool unowned) { |
| 815 LoadHTML(html); |
| 816 WebFrame* web_frame = GetMainFrame(); |
| 817 ASSERT_NE(nullptr, web_frame); |
| 818 |
| 819 FormCache form_cache; |
| 820 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 821 ASSERT_EQ(1U, forms.size()); |
| 822 |
| 823 // Get the input element we want to find. |
| 824 WebInputElement input_element = GetInputElementById("firstname"); |
| 825 |
| 826 // Find the form that contains the input element. |
| 827 FormData form; |
| 828 FormFieldData field; |
| 829 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 830 input_element, &form, &field, REQUIRE_NONE)); |
| 831 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 832 if (!unowned) { |
| 833 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 834 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 835 } |
| 836 |
| 837 const std::vector<FormFieldData>& fields = form.fields; |
| 838 ASSERT_EQ(3U, fields.size()); |
| 839 |
| 840 FormFieldData expected; |
| 841 expected.form_control_type = "text"; |
| 842 expected.max_length = WebInputElement::defaultMaxLength(); |
| 843 |
| 844 expected.name = ASCIIToUTF16("firstname"); |
| 845 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 846 |
| 847 expected.name = ASCIIToUTF16("lastname"); |
| 848 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 849 |
| 850 expected.name = ASCIIToUTF16("email"); |
| 851 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 852 |
| 853 // Fill the form. |
| 854 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 855 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 856 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 857 FillForm(form, input_element); |
| 858 |
| 859 // Find the newly-filled form that contains the input element. |
| 860 FormData form2; |
| 861 FormFieldData field2; |
| 862 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 863 input_element, &form2, &field2, REQUIRE_NONE)); |
| 864 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 865 if (!unowned) { |
| 866 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 867 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 868 } |
| 869 |
| 870 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 871 ASSERT_EQ(3U, fields2.size()); |
| 872 |
| 873 expected.form_control_type = "text"; |
| 874 expected.max_length = WebInputElement::defaultMaxLength(); |
| 875 |
| 876 expected.name = ASCIIToUTF16("firstname"); |
| 877 expected.value = ASCIIToUTF16("Wyatt"); |
| 878 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 879 |
| 880 expected.name = ASCIIToUTF16("lastname"); |
| 881 expected.value = ASCIIToUTF16("Earp"); |
| 882 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 883 |
| 884 expected.name = ASCIIToUTF16("email"); |
| 885 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 886 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 887 } |
| 888 |
| 889 void TestFillFormEmptyFormNames(const char* html, bool unowned) { |
| 890 LoadHTML(html); |
| 891 WebFrame* web_frame = GetMainFrame(); |
| 892 ASSERT_NE(nullptr, web_frame); |
| 893 |
| 894 FormCache form_cache; |
| 895 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 896 const size_t expected_size = unowned ? 1 : 2; |
| 897 ASSERT_EQ(expected_size, forms.size()); |
| 898 |
| 899 // Get the input element we want to find. |
| 900 WebInputElement input_element = GetInputElementById("apple"); |
| 901 |
| 902 // Find the form that contains the input element. |
| 903 FormData form; |
| 904 FormFieldData field; |
| 905 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 906 input_element, &form, &field, REQUIRE_NONE)); |
| 907 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 908 if (!unowned) { |
| 909 EXPECT_TRUE(form.name.empty()); |
| 910 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 911 } |
| 912 |
| 913 const std::vector<FormFieldData>& fields = form.fields; |
| 914 const size_t unowned_offset = unowned ? 3 : 0; |
| 915 ASSERT_EQ(unowned_offset + 3, fields.size()); |
| 916 |
| 917 FormFieldData expected; |
| 918 expected.form_control_type = "text"; |
| 919 expected.max_length = WebInputElement::defaultMaxLength(); |
| 920 |
| 921 expected.name = ASCIIToUTF16("apple"); |
| 922 expected.is_autofilled = false; |
| 923 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[unowned_offset]); |
| 924 |
| 925 expected.name = ASCIIToUTF16("banana"); |
| 926 expected.is_autofilled = false; |
| 927 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[unowned_offset + 1]); |
| 928 |
| 929 expected.name = ASCIIToUTF16("cantelope"); |
| 930 expected.is_autofilled = false; |
| 931 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[unowned_offset + 2]); |
| 932 |
| 933 // Fill the form. |
| 934 form.fields[unowned_offset + 0].value = ASCIIToUTF16("Red"); |
| 935 form.fields[unowned_offset + 1].value = ASCIIToUTF16("Yellow"); |
| 936 form.fields[unowned_offset + 2].value = ASCIIToUTF16("Also Yellow"); |
| 937 form.fields[unowned_offset + 0].is_autofilled = true; |
| 938 form.fields[unowned_offset + 1].is_autofilled = true; |
| 939 form.fields[unowned_offset + 2].is_autofilled = true; |
| 940 FillForm(form, input_element); |
| 941 |
| 942 // Find the newly-filled form that contains the input element. |
| 943 FormData form2; |
| 944 FormFieldData field2; |
| 945 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 946 input_element, &form2, &field2, REQUIRE_NONE)); |
| 947 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 948 if (!unowned) { |
| 949 EXPECT_TRUE(form2.name.empty()); |
| 950 EXPECT_EQ(GURL("http://abc.com"), form2.action); |
| 951 } |
| 952 |
| 953 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 954 ASSERT_EQ(unowned_offset + 3, fields2.size()); |
| 955 |
| 956 expected.name = ASCIIToUTF16("apple"); |
| 957 expected.value = ASCIIToUTF16("Red"); |
| 958 expected.is_autofilled = true; |
| 959 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 0]); |
| 960 |
| 961 expected.name = ASCIIToUTF16("banana"); |
| 962 expected.value = ASCIIToUTF16("Yellow"); |
| 963 expected.is_autofilled = true; |
| 964 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 1]); |
| 965 |
| 966 expected.name = ASCIIToUTF16("cantelope"); |
| 967 expected.value = ASCIIToUTF16("Also Yellow"); |
| 968 expected.is_autofilled = true; |
| 969 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 2]); |
| 970 } |
| 971 |
| 972 void TestFillFormNonEmptyField(const char* html, bool unowned) { |
| 973 LoadHTML(html); |
| 974 WebFrame* web_frame = GetMainFrame(); |
| 975 ASSERT_NE(nullptr, web_frame); |
| 976 |
| 977 FormCache form_cache; |
| 978 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 979 ASSERT_EQ(1U, forms.size()); |
| 980 |
| 981 // Get the input element we want to find. |
| 982 WebInputElement input_element = GetInputElementById("firstname"); |
| 983 |
| 984 // Simulate typing by modifying the field value. |
| 985 input_element.setValue(ASCIIToUTF16("Wy")); |
| 986 |
| 987 // Find the form that contains the input element. |
| 988 FormData form; |
| 989 FormFieldData field; |
| 990 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 991 input_element, &form, &field, REQUIRE_NONE)); |
| 992 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 993 if (!unowned) { |
| 994 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 995 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 996 } |
| 997 |
| 998 const std::vector<FormFieldData>& fields = form.fields; |
| 999 ASSERT_EQ(3U, fields.size()); |
| 1000 |
| 1001 FormFieldData expected; |
| 1002 expected.form_control_type = "text"; |
| 1003 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1004 |
| 1005 expected.name = ASCIIToUTF16("firstname"); |
| 1006 expected.value = ASCIIToUTF16("Wy"); |
| 1007 expected.is_autofilled = false; |
| 1008 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 1009 |
| 1010 expected.name = ASCIIToUTF16("lastname"); |
| 1011 expected.value.clear(); |
| 1012 expected.is_autofilled = false; |
| 1013 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 1014 |
| 1015 expected.name = ASCIIToUTF16("email"); |
| 1016 expected.value.clear(); |
| 1017 expected.is_autofilled = false; |
| 1018 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1019 |
| 1020 // Preview the form and verify that the cursor position has been updated. |
| 1021 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 1022 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 1023 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 1024 form.fields[0].is_autofilled = true; |
| 1025 form.fields[1].is_autofilled = true; |
| 1026 form.fields[2].is_autofilled = true; |
| 1027 PreviewForm(form, input_element); |
| 1028 EXPECT_EQ(2, input_element.selectionStart()); |
| 1029 EXPECT_EQ(5, input_element.selectionEnd()); |
| 1030 |
| 1031 // Fill the form. |
| 1032 FillForm(form, input_element); |
| 1033 |
| 1034 // Find the newly-filled form that contains the input element. |
| 1035 FormData form2; |
| 1036 FormFieldData field2; |
| 1037 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 1038 input_element, &form2, &field2, REQUIRE_NONE)); |
| 1039 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 1040 if (!unowned) { |
| 1041 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 1042 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 1043 } |
| 1044 |
| 1045 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 1046 ASSERT_EQ(3U, fields2.size()); |
| 1047 |
| 1048 expected.name = ASCIIToUTF16("firstname"); |
| 1049 expected.value = ASCIIToUTF16("Wyatt"); |
| 1050 expected.is_autofilled = true; |
| 1051 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 1052 |
| 1053 expected.name = ASCIIToUTF16("lastname"); |
| 1054 expected.value = ASCIIToUTF16("Earp"); |
| 1055 expected.is_autofilled = true; |
| 1056 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 1057 |
| 1058 expected.name = ASCIIToUTF16("email"); |
| 1059 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 1060 expected.is_autofilled = true; |
| 1061 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 1062 |
| 1063 // Verify that the cursor position has been updated. |
| 1064 EXPECT_EQ(5, input_element.selectionStart()); |
| 1065 EXPECT_EQ(5, input_element.selectionEnd()); |
| 1066 } |
| 1067 |
| 1068 void TestClearFormWithNode(const char* html, bool unowned) { |
| 1069 LoadHTML(html); |
| 1070 WebFrame* web_frame = GetMainFrame(); |
| 1071 ASSERT_NE(nullptr, web_frame); |
| 1072 |
| 1073 FormCache form_cache; |
| 1074 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 1075 ASSERT_EQ(1U, forms.size()); |
| 1076 |
| 1077 // Set the auto-filled attribute. |
| 1078 WebInputElement firstname = GetInputElementById("firstname"); |
| 1079 firstname.setAutofilled(true); |
| 1080 WebInputElement lastname = GetInputElementById("lastname"); |
| 1081 lastname.setAutofilled(true); |
| 1082 WebInputElement month = GetInputElementById("month"); |
| 1083 month.setAutofilled(true); |
| 1084 WebInputElement textarea = GetInputElementById("textarea"); |
| 1085 textarea.setAutofilled(true); |
| 1086 |
| 1087 // Set the value of the disabled text input element. |
| 1088 WebInputElement notenabled = GetInputElementById("notenabled"); |
| 1089 notenabled.setValue(WebString::fromUTF8("no clear")); |
| 1090 |
| 1091 // Clear the form. |
| 1092 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 1093 |
| 1094 // Verify that the auto-filled attribute has been turned off. |
| 1095 EXPECT_FALSE(firstname.isAutofilled()); |
| 1096 |
| 1097 // Verify the form is cleared. |
| 1098 FormData form; |
| 1099 FormFieldData field; |
| 1100 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 1101 firstname, &form, &field, REQUIRE_NONE)); |
| 1102 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1103 if (!unowned) { |
| 1104 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1105 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1106 } |
| 1107 |
| 1108 const std::vector<FormFieldData>& fields = form.fields; |
| 1109 ASSERT_EQ(9U, fields.size()); |
| 1110 |
| 1111 FormFieldData expected; |
| 1112 expected.form_control_type = "text"; |
| 1113 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1114 |
| 1115 expected.name = ASCIIToUTF16("firstname"); |
| 1116 expected.value.clear(); |
| 1117 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 1118 |
| 1119 expected.name = ASCIIToUTF16("lastname"); |
| 1120 expected.value.clear(); |
| 1121 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 1122 |
| 1123 expected.name = ASCIIToUTF16("noAC"); |
| 1124 expected.value = ASCIIToUTF16("one"); |
| 1125 expected.autocomplete_attribute = "off"; |
| 1126 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1127 expected.autocomplete_attribute.clear(); |
| 1128 |
| 1129 expected.name = ASCIIToUTF16("notenabled"); |
| 1130 expected.value = ASCIIToUTF16("no clear"); |
| 1131 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 1132 |
| 1133 expected.form_control_type = "month"; |
| 1134 expected.max_length = 0; |
| 1135 expected.name = ASCIIToUTF16("month"); |
| 1136 expected.value.clear(); |
| 1137 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]); |
| 1138 |
| 1139 expected.name = ASCIIToUTF16("month-disabled"); |
| 1140 expected.value = ASCIIToUTF16("2012-11"); |
| 1141 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
| 1142 |
| 1143 expected.form_control_type = "textarea"; |
| 1144 expected.name = ASCIIToUTF16("textarea"); |
| 1145 expected.value.clear(); |
| 1146 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[6]); |
| 1147 |
| 1148 expected.name = ASCIIToUTF16("textarea-disabled"); |
| 1149 expected.value = ASCIIToUTF16(" Banana! "); |
| 1150 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[7]); |
| 1151 |
| 1152 expected.name = ASCIIToUTF16("textarea-noAC"); |
| 1153 expected.value = ASCIIToUTF16("Carrot?"); |
| 1154 expected.autocomplete_attribute = "off"; |
| 1155 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[8]); |
| 1156 expected.autocomplete_attribute.clear(); |
| 1157 |
| 1158 // Verify that the cursor position has been updated. |
| 1159 EXPECT_EQ(0, firstname.selectionStart()); |
| 1160 EXPECT_EQ(0, firstname.selectionEnd()); |
| 1161 } |
| 1162 |
| 1163 void TestClearFormWithNodeContainingSelectOne(const char* html, |
| 1164 bool unowned) { |
| 1165 LoadHTML(html); |
| 1166 WebFrame* web_frame = GetMainFrame(); |
| 1167 ASSERT_NE(nullptr, web_frame); |
| 1168 |
| 1169 FormCache form_cache; |
| 1170 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 1171 ASSERT_EQ(1U, forms.size()); |
| 1172 |
| 1173 // Set the auto-filled attribute. |
| 1174 WebInputElement firstname = GetInputElementById("firstname"); |
| 1175 firstname.setAutofilled(true); |
| 1176 WebInputElement lastname = GetInputElementById("lastname"); |
| 1177 lastname.setAutofilled(true); |
| 1178 |
| 1179 // Set the value and auto-filled attribute of the state element. |
| 1180 WebSelectElement state = |
| 1181 web_frame->document().getElementById("state").to<WebSelectElement>(); |
| 1182 state.setValue(WebString::fromUTF8("AK")); |
| 1183 state.setAutofilled(true); |
| 1184 |
| 1185 // Clear the form. |
| 1186 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 1187 |
| 1188 // Verify that the auto-filled attribute has been turned off. |
| 1189 EXPECT_FALSE(firstname.isAutofilled()); |
| 1190 |
| 1191 // Verify the form is cleared. |
| 1192 FormData form; |
| 1193 FormFieldData field; |
| 1194 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 1195 firstname, &form, &field, REQUIRE_NONE)); |
| 1196 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1197 if (!unowned) { |
| 1198 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1199 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1200 } |
| 1201 |
| 1202 const std::vector<FormFieldData>& fields = form.fields; |
| 1203 ASSERT_EQ(3U, fields.size()); |
| 1204 |
| 1205 FormFieldData expected; |
| 1206 |
| 1207 expected.name = ASCIIToUTF16("firstname"); |
| 1208 expected.value.clear(); |
| 1209 expected.form_control_type = "text"; |
| 1210 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1211 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 1212 |
| 1213 expected.name = ASCIIToUTF16("lastname"); |
| 1214 expected.value.clear(); |
| 1215 expected.form_control_type = "text"; |
| 1216 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1217 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 1218 |
| 1219 expected.name = ASCIIToUTF16("state"); |
| 1220 expected.value = ASCIIToUTF16("?"); |
| 1221 expected.form_control_type = "select-one"; |
| 1222 expected.max_length = 0; |
| 1223 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1224 |
| 1225 // Verify that the cursor position has been updated. |
| 1226 EXPECT_EQ(0, firstname.selectionStart()); |
| 1227 EXPECT_EQ(0, firstname.selectionEnd()); |
| 1228 } |
| 1229 |
| 1230 void TestClearPreviewedFormWithElement(const char* html) { |
| 1231 LoadHTML(html); |
| 1232 WebFrame* web_frame = GetMainFrame(); |
| 1233 ASSERT_NE(nullptr, web_frame); |
| 1234 |
| 1235 FormCache form_cache; |
| 1236 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 1237 ASSERT_EQ(1U, forms.size()); |
| 1238 |
| 1239 // Set the auto-filled attribute. |
| 1240 WebInputElement firstname = GetInputElementById("firstname"); |
| 1241 firstname.setAutofilled(true); |
| 1242 WebInputElement lastname = GetInputElementById("lastname"); |
| 1243 lastname.setAutofilled(true); |
| 1244 WebInputElement email = GetInputElementById("email"); |
| 1245 email.setAutofilled(true); |
| 1246 WebInputElement email2 = GetInputElementById("email2"); |
| 1247 email2.setAutofilled(true); |
| 1248 WebInputElement phone = GetInputElementById("phone"); |
| 1249 phone.setAutofilled(true); |
| 1250 |
| 1251 // Set the suggested values on two of the elements. |
| 1252 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
| 1253 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
| 1254 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
| 1255 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
| 1256 |
| 1257 // Clear the previewed fields. |
| 1258 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false)); |
| 1259 |
| 1260 // Fields with empty suggestions suggestions are not modified. |
| 1261 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
| 1262 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
| 1263 EXPECT_TRUE(firstname.isAutofilled()); |
| 1264 |
| 1265 // Verify the previewed fields are cleared. |
| 1266 EXPECT_TRUE(lastname.value().isEmpty()); |
| 1267 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
| 1268 EXPECT_FALSE(lastname.isAutofilled()); |
| 1269 EXPECT_TRUE(email.value().isEmpty()); |
| 1270 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 1271 EXPECT_FALSE(email.isAutofilled()); |
| 1272 EXPECT_TRUE(email2.value().isEmpty()); |
| 1273 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
| 1274 EXPECT_FALSE(email2.isAutofilled()); |
| 1275 EXPECT_TRUE(phone.value().isEmpty()); |
| 1276 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 1277 EXPECT_FALSE(phone.isAutofilled()); |
| 1278 |
| 1279 // Verify that the cursor position has been updated. |
| 1280 EXPECT_EQ(0, lastname.selectionStart()); |
| 1281 EXPECT_EQ(0, lastname.selectionEnd()); |
| 1282 } |
| 1283 |
| 1284 void TestClearPreviewedFormWithNonEmptyInitiatingNode(const char* html) { |
| 1285 LoadHTML(html); |
| 1286 WebFrame* web_frame = GetMainFrame(); |
| 1287 ASSERT_NE(nullptr, web_frame); |
| 1288 |
| 1289 FormCache form_cache; |
| 1290 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 1291 ASSERT_EQ(1U, forms.size()); |
| 1292 |
| 1293 // Set the auto-filled attribute. |
| 1294 WebInputElement firstname = GetInputElementById("firstname"); |
| 1295 firstname.setAutofilled(true); |
| 1296 WebInputElement lastname = GetInputElementById("lastname"); |
| 1297 lastname.setAutofilled(true); |
| 1298 WebInputElement email = GetInputElementById("email"); |
| 1299 email.setAutofilled(true); |
| 1300 WebInputElement email2 = GetInputElementById("email2"); |
| 1301 email2.setAutofilled(true); |
| 1302 WebInputElement phone = GetInputElementById("phone"); |
| 1303 phone.setAutofilled(true); |
| 1304 |
| 1305 |
| 1306 // Set the suggested values on all of the elements. |
| 1307 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
| 1308 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
| 1309 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
| 1310 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
| 1311 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
| 1312 |
| 1313 // Clear the previewed fields. |
| 1314 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, false)); |
| 1315 |
| 1316 // Fields with non-empty values are restored. |
| 1317 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); |
| 1318 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
| 1319 EXPECT_FALSE(firstname.isAutofilled()); |
| 1320 EXPECT_EQ(1, firstname.selectionStart()); |
| 1321 EXPECT_EQ(1, firstname.selectionEnd()); |
| 1322 |
| 1323 // Verify the previewed fields are cleared. |
| 1324 EXPECT_TRUE(lastname.value().isEmpty()); |
| 1325 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
| 1326 EXPECT_FALSE(lastname.isAutofilled()); |
| 1327 EXPECT_TRUE(email.value().isEmpty()); |
| 1328 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 1329 EXPECT_FALSE(email.isAutofilled()); |
| 1330 EXPECT_TRUE(email2.value().isEmpty()); |
| 1331 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
| 1332 EXPECT_FALSE(email2.isAutofilled()); |
| 1333 EXPECT_TRUE(phone.value().isEmpty()); |
| 1334 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 1335 EXPECT_FALSE(phone.isAutofilled()); |
| 1336 } |
| 1337 |
| 1338 void TestClearPreviewedFormWithAutofilledInitiatingNode(const char* html) { |
| 1339 LoadHTML(html); |
| 1340 WebFrame* web_frame = GetMainFrame(); |
| 1341 ASSERT_NE(nullptr, web_frame); |
| 1342 |
| 1343 FormCache form_cache; |
| 1344 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 1345 ASSERT_EQ(1U, forms.size()); |
| 1346 |
| 1347 // Set the auto-filled attribute. |
| 1348 WebInputElement firstname = GetInputElementById("firstname"); |
| 1349 firstname.setAutofilled(true); |
| 1350 WebInputElement lastname = GetInputElementById("lastname"); |
| 1351 lastname.setAutofilled(true); |
| 1352 WebInputElement email = GetInputElementById("email"); |
| 1353 email.setAutofilled(true); |
| 1354 WebInputElement email2 = GetInputElementById("email2"); |
| 1355 email2.setAutofilled(true); |
| 1356 WebInputElement phone = GetInputElementById("phone"); |
| 1357 phone.setAutofilled(true); |
| 1358 |
| 1359 // Set the suggested values on all of the elements. |
| 1360 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
| 1361 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
| 1362 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
| 1363 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
| 1364 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
| 1365 |
| 1366 // Clear the previewed fields. |
| 1367 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, true)); |
| 1368 |
| 1369 // Fields with non-empty values are restored. |
| 1370 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); |
| 1371 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
| 1372 EXPECT_TRUE(firstname.isAutofilled()); |
| 1373 EXPECT_EQ(1, firstname.selectionStart()); |
| 1374 EXPECT_EQ(1, firstname.selectionEnd()); |
| 1375 |
| 1376 // Verify the previewed fields are cleared. |
| 1377 EXPECT_TRUE(lastname.value().isEmpty()); |
| 1378 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
| 1379 EXPECT_FALSE(lastname.isAutofilled()); |
| 1380 EXPECT_TRUE(email.value().isEmpty()); |
| 1381 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 1382 EXPECT_FALSE(email.isAutofilled()); |
| 1383 EXPECT_TRUE(email2.value().isEmpty()); |
| 1384 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
| 1385 EXPECT_FALSE(email2.isAutofilled()); |
| 1386 EXPECT_TRUE(phone.value().isEmpty()); |
| 1387 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 1388 EXPECT_FALSE(phone.isAutofilled()); |
| 1389 } |
| 1390 |
| 1391 void TestClearOnlyAutofilledFields(const char* html) { |
| 1392 LoadHTML(html); |
| 1393 |
| 1394 WebFrame* web_frame = GetMainFrame(); |
| 1395 ASSERT_NE(nullptr, web_frame); |
| 1396 |
| 1397 FormCache form_cache; |
| 1398 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
| 1399 ASSERT_EQ(1U, forms.size()); |
| 1400 |
| 1401 // Set the autofilled attribute. |
| 1402 WebInputElement firstname = GetInputElementById("firstname"); |
| 1403 firstname.setAutofilled(false); |
| 1404 WebInputElement lastname = GetInputElementById("lastname"); |
| 1405 lastname.setAutofilled(true); |
| 1406 WebInputElement email = GetInputElementById("email"); |
| 1407 email.setAutofilled(true); |
| 1408 WebInputElement phone = GetInputElementById("phone"); |
| 1409 phone.setAutofilled(true); |
| 1410 |
| 1411 // Clear the fields. |
| 1412 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 1413 |
| 1414 // Verify only autofilled fields are cleared. |
| 1415 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
| 1416 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
| 1417 EXPECT_FALSE(firstname.isAutofilled()); |
| 1418 EXPECT_TRUE(lastname.value().isEmpty()); |
| 1419 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
| 1420 EXPECT_FALSE(lastname.isAutofilled()); |
| 1421 EXPECT_TRUE(email.value().isEmpty()); |
| 1422 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 1423 EXPECT_FALSE(email.isAutofilled()); |
| 1424 EXPECT_TRUE(phone.value().isEmpty()); |
| 1425 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 1426 EXPECT_FALSE(phone.isAutofilled()); |
| 1427 } |
| 1428 |
| 310 static void FillFormIncludingNonFocusableElementsWrapper( | 1429 static void FillFormIncludingNonFocusableElementsWrapper( |
| 311 const FormData& form, | 1430 const FormData& form, |
| 312 const WebFormControlElement& element) { | 1431 const WebFormControlElement& element) { |
| 313 FillFormIncludingNonFocusableElements(form, element.form()); | 1432 FillFormIncludingNonFocusableElements(form, element.form()); |
| 314 } | 1433 } |
| 315 | 1434 |
| 316 static WebString GetValueWrapper(WebFormControlElement element) { | 1435 static WebString GetValueWrapper(WebFormControlElement element) { |
| 317 if (element.formControlType() == "textarea") | 1436 if (element.formControlType() == "textarea") |
| 318 return element.to<WebTextAreaElement>().value(); | 1437 return element.to<WebTextAreaElement>().value(); |
| 319 | 1438 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 339 | 1458 |
| 340 // We should be able to extract a normal text field. | 1459 // We should be able to extract a normal text field. |
| 341 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { | 1460 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { |
| 342 LoadHTML("<INPUT type='text' id='element' value='value'/>"); | 1461 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
| 343 | 1462 |
| 344 WebFrame* frame = GetMainFrame(); | 1463 WebFrame* frame = GetMainFrame(); |
| 345 ASSERT_NE(nullptr, frame); | 1464 ASSERT_NE(nullptr, frame); |
| 346 | 1465 |
| 347 WebFormControlElement element = GetFormControlElementById("element"); | 1466 WebFormControlElement element = GetFormControlElementById("element"); |
| 348 FormFieldData result1; | 1467 FormFieldData result1; |
| 349 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); | 1468 WebFormControlElementToFormField(element, EXTRACT_NONE, &result1); |
| 350 | 1469 |
| 351 FormFieldData expected; | 1470 FormFieldData expected; |
| 352 expected.form_control_type = "text"; | 1471 expected.form_control_type = "text"; |
| 353 expected.max_length = WebInputElement::defaultMaxLength(); | 1472 expected.max_length = WebInputElement::defaultMaxLength(); |
| 354 | 1473 |
| 355 expected.name = ASCIIToUTF16("element"); | 1474 expected.name = ASCIIToUTF16("element"); |
| 356 expected.value = base::string16(); | 1475 expected.value.clear(); |
| 357 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 1476 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
| 358 | 1477 |
| 359 FormFieldData result2; | 1478 FormFieldData result2; |
| 360 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); | 1479 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result2); |
| 361 | 1480 |
| 362 expected.name = ASCIIToUTF16("element"); | 1481 expected.name = ASCIIToUTF16("element"); |
| 363 expected.value = ASCIIToUTF16("value"); | 1482 expected.value = ASCIIToUTF16("value"); |
| 364 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); | 1483 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
| 365 } | 1484 } |
| 366 | 1485 |
| 367 // We should be able to extract a text field with autocomplete="off". | 1486 // We should be able to extract a text field with autocomplete="off". |
| 368 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { | 1487 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { |
| 369 LoadHTML("<INPUT type='text' id='element' value='value'" | 1488 LoadHTML("<INPUT type='text' id='element' value='value'" |
| 370 " autocomplete='off'/>"); | 1489 " autocomplete='off'/>"); |
| 371 | 1490 |
| 372 WebFrame* frame = GetMainFrame(); | 1491 WebFrame* frame = GetMainFrame(); |
| 373 ASSERT_NE(nullptr, frame); | 1492 ASSERT_NE(nullptr, frame); |
| 374 | 1493 |
| 375 WebFormControlElement element = GetFormControlElementById("element"); | 1494 WebFormControlElement element = GetFormControlElementById("element"); |
| 376 FormFieldData result; | 1495 FormFieldData result; |
| 377 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1496 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 378 | 1497 |
| 379 FormFieldData expected; | 1498 FormFieldData expected; |
| 380 expected.name = ASCIIToUTF16("element"); | 1499 expected.name = ASCIIToUTF16("element"); |
| 381 expected.value = ASCIIToUTF16("value"); | 1500 expected.value = ASCIIToUTF16("value"); |
| 382 expected.form_control_type = "text"; | 1501 expected.form_control_type = "text"; |
| 383 expected.autocomplete_attribute = "off"; | 1502 expected.autocomplete_attribute = "off"; |
| 384 expected.max_length = WebInputElement::defaultMaxLength(); | 1503 expected.max_length = WebInputElement::defaultMaxLength(); |
| 385 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1504 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 386 } | 1505 } |
| 387 | 1506 |
| 388 // We should be able to extract a text field with maxlength specified. | 1507 // We should be able to extract a text field with maxlength specified. |
| 389 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { | 1508 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { |
| 390 LoadHTML("<INPUT type='text' id='element' value='value'" | 1509 LoadHTML("<INPUT type='text' id='element' value='value'" |
| 391 " maxlength='5'/>"); | 1510 " maxlength='5'/>"); |
| 392 | 1511 |
| 393 WebFrame* frame = GetMainFrame(); | 1512 WebFrame* frame = GetMainFrame(); |
| 394 ASSERT_NE(nullptr, frame); | 1513 ASSERT_NE(nullptr, frame); |
| 395 | 1514 |
| 396 WebFormControlElement element = GetFormControlElementById("element"); | 1515 WebFormControlElement element = GetFormControlElementById("element"); |
| 397 FormFieldData result; | 1516 FormFieldData result; |
| 398 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1517 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 399 | 1518 |
| 400 FormFieldData expected; | 1519 FormFieldData expected; |
| 401 expected.name = ASCIIToUTF16("element"); | 1520 expected.name = ASCIIToUTF16("element"); |
| 402 expected.value = ASCIIToUTF16("value"); | 1521 expected.value = ASCIIToUTF16("value"); |
| 403 expected.form_control_type = "text"; | 1522 expected.form_control_type = "text"; |
| 404 expected.max_length = 5; | 1523 expected.max_length = 5; |
| 405 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1524 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 406 } | 1525 } |
| 407 | 1526 |
| 408 // We should be able to extract a text field that has been autofilled. | 1527 // We should be able to extract a text field that has been autofilled. |
| 409 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { | 1528 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { |
| 410 LoadHTML("<INPUT type='text' id='element' value='value'/>"); | 1529 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
| 411 | 1530 |
| 412 WebFrame* frame = GetMainFrame(); | 1531 WebFrame* frame = GetMainFrame(); |
| 413 ASSERT_NE(nullptr, frame); | 1532 ASSERT_NE(nullptr, frame); |
| 414 | 1533 |
| 415 WebInputElement element = GetInputElementById("element"); | 1534 WebInputElement element = GetInputElementById("element"); |
| 416 element.setAutofilled(true); | 1535 element.setAutofilled(true); |
| 417 FormFieldData result; | 1536 FormFieldData result; |
| 418 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1537 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 419 | 1538 |
| 420 FormFieldData expected; | 1539 FormFieldData expected; |
| 421 expected.name = ASCIIToUTF16("element"); | 1540 expected.name = ASCIIToUTF16("element"); |
| 422 expected.value = ASCIIToUTF16("value"); | 1541 expected.value = ASCIIToUTF16("value"); |
| 423 expected.form_control_type = "text"; | 1542 expected.form_control_type = "text"; |
| 424 expected.max_length = WebInputElement::defaultMaxLength(); | 1543 expected.max_length = WebInputElement::defaultMaxLength(); |
| 425 expected.is_autofilled = true; | 1544 expected.is_autofilled = true; |
| 426 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1545 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 427 } | 1546 } |
| 428 | 1547 |
| 429 // We should be able to extract a radio or a checkbox field that has been | 1548 // We should be able to extract a radio or a checkbox field that has been |
| 430 // autofilled. | 1549 // autofilled. |
| 431 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { | 1550 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { |
| 432 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" | 1551 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" |
| 433 "<INPUT type='radio' id='radio' value='male'/>"); | 1552 "<INPUT type='radio' id='radio' value='male'/>"); |
| 434 | 1553 |
| 435 WebFrame* frame = GetMainFrame(); | 1554 WebFrame* frame = GetMainFrame(); |
| 436 ASSERT_NE(nullptr, frame); | 1555 ASSERT_NE(nullptr, frame); |
| 437 | 1556 |
| 438 WebInputElement element = GetInputElementById("checkbox"); | 1557 WebInputElement element = GetInputElementById("checkbox"); |
| 439 element.setAutofilled(true); | 1558 element.setAutofilled(true); |
| 440 FormFieldData result; | 1559 FormFieldData result; |
| 441 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1560 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 442 | 1561 |
| 443 FormFieldData expected; | 1562 FormFieldData expected; |
| 444 expected.name = ASCIIToUTF16("checkbox"); | 1563 expected.name = ASCIIToUTF16("checkbox"); |
| 445 expected.value = ASCIIToUTF16("mail"); | 1564 expected.value = ASCIIToUTF16("mail"); |
| 446 expected.form_control_type = "checkbox"; | 1565 expected.form_control_type = "checkbox"; |
| 447 expected.is_autofilled = true; | 1566 expected.is_autofilled = true; |
| 448 expected.is_checkable = true; | 1567 expected.is_checkable = true; |
| 449 expected.is_checked = true; | 1568 expected.is_checked = true; |
| 450 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1569 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 451 | 1570 |
| 452 element = GetInputElementById("radio"); | 1571 element = GetInputElementById("radio"); |
| 453 element.setAutofilled(true); | 1572 element.setAutofilled(true); |
| 454 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1573 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 455 expected.name = ASCIIToUTF16("radio"); | 1574 expected.name = ASCIIToUTF16("radio"); |
| 456 expected.value = ASCIIToUTF16("male"); | 1575 expected.value = ASCIIToUTF16("male"); |
| 457 expected.form_control_type = "radio"; | 1576 expected.form_control_type = "radio"; |
| 458 expected.is_autofilled = true; | 1577 expected.is_autofilled = true; |
| 459 expected.is_checkable = true; | 1578 expected.is_checkable = true; |
| 460 expected.is_checked = false; | 1579 expected.is_checked = false; |
| 461 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1580 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 462 } | 1581 } |
| 463 | 1582 |
| 464 // We should be able to extract a <select> field. | 1583 // We should be able to extract a <select> field. |
| 465 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 1584 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
| 466 LoadHTML("<SELECT id='element'/>" | 1585 LoadHTML("<SELECT id='element'/>" |
| 467 " <OPTION value='CA'>California</OPTION>" | 1586 " <OPTION value='CA'>California</OPTION>" |
| 468 " <OPTION value='TX'>Texas</OPTION>" | 1587 " <OPTION value='TX'>Texas</OPTION>" |
| 469 "</SELECT>"); | 1588 "</SELECT>"); |
| 470 | 1589 |
| 471 WebFrame* frame = GetMainFrame(); | 1590 WebFrame* frame = GetMainFrame(); |
| 472 ASSERT_NE(nullptr, frame); | 1591 ASSERT_NE(nullptr, frame); |
| 473 | 1592 |
| 474 WebFormControlElement element = GetFormControlElementById("element"); | 1593 WebFormControlElement element = GetFormControlElementById("element"); |
| 475 FormFieldData result1; | 1594 FormFieldData result1; |
| 476 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); | 1595 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result1); |
| 477 | 1596 |
| 478 FormFieldData expected; | 1597 FormFieldData expected; |
| 479 expected.name = ASCIIToUTF16("element"); | 1598 expected.name = ASCIIToUTF16("element"); |
| 480 expected.max_length = 0; | 1599 expected.max_length = 0; |
| 481 expected.form_control_type = "select-one"; | 1600 expected.form_control_type = "select-one"; |
| 482 | 1601 |
| 483 expected.value = ASCIIToUTF16("CA"); | 1602 expected.value = ASCIIToUTF16("CA"); |
| 484 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 1603 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
| 485 | 1604 |
| 486 FormFieldData result2; | 1605 FormFieldData result2; |
| 487 WebFormControlElementToFormField( | 1606 WebFormControlElementToFormField( |
| 488 element, | 1607 element, |
| 489 static_cast<autofill::ExtractMask>(autofill::EXTRACT_VALUE | | 1608 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), |
| 490 autofill::EXTRACT_OPTION_TEXT), | |
| 491 &result2); | 1609 &result2); |
| 492 expected.value = ASCIIToUTF16("California"); | 1610 expected.value = ASCIIToUTF16("California"); |
| 493 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); | 1611 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
| 494 | 1612 |
| 495 FormFieldData result3; | 1613 FormFieldData result3; |
| 496 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, | 1614 WebFormControlElementToFormField(element, EXTRACT_OPTIONS, &result3); |
| 497 &result3); | 1615 expected.value.clear(); |
| 498 expected.value = base::string16(); | |
| 499 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3); | 1616 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3); |
| 500 | 1617 |
| 501 ASSERT_EQ(2U, result3.option_values.size()); | 1618 ASSERT_EQ(2U, result3.option_values.size()); |
| 502 ASSERT_EQ(2U, result3.option_contents.size()); | 1619 ASSERT_EQ(2U, result3.option_contents.size()); |
| 503 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); | 1620 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); |
| 504 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); | 1621 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); |
| 505 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); | 1622 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); |
| 506 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); | 1623 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); |
| 507 } | 1624 } |
| 508 | 1625 |
| 509 // When faced with <select> field with *many* options, we should trim them to a | 1626 // When faced with <select> field with *many* options, we should trim them to a |
| 510 // reasonable number. | 1627 // reasonable number. |
| 511 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) { | 1628 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) { |
| 512 std::string html = "<SELECT id='element'/>"; | 1629 std::string html = "<SELECT id='element'/>"; |
| 513 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { | 1630 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { |
| 514 html += base::StringPrintf("<OPTION value='%" PRIuS "'>" | 1631 html += base::StringPrintf("<OPTION value='%" PRIuS "'>" |
| 515 "%" PRIuS "</OPTION>", i, i); | 1632 "%" PRIuS "</OPTION>", i, i); |
| 516 } | 1633 } |
| 517 html += "</SELECT>"; | 1634 html += "</SELECT>"; |
| 518 LoadHTML(html.c_str()); | 1635 LoadHTML(html.c_str()); |
| 519 | 1636 |
| 520 WebFrame* frame = GetMainFrame(); | 1637 WebFrame* frame = GetMainFrame(); |
| 521 ASSERT_TRUE(frame); | 1638 ASSERT_TRUE(frame); |
| 522 | 1639 |
| 523 WebFormControlElement element = GetFormControlElementById("element"); | 1640 WebFormControlElement element = GetFormControlElementById("element"); |
| 524 FormFieldData result; | 1641 FormFieldData result; |
| 525 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, &result); | 1642 WebFormControlElementToFormField(element, EXTRACT_OPTIONS, &result); |
| 526 | 1643 |
| 527 EXPECT_TRUE(result.option_values.empty()); | 1644 EXPECT_TRUE(result.option_values.empty()); |
| 528 EXPECT_TRUE(result.option_contents.empty()); | 1645 EXPECT_TRUE(result.option_contents.empty()); |
| 529 } | 1646 } |
| 530 | 1647 |
| 531 // We should be able to extract a <textarea> field. | 1648 // We should be able to extract a <textarea> field. |
| 532 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { | 1649 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { |
| 533 LoadHTML("<TEXTAREA id='element'>" | 1650 LoadHTML("<TEXTAREA id='element'>" |
| 534 "This element's value " | 1651 "This element's value " |
| 535 "spans multiple lines." | 1652 "spans multiple lines." |
| 536 "</TEXTAREA>"); | 1653 "</TEXTAREA>"); |
| 537 | 1654 |
| 538 WebFrame* frame = GetMainFrame(); | 1655 WebFrame* frame = GetMainFrame(); |
| 539 ASSERT_NE(nullptr, frame); | 1656 ASSERT_NE(nullptr, frame); |
| 540 | 1657 |
| 541 WebFormControlElement element = GetFormControlElementById("element"); | 1658 WebFormControlElement element = GetFormControlElementById("element"); |
| 542 FormFieldData result_sans_value; | 1659 FormFieldData result_sans_value; |
| 543 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, | 1660 WebFormControlElementToFormField(element, EXTRACT_NONE, &result_sans_value); |
| 544 &result_sans_value); | |
| 545 | 1661 |
| 546 FormFieldData expected; | 1662 FormFieldData expected; |
| 547 expected.name = ASCIIToUTF16("element"); | 1663 expected.name = ASCIIToUTF16("element"); |
| 548 expected.max_length = 0; | 1664 expected.max_length = 0; |
| 549 expected.form_control_type = "textarea"; | 1665 expected.form_control_type = "textarea"; |
| 550 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 1666 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
| 551 | 1667 |
| 552 FormFieldData result_with_value; | 1668 FormFieldData result_with_value; |
| 553 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, | 1669 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result_with_value); |
| 554 &result_with_value); | |
| 555 expected.value = ASCIIToUTF16("This element's value\n" | 1670 expected.value = ASCIIToUTF16("This element's value\n" |
| 556 "spans multiple lines."); | 1671 "spans multiple lines."); |
| 557 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 1672 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
| 558 } | 1673 } |
| 559 | 1674 |
| 560 // We should be able to extract an <input type="month"> field. | 1675 // We should be able to extract an <input type="month"> field. |
| 561 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { | 1676 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { |
| 562 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); | 1677 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); |
| 563 | 1678 |
| 564 WebFrame* frame = GetMainFrame(); | 1679 WebFrame* frame = GetMainFrame(); |
| 565 ASSERT_NE(nullptr, frame); | 1680 ASSERT_NE(nullptr, frame); |
| 566 | 1681 |
| 567 WebFormControlElement element = GetFormControlElementById("element"); | 1682 WebFormControlElement element = GetFormControlElementById("element"); |
| 568 FormFieldData result_sans_value; | 1683 FormFieldData result_sans_value; |
| 569 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, | 1684 WebFormControlElementToFormField(element, EXTRACT_NONE, &result_sans_value); |
| 570 &result_sans_value); | |
| 571 | 1685 |
| 572 FormFieldData expected; | 1686 FormFieldData expected; |
| 573 expected.name = ASCIIToUTF16("element"); | 1687 expected.name = ASCIIToUTF16("element"); |
| 574 expected.max_length = 0; | 1688 expected.max_length = 0; |
| 575 expected.form_control_type = "month"; | 1689 expected.form_control_type = "month"; |
| 576 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 1690 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
| 577 | 1691 |
| 578 FormFieldData result_with_value; | 1692 FormFieldData result_with_value; |
| 579 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, | 1693 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result_with_value); |
| 580 &result_with_value); | |
| 581 expected.value = ASCIIToUTF16("2011-12"); | 1694 expected.value = ASCIIToUTF16("2011-12"); |
| 582 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 1695 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
| 583 } | 1696 } |
| 584 | 1697 |
| 585 // We should not extract the value for non-text and non-select fields. | 1698 // We should not extract the value for non-text and non-select fields. |
| 586 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { | 1699 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { |
| 587 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 1700 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 588 " <INPUT type='hidden' id='hidden' value='apple'/>" | 1701 " <INPUT type='hidden' id='hidden' value='apple'/>" |
| 589 " <INPUT type='submit' id='submit' value='Send'/>" | 1702 " <INPUT type='submit' id='submit' value='Send'/>" |
| 590 "</FORM>"); | 1703 "</FORM>"); |
| 591 | 1704 |
| 592 WebFrame* frame = GetMainFrame(); | 1705 WebFrame* frame = GetMainFrame(); |
| 593 ASSERT_NE(nullptr, frame); | 1706 ASSERT_NE(nullptr, frame); |
| 594 | 1707 |
| 595 WebFormControlElement element = GetFormControlElementById("hidden"); | 1708 WebFormControlElement element = GetFormControlElementById("hidden"); |
| 596 FormFieldData result; | 1709 FormFieldData result; |
| 597 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1710 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 598 | 1711 |
| 599 FormFieldData expected; | 1712 FormFieldData expected; |
| 600 expected.max_length = 0; | 1713 expected.max_length = 0; |
| 601 | 1714 |
| 602 expected.name = ASCIIToUTF16("hidden"); | 1715 expected.name = ASCIIToUTF16("hidden"); |
| 603 expected.form_control_type = "hidden"; | 1716 expected.form_control_type = "hidden"; |
| 604 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1717 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 605 | 1718 |
| 606 element = GetFormControlElementById("submit"); | 1719 element = GetFormControlElementById("submit"); |
| 607 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1720 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 608 expected.name = ASCIIToUTF16("submit"); | 1721 expected.name = ASCIIToUTF16("submit"); |
| 609 expected.form_control_type = "submit"; | 1722 expected.form_control_type = "submit"; |
| 610 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1723 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 611 } | 1724 } |
| 612 | 1725 |
| 613 // We should be able to extract password fields. | 1726 // We should be able to extract password fields. |
| 614 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { | 1727 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { |
| 615 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 1728 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 616 " <INPUT type='password' id='password' value='secret'/>" | 1729 " <INPUT type='password' id='password' value='secret'/>" |
| 617 "</FORM>"); | 1730 "</FORM>"); |
| 618 | 1731 |
| 619 WebFrame* frame = GetMainFrame(); | 1732 WebFrame* frame = GetMainFrame(); |
| 620 ASSERT_NE(nullptr, frame); | 1733 ASSERT_NE(nullptr, frame); |
| 621 | 1734 |
| 622 WebFormControlElement element = GetFormControlElementById("password"); | 1735 WebFormControlElement element = GetFormControlElementById("password"); |
| 623 FormFieldData result; | 1736 FormFieldData result; |
| 624 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1737 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 625 | 1738 |
| 626 FormFieldData expected; | 1739 FormFieldData expected; |
| 627 expected.max_length = WebInputElement::defaultMaxLength(); | 1740 expected.max_length = WebInputElement::defaultMaxLength(); |
| 628 expected.name = ASCIIToUTF16("password"); | 1741 expected.name = ASCIIToUTF16("password"); |
| 629 expected.form_control_type = "password"; | 1742 expected.form_control_type = "password"; |
| 630 expected.value = ASCIIToUTF16("secret"); | 1743 expected.value = ASCIIToUTF16("secret"); |
| 631 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1744 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 632 } | 1745 } |
| 633 | 1746 |
| 634 // We should be able to extract the autocompletetype attribute. | 1747 // We should be able to extract the autocompletetype attribute. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 // Very long attribute values should be replaced by a default string, to | 1802 // Very long attribute values should be replaced by a default string, to |
| 690 // prevent malicious websites from DOSing the browser process. | 1803 // prevent malicious websites from DOSing the browser process. |
| 691 { "malicious", "text", "x-max-data-length-exceeded" }, | 1804 { "malicious", "text", "x-max-data-length-exceeded" }, |
| 692 }; | 1805 }; |
| 693 | 1806 |
| 694 WebDocument document = frame->document(); | 1807 WebDocument document = frame->document(); |
| 695 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 1808 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 696 WebFormControlElement element = | 1809 WebFormControlElement element = |
| 697 GetFormControlElementById(ASCIIToUTF16(test_cases[i].element_id)); | 1810 GetFormControlElementById(ASCIIToUTF16(test_cases[i].element_id)); |
| 698 FormFieldData result; | 1811 FormFieldData result; |
| 699 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result); | 1812 WebFormControlElementToFormField(element, EXTRACT_NONE, &result); |
| 700 | 1813 |
| 701 FormFieldData expected; | 1814 FormFieldData expected; |
| 702 expected.name = ASCIIToUTF16(test_cases[i].element_id); | 1815 expected.name = ASCIIToUTF16(test_cases[i].element_id); |
| 703 expected.form_control_type = test_cases[i].form_control_type; | 1816 expected.form_control_type = test_cases[i].form_control_type; |
| 704 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute; | 1817 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute; |
| 705 if (test_cases[i].form_control_type == "text") | 1818 if (test_cases[i].form_control_type == "text") |
| 706 expected.max_length = WebInputElement::defaultMaxLength(); | 1819 expected.max_length = WebInputElement::defaultMaxLength(); |
| 707 else | 1820 else |
| 708 expected.max_length = 0; | 1821 expected.max_length = 0; |
| 709 | 1822 |
| 710 SCOPED_TRACE(test_cases[i].element_id); | 1823 SCOPED_TRACE(test_cases[i].element_id); |
| 711 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1824 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 712 } | 1825 } |
| 713 } | 1826 } |
| 714 | 1827 |
| 715 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { | 1828 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { |
| 716 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" | 1829 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" |
| 717 "<FORM>" | 1830 "<FORM>" |
| 718 " <INPUT type='text' id='element'>" | 1831 " <INPUT type='text' id='element'>" |
| 719 "</FORM>"); | 1832 "</FORM>"); |
| 720 | 1833 |
| 721 WebFrame* frame = GetMainFrame(); | 1834 WebFrame* frame = GetMainFrame(); |
| 722 ASSERT_NE(nullptr, frame); | 1835 ASSERT_NE(nullptr, frame); |
| 723 | 1836 |
| 724 WebFormControlElement element = GetFormControlElementById("element"); | 1837 WebFormControlElement element = GetFormControlElementById("element"); |
| 725 | 1838 |
| 726 FormFieldData result; | 1839 FormFieldData result; |
| 727 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1840 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 728 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 1841 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 729 } | 1842 } |
| 730 | 1843 |
| 731 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { | 1844 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { |
| 732 LoadHTML("<FORM>" | 1845 LoadHTML("<FORM>" |
| 733 " <INPUT dir='rtl' type='text' id='element'/>" | 1846 " <INPUT dir='rtl' type='text' id='element'/>" |
| 734 "</FORM>"); | 1847 "</FORM>"); |
| 735 | 1848 |
| 736 WebFrame* frame = GetMainFrame(); | 1849 WebFrame* frame = GetMainFrame(); |
| 737 ASSERT_NE(nullptr, frame); | 1850 ASSERT_NE(nullptr, frame); |
| 738 | 1851 |
| 739 WebFormControlElement element = GetFormControlElementById("element"); | 1852 WebFormControlElement element = GetFormControlElementById("element"); |
| 740 | 1853 |
| 741 FormFieldData result; | 1854 FormFieldData result; |
| 742 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1855 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 743 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 1856 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 744 } | 1857 } |
| 745 | 1858 |
| 746 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { | 1859 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { |
| 747 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" | 1860 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" |
| 748 "<FORM>" | 1861 "<FORM>" |
| 749 " <INPUT type='text' id='element'/>" | 1862 " <INPUT type='text' id='element'/>" |
| 750 "</FORM>"); | 1863 "</FORM>"); |
| 751 | 1864 |
| 752 WebFrame* frame = GetMainFrame(); | 1865 WebFrame* frame = GetMainFrame(); |
| 753 ASSERT_NE(nullptr, frame); | 1866 ASSERT_NE(nullptr, frame); |
| 754 | 1867 |
| 755 WebFormControlElement element = GetFormControlElementById("element"); | 1868 WebFormControlElement element = GetFormControlElementById("element"); |
| 756 | 1869 |
| 757 FormFieldData result; | 1870 FormFieldData result; |
| 758 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1871 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 759 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 1872 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 760 } | 1873 } |
| 761 | 1874 |
| 762 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { | 1875 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { |
| 763 LoadHTML("<FORM dir='rtl'>" | 1876 LoadHTML("<FORM dir='rtl'>" |
| 764 " <INPUT type='text' id='element'/>" | 1877 " <INPUT type='text' id='element'/>" |
| 765 "</FORM>"); | 1878 "</FORM>"); |
| 766 | 1879 |
| 767 WebFrame* frame = GetMainFrame(); | 1880 WebFrame* frame = GetMainFrame(); |
| 768 ASSERT_NE(nullptr, frame); | 1881 ASSERT_NE(nullptr, frame); |
| 769 | 1882 |
| 770 WebFormControlElement element = GetFormControlElementById("element"); | 1883 WebFormControlElement element = GetFormControlElementById("element"); |
| 771 | 1884 |
| 772 FormFieldData result; | 1885 FormFieldData result; |
| 773 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1886 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 774 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 1887 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 775 } | 1888 } |
| 776 | 1889 |
| 777 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { | 1890 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { |
| 778 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" | 1891 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" |
| 779 "<FORM dir='rtl'>" | 1892 "<FORM dir='rtl'>" |
| 780 " <INPUT type='text' id='element'/>" | 1893 " <INPUT type='text' id='element'/>" |
| 781 "</FORM>"); | 1894 "</FORM>"); |
| 782 | 1895 |
| 783 WebFrame* frame = GetMainFrame(); | 1896 WebFrame* frame = GetMainFrame(); |
| 784 ASSERT_NE(nullptr, frame); | 1897 ASSERT_NE(nullptr, frame); |
| 785 | 1898 |
| 786 WebFormControlElement element = GetFormControlElementById("element"); | 1899 WebFormControlElement element = GetFormControlElementById("element"); |
| 787 | 1900 |
| 788 FormFieldData result; | 1901 FormFieldData result; |
| 789 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1902 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 790 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | 1903 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
| 791 } | 1904 } |
| 792 | 1905 |
| 793 TEST_F(FormAutofillTest, | 1906 TEST_F(FormAutofillTest, |
| 794 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { | 1907 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { |
| 795 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" | 1908 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" |
| 796 "<FORM dir='rtl'>" | 1909 "<FORM dir='rtl'>" |
| 797 " <INPUT type='text' id='element'/>" | 1910 " <INPUT type='text' id='element'/>" |
| 798 "</FORM>"); | 1911 "</FORM>"); |
| 799 | 1912 |
| 800 WebFrame* frame = GetMainFrame(); | 1913 WebFrame* frame = GetMainFrame(); |
| 801 ASSERT_NE(nullptr, frame); | 1914 ASSERT_NE(nullptr, frame); |
| 802 | 1915 |
| 803 WebFormControlElement element = GetFormControlElementById("element"); | 1916 WebFormControlElement element = GetFormControlElementById("element"); |
| 804 | 1917 |
| 805 FormFieldData result; | 1918 FormFieldData result; |
| 806 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1919 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 807 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | 1920 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
| 808 } | 1921 } |
| 809 | 1922 |
| 810 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { | 1923 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { |
| 811 LoadHTML("<FORM style='direction:ltr'>" | 1924 LoadHTML("<FORM style='direction:ltr'>" |
| 812 " <SPAN dir='rtl'>" | 1925 " <SPAN dir='rtl'>" |
| 813 " <INPUT type='text' id='element'/>" | 1926 " <INPUT type='text' id='element'/>" |
| 814 " </SPAN>" | 1927 " </SPAN>" |
| 815 "</FORM>"); | 1928 "</FORM>"); |
| 816 | 1929 |
| 817 WebFrame* frame = GetMainFrame(); | 1930 WebFrame* frame = GetMainFrame(); |
| 818 ASSERT_NE(nullptr, frame); | 1931 ASSERT_NE(nullptr, frame); |
| 819 | 1932 |
| 820 WebFormControlElement element = GetFormControlElementById("element"); | 1933 WebFormControlElement element = GetFormControlElementById("element"); |
| 821 | 1934 |
| 822 FormFieldData result; | 1935 FormFieldData result; |
| 823 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 1936 WebFormControlElementToFormField(element, EXTRACT_VALUE, &result); |
| 824 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 1937 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 825 } | 1938 } |
| 826 | 1939 |
| 827 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 1940 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
| 828 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 1941 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 829 " <LABEL for='firstname'>First name:</LABEL>" | 1942 " <LABEL for='firstname'>First name:</LABEL>" |
| 830 " <INPUT type='text' id='firstname' value='John'/>" | 1943 " <INPUT type='text' id='firstname' value='John'/>" |
| 831 " <LABEL for='lastname'>Last name:</LABEL>" | 1944 " <LABEL for='lastname'>Last name:</LABEL>" |
| 832 " <INPUT type='text' id='lastname' value='Smith'/>" | 1945 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 833 " <LABEL for='street-address'>Address:</LABEL>" | 1946 " <LABEL for='street-address'>Address:</LABEL>" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 856 WebVector<WebFormElement> forms; | 1969 WebVector<WebFormElement> forms; |
| 857 frame->document().forms(forms); | 1970 frame->document().forms(forms); |
| 858 ASSERT_EQ(1U, forms.size()); | 1971 ASSERT_EQ(1U, forms.size()); |
| 859 | 1972 |
| 860 WebInputElement input_element = GetInputElementById("firstname"); | 1973 WebInputElement input_element = GetInputElementById("firstname"); |
| 861 | 1974 |
| 862 FormData form; | 1975 FormData form; |
| 863 FormFieldData field; | 1976 FormFieldData field; |
| 864 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 1977 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 865 input_element, | 1978 input_element, |
| 866 autofill::REQUIRE_NONE, | 1979 REQUIRE_NONE, |
| 867 autofill::EXTRACT_VALUE, | 1980 EXTRACT_VALUE, |
| 868 &form, | 1981 &form, |
| 869 &field)); | 1982 &field)); |
| 870 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1983 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 871 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 1984 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 872 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 1985 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 873 | 1986 |
| 874 const std::vector<FormFieldData>& fields = form.fields; | 1987 const std::vector<FormFieldData>& fields = form.fields; |
| 875 ASSERT_EQ(6U, fields.size()); | 1988 ASSERT_EQ(6U, fields.size()); |
| 876 | 1989 |
| 877 FormFieldData expected; | 1990 FormFieldData expected; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 expected.label = ASCIIToUTF16("Card expiration:"); | 2028 expected.label = ASCIIToUTF16("Card expiration:"); |
| 916 expected.form_control_type = "month"; | 2029 expected.form_control_type = "month"; |
| 917 expected.max_length = 0; | 2030 expected.max_length = 0; |
| 918 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); | 2031 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
| 919 } | 2032 } |
| 920 | 2033 |
| 921 // We should not be able to serialize a form with too many fillable fields. | 2034 // We should not be able to serialize a form with too many fillable fields. |
| 922 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { | 2035 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { |
| 923 std::string html = | 2036 std::string html = |
| 924 "<FORM name='TestForm' action='http://cnn.com' method='post'>"; | 2037 "<FORM name='TestForm' action='http://cnn.com' method='post'>"; |
| 925 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { | 2038 for (size_t i = 0; i < (kMaxParseableFields + 1); ++i) { |
| 926 html += "<INPUT type='text'/>"; | 2039 html += "<INPUT type='text'/>"; |
| 927 } | 2040 } |
| 928 html += "</FORM>"; | 2041 html += "</FORM>"; |
| 929 LoadHTML(html.c_str()); | 2042 LoadHTML(html.c_str()); |
| 930 | 2043 |
| 931 WebFrame* frame = GetMainFrame(); | 2044 WebFrame* frame = GetMainFrame(); |
| 932 ASSERT_NE(nullptr, frame); | 2045 ASSERT_NE(nullptr, frame); |
| 933 | 2046 |
| 934 WebVector<WebFormElement> forms; | 2047 WebVector<WebFormElement> forms; |
| 935 frame->document().forms(forms); | 2048 frame->document().forms(forms); |
| 936 ASSERT_EQ(1U, forms.size()); | 2049 ASSERT_EQ(1U, forms.size()); |
| 937 | 2050 |
| 938 WebInputElement input_element = GetInputElementById("firstname"); | 2051 WebInputElement input_element = GetInputElementById("firstname"); |
| 939 | 2052 |
| 940 FormData form; | 2053 FormData form; |
| 941 FormFieldData field; | 2054 FormFieldData field; |
| 942 EXPECT_FALSE(WebFormElementToFormData(forms[0], | 2055 EXPECT_FALSE(WebFormElementToFormData(forms[0], |
| 943 input_element, | 2056 input_element, |
| 944 autofill::REQUIRE_NONE, | 2057 REQUIRE_NONE, |
| 945 autofill::EXTRACT_VALUE, | 2058 EXTRACT_VALUE, |
| 946 &form, | 2059 &form, |
| 947 &field)); | 2060 &field)); |
| 948 } | 2061 } |
| 949 | 2062 |
| 950 TEST_F(FormAutofillTest, ExtractForms) { | 2063 TEST_F(FormAutofillTest, ExtractForms) { |
| 951 ExpectJohnSmithLabels( | 2064 ExpectJohnSmithLabels( |
| 952 "<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2065 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 953 " First name: <INPUT type='text' id='firstname' value='John'/>" | 2066 " First name: <INPUT type='text' id='firstname' value='John'/>" |
| 954 " Last name: <INPUT type='text' id='lastname' value='Smith'/>" | 2067 " Last name: <INPUT type='text' id='lastname' value='Smith'/>" |
| 955 " Email: <INPUT type='text' id='email' value='john@example.com'/>" | 2068 " Email: <INPUT type='text' id='email' value='john@example.com'/>" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 WebFrame* web_frame = GetMainFrame(); | 2316 WebFrame* web_frame = GetMainFrame(); |
| 1204 ASSERT_NE(nullptr, web_frame); | 2317 ASSERT_NE(nullptr, web_frame); |
| 1205 | 2318 |
| 1206 WebVector<WebFormElement> web_forms; | 2319 WebVector<WebFormElement> web_forms; |
| 1207 web_frame->document().forms(web_forms); | 2320 web_frame->document().forms(web_forms); |
| 1208 ASSERT_EQ(1U, web_forms.size()); | 2321 ASSERT_EQ(1U, web_forms.size()); |
| 1209 WebFormElement web_form = web_forms[0]; | 2322 WebFormElement web_form = web_forms[0]; |
| 1210 | 2323 |
| 1211 FormData form; | 2324 FormData form; |
| 1212 EXPECT_TRUE(WebFormElementToFormData( | 2325 EXPECT_TRUE(WebFormElementToFormData( |
| 1213 web_form, WebFormControlElement(), autofill::REQUIRE_NONE, | 2326 web_form, WebFormControlElement(), REQUIRE_NONE, EXTRACT_NONE, &form, |
| 1214 autofill::EXTRACT_NONE, &form, NULL)); | 2327 nullptr)); |
| 1215 EXPECT_FALSE(WebFormElementToFormData( | 2328 EXPECT_FALSE(WebFormElementToFormData( |
| 1216 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE, | 2329 web_form, WebFormControlElement(), REQUIRE_AUTOCOMPLETE, EXTRACT_NONE, |
| 1217 autofill::EXTRACT_NONE, &form, NULL)); | 2330 &form, nullptr)); |
| 1218 } | 2331 } |
| 1219 | 2332 |
| 1220 { | 2333 { |
| 1221 // The firstname element is not auto-completable due to autocomplete=off. | 2334 // The firstname element is not auto-completable due to autocomplete=off. |
| 1222 LoadHTML("<FORM name='TestForm' action='http://abc.com' " | 2335 LoadHTML("<FORM name='TestForm' action='http://abc.com' " |
| 1223 " method='post'>" | 2336 " method='post'>" |
| 1224 " <INPUT type='text' id='firstname' value='John'" | 2337 " <INPUT type='text' id='firstname' value='John'" |
| 1225 " autocomplete=off>" | 2338 " autocomplete=off>" |
| 1226 " <INPUT type='text' id='middlename' value='Jack'/>" | 2339 " <INPUT type='text' id='middlename' value='Jack'/>" |
| 1227 " <INPUT type='text' id='lastname' value='Smith'/>" | 2340 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 1228 " <INPUT type='text' id='email' value='john@example.com'/>" | 2341 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 1229 " <INPUT type='submit' name='reply' value='Send'/>" | 2342 " <INPUT type='submit' name='reply' value='Send'/>" |
| 1230 "</FORM>"); | 2343 "</FORM>"); |
| 1231 | 2344 |
| 1232 WebFrame* web_frame = GetMainFrame(); | 2345 WebFrame* web_frame = GetMainFrame(); |
| 1233 ASSERT_NE(nullptr, web_frame); | 2346 ASSERT_NE(nullptr, web_frame); |
| 1234 | 2347 |
| 1235 WebVector<WebFormElement> web_forms; | 2348 WebVector<WebFormElement> web_forms; |
| 1236 web_frame->document().forms(web_forms); | 2349 web_frame->document().forms(web_forms); |
| 1237 ASSERT_EQ(1U, web_forms.size()); | 2350 ASSERT_EQ(1U, web_forms.size()); |
| 1238 WebFormElement web_form = web_forms[0]; | 2351 WebFormElement web_form = web_forms[0]; |
| 1239 | 2352 |
| 1240 FormData form; | 2353 FormData form; |
| 1241 EXPECT_TRUE(WebFormElementToFormData( | 2354 EXPECT_TRUE(WebFormElementToFormData( |
| 1242 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE, | 2355 web_form, WebFormControlElement(), REQUIRE_AUTOCOMPLETE, EXTRACT_VALUE, |
| 1243 autofill::EXTRACT_VALUE, &form, NULL)); | 2356 &form, nullptr)); |
| 1244 | 2357 |
| 1245 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2358 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1246 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2359 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1247 EXPECT_EQ(GURL("http://abc.com"), form.action); | 2360 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 1248 | 2361 |
| 1249 const std::vector<FormFieldData>& fields = form.fields; | 2362 const std::vector<FormFieldData>& fields = form.fields; |
| 1250 ASSERT_EQ(3U, fields.size()); | 2363 ASSERT_EQ(3U, fields.size()); |
| 1251 | 2364 |
| 1252 FormFieldData expected; | 2365 FormFieldData expected; |
| 1253 expected.form_control_type = "text"; | 2366 expected.form_control_type = "text"; |
| 1254 expected.max_length = WebInputElement::defaultMaxLength(); | 2367 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1255 | 2368 |
| 1256 expected.name = ASCIIToUTF16("middlename"); | 2369 expected.name = ASCIIToUTF16("middlename"); |
| 1257 expected.value = ASCIIToUTF16("Jack"); | 2370 expected.value = ASCIIToUTF16("Jack"); |
| 1258 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2371 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 1259 | 2372 |
| 1260 expected.name = ASCIIToUTF16("lastname"); | 2373 expected.name = ASCIIToUTF16("lastname"); |
| 1261 expected.value = ASCIIToUTF16("Smith"); | 2374 expected.value = ASCIIToUTF16("Smith"); |
| 1262 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2375 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 1263 | 2376 |
| 1264 expected.name = ASCIIToUTF16("email"); | 2377 expected.name = ASCIIToUTF16("email"); |
| 1265 expected.value = ASCIIToUTF16("john@example.com"); | 2378 expected.value = ASCIIToUTF16("john@example.com"); |
| 1266 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2379 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1267 } | 2380 } |
| 1268 } | 2381 } |
| 1269 | 2382 |
| 1270 TEST_F(FormAutofillTest, FindFormForInputElement) { | 2383 TEST_F(FormAutofillTest, FindFormForInputElement) { |
| 1271 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 2384 TestFindFormForInputElement( |
| 1272 " <INPUT type='text' id='firstname' value='John'/>" | 2385 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 1273 " <INPUT type='text' id='lastname' value='Smith'/>" | 2386 " <INPUT type='text' id='firstname' value='John'/>" |
| 1274 " <INPUT type='text' id='email' value='john@example.com'" | 2387 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 1275 "autocomplete='off' />" | 2388 " <INPUT type='text' id='email' value='john@example.com'" |
| 1276 " <INPUT type='text' id='phone' value='1.800.555.1234'/>" | 2389 "autocomplete='off' />" |
| 1277 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2390 " <INPUT type='text' id='phone' value='1.800.555.1234'/>" |
| 1278 "</FORM>"); | 2391 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2392 "</FORM>", |
| 2393 false); |
| 2394 } |
| 1279 | 2395 |
| 1280 WebFrame* web_frame = GetMainFrame(); | 2396 TEST_F(FormAutofillTest, FindFormForInputElementForUnownedForm) { |
| 1281 ASSERT_NE(nullptr, web_frame); | 2397 TestFindFormForInputElement( |
| 1282 | 2398 "<INPUT type='text' id='firstname' value='John'/>" |
| 1283 FormCache form_cache; | 2399 "<INPUT type='text' id='lastname' value='Smith'/>" |
| 1284 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 2400 "<INPUT type='text' id='email' value='john@example.com'" |
| 1285 ASSERT_EQ(1U, forms.size()); | 2401 "autocomplete='off' />" |
| 1286 | 2402 "<INPUT type='text' id='phone' value='1.800.555.1234'/>" |
| 1287 // Get the input element we want to find. | 2403 "<INPUT type='submit' name='reply-send' value='Send'/>", |
| 1288 WebInputElement input_element = GetInputElementById("firstname"); | 2404 true); |
| 1289 | |
| 1290 // Find the form and verify it's the correct form. | |
| 1291 FormData form; | |
| 1292 FormFieldData field; | |
| 1293 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 1294 &form, | |
| 1295 &field, | |
| 1296 autofill::REQUIRE_NONE)); | |
| 1297 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | |
| 1298 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
| 1299 EXPECT_EQ(GURL("http://buh.com"), form.action); | |
| 1300 | |
| 1301 const std::vector<FormFieldData>& fields = form.fields; | |
| 1302 ASSERT_EQ(4U, fields.size()); | |
| 1303 | |
| 1304 FormFieldData expected; | |
| 1305 expected.form_control_type = "text"; | |
| 1306 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 1307 | |
| 1308 expected.name = ASCIIToUTF16("firstname"); | |
| 1309 expected.value = ASCIIToUTF16("John"); | |
| 1310 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 1311 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | |
| 1312 | |
| 1313 expected.name = ASCIIToUTF16("lastname"); | |
| 1314 expected.value = ASCIIToUTF16("Smith"); | |
| 1315 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 1316 | |
| 1317 expected.name = ASCIIToUTF16("email"); | |
| 1318 expected.value = ASCIIToUTF16("john@example.com"); | |
| 1319 expected.autocomplete_attribute = "off"; | |
| 1320 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 1321 expected.autocomplete_attribute = std::string(); // reset | |
| 1322 | |
| 1323 expected.name = ASCIIToUTF16("phone"); | |
| 1324 expected.value = ASCIIToUTF16("1.800.555.1234"); | |
| 1325 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | |
| 1326 | |
| 1327 // Try again, but require autocomplete. | |
| 1328 FormData form2; | |
| 1329 FormFieldData field2; | |
| 1330 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | |
| 1331 input_element, | |
| 1332 &form2, | |
| 1333 &field2, | |
| 1334 autofill::REQUIRE_AUTOCOMPLETE)); | |
| 1335 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 1336 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 1337 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 1338 | |
| 1339 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 1340 ASSERT_EQ(3U, fields2.size()); | |
| 1341 | |
| 1342 expected.form_control_type = "text"; | |
| 1343 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 1344 | |
| 1345 expected.name = ASCIIToUTF16("firstname"); | |
| 1346 expected.value = ASCIIToUTF16("John"); | |
| 1347 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
| 1348 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | |
| 1349 | |
| 1350 expected.name = ASCIIToUTF16("lastname"); | |
| 1351 expected.value = ASCIIToUTF16("Smith"); | |
| 1352 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
| 1353 | |
| 1354 expected.name = ASCIIToUTF16("phone"); | |
| 1355 expected.value = ASCIIToUTF16("1.800.555.1234"); | |
| 1356 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
| 1357 } | 2405 } |
| 1358 | 2406 |
| 1359 TEST_F(FormAutofillTest, FindFormForTextAreaElement) { | 2407 TEST_F(FormAutofillTest, FindFormForTextAreaElement) { |
| 1360 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 2408 TestFindFormForTextAreaElement( |
| 1361 " <INPUT type='text' id='firstname' value='John'/>" | 2409 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 1362 " <INPUT type='text' id='lastname' value='Smith'/>" | 2410 " <INPUT type='text' id='firstname' value='John'/>" |
| 1363 " <INPUT type='text' id='email' value='john@example.com'" | 2411 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 1364 "autocomplete='off' />" | 2412 " <INPUT type='text' id='email' value='john@example.com'" |
| 1365 " <TEXTAREA id='street-address'>" | 2413 "autocomplete='off' />" |
| 1366 "123 Fantasy Ln. " | 2414 " <TEXTAREA id='street-address'>" |
| 1367 "Apt. 42" | 2415 "123 Fantasy Ln. " |
| 1368 "</TEXTAREA>" | 2416 "Apt. 42" |
| 1369 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2417 "</TEXTAREA>" |
| 1370 "</FORM>"); | 2418 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2419 "</FORM>", |
| 2420 false); |
| 2421 } |
| 1371 | 2422 |
| 1372 WebFrame* web_frame = GetMainFrame(); | 2423 TEST_F(FormAutofillTest, FindFormForTextAreaElementForUnownedForm) { |
| 1373 ASSERT_NE(nullptr, web_frame); | 2424 TestFindFormForTextAreaElement( |
| 1374 | 2425 "<INPUT type='text' id='firstname' value='John'/>" |
| 1375 FormCache form_cache; | 2426 "<INPUT type='text' id='lastname' value='Smith'/>" |
| 1376 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 2427 "<INPUT type='text' id='email' value='john@example.com'" |
| 1377 ASSERT_EQ(1U, forms.size()); | 2428 "autocomplete='off' />" |
| 1378 | 2429 "<TEXTAREA id='street-address'>" |
| 1379 // Get the textarea element we want to find. | 2430 "123 Fantasy Ln. " |
| 1380 WebElement element = web_frame->document().getElementById("street-address"); | 2431 "Apt. 42" |
| 1381 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); | 2432 "</TEXTAREA>" |
| 1382 | 2433 "<INPUT type='submit' name='reply-send' value='Send'/>", |
| 1383 // Find the form and verify it's the correct form. | 2434 true); |
| 1384 FormData form; | |
| 1385 FormFieldData field; | |
| 1386 EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element, | |
| 1387 &form, | |
| 1388 &field, | |
| 1389 autofill::REQUIRE_NONE)); | |
| 1390 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | |
| 1391 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
| 1392 EXPECT_EQ(GURL("http://buh.com"), form.action); | |
| 1393 | |
| 1394 const std::vector<FormFieldData>& fields = form.fields; | |
| 1395 ASSERT_EQ(4U, fields.size()); | |
| 1396 | |
| 1397 FormFieldData expected; | |
| 1398 | |
| 1399 expected.name = ASCIIToUTF16("firstname"); | |
| 1400 expected.value = ASCIIToUTF16("John"); | |
| 1401 expected.form_control_type = "text"; | |
| 1402 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 1403 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 1404 | |
| 1405 expected.name = ASCIIToUTF16("lastname"); | |
| 1406 expected.value = ASCIIToUTF16("Smith"); | |
| 1407 expected.form_control_type = "text"; | |
| 1408 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 1409 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 1410 | |
| 1411 expected.name = ASCIIToUTF16("email"); | |
| 1412 expected.value = ASCIIToUTF16("john@example.com"); | |
| 1413 expected.autocomplete_attribute = "off"; | |
| 1414 expected.form_control_type = "text"; | |
| 1415 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 1416 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 1417 expected.autocomplete_attribute = std::string(); // reset | |
| 1418 | |
| 1419 expected.name = ASCIIToUTF16("street-address"); | |
| 1420 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); | |
| 1421 expected.form_control_type = "textarea"; | |
| 1422 expected.max_length = 0; | |
| 1423 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | |
| 1424 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | |
| 1425 | |
| 1426 // Try again, but require autocomplete. | |
| 1427 FormData form2; | |
| 1428 FormFieldData field2; | |
| 1429 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | |
| 1430 textarea_element, | |
| 1431 &form2, | |
| 1432 &field2, | |
| 1433 autofill::REQUIRE_AUTOCOMPLETE)); | |
| 1434 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 1435 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 1436 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 1437 | |
| 1438 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 1439 ASSERT_EQ(3U, fields2.size()); | |
| 1440 | |
| 1441 expected.name = ASCIIToUTF16("firstname"); | |
| 1442 expected.value = ASCIIToUTF16("John"); | |
| 1443 expected.form_control_type = "text"; | |
| 1444 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 1445 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
| 1446 | |
| 1447 expected.name = ASCIIToUTF16("lastname"); | |
| 1448 expected.value = ASCIIToUTF16("Smith"); | |
| 1449 expected.form_control_type = "text"; | |
| 1450 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 1451 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
| 1452 | |
| 1453 expected.name = ASCIIToUTF16("street-address"); | |
| 1454 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); | |
| 1455 expected.form_control_type = "textarea"; | |
| 1456 expected.max_length = 0; | |
| 1457 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
| 1458 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | |
| 1459 } | 2435 } |
| 1460 | 2436 |
| 1461 // Test regular FillForm function. | 2437 // Test regular FillForm function. |
| 1462 TEST_F(FormAutofillTest, FillForm) { | 2438 TEST_F(FormAutofillTest, FillForm) { |
| 1463 static const AutofillFieldCase field_cases[] = { | 2439 TestFillForm(kFormHtml, false); |
| 1464 // fields: form_control_type, name, initial_value, autocomplete_attribute, | 2440 } |
| 1465 // should_be_autofilled, autofill_value, expected_value | |
| 1466 | 2441 |
| 1467 // Regular empty fields (firstname & lastname) should be autofilled. | 2442 TEST_F(FormAutofillTest, FillFormForUnownedForm) { |
| 1468 {"text", | 2443 TestFillForm(kUnownedFormHtml, true); |
| 1469 "firstname", | |
| 1470 "", | |
| 1471 "", | |
| 1472 true, | |
| 1473 "filled firstname", | |
| 1474 "filled firstname"}, | |
| 1475 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, | |
| 1476 // hidden fields should not be extracted to form_data. | |
| 1477 // Non empty fields should not be autofilled. | |
| 1478 {"text", "notempty", "Hi", "", false, "filled notempty", "Hi"}, | |
| 1479 {"text", | |
| 1480 "noautocomplete", | |
| 1481 "", | |
| 1482 "off", | |
| 1483 true, | |
| 1484 "filled noautocomplete", | |
| 1485 "filled noautocomplete"}, | |
| 1486 // Disabled fields should not be autofilled. | |
| 1487 {"text", "notenabled", "", "", false, "filled notenabled", ""}, | |
| 1488 // Readonly fields should not be autofilled. | |
| 1489 {"text", "readonly", "", "", false, "filled readonly", ""}, | |
| 1490 // Fields with "visibility: hidden" should not be autofilled. | |
| 1491 {"text", "invisible", "", "", false, "filled invisible", ""}, | |
| 1492 // Fields with "display:none" should not be autofilled. | |
| 1493 {"text", "displaynone", "", "", false, "filled displaynone", ""}, | |
| 1494 // Regular <input type="month"> should be autofilled. | |
| 1495 {"month", "month", "", "", true, "2017-11", "2017-11"}, | |
| 1496 // Non-empty <input type="month"> should not be autofilled. | |
| 1497 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"}, | |
| 1498 // Regular select fields should be autofilled. | |
| 1499 {"select-one", "select", "", "", true, "TX", "TX"}, | |
| 1500 // Select fields should be autofilled even if they already have a | |
| 1501 // non-empty value. | |
| 1502 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, | |
| 1503 // Select fields should not be autofilled if no new value is passed from | |
| 1504 // autofill profile. The existing value should not be overriden. | |
| 1505 {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"}, | |
| 1506 // Regular textarea elements should be autofilled. | |
| 1507 {"textarea", | |
| 1508 "textarea", | |
| 1509 "", | |
| 1510 "", | |
| 1511 true, | |
| 1512 "some multi-\nline value", | |
| 1513 "some multi-\nline value"}, | |
| 1514 // Non-empty textarea elements should not be autofilled. | |
| 1515 {"textarea", | |
| 1516 "textarea-nonempty", | |
| 1517 "Go\naway!", | |
| 1518 "", | |
| 1519 false, | |
| 1520 "some multi-\nline value", | |
| 1521 "Go\naway!"}, | |
| 1522 }; | |
| 1523 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | |
| 1524 FillForm, &GetValueWrapper); | |
| 1525 // Verify preview selection. | |
| 1526 WebInputElement firstname = GetInputElementById("firstname"); | |
| 1527 EXPECT_EQ(16, firstname.selectionStart()); | |
| 1528 EXPECT_EQ(16, firstname.selectionEnd()); | |
| 1529 } | 2444 } |
| 1530 | 2445 |
| 1531 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { | 2446 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { |
| 1532 static const AutofillFieldCase field_cases[] = { | 2447 static const AutofillFieldCase field_cases[] = { |
| 1533 // fields: form_control_type, name, initial_value, autocomplete_attribute, | 2448 // fields: form_control_type, name, initial_value, autocomplete_attribute, |
| 1534 // should_be_autofilled, autofill_value, expected_value | 2449 // should_be_autofilled, autofill_value, expected_value |
| 1535 | 2450 |
| 1536 // Regular empty fields (firstname & lastname) should be autofilled. | 2451 // Regular empty fields (firstname & lastname) should be autofilled. |
| 1537 {"text", | 2452 {"text", |
| 1538 "firstname", | 2453 "firstname", |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 "some multi-\nline value"}, | 2515 "some multi-\nline value"}, |
| 1601 // Nonempty textarea elements should be overridden. | 2516 // Nonempty textarea elements should be overridden. |
| 1602 {"textarea", | 2517 {"textarea", |
| 1603 "textarea-nonempty", | 2518 "textarea-nonempty", |
| 1604 "Go\naway!", | 2519 "Go\naway!", |
| 1605 "", | 2520 "", |
| 1606 true, | 2521 true, |
| 1607 "some multi-\nline value", | 2522 "some multi-\nline value", |
| 1608 "some multi-\nline value"}, | 2523 "some multi-\nline value"}, |
| 1609 }; | 2524 }; |
| 1610 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | 2525 TestFormFillFunctions(kFormHtml, false, field_cases, arraysize(field_cases), |
| 1611 &FillFormIncludingNonFocusableElementsWrapper, | 2526 &FillFormIncludingNonFocusableElementsWrapper, |
| 1612 &GetValueWrapper); | 2527 &GetValueWrapper); |
| 1613 } | 2528 } |
| 1614 | 2529 |
| 1615 TEST_F(FormAutofillTest, PreviewForm) { | 2530 TEST_F(FormAutofillTest, PreviewForm) { |
| 1616 static const AutofillFieldCase field_cases[] = { | 2531 TestPreviewForm(kFormHtml, false); |
| 1617 // Normal empty fields should be previewed. | 2532 } |
| 1618 {"text", | |
| 1619 "firstname", | |
| 1620 "", | |
| 1621 "", | |
| 1622 true, | |
| 1623 "suggested firstname", | |
| 1624 "suggested firstname"}, | |
| 1625 {"text", | |
| 1626 "lastname", | |
| 1627 "", | |
| 1628 "", | |
| 1629 true, | |
| 1630 "suggested lastname", | |
| 1631 "suggested lastname"}, | |
| 1632 // Hidden fields should not be extracted to form_data. | |
| 1633 // Non empty fields should not be previewed. | |
| 1634 {"text", "notempty", "Hi", "", false, "suggested notempty", ""}, | |
| 1635 {"text", | |
| 1636 "noautocomplete", | |
| 1637 "", | |
| 1638 "off", | |
| 1639 true, | |
| 1640 "filled noautocomplete", | |
| 1641 "filled noautocomplete"}, | |
| 1642 // Disabled fields should not be previewed. | |
| 1643 {"text", "notenabled", "", "", false, "suggested notenabled", ""}, | |
| 1644 // Readonly fields should not be previewed. | |
| 1645 {"text", "readonly", "", "", false, "suggested readonly", ""}, | |
| 1646 // Fields with "visibility: hidden" should not be previewed. | |
| 1647 {"text", "invisible", "", "", false, "suggested invisible", ""}, | |
| 1648 // Fields with "display:none" should not previewed. | |
| 1649 {"text", "displaynone", "", "", false, "suggested displaynone", ""}, | |
| 1650 // Regular <input type="month"> should be previewed. | |
| 1651 {"month", "month", "", "", true, "2017-11", "2017-11"}, | |
| 1652 // Non-empty <input type="month"> should not be previewed. | |
| 1653 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, | |
| 1654 // Regular select fields should be previewed. | |
| 1655 {"select-one", "select", "", "", true, "TX", "TX"}, | |
| 1656 // Select fields should be previewed even if they already have a | |
| 1657 // non-empty value. | |
| 1658 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, | |
| 1659 // Select fields should not be previewed if no suggestion is passed from | |
| 1660 // autofill profile. | |
| 1661 {"select-one", "select-unchanged", "CA", "", false, "", ""}, | |
| 1662 // Normal textarea elements should be previewed. | |
| 1663 {"textarea", | |
| 1664 "textarea", | |
| 1665 "", | |
| 1666 "", | |
| 1667 true, | |
| 1668 "suggested multi-\nline value", | |
| 1669 "suggested multi-\nline value"}, | |
| 1670 // Nonempty textarea elements should not be previewed. | |
| 1671 {"textarea", | |
| 1672 "textarea-nonempty", | |
| 1673 "Go\naway!", | |
| 1674 "", | |
| 1675 false, | |
| 1676 "suggested multi-\nline value", | |
| 1677 ""}, | |
| 1678 }; | |
| 1679 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | |
| 1680 &PreviewForm, &GetSuggestedValueWrapper); | |
| 1681 | 2533 |
| 1682 // Verify preview selection. | 2534 TEST_F(FormAutofillTest, PreviewFormForUnownedForm) { |
| 1683 WebInputElement firstname = GetInputElementById("firstname"); | 2535 TestPreviewForm(kUnownedFormHtml, true); |
| 1684 EXPECT_EQ(0, firstname.selectionStart()); | |
| 1685 EXPECT_EQ(19, firstname.selectionEnd()); | |
| 1686 } | 2536 } |
| 1687 | 2537 |
| 1688 TEST_F(FormAutofillTest, Labels) { | 2538 TEST_F(FormAutofillTest, Labels) { |
| 1689 ExpectJohnSmithLabels( | 2539 ExpectJohnSmithLabels( |
| 1690 "<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2540 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 1691 " <LABEL for='firstname'> First name: </LABEL>" | 2541 " <LABEL for='firstname'> First name: </LABEL>" |
| 1692 " <INPUT type='text' id='firstname' value='John'/>" | 2542 " <INPUT type='text' id='firstname' value='John'/>" |
| 1693 " <LABEL for='lastname'> Last name: </LABEL>" | 2543 " <LABEL for='lastname'> Last name: </LABEL>" |
| 1694 " <INPUT type='text' id='lastname' value='Smith'/>" | 2544 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 1695 " <LABEL for='email'> Email: </LABEL>" | 2545 " <LABEL for='email'> Email: </LABEL>" |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2539 " <DT></DT>" | 3389 " <DT></DT>" |
| 2540 " <DD>" | 3390 " <DD>" |
| 2541 " <INPUT type='submit' name='reply-send' value='Send'/>" | 3391 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2542 " </DD>" | 3392 " </DD>" |
| 2543 "</DL>" | 3393 "</DL>" |
| 2544 "</DIV>" | 3394 "</DIV>" |
| 2545 "</FORM>"); | 3395 "</FORM>"); |
| 2546 } | 3396 } |
| 2547 | 3397 |
| 2548 TEST_F(FormAutofillTest, FillFormMaxLength) { | 3398 TEST_F(FormAutofillTest, FillFormMaxLength) { |
| 2549 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 3399 TestFillFormMaxLength( |
| 2550 " <INPUT type='text' id='firstname' maxlength='5'/>" | 3400 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 2551 " <INPUT type='text' id='lastname' maxlength='7'/>" | 3401 " <INPUT type='text' id='firstname' maxlength='5'/>" |
| 2552 " <INPUT type='text' id='email' maxlength='9'/>" | 3402 " <INPUT type='text' id='lastname' maxlength='7'/>" |
| 2553 " <INPUT type='submit' name='reply-send' value='Send'/>" | 3403 " <INPUT type='text' id='email' maxlength='9'/>" |
| 2554 "</FORM>"); | 3404 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 3405 "</FORM>", |
| 3406 false); |
| 3407 } |
| 2555 | 3408 |
| 2556 WebFrame* web_frame = GetMainFrame(); | 3409 TEST_F(FormAutofillTest, FillFormMaxLengthForUnownedForm) { |
| 2557 ASSERT_NE(nullptr, web_frame); | 3410 TestFillFormMaxLength( |
| 2558 | 3411 "<INPUT type='text' id='firstname' maxlength='5'/>" |
| 2559 FormCache form_cache; | 3412 "<INPUT type='text' id='lastname' maxlength='7'/>" |
| 2560 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3413 "<INPUT type='text' id='email' maxlength='9'/>" |
| 2561 ASSERT_EQ(1U, forms.size()); | 3414 "<INPUT type='submit' name='reply-send' value='Send'/>", |
| 2562 | 3415 true); |
| 2563 // Get the input element we want to find. | |
| 2564 WebInputElement input_element = GetInputElementById("firstname"); | |
| 2565 | |
| 2566 // Find the form that contains the input element. | |
| 2567 FormData form; | |
| 2568 FormFieldData field; | |
| 2569 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2570 &form, | |
| 2571 &field, | |
| 2572 autofill::REQUIRE_NONE)); | |
| 2573 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | |
| 2574 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
| 2575 EXPECT_EQ(GURL("http://buh.com"), form.action); | |
| 2576 | |
| 2577 const std::vector<FormFieldData>& fields = form.fields; | |
| 2578 ASSERT_EQ(3U, fields.size()); | |
| 2579 | |
| 2580 FormFieldData expected; | |
| 2581 expected.form_control_type = "text"; | |
| 2582 | |
| 2583 expected.name = ASCIIToUTF16("firstname"); | |
| 2584 expected.max_length = 5; | |
| 2585 expected.is_autofilled = false; | |
| 2586 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 2587 | |
| 2588 expected.name = ASCIIToUTF16("lastname"); | |
| 2589 expected.max_length = 7; | |
| 2590 expected.is_autofilled = false; | |
| 2591 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 2592 | |
| 2593 expected.name = ASCIIToUTF16("email"); | |
| 2594 expected.max_length = 9; | |
| 2595 expected.is_autofilled = false; | |
| 2596 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 2597 | |
| 2598 // Fill the form. | |
| 2599 form.fields[0].value = ASCIIToUTF16("Brother"); | |
| 2600 form.fields[1].value = ASCIIToUTF16("Jonathan"); | |
| 2601 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | |
| 2602 form.fields[0].is_autofilled = true; | |
| 2603 form.fields[1].is_autofilled = true; | |
| 2604 form.fields[2].is_autofilled = true; | |
| 2605 FillForm(form, input_element); | |
| 2606 | |
| 2607 // Find the newly-filled form that contains the input element. | |
| 2608 FormData form2; | |
| 2609 FormFieldData field2; | |
| 2610 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2611 &form2, | |
| 2612 &field2, | |
| 2613 autofill::REQUIRE_NONE)); | |
| 2614 | |
| 2615 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 2616 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 2617 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 2618 | |
| 2619 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 2620 ASSERT_EQ(3U, fields2.size()); | |
| 2621 | |
| 2622 expected.form_control_type = "text"; | |
| 2623 | |
| 2624 expected.name = ASCIIToUTF16("firstname"); | |
| 2625 expected.value = ASCIIToUTF16("Broth"); | |
| 2626 expected.max_length = 5; | |
| 2627 expected.is_autofilled = true; | |
| 2628 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
| 2629 | |
| 2630 expected.name = ASCIIToUTF16("lastname"); | |
| 2631 expected.value = ASCIIToUTF16("Jonatha"); | |
| 2632 expected.max_length = 7; | |
| 2633 expected.is_autofilled = true; | |
| 2634 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
| 2635 | |
| 2636 expected.name = ASCIIToUTF16("email"); | |
| 2637 expected.value = ASCIIToUTF16("brotherj@"); | |
| 2638 expected.max_length = 9; | |
| 2639 expected.is_autofilled = true; | |
| 2640 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
| 2641 } | 3416 } |
| 2642 | 3417 |
| 2643 // This test uses negative values of the maxlength attribute for input elements. | 3418 // This test uses negative values of the maxlength attribute for input elements. |
| 2644 // In this case, the maxlength of the input elements is set to the default | 3419 // In this case, the maxlength of the input elements is set to the default |
| 2645 // maxlength (defined in WebKit.) | 3420 // maxlength (defined in WebKit.) |
| 2646 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) { | 3421 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) { |
| 2647 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 3422 TestFillFormNegativeMaxLength( |
| 2648 " <INPUT type='text' id='firstname' maxlength='-1'/>" | 3423 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 2649 " <INPUT type='text' id='lastname' maxlength='-10'/>" | 3424 " <INPUT type='text' id='firstname' maxlength='-1'/>" |
| 2650 " <INPUT type='text' id='email' maxlength='-13'/>" | 3425 " <INPUT type='text' id='lastname' maxlength='-10'/>" |
| 2651 " <INPUT type='submit' name='reply-send' value='Send'/>" | 3426 " <INPUT type='text' id='email' maxlength='-13'/>" |
| 2652 "</FORM>"); | 3427 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 3428 "</FORM>", |
| 3429 false); |
| 3430 } |
| 2653 | 3431 |
| 2654 WebFrame* web_frame = GetMainFrame(); | 3432 TEST_F(FormAutofillTest, FillFormNegativeMaxLengthForUnownedForm) { |
| 2655 ASSERT_NE(nullptr, web_frame); | 3433 TestFillFormNegativeMaxLength( |
| 2656 | 3434 "<INPUT type='text' id='firstname' maxlength='-1'/>" |
| 2657 FormCache form_cache; | 3435 "<INPUT type='text' id='lastname' maxlength='-10'/>" |
| 2658 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3436 "<INPUT type='text' id='email' maxlength='-13'/>" |
| 2659 ASSERT_EQ(1U, forms.size()); | 3437 "<INPUT type='submit' name='reply-send' value='Send'/>", |
| 2660 | 3438 true); |
| 2661 // Get the input element we want to find. | |
| 2662 WebInputElement input_element = GetInputElementById("firstname"); | |
| 2663 | |
| 2664 // Find the form that contains the input element. | |
| 2665 FormData form; | |
| 2666 FormFieldData field; | |
| 2667 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2668 &form, | |
| 2669 &field, | |
| 2670 autofill::REQUIRE_NONE)); | |
| 2671 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | |
| 2672 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
| 2673 EXPECT_EQ(GURL("http://buh.com"), form.action); | |
| 2674 | |
| 2675 const std::vector<FormFieldData>& fields = form.fields; | |
| 2676 ASSERT_EQ(3U, fields.size()); | |
| 2677 | |
| 2678 FormFieldData expected; | |
| 2679 expected.form_control_type = "text"; | |
| 2680 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 2681 | |
| 2682 expected.name = ASCIIToUTF16("firstname"); | |
| 2683 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 2684 | |
| 2685 expected.name = ASCIIToUTF16("lastname"); | |
| 2686 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 2687 | |
| 2688 expected.name = ASCIIToUTF16("email"); | |
| 2689 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 2690 | |
| 2691 // Fill the form. | |
| 2692 form.fields[0].value = ASCIIToUTF16("Brother"); | |
| 2693 form.fields[1].value = ASCIIToUTF16("Jonathan"); | |
| 2694 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | |
| 2695 FillForm(form, input_element); | |
| 2696 | |
| 2697 // Find the newly-filled form that contains the input element. | |
| 2698 FormData form2; | |
| 2699 FormFieldData field2; | |
| 2700 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2701 &form2, | |
| 2702 &field2, | |
| 2703 autofill::REQUIRE_NONE)); | |
| 2704 | |
| 2705 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 2706 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 2707 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 2708 | |
| 2709 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 2710 ASSERT_EQ(3U, fields2.size()); | |
| 2711 | |
| 2712 expected.name = ASCIIToUTF16("firstname"); | |
| 2713 expected.value = ASCIIToUTF16("Brother"); | |
| 2714 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 2715 | |
| 2716 expected.name = ASCIIToUTF16("lastname"); | |
| 2717 expected.value = ASCIIToUTF16("Jonathan"); | |
| 2718 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 2719 | |
| 2720 expected.name = ASCIIToUTF16("email"); | |
| 2721 expected.value = ASCIIToUTF16("brotherj@example.com"); | |
| 2722 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 2723 } | 3439 } |
| 2724 | 3440 |
| 2725 TEST_F(FormAutofillTest, FillFormEmptyName) { | 3441 TEST_F(FormAutofillTest, FillFormEmptyName) { |
| 2726 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 3442 TestFillFormEmptyName( |
| 2727 " <INPUT type='text' id='firstname'/>" | 3443 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 2728 " <INPUT type='text' id='lastname'/>" | 3444 " <INPUT type='text' id='firstname'/>" |
| 2729 " <INPUT type='text' id='email'/>" | 3445 " <INPUT type='text' id='lastname'/>" |
| 2730 " <INPUT type='submit' value='Send'/>" | 3446 " <INPUT type='text' id='email'/>" |
| 2731 "</FORM>"); | 3447 " <INPUT type='submit' value='Send'/>" |
| 3448 "</FORM>", |
| 3449 false); |
| 3450 } |
| 2732 | 3451 |
| 2733 WebFrame* web_frame = GetMainFrame(); | 3452 TEST_F(FormAutofillTest, FillFormEmptyNameForUnownedForm) { |
| 2734 ASSERT_NE(nullptr, web_frame); | 3453 TestFillFormEmptyName( |
| 2735 | 3454 "<INPUT type='text' id='firstname'/>" |
| 2736 FormCache form_cache; | 3455 "<INPUT type='text' id='lastname'/>" |
| 2737 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3456 "<INPUT type='text' id='email'/>" |
| 2738 ASSERT_EQ(1U, forms.size()); | 3457 "<INPUT type='submit' value='Send'/>", |
| 2739 | 3458 true); |
| 2740 // Get the input element we want to find. | |
| 2741 WebInputElement input_element = GetInputElementById("firstname"); | |
| 2742 | |
| 2743 // Find the form that contains the input element. | |
| 2744 FormData form; | |
| 2745 FormFieldData field; | |
| 2746 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2747 &form, | |
| 2748 &field, | |
| 2749 autofill::REQUIRE_NONE)); | |
| 2750 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | |
| 2751 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
| 2752 EXPECT_EQ(GURL("http://buh.com"), form.action); | |
| 2753 | |
| 2754 const std::vector<FormFieldData>& fields = form.fields; | |
| 2755 ASSERT_EQ(3U, fields.size()); | |
| 2756 | |
| 2757 FormFieldData expected; | |
| 2758 expected.form_control_type = "text"; | |
| 2759 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 2760 | |
| 2761 expected.name = ASCIIToUTF16("firstname"); | |
| 2762 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 2763 | |
| 2764 expected.name = ASCIIToUTF16("lastname"); | |
| 2765 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 2766 | |
| 2767 expected.name = ASCIIToUTF16("email"); | |
| 2768 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 2769 | |
| 2770 // Fill the form. | |
| 2771 form.fields[0].value = ASCIIToUTF16("Wyatt"); | |
| 2772 form.fields[1].value = ASCIIToUTF16("Earp"); | |
| 2773 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | |
| 2774 FillForm(form, input_element); | |
| 2775 | |
| 2776 // Find the newly-filled form that contains the input element. | |
| 2777 FormData form2; | |
| 2778 FormFieldData field2; | |
| 2779 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2780 &form2, | |
| 2781 &field2, | |
| 2782 autofill::REQUIRE_NONE)); | |
| 2783 | |
| 2784 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 2785 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 2786 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 2787 | |
| 2788 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 2789 ASSERT_EQ(3U, fields2.size()); | |
| 2790 | |
| 2791 expected.form_control_type = "text"; | |
| 2792 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 2793 | |
| 2794 expected.name = ASCIIToUTF16("firstname"); | |
| 2795 expected.value = ASCIIToUTF16("Wyatt"); | |
| 2796 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 2797 | |
| 2798 expected.name = ASCIIToUTF16("lastname"); | |
| 2799 expected.value = ASCIIToUTF16("Earp"); | |
| 2800 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 2801 | |
| 2802 expected.name = ASCIIToUTF16("email"); | |
| 2803 expected.value = ASCIIToUTF16("wyatt@example.com"); | |
| 2804 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 2805 } | 3459 } |
| 2806 | 3460 |
| 2807 TEST_F(FormAutofillTest, FillFormEmptyFormNames) { | 3461 TEST_F(FormAutofillTest, FillFormEmptyFormNames) { |
| 2808 LoadHTML("<FORM action='http://buh.com' method='post'>" | 3462 TestFillFormEmptyFormNames( |
| 2809 " <INPUT type='text' id='firstname'/>" | 3463 "<FORM action='http://buh.com' method='post'>" |
| 2810 " <INPUT type='text' id='middlename'/>" | 3464 " <INPUT type='text' id='firstname'/>" |
| 2811 " <INPUT type='text' id='lastname'/>" | 3465 " <INPUT type='text' id='middlename'/>" |
| 2812 " <INPUT type='submit' value='Send'/>" | 3466 " <INPUT type='text' id='lastname'/>" |
| 2813 "</FORM>" | 3467 " <INPUT type='submit' value='Send'/>" |
| 2814 "<FORM action='http://abc.com' method='post'>" | 3468 "</FORM>" |
| 2815 " <INPUT type='text' id='apple'/>" | 3469 "<FORM action='http://abc.com' method='post'>" |
| 2816 " <INPUT type='text' id='banana'/>" | 3470 " <INPUT type='text' id='apple'/>" |
| 2817 " <INPUT type='text' id='cantelope'/>" | 3471 " <INPUT type='text' id='banana'/>" |
| 2818 " <INPUT type='submit' value='Send'/>" | 3472 " <INPUT type='text' id='cantelope'/>" |
| 2819 "</FORM>"); | 3473 " <INPUT type='submit' value='Send'/>" |
| 3474 "</FORM>", |
| 3475 false); |
| 3476 } |
| 2820 | 3477 |
| 2821 WebFrame* web_frame = GetMainFrame(); | 3478 TEST_F(FormAutofillTest, FillFormEmptyFormNamesForUnownedForm) { |
| 2822 ASSERT_NE(nullptr, web_frame); | 3479 TestFillFormEmptyFormNames( |
| 2823 | 3480 "<INPUT type='text' id='firstname'/>" |
| 2824 FormCache form_cache; | 3481 "<INPUT type='text' id='middlename'/>" |
| 2825 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3482 "<INPUT type='text' id='lastname'/>" |
| 2826 ASSERT_EQ(2U, forms.size()); | 3483 "<INPUT type='text' id='apple'/>" |
| 2827 | 3484 "<INPUT type='text' id='banana'/>" |
| 2828 // Get the input element we want to find. | 3485 "<INPUT type='text' id='cantelope'/>" |
| 2829 WebInputElement input_element = GetInputElementById("apple"); | 3486 "<INPUT type='submit' value='Send'/>", |
| 2830 | 3487 true); |
| 2831 // Find the form that contains the input element. | |
| 2832 FormData form; | |
| 2833 FormFieldData field; | |
| 2834 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2835 &form, | |
| 2836 &field, | |
| 2837 autofill::REQUIRE_NONE)); | |
| 2838 EXPECT_EQ(base::string16(), form.name); | |
| 2839 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
| 2840 EXPECT_EQ(GURL("http://abc.com"), form.action); | |
| 2841 | |
| 2842 const std::vector<FormFieldData>& fields = form.fields; | |
| 2843 ASSERT_EQ(3U, fields.size()); | |
| 2844 | |
| 2845 FormFieldData expected; | |
| 2846 expected.form_control_type = "text"; | |
| 2847 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 2848 | |
| 2849 expected.name = ASCIIToUTF16("apple"); | |
| 2850 expected.is_autofilled = false; | |
| 2851 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 2852 | |
| 2853 expected.name = ASCIIToUTF16("banana"); | |
| 2854 expected.is_autofilled = false; | |
| 2855 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 2856 | |
| 2857 expected.name = ASCIIToUTF16("cantelope"); | |
| 2858 expected.is_autofilled = false; | |
| 2859 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 2860 | |
| 2861 // Fill the form. | |
| 2862 form.fields[0].value = ASCIIToUTF16("Red"); | |
| 2863 form.fields[1].value = ASCIIToUTF16("Yellow"); | |
| 2864 form.fields[2].value = ASCIIToUTF16("Also Yellow"); | |
| 2865 form.fields[0].is_autofilled = true; | |
| 2866 form.fields[1].is_autofilled = true; | |
| 2867 form.fields[2].is_autofilled = true; | |
| 2868 FillForm(form, input_element); | |
| 2869 | |
| 2870 // Find the newly-filled form that contains the input element. | |
| 2871 FormData form2; | |
| 2872 FormFieldData field2; | |
| 2873 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 2874 &form2, | |
| 2875 &field2, | |
| 2876 autofill::REQUIRE_NONE)); | |
| 2877 | |
| 2878 EXPECT_EQ(base::string16(), form2.name); | |
| 2879 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 2880 EXPECT_EQ(GURL("http://abc.com"), form2.action); | |
| 2881 | |
| 2882 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 2883 ASSERT_EQ(3U, fields2.size()); | |
| 2884 | |
| 2885 expected.name = ASCIIToUTF16("apple"); | |
| 2886 expected.value = ASCIIToUTF16("Red"); | |
| 2887 expected.is_autofilled = true; | |
| 2888 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
| 2889 | |
| 2890 expected.name = ASCIIToUTF16("banana"); | |
| 2891 expected.value = ASCIIToUTF16("Yellow"); | |
| 2892 expected.is_autofilled = true; | |
| 2893 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
| 2894 | |
| 2895 expected.name = ASCIIToUTF16("cantelope"); | |
| 2896 expected.value = ASCIIToUTF16("Also Yellow"); | |
| 2897 expected.is_autofilled = true; | |
| 2898 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
| 2899 } | 3488 } |
| 2900 | 3489 |
| 2901 TEST_F(FormAutofillTest, ThreePartPhone) { | 3490 TEST_F(FormAutofillTest, ThreePartPhone) { |
| 2902 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 3491 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2903 " Phone:" | 3492 " Phone:" |
| 2904 " <input type='text' name='dayphone1'>" | 3493 " <input type='text' name='dayphone1'>" |
| 2905 " -" | 3494 " -" |
| 2906 " <input type='text' name='dayphone2'>" | 3495 " <input type='text' name='dayphone2'>" |
| 2907 " -" | 3496 " -" |
| 2908 " <input type='text' name='dayphone3'>" | 3497 " <input type='text' name='dayphone3'>" |
| 2909 " ext.:" | 3498 " ext.:" |
| 2910 " <input type='text' name='dayphone4'>" | 3499 " <input type='text' name='dayphone4'>" |
| 2911 " <input type='submit' name='reply-send' value='Send'>" | 3500 " <input type='submit' name='reply-send' value='Send'>" |
| 2912 "</FORM>"); | 3501 "</FORM>"); |
| 2913 | 3502 |
| 2914 | 3503 |
| 2915 WebFrame* frame = GetMainFrame(); | 3504 WebFrame* frame = GetMainFrame(); |
| 2916 ASSERT_NE(nullptr, frame); | 3505 ASSERT_NE(nullptr, frame); |
| 2917 | 3506 |
| 2918 WebVector<WebFormElement> forms; | 3507 WebVector<WebFormElement> forms; |
| 2919 frame->document().forms(forms); | 3508 frame->document().forms(forms); |
| 2920 ASSERT_EQ(1U, forms.size()); | 3509 ASSERT_EQ(1U, forms.size()); |
| 2921 | 3510 |
| 2922 FormData form; | 3511 FormData form; |
| 2923 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 3512 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 2924 WebFormControlElement(), | 3513 WebFormControlElement(), |
| 2925 autofill::REQUIRE_NONE, | 3514 REQUIRE_NONE, |
| 2926 autofill::EXTRACT_VALUE, | 3515 EXTRACT_VALUE, |
| 2927 &form, | 3516 &form, |
| 2928 NULL)); | 3517 nullptr)); |
| 2929 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3518 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2930 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3519 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2931 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3520 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2932 | 3521 |
| 2933 const std::vector<FormFieldData>& fields = form.fields; | 3522 const std::vector<FormFieldData>& fields = form.fields; |
| 2934 ASSERT_EQ(4U, fields.size()); | 3523 ASSERT_EQ(4U, fields.size()); |
| 2935 | 3524 |
| 2936 FormFieldData expected; | 3525 FormFieldData expected; |
| 2937 expected.form_control_type = "text"; | 3526 expected.form_control_type = "text"; |
| 2938 expected.max_length = WebInputElement::defaultMaxLength(); | 3527 expected.max_length = WebInputElement::defaultMaxLength(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2974 WebFrame* frame = GetMainFrame(); | 3563 WebFrame* frame = GetMainFrame(); |
| 2975 ASSERT_NE(nullptr, frame); | 3564 ASSERT_NE(nullptr, frame); |
| 2976 | 3565 |
| 2977 WebVector<WebFormElement> forms; | 3566 WebVector<WebFormElement> forms; |
| 2978 frame->document().forms(forms); | 3567 frame->document().forms(forms); |
| 2979 ASSERT_EQ(1U, forms.size()); | 3568 ASSERT_EQ(1U, forms.size()); |
| 2980 | 3569 |
| 2981 FormData form; | 3570 FormData form; |
| 2982 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 3571 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 2983 WebFormControlElement(), | 3572 WebFormControlElement(), |
| 2984 autofill::REQUIRE_NONE, | 3573 REQUIRE_NONE, |
| 2985 autofill::EXTRACT_VALUE, | 3574 EXTRACT_VALUE, |
| 2986 &form, | 3575 &form, |
| 2987 NULL)); | 3576 nullptr)); |
| 2988 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3577 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2989 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3578 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2990 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3579 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2991 | 3580 |
| 2992 const std::vector<FormFieldData>& fields = form.fields; | 3581 const std::vector<FormFieldData>& fields = form.fields; |
| 2993 ASSERT_EQ(6U, fields.size()); | 3582 ASSERT_EQ(6U, fields.size()); |
| 2994 | 3583 |
| 2995 FormFieldData expected; | 3584 FormFieldData expected; |
| 2996 expected.form_control_type = "text"; | 3585 expected.form_control_type = "text"; |
| 2997 | 3586 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3009 expected.name = ASCIIToUTF16("dayphone3"); | 3598 expected.name = ASCIIToUTF16("dayphone3"); |
| 3010 expected.max_length = 4; | 3599 expected.max_length = 4; |
| 3011 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3600 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 3012 | 3601 |
| 3013 expected.label = ASCIIToUTF16("ext.:"); | 3602 expected.label = ASCIIToUTF16("ext.:"); |
| 3014 expected.name = ASCIIToUTF16("dayphone4"); | 3603 expected.name = ASCIIToUTF16("dayphone4"); |
| 3015 expected.max_length = 5; | 3604 expected.max_length = 5; |
| 3016 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | 3605 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 3017 | 3606 |
| 3018 // When unspecified |size|, default is returned. | 3607 // When unspecified |size|, default is returned. |
| 3019 expected.label = base::string16(); | 3608 expected.label.clear(); |
| 3020 expected.name = ASCIIToUTF16("default1"); | 3609 expected.name = ASCIIToUTF16("default1"); |
| 3021 expected.max_length = WebInputElement::defaultMaxLength(); | 3610 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3022 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]); | 3611 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]); |
| 3023 | 3612 |
| 3024 // When invalid |size|, default is returned. | 3613 // When invalid |size|, default is returned. |
| 3025 expected.label = base::string16(); | 3614 expected.label.clear(); |
| 3026 expected.name = ASCIIToUTF16("invalid1"); | 3615 expected.name = ASCIIToUTF16("invalid1"); |
| 3027 expected.max_length = WebInputElement::defaultMaxLength(); | 3616 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3028 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); | 3617 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
| 3029 } | 3618 } |
| 3030 | 3619 |
| 3031 // This test re-creates the experience of typing in a field then selecting a | 3620 // This test re-creates the experience of typing in a field then selecting a |
| 3032 // profile from the Autofill suggestions popup. The field that is being typed | 3621 // profile from the Autofill suggestions popup. The field that is being typed |
| 3033 // into should be filled even though it's not technically empty. | 3622 // into should be filled even though it's not technically empty. |
| 3034 TEST_F(FormAutofillTest, FillFormNonEmptyField) { | 3623 TEST_F(FormAutofillTest, FillFormNonEmptyField) { |
| 3035 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 3624 TestFillFormNonEmptyField( |
| 3036 " <INPUT type='text' id='firstname'/>" | 3625 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3037 " <INPUT type='text' id='lastname'/>" | 3626 " <INPUT type='text' id='firstname'/>" |
| 3038 " <INPUT type='text' id='email'/>" | 3627 " <INPUT type='text' id='lastname'/>" |
| 3039 " <INPUT type='submit' value='Send'/>" | 3628 " <INPUT type='text' id='email'/>" |
| 3040 "</FORM>"); | 3629 " <INPUT type='submit' value='Send'/>" |
| 3630 "</FORM>", |
| 3631 false); |
| 3632 } |
| 3041 | 3633 |
| 3042 WebFrame* web_frame = GetMainFrame(); | 3634 TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) { |
| 3043 ASSERT_NE(nullptr, web_frame); | 3635 TestFillFormNonEmptyField("<INPUT type='text' id='firstname'/>" |
| 3044 | 3636 "<INPUT type='text' id='lastname'/>" |
| 3045 FormCache form_cache; | 3637 "<INPUT type='text' id='email'/>" |
| 3046 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3638 "<INPUT type='submit' value='Send'/>", |
| 3047 ASSERT_EQ(1U, forms.size()); | 3639 true); |
| 3048 | |
| 3049 // Get the input element we want to find. | |
| 3050 WebInputElement input_element = GetInputElementById("firstname"); | |
| 3051 | |
| 3052 // Simulate typing by modifying the field value. | |
| 3053 input_element.setValue(ASCIIToUTF16("Wy")); | |
| 3054 | |
| 3055 // Find the form that contains the input element. | |
| 3056 FormData form; | |
| 3057 FormFieldData field; | |
| 3058 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 3059 &form, | |
| 3060 &field, | |
| 3061 autofill::REQUIRE_NONE)); | |
| 3062 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | |
| 3063 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
| 3064 EXPECT_EQ(GURL("http://buh.com"), form.action); | |
| 3065 | |
| 3066 const std::vector<FormFieldData>& fields = form.fields; | |
| 3067 ASSERT_EQ(3U, fields.size()); | |
| 3068 | |
| 3069 FormFieldData expected; | |
| 3070 expected.form_control_type = "text"; | |
| 3071 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 3072 | |
| 3073 expected.name = ASCIIToUTF16("firstname"); | |
| 3074 expected.value = ASCIIToUTF16("Wy"); | |
| 3075 expected.is_autofilled = false; | |
| 3076 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
| 3077 | |
| 3078 expected.name = ASCIIToUTF16("lastname"); | |
| 3079 expected.value = base::string16(); | |
| 3080 expected.is_autofilled = false; | |
| 3081 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
| 3082 | |
| 3083 expected.name = ASCIIToUTF16("email"); | |
| 3084 expected.value = base::string16(); | |
| 3085 expected.is_autofilled = false; | |
| 3086 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
| 3087 | |
| 3088 // Preview the form and verify that the cursor position has been updated. | |
| 3089 form.fields[0].value = ASCIIToUTF16("Wyatt"); | |
| 3090 form.fields[1].value = ASCIIToUTF16("Earp"); | |
| 3091 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | |
| 3092 form.fields[0].is_autofilled = true; | |
| 3093 form.fields[1].is_autofilled = true; | |
| 3094 form.fields[2].is_autofilled = true; | |
| 3095 PreviewForm(form, input_element); | |
| 3096 EXPECT_EQ(2, input_element.selectionStart()); | |
| 3097 EXPECT_EQ(5, input_element.selectionEnd()); | |
| 3098 | |
| 3099 // Fill the form. | |
| 3100 FillForm(form, input_element); | |
| 3101 | |
| 3102 // Find the newly-filled form that contains the input element. | |
| 3103 FormData form2; | |
| 3104 FormFieldData field2; | |
| 3105 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | |
| 3106 &form2, | |
| 3107 &field2, | |
| 3108 autofill::REQUIRE_NONE)); | |
| 3109 | |
| 3110 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 3111 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 3112 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 3113 | |
| 3114 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 3115 ASSERT_EQ(3U, fields2.size()); | |
| 3116 | |
| 3117 expected.name = ASCIIToUTF16("firstname"); | |
| 3118 expected.value = ASCIIToUTF16("Wyatt"); | |
| 3119 expected.is_autofilled = true; | |
| 3120 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
| 3121 | |
| 3122 expected.name = ASCIIToUTF16("lastname"); | |
| 3123 expected.value = ASCIIToUTF16("Earp"); | |
| 3124 expected.is_autofilled = true; | |
| 3125 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
| 3126 | |
| 3127 expected.name = ASCIIToUTF16("email"); | |
| 3128 expected.value = ASCIIToUTF16("wyatt@example.com"); | |
| 3129 expected.is_autofilled = true; | |
| 3130 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
| 3131 | |
| 3132 // Verify that the cursor position has been updated. | |
| 3133 EXPECT_EQ(5, input_element.selectionStart()); | |
| 3134 EXPECT_EQ(5, input_element.selectionEnd()); | |
| 3135 } | 3640 } |
| 3136 | 3641 |
| 3137 TEST_F(FormAutofillTest, ClearFormWithNode) { | 3642 TEST_F(FormAutofillTest, ClearFormWithNode) { |
| 3138 LoadHTML( | 3643 TestClearFormWithNode( |
| 3139 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3644 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3140 " <INPUT type='text' id='firstname' value='Wyatt'/>" | 3645 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3141 " <INPUT type='text' id='lastname' value='Earp'/>" | 3646 " <INPUT type='text' id='lastname' value='Earp'/>" |
| 3142 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" | 3647 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" |
| 3143 " <INPUT type='text' id='notenabled' disabled='disabled'>" | 3648 " <INPUT type='text' id='notenabled' disabled='disabled'>" |
| 3144 " <INPUT type='month' id='month' value='2012-11'>" | 3649 " <INPUT type='month' id='month' value='2012-11'>" |
| 3145 " <INPUT type='month' id='month-disabled' value='2012-11'" | 3650 " <INPUT type='month' id='month-disabled' value='2012-11'" |
| 3146 " disabled='disabled'>" | 3651 " disabled='disabled'>" |
| 3147 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>" | 3652 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>" |
| 3148 " <TEXTAREA id='textarea-disabled' disabled='disabled'>" | 3653 " <TEXTAREA id='textarea-disabled' disabled='disabled'>" |
| 3149 " Banana!" | 3654 " Banana!" |
| 3150 " </TEXTAREA>" | 3655 " </TEXTAREA>" |
| 3151 " <TEXTAREA id='textarea-noAC' autocomplete='off'>Carrot?</TEXTAREA>" | 3656 " <TEXTAREA id='textarea-noAC' autocomplete='off'>Carrot?</TEXTAREA>" |
| 3152 " <INPUT type='submit' value='Send'/>" | 3657 " <INPUT type='submit' value='Send'/>" |
| 3153 "</FORM>"); | 3658 "</FORM>", |
| 3659 false); |
| 3660 } |
| 3154 | 3661 |
| 3155 WebFrame* web_frame = GetMainFrame(); | 3662 TEST_F(FormAutofillTest, ClearFormWithNodeForUnownedForm) { |
| 3156 ASSERT_NE(nullptr, web_frame); | 3663 TestClearFormWithNode( |
| 3157 | 3664 " <!-- Indented on purpose //-->" |
| 3158 FormCache form_cache; | 3665 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3159 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3666 " <INPUT type='text' id='lastname' value='Earp'/>" |
| 3160 ASSERT_EQ(1U, forms.size()); | 3667 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" |
| 3161 | 3668 " <INPUT type='text' id='notenabled' disabled='disabled'>" |
| 3162 // Set the auto-filled attribute. | 3669 " <INPUT type='month' id='month' value='2012-11'>" |
| 3163 WebInputElement firstname = GetInputElementById("firstname"); | 3670 " <INPUT type='month' id='month-disabled' value='2012-11'" |
| 3164 firstname.setAutofilled(true); | 3671 " disabled='disabled'>" |
| 3165 WebInputElement lastname = GetInputElementById("lastname"); | 3672 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>" |
| 3166 lastname.setAutofilled(true); | 3673 " <TEXTAREA id='textarea-disabled' disabled='disabled'>" |
| 3167 WebInputElement month = GetInputElementById("month"); | 3674 " Banana!" |
| 3168 month.setAutofilled(true); | 3675 " </TEXTAREA>" |
| 3169 WebInputElement textarea = GetInputElementById("textarea"); | 3676 " <TEXTAREA id='textarea-noAC' autocomplete='off'>Carrot?</TEXTAREA>" |
| 3170 textarea.setAutofilled(true); | 3677 " <INPUT type='submit' value='Send'/>", |
| 3171 | 3678 true); |
| 3172 // Set the value of the disabled text input element. | |
| 3173 WebInputElement notenabled = GetInputElementById("notenabled"); | |
| 3174 notenabled.setValue(WebString::fromUTF8("no clear")); | |
| 3175 | |
| 3176 // Clear the form. | |
| 3177 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | |
| 3178 | |
| 3179 // Verify that the auto-filled attribute has been turned off. | |
| 3180 EXPECT_FALSE(firstname.isAutofilled()); | |
| 3181 | |
| 3182 // Verify the form is cleared. | |
| 3183 FormData form2; | |
| 3184 FormFieldData field2; | |
| 3185 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, | |
| 3186 &form2, | |
| 3187 &field2, | |
| 3188 autofill::REQUIRE_NONE)); | |
| 3189 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 3190 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 3191 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 3192 | |
| 3193 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 3194 ASSERT_EQ(9U, fields2.size()); | |
| 3195 | |
| 3196 FormFieldData expected; | |
| 3197 expected.form_control_type = "text"; | |
| 3198 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 3199 | |
| 3200 expected.name = ASCIIToUTF16("firstname"); | |
| 3201 expected.value = base::string16(); | |
| 3202 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
| 3203 | |
| 3204 expected.name = ASCIIToUTF16("lastname"); | |
| 3205 expected.value = base::string16(); | |
| 3206 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
| 3207 | |
| 3208 expected.name = ASCIIToUTF16("noAC"); | |
| 3209 expected.value = ASCIIToUTF16("one"); | |
| 3210 expected.autocomplete_attribute = "off"; | |
| 3211 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
| 3212 expected.autocomplete_attribute = std::string(); // reset | |
| 3213 | |
| 3214 expected.name = ASCIIToUTF16("notenabled"); | |
| 3215 expected.value = ASCIIToUTF16("no clear"); | |
| 3216 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); | |
| 3217 | |
| 3218 expected.form_control_type = "month"; | |
| 3219 expected.max_length = 0; | |
| 3220 expected.name = ASCIIToUTF16("month"); | |
| 3221 expected.value = base::string16(); | |
| 3222 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[4]); | |
| 3223 | |
| 3224 expected.name = ASCIIToUTF16("month-disabled"); | |
| 3225 expected.value = ASCIIToUTF16("2012-11"); | |
| 3226 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[5]); | |
| 3227 | |
| 3228 expected.form_control_type = "textarea"; | |
| 3229 expected.name = ASCIIToUTF16("textarea"); | |
| 3230 expected.value = base::string16(); | |
| 3231 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[6]); | |
| 3232 | |
| 3233 expected.name = ASCIIToUTF16("textarea-disabled"); | |
| 3234 expected.value = ASCIIToUTF16(" Banana! "); | |
| 3235 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[7]); | |
| 3236 | |
| 3237 expected.name = ASCIIToUTF16("textarea-noAC"); | |
| 3238 expected.value = ASCIIToUTF16("Carrot?"); | |
| 3239 expected.autocomplete_attribute = "off"; | |
| 3240 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]); | |
| 3241 expected.autocomplete_attribute = std::string(); // reset | |
| 3242 | |
| 3243 // Verify that the cursor position has been updated. | |
| 3244 EXPECT_EQ(0, firstname.selectionStart()); | |
| 3245 EXPECT_EQ(0, firstname.selectionEnd()); | |
| 3246 } | 3679 } |
| 3247 | 3680 |
| 3248 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { | 3681 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { |
| 3249 LoadHTML( | 3682 TestClearFormWithNodeContainingSelectOne( |
| 3250 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3683 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3251 " <INPUT type='text' id='firstname' value='Wyatt'/>" | 3684 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3252 " <INPUT type='text' id='lastname' value='Earp'/>" | 3685 " <INPUT type='text' id='lastname' value='Earp'/>" |
| 3253 " <SELECT id='state' name='state'>" | 3686 " <SELECT id='state' name='state'>" |
| 3254 " <OPTION selected>?</OPTION>" | 3687 " <OPTION selected>?</OPTION>" |
| 3255 " <OPTION>AA</OPTION>" | 3688 " <OPTION>AA</OPTION>" |
| 3256 " <OPTION>AE</OPTION>" | 3689 " <OPTION>AE</OPTION>" |
| 3257 " <OPTION>AK</OPTION>" | 3690 " <OPTION>AK</OPTION>" |
| 3258 " </SELECT>" | 3691 " </SELECT>" |
| 3259 " <INPUT type='submit' value='Send'/>" | 3692 " <INPUT type='submit' value='Send'/>" |
| 3260 "</FORM>"); | 3693 "</FORM>", |
| 3694 false); |
| 3695 } |
| 3261 | 3696 |
| 3262 WebFrame* web_frame = GetMainFrame(); | 3697 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOneForUnownedForm) { |
| 3263 ASSERT_NE(nullptr, web_frame); | 3698 TestClearFormWithNodeContainingSelectOne( |
| 3264 | 3699 "<INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3265 FormCache form_cache; | 3700 "<INPUT type='text' id='lastname' value='Earp'/>" |
| 3266 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3701 "<SELECT id='state' name='state'>" |
| 3267 ASSERT_EQ(1U, forms.size()); | 3702 " <OPTION selected>?</OPTION>" |
| 3268 | 3703 " <OPTION>AA</OPTION>" |
| 3269 // Set the auto-filled attribute. | 3704 " <OPTION>AE</OPTION>" |
| 3270 WebInputElement firstname = GetInputElementById("firstname"); | 3705 " <OPTION>AK</OPTION>" |
| 3271 firstname.setAutofilled(true); | 3706 "</SELECT>" |
| 3272 WebInputElement lastname = GetInputElementById("lastname"); | 3707 "<INPUT type='submit' value='Send'/>", |
| 3273 lastname.setAutofilled(true); | 3708 true); |
| 3274 | |
| 3275 // Set the value and auto-filled attribute of the state element. | |
| 3276 WebSelectElement state = | |
| 3277 web_frame->document().getElementById("state").to<WebSelectElement>(); | |
| 3278 state.setValue(WebString::fromUTF8("AK")); | |
| 3279 state.setAutofilled(true); | |
| 3280 | |
| 3281 // Clear the form. | |
| 3282 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | |
| 3283 | |
| 3284 // Verify that the auto-filled attribute has been turned off. | |
| 3285 EXPECT_FALSE(firstname.isAutofilled()); | |
| 3286 | |
| 3287 // Verify the form is cleared. | |
| 3288 FormData form2; | |
| 3289 FormFieldData field2; | |
| 3290 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, | |
| 3291 &form2, | |
| 3292 &field2, | |
| 3293 autofill::REQUIRE_NONE)); | |
| 3294 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
| 3295 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
| 3296 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
| 3297 | |
| 3298 const std::vector<FormFieldData>& fields2 = form2.fields; | |
| 3299 ASSERT_EQ(3U, fields2.size()); | |
| 3300 | |
| 3301 FormFieldData expected; | |
| 3302 | |
| 3303 expected.name = ASCIIToUTF16("firstname"); | |
| 3304 expected.value = base::string16(); | |
| 3305 expected.form_control_type = "text"; | |
| 3306 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 3307 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
| 3308 | |
| 3309 expected.name = ASCIIToUTF16("lastname"); | |
| 3310 expected.value = base::string16(); | |
| 3311 expected.form_control_type = "text"; | |
| 3312 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 3313 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
| 3314 | |
| 3315 expected.name = ASCIIToUTF16("state"); | |
| 3316 expected.value = ASCIIToUTF16("?"); | |
| 3317 expected.form_control_type = "select-one"; | |
| 3318 expected.max_length = 0; | |
| 3319 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
| 3320 | |
| 3321 // Verify that the cursor position has been updated. | |
| 3322 EXPECT_EQ(0, firstname.selectionStart()); | |
| 3323 EXPECT_EQ(0, firstname.selectionEnd()); | |
| 3324 } | 3709 } |
| 3325 | 3710 |
| 3326 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { | 3711 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
| 3327 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 3712 TestClearPreviewedFormWithElement( |
| 3328 " <INPUT type='text' id='firstname' value='Wyatt'/>" | 3713 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3329 " <INPUT type='text' id='lastname'/>" | 3714 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3330 " <INPUT type='text' id='email'/>" | 3715 " <INPUT type='text' id='lastname'/>" |
| 3331 " <INPUT type='email' id='email2'/>" | 3716 " <INPUT type='text' id='email'/>" |
| 3332 " <INPUT type='tel' id='phone'/>" | 3717 " <INPUT type='email' id='email2'/>" |
| 3333 " <INPUT type='submit' value='Send'/>" | 3718 " <INPUT type='tel' id='phone'/>" |
| 3334 "</FORM>"); | 3719 " <INPUT type='submit' value='Send'/>" |
| 3720 "</FORM>"); |
| 3721 } |
| 3335 | 3722 |
| 3336 WebFrame* web_frame = GetMainFrame(); | 3723 TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) { |
| 3337 ASSERT_NE(nullptr, web_frame); | 3724 TestClearPreviewedFormWithElement( |
| 3338 | 3725 "<INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3339 FormCache form_cache; | 3726 "<INPUT type='text' id='lastname'/>" |
| 3340 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3727 "<INPUT type='text' id='email'/>" |
| 3341 ASSERT_EQ(1U, forms.size()); | 3728 "<INPUT type='email' id='email2'/>" |
| 3342 | 3729 "<INPUT type='tel' id='phone'/>" |
| 3343 // Set the auto-filled attribute. | 3730 "<INPUT type='submit' value='Send'/>"); |
| 3344 WebInputElement firstname = GetInputElementById("firstname"); | |
| 3345 firstname.setAutofilled(true); | |
| 3346 WebInputElement lastname = GetInputElementById("lastname"); | |
| 3347 lastname.setAutofilled(true); | |
| 3348 WebInputElement email = GetInputElementById("email"); | |
| 3349 email.setAutofilled(true); | |
| 3350 WebInputElement email2 = GetInputElementById("email2"); | |
| 3351 email2.setAutofilled(true); | |
| 3352 WebInputElement phone = GetInputElementById("phone"); | |
| 3353 phone.setAutofilled(true); | |
| 3354 | |
| 3355 // Set the suggested values on two of the elements. | |
| 3356 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | |
| 3357 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | |
| 3358 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | |
| 3359 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | |
| 3360 | |
| 3361 // Clear the previewed fields. | |
| 3362 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false)); | |
| 3363 | |
| 3364 // Fields with empty suggestions suggestions are not modified. | |
| 3365 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | |
| 3366 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | |
| 3367 EXPECT_TRUE(firstname.isAutofilled()); | |
| 3368 | |
| 3369 // Verify the previewed fields are cleared. | |
| 3370 EXPECT_TRUE(lastname.value().isEmpty()); | |
| 3371 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | |
| 3372 EXPECT_FALSE(lastname.isAutofilled()); | |
| 3373 EXPECT_TRUE(email.value().isEmpty()); | |
| 3374 EXPECT_TRUE(email.suggestedValue().isEmpty()); | |
| 3375 EXPECT_FALSE(email.isAutofilled()); | |
| 3376 EXPECT_TRUE(email2.value().isEmpty()); | |
| 3377 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | |
| 3378 EXPECT_FALSE(email2.isAutofilled()); | |
| 3379 EXPECT_TRUE(phone.value().isEmpty()); | |
| 3380 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | |
| 3381 EXPECT_FALSE(phone.isAutofilled()); | |
| 3382 | |
| 3383 // Verify that the cursor position has been updated. | |
| 3384 EXPECT_EQ(0, lastname.selectionStart()); | |
| 3385 EXPECT_EQ(0, lastname.selectionEnd()); | |
| 3386 } | 3731 } |
| 3387 | 3732 |
| 3388 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { | 3733 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { |
| 3389 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 3734 TestClearPreviewedFormWithNonEmptyInitiatingNode( |
| 3390 " <INPUT type='text' id='firstname' value='W'/>" | 3735 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3391 " <INPUT type='text' id='lastname'/>" | 3736 " <INPUT type='text' id='firstname' value='W'/>" |
| 3392 " <INPUT type='text' id='email'/>" | 3737 " <INPUT type='text' id='lastname'/>" |
| 3393 " <INPUT type='email' id='email2'/>" | 3738 " <INPUT type='text' id='email'/>" |
| 3394 " <INPUT type='tel' id='phone'/>" | 3739 " <INPUT type='email' id='email2'/>" |
| 3395 " <INPUT type='submit' value='Send'/>" | 3740 " <INPUT type='tel' id='phone'/>" |
| 3396 "</FORM>"); | 3741 " <INPUT type='submit' value='Send'/>" |
| 3742 "</FORM>"); |
| 3743 } |
| 3397 | 3744 |
| 3398 WebFrame* web_frame = GetMainFrame(); | 3745 TEST_F(FormAutofillTest, |
| 3399 ASSERT_NE(nullptr, web_frame); | 3746 ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) { |
| 3400 | 3747 TestClearPreviewedFormWithNonEmptyInitiatingNode( |
| 3401 FormCache form_cache; | 3748 "<INPUT type='text' id='firstname' value='W'/>" |
| 3402 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3749 "<INPUT type='text' id='lastname'/>" |
| 3403 ASSERT_EQ(1U, forms.size()); | 3750 "<INPUT type='text' id='email'/>" |
| 3404 | 3751 "<INPUT type='email' id='email2'/>" |
| 3405 // Set the auto-filled attribute. | 3752 "<INPUT type='tel' id='phone'/>" |
| 3406 WebInputElement firstname = GetInputElementById("firstname"); | 3753 "<INPUT type='submit' value='Send'/>"); |
| 3407 firstname.setAutofilled(true); | |
| 3408 WebInputElement lastname = GetInputElementById("lastname"); | |
| 3409 lastname.setAutofilled(true); | |
| 3410 WebInputElement email = GetInputElementById("email"); | |
| 3411 email.setAutofilled(true); | |
| 3412 WebInputElement email2 = GetInputElementById("email2"); | |
| 3413 email2.setAutofilled(true); | |
| 3414 WebInputElement phone = GetInputElementById("phone"); | |
| 3415 phone.setAutofilled(true); | |
| 3416 | |
| 3417 | |
| 3418 // Set the suggested values on all of the elements. | |
| 3419 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | |
| 3420 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | |
| 3421 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | |
| 3422 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | |
| 3423 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | |
| 3424 | |
| 3425 // Clear the previewed fields. | |
| 3426 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, false)); | |
| 3427 | |
| 3428 // Fields with non-empty values are restored. | |
| 3429 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); | |
| 3430 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | |
| 3431 EXPECT_FALSE(firstname.isAutofilled()); | |
| 3432 EXPECT_EQ(1, firstname.selectionStart()); | |
| 3433 EXPECT_EQ(1, firstname.selectionEnd()); | |
| 3434 | |
| 3435 // Verify the previewed fields are cleared. | |
| 3436 EXPECT_TRUE(lastname.value().isEmpty()); | |
| 3437 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | |
| 3438 EXPECT_FALSE(lastname.isAutofilled()); | |
| 3439 EXPECT_TRUE(email.value().isEmpty()); | |
| 3440 EXPECT_TRUE(email.suggestedValue().isEmpty()); | |
| 3441 EXPECT_FALSE(email.isAutofilled()); | |
| 3442 EXPECT_TRUE(email2.value().isEmpty()); | |
| 3443 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | |
| 3444 EXPECT_FALSE(email2.isAutofilled()); | |
| 3445 EXPECT_TRUE(phone.value().isEmpty()); | |
| 3446 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | |
| 3447 EXPECT_FALSE(phone.isAutofilled()); | |
| 3448 } | 3754 } |
| 3449 | 3755 |
| 3450 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { | 3756 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { |
| 3451 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | 3757 TestClearPreviewedFormWithAutofilledInitiatingNode( |
| 3452 " <INPUT type='text' id='firstname' value='W'/>" | 3758 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3453 " <INPUT type='text' id='lastname'/>" | 3759 " <INPUT type='text' id='firstname' value='W'/>" |
| 3454 " <INPUT type='text' id='email'/>" | 3760 " <INPUT type='text' id='lastname'/>" |
| 3455 " <INPUT type='email' id='email2'/>" | 3761 " <INPUT type='text' id='email'/>" |
| 3456 " <INPUT type='tel' id='phone'/>" | 3762 " <INPUT type='email' id='email2'/>" |
| 3457 " <INPUT type='submit' value='Send'/>" | 3763 " <INPUT type='tel' id='phone'/>" |
| 3458 "</FORM>"); | 3764 " <INPUT type='submit' value='Send'/>" |
| 3765 "</FORM>"); |
| 3766 } |
| 3459 | 3767 |
| 3460 WebFrame* web_frame = GetMainFrame(); | 3768 TEST_F(FormAutofillTest, |
| 3461 ASSERT_NE(nullptr, web_frame); | 3769 ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) { |
| 3462 | 3770 TestClearPreviewedFormWithAutofilledInitiatingNode( |
| 3463 FormCache form_cache; | 3771 "<INPUT type='text' id='firstname' value='W'/>" |
| 3464 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3772 "<INPUT type='text' id='lastname'/>" |
| 3465 ASSERT_EQ(1U, forms.size()); | 3773 "<INPUT type='text' id='email'/>" |
| 3466 | 3774 "<INPUT type='email' id='email2'/>" |
| 3467 // Set the auto-filled attribute. | 3775 "<INPUT type='tel' id='phone'/>" |
| 3468 WebInputElement firstname = GetInputElementById("firstname"); | 3776 "<INPUT type='submit' value='Send'/>"); |
| 3469 firstname.setAutofilled(true); | |
| 3470 WebInputElement lastname = GetInputElementById("lastname"); | |
| 3471 lastname.setAutofilled(true); | |
| 3472 WebInputElement email = GetInputElementById("email"); | |
| 3473 email.setAutofilled(true); | |
| 3474 WebInputElement email2 = GetInputElementById("email2"); | |
| 3475 email2.setAutofilled(true); | |
| 3476 WebInputElement phone = GetInputElementById("phone"); | |
| 3477 phone.setAutofilled(true); | |
| 3478 | |
| 3479 // Set the suggested values on all of the elements. | |
| 3480 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | |
| 3481 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | |
| 3482 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | |
| 3483 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | |
| 3484 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | |
| 3485 | |
| 3486 // Clear the previewed fields. | |
| 3487 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, true)); | |
| 3488 | |
| 3489 // Fields with non-empty values are restored. | |
| 3490 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); | |
| 3491 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | |
| 3492 EXPECT_TRUE(firstname.isAutofilled()); | |
| 3493 EXPECT_EQ(1, firstname.selectionStart()); | |
| 3494 EXPECT_EQ(1, firstname.selectionEnd()); | |
| 3495 | |
| 3496 // Verify the previewed fields are cleared. | |
| 3497 EXPECT_TRUE(lastname.value().isEmpty()); | |
| 3498 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | |
| 3499 EXPECT_FALSE(lastname.isAutofilled()); | |
| 3500 EXPECT_TRUE(email.value().isEmpty()); | |
| 3501 EXPECT_TRUE(email.suggestedValue().isEmpty()); | |
| 3502 EXPECT_FALSE(email.isAutofilled()); | |
| 3503 EXPECT_TRUE(email2.value().isEmpty()); | |
| 3504 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | |
| 3505 EXPECT_FALSE(email2.isAutofilled()); | |
| 3506 EXPECT_TRUE(phone.value().isEmpty()); | |
| 3507 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | |
| 3508 EXPECT_FALSE(phone.isAutofilled()); | |
| 3509 } | 3777 } |
| 3510 | 3778 |
| 3511 // Autofill's "Clear Form" should clear only autofilled fields | 3779 // Autofill's "Clear Form" should clear only autofilled fields |
| 3512 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { | 3780 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { |
| 3513 // Load the form. | 3781 TestClearOnlyAutofilledFields( |
| 3514 LoadHTML( | |
| 3515 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3782 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3516 " <INPUT type='text' id='firstname' value='Wyatt'/>" | 3783 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3517 " <INPUT type='text' id='lastname' value='Earp'/>" | 3784 " <INPUT type='text' id='lastname' value='Earp'/>" |
| 3518 " <INPUT type='email' id='email' value='wyatt@earp.com'/>" | 3785 " <INPUT type='email' id='email' value='wyatt@earp.com'/>" |
| 3519 " <INPUT type='tel' id='phone' value='650-777-9999'/>" | 3786 " <INPUT type='tel' id='phone' value='650-777-9999'/>" |
| 3520 " <INPUT type='submit' value='Send'/>" | 3787 " <INPUT type='submit' value='Send'/>" |
| 3521 "</FORM>"); | 3788 "</FORM>"); |
| 3789 } |
| 3522 | 3790 |
| 3523 WebFrame* web_frame = GetMainFrame(); | 3791 TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) { |
| 3524 ASSERT_NE(nullptr, web_frame); | 3792 TestClearOnlyAutofilledFields( |
| 3525 | 3793 "<INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3526 FormCache form_cache; | 3794 "<INPUT type='text' id='lastname' value='Earp'/>" |
| 3527 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3795 "<INPUT type='email' id='email' value='wyatt@earp.com'/>" |
| 3528 ASSERT_EQ(1U, forms.size()); | 3796 "<INPUT type='tel' id='phone' value='650-777-9999'/>" |
| 3529 | 3797 "<INPUT type='submit' value='Send'/>"); |
| 3530 // Set the autofilled attribute. | |
| 3531 WebInputElement firstname = GetInputElementById("firstname"); | |
| 3532 firstname.setAutofilled(false); | |
| 3533 WebInputElement lastname = GetInputElementById("lastname"); | |
| 3534 lastname.setAutofilled(true); | |
| 3535 WebInputElement email = GetInputElementById("email"); | |
| 3536 email.setAutofilled(true); | |
| 3537 WebInputElement phone = GetInputElementById("phone"); | |
| 3538 phone.setAutofilled(true); | |
| 3539 | |
| 3540 // Clear the fields. | |
| 3541 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | |
| 3542 | |
| 3543 // Verify only autofilled fields are cleared. | |
| 3544 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | |
| 3545 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | |
| 3546 EXPECT_FALSE(firstname.isAutofilled()); | |
| 3547 EXPECT_TRUE(lastname.value().isEmpty()); | |
| 3548 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | |
| 3549 EXPECT_FALSE(lastname.isAutofilled()); | |
| 3550 EXPECT_TRUE(email.value().isEmpty()); | |
| 3551 EXPECT_TRUE(email.suggestedValue().isEmpty()); | |
| 3552 EXPECT_FALSE(email.isAutofilled()); | |
| 3553 EXPECT_TRUE(phone.value().isEmpty()); | |
| 3554 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | |
| 3555 EXPECT_FALSE(phone.isAutofilled()); | |
| 3556 } | 3798 } |
| 3557 | 3799 |
| 3558 // If we have multiple labels per id, the labels concatenated into label string. | 3800 // If we have multiple labels per id, the labels concatenated into label string. |
| 3559 TEST_F(FormAutofillTest, MultipleLabelsPerElement) { | 3801 TEST_F(FormAutofillTest, MultipleLabelsPerElement) { |
| 3560 std::vector<base::string16> labels, names, values; | 3802 std::vector<base::string16> labels, names, values; |
| 3561 | 3803 |
| 3562 labels.push_back(ASCIIToUTF16("First Name:")); | 3804 labels.push_back(ASCIIToUTF16("First Name:")); |
| 3563 names.push_back(ASCIIToUTF16("firstname")); | 3805 names.push_back(ASCIIToUTF16("firstname")); |
| 3564 values.push_back(ASCIIToUTF16("John")); | 3806 values.push_back(ASCIIToUTF16("John")); |
| 3565 | 3807 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3587 labels, names, values); | 3829 labels, names, values); |
| 3588 } | 3830 } |
| 3589 | 3831 |
| 3590 TEST_F(FormAutofillTest, ClickElement) { | 3832 TEST_F(FormAutofillTest, ClickElement) { |
| 3591 LoadHTML("<BUTTON id='link'>Button</BUTTON>" | 3833 LoadHTML("<BUTTON id='link'>Button</BUTTON>" |
| 3592 "<BUTTON name='button'>Button</BUTTON>"); | 3834 "<BUTTON name='button'>Button</BUTTON>"); |
| 3593 WebFrame* frame = GetMainFrame(); | 3835 WebFrame* frame = GetMainFrame(); |
| 3594 ASSERT_NE(nullptr, frame); | 3836 ASSERT_NE(nullptr, frame); |
| 3595 | 3837 |
| 3596 // Successful retrieval by id. | 3838 // Successful retrieval by id. |
| 3597 autofill::WebElementDescriptor clicker; | 3839 WebElementDescriptor clicker; |
| 3598 clicker.retrieval_method = autofill::WebElementDescriptor::ID; | 3840 clicker.retrieval_method = WebElementDescriptor::ID; |
| 3599 clicker.descriptor = "link"; | 3841 clicker.descriptor = "link"; |
| 3600 EXPECT_TRUE(ClickElement(frame->document(), clicker)); | 3842 EXPECT_TRUE(ClickElement(frame->document(), clicker)); |
| 3601 | 3843 |
| 3602 // Successful retrieval by css selector. | 3844 // Successful retrieval by css selector. |
| 3603 clicker.retrieval_method = autofill::WebElementDescriptor::CSS_SELECTOR; | 3845 clicker.retrieval_method = WebElementDescriptor::CSS_SELECTOR; |
| 3604 clicker.descriptor = "button[name='button']"; | 3846 clicker.descriptor = "button[name='button']"; |
| 3605 EXPECT_TRUE(ClickElement(frame->document(), clicker)); | 3847 EXPECT_TRUE(ClickElement(frame->document(), clicker)); |
| 3606 | 3848 |
| 3607 // Unsuccessful retrieval due to invalid CSS selector. | 3849 // Unsuccessful retrieval due to invalid CSS selector. |
| 3608 clicker.descriptor = "^*&"; | 3850 clicker.descriptor = "^*&"; |
| 3609 EXPECT_FALSE(ClickElement(frame->document(), clicker)); | 3851 EXPECT_FALSE(ClickElement(frame->document(), clicker)); |
| 3610 | 3852 |
| 3611 // Unsuccessful retrieval because element does not exist. | 3853 // Unsuccessful retrieval because element does not exist. |
| 3612 clicker.descriptor = "#junk"; | 3854 clicker.descriptor = "#junk"; |
| 3613 EXPECT_FALSE(ClickElement(frame->document(), clicker)); | 3855 EXPECT_FALSE(ClickElement(frame->document(), clicker)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3634 select_element.setValue(WebString::fromUTF8("AL")); | 3876 select_element.setValue(WebString::fromUTF8("AL")); |
| 3635 | 3877 |
| 3636 WebVector<WebFormElement> forms; | 3878 WebVector<WebFormElement> forms; |
| 3637 frame->document().forms(forms); | 3879 frame->document().forms(forms); |
| 3638 ASSERT_EQ(1U, forms.size()); | 3880 ASSERT_EQ(1U, forms.size()); |
| 3639 | 3881 |
| 3640 FormData form; | 3882 FormData form; |
| 3641 | 3883 |
| 3642 // Extract the country select-one value as text. | 3884 // Extract the country select-one value as text. |
| 3643 EXPECT_TRUE(WebFormElementToFormData( | 3885 EXPECT_TRUE(WebFormElementToFormData( |
| 3644 forms[0], WebFormControlElement(), autofill::REQUIRE_NONE, | 3886 forms[0], WebFormControlElement(), REQUIRE_NONE, |
| 3645 static_cast<autofill::ExtractMask>( | 3887 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), |
| 3646 autofill::EXTRACT_VALUE | autofill::EXTRACT_OPTION_TEXT), | 3888 &form, nullptr)); |
| 3647 &form, NULL)); | |
| 3648 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3889 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 3649 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3890 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 3650 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3891 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 3651 | 3892 |
| 3652 const std::vector<FormFieldData>& fields = form.fields; | 3893 const std::vector<FormFieldData>& fields = form.fields; |
| 3653 ASSERT_EQ(3U, fields.size()); | 3894 ASSERT_EQ(3U, fields.size()); |
| 3654 | 3895 |
| 3655 FormFieldData expected; | 3896 FormFieldData expected; |
| 3656 | 3897 |
| 3657 expected.name = ASCIIToUTF16("firstname"); | 3898 expected.name = ASCIIToUTF16("firstname"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3669 expected.name = ASCIIToUTF16("country"); | 3910 expected.name = ASCIIToUTF16("country"); |
| 3670 expected.value = ASCIIToUTF16("Albania"); | 3911 expected.value = ASCIIToUTF16("Albania"); |
| 3671 expected.form_control_type = "select-one"; | 3912 expected.form_control_type = "select-one"; |
| 3672 expected.max_length = 0; | 3913 expected.max_length = 0; |
| 3673 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3914 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 3674 | 3915 |
| 3675 form.fields.clear(); | 3916 form.fields.clear(); |
| 3676 // Extract the country select-one value as value. | 3917 // Extract the country select-one value as value. |
| 3677 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 3918 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 3678 WebFormControlElement(), | 3919 WebFormControlElement(), |
| 3679 autofill::REQUIRE_NONE, | 3920 REQUIRE_NONE, |
| 3680 autofill::EXTRACT_VALUE, | 3921 EXTRACT_VALUE, |
| 3681 &form, | 3922 &form, |
| 3682 NULL)); | 3923 nullptr)); |
| 3683 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3924 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 3684 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3925 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 3685 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3926 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 3686 | 3927 |
| 3687 ASSERT_EQ(3U, fields.size()); | 3928 ASSERT_EQ(3U, fields.size()); |
| 3688 | 3929 |
| 3689 expected.name = ASCIIToUTF16("firstname"); | 3930 expected.name = ASCIIToUTF16("firstname"); |
| 3690 expected.value = ASCIIToUTF16("John"); | 3931 expected.value = ASCIIToUTF16("John"); |
| 3691 expected.form_control_type = "text"; | 3932 expected.form_control_type = "text"; |
| 3692 expected.max_length = WebInputElement::defaultMaxLength(); | 3933 expected.max_length = WebInputElement::defaultMaxLength(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3723 " </FIELDSET>" | 3964 " </FIELDSET>" |
| 3724 " <FIELDSET>" | 3965 " <FIELDSET>" |
| 3725 " <LABEL for='email'>Email:</LABEL>" | 3966 " <LABEL for='email'>Email:</LABEL>" |
| 3726 " <INPUT type='text' id='email' value='john@example.com'/>" | 3967 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 3727 " </FIELDSET>" | 3968 " </FIELDSET>" |
| 3728 "</DIV>"); | 3969 "</DIV>"); |
| 3729 | 3970 |
| 3730 WebFrame* frame = GetMainFrame(); | 3971 WebFrame* frame = GetMainFrame(); |
| 3731 ASSERT_NE(nullptr, frame); | 3972 ASSERT_NE(nullptr, frame); |
| 3732 | 3973 |
| 3733 control_elements = FormCache::GetUnownedAutofillableFormFieldElements( | 3974 control_elements = GetUnownedAutofillableFormFieldElements( |
| 3734 frame->document().all(), &fieldsets); | 3975 frame->document().all(), &fieldsets); |
| 3735 ASSERT_EQ(3U, control_elements.size()); | 3976 ASSERT_EQ(3U, control_elements.size()); |
| 3736 ASSERT_EQ(2U, fieldsets.size()); | 3977 ASSERT_EQ(2U, fieldsets.size()); |
| 3737 | 3978 |
| 3738 FormData form; | 3979 FormData form; |
| 3739 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( | 3980 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( |
| 3740 fieldsets, control_elements, dummy_origin, extract_mask, &form)); | 3981 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, |
| 3982 extract_mask, &form, nullptr)); |
| 3741 | 3983 |
| 3742 EXPECT_TRUE(form.name.empty()); | 3984 EXPECT_TRUE(form.name.empty()); |
| 3743 EXPECT_EQ(dummy_origin, form.origin); | 3985 EXPECT_EQ(dummy_origin, form.origin); |
| 3744 EXPECT_FALSE(form.action.is_valid()); | 3986 EXPECT_FALSE(form.action.is_valid()); |
| 3745 | 3987 |
| 3746 const std::vector<FormFieldData>& fields = form.fields; | 3988 const std::vector<FormFieldData>& fields = form.fields; |
| 3747 ASSERT_EQ(3U, fields.size()); | 3989 ASSERT_EQ(3U, fields.size()); |
| 3748 | 3990 |
| 3749 FormFieldData expected; | 3991 FormFieldData expected; |
| 3750 expected.form_control_type = "text"; | 3992 expected.form_control_type = "text"; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3782 " <INPUT type='text' id='firstname' value='John'/>" | 4024 " <INPUT type='text' id='firstname' value='John'/>" |
| 3783 " <INPUT type='text' id='lastname' value='Smith'/>" | 4025 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 3784 " <LABEL for='email'>Email:</LABEL>" | 4026 " <LABEL for='email'>Email:</LABEL>" |
| 3785 " </FIELDSET>" | 4027 " </FIELDSET>" |
| 3786 " <INPUT type='text' id='email' value='john@example.com'/>" | 4028 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 3787 "</DIV>"); | 4029 "</DIV>"); |
| 3788 | 4030 |
| 3789 WebFrame* frame = GetMainFrame(); | 4031 WebFrame* frame = GetMainFrame(); |
| 3790 ASSERT_NE(nullptr, frame); | 4032 ASSERT_NE(nullptr, frame); |
| 3791 | 4033 |
| 3792 control_elements = FormCache::GetUnownedAutofillableFormFieldElements( | 4034 control_elements = GetUnownedAutofillableFormFieldElements( |
| 3793 frame->document().all(), &fieldsets); | 4035 frame->document().all(), &fieldsets); |
| 3794 ASSERT_EQ(3U, control_elements.size()); | 4036 ASSERT_EQ(3U, control_elements.size()); |
| 3795 ASSERT_EQ(1U, fieldsets.size()); | 4037 ASSERT_EQ(1U, fieldsets.size()); |
| 3796 | 4038 |
| 3797 FormData form; | 4039 FormData form; |
| 3798 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( | 4040 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( |
| 3799 fieldsets, control_elements, dummy_origin, extract_mask, &form)); | 4041 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, |
| 4042 extract_mask, &form, nullptr)); |
| 3800 | 4043 |
| 3801 EXPECT_TRUE(form.name.empty()); | 4044 EXPECT_TRUE(form.name.empty()); |
| 3802 EXPECT_EQ(dummy_origin, form.origin); | 4045 EXPECT_EQ(dummy_origin, form.origin); |
| 3803 EXPECT_FALSE(form.action.is_valid()); | 4046 EXPECT_FALSE(form.action.is_valid()); |
| 3804 | 4047 |
| 3805 const std::vector<FormFieldData>& fields = form.fields; | 4048 const std::vector<FormFieldData>& fields = form.fields; |
| 3806 ASSERT_EQ(3U, fields.size()); | 4049 ASSERT_EQ(3U, fields.size()); |
| 3807 | 4050 |
| 3808 FormFieldData expected; | 4051 FormFieldData expected; |
| 3809 expected.form_control_type = "text"; | 4052 expected.form_control_type = "text"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3831 | 4074 |
| 3832 const ExtractMask extract_mask = | 4075 const ExtractMask extract_mask = |
| 3833 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); | 4076 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); |
| 3834 const GURL dummy_origin("http://www.example.com"); | 4077 const GURL dummy_origin("http://www.example.com"); |
| 3835 | 4078 |
| 3836 LoadHTML(kFormHtml); | 4079 LoadHTML(kFormHtml); |
| 3837 | 4080 |
| 3838 WebFrame* frame = GetMainFrame(); | 4081 WebFrame* frame = GetMainFrame(); |
| 3839 ASSERT_NE(nullptr, frame); | 4082 ASSERT_NE(nullptr, frame); |
| 3840 | 4083 |
| 3841 control_elements = FormCache::GetUnownedAutofillableFormFieldElements( | 4084 control_elements = GetUnownedAutofillableFormFieldElements( |
| 3842 frame->document().all(), &fieldsets); | 4085 frame->document().all(), &fieldsets); |
| 3843 ASSERT_EQ(0U, control_elements.size()); | 4086 ASSERT_TRUE(control_elements.empty()); |
| 3844 ASSERT_EQ(0U, fieldsets.size()); | 4087 ASSERT_TRUE(fieldsets.empty()); |
| 3845 | 4088 |
| 3846 FormData form; | 4089 FormData form; |
| 3847 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( | 4090 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( |
| 3848 fieldsets, control_elements, dummy_origin, extract_mask, &form)); | 4091 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, |
| 4092 extract_mask, &form, nullptr)); |
| 3849 } | 4093 } |
| 3850 | 4094 |
| 3851 } // namespace autofill | 4095 } // namespace autofill |
| OLD | NEW |