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

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: Fun with merging Created 7 years, 7 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/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 20 matching lines...) Expand all
31 #include "components/autofill/browser/autofill_common_test.h" 31 #include "components/autofill/browser/autofill_common_test.h"
32 #include "components/autofill/browser/autofill_manager.h" 32 #include "components/autofill/browser/autofill_manager.h"
33 #include "components/autofill/browser/autofill_metrics.h" 33 #include "components/autofill/browser/autofill_metrics.h"
34 #include "components/autofill/browser/autofill_profile.h" 34 #include "components/autofill/browser/autofill_profile.h"
35 #include "components/autofill/browser/credit_card.h" 35 #include "components/autofill/browser/credit_card.h"
36 #include "components/autofill/browser/personal_data_manager.h" 36 #include "components/autofill/browser/personal_data_manager.h"
37 #include "components/autofill/browser/test_autofill_external_delegate.h" 37 #include "components/autofill/browser/test_autofill_external_delegate.h"
38 #include "components/autofill/common/autofill_messages.h" 38 #include "components/autofill/common/autofill_messages.h"
39 #include "components/autofill/common/form_data.h" 39 #include "components/autofill/common/form_data.h"
40 #include "components/autofill/common/form_field_data.h" 40 #include "components/autofill/common/form_field_data.h"
41 #include "components/autofill/common/forms_seen_state.h"
41 #include "components/user_prefs/user_prefs.h" 42 #include "components/user_prefs/user_prefs.h"
42 #include "content/public/browser/web_contents.h" 43 #include "content/public/browser/web_contents.h"
43 #include "content/public/test/mock_render_process_host.h" 44 #include "content/public/test/mock_render_process_host.h"
44 #include "content/public/test/test_browser_thread.h" 45 #include "content/public/test/test_browser_thread.h"
45 #include "content/public/test/test_utils.h" 46 #include "content/public/test/test_utils.h"
46 #include "googleurl/src/gurl.h" 47 #include "googleurl/src/gurl.h"
47 #include "grit/generated_resources.h" 48 #include "grit/generated_resources.h"
48 #include "ipc/ipc_test_sink.h" 49 #include "ipc/ipc_test_sink.h"
49 #include "testing/gmock/include/gmock/gmock.h" 50 #include "testing/gmock/include/gmock/gmock.h"
50 #include "testing/gtest/include/gtest/gtest.h" 51 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 const FormFieldData& field) { 691 const FormFieldData& field) {
691 GetAutofillSuggestions(kDefaultPageID, form, field); 692 GetAutofillSuggestions(kDefaultPageID, form, field);
692 } 693 }
693 694
694 void AutocompleteSuggestionsReturned( 695 void AutocompleteSuggestionsReturned(
695 const std::vector<base::string16>& result) { 696 const std::vector<base::string16>& result) {
696 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); 697 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result);
697 } 698 }
698 699
699 void FormsSeen(const std::vector<FormData>& forms) { 700 void FormsSeen(const std::vector<FormData>& forms) {
700 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false); 701 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
702 autofill::NO_SPECIAL_FORMS_SEEN);
701 } 703 }
702 704
703 void PartialFormsSeen(const std::vector<FormData>& forms) { 705 void PartialFormsSeen(const std::vector<FormData>& forms) {
704 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true); 706 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
707 autofill::PARTIAL_FORMS_SEEN);
708 }
709
710 void DynamicFormsSeen(const std::vector<FormData>& forms) {
711 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
712 autofill::DYNAMIC_FORMS_SEEN);
705 } 713 }
706 714
707 void FormSubmitted(const FormData& form) { 715 void FormSubmitted(const FormData& form) {
708 autofill_manager_->ResetMessageLoopRunner(); 716 autofill_manager_->ResetMessageLoopRunner();
709 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) 717 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now()))
710 autofill_manager_->WaitForAsyncFormSubmit(); 718 autofill_manager_->WaitForAsyncFormSubmit();
711 } 719 }
712 720
713 void FillAutofillFormData(int query_id, 721 void FillAutofillFormData(int query_id,
714 const FormData& form, 722 const FormData& form,
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 // userspecified and then address form. 908 // userspecified and then address form.
901 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); 909 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout");
902 FormsSeen(forms); 910 FormsSeen(forms);
903 form_structures = autofill_manager_->GetFormStructures(); 911 form_structures = autofill_manager_->GetFormStructures();
904 ASSERT_EQ(3U, form_structures.size()); 912 ASSERT_EQ(3U, form_structures.size());
905 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); 913 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path());
906 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); 914 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path());
907 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); 915 EXPECT_EQ("/form.html", form_structures[2]->source_url().path());
908 } 916 }
909 917
918 // Test that in the case of Autocheckout, forms seen are in order supplied.
919 TEST_F(AutofillManagerTest, DynamicFormsSeen) {
920 FormData shipping_options;
921 CreateTestShippingOptionsFormData(&shipping_options);
922 FormData user_supplied;
923 CreateTestFormWithAutocompleteAttribute(&user_supplied);
924 FormData address;
925 CreateTestAddressFormData(&address);
926
927 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
928 // Push user_supplied only
929 std::vector<FormData> forms;
930 forms.push_back(user_supplied);
931
932 // Make sure normal form is handled correctly.
933 FormsSeen(forms);
934 std::vector<FormStructure*> form_structures;
935 form_structures = autofill_manager_->GetFormStructures();
936 ASSERT_EQ(1U, form_structures.size());
937 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path());
938
939 // Push other forms
940 forms.push_back(shipping_options);
941 forms.push_back(address);
942
943 // FormStructure should contain three and only three forms. Otherwise, it
944 // would indicate that the manager didn't reset upon being notified of
945 // the new forms;
946 DynamicFormsSeen(forms);
947 form_structures = autofill_manager_->GetFormStructures();
948 ASSERT_EQ(3U, form_structures.size());
949 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path());
950 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path());
951 EXPECT_EQ("/form.html", form_structures[2]->source_url().path());
952 }
953
910 // Test that we return only matching address profile suggestions when the 954 // Test that we return only matching address profile suggestions when the
911 // selected form field has been partially filled out. 955 // selected form field has been partially filled out.
912 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { 956 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) {
913 // Set up our form data. 957 // Set up our form data.
914 FormData form; 958 FormData form;
915 CreateTestAddressFormData(&form); 959 CreateTestAddressFormData(&form);
916 std::vector<FormData> forms(1, form); 960 std::vector<FormData> forms(1, form);
917 FormsSeen(forms); 961 FormsSeen(forms);
918 962
919 FormFieldData field; 963 FormFieldData field;
(...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 CreateTestAddressFormData(&form); 3210 CreateTestAddressFormData(&form);
3167 std::vector<FormData> forms(1, form); 3211 std::vector<FormData> forms(1, form);
3168 FormsSeen(forms); 3212 FormsSeen(forms);
3169 const FormFieldData& field = form.fields[0]; 3213 const FormFieldData& field = form.fields[0];
3170 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3214 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3171 3215
3172 autofill_manager_->SetExternalDelegate(NULL); 3216 autofill_manager_->SetExternalDelegate(NULL);
3173 } 3217 }
3174 3218
3175 } // namespace autofill 3219 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_manager.cc ('k') | components/autofill/browser/autofill_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698