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

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: Review comments and more tests. 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 3 fields and a field with autocomplete attribute.
208 void CreateTestFormWithAutocompleteAttribute(FormData* form) {
209 form->name = ASCIIToUTF16("UserSpecified");
210 form->method = ASCIIToUTF16("POST");
211 form->origin = GURL("http://myform.com/userspecified.html");
212 form->action = GURL("http://myform.com/submit.html");
213 form->user_submitted = true;
214
215 FormFieldData field;
216 autofill_test::CreateTestFormField(
217 "First Name", "firstname", "", "text", &field);
218 form->fields.push_back(field);
219 autofill_test::CreateTestFormField(
220 "Middle Name", "middlename", "", "text", &field);
221 form->fields.push_back(field);
222 autofill_test::CreateTestFormField(
223 "Last Name", "lastname", "", "text", &field);
224 form->fields.push_back(field);
225 field.autocomplete_attribute="cc-type";
226 autofill_test::CreateTestFormField(
227 "cc-type", "cc-type", "", "text", &field);
228 form->fields.push_back(field);
229 }
230
231 // Populates |form| with data corresponding to a simple shipping options form.
232 void CreateTestShippingOptionsFormData(FormData* form) {
233 form->name = ASCIIToUTF16("Shipping Options");
234 form->method = ASCIIToUTF16("POST");
235 form->origin = GURL("http://myform.com/shipping.html");
236 form->action = GURL("http://myform.com/submit.html");
237 form->user_submitted = true;
238
239 FormFieldData field;
240 autofill_test::CreateTestFormField(
241 "Shipping1", "option", "option1", "radio", &field);
242 form->fields.push_back(field);
243 autofill_test::CreateTestFormField(
244 "Shipping2", "option", "option2", "radio", &field);
245 form->fields.push_back(field);
246 }
247
207 // Populates |form| with data corresponding to a simple address form. 248 // 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 249 // Note that this actually appends fields to the form data, which can be useful
209 // for building up more complex test forms. 250 // for building up more complex test forms.
210 void CreateTestAddressFormData(FormData* form) { 251 void CreateTestAddressFormData(FormData* form) {
211 form->name = ASCIIToUTF16("MyForm"); 252 form->name = ASCIIToUTF16("MyForm");
212 form->method = ASCIIToUTF16("POST"); 253 form->method = ASCIIToUTF16("POST");
213 form->origin = GURL("http://myform.com/form.html"); 254 form->origin = GURL("http://myform.com/form.html");
214 form->action = GURL("http://myform.com/submit.html"); 255 form->action = GURL("http://myform.com/submit.html");
215 form->user_submitted = true; 256 form->user_submitted = true;
216 257
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 message_loop_is_running_(false) { 508 message_loop_is_running_(false) {
468 } 509 }
469 virtual ~TestAutofillManager() {} 510 virtual ~TestAutofillManager() {}
470 511
471 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } 512 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; }
472 513
473 void set_autofill_enabled(bool autofill_enabled) { 514 void set_autofill_enabled(bool autofill_enabled) {
474 autofill_enabled_ = autofill_enabled; 515 autofill_enabled_ = autofill_enabled;
475 } 516 }
476 517
477 void set_autocheckout_url_prefix(std::string autocheckout_url_prefix) { 518 void set_autocheckout_url_prefix(const std::string& autocheckout_url_prefix) {
478 autocheckout_url_prefix_ = autocheckout_url_prefix; 519 autocheckout_url_prefix_ = autocheckout_url_prefix;
479 } 520 }
480 521
481 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE { 522 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE {
482 return autocheckout_url_prefix_; 523 return autocheckout_url_prefix_;
483 } 524 }
484 525
485 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& 526 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >&
486 request_autocomplete_results() const { 527 request_autocomplete_results() const {
487 return request_autocomplete_results_; 528 return request_autocomplete_results_;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 std::string credit_card_guid = 626 std::string credit_card_guid =
586 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); 627 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id);
587 628
588 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); 629 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0));
589 } 630 }
590 631
591 void AddSeenForm(FormStructure* form) { 632 void AddSeenForm(FormStructure* form) {
592 form_structures()->push_back(form); 633 form_structures()->push_back(form);
593 } 634 }
594 635
636 void ClearFormStructures() {
637 form_structures()->clear();
638 }
639
595 virtual void ReturnAutocompleteResult( 640 virtual void ReturnAutocompleteResult(
596 WebFormElement::AutocompleteResult result, 641 WebFormElement::AutocompleteResult result,
597 const FormData& form_data) OVERRIDE { 642 const FormData& form_data) OVERRIDE {
598 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); 643 request_autocomplete_results_.push_back(std::make_pair(result, form_data));
599 } 644 }
600 645
601 private: 646 private:
602 // Weak reference. 647 // Weak reference.
603 TestPersonalDataManager* personal_data_; 648 TestPersonalDataManager* personal_data_;
604 649
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 ASCIIToUTF16("3734 Elvis Presley Blvd."), 913 ASCIIToUTF16("3734 Elvis Presley Blvd."),
869 ASCIIToUTF16("123 Apple St.") 914 ASCIIToUTF16("123 Apple St.")
870 }; 915 };
871 string16 expected_icons[] = {string16(), string16()}; 916 string16 expected_icons[] = {string16(), string16()};
872 int expected_unique_ids[] = {1, 2}; 917 int expected_unique_ids[] = {1, 2};
873 ExpectSuggestions(page_id, values, labels, icons, unique_ids, 918 ExpectSuggestions(page_id, values, labels, icons, unique_ids,
874 kDefaultPageID, arraysize(expected_values), expected_values, 919 kDefaultPageID, arraysize(expected_values), expected_values,
875 expected_labels, expected_icons, expected_unique_ids); 920 expected_labels, expected_icons, expected_unique_ids);
876 } 921 }
877 922
923 // Test that in the case of Autocheckout, forms seen are in order supplied.
924 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) {
925 FormData shipping_options;
926 CreateTestShippingOptionsFormData(&shipping_options);
927 FormData user_supplied;
928 CreateTestFormWithAutocompleteAttribute(&user_supplied);
929 FormData address;
930 CreateTestAddressFormData(&address);
931
932 // Push user_supplied before address and observe order changing when
933 // Autocheckout is not enabled..
934 std::vector<FormData> forms;
935 forms.push_back(shipping_options);
936 forms.push_back(user_supplied);
937 forms.push_back(address);
938
939 // Test without enabling Autocheckout. FormStructure should only contain
940 // form1. Shipping Options form will not qualify as parsable form.
941 FormsSeen(forms);
942 std::vector<FormStructure*> form_structures;
943 form_structures = autofill_manager_->GetFormStructures();
944 ASSERT_EQ(2U, form_structures.size());
945 EXPECT_EQ("/form.html", form_structures[0]->source_url().path());
946 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path());
947 autofill_manager_->ClearFormStructures();
948
949 // Test after enabling Autocheckout. Order should be shipping_options,
950 // userspecified and then address form.
951 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout");
952 FormsSeen(forms);
953 form_structures = autofill_manager_->GetFormStructures();
954 ASSERT_EQ(3U, form_structures.size());
955 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path());
956 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path());
957 EXPECT_EQ("/form.html", form_structures[2]->source_url().path());
958 }
959
878 // Test that we return only matching address profile suggestions when the 960 // Test that we return only matching address profile suggestions when the
879 // selected form field has been partially filled out. 961 // selected form field has been partially filled out.
880 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { 962 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) {
881 // Set up our form data. 963 // Set up our form data.
882 FormData form; 964 FormData form;
883 CreateTestAddressFormData(&form); 965 CreateTestAddressFormData(&form);
884 std::vector<FormData> forms(1, form); 966 std::vector<FormData> forms(1, form);
885 FormsSeen(forms); 967 FormsSeen(forms);
886 968
887 FormFieldData field; 969 FormFieldData field;
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3252 3334
3253 FormData form; 3335 FormData form;
3254 CreateTestAddressFormData(&form); 3336 CreateTestAddressFormData(&form);
3255 std::vector<FormData> forms(1, form); 3337 std::vector<FormData> forms(1, form);
3256 FormsSeen(forms); 3338 FormsSeen(forms);
3257 const FormFieldData& field = form.fields[0]; 3339 const FormFieldData& field = form.fields[0];
3258 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3340 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3259 3341
3260 autofill_manager_->SetExternalDelegate(NULL); 3342 autofill_manager_->SetExternalDelegate(NULL);
3261 } 3343 }
OLDNEW
« no previous file with comments | « no previous file | components/autofill/browser/form_structure.cc » ('j') | components/autofill/browser/form_structure.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698