Chromium Code Reviews| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 " </SELECT>" | 94 " </SELECT>" |
| 95 " <SELECT id='select-unchanged'>" | 95 " <SELECT id='select-unchanged'>" |
| 96 " <OPTION value='CA' selected>California</OPTION>" | 96 " <OPTION value='CA' selected>California</OPTION>" |
| 97 " <OPTION value='TX'>Texas</OPTION>" | 97 " <OPTION value='TX'>Texas</OPTION>" |
| 98 " </SELECT>" | 98 " </SELECT>" |
| 99 " <TEXTAREA id='textarea'></TEXTAREA>" | 99 " <TEXTAREA id='textarea'></TEXTAREA>" |
| 100 " <TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" | 100 " <TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" |
| 101 " <INPUT type='submit' name='reply-send' value='Send'/>" | 101 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 102 "</FORM>"; | 102 "</FORM>"; |
| 103 | 103 |
| 104 // This constant uses a mixed-case title tag to be sure that the title match is | |
| 105 // not case-sensitive. Other tests in this file use an all-lower title tag. | |
| 104 const char kUnownedFormHtml[] = | 106 const char kUnownedFormHtml[] = |
| 105 "<HEAD><TITLE>enter shipping info</TITLE></HEAD>" | 107 "<HEAD><TITLE>Enter Shipping Info</TITLE></HEAD>" |
| 106 "<INPUT type='text' id='firstname'/>" | 108 "<INPUT type='text' id='firstname'/>" |
| 107 "<INPUT type='text' id='lastname'/>" | 109 "<INPUT type='text' id='lastname'/>" |
| 108 "<INPUT type='hidden' id='imhidden'/>" | 110 "<INPUT type='hidden' id='imhidden'/>" |
| 109 "<INPUT type='text' id='notempty' value='Hi'/>" | 111 "<INPUT type='text' id='notempty' value='Hi'/>" |
| 110 "<INPUT type='text' autocomplete='off' id='noautocomplete'/>" | 112 "<INPUT type='text' autocomplete='off' id='noautocomplete'/>" |
| 111 "<INPUT type='text' disabled='disabled' id='notenabled'/>" | 113 "<INPUT type='text' disabled='disabled' id='notenabled'/>" |
| 112 "<INPUT type='text' readonly id='readonly'/>" | 114 "<INPUT type='text' readonly id='readonly'/>" |
| 113 "<INPUT type='text' style='visibility: hidden'" | 115 "<INPUT type='text' style='visibility: hidden'" |
| 114 " id='invisible'/>" | 116 " id='invisible'/>" |
| 115 "<INPUT type='text' style='display: none' id='displaynone'/>" | 117 "<INPUT type='text' style='display: none' id='displaynone'/>" |
| 116 "<INPUT type='month' id='month'/>" | 118 "<INPUT type='month' id='month'/>" |
| 117 "<INPUT type='month' id='month-nonempty' value='2011-12'/>" | 119 "<INPUT type='month' id='month-nonempty' value='2011-12'/>" |
| 118 "<SELECT id='select'>" | 120 "<SELECT id='select'>" |
| 119 " <OPTION></OPTION>" | 121 " <OPTION></OPTION>" |
| 120 " <OPTION value='CA'>California</OPTION>" | 122 " <OPTION value='CA'>California</OPTION>" |
| 121 " <OPTION value='TX'>Texas</OPTION>" | 123 " <OPTION value='TX'>Texas</OPTION>" |
| 122 "</SELECT>" | 124 "</SELECT>" |
| 123 "<SELECT id='select-nonempty'>" | 125 "<SELECT id='select-nonempty'>" |
| 124 " <OPTION value='CA' selected>California</OPTION>" | 126 " <OPTION value='CA' selected>California</OPTION>" |
| 125 " <OPTION value='TX'>Texas</OPTION>" | 127 " <OPTION value='TX'>Texas</OPTION>" |
| 126 "</SELECT>" | 128 "</SELECT>" |
| 127 "<SELECT id='select-unchanged'>" | 129 "<SELECT id='select-unchanged'>" |
| 128 " <OPTION value='CA' selected>California</OPTION>" | 130 " <OPTION value='CA' selected>California</OPTION>" |
| 129 " <OPTION value='TX'>Texas</OPTION>" | 131 " <OPTION value='TX'>Texas</OPTION>" |
| 130 "</SELECT>" | 132 "</SELECT>" |
| 131 "<TEXTAREA id='textarea'></TEXTAREA>" | 133 "<TEXTAREA id='textarea'></TEXTAREA>" |
| 132 "<TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" | 134 "<TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" |
| 133 "<INPUT type='submit' name='reply-send' value='Send'/>"; | 135 "<INPUT type='submit' name='reply-send' value='Send'/>"; |
| 134 | 136 |
| 137 // This constant has no title tag, and should be passed to | |
| 138 // LoadHTMLWithURLOverride to test the detection of unowned forms by URL. | |
| 139 const char kUnownedUntitledFormHtml[] = | |
| 140 "<INPUT type='text' id='firstname'/>" | |
| 141 "<INPUT type='text' id='lastname'/>" | |
| 142 "<INPUT type='hidden' id='imhidden'/>" | |
| 143 "<INPUT type='text' id='notempty' value='Hi'/>" | |
| 144 "<INPUT type='text' autocomplete='off' id='noautocomplete'/>" | |
| 145 "<INPUT type='text' disabled='disabled' id='notenabled'/>" | |
| 146 "<INPUT type='text' readonly id='readonly'/>" | |
| 147 "<INPUT type='text' style='visibility: hidden'" | |
| 148 " id='invisible'/>" | |
| 149 "<INPUT type='text' style='display: none' id='displaynone'/>" | |
| 150 "<INPUT type='month' id='month'/>" | |
| 151 "<INPUT type='month' id='month-nonempty' value='2011-12'/>" | |
| 152 "<SELECT id='select'>" | |
| 153 " <OPTION></OPTION>" | |
| 154 " <OPTION value='CA'>California</OPTION>" | |
| 155 " <OPTION value='TX'>Texas</OPTION>" | |
| 156 "</SELECT>" | |
| 157 "<SELECT id='select-nonempty'>" | |
| 158 " <OPTION value='CA' selected>California</OPTION>" | |
| 159 " <OPTION value='TX'>Texas</OPTION>" | |
| 160 "</SELECT>" | |
| 161 "<SELECT id='select-unchanged'>" | |
| 162 " <OPTION value='CA' selected>California</OPTION>" | |
| 163 " <OPTION value='TX'>Texas</OPTION>" | |
| 164 "</SELECT>" | |
| 165 "<TEXTAREA id='textarea'></TEXTAREA>" | |
| 166 "<TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" | |
| 167 "<INPUT type='submit' name='reply-send' value='Send'/>"; | |
| 168 | |
| 169 // This constant does not have a title tag, but should match an unowned form | |
| 170 // anyway because it is not English. | |
| 171 const char kUnownedNonEnglishFormHtml[] = | |
| 172 "<HTML LANG='fr'>" | |
| 173 "<INPUT type='text' id='firstname'/>" | |
| 174 "<INPUT type='text' id='lastname'/>" | |
| 175 "<INPUT type='hidden' id='imhidden'/>" | |
| 176 "<INPUT type='text' id='notempty' value='Hi'/>" | |
| 177 "<INPUT type='text' autocomplete='off' id='noautocomplete'/>" | |
| 178 "<INPUT type='text' disabled='disabled' id='notenabled'/>" | |
| 179 "<INPUT type='text' readonly id='readonly'/>" | |
| 180 "<INPUT type='text' style='visibility: hidden'" | |
| 181 " id='invisible'/>" | |
| 182 "<INPUT type='text' style='display: none' id='displaynone'/>" | |
| 183 "<INPUT type='month' id='month'/>" | |
| 184 "<INPUT type='month' id='month-nonempty' value='2011-12'/>" | |
| 185 "<SELECT id='select'>" | |
| 186 " <OPTION></OPTION>" | |
| 187 " <OPTION value='CA'>California</OPTION>" | |
| 188 " <OPTION value='TX'>Texas</OPTION>" | |
| 189 "</SELECT>" | |
| 190 "<SELECT id='select-nonempty'>" | |
| 191 " <OPTION value='CA' selected>California</OPTION>" | |
| 192 " <OPTION value='TX'>Texas</OPTION>" | |
| 193 "</SELECT>" | |
| 194 "<SELECT id='select-unchanged'>" | |
| 195 " <OPTION value='CA' selected>California</OPTION>" | |
| 196 " <OPTION value='TX'>Texas</OPTION>" | |
| 197 "</SELECT>" | |
| 198 "<TEXTAREA id='textarea'></TEXTAREA>" | |
| 199 "<TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" | |
| 200 "<INPUT type='submit' name='reply-send' value='Send'/>" | |
| 201 "</HTML>"; | |
| 202 | |
|
Evan Stade
2015/12/11 23:44:45
remove extra newline
Joe Mason
2015/12/14 16:07:17
Done.
| |
| 203 | |
| 135 std::string RetrievalMethodToString( | 204 std::string RetrievalMethodToString( |
| 136 const WebElementDescriptor::RetrievalMethod& method) { | 205 const WebElementDescriptor::RetrievalMethod& method) { |
| 137 switch (method) { | 206 switch (method) { |
| 138 case WebElementDescriptor::CSS_SELECTOR: | 207 case WebElementDescriptor::CSS_SELECTOR: |
| 139 return "CSS_SELECTOR"; | 208 return "CSS_SELECTOR"; |
| 140 case WebElementDescriptor::ID: | 209 case WebElementDescriptor::ID: |
| 141 return "ID"; | 210 return "ID"; |
| 142 case WebElementDescriptor::NONE: | 211 case WebElementDescriptor::NONE: |
| 143 return "NONE"; | 212 return "NONE"; |
| 144 } | 213 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 } | 321 } |
| 253 | 322 |
| 254 typedef void (*FillFormFunction)(const FormData& form, | 323 typedef void (*FillFormFunction)(const FormData& form, |
| 255 const WebFormControlElement& element); | 324 const WebFormControlElement& element); |
| 256 | 325 |
| 257 typedef WebString (*GetValueFunction)(WebFormControlElement element); | 326 typedef WebString (*GetValueFunction)(WebFormControlElement element); |
| 258 | 327 |
| 259 // Test FormFillxxx functions. | 328 // Test FormFillxxx functions. |
| 260 void TestFormFillFunctions(const char* html, | 329 void TestFormFillFunctions(const char* html, |
| 261 bool unowned, | 330 bool unowned, |
| 331 const char* url_override, | |
| 262 const AutofillFieldCase* field_cases, | 332 const AutofillFieldCase* field_cases, |
| 263 size_t number_of_field_cases, | 333 size_t number_of_field_cases, |
| 264 FillFormFunction fill_form_function, | 334 FillFormFunction fill_form_function, |
| 265 GetValueFunction get_value_function) { | 335 GetValueFunction get_value_function) { |
| 266 LoadHTML(html); | 336 if (url_override) |
| 337 LoadHTMLWithUrlOverride(html, url_override); | |
| 338 else | |
| 339 LoadHTML(html); | |
| 267 | 340 |
| 268 WebFrame* web_frame = GetMainFrame(); | 341 WebFrame* web_frame = GetMainFrame(); |
| 269 ASSERT_NE(nullptr, web_frame); | 342 ASSERT_NE(nullptr, web_frame); |
| 270 | 343 |
| 271 FormCache form_cache(*web_frame); | 344 FormCache form_cache(*web_frame); |
| 272 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 345 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 273 ASSERT_EQ(1U, forms.size()); | 346 ASSERT_EQ(1U, forms.size()); |
| 274 | 347 |
| 275 // Get the input element we want to find. | 348 // Get the input element we want to find. |
| 276 WebInputElement input_element = GetInputElementById("firstname"); | 349 WebInputElement input_element = GetInputElementById("firstname"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 WebFormControlElement GetFormControlElementById(const WebString& id) { | 418 WebFormControlElement GetFormControlElementById(const WebString& id) { |
| 346 return GetMainFrame()->document().getElementById( | 419 return GetMainFrame()->document().getElementById( |
| 347 id).to<WebFormControlElement>(); | 420 id).to<WebFormControlElement>(); |
| 348 } | 421 } |
| 349 | 422 |
| 350 WebInputElement GetInputElementById(const WebString& id) { | 423 WebInputElement GetInputElementById(const WebString& id) { |
| 351 return GetMainFrame()->document().getElementById( | 424 return GetMainFrame()->document().getElementById( |
| 352 id).to<WebInputElement>(); | 425 id).to<WebInputElement>(); |
| 353 } | 426 } |
| 354 | 427 |
| 355 void TestFillForm(const char* html, bool unowned) { | 428 void TestFillForm(const char* html, bool unowned, const char* url_override) { |
| 356 static const AutofillFieldCase field_cases[] = { | 429 static const AutofillFieldCase field_cases[] = { |
| 357 // fields: form_control_type, name, initial_value, autocomplete_attribute, | 430 // fields: form_control_type, name, initial_value, autocomplete_attribute, |
| 358 // should_be_autofilled, autofill_value, expected_value | 431 // should_be_autofilled, autofill_value, expected_value |
| 359 | 432 |
| 360 // Regular empty fields (firstname & lastname) should be autofilled. | 433 // Regular empty fields (firstname & lastname) should be autofilled. |
| 361 {"text", | 434 {"text", |
| 362 "firstname", | 435 "firstname", |
| 363 "", | 436 "", |
| 364 "", | 437 "", |
| 365 true, | 438 true, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 "some multi-\nline value"}, | 479 "some multi-\nline value"}, |
| 407 // Non-empty textarea elements should not be autofilled. | 480 // Non-empty textarea elements should not be autofilled. |
| 408 {"textarea", | 481 {"textarea", |
| 409 "textarea-nonempty", | 482 "textarea-nonempty", |
| 410 "Go\naway!", | 483 "Go\naway!", |
| 411 "", | 484 "", |
| 412 false, | 485 false, |
| 413 "some multi-\nline value", | 486 "some multi-\nline value", |
| 414 "Go\naway!"}, | 487 "Go\naway!"}, |
| 415 }; | 488 }; |
| 416 TestFormFillFunctions(html, unowned, field_cases, arraysize(field_cases), | 489 TestFormFillFunctions(html, unowned, url_override, |
| 490 field_cases, arraysize(field_cases), | |
| 417 FillForm, &GetValueWrapper); | 491 FillForm, &GetValueWrapper); |
| 418 // Verify preview selection. | 492 // Verify preview selection. |
| 419 WebInputElement firstname = GetInputElementById("firstname"); | 493 WebInputElement firstname = GetInputElementById("firstname"); |
| 420 EXPECT_EQ(16, firstname.selectionStart()); | 494 EXPECT_EQ(16, firstname.selectionStart()); |
| 421 EXPECT_EQ(16, firstname.selectionEnd()); | 495 EXPECT_EQ(16, firstname.selectionEnd()); |
| 422 } | 496 } |
| 423 | 497 |
| 424 void TestPreviewForm(const char* html, bool unowned) { | 498 void TestPreviewForm(const char* html, bool unowned, |
| 499 const char* url_override) { | |
| 425 static const AutofillFieldCase field_cases[] = { | 500 static const AutofillFieldCase field_cases[] = { |
| 426 // Normal empty fields should be previewed. | 501 // Normal empty fields should be previewed. |
| 427 {"text", | 502 {"text", |
| 428 "firstname", | 503 "firstname", |
| 429 "", | 504 "", |
| 430 "", | 505 "", |
| 431 true, | 506 true, |
| 432 "suggested firstname", | 507 "suggested firstname", |
| 433 "suggested firstname"}, | 508 "suggested firstname"}, |
| 434 {"text", | 509 {"text", |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 "suggested multi-\nline value"}, | 553 "suggested multi-\nline value"}, |
| 479 // Nonempty textarea elements should not be previewed. | 554 // Nonempty textarea elements should not be previewed. |
| 480 {"textarea", | 555 {"textarea", |
| 481 "textarea-nonempty", | 556 "textarea-nonempty", |
| 482 "Go\naway!", | 557 "Go\naway!", |
| 483 "", | 558 "", |
| 484 false, | 559 false, |
| 485 "suggested multi-\nline value", | 560 "suggested multi-\nline value", |
| 486 ""}, | 561 ""}, |
| 487 }; | 562 }; |
| 488 TestFormFillFunctions(html, unowned, field_cases, arraysize(field_cases), | 563 TestFormFillFunctions(html, unowned, url_override, |
| 564 field_cases, arraysize(field_cases), | |
| 489 &PreviewForm, &GetSuggestedValueWrapper); | 565 &PreviewForm, &GetSuggestedValueWrapper); |
| 490 | 566 |
| 491 // Verify preview selection. | 567 // Verify preview selection. |
| 492 WebInputElement firstname = GetInputElementById("firstname"); | 568 WebInputElement firstname = GetInputElementById("firstname"); |
| 493 EXPECT_EQ(0, firstname.selectionStart()); | 569 EXPECT_EQ(0, firstname.selectionStart()); |
| 494 EXPECT_EQ(19, firstname.selectionEnd()); | 570 EXPECT_EQ(19, firstname.selectionEnd()); |
| 495 } | 571 } |
| 496 | 572 |
| 573 void TestUnmatchedUnownedForm(const char* html, const char* url_override) { | |
| 574 if (url_override) | |
| 575 LoadHTMLWithUrlOverride(html, url_override); | |
| 576 else | |
| 577 LoadHTML(html); | |
| 578 | |
| 579 WebFrame* web_frame = GetMainFrame(); | |
| 580 ASSERT_NE(nullptr, web_frame); | |
| 581 | |
| 582 FormCache form_cache(*web_frame); | |
| 583 std::vector<FormData> forms = form_cache.ExtractNewForms(); | |
| 584 ASSERT_EQ(0U, forms.size()); | |
| 585 } | |
| 586 | |
| 497 void TestFindFormForInputElement(const char* html, bool unowned) { | 587 void TestFindFormForInputElement(const char* html, bool unowned) { |
| 498 LoadHTML(html); | 588 LoadHTML(html); |
| 499 WebFrame* web_frame = GetMainFrame(); | 589 WebFrame* web_frame = GetMainFrame(); |
| 500 ASSERT_NE(nullptr, web_frame); | 590 ASSERT_NE(nullptr, web_frame); |
| 501 | 591 |
| 502 FormCache form_cache(*web_frame); | 592 FormCache form_cache(*web_frame); |
| 503 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 593 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 504 ASSERT_EQ(1U, forms.size()); | 594 ASSERT_EQ(1U, forms.size()); |
| 505 | 595 |
| 506 // Get the input element we want to find. | 596 // Get the input element we want to find. |
| (...skipping 1927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2434 "123 Fantasy Ln. " | 2524 "123 Fantasy Ln. " |
| 2435 "Apt. 42" | 2525 "Apt. 42" |
| 2436 "</TEXTAREA>" | 2526 "</TEXTAREA>" |
| 2437 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2527 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2438 "</FORM>", | 2528 "</FORM>", |
| 2439 false); | 2529 false); |
| 2440 } | 2530 } |
| 2441 | 2531 |
| 2442 TEST_F(FormAutofillTest, FindFormForTextAreaElementForUnownedForm) { | 2532 TEST_F(FormAutofillTest, FindFormForTextAreaElementForUnownedForm) { |
| 2443 TestFindFormForTextAreaElement( | 2533 TestFindFormForTextAreaElement( |
| 2444 "<HEAD><TITLE>delivery address</TITLE></HEAD>" | 2534 "<HEAD><TITLE>delivery address</TITLE></HEAD>" |
|
Evan Stade
2015/12/11 23:44:45
add test that would have caught this regression? (
Joe Mason
2015/12/14 16:07:17
I already added a mixed-case title to kUnownedForm
| |
| 2445 "<INPUT type='text' id='firstname' value='John'/>" | 2535 "<INPUT type='text' id='firstname' value='John'/>" |
| 2446 "<INPUT type='text' id='lastname' value='Smith'/>" | 2536 "<INPUT type='text' id='lastname' value='Smith'/>" |
| 2447 "<INPUT type='text' id='email' value='john@example.com'" | 2537 "<INPUT type='text' id='email' value='john@example.com'" |
| 2448 "autocomplete='off' />" | 2538 "autocomplete='off' />" |
| 2449 "<TEXTAREA id='street-address'>" | 2539 "<TEXTAREA id='street-address'>" |
| 2450 "123 Fantasy Ln. " | 2540 "123 Fantasy Ln. " |
| 2451 "Apt. 42" | 2541 "Apt. 42" |
| 2452 "</TEXTAREA>" | 2542 "</TEXTAREA>" |
| 2453 "<INPUT type='submit' name='reply-send' value='Send'/>", | 2543 "<INPUT type='submit' name='reply-send' value='Send'/>", |
| 2454 true); | 2544 true); |
| 2455 } | 2545 } |
| 2456 | 2546 |
| 2457 // Test regular FillForm function. | 2547 // Test regular FillForm function. |
| 2458 TEST_F(FormAutofillTest, FillForm) { | 2548 TEST_F(FormAutofillTest, FillForm) { |
| 2459 TestFillForm(kFormHtml, false); | 2549 TestFillForm(kFormHtml, false, nullptr); |
| 2460 } | 2550 } |
| 2461 | 2551 |
| 2462 TEST_F(FormAutofillTest, FillFormForUnownedForm) { | 2552 TEST_F(FormAutofillTest, FillFormForUnownedForm) { |
| 2463 TestFillForm(kUnownedFormHtml, true); | 2553 TestFillForm(kUnownedFormHtml, true, nullptr); |
| 2554 } | |
| 2555 | |
| 2556 TEST_F(FormAutofillTest, FillFormForUnownedUntitledForm) { | |
| 2557 TestFillForm(kUnownedUntitledFormHtml, true, | |
| 2558 "http://example.test/checkout_flow"); | |
| 2559 } | |
| 2560 | |
| 2561 TEST_F(FormAutofillTest, FillFormForUnownedNonEnglishForm) { | |
| 2562 TestFillForm(kUnownedNonEnglishFormHtml, true, nullptr); | |
| 2464 } | 2563 } |
| 2465 | 2564 |
| 2466 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { | 2565 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { |
| 2467 static const AutofillFieldCase field_cases[] = { | 2566 static const AutofillFieldCase field_cases[] = { |
| 2468 // fields: form_control_type, name, initial_value, autocomplete_attribute, | 2567 // fields: form_control_type, name, initial_value, autocomplete_attribute, |
| 2469 // should_be_autofilled, autofill_value, expected_value | 2568 // should_be_autofilled, autofill_value, expected_value |
| 2470 | 2569 |
| 2471 // Regular empty fields (firstname & lastname) should be autofilled. | 2570 // Regular empty fields (firstname & lastname) should be autofilled. |
| 2472 {"text", | 2571 {"text", |
| 2473 "firstname", | 2572 "firstname", |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2535 "some multi-\nline value"}, | 2634 "some multi-\nline value"}, |
| 2536 // Nonempty textarea elements should be overridden. | 2635 // Nonempty textarea elements should be overridden. |
| 2537 {"textarea", | 2636 {"textarea", |
| 2538 "textarea-nonempty", | 2637 "textarea-nonempty", |
| 2539 "Go\naway!", | 2638 "Go\naway!", |
| 2540 "", | 2639 "", |
| 2541 true, | 2640 true, |
| 2542 "some multi-\nline value", | 2641 "some multi-\nline value", |
| 2543 "some multi-\nline value"}, | 2642 "some multi-\nline value"}, |
| 2544 }; | 2643 }; |
| 2545 TestFormFillFunctions(kFormHtml, false, field_cases, arraysize(field_cases), | 2644 TestFormFillFunctions(kFormHtml, false, nullptr, |
| 2645 field_cases, arraysize(field_cases), | |
| 2546 &FillFormIncludingNonFocusableElementsWrapper, | 2646 &FillFormIncludingNonFocusableElementsWrapper, |
| 2547 &GetValueWrapper); | 2647 &GetValueWrapper); |
| 2548 } | 2648 } |
| 2549 | 2649 |
| 2550 TEST_F(FormAutofillTest, PreviewForm) { | 2650 TEST_F(FormAutofillTest, PreviewForm) { |
| 2551 TestPreviewForm(kFormHtml, false); | 2651 TestPreviewForm(kFormHtml, false, nullptr); |
| 2552 } | 2652 } |
| 2553 | 2653 |
| 2554 TEST_F(FormAutofillTest, PreviewFormForUnownedForm) { | 2654 TEST_F(FormAutofillTest, PreviewFormForUnownedForm) { |
| 2555 TestPreviewForm(kUnownedFormHtml, true); | 2655 TestPreviewForm(kUnownedFormHtml, true, nullptr); |
| 2656 } | |
| 2657 | |
| 2658 TEST_F(FormAutofillTest, PreviewFormForUnownedUntitledForm) { | |
| 2659 // This test uses a mixed-case URL to be sure that the url match is not | |
| 2660 // case-sensitive. | |
| 2661 TestPreviewForm(kUnownedUntitledFormHtml, true, | |
| 2662 "http://example.test/Enter_Shipping_Address/"); | |
| 2663 } | |
| 2664 | |
| 2665 TEST_F(FormAutofillTest, PreviewFormForUnownedNonEnglishForm) { | |
| 2666 TestPreviewForm(kUnownedNonEnglishFormHtml, true, nullptr); | |
| 2667 } | |
| 2668 | |
| 2669 // Data that looks like an unowned form should NOT be matched unless an | |
| 2670 // additional indicator is present, such as title tag or url, to prevent false | |
| 2671 // positives. | |
| 2672 | |
| 2673 TEST_F(FormAutofillTest, UnmatchedFormNoURL) { | |
| 2674 TestUnmatchedUnownedForm(kUnownedUntitledFormHtml, nullptr); | |
| 2675 } | |
| 2676 | |
| 2677 TEST_F(FormAutofillTest, UnmatchedFormPathWithoutKeywords) { | |
| 2678 TestUnmatchedUnownedForm(kUnownedUntitledFormHtml, | |
| 2679 "http://example.test/path_without_keywords"); | |
| 2680 } | |
| 2681 | |
| 2682 TEST_F(FormAutofillTest, UnmatchedFormKeywordInQueryOnly) { | |
| 2683 TestUnmatchedUnownedForm(kUnownedUntitledFormHtml, | |
| 2684 "http://example.test/search?q=checkout+in+query"); | |
| 2685 } | |
| 2686 | |
| 2687 TEST_F(FormAutofillTest, UnmatchedFormTitleWithoutKeywords) { | |
| 2688 std::string wrong_title_html( | |
| 2689 "<TITLE>This title has nothing to do with autofill</TITLE>"); | |
|
Evan Stade
2015/12/11 23:44:45
please add some non-ascii test cases
Joe Mason
2015/12/14 16:07:17
Done.
| |
| 2690 wrong_title_html += kUnownedUntitledFormHtml; | |
| 2691 TestUnmatchedUnownedForm(wrong_title_html.c_str(), nullptr); | |
| 2556 } | 2692 } |
| 2557 | 2693 |
| 2558 TEST_F(FormAutofillTest, Labels) { | 2694 TEST_F(FormAutofillTest, Labels) { |
| 2559 ExpectJohnSmithLabels( | 2695 ExpectJohnSmithLabels( |
| 2560 "<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2696 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2561 " <LABEL for='firstname'> First name: </LABEL>" | 2697 " <LABEL for='firstname'> First name: </LABEL>" |
| 2562 " <INPUT type='text' id='firstname' value='John'/>" | 2698 " <INPUT type='text' id='firstname' value='John'/>" |
| 2563 " <LABEL for='lastname'> Last name: </LABEL>" | 2699 " <LABEL for='lastname'> Last name: </LABEL>" |
| 2564 " <INPUT type='text' id='lastname' value='Smith'/>" | 2700 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2565 " <LABEL for='email'> Email: </LABEL>" | 2701 " <LABEL for='email'> Email: </LABEL>" |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4240 ASSERT_NE(nullptr, web_frame); | 4376 ASSERT_NE(nullptr, web_frame); |
| 4241 | 4377 |
| 4242 FormCache form_cache(*web_frame); | 4378 FormCache form_cache(*web_frame); |
| 4243 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 4379 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 4244 EXPECT_EQ(test_case.expected_forms, forms.size()); | 4380 EXPECT_EQ(test_case.expected_forms, forms.size()); |
| 4245 } | 4381 } |
| 4246 } | 4382 } |
| 4247 | 4383 |
| 4248 } // namespace form_util | 4384 } // namespace form_util |
| 4249 } // namespace autofill | 4385 } // namespace autofill |
| OLD | NEW |