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

Side by Side Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 1671753004: [Autofill] Fill fields that have an autocomplete attributes even if not in a form. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added IPC Trait for new attribute Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_param_traits_macros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 2732 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 TestPreviewForm(kUnownedUntitledFormHtml, true, 2743 TestPreviewForm(kUnownedUntitledFormHtml, true,
2744 "http://example.test/Enter_Shipping_Address/"); 2744 "http://example.test/Enter_Shipping_Address/");
2745 } 2745 }
2746 2746
2747 TEST_F(FormAutofillTest, PreviewFormForUnownedNonEnglishForm) { 2747 TEST_F(FormAutofillTest, PreviewFormForUnownedNonEnglishForm) {
2748 TestPreviewForm(kUnownedNonEnglishFormHtml, true, nullptr); 2748 TestPreviewForm(kUnownedNonEnglishFormHtml, true, nullptr);
2749 } 2749 }
2750 2750
2751 // Data that looks like an unowned form should NOT be matched unless an 2751 // Data that looks like an unowned form should NOT be matched unless an
2752 // additional indicator is present, such as title tag or url, to prevent false 2752 // additional indicator is present, such as title tag or url, to prevent false
2753 // positives. 2753 // positives. The fields that have an autocomplete attribute should match since
2754 // there is no chance of making a prediction error.
2754 2755
2755 TEST_F(FormAutofillTest, UnmatchedFormNoURL) { 2756 TEST_F(FormAutofillTest, UnmatchedFormNoURL) {
2756 TestUnmatchedUnownedForm(kUnownedUntitledFormHtml, nullptr); 2757 TestUnmatchedUnownedForm(kUnownedUntitledFormHtml, nullptr);
2757 } 2758 }
2758 2759
2759 TEST_F(FormAutofillTest, UnmatchedFormPathWithoutKeywords) { 2760 TEST_F(FormAutofillTest, UnmatchedFormPathWithoutKeywords) {
2760 TestUnmatchedUnownedForm(kUnownedUntitledFormHtml, 2761 TestUnmatchedUnownedForm(kUnownedUntitledFormHtml,
2761 "http://example.test/path_without_keywords"); 2762 "http://example.test/path_without_keywords");
2762 } 2763 }
2763 2764
(...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after
4430 4431
4431 FormData form; 4432 FormData form;
4432 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData( 4433 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData(
4433 fieldsets, control_elements, nullptr, frame->document(), extract_mask, 4434 fieldsets, control_elements, nullptr, frame->document(), extract_mask,
4434 &form, nullptr)); 4435 &form, nullptr));
4435 } 4436 }
4436 4437
4437 TEST_F(FormAutofillTest, FormCache_ExtractNewForms) { 4438 TEST_F(FormAutofillTest, FormCache_ExtractNewForms) {
4438 struct { 4439 struct {
4439 const char* html; 4440 const char* html;
4440 const size_t expected_forms; 4441 const bool has_extracted_form;
4442 const bool is_form_tag;
4443 const bool is_formless_checkout;
4441 } test_cases[] = { 4444 } test_cases[] = {
4442 // An empty form should not be extracted 4445 // An empty form should not be extracted
4443 {"<FORM name='TestForm' action='http://buh.com' method='post'>" 4446 {"<FORM name='TestForm' action='http://buh.com' method='post'>"
4444 "</FORM>", 4447 "</FORM>",
4445 0}, 4448 false, true, false},
4446 // A form with less than three fields with no autocomplete type(s) should 4449 // A form with less than three fields with no autocomplete type(s) should
4447 // not be extracted. 4450 // not be extracted.
4448 {"<FORM name='TestForm' action='http://buh.com' method='post'>" 4451 {"<FORM name='TestForm' action='http://buh.com' method='post'>"
4449 " <INPUT type='name' id='firstname'/>" 4452 " <INPUT type='name' id='firstname'/>"
4450 "</FORM>", 4453 "</FORM>",
4451 0}, 4454 false, true, false},
4452 // A form with less than three fields with at least one autocomplete type 4455 // A form with less than three fields with at least one autocomplete type
4453 // should be extracted. 4456 // should be extracted.
4454 {"<FORM name='TestForm' action='http://buh.com' method='post'>" 4457 {"<FORM name='TestForm' action='http://buh.com' method='post'>"
4455 " <INPUT type='name' id='firstname' autocomplete='given-name'/>" 4458 " <INPUT type='name' id='firstname' autocomplete='given-name'/>"
4456 "</FORM>", 4459 "</FORM>",
4457 1}, 4460 true, true, false},
4458 // A form with three or more fields should be extracted. 4461 // A form with three or more fields should be extracted.
4459 {"<FORM name='TestForm' action='http://buh.com' method='post'>" 4462 {"<FORM name='TestForm' action='http://buh.com' method='post'>"
4460 " <INPUT type='text' id='firstname'/>" 4463 " <INPUT type='text' id='firstname'/>"
4461 " <INPUT type='text' id='lastname'/>" 4464 " <INPUT type='text' id='lastname'/>"
4462 " <INPUT type='text' id='email'/>" 4465 " <INPUT type='text' id='email'/>"
4463 " <INPUT type='submit' value='Send'/>" 4466 " <INPUT type='submit' value='Send'/>"
4464 "</FORM>", 4467 "</FORM>",
4465 1}, 4468 true, true, false},
4469 // An input field with an autocomplete attribute outside of a form should
4470 // be extracted. The is_formless_checkout attribute should
4471 // then be true.
4472 {"<INPUT type='text' id='firstname' autocomplete='given-name'/>"
4473 "<INPUT type='submit' value='Send'/>",
4474 true, false, false},
4475 // An input field without an autocomplete attribute outside of a form
4476 // should not be extracted.
4477 {"<INPUT type='text' id='firstname'/>"
4478 "<INPUT type='submit' value='Send'/>",
4479 false, false, false},
4466 }; 4480 };
4467 4481
4468 for (auto test_case : test_cases) { 4482 for (auto test_case : test_cases) {
4469 LoadHTML(test_case.html); 4483 LoadHTML(test_case.html);
4470 4484
4471 WebFrame* web_frame = GetMainFrame(); 4485 WebFrame* web_frame = GetMainFrame();
4472 ASSERT_NE(nullptr, web_frame); 4486 ASSERT_NE(nullptr, web_frame);
4473 4487
4474 FormCache form_cache(*web_frame); 4488 FormCache form_cache(*web_frame);
4475 std::vector<FormData> forms = form_cache.ExtractNewForms(); 4489 std::vector<FormData> forms = form_cache.ExtractNewForms();
4476 EXPECT_EQ(test_case.expected_forms, forms.size()); 4490 EXPECT_EQ(test_case.has_extracted_form, forms.size() == 1);
4491
4492 if (test_case.has_extracted_form) {
4493 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag);
4494 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout);
4495 }
4477 } 4496 }
4478 } 4497 }
4479 4498
4480 } // namespace form_util 4499 } // namespace form_util
4481 } // namespace autofill 4500 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_param_traits_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698