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

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: Created 7 years, 4 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 TestPersonalDataManager personal_data_; 808 TestPersonalDataManager personal_data_;
855 809
856 // Used when we want an off the record profile. This will store the original 810 // 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. 811 // profile from which the off the record profile is derived.
858 scoped_ptr<Profile> other_browser_context_; 812 scoped_ptr<Profile> other_browser_context_;
859 }; 813 };
860 814
861 class TestFormStructure : public FormStructure { 815 class TestFormStructure : public FormStructure {
862 public: 816 public:
863 explicit TestFormStructure(const FormData& form) 817 explicit TestFormStructure(const FormData& form)
864 : FormStructure(form, std::string()) {} 818 : FormStructure(form) {}
865 virtual ~TestFormStructure() {} 819 virtual ~TestFormStructure() {}
866 820
867 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types, 821 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types,
868 const std::vector<ServerFieldType>& server_types) { 822 const std::vector<ServerFieldType>& server_types) {
869 ASSERT_EQ(field_count(), heuristic_types.size()); 823 ASSERT_EQ(field_count(), heuristic_types.size());
870 ASSERT_EQ(field_count(), server_types.size()); 824 ASSERT_EQ(field_count(), server_types.size());
871 825
872 for (size_t i = 0; i < field_count(); ++i) { 826 for (size_t i = 0; i < field_count(); ++i) {
873 AutofillField* form_field = field(i); 827 AutofillField* form_field = field(i);
874 ASSERT_TRUE(form_field); 828 ASSERT_TRUE(form_field);
875 form_field->set_heuristic_type(heuristic_types[i]); 829 form_field->set_heuristic_type(heuristic_types[i]);
876 form_field->set_server_type(server_types[i]); 830 form_field->set_server_type(server_types[i]);
877 } 831 }
878 832
879 UpdateAutofillCount(); 833 UpdateAutofillCount();
880 } 834 }
881 835
882 private: 836 private:
883 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); 837 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
884 }; 838 };
885 839
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 840 // Test that we return all address profile suggestions when all form fields are
900 // empty. 841 // empty.
901 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { 842 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) {
902 // Set up our form data. 843 // Set up our form data.
903 FormData form; 844 FormData form;
904 test::CreateTestAddressFormData(&form); 845 test::CreateTestAddressFormData(&form);
905 std::vector<FormData> forms(1, form); 846 std::vector<FormData> forms(1, form);
906 FormsSeen(forms); 847 FormsSeen(forms);
907 848
908 const FormFieldData& field = form.fields[0]; 849 const FormFieldData& field = form.fields[0];
(...skipping 14 matching lines...) Expand all
923 ASCIIToUTF16("3734 Elvis Presley Blvd."), 864 ASCIIToUTF16("3734 Elvis Presley Blvd."),
924 ASCIIToUTF16("123 Apple St.") 865 ASCIIToUTF16("123 Apple St.")
925 }; 866 };
926 base::string16 expected_icons[] = {base::string16(), base::string16()}; 867 base::string16 expected_icons[] = {base::string16(), base::string16()};
927 int expected_unique_ids[] = {1, 2}; 868 int expected_unique_ids[] = {1, 2};
928 external_delegate_->CheckSuggestions( 869 external_delegate_->CheckSuggestions(
929 kDefaultPageID, arraysize(expected_values), expected_values, 870 kDefaultPageID, arraysize(expected_values), expected_values,
930 expected_labels, expected_icons, expected_unique_ids); 871 expected_labels, expected_icons, expected_unique_ids);
931 } 872 }
932 873
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 874 // Test that we return only matching address profile suggestions when the
1007 // selected form field has been partially filled out. 875 // selected form field has been partially filled out.
1008 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { 876 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) {
1009 // Set up our form data. 877 // Set up our form data.
1010 FormData form; 878 FormData form;
1011 test::CreateTestAddressFormData(&form); 879 test::CreateTestAddressFormData(&form);
1012 std::vector<FormData> forms(1, form); 880 std::vector<FormData> forms(1, form);
1013 FormsSeen(forms); 881 FormsSeen(forms);
1014 882
1015 FormFieldData field; 883 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 2544 // Test that the form signature for an uploaded form always matches the form
2677 // signature from the query. 2545 // signature from the query.
2678 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { 2546 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) {
2679 // Set up our form data. 2547 // Set up our form data.
2680 FormData form; 2548 FormData form;
2681 test::CreateTestAddressFormData(&form); 2549 test::CreateTestAddressFormData(&form);
2682 std::vector<FormData> forms(1, form); 2550 std::vector<FormData> forms(1, form);
2683 FormsSeen(forms); 2551 FormsSeen(forms);
2684 2552
2685 // Cache the expected form signature. 2553 // Cache the expected form signature.
2686 std::string signature = FormStructure(form, std::string()).FormSignature(); 2554 std::string signature = FormStructure(form).FormSignature();
2687 2555
2688 // Change the structure of the form prior to submission. 2556 // Change the structure of the form prior to submission.
2689 // Websites would typically invoke JavaScript either on page load or on form 2557 // Websites would typically invoke JavaScript either on page load or on form
2690 // submit to achieve this. 2558 // submit to achieve this.
2691 form.fields.pop_back(); 2559 form.fields.pop_back();
2692 FormFieldData field = form.fields[3]; 2560 FormFieldData field = form.fields[3];
2693 form.fields[3] = form.fields[7]; 2561 form.fields[3] = form.fields[7];
2694 form.fields[7] = field; 2562 form.fields[7] = field;
2695 2563
2696 // Simulate form submission. 2564 // Simulate form submission.
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
3101 2969
3102 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size()); 2970 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size());
3103 EXPECT_EQ(WebFormElement::AutocompleteResultErrorDisabled, 2971 EXPECT_EQ(WebFormElement::AutocompleteResultErrorDisabled,
3104 autofill_manager_->request_autocomplete_results()[0].first); 2972 autofill_manager_->request_autocomplete_results()[0].first);
3105 } 2973 }
3106 2974
3107 namespace { 2975 namespace {
3108 2976
3109 class MockAutofillManagerDelegate : public TestAutofillManagerDelegate { 2977 class MockAutofillManagerDelegate : public TestAutofillManagerDelegate {
3110 public: 2978 public:
3111 MockAutofillManagerDelegate() 2979 MockAutofillManagerDelegate() {}
3112 : autocheckout_bubble_shown_(false) {}
3113 2980
3114 virtual ~MockAutofillManagerDelegate() {} 2981 virtual ~MockAutofillManagerDelegate() {}
3115 2982
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( 2983 virtual void ShowRequestAutocompleteDialog(
3126 const FormData& form, 2984 const FormData& form,
3127 const GURL& source_url, 2985 const GURL& source_url,
3128 DialogType dialog_type, 2986 DialogType dialog_type,
3129 const base::Callback<void(const FormStructure*, 2987 const base::Callback<void(const FormStructure*,
3130 const std::string&)>& callback) OVERRIDE { 2988 const std::string&)>& callback) OVERRIDE {
3131 callback.Run(user_supplied_data_.get(), "google_transaction_id"); 2989 callback.Run(user_supplied_data_.get(), "google_transaction_id");
3132 } 2990 }
3133 2991
3134 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { 2992 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) {
3135 user_supplied_data_.reset(user_supplied_data.release()); 2993 user_supplied_data_.reset(user_supplied_data.release());
3136 } 2994 }
3137 2995
3138 bool autocheckout_bubble_shown() const {
3139 return autocheckout_bubble_shown_;
3140 }
3141
3142 private: 2996 private:
3143 bool autocheckout_bubble_shown_;
3144 scoped_ptr<FormStructure> user_supplied_data_; 2997 scoped_ptr<FormStructure> user_supplied_data_;
3145 2998
3146 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 2999 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
3147 }; 3000 };
3148 3001
3149 } // namespace 3002 } // namespace
3150 3003
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. 3004 // Test our external delegate is called at the right time.
3211 TEST_F(AutofillManagerTest, TestExternalDelegate) { 3005 TEST_F(AutofillManagerTest, TestExternalDelegate) {
3212 FormData form; 3006 FormData form;
3213 test::CreateTestAddressFormData(&form); 3007 test::CreateTestAddressFormData(&form);
3214 std::vector<FormData> forms(1, form); 3008 std::vector<FormData> forms(1, form);
3215 FormsSeen(forms); 3009 FormsSeen(forms);
3216 const FormFieldData& field = form.fields[0]; 3010 const FormFieldData& field = form.fields[0];
3217 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3011 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3218 3012
3219 EXPECT_TRUE(external_delegate_->on_query_seen()); 3013 EXPECT_TRUE(external_delegate_->on_query_seen());
3220 } 3014 }
3221 3015
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 3016 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698