Chromium Code Reviews| Index: components/autofill/browser/autofill_manager_unittest.cc |
| diff --git a/components/autofill/browser/autofill_manager_unittest.cc b/components/autofill/browser/autofill_manager_unittest.cc |
| index 6584def184cb974d3c6fd24be803b1c4987c44e2..0f18d63394e0ffed7363c7e4fb3c6fece16387dd 100644 |
| --- a/components/autofill/browser/autofill_manager_unittest.cc |
| +++ b/components/autofill/browser/autofill_manager_unittest.cc |
| @@ -204,6 +204,48 @@ class TestPersonalDataManager : public PersonalDataManager { |
| DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| }; |
| +// 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.
|
| +// with a field with autocomplete_attribute specified. |
| +void CreateTestNameFormWithUserSuppliedAttr(FormData* form) { |
| + form->name = ASCIIToUTF16("UserSpecified"); |
| + form->method = ASCIIToUTF16("POST"); |
| + form->origin = GURL("http://myform.com/userspecified.html"); |
| + form->action = GURL("http://myform.com/submit.html"); |
| + form->user_submitted = true; |
| + |
| + FormFieldData field; |
| + autofill_test::CreateTestFormField( |
| + "First Name", "firstname", "", "text", &field); |
| + form->fields.push_back(field); |
| + autofill_test::CreateTestFormField( |
| + "Middle Name", "middlename", "", "text", &field); |
| + form->fields.push_back(field); |
| + autofill_test::CreateTestFormField( |
| + "Last Name", "lastname", "", "text", &field); |
| + form->fields.push_back(field); |
| + field.autocomplete_attribute="cc-type"; |
| + autofill_test::CreateTestFormField( |
| + "cc-type", "cc-type", "", "text", &field); |
| + form->fields.push_back(field); |
| +} |
| + |
| +// Populates |form| with data corresponding to a simple shipping options form. |
| +void CreateTestShippingOptionsFormData(FormData* form) { |
| + form->name = ASCIIToUTF16("Shipping Options"); |
| + form->method = ASCIIToUTF16("POST"); |
| + form->origin = GURL("http://myform.com/shipping.html"); |
| + form->action = GURL("http://myform.com/submit.html"); |
| + form->user_submitted = true; |
| + |
| + FormFieldData field; |
| + autofill_test::CreateTestFormField( |
| + "Shipping1", "option", "option1", "radio", &field); |
| + form->fields.push_back(field); |
| + autofill_test::CreateTestFormField( |
| + "Shipping2", "option", "option2", "radio", &field); |
| + form->fields.push_back(field); |
| +} |
| + |
| // Populates |form| with data corresponding to a simple address form. |
| // Note that this actually appends fields to the form data, which can be useful |
| // for building up more complex test forms. |
| @@ -474,6 +516,14 @@ class TestAutofillManager : public AutofillManager { |
| autofill_enabled_ = autofill_enabled; |
| } |
| + void set_autocheckout_url_prefix(std::string autocheckout_url_prefix) { |
| + autocheckout_url_prefix_ = autocheckout_url_prefix; |
| + } |
| + |
| + virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE { |
| + return autocheckout_url_prefix_; |
| + } |
| + |
| const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& |
| request_autocomplete_results() const { |
| return request_autocomplete_results_; |
| @@ -584,6 +634,10 @@ class TestAutofillManager : public AutofillManager { |
| form_structures()->push_back(form); |
| } |
| + void ClearFormStructures() { |
| + form_structures()->clear(); |
| + } |
| + |
| virtual void ReturnAutocompleteResult( |
| WebFormElement::AutocompleteResult result, |
| const FormData& form_data) OVERRIDE { |
| @@ -601,6 +655,7 @@ class TestAutofillManager : public AutofillManager { |
| bool did_finish_async_form_submit_; |
| bool message_loop_is_running_; |
| + std::string autocheckout_url_prefix_; |
| std::string submitted_form_signature_; |
| std::vector<FieldTypeSet> expected_submitted_field_types_; |
| std::vector<bool> sent_states_; |
| @@ -842,6 +897,48 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
| expected_labels, expected_icons, expected_unique_ids); |
| } |
| +// Test that in the case of Autocheckout, forms seen are in order supplied. |
| +TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) { |
| + FormData shipping_options; |
| + CreateTestShippingOptionsFormData(&shipping_options); |
| + FormData user_supplied; |
| + CreateTestNameFormWithUserSuppliedAttr(&user_supplied); |
| + FormData address; |
| + CreateTestAddressFormData(&address); |
| + |
| + // Push user_supplied before address and observe order changing when |
| + // Autocheckout is not enabled.. |
| + std::vector<FormData> forms; |
| + forms.push_back(shipping_options); |
| + forms.push_back(user_supplied); |
| + forms.push_back(address); |
| + |
| + // Test without enabling Autocheckout. FormStructure should only contain |
| + // form1. Shipping Options form will not qualify as parsable form. |
| + FormsSeen(forms); |
| + std::vector<FormStructure*> form_structures; |
| + form_structures = autofill_manager_->GetFormStructures(); |
| + ASSERT_EQ(2U, form_structures.size()); |
| + ASSERT_EQ("/form.html", |
| + form_structures[0]->source_url().path()); |
| + ASSERT_EQ("/userspecified.html", |
| + form_structures[1]->source_url().path()); |
| + autofill_manager_->ClearFormStructures(); |
| + |
| + // Test after enabling Autocheckout. Order should be shipping_options, |
| + // userspecified and then address form. |
| + autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); |
| + FormsSeen(forms); |
| + form_structures = autofill_manager_->GetFormStructures(); |
| + ASSERT_EQ(3U, form_structures.size()); |
| + ASSERT_EQ("/shipping.html", |
| + form_structures[0]->source_url().path()); |
| + ASSERT_EQ("/userspecified.html", |
| + form_structures[1]->source_url().path()); |
| + ASSERT_EQ("/form.html", |
| + form_structures[2]->source_url().path()); |
| +} |
| + |
| // Test that we return only matching address profile suggestions when the |
| // selected form field has been partially filled out. |
| TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |