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

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 2730383003: Improve autofill form matching. (Closed)
Patch Set: Move DetermineHeuristicTypes after the add. Rebase. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/feature_list.h" 15 #include "base/feature_list.h"
15 #include "base/format_macros.h" 16 #include "base/format_macros.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_vector.h" 20 #include "base/memory/scoped_vector.h"
20 #include "base/metrics/field_trial.h" 21 #include "base/metrics/field_trial.h"
(...skipping 29 matching lines...) Expand all
50 #include "components/autofill/core/common/form_field_data.h" 51 #include "components/autofill/core/common/form_field_data.h"
51 #include "components/metrics/proto/ukm/entry.pb.h" 52 #include "components/metrics/proto/ukm/entry.pb.h"
52 #include "components/prefs/pref_service.h" 53 #include "components/prefs/pref_service.h"
53 #include "components/rappor/test_rappor_service.h" 54 #include "components/rappor/test_rappor_service.h"
54 #include "components/security_state/core/security_state.h" 55 #include "components/security_state/core/security_state.h"
55 #include "components/strings/grit/components_strings.h" 56 #include "components/strings/grit/components_strings.h"
56 #include "components/ukm/test_ukm_service.h" 57 #include "components/ukm/test_ukm_service.h"
57 #include "components/ukm/ukm_entry.h" 58 #include "components/ukm/ukm_entry.h"
58 #include "components/ukm/ukm_source.h" 59 #include "components/ukm/ukm_source.h"
59 #include "components/variations/variations_associated_data.h" 60 #include "components/variations/variations_associated_data.h"
61 #include "net/base/url_util.h"
60 #include "net/url_request/url_request_test_util.h" 62 #include "net/url_request/url_request_test_util.h"
61 #include "testing/gmock/include/gmock/gmock.h" 63 #include "testing/gmock/include/gmock/gmock.h"
62 #include "testing/gtest/include/gtest/gtest.h" 64 #include "testing/gtest/include/gtest/gtest.h"
63 #include "ui/base/l10n/l10n_util.h" 65 #include "ui/base/l10n/l10n_util.h"
64 #include "ui/gfx/geometry/rect.h" 66 #include "ui/gfx/geometry/rect.h"
65 #include "url/gurl.h" 67 #include "url/gurl.h"
66 68
67 using base::ASCIIToUTF16; 69 using base::ASCIIToUTF16;
68 using base::UTF8ToUTF16; 70 using base::UTF8ToUTF16;
69 using testing::_; 71 using testing::_;
(...skipping 5665 matching lines...) Expand 10 before | Expand all | Expand 10 after
5735 EXPECT_FALSE(autofill_driver_->did_interact_with_credit_card_form()); 5737 EXPECT_FALSE(autofill_driver_->did_interact_with_credit_card_form());
5736 5738
5737 // The driver should always be notified. 5739 // The driver should always be notified.
5738 for (const FormFieldData& field : form.fields) { 5740 for (const FormFieldData& field : form.fields) {
5739 GetAutofillSuggestions(form, field); 5741 GetAutofillSuggestions(form, field);
5740 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); 5742 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5741 autofill_driver_->ClearDidInteractWithCreditCardForm(); 5743 autofill_driver_->ClearDidInteractWithCreditCardForm();
5742 } 5744 }
5743 } 5745 }
5744 5746
5747 // Tests that a form with server only types is still autofillable if the form
5748 // gets updated in cache.
5749 TEST_F(AutofillManagerTest, DisplaySuggestionsForUpdatedServerTypedForm) {
5750 // Create a form with unknown heuristic fields.
5751 FormData form;
5752 form.name = ASCIIToUTF16("MyForm");
5753 form.origin = GURL("http://myform.com/form.html");
5754 form.action = GURL("http://myform.com/submit.html");
5755
5756 FormFieldData field;
5757 test::CreateTestFormField("Field 1", "field1", "", "text", &field);
5758 form.fields.push_back(field);
5759 test::CreateTestFormField("Field 2", "field2", "", "text", &field);
5760 form.fields.push_back(field);
5761 test::CreateTestFormField("Field 3", "field3", "", "text", &field);
5762 form.fields.push_back(field);
5763
5764 auto form_structure = base::MakeUnique<TestFormStructure>(form);
5765 form_structure->DetermineHeuristicTypes();
5766 // Make sure the form can not be autofilled now.
5767 ASSERT_EQ(0u, form_structure->autofill_count());
5768 for (size_t idx = 0; idx < form_structure->field_count(); ++idx) {
5769 ASSERT_EQ(UNKNOWN_TYPE, form_structure->field(idx)->heuristic_type());
5770 }
5771
5772 // Prepare and set known server fields.
5773 const std::vector<ServerFieldType> heuristic_types(form.fields.size(),
5774 UNKNOWN_TYPE);
5775 const std::vector<ServerFieldType> server_types{NAME_FIRST, NAME_MIDDLE,
5776 NAME_LAST};
5777 form_structure->SetFieldTypes(heuristic_types, server_types);
5778 autofill_manager_->AddSeenForm(std::move(form_structure));
5779
5780 // Make sure the form can be autofilled.
5781 for (const FormFieldData& field : form.fields) {
5782 GetAutofillSuggestions(form, field);
5783 ASSERT_TRUE(external_delegate_->on_suggestions_returned_seen());
5784 }
5785
5786 // Modify one of the fields in the original form.
5787 form.fields[0].css_classes += ASCIIToUTF16("a");
5788
5789 // Expect the form still can be autofilled.
5790 for (const FormFieldData& field : form.fields) {
5791 GetAutofillSuggestions(form, field);
5792 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
5793 }
5794
5795 // Modify form action URL. This can happen on in-page navitaion if the form
5796 // doesn't have an actual action (attribute is empty).
5797 form.action = net::AppendQueryParameter(form.action, "arg", "value");
5798
5799 // Expect the form still can be autofilled.
5800 for (const FormFieldData& field : form.fields) {
5801 GetAutofillSuggestions(form, field);
5802 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
5803 }
5804 }
5805
5806 // Tests that a form with <select> field is accepted if <option> value (not
5807 // content) is quite long. Some websites use value to propagate long JSON to
5808 // JS-backed logic.
5809 TEST_F(AutofillManagerTest, FormWithLongOptionValuesIsAcceptable) {
5810 FormData form;
5811 form.name = ASCIIToUTF16("MyForm");
5812 form.origin = GURL("http://myform.com/form.html");
5813 form.action = GURL("http://myform.com/submit.html");
5814
5815 FormFieldData field;
5816 test::CreateTestFormField("First name", "firstname", "", "text", &field);
5817 form.fields.push_back(field);
5818 test::CreateTestFormField("Last name", "lastname", "", "text", &field);
5819 form.fields.push_back(field);
5820
5821 // Prepare <select> field with long <option> values.
5822 const size_t kOptionValueLength = 10240;
5823 const std::string long_string(kOptionValueLength, 'a');
5824 const std::vector<const char*> values(3, long_string.c_str());
5825 const std::vector<const char*> contents{"A", "B", "C"};
5826 test::CreateTestSelectField("Country", "country", "", values, contents,
5827 values.size(), &field);
5828 form.fields.push_back(field);
5829
5830 FormsSeen({form});
5831
5832 // Suggestions should be displayed.
5833 for (const FormFieldData& field : form.fields) {
5834 GetAutofillSuggestions(form, field);
5835 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
5836 }
5837 }
5838
5745 } // namespace autofill 5839 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698