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

Unified 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: update comment in test file. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/browser/autofill_manager.h ('k') | components/autofill/browser/form_structure.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..9d9155e9c4ea28dc4a019c97297e31d432180c09 100644
--- a/components/autofill/browser/autofill_manager_unittest.cc
+++ b/components/autofill/browser/autofill_manager_unittest.cc
@@ -204,6 +204,47 @@ class TestPersonalDataManager : public PersonalDataManager {
DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
};
+// Populates |form| with 3 fields and a field with autocomplete attribute.
+void CreateTestFormWithAutocompleteAttribute(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 +515,14 @@ class TestAutofillManager : public AutofillManager {
autofill_enabled_ = autofill_enabled;
}
+ void set_autocheckout_url_prefix(std::string autocheckout_url_prefix) {
Ilya Sherman 2013/03/15 23:37:18 nit: Pass by const-reference.
Raman Kakilate 2013/03/18 16:14:32 Done.
+ 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 +633,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 +654,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 +896,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;
+ CreateTestFormWithAutocompleteAttribute(&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",
Ilya Sherman 2013/03/15 23:37:18 nit: EXPECT_EQ
Raman Kakilate 2013/03/18 16:14:32 Done.
+ form_structures[0]->source_url().path());
Ilya Sherman 2013/03/15 23:37:18 nit: Looks like this fits on the previous line. (
Raman Kakilate 2013/03/18 16:14:32 Done.
+ ASSERT_EQ("/userspecified.html",
Ilya Sherman 2013/03/15 23:37:18 nit: EXPECT_EQ
Raman Kakilate 2013/03/18 16:14:32 Done.
+ 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) {
« 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