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

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

Issue 23033016: Remove autocheckout code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Even more deletes, and Ilya review. Created 7 years, 3 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 | Annotate | Revision Log
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 <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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 personal_data_(personal_data), 472 personal_data_(personal_data),
473 autofill_enabled_(true) {} 473 autofill_enabled_(true) {}
474 virtual ~TestAutofillManager() {} 474 virtual ~TestAutofillManager() {}
475 475
476 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } 476 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; }
477 477
478 void set_autofill_enabled(bool autofill_enabled) { 478 void set_autofill_enabled(bool autofill_enabled) {
479 autofill_enabled_ = autofill_enabled; 479 autofill_enabled_ = autofill_enabled;
480 } 480 }
481 481
482 void set_autocheckout_url_prefix(const std::string& autocheckout_url_prefix) {
483 autocheckout_url_prefix_ = autocheckout_url_prefix;
484 }
485
486 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE {
487 return autocheckout_url_prefix_;
488 }
489
490 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& 482 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >&
491 request_autocomplete_results() const { 483 request_autocomplete_results() const {
492 return request_autocomplete_results_; 484 return request_autocomplete_results_;
493 } 485 }
494 486
495 487
496 void set_expected_submitted_field_types( 488 void set_expected_submitted_field_types(
497 const std::vector<ServerFieldTypeSet>& expected_types) { 489 const std::vector<ServerFieldTypeSet>& expected_types) {
498 expected_submitted_field_types_ = expected_types; 490 expected_submitted_field_types_ = expected_types;
499 } 491 }
(...skipping 26 matching lines...) Expand all
526 } 518 }
527 } 519 }
528 } 520 }
529 521
530 AutofillManager::UploadFormDataAsyncCallback(submitted_form, 522 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
531 load_time, 523 load_time,
532 interaction_time, 524 interaction_time,
533 submission_time); 525 submission_time);
534 } 526 }
535 527
536 virtual void OnMaybeShowAutocheckoutBubble(
537 const FormData& form,
538 const gfx::RectF& bounding_box) OVERRIDE {
539 AutofillManager::OnMaybeShowAutocheckoutBubble(form, bounding_box);
540 // Needed for AutocheckoutManager to post task on IO thread.
541 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
542 }
543
544 // Resets the MessageLoopRunner so that it can wait for an asynchronous form 528 // Resets the MessageLoopRunner so that it can wait for an asynchronous form
545 // submission to complete. 529 // submission to complete.
546 void ResetMessageLoopRunner() { 530 void ResetMessageLoopRunner() {
547 message_loop_runner_ = new content::MessageLoopRunner(); 531 message_loop_runner_ = new content::MessageLoopRunner();
548 } 532 }
549 533
550 // Wait for the asynchronous OnFormSubmitted() call to complete. 534 // Wait for the asynchronous OnFormSubmitted() call to complete.
551 void WaitForAsyncFormSubmit() { 535 void WaitForAsyncFormSubmit() {
552 message_loop_runner_->Run(); 536 message_loop_runner_->Run();
553 } 537 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 void ClearFormStructures() { 574 void ClearFormStructures() {
591 form_structures()->clear(); 575 form_structures()->clear();
592 } 576 }
593 577
594 virtual void ReturnAutocompleteResult( 578 virtual void ReturnAutocompleteResult(
595 WebFormElement::AutocompleteResult result, 579 WebFormElement::AutocompleteResult result,
596 const FormData& form_data) OVERRIDE { 580 const FormData& form_data) OVERRIDE {
597 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); 581 request_autocomplete_results_.push_back(std::make_pair(result, form_data));
598 } 582 }
599 583
600 // Set autocheckout manager's page meta data to first page on Autocheckout
601 // flow.
602 void MarkAsFirstPageInAutocheckoutFlow() {
603 scoped_ptr<AutocheckoutPageMetaData> start_of_flow(
604 new AutocheckoutPageMetaData());
605 start_of_flow->current_page_number = 0;
606 start_of_flow->total_pages = 3;
607 WebElementDescriptor* proceed_element =
608 &start_of_flow->proceed_element_descriptor;
609 proceed_element->descriptor = "#foo";
610 proceed_element->retrieval_method = WebElementDescriptor::ID;
611 autocheckout_manager()->OnLoadedPageMetaData(start_of_flow.Pass());
612 }
613
614 // Set autocheckout manager's page meta data to first page on Autocheckout
615 // flow.
616 void MarkAsFirstPageInAutocheckoutFlowIgnoringAjax() {
617 scoped_ptr<AutocheckoutPageMetaData> start_of_flow(
618 new AutocheckoutPageMetaData());
619 start_of_flow->current_page_number = 0;
620 start_of_flow->total_pages = 3;
621 start_of_flow->ignore_ajax = true;
622 WebElementDescriptor* proceed_element =
623 &start_of_flow->proceed_element_descriptor;
624 proceed_element->descriptor = "#foo";
625 proceed_element->retrieval_method = WebElementDescriptor::ID;
626 autocheckout_manager()->OnLoadedPageMetaData(start_of_flow.Pass());
627 }
628
629 private: 584 private:
630 // Weak reference. 585 // Weak reference.
631 TestPersonalDataManager* personal_data_; 586 TestPersonalDataManager* personal_data_;
632 587
633 bool autofill_enabled_; 588 bool autofill_enabled_;
634 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > 589 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >
635 request_autocomplete_results_; 590 request_autocomplete_results_;
636 591
637 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 592 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
638 593
639 std::string autocheckout_url_prefix_;
640 std::string submitted_form_signature_; 594 std::string submitted_form_signature_;
641 std::vector<ServerFieldTypeSet> expected_submitted_field_types_; 595 std::vector<ServerFieldTypeSet> expected_submitted_field_types_;
642 596
643 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 597 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
644 }; 598 };
645 599
646 class TestAutofillExternalDelegate : public AutofillExternalDelegate { 600 class TestAutofillExternalDelegate : public AutofillExternalDelegate {
647 public: 601 public:
648 explicit TestAutofillExternalDelegate(content::WebContents* web_contents, 602 explicit TestAutofillExternalDelegate(content::WebContents* web_contents,
649 AutofillManager* autofill_manager, 603 AutofillManager* autofill_manager,
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _)). 786 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _)).
833 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), 787 WillOnce((DoAll(testing::SaveArg<0>(response_query_id),
834 testing::SaveArg<1>(response_data)))); 788 testing::SaveArg<1>(response_data))));
835 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); 789 FillAutofillFormData(input_query_id, input_form, input_field, unique_id);
836 } 790 }
837 791
838 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { 792 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const {
839 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); 793 return autofill_manager_->PackGUIDs(cc_guid, profile_guid);
840 } 794 }
841 795
842
843 bool HasSeenAutofillGetAllFormsMessage() {
844 const uint32 kMsgID = AutofillMsg_GetAllForms::ID;
845 const IPC::Message* message =
846 process()->sink().GetFirstMessageMatching(kMsgID);
847 return message != NULL;
848 }
849
850 protected: 796 protected:
851 scoped_ptr<MockAutofillDriver> autofill_driver_; 797 scoped_ptr<MockAutofillDriver> autofill_driver_;
852 scoped_ptr<TestAutofillManager> autofill_manager_; 798 scoped_ptr<TestAutofillManager> autofill_manager_;
853 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; 799 scoped_ptr<TestAutofillExternalDelegate> external_delegate_;
854 TestPersonalDataManager personal_data_; 800 TestPersonalDataManager personal_data_;
855 801
856 // Used when we want an off the record profile. This will store the original 802 // Used when we want an off the record profile. This will store the original
857 // profile from which the off the record profile is derived. 803 // profile from which the off the record profile is derived.
858 scoped_ptr<Profile> other_browser_context_; 804 scoped_ptr<Profile> other_browser_context_;
859 }; 805 };
860 806
861 class TestFormStructure : public FormStructure { 807 class TestFormStructure : public FormStructure {
862 public: 808 public:
863 explicit TestFormStructure(const FormData& form) 809 explicit TestFormStructure(const FormData& form)
864 : FormStructure(form, std::string()) {} 810 : FormStructure(form) {}
865 virtual ~TestFormStructure() {} 811 virtual ~TestFormStructure() {}
866 812
867 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types, 813 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types,
868 const std::vector<ServerFieldType>& server_types) { 814 const std::vector<ServerFieldType>& server_types) {
869 ASSERT_EQ(field_count(), heuristic_types.size()); 815 ASSERT_EQ(field_count(), heuristic_types.size());
870 ASSERT_EQ(field_count(), server_types.size()); 816 ASSERT_EQ(field_count(), server_types.size());
871 817
872 for (size_t i = 0; i < field_count(); ++i) { 818 for (size_t i = 0; i < field_count(); ++i) {
873 AutofillField* form_field = field(i); 819 AutofillField* form_field = field(i);
874 ASSERT_TRUE(form_field); 820 ASSERT_TRUE(form_field);
875 form_field->set_heuristic_type(heuristic_types[i]); 821 form_field->set_heuristic_type(heuristic_types[i]);
876 form_field->set_server_type(server_types[i]); 822 form_field->set_server_type(server_types[i]);
877 } 823 }
878 824
879 UpdateAutofillCount(); 825 UpdateAutofillCount();
880 } 826 }
881 827
882 private: 828 private:
883 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); 829 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
884 }; 830 };
885 831
886 // Test that browser asks for all forms when Autocheckout is enabled.
887 TEST_F(AutofillManagerTest, GetAllForms) {
888 FormData form;
889 test::CreateTestAddressFormData(&form);
890 std::vector<FormData> forms(1, form);
891 // Enable autocheckout.
892 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
893
894 PartialFormsSeen(forms);
895
896 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage());
897 }
898
899 // Test that we return all address profile suggestions when all form fields are 832 // Test that we return all address profile suggestions when all form fields are
900 // empty. 833 // empty.
901 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { 834 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) {
902 // Set up our form data. 835 // Set up our form data.
903 FormData form; 836 FormData form;
904 test::CreateTestAddressFormData(&form); 837 test::CreateTestAddressFormData(&form);
905 std::vector<FormData> forms(1, form); 838 std::vector<FormData> forms(1, form);
906 FormsSeen(forms); 839 FormsSeen(forms);
907 840
908 const FormFieldData& field = form.fields[0]; 841 const FormFieldData& field = form.fields[0];
(...skipping 14 matching lines...) Expand all
923 ASCIIToUTF16("3734 Elvis Presley Blvd."), 856 ASCIIToUTF16("3734 Elvis Presley Blvd."),
924 ASCIIToUTF16("123 Apple St.") 857 ASCIIToUTF16("123 Apple St.")
925 }; 858 };
926 base::string16 expected_icons[] = {base::string16(), base::string16()}; 859 base::string16 expected_icons[] = {base::string16(), base::string16()};
927 int expected_unique_ids[] = {1, 2}; 860 int expected_unique_ids[] = {1, 2};
928 external_delegate_->CheckSuggestions( 861 external_delegate_->CheckSuggestions(
929 kDefaultPageID, arraysize(expected_values), expected_values, 862 kDefaultPageID, arraysize(expected_values), expected_values,
930 expected_labels, expected_icons, expected_unique_ids); 863 expected_labels, expected_icons, expected_unique_ids);
931 } 864 }
932 865
933 // Test that in the case of Autocheckout, forms seen are in order supplied.
934 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) {
935 FormData shipping_options;
936 CreateTestShippingOptionsFormData(&shipping_options);
937 FormData user_supplied;
938 CreateTestFormWithAutocompleteAttribute(&user_supplied);
939 FormData address;
940 test::CreateTestAddressFormData(&address);
941
942 // Push user_supplied before address and observe order changing when
943 // Autocheckout is not enabled..
944 std::vector<FormData> forms;
945 forms.push_back(shipping_options);
946 forms.push_back(user_supplied);
947 forms.push_back(address);
948
949 // Test without enabling Autocheckout. FormStructure should only contain
950 // form1. Shipping Options form will not qualify as parsable form.
951 FormsSeen(forms);
952 std::vector<FormStructure*> form_structures;
953 form_structures = autofill_manager_->GetFormStructures();
954 ASSERT_EQ(2U, form_structures.size());
955 EXPECT_EQ("/form.html", form_structures[0]->source_url().path());
956 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path());
957 autofill_manager_->ClearFormStructures();
958
959 // Test after enabling Autocheckout. Order should be shipping_options,
960 // userspecified and then address form.
961 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout");
962 FormsSeen(forms);
963 form_structures = autofill_manager_->GetFormStructures();
964 ASSERT_EQ(3U, form_structures.size());
965 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path());
966 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path());
967 EXPECT_EQ("/form.html", form_structures[2]->source_url().path());
968 }
969
970 // Test that in the case of Autocheckout, forms seen are in order supplied.
971 TEST_F(AutofillManagerTest, DynamicFormsSeen) {
972 FormData shipping_options;
973 CreateTestShippingOptionsFormData(&shipping_options);
974 FormData user_supplied;
975 CreateTestFormWithAutocompleteAttribute(&user_supplied);
976 FormData address;
977 test::CreateTestAddressFormData(&address);
978
979 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
980 // Push user_supplied only
981 std::vector<FormData> forms;
982 forms.push_back(user_supplied);
983
984 // Make sure normal form is handled correctly.
985 FormsSeen(forms);
986 std::vector<FormStructure*> form_structures;
987 form_structures = autofill_manager_->GetFormStructures();
988 ASSERT_EQ(1U, form_structures.size());
989 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path());
990
991 // Push other forms
992 forms.push_back(shipping_options);
993 forms.push_back(address);
994
995 // FormStructure should contain three and only three forms. Otherwise, it
996 // would indicate that the manager didn't reset upon being notified of
997 // the new forms;
998 DynamicFormsSeen(forms);
999 form_structures = autofill_manager_->GetFormStructures();
1000 ASSERT_EQ(3U, form_structures.size());
1001 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path());
1002 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path());
1003 EXPECT_EQ("/form.html", form_structures[2]->source_url().path());
1004 }
1005
1006 // Test that we return only matching address profile suggestions when the 866 // Test that we return only matching address profile suggestions when the
1007 // selected form field has been partially filled out. 867 // selected form field has been partially filled out.
1008 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { 868 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) {
1009 // Set up our form data. 869 // Set up our form data.
1010 FormData form; 870 FormData form;
1011 test::CreateTestAddressFormData(&form); 871 test::CreateTestAddressFormData(&form);
1012 std::vector<FormData> forms(1, form); 872 std::vector<FormData> forms(1, form);
1013 FormsSeen(forms); 873 FormsSeen(forms);
1014 874
1015 FormFieldData field; 875 FormFieldData field;
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 // Test that the form signature for an uploaded form always matches the form 2536 // Test that the form signature for an uploaded form always matches the form
2677 // signature from the query. 2537 // signature from the query.
2678 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { 2538 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) {
2679 // Set up our form data. 2539 // Set up our form data.
2680 FormData form; 2540 FormData form;
2681 test::CreateTestAddressFormData(&form); 2541 test::CreateTestAddressFormData(&form);
2682 std::vector<FormData> forms(1, form); 2542 std::vector<FormData> forms(1, form);
2683 FormsSeen(forms); 2543 FormsSeen(forms);
2684 2544
2685 // Cache the expected form signature. 2545 // Cache the expected form signature.
2686 std::string signature = FormStructure(form, std::string()).FormSignature(); 2546 std::string signature = FormStructure(form).FormSignature();
2687 2547
2688 // Change the structure of the form prior to submission. 2548 // Change the structure of the form prior to submission.
2689 // Websites would typically invoke JavaScript either on page load or on form 2549 // Websites would typically invoke JavaScript either on page load or on form
2690 // submit to achieve this. 2550 // submit to achieve this.
2691 form.fields.pop_back(); 2551 form.fields.pop_back();
2692 FormFieldData field = form.fields[3]; 2552 FormFieldData field = form.fields[3];
2693 form.fields[3] = form.fields[7]; 2553 form.fields[3] = form.fields[7];
2694 form.fields[7] = field; 2554 form.fields[7] = field;
2695 2555
2696 // Simulate form submission. 2556 // Simulate form submission.
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
3101 2961
3102 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size()); 2962 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size());
3103 EXPECT_EQ(WebFormElement::AutocompleteResultErrorDisabled, 2963 EXPECT_EQ(WebFormElement::AutocompleteResultErrorDisabled,
3104 autofill_manager_->request_autocomplete_results()[0].first); 2964 autofill_manager_->request_autocomplete_results()[0].first);
3105 } 2965 }
3106 2966
3107 namespace { 2967 namespace {
3108 2968
3109 class MockAutofillManagerDelegate : public TestAutofillManagerDelegate { 2969 class MockAutofillManagerDelegate : public TestAutofillManagerDelegate {
3110 public: 2970 public:
3111 MockAutofillManagerDelegate() 2971 MockAutofillManagerDelegate() {}
3112 : autocheckout_bubble_shown_(false) {}
3113 2972
3114 virtual ~MockAutofillManagerDelegate() {} 2973 virtual ~MockAutofillManagerDelegate() {}
3115 2974
3116 virtual bool ShowAutocheckoutBubble(
3117 const gfx::RectF& bounds,
3118 bool is_google_user,
3119 const base::Callback<void(AutocheckoutBubbleState)>& callback) OVERRIDE {
3120 autocheckout_bubble_shown_ = true;
3121 callback.Run(AUTOCHECKOUT_BUBBLE_ACCEPTED);
3122 return true;
3123 }
3124
3125 virtual void ShowRequestAutocompleteDialog( 2975 virtual void ShowRequestAutocompleteDialog(
3126 const FormData& form, 2976 const FormData& form,
3127 const GURL& source_url, 2977 const GURL& source_url,
3128 DialogType dialog_type, 2978 DialogType dialog_type,
3129 const base::Callback<void(const FormStructure*, 2979 const base::Callback<void(const FormStructure*,
3130 const std::string&)>& callback) OVERRIDE { 2980 const std::string&)>& callback) OVERRIDE {
3131 callback.Run(user_supplied_data_.get(), "google_transaction_id"); 2981 callback.Run(user_supplied_data_.get(), "google_transaction_id");
3132 } 2982 }
3133 2983
3134 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { 2984 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) {
3135 user_supplied_data_.reset(user_supplied_data.release()); 2985 user_supplied_data_.reset(user_supplied_data.release());
3136 } 2986 }
3137 2987
3138 bool autocheckout_bubble_shown() const {
3139 return autocheckout_bubble_shown_;
3140 }
3141
3142 private: 2988 private:
3143 bool autocheckout_bubble_shown_;
3144 scoped_ptr<FormStructure> user_supplied_data_; 2989 scoped_ptr<FormStructure> user_supplied_data_;
3145 2990
3146 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 2991 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
3147 }; 2992 };
3148 2993
3149 } // namespace 2994 } // namespace
3150 2995
3151 // Test that Autocheckout bubble is offered when server specifies field types.
3152 TEST_F(AutofillManagerTest, TestBubbleShown) {
3153 MockAutofillManagerDelegate delegate;
3154 autofill_manager_.reset(new TestAutofillManager(
3155 autofill_driver_.get(), &delegate, &personal_data_));
3156 autofill_manager_->set_autofill_enabled(true);
3157 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
3158
3159 FormData form;
3160 test::CreateTestAddressFormData(&form);
3161
3162 TestFormStructure* form_structure = new TestFormStructure(form);
3163 AutofillMetrics metrics_logger; // ignored
3164 form_structure->DetermineHeuristicTypes(metrics_logger);
3165
3166 // Build and add form structure with server data.
3167 std::vector<ServerFieldType> heuristic_types, server_types;
3168 for (size_t i = 0; i < form.fields.size(); ++i) {
3169 heuristic_types.push_back(UNKNOWN_TYPE);
3170 server_types.push_back(form_structure->field(i)->heuristic_type());
3171 }
3172 form_structure->SetFieldTypes(heuristic_types, server_types);
3173 autofill_manager_->AddSeenForm(form_structure);
3174
3175 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
3176
3177 EXPECT_TRUE(delegate.autocheckout_bubble_shown());
3178 }
3179
3180 // Test that Autocheckout bubble is not offered when server doesn't have data
3181 // for the form.
3182 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) {
3183 MockAutofillManagerDelegate delegate;
3184 autofill_manager_.reset(new TestAutofillManager(
3185 autofill_driver_.get(), &delegate, &personal_data_));
3186 autofill_manager_->set_autofill_enabled(true);
3187 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
3188
3189 FormData form;
3190 test::CreateTestAddressFormData(&form);
3191
3192 TestFormStructure* form_structure = new TestFormStructure(form);
3193 AutofillMetrics metrics_logger; // ignored
3194 form_structure->DetermineHeuristicTypes(metrics_logger);
3195
3196 // Build form structure without server data.
3197 std::vector<ServerFieldType> heuristic_types, server_types;
3198 for (size_t i = 0; i < form.fields.size(); ++i) {
3199 heuristic_types.push_back(form_structure->field(i)->heuristic_type());
3200 server_types.push_back(NO_SERVER_DATA);
3201 }
3202 form_structure->SetFieldTypes(heuristic_types, server_types);
3203 autofill_manager_->AddSeenForm(form_structure);
3204
3205 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
3206
3207 EXPECT_FALSE(delegate.autocheckout_bubble_shown());
3208 }
3209
3210 // Test our external delegate is called at the right time. 2996 // Test our external delegate is called at the right time.
3211 TEST_F(AutofillManagerTest, TestExternalDelegate) { 2997 TEST_F(AutofillManagerTest, TestExternalDelegate) {
3212 FormData form; 2998 FormData form;
3213 test::CreateTestAddressFormData(&form); 2999 test::CreateTestAddressFormData(&form);
3214 std::vector<FormData> forms(1, form); 3000 std::vector<FormData> forms(1, form);
3215 FormsSeen(forms); 3001 FormsSeen(forms);
3216 const FormFieldData& field = form.fields[0]; 3002 const FormFieldData& field = form.fields[0];
3217 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3003 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3218 3004
3219 EXPECT_TRUE(external_delegate_->on_query_seen()); 3005 EXPECT_TRUE(external_delegate_->on_query_seen());
3220 } 3006 }
3221 3007
3222 // Test that in the case of Autocheckout, forms seen are in order supplied.
3223 TEST_F(AutofillManagerTest, DynamicFormsSeenAndIgnored) {
3224 MockAutofillManagerDelegate delegate;
3225 autofill_manager_.reset(new TestAutofillManager(
3226 autofill_driver_.get(), &delegate, &personal_data_));
3227 FormData shipping_options;
3228 CreateTestShippingOptionsFormData(&shipping_options);
3229 FormData user_supplied;
3230 CreateTestFormWithAutocompleteAttribute(&user_supplied);
3231 FormData address;
3232 test::CreateTestAddressFormData(&address);
3233
3234 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
3235 // Push address only
3236 std::vector<FormData> forms;
3237 forms.push_back(address);
3238
3239 // Build and add form structure with server data.
3240 scoped_ptr<TestFormStructure> form_structure(new TestFormStructure(address));
3241 std::vector<ServerFieldType> heuristic_types, server_types;
3242 for (size_t i = 0; i < address.fields.size(); ++i) {
3243 heuristic_types.push_back(UNKNOWN_TYPE);
3244 server_types.push_back(form_structure->field(i)->heuristic_type());
3245 }
3246 form_structure->SetFieldTypes(heuristic_types, server_types);
3247 autofill_manager_->AddSeenForm(form_structure.release());
3248
3249 // Make sure normal form is handled correctly.
3250 autofill_manager_->MarkAsFirstPageInAutocheckoutFlowIgnoringAjax();
3251 std::vector<FormStructure*> form_structures;
3252 form_structures = autofill_manager_->GetFormStructures();
3253 ASSERT_EQ(1U, form_structures.size());
3254 EXPECT_EQ("/form.html", form_structures[0]->source_url().path());
3255
3256 scoped_ptr<FormStructure> filled_form(new TestFormStructure(address));
3257 delegate.SetUserSuppliedData(filled_form.Pass());
3258 autofill_manager_->OnMaybeShowAutocheckoutBubble(address, gfx::RectF());
3259
3260 // Push other forms
3261 forms.push_back(shipping_options);
3262 forms.push_back(user_supplied);
3263
3264 // FormStructure should contain the same forms as before.
3265 DynamicFormsSeen(forms);
3266 form_structures = autofill_manager_->GetFormStructures();
3267 ASSERT_EQ(1U, form_structures.size());
3268 EXPECT_EQ("/form.html", form_structures[0]->source_url().path());
3269 }
3270
3271 } // namespace autofill 3008 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698