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

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

Issue 12852003: Autofill:Autocheckout: Enable looking at all elements for Autocheckout flow (ignoring 3 element lim… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 credit_card = new CreditCard; 198 credit_card = new CreditCard;
199 autofill_test::SetCreditCardInfo(credit_card, "", "", "", ""); 199 autofill_test::SetCreditCardInfo(credit_card, "", "", "", "");
200 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); 200 credit_card->set_guid("00000000-0000-0000-0000-000000000006");
201 credit_cards->push_back(credit_card); 201 credit_cards->push_back(credit_card);
202 } 202 }
203 203
204 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 204 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
205 }; 205 };
206 206
207 // Populates |form| with data corresponding to minimual name form along
Albert Bodenhamer 2013/03/15 17:22:53 spelling of "minimal". I don't understand this co
Raman Kakilate 2013/03/15 17:39:22 Tried to simplify it. PTAL.
208 // with a field with autocomplete_attribute specified.
209 void CreateTestNameFormWithUserSuppliedAttr(FormData* form) {
210 form->name = ASCIIToUTF16("UserSpecified");
211 form->method = ASCIIToUTF16("POST");
212 form->origin = GURL("http://myform.com/userspecified.html");
213 form->action = GURL("http://myform.com/submit.html");
214 form->user_submitted = true;
215
216 FormFieldData field;
217 autofill_test::CreateTestFormField(
218 "First Name", "firstname", "", "text", &field);
219 form->fields.push_back(field);
220 autofill_test::CreateTestFormField(
221 "Middle Name", "middlename", "", "text", &field);
222 form->fields.push_back(field);
223 autofill_test::CreateTestFormField(
224 "Last Name", "lastname", "", "text", &field);
225 form->fields.push_back(field);
226 field.autocomplete_attribute="cc-type";
227 autofill_test::CreateTestFormField(
228 "cc-type", "cc-type", "", "text", &field);
229 form->fields.push_back(field);
230 }
231
232 // Populates |form| with data corresponding to a simple shipping options form.
233 void CreateTestShippingOptionsFormData(FormData* form) {
234 form->name = ASCIIToUTF16("Shipping Options");
235 form->method = ASCIIToUTF16("POST");
236 form->origin = GURL("http://myform.com/shipping.html");
237 form->action = GURL("http://myform.com/submit.html");
238 form->user_submitted = true;
239
240 FormFieldData field;
241 autofill_test::CreateTestFormField(
242 "Shipping1", "option", "option1", "radio", &field);
243 form->fields.push_back(field);
244 autofill_test::CreateTestFormField(
245 "Shipping2", "option", "option2", "radio", &field);
246 form->fields.push_back(field);
247 }
248
207 // Populates |form| with data corresponding to a simple address form. 249 // Populates |form| with data corresponding to a simple address form.
208 // Note that this actually appends fields to the form data, which can be useful 250 // Note that this actually appends fields to the form data, which can be useful
209 // for building up more complex test forms. 251 // for building up more complex test forms.
210 void CreateTestAddressFormData(FormData* form) { 252 void CreateTestAddressFormData(FormData* form) {
211 form->name = ASCIIToUTF16("MyForm"); 253 form->name = ASCIIToUTF16("MyForm");
212 form->method = ASCIIToUTF16("POST"); 254 form->method = ASCIIToUTF16("POST");
213 form->origin = GURL("http://myform.com/form.html"); 255 form->origin = GURL("http://myform.com/form.html");
214 form->action = GURL("http://myform.com/submit.html"); 256 form->action = GURL("http://myform.com/submit.html");
215 form->user_submitted = true; 257 form->user_submitted = true;
216 258
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 message_loop_is_running_(false) { 509 message_loop_is_running_(false) {
468 } 510 }
469 virtual ~TestAutofillManager() {} 511 virtual ~TestAutofillManager() {}
470 512
471 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } 513 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; }
472 514
473 void set_autofill_enabled(bool autofill_enabled) { 515 void set_autofill_enabled(bool autofill_enabled) {
474 autofill_enabled_ = autofill_enabled; 516 autofill_enabled_ = autofill_enabled;
475 } 517 }
476 518
519 void set_autocheckout_url_prefix(std::string autocheckout_url_prefix) {
520 autocheckout_url_prefix_ = autocheckout_url_prefix;
521 }
522
523 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE {
524 return autocheckout_url_prefix_;
525 }
526
477 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& 527 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >&
478 request_autocomplete_results() const { 528 request_autocomplete_results() const {
479 return request_autocomplete_results_; 529 return request_autocomplete_results_;
480 } 530 }
481 531
482 532
483 void set_expected_submitted_field_types( 533 void set_expected_submitted_field_types(
484 const std::vector<FieldTypeSet>& expected_types) { 534 const std::vector<FieldTypeSet>& expected_types) {
485 expected_submitted_field_types_ = expected_types; 535 expected_submitted_field_types_ = expected_types;
486 } 536 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 std::string credit_card_guid = 627 std::string credit_card_guid =
578 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); 628 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id);
579 629
580 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); 630 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0));
581 } 631 }
582 632
583 void AddSeenForm(FormStructure* form) { 633 void AddSeenForm(FormStructure* form) {
584 form_structures()->push_back(form); 634 form_structures()->push_back(form);
585 } 635 }
586 636
637 void ClearFormStructures() {
638 form_structures()->clear();
639 }
640
587 virtual void ReturnAutocompleteResult( 641 virtual void ReturnAutocompleteResult(
588 WebFormElement::AutocompleteResult result, 642 WebFormElement::AutocompleteResult result,
589 const FormData& form_data) OVERRIDE { 643 const FormData& form_data) OVERRIDE {
590 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); 644 request_autocomplete_results_.push_back(std::make_pair(result, form_data));
591 } 645 }
592 646
593 private: 647 private:
594 // Weak reference. 648 // Weak reference.
595 TestPersonalDataManager* personal_data_; 649 TestPersonalDataManager* personal_data_;
596 650
597 bool autofill_enabled_; 651 bool autofill_enabled_;
598 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > 652 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >
599 request_autocomplete_results_; 653 request_autocomplete_results_;
600 654
601 bool did_finish_async_form_submit_; 655 bool did_finish_async_form_submit_;
602 bool message_loop_is_running_; 656 bool message_loop_is_running_;
603 657
658 std::string autocheckout_url_prefix_;
604 std::string submitted_form_signature_; 659 std::string submitted_form_signature_;
605 std::vector<FieldTypeSet> expected_submitted_field_types_; 660 std::vector<FieldTypeSet> expected_submitted_field_types_;
606 std::vector<bool> sent_states_; 661 std::vector<bool> sent_states_;
607 662
608 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 663 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
609 }; 664 };
610 665
611 } // namespace 666 } // namespace
612 667
613 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { 668 class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 ASCIIToUTF16("3734 Elvis Presley Blvd."), 890 ASCIIToUTF16("3734 Elvis Presley Blvd."),
836 ASCIIToUTF16("123 Apple St.") 891 ASCIIToUTF16("123 Apple St.")
837 }; 892 };
838 string16 expected_icons[] = {string16(), string16()}; 893 string16 expected_icons[] = {string16(), string16()};
839 int expected_unique_ids[] = {1, 2}; 894 int expected_unique_ids[] = {1, 2};
840 ExpectSuggestions(page_id, values, labels, icons, unique_ids, 895 ExpectSuggestions(page_id, values, labels, icons, unique_ids,
841 kDefaultPageID, arraysize(expected_values), expected_values, 896 kDefaultPageID, arraysize(expected_values), expected_values,
842 expected_labels, expected_icons, expected_unique_ids); 897 expected_labels, expected_icons, expected_unique_ids);
843 } 898 }
844 899
900 // Test that in the case of Autocheckout, forms seen are in order supplied.
901 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) {
902 FormData shipping_options;
903 CreateTestShippingOptionsFormData(&shipping_options);
904 FormData user_supplied;
905 CreateTestNameFormWithUserSuppliedAttr(&user_supplied);
906 FormData address;
907 CreateTestAddressFormData(&address);
908
909 // Push user_supplied before address and observe order changing when
910 // Autocheckout is not enabled..
911 std::vector<FormData> forms;
912 forms.push_back(shipping_options);
913 forms.push_back(user_supplied);
914 forms.push_back(address);
915
916 // Test without enabling Autocheckout. FormStructure should only contain
917 // form1. Shipping Options form will not qualify as parsable form.
918 FormsSeen(forms);
919 std::vector<FormStructure*> form_structures;
920 form_structures = autofill_manager_->GetFormStructures();
921 ASSERT_EQ(2U, form_structures.size());
922 ASSERT_EQ("/form.html",
923 form_structures[0]->source_url().path());
924 ASSERT_EQ("/userspecified.html",
925 form_structures[1]->source_url().path());
926 autofill_manager_->ClearFormStructures();
927
928 // Test after enabling Autocheckout. Order should be shipping_options,
929 // userspecified and then address form.
930 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout");
931 FormsSeen(forms);
932 form_structures = autofill_manager_->GetFormStructures();
933 ASSERT_EQ(3U, form_structures.size());
934 ASSERT_EQ("/shipping.html",
935 form_structures[0]->source_url().path());
936 ASSERT_EQ("/userspecified.html",
937 form_structures[1]->source_url().path());
938 ASSERT_EQ("/form.html",
939 form_structures[2]->source_url().path());
940 }
941
845 // Test that we return only matching address profile suggestions when the 942 // Test that we return only matching address profile suggestions when the
846 // selected form field has been partially filled out. 943 // selected form field has been partially filled out.
847 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { 944 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) {
848 // Set up our form data. 945 // Set up our form data.
849 FormData form; 946 FormData form;
850 CreateTestAddressFormData(&form); 947 CreateTestAddressFormData(&form);
851 std::vector<FormData> forms(1, form); 948 std::vector<FormData> forms(1, form);
852 FormsSeen(forms); 949 FormsSeen(forms);
853 950
854 FormFieldData field; 951 FormFieldData field;
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3219 3316
3220 FormData form; 3317 FormData form;
3221 CreateTestAddressFormData(&form); 3318 CreateTestAddressFormData(&form);
3222 std::vector<FormData> forms(1, form); 3319 std::vector<FormData> forms(1, form);
3223 FormsSeen(forms); 3320 FormsSeen(forms);
3224 const FormFieldData& field = form.fields[0]; 3321 const FormFieldData& field = form.fields[0];
3225 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3322 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3226 3323
3227 autofill_manager_->SetExternalDelegate(NULL); 3324 autofill_manager_->SetExternalDelegate(NULL);
3228 } 3325 }
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_manager.h ('k') | components/autofill/browser/form_structure.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698