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

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

Issue 13264002: Requery the autofill server when forms and input fields are dynamically added. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor style fix Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 19 matching lines...) Expand all
30 #include "components/autofill/browser/autofill_common_test.h" 30 #include "components/autofill/browser/autofill_common_test.h"
31 #include "components/autofill/browser/autofill_manager.h" 31 #include "components/autofill/browser/autofill_manager.h"
32 #include "components/autofill/browser/autofill_metrics.h" 32 #include "components/autofill/browser/autofill_metrics.h"
33 #include "components/autofill/browser/autofill_profile.h" 33 #include "components/autofill/browser/autofill_profile.h"
34 #include "components/autofill/browser/credit_card.h" 34 #include "components/autofill/browser/credit_card.h"
35 #include "components/autofill/browser/personal_data_manager.h" 35 #include "components/autofill/browser/personal_data_manager.h"
36 #include "components/autofill/browser/test_autofill_external_delegate.h" 36 #include "components/autofill/browser/test_autofill_external_delegate.h"
37 #include "components/autofill/common/autofill_messages.h" 37 #include "components/autofill/common/autofill_messages.h"
38 #include "components/autofill/common/form_data.h" 38 #include "components/autofill/common/form_data.h"
39 #include "components/autofill/common/form_field_data.h" 39 #include "components/autofill/common/form_field_data.h"
40 #include "components/autofill/common/forms_seen_param.h"
40 #include "components/user_prefs/user_prefs.h" 41 #include "components/user_prefs/user_prefs.h"
41 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
42 #include "content/public/test/mock_render_process_host.h" 43 #include "content/public/test/mock_render_process_host.h"
43 #include "content/public/test/test_browser_thread.h" 44 #include "content/public/test/test_browser_thread.h"
44 #include "googleurl/src/gurl.h" 45 #include "googleurl/src/gurl.h"
45 #include "grit/generated_resources.h" 46 #include "grit/generated_resources.h"
46 #include "ipc/ipc_test_sink.h" 47 #include "ipc/ipc_test_sink.h"
47 #include "testing/gmock/include/gmock/gmock.h" 48 #include "testing/gmock/include/gmock/gmock.h"
48 #include "testing/gtest/include/gtest/gtest.h" 49 #include "testing/gtest/include/gtest/gtest.h"
49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 void GetAutofillSuggestions(const FormData& form, 734 void GetAutofillSuggestions(const FormData& form,
734 const FormFieldData& field) { 735 const FormFieldData& field) {
735 GetAutofillSuggestions(kDefaultPageID, form, field); 736 GetAutofillSuggestions(kDefaultPageID, form, field);
736 } 737 }
737 738
738 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { 739 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) {
739 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); 740 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result);
740 } 741 }
741 742
742 void FormsSeen(const std::vector<FormData>& forms) { 743 void FormsSeen(const std::vector<FormData>& forms) {
743 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false); 744 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
745 autofill::NO_SPECIAL_FORMS_SEEN);
744 } 746 }
745 747
746 void PartialFormsSeen(const std::vector<FormData>& forms) { 748 void PartialFormsSeen(const std::vector<FormData>& forms) {
747 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true); 749 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
750 autofill::PARTIAL_FORMS_SEEN);
751 }
752
753 void DynamicFormsSeen(const std::vector<FormData>& forms) {
754 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
755 autofill::DYNAMIC_FORMS_SEEN);
756 }
757
758 void PartialDynamicFormsSeen(const std::vector<FormData>& forms) {
759 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
760 autofill::PARTIAL_AND_DYNAMIC_FORMS_SEEN);
748 } 761 }
749 762
750 void FormSubmitted(const FormData& form) { 763 void FormSubmitted(const FormData& form) {
751 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) 764 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now()))
752 autofill_manager_->WaitForAsyncFormSubmit(); 765 autofill_manager_->WaitForAsyncFormSubmit();
753 } 766 }
754 767
755 void FillAutofillFormData(int query_id, 768 void FillAutofillFormData(int query_id,
756 const FormData& form, 769 const FormData& form,
757 const FormFieldData& field, 770 const FormFieldData& field,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 CreateTestAddressFormData(&form); 890 CreateTestAddressFormData(&form);
878 std::vector<FormData> forms(1, form); 891 std::vector<FormData> forms(1, form);
879 // Enable autocheckout. 892 // Enable autocheckout.
880 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); 893 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
881 894
882 PartialFormsSeen(forms); 895 PartialFormsSeen(forms);
883 896
884 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); 897 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage());
885 } 898 }
886 899
900 // Test that browser asks for all forms after DOM changes when
901 // Autocheckout is enabled.
902 TEST_F(AutofillManagerTest, GetAllDynamicForms) {
903 FormData form;
904 CreateTestAddressFormData(&form);
905 std::vector<FormData> forms(1, form);
906 // Enable autocheckout.
907 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
908
909 PartialDynamicFormsSeen(forms);
910
911 EXPECT_TRUE(HasSeenAutofillGetAllFormsMessage());
912 }
913
887 // Test that we return all address profile suggestions when all form fields are 914 // Test that we return all address profile suggestions when all form fields are
888 // empty. 915 // empty.
889 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { 916 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) {
890 // Set up our form data. 917 // Set up our form data.
891 FormData form; 918 FormData form;
892 CreateTestAddressFormData(&form); 919 CreateTestAddressFormData(&form);
893 std::vector<FormData> forms(1, form); 920 std::vector<FormData> forms(1, form);
894 FormsSeen(forms); 921 FormsSeen(forms);
895 922
896 const FormFieldData& field = form.fields[0]; 923 const FormFieldData& field = form.fields[0];
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 // userspecified and then address form. 983 // userspecified and then address form.
957 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); 984 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout");
958 FormsSeen(forms); 985 FormsSeen(forms);
959 form_structures = autofill_manager_->GetFormStructures(); 986 form_structures = autofill_manager_->GetFormStructures();
960 ASSERT_EQ(3U, form_structures.size()); 987 ASSERT_EQ(3U, form_structures.size());
961 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); 988 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path());
962 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); 989 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path());
963 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); 990 EXPECT_EQ("/form.html", form_structures[2]->source_url().path());
964 } 991 }
965 992
993 // Test that in the case of Autocheckout, forms seen are in order supplied.
994 TEST_F(AutofillManagerTest, DynamicFormsSeen) {
995 FormData shipping_options;
996 CreateTestShippingOptionsFormData(&shipping_options);
997 FormData user_supplied;
998 CreateTestFormWithAutocompleteAttribute(&user_supplied);
999 FormData address;
1000 CreateTestAddressFormData(&address);
1001
1002 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
1003 // Push user_supplied only
1004 std::vector<FormData> forms;
1005 forms.push_back(user_supplied);
1006
1007 // Make sure normal form is handled correctly.
1008 FormsSeen(forms);
1009 std::vector<FormStructure*> form_structures;
1010 form_structures = autofill_manager_->GetFormStructures();
1011 ASSERT_EQ(1U, form_structures.size());
1012 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path());
1013
1014 // Push other forms
1015 forms.push_back(shipping_options);
1016 forms.push_back(address);
1017
1018 // FormStructure should contain three and only three forms. Otherwise, it
1019 // would indicate that the manager didn't reset upon being notified of
1020 // the new forms;
1021 DynamicFormsSeen(forms);
1022 form_structures = autofill_manager_->GetFormStructures();
1023 ASSERT_EQ(3U, form_structures.size());
1024 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path());
1025 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path());
1026 EXPECT_EQ("/form.html", form_structures[2]->source_url().path());
1027 }
1028
966 // Test that we return only matching address profile suggestions when the 1029 // Test that we return only matching address profile suggestions when the
967 // selected form field has been partially filled out. 1030 // selected form field has been partially filled out.
968 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { 1031 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) {
969 // Set up our form data. 1032 // Set up our form data.
970 FormData form; 1033 FormData form;
971 CreateTestAddressFormData(&form); 1034 CreateTestAddressFormData(&form);
972 std::vector<FormData> forms(1, form); 1035 std::vector<FormData> forms(1, form);
973 FormsSeen(forms); 1036 FormsSeen(forms);
974 1037
975 FormFieldData field; 1038 FormFieldData field;
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3340 3403
3341 FormData form; 3404 FormData form;
3342 CreateTestAddressFormData(&form); 3405 CreateTestAddressFormData(&form);
3343 std::vector<FormData> forms(1, form); 3406 std::vector<FormData> forms(1, form);
3344 FormsSeen(forms); 3407 FormsSeen(forms);
3345 const FormFieldData& field = form.fields[0]; 3408 const FormFieldData& field = form.fields[0];
3346 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3409 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3347 3410
3348 autofill_manager_->SetExternalDelegate(NULL); 3411 autofill_manager_->SetExternalDelegate(NULL);
3349 } 3412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698