summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_manager_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/autofill/autofill_manager_unittest.cc')
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc1508
1 files changed, 679 insertions, 829 deletions
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 228bbdb..506c7cb 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -32,6 +32,13 @@
#include "webkit/glue/form_field.h"
using webkit_glue::FormData;
+using webkit_glue::FormField;
+
+namespace {
+
+// The page ID sent to the AutoFillManager from the RenderView, used to send
+// an IPC message back to the renderer.
+const int kDefaultPageID = 137;
typedef Tuple5<int,
std::vector<string16>,
@@ -53,8 +60,17 @@ class TestPersonalDataManager : public PersonalDataManager {
AutoFillProfile* GetLabeledProfile(const char* label) {
for (std::vector<AutoFillProfile *>::iterator it = web_profiles_.begin();
it != web_profiles_.end(); ++it) {
- if (!(*it)->Label().compare(ASCIIToUTF16(label)))
- return *it;
+ if (!(*it)->Label().compare(ASCIIToUTF16(label)))
+ return *it;
+ }
+ return NULL;
+ }
+
+ CreditCard* GetLabeledCreditCard(const char* label) {
+ for (std::vector<CreditCard *>::iterator it = credit_cards_.begin();
+ it != credit_cards_.end(); ++it) {
+ if (!(*it)->Label().compare(ASCIIToUTF16(label)))
+ return *it;
}
return NULL;
}
@@ -118,62 +134,6 @@ class TestPersonalDataManager : public PersonalDataManager {
DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
};
-class TestAutoFillManager : public AutoFillManager {
- public:
- TestAutoFillManager(TabContents* tab_contents,
- TestPersonalDataManager* personal_manager)
- : AutoFillManager(tab_contents, NULL),
- autofill_enabled_(true) {
- test_personal_data_ = personal_manager;
- set_personal_data_manager(personal_manager);
- // Download manager requests are disabled for purposes of this unit-test.
- // These request are tested in autofill_download_unittest.cc.
- set_disable_download_manager_requests(true);
- }
-
- virtual bool IsAutoFillEnabled() const { return autofill_enabled_; }
-
- void set_autofill_enabled(bool autofill_enabled) {
- autofill_enabled_ = autofill_enabled;
- }
-
- AutoFillProfile* GetLabeledProfile(const char* label) {
- return test_personal_data_->GetLabeledProfile(label);
- }
-
- void AddProfile(AutoFillProfile* profile) {
- test_personal_data_->AddProfile(profile);
- }
-
- int GetPackedCreditCardID(int credit_card_id) {
- return PackGUIDs(IDToGUID(credit_card_id), std::string());
- }
-
- protected:
- virtual int GUIDToID(const std::string& guid) OVERRIDE {
- if (guid.empty())
- return 0;
-
- int id;
- EXPECT_TRUE(base::StringToInt(guid.substr(guid.rfind("-") + 1), &id));
- return id;
- }
-
- virtual const std::string IDToGUID(int id) OVERRIDE {
- EXPECT_TRUE(id >= 0);
- if (id <= 0)
- return std::string();
-
- return base::StringPrintf("00000000-0000-0000-0000-%012d", id);
- }
-
- private:
- TestPersonalDataManager* test_personal_data_;
- bool autofill_enabled_;
-
- DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager);
-};
-
// 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.
@@ -184,7 +144,7 @@ void CreateTestAddressFormData(FormData* form) {
form->action = GURL("http://myform.com/submit.html");
form->user_submitted = true;
- webkit_glue::FormField field;
+ FormField field;
autofill_test::CreateTestFormField(
"First Name", "firstname", "", "text", &field);
form->fields.push_back(field);
@@ -216,6 +176,9 @@ void CreateTestAddressFormData(FormData* form) {
"Phone Number", "phonenumber", "", "text", &field);
form->fields.push_back(field);
autofill_test::CreateTestFormField(
+ "Fax", "fax", "", "text", &field);
+ form->fields.push_back(field);
+ autofill_test::CreateTestFormField(
"Email", "email", "", "text", &field);
form->fields.push_back(field);
}
@@ -235,7 +198,7 @@ void CreateTestCreditCardFormData(FormData* form, bool is_https) {
}
form->user_submitted = true;
- webkit_glue::FormField field;
+ FormField field;
autofill_test::CreateTestFormField(
"Name on Card", "nameoncard", "", "text", &field);
form->fields.push_back(field);
@@ -250,6 +213,218 @@ void CreateTestCreditCardFormData(FormData* form, bool is_https) {
form->fields.push_back(field);
}
+void ExpectSuggestions(int page_id,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& unique_ids,
+ int expected_page_id,
+ size_t expected_num_suggestions,
+ const string16 expected_values[],
+ const string16 expected_labels[],
+ const string16 expected_icons[],
+ const int expected_unique_ids[]) {
+ EXPECT_EQ(expected_page_id, page_id);
+ ASSERT_EQ(expected_num_suggestions, values.size());
+ ASSERT_EQ(expected_num_suggestions, labels.size());
+ ASSERT_EQ(expected_num_suggestions, icons.size());
+ ASSERT_EQ(expected_num_suggestions, unique_ids.size());
+ for (size_t i = 0; i < expected_num_suggestions; ++i) {
+ SCOPED_TRACE(StringPrintf("i: %" PRIuS, i));
+ EXPECT_EQ(expected_values[i], values[i]);
+ EXPECT_EQ(expected_labels[i], labels[i]);
+ EXPECT_EQ(expected_icons[i], icons[i]);
+ EXPECT_EQ(expected_unique_ids[i], unique_ids[i]);
+ }
+}
+
+// Verifies that the |filled_form| has been filled with the given data.
+// Verifies address fields if |has_address_fields| is true, and verifies
+// credit card fields if |has_credit_card_fields| is true. Verifies both if both
+// are true.
+void ExpectFilledForm(int page_id,
+ const FormData& filled_form,
+ int expected_page_id,
+ const char* first,
+ const char* middle,
+ const char* last,
+ const char* address1,
+ const char* address2,
+ const char* city,
+ const char* state,
+ const char* postal_code,
+ const char* country,
+ const char* phone,
+ const char* fax,
+ const char* email,
+ const char* name_on_card,
+ const char* card_number,
+ const char* expiration_month,
+ const char* expiration_year,
+ bool has_address_fields,
+ bool has_credit_card_fields) {
+ // The number of fields in the address and credit card forms created above.
+ const size_t kAddressFormSize = 12;
+ const size_t kCreditCardFormSize = 4;
+
+ EXPECT_EQ(expected_page_id, page_id);
+ EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name);
+ EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method);
+ if (has_credit_card_fields) {
+ EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin);
+ EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action);
+ } else {
+ EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin);
+ EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action);
+ }
+ EXPECT_TRUE(filled_form.user_submitted);
+
+ size_t form_size = 0;
+ if (has_address_fields)
+ form_size += kAddressFormSize;
+ if (has_credit_card_fields)
+ form_size += kCreditCardFormSize;
+ ASSERT_EQ(form_size, filled_form.fields.size());
+
+ FormField field;
+ if (has_address_fields) {
+ autofill_test::CreateTestFormField(
+ "First Name", "firstname", first, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[0]));
+ autofill_test::CreateTestFormField(
+ "Middle Name", "middlename", middle, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[1]));
+ autofill_test::CreateTestFormField(
+ "Last Name", "lastname", last, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[2]));
+ autofill_test::CreateTestFormField(
+ "Address Line 1", "addr1", address1, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[3]));
+ autofill_test::CreateTestFormField(
+ "Address Line 2", "addr2", address2, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[4]));
+ autofill_test::CreateTestFormField(
+ "City", "city", city, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[5]));
+ autofill_test::CreateTestFormField(
+ "State", "state", state, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[6]));
+ autofill_test::CreateTestFormField(
+ "Postal Code", "zipcode", postal_code, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[7]));
+ autofill_test::CreateTestFormField(
+ "Country", "country", country, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8]));
+ autofill_test::CreateTestFormField(
+ "Phone Number", "phonenumber", phone, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9]));
+ autofill_test::CreateTestFormField(
+ "Fax", "fax", fax, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10]));
+ autofill_test::CreateTestFormField(
+ "Email", "email", email, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11]));
+ }
+
+ if (has_credit_card_fields) {
+ size_t offset = has_address_fields? kAddressFormSize : 0;
+ autofill_test::CreateTestFormField(
+ "Name on Card", "nameoncard", name_on_card, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0]));
+ autofill_test::CreateTestFormField(
+ "Card Number", "cardnumber", card_number, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1]));
+ autofill_test::CreateTestFormField(
+ "Expiration Date", "ccmonth", expiration_month, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2]));
+ autofill_test::CreateTestFormField(
+ "", "ccyear", expiration_year, "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3]));
+ }
+}
+
+void ExpectFilledAddressFormElvis(int page_id,
+ const FormData& filled_form,
+ int expected_page_id,
+ bool has_credit_card_fields) {
+ ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron",
+ "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis",
+ "Tennessee", "38116", "USA", "12345678901", "",
+ "theking@gmail.com", "", "", "", "", true,
+ has_credit_card_fields);
+}
+
+void ExpectFilledCreditCardFormElvis(int page_id,
+ const FormData& filled_form,
+ int expected_page_id,
+ bool has_address_fields) {
+ ExpectFilledForm(page_id, filled_form, expected_page_id,
+ "", "", "", "", "", "", "", "", "", "", "", "",
+ "Elvis Presley", "4234567890123456", "04", "2012",
+ has_address_fields, true);
+}
+
+} // namespace
+
+class TestAutoFillManager : public AutoFillManager {
+ public:
+ TestAutoFillManager(TabContents* tab_contents,
+ TestPersonalDataManager* personal_manager)
+ : AutoFillManager(tab_contents, NULL),
+ autofill_enabled_(true) {
+ test_personal_data_ = personal_manager;
+ set_personal_data_manager(personal_manager);
+ // Download manager requests are disabled for purposes of this unit test.
+ // These requests are tested in autofill_download_unittest.cc.
+ set_disable_download_manager_requests(true);
+ }
+
+ virtual bool IsAutoFillEnabled() const { return autofill_enabled_; }
+
+ void set_autofill_enabled(bool autofill_enabled) {
+ autofill_enabled_ = autofill_enabled;
+ }
+
+ AutoFillProfile* GetLabeledProfile(const char* label) {
+ return test_personal_data_->GetLabeledProfile(label);
+ }
+
+ CreditCard* GetLabeledCreditCard(const char* label) {
+ return test_personal_data_->GetLabeledCreditCard(label);
+ }
+
+ void AddProfile(AutoFillProfile* profile) {
+ test_personal_data_->AddProfile(profile);
+ }
+
+ int GetPackedCreditCardID(int credit_card_id) {
+ return PackGUIDs(IDToGUID(credit_card_id), std::string());
+ }
+
+ virtual int GUIDToID(const std::string& guid) OVERRIDE {
+ if (guid.empty())
+ return 0;
+
+ int id;
+ EXPECT_TRUE(base::StringToInt(guid.substr(guid.rfind("-") + 1), &id));
+ return id;
+ }
+
+ virtual const std::string IDToGUID(int id) OVERRIDE {
+ EXPECT_TRUE(id >= 0);
+ if (id <= 0)
+ return std::string();
+
+ return base::StringPrintf("00000000-0000-0000-0000-%012d", id);
+ }
+
+ private:
+ TestPersonalDataManager* test_personal_data_;
+ bool autofill_enabled_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager);
+};
+
class AutoFillManagerTest : public RenderViewHostTestHarness {
public:
AutoFillManagerTest() {}
@@ -321,23 +496,15 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
// Test that we return all address profile suggestions when all form fields are
// empty.
TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ const FormField& field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -351,43 +518,38 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
- ASSERT_EQ(2U, labels.size());
- // Inferred labels now include full first relevant field, which in this case
- // the address #1.
- EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(1, unique_ids[0]);
- EXPECT_EQ(2, unique_ids[1]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Charles")
+ };
+ // Inferred labels include full first relevant field, which in this case is
+ // the address line 1.
+ string16 expected_labels[] = {
+ ASCIIToUTF16("3734 Elvis Presley Blvd."),
+ ASCIIToUTF16("123 Apple St.")
+ };
+ string16 expected_icons[] = {string16(), string16()};
+ int expected_unique_ids[] = {1, 2};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we return only matching address profile suggestions when the
// selected form field has been partially filled out.
TEST_F(AutoFillManagerTest, GetProfileSuggestionsMatchCharacter) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "E", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ FormField field;
+ autofill_test::CreateTestFormField("First Name", "firstname", "E", "text",
+ &field);
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -401,19 +563,19 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMatchCharacter) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(1U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
- ASSERT_EQ(1U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]);
- ASSERT_EQ(1U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- ASSERT_EQ(1U, unique_ids.size());
- EXPECT_EQ(1, unique_ids[0]);
+
+ string16 expected_values[] = {ASCIIToUTF16("Elvis")};
+ string16 expected_labels[] = {ASCIIToUTF16("3734 Elvis Presley Blvd.")};
+ string16 expected_icons[] = {string16()};
+ int expected_unique_ids[] = {1};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we return no suggestions when the form has no relevant fields.
TEST_F(AutoFillManagerTest, GetProfileSuggestionsUnknownFields) {
+ // Set up our form data.
FormData form;
form.name = ASCIIToUTF16("MyForm");
form.method = ASCIIToUTF16("POST");
@@ -421,81 +583,54 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsUnknownFields) {
form.action = GURL("http://myform.com/submit.html");
form.user_submitted = true;
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "Username", "username", "", "text", &field);
+ FormField field;
+ autofill_test::CreateTestFormField("Username", "username", "", "text",
+ &field);
form.fields.push_back(field);
- autofill_test::CreateTestFormField(
- "Password", "password", "", "password", &field);
+ autofill_test::CreateTestFormField("Password", "password", "", "password",
+ &field);
form.fields.push_back(field);
- autofill_test::CreateTestFormField(
- "Quest", "quest", "", "quest", &field);
+ autofill_test::CreateTestFormField("Quest", "quest", "", "quest", &field);
form.fields.push_back(field);
- autofill_test::CreateTestFormField(
- "Color", "color", "", "text", &field);
+ autofill_test::CreateTestFormField("Color", "color", "", "text", &field);
form.fields.push_back(field);
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- autofill_test::CreateTestFormField(
- "Username", "username", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_FALSE(
- autofill_manager_->GetAutoFillSuggestions(false, field));
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
}
// Test that we return no suggestions when autofill is disabled.
TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
// Disable AutoFill.
autofill_manager_->set_autofill_enabled(false);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ const FormField& field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
}
// Test that we return a warning explaining that autofill suggestions are
// unavailable when the form method is GET rather than POST.
TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
form.method = ASCIIToUTF16("GET");
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ const FormField& field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -509,23 +644,23 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(1U, values.size());
- EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED),
- values[0]);
- ASSERT_EQ(1U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- ASSERT_EQ(1U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- ASSERT_EQ(1U, unique_ids.size());
- EXPECT_EQ(-1, unique_ids[0]);
+
+ string16 expected_values[] = {
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)
+ };
+ string16 expected_labels[] = {string16()};
+ string16 expected_icons[] = {string16()};
+ int expected_unique_ids[] = {-1};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
// Now add some Autocomplete suggestions. We should return the autocomplete
// suggestions and the warning; these will be culled by the renderer.
process()->sink().ClearMessages();
const int kPageID2 = 2;
rvh()->ResetAutoFillState(kPageID2);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
std::vector<string16> suggestions;
suggestions.push_back(ASCIIToUTF16("Jay"));
@@ -534,50 +669,36 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID2, page_id);
- ASSERT_EQ(3U, values.size());
- EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED),
- values[0]);
- EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]);
- EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]);
- ASSERT_EQ(3U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
- EXPECT_EQ(string16(), labels[2]);
- ASSERT_EQ(3U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- EXPECT_EQ(string16(), icons[2]);
- ASSERT_EQ(3U, unique_ids.size());
- EXPECT_EQ(-1, unique_ids[0]);
- EXPECT_EQ(0, unique_ids[1]);
- EXPECT_EQ(0, unique_ids[2]);
+
+ string16 expected_values2[] = {
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED),
+ ASCIIToUTF16("Jay"),
+ ASCIIToUTF16("Jason")
+ };
+ string16 expected_labels2[] = {string16(), string16(), string16()};
+ string16 expected_icons2[] = {string16(), string16(), string16()};
+ int expected_unique_ids2[] = {-1, 0, 0};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kPageID2, arraysize(expected_values2), expected_values2,
+ expected_labels2, expected_icons2, expected_unique_ids2);
// Now clear the test profiles and try again -- we shouldn't return a warning.
test_personal_data_->ClearAutoFillProfiles();
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
}
// Test that we return all credit card profile suggestions when all form fields
// are empty.
TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
+ // Set up our form data.
FormData form;
CreateTestCreditCardFormData(&form, true);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "Card Number", "cardnumber", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ FormField field = form.fields[1];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -591,41 +712,39 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]);
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]);
- EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]);
- EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(5), unique_ids[1]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("************3456"),
+ ASCIIToUTF16("************8765")
+ };
+ string16 expected_labels[] = {ASCIIToUTF16("*3456"), ASCIIToUTF16("*8765")};
+ string16 expected_icons[] = {
+ ASCIIToUTF16("visaCC"),
+ ASCIIToUTF16("masterCardCC")
+ };
+ int expected_unique_ids[] = {
+ autofill_manager_->GetPackedCreditCardID(4),
+ autofill_manager_->GetPackedCreditCardID(5)
+ };
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we return only matching credit card profile suggestions when the
// selected form field has been partially filled out.
TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
+ // Set up our form data.
FormData form;
CreateTestCreditCardFormData(&form, true);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
+ FormField field;
autofill_test::CreateTestFormField(
"Card Number", "cardnumber", "4", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -639,37 +758,28 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(1U, values.size());
- EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]);
- ASSERT_EQ(1U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]);
- ASSERT_EQ(1U, icons.size());
- EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]);
- ASSERT_EQ(1U, unique_ids.size());
- EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]);
+
+ string16 expected_values[] = {ASCIIToUTF16("************3456")};
+ string16 expected_labels[] = {ASCIIToUTF16("*3456")};
+ string16 expected_icons[] = {ASCIIToUTF16("visaCC")};
+ int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we return credit card profile suggestions when the selected form
// field is not the credit card number field.
TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
+ // Set up our form data.
FormData form;
CreateTestCreditCardFormData(&form, true);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "Name on Card", "nameoncard", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ const FormField& field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -683,41 +793,37 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]);
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]);
- EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]);
- EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(5), unique_ids[1]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("Elvis Presley"),
+ ASCIIToUTF16("Buddy Holly")
+ };
+ string16 expected_labels[] = {ASCIIToUTF16("*3456"), ASCIIToUTF16("*8765")};
+ string16 expected_icons[] = {
+ ASCIIToUTF16("visaCC"),
+ ASCIIToUTF16("masterCardCC")
+ };
+ int expected_unique_ids[] = {
+ autofill_manager_->GetPackedCreditCardID(4),
+ autofill_manager_->GetPackedCreditCardID(5)
+ };
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we return a warning explaining that credit card profile suggestions
// are unavailable when the form is not https.
TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
+ // Set up our form data.
FormData form;
CreateTestCreditCardFormData(&form, false);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "Card Number", "cardnumber", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ const FormField& field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -731,23 +837,23 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(1U, values.size());
- EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
- values[0]);
- ASSERT_EQ(1U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- ASSERT_EQ(1U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- ASSERT_EQ(1U, unique_ids.size());
- EXPECT_EQ(-1, unique_ids[0]);
+
+ string16 expected_values[] = {
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION)
+ };
+ string16 expected_labels[] = {string16()};
+ string16 expected_icons[] = {string16()};
+ int expected_unique_ids[] = {-1};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
// Now add some Autocomplete suggestions. We should show the autocomplete
// suggestions and the warning.
process()->sink().ClearMessages();
const int kPageID2 = 2;
rvh()->ResetAutoFillState(kPageID2);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
std::vector<string16> suggestions;
suggestions.push_back(ASCIIToUTF16("Jay"));
@@ -756,50 +862,35 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID2, page_id);
- ASSERT_EQ(3U, values.size());
- EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
- values[0]);
- EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]);
- EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]);
- ASSERT_EQ(3U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
- EXPECT_EQ(string16(), labels[2]);
- ASSERT_EQ(3U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- EXPECT_EQ(string16(), icons[2]);
- ASSERT_EQ(3U, unique_ids.size());
- EXPECT_EQ(-1, unique_ids[0]);
- EXPECT_EQ(0, unique_ids[1]);
- EXPECT_EQ(0, unique_ids[2]);
+ string16 expected_values2[] = {
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
+ ASCIIToUTF16("Jay"),
+ ASCIIToUTF16("Jason")
+ };
+ string16 expected_labels2[] = {string16(), string16(), string16()};
+ string16 expected_icons2[] = {string16(), string16(), string16()};
+ int expected_unique_ids2[] = {-1, 0, 0};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kPageID2, arraysize(expected_values2), expected_values2,
+ expected_labels2, expected_icons2, expected_unique_ids2);
// Clear the test credit cards and try again -- we shouldn't return a warning.
test_personal_data_->ClearCreditCards();
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
}
// Test that we return profile and credit card suggestions for combined forms.
TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, true);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ FormField field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -813,27 +904,27 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
- ASSERT_EQ(2U, labels.size());
- // Inferred labels now include full first relevant field, which in this case
- // the address #1.
- EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(1, unique_ids[0]);
- EXPECT_EQ(2, unique_ids[1]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Charles")
+ };
+ string16 expected_labels[] = {
+ ASCIIToUTF16("3734 Elvis Presley Blvd."),
+ ASCIIToUTF16("123 Apple St.")
+ };
+ string16 expected_icons[] = {string16(), string16()};
+ int expected_unique_ids[] = {1, 2};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
process()->sink().ClearMessages();
+ const int kPageID2 = 2;
autofill_test::CreateTestFormField(
"Card Number", "cardnumber", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ rvh()->ResetAutoFillState(kPageID2);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -843,19 +934,23 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
page_id = 0;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]);
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]);
- EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]);
- EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(5), unique_ids[1]);
+
+ string16 expected_values2[] = {
+ ASCIIToUTF16("************3456"),
+ ASCIIToUTF16("************8765")
+ };
+ string16 expected_labels2[] = {ASCIIToUTF16("*3456"), ASCIIToUTF16("*8765")};
+ string16 expected_icons2[] = {
+ ASCIIToUTF16("visaCC"),
+ ASCIIToUTF16("masterCardCC")
+ };
+ int expected_unique_ids2[] = {
+ autofill_manager_->GetPackedCreditCardID(4),
+ autofill_manager_->GetPackedCreditCardID(5)
+ };
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kPageID2, arraysize(expected_values2), expected_values2,
+ expected_labels2, expected_icons2, expected_unique_ids2);
}
// Test that for non-https forms with both address and credit card fields, we
@@ -863,24 +958,16 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
// should return a warning explaining that credit card profile suggestions are
// unavailable when the form is not https.
TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, false);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ FormField field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -894,27 +981,27 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
- ASSERT_EQ(2U, labels.size());
- // Inferred labels now include full first relevant field, which in this case
- // the address #1.
- EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(1, unique_ids[0]);
- EXPECT_EQ(2, unique_ids[1]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Charles")
+ };
+ string16 expected_labels[] = {
+ ASCIIToUTF16("3734 Elvis Presley Blvd."),
+ ASCIIToUTF16("123 Apple St.")
+ };
+ string16 expected_icons[] = {string16(), string16()};
+ int expected_unique_ids[] = {1, 2};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
process()->sink().ClearMessages();
autofill_test::CreateTestFormField(
"Card Number", "cardnumber", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ const int kPageID2 = 2;
+ rvh()->ResetAutoFillState(kPageID2);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -923,41 +1010,33 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
// Test that we sent the right message to the renderer.
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(1U, values.size());
- EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
- values[0]);
- ASSERT_EQ(1U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- ASSERT_EQ(1U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- ASSERT_EQ(1U, unique_ids.size());
- EXPECT_EQ(-1, unique_ids[0]);
+
+ string16 expected_values2[] = {
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION)
+ };
+ string16 expected_labels2[] = {string16()};
+ string16 expected_icons2[] = {string16()};
+ int expected_unique_ids2[] = {-1};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kPageID2, arraysize(expected_values2), expected_values2,
+ expected_labels2, expected_icons2, expected_unique_ids2);
// Clear the test credit cards and try again -- we shouldn't return a warning.
test_personal_data_->ClearCreditCards();
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
}
// Test that we correctly combine autofill and autocomplete suggestions.
TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
+ const FormField& field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// Add some Autocomplete suggestions.
// This triggers the combined message send.
@@ -976,49 +1055,40 @@ TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(4U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
- EXPECT_EQ(ASCIIToUTF16("Jay"), values[2]);
- EXPECT_EQ(ASCIIToUTF16("Jason"), values[3]);
- ASSERT_EQ(4U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]);
- EXPECT_EQ(string16(), labels[2]);
- EXPECT_EQ(string16(), labels[3]);
- ASSERT_EQ(4U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- EXPECT_EQ(string16(), icons[2]);
- EXPECT_EQ(string16(), icons[3]);
- ASSERT_EQ(4U, unique_ids.size());
- EXPECT_EQ(1, unique_ids[0]);
- EXPECT_EQ(2, unique_ids[1]);
- EXPECT_EQ(0, unique_ids[2]);
- EXPECT_EQ(0, unique_ids[3]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Charles"),
+ ASCIIToUTF16("Jay"),
+ ASCIIToUTF16("Jason")
+ };
+ string16 expected_labels[] = {
+ ASCIIToUTF16("3734 Elvis Presley Blvd."),
+ ASCIIToUTF16("123 Apple St."),
+ string16(),
+ string16()
+ };
+ string16 expected_icons[] = {string16(), string16(), string16(), string16()};
+ int expected_unique_ids[] = {1, 2, 0, 0};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we return autocomplete-like suggestions when trying to autofill
-// already filled fields.
-TEST_F(AutoFillManagerTest, GetFieldSuggestionsFieldIsAutoFilled) {
+// already filled forms.
+TEST_F(AutoFillManagerTest, GetFieldSuggestionsWhenFormIsAutoFilled) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field));
+ // Mark one of the fields as filled.
+ form.fields[2].set_autofilled(true);
+ const FormField& field = form.fields[0];
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -1032,41 +1102,33 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsFieldIsAutoFilled) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(1, unique_ids[0]);
- EXPECT_EQ(2, unique_ids[1]);
+ string16 expected_values[] = {
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Charles")
+ };
+ string16 expected_labels[] = {string16(), string16()};
+ string16 expected_icons[] = {string16(), string16()};
+ int expected_unique_ids[] = {1, 2};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that nothing breaks when there are autocomplete suggestions but no
// autofill suggestions.
TEST_F(AutoFillManagerTest, GetFieldSuggestionsForAutocompleteOnly) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
- autofill_manager_->FormsSeen(forms);
-
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
+ FormField field;
autofill_test::CreateTestFormField(
"Some Field", "somefield", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(true, field));
+ form.fields.push_back(field);
+ std::vector<FormData> forms(1, form);
+ autofill_manager_->FormsSeen(forms);
+
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
// Add some Autocomplete suggestions.
// This triggers the combined message send.
@@ -1083,30 +1145,26 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsForAutocompleteOnly) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("one"), values[0]);
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("two"), values[1]);
- EXPECT_EQ(string16(), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(0, unique_ids[0]);
- EXPECT_EQ(0, unique_ids[1]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("one"),
+ ASCIIToUTF16("two")
+ };
+ string16 expected_labels[] = {string16(), string16()};
+ string16 expected_icons[] = {string16(), string16()};
+ int expected_unique_ids[] = {0, 0};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we do not return duplicate values drawn from multiple profiles when
// filling an already filled field.
TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
// |profile| will be owned by the mock PersonalDataManager.
@@ -1116,15 +1174,10 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
profile->set_guid("00000000-0000-0000-0000-000000000101");
autofill_manager_->AddProfile(profile);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field));
+ FormField& field = form.fields[0];
+ field.set_autofilled(true);
+ rvh()->ResetAutoFillState(kDefaultPageID);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
@@ -1138,296 +1191,173 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
std::vector<int> unique_ids;
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
- EXPECT_EQ(kPageID, page_id);
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
- ASSERT_EQ(2U, icons.size());
- EXPECT_EQ(string16(), icons[0]);
- EXPECT_EQ(string16(), icons[1]);
- ASSERT_EQ(2U, unique_ids.size());
- EXPECT_EQ(1, unique_ids[0]);
- EXPECT_EQ(2, unique_ids[1]);
+
+ string16 expected_values[] = {
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Charles")
+ };
+ string16 expected_labels[] = {string16(), string16()};
+ string16 expected_icons[] = {string16(), string16()};
+ int expected_unique_ids[] = {1, 2};
+ ExpectSuggestions(page_id, values, labels, icons, unique_ids,
+ kDefaultPageID, arraysize(expected_values), expected_values,
+ expected_labels, expected_icons, expected_unique_ids);
}
// Test that we correctly fill an address form.
TEST_F(AutoFillManagerTest, FillAddressForm) {
- // |profile| will be owned by the mock PersonalDataManager.
- AutoFillProfile* profile = new AutoFillProfile;
- autofill_test::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely",
- "flatlander@gmail.com", "MCA",
- "916 16th St.", "Apt. 6", "Lubbock",
- "Texas", "79401", "USA",
- "12345678901", "");
- profile->set_guid("00000000-0000-0000-0000-000000000007");
- autofill_manager_->AddProfile(profile);
-
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
+ std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- kPageID, form, autofill_manager_->PackGUIDs(std::string(),
- profile->guid())));
+ kDefaultPageID, form, form.fields[0],
+ autofill_manager_->PackGUIDs(std::string(), guid)));
int page_id = 0;
FormData results;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
- EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name);
- EXPECT_EQ(ASCIIToUTF16("POST"), results.method);
- EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin);
- EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action);
- ASSERT_EQ(11U, results.fields.size());
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "Joe", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
- autofill_test::CreateTestFormField(
- "Middle Name", "middlename", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
- autofill_test::CreateTestFormField(
- "Last Name", "lastname", "Ely", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
- autofill_test::CreateTestFormField(
- "Address Line 1", "addr1", "916 16th St.", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
- autofill_test::CreateTestFormField(
- "Address Line 2", "addr2", "Apt. 6", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4]));
- autofill_test::CreateTestFormField(
- "City", "city", "Lubbock", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5]));
- autofill_test::CreateTestFormField(
- "State", "state", "Texas", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6]));
- autofill_test::CreateTestFormField(
- "Postal Code", "zipcode", "79401", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7]));
- autofill_test::CreateTestFormField(
- "Country", "country", "USA", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8]));
- autofill_test::CreateTestFormField(
- "Phone Number", "phonenumber", "12345678901", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9]));
- autofill_test::CreateTestFormField(
- "Email", "email", "flatlander@gmail.com", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10]));
+ ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false);
}
// Test that we correctly fill a credit card form.
TEST_F(AutoFillManagerTest, FillCreditCardForm) {
+ // Set up our form data.
FormData form;
CreateTestCreditCardFormData(&form, true);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
+ std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- kPageID, form,
- autofill_manager_->PackGUIDs("00000000-0000-0000-0000-000000000004",
- std::string())));
+ kDefaultPageID, form, *form.fields.begin(),
+ autofill_manager_->PackGUIDs(guid, std::string())));
int page_id = 0;
FormData results;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
- EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name);
- EXPECT_EQ(ASCIIToUTF16("POST"), results.method);
- EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin);
- EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action);
- ASSERT_EQ(4U, results.fields.size());
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "Name on Card", "nameoncard", "Elvis Presley", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
- autofill_test::CreateTestFormField(
- "Card Number", "cardnumber", "4234567890123456", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
- autofill_test::CreateTestFormField(
- "Expiration Date", "ccmonth", "04", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
- autofill_test::CreateTestFormField(
- "", "ccyear", "2012", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
+ ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false);
}
// Test that we correctly fill a combined address and credit card form.
TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) {
- // |profile| will be owned by the mock PersonalDataManager.
- AutoFillProfile* profile = new AutoFillProfile;
- autofill_test::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely",
- "flatlander@gmail.com", "MCA",
- "916 16th St.", "Apt. 6", "Lubbock",
- "Texas", "79401", "USA",
- "12345678901", "");
- profile->set_guid("00000000-0000-0000-0000-000000000008");
- autofill_manager_->AddProfile(profile);
-
+ // Set up our form data.
FormData form;
CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, true);
-
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
// First fill the address data.
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
+ std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- kPageID, form,
- autofill_manager_->PackGUIDs(std::string(),
- "00000000-0000-0000-0000-000000000008")));
+ kDefaultPageID, form, form.fields[0],
+ autofill_manager_->PackGUIDs(std::string(), guid)));
int page_id = 0;
FormData results;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
- EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name);
- EXPECT_EQ(ASCIIToUTF16("POST"), results.method);
- EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin);
- EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action);
- ASSERT_EQ(15U, results.fields.size());
-
- webkit_glue::FormField field;
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "Joe", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
- autofill_test::CreateTestFormField(
- "Middle Name", "middlename", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
- autofill_test::CreateTestFormField(
- "Last Name", "lastname", "Ely", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
- autofill_test::CreateTestFormField(
- "Address Line 1", "addr1", "916 16th St.", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
- autofill_test::CreateTestFormField(
- "Address Line 2", "addr2", "Apt. 6", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4]));
- autofill_test::CreateTestFormField(
- "City", "city", "Lubbock", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5]));
- autofill_test::CreateTestFormField(
- "State", "state", "Texas", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6]));
- autofill_test::CreateTestFormField(
- "Postal Code", "zipcode", "79401", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7]));
- autofill_test::CreateTestFormField(
- "Country", "country", "USA", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8]));
- autofill_test::CreateTestFormField(
- "Phone Number", "phonenumber", "12345678901", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9]));
- autofill_test::CreateTestFormField(
- "Email", "email", "flatlander@gmail.com", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10]));
- autofill_test::CreateTestFormField(
- "Name on Card", "nameoncard", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11]));
- autofill_test::CreateTestFormField(
- "Card Number", "cardnumber", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12]));
- autofill_test::CreateTestFormField(
- "Expiration Date", "ccmonth", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13]));
- autofill_test::CreateTestFormField(
- "", "ccyear", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14]));
+ {
+ SCOPED_TRACE("Address");
+ ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, true);
+ }
// Now fill the credit card data.
process()->sink().ClearMessages();
+ const int kPageID2 = 2;
+ guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- kPageID, form,
- autofill_manager_->PackGUIDs("00000000-0000-0000-0000-000000000004",
- std::string())));
+ kPageID2, form, form.fields.back(),
+ autofill_manager_->PackGUIDs(guid, std::string())));
+
+ page_id = 0;
+ EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
+ {
+ SCOPED_TRACE("Credit card");
+ ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true);
+ }
+}
+// Test that we correctly fill a previously auto-filled form.
+TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
+ // Set up our form data.
+ FormData form;
+ CreateTestAddressFormData(&form);
+ // Mark one of the address fields as autofilled.
+ form.fields[4].set_autofilled(true);
+ CreateTestCreditCardFormData(&form, true);
+ std::vector<FormData> forms(1, form);
+ autofill_manager_->FormsSeen(forms);
+
+ // First fill the address data.
+ std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
+ EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ kDefaultPageID, form, *form.fields.begin(),
+ autofill_manager_->PackGUIDs(std::string(), guid)));
+
+ int page_id = 0;
+ FormData results;
+ EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
+ {
+ SCOPED_TRACE("Address");
+ ExpectFilledForm(page_id, results, kDefaultPageID,
+ "Elvis", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", true, true);
+ }
+
+ // Now fill the credit card data.
+ process()->sink().ClearMessages();
+ const int kPageID2 = 2;
+ guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
+ EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ kPageID2, form, form.fields.back(),
+ autofill_manager_->PackGUIDs(guid, std::string())));
page_id = 0;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
- EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name);
- EXPECT_EQ(ASCIIToUTF16("POST"), results.method);
- EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin);
- EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action);
- ASSERT_EQ(15U, results.fields.size());
+ {
+ SCOPED_TRACE("Credit card 1");
+ ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true);
+ }
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
- autofill_test::CreateTestFormField(
- "Middle Name", "middlename", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
- autofill_test::CreateTestFormField(
- "Last Name", "lastname", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
- autofill_test::CreateTestFormField(
- "Address Line 1", "addr1", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
- autofill_test::CreateTestFormField(
- "Address Line 2", "addr2", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4]));
- autofill_test::CreateTestFormField(
- "City", "city", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5]));
- autofill_test::CreateTestFormField(
- "State", "state", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6]));
- autofill_test::CreateTestFormField(
- "Postal Code", "zipcode", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7]));
- autofill_test::CreateTestFormField(
- "Country", "country", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8]));
- autofill_test::CreateTestFormField(
- "Phone Number", "phonenumber", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9]));
- autofill_test::CreateTestFormField(
- "Email", "email", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10]));
- autofill_test::CreateTestFormField(
- "Name on Card", "nameoncard", "Elvis Presley", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11]));
- autofill_test::CreateTestFormField(
- "Card Number", "cardnumber", "4234567890123456", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12]));
- autofill_test::CreateTestFormField(
- "Expiration Date", "ccmonth", "04", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13]));
- autofill_test::CreateTestFormField(
- "", "ccyear", "2012", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14]));
+ // Now set the credit card fields to also be auto-filled, and try again to
+ // fill the credit card data
+ for (std::vector<FormField>::iterator iter = form.fields.begin();
+ iter != form.fields.end();
+ ++iter){
+ iter->set_autofilled(true);
+ }
+
+ process()->sink().ClearMessages();
+ const int kPageID3 = 3;
+ EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ kPageID3, form, *form.fields.rbegin(),
+ autofill_manager_->PackGUIDs(guid, std::string())));
+
+ page_id = 0;
+ EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
+ {
+ SCOPED_TRACE("Credit card 2");
+ ExpectFilledForm(page_id, results, kPageID3,
+ "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "2012", true, true);
+ }
}
// Test that we correctly fill a phone number split across multiple fields.
TEST_F(AutoFillManagerTest, FillPhoneNumber) {
+ // Set up our form data.
FormData form;
-
form.name = ASCIIToUTF16("MyPhoneForm");
form.method = ASCIIToUTF16("POST");
form.origin = GURL("http://myform.com/phone_form.html");
form.action = GURL("http://myform.com/phone_submit.html");
form.user_submitted = true;
- webkit_glue::FormField field;
-
+ FormField field;
autofill_test::CreateTestFormField(
"country code", "country code", "", "text", &field);
field.set_max_length(1);
@@ -1449,13 +1379,11 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) {
field.set_max_length(3);
form.fields.push_back(field);
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
AutoFillProfile *work_profile = autofill_manager_->GetLabeledProfile("Work");
- EXPECT_TRUE(work_profile != NULL);
+ ASSERT_TRUE(work_profile != NULL);
const AutoFillType phone_type(PHONE_HOME_NUMBER);
string16 saved_phone = work_profile->GetFieldText(phone_type);
@@ -1468,7 +1396,7 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) {
int page_id = 100 - i;
process()->sink().ClearMessages();
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- page_id, form,
+ page_id, form, *form.fields.begin(),
autofill_manager_->PackGUIDs(std::string(), work_profile->guid())));
page_id = 0;
FormData results;
@@ -1489,139 +1417,61 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) {
// Test that we can still fill a form when a field has been removed from it.
TEST_F(AutoFillManagerTest, FormChangesRemoveField) {
+ // Set up our form data.
FormData form;
- form.name = ASCIIToUTF16("MyForm");
- form.method = ASCIIToUTF16("POST");
- form.origin = GURL("http://myform.com/form.html");
- form.action = GURL("http://myform.com/submit.html");
- form.user_submitted = true;
+ CreateTestAddressFormData(&form);
- webkit_glue::FormField 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);
- autofill_test::CreateTestFormField(
- "Phone Number", "phonenumber", "", "text", &field);
- form.fields.push_back(field);
- autofill_test::CreateTestFormField(
- "Email", "email", "", "text", &field);
- form.fields.push_back(field);
+ // Add a field -- we'll remove it again later.
+ FormField field;
+ autofill_test::CreateTestFormField("Some", "field", "", "text", &field);
+ form.fields.insert(form.fields.begin() + 3, field);
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // Now, after the call to |FormsSeen| we remove the phone number field before
- // filling.
+ // Now, after the call to |FormsSeen|, we remove the field before filling.
form.fields.erase(form.fields.begin() + 3);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
+ std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- kPageID, form,
- autofill_manager_->PackGUIDs(std::string(),
- "00000000-0000-0000-0000-000000000001")));
+ kDefaultPageID, form, form.fields[0],
+ autofill_manager_->PackGUIDs(std::string(), guid)));
int page_id = 0;
FormData results;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
- EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name);
- EXPECT_EQ(ASCIIToUTF16("POST"), results.method);
- EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin);
- EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action);
- EXPECT_TRUE(results.user_submitted);
- ASSERT_EQ(4U, results.fields.size());
-
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "Elvis", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
- autofill_test::CreateTestFormField(
- "Middle Name", "middlename", "Aaron", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
- autofill_test::CreateTestFormField(
- "Last Name", "lastname", "Presley", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
- autofill_test::CreateTestFormField(
- "Email", "email", "theking@gmail.com", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
+ ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false);
}
// Test that we can still fill a form when a field has been added to it.
TEST_F(AutoFillManagerTest, FormChangesAddField) {
+ // The offset of the fax field in the address form.
+ const int kFaxFieldOffset = 10;
+
+ // Set up our form data.
FormData form;
- form.name = ASCIIToUTF16("MyForm");
- form.method = ASCIIToUTF16("POST");
- form.origin = GURL("http://myform.com/form.html");
- form.action = GURL("http://myform.com/submit.html");
- form.user_submitted = true;
+ CreateTestAddressFormData(&form);
- webkit_glue::FormField 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);
- // Note: absent phone number. Adding this below.
- form.fields.push_back(field);
- autofill_test::CreateTestFormField(
- "Email", "email", "", "text", &field);
- form.fields.push_back(field);
+ // Remove the fax field -- we'll add it back later.
+ std::vector<FormField>::iterator pos = form.fields.begin() + kFaxFieldOffset;
+ FormField field = *pos;
+ pos = form.fields.erase(pos);
- // Set up our FormStructures.
- std::vector<FormData> forms;
- forms.push_back(form);
+ std::vector<FormData> forms(1, form);
autofill_manager_->FormsSeen(forms);
- // Now, after the call to |FormsSeen| we add the phone number field before
- // filling.
- autofill_test::CreateTestFormField(
- "Phone Number", "phonenumber", "", "text", &field);
- form.fields.insert(form.fields.begin() + 3, field);
+ // Now, after the call to |FormsSeen|, we restore the field before filling.
+ form.fields.insert(pos, field);
- // The page ID sent to the AutoFillManager from the RenderView, used to send
- // an IPC message back to the renderer.
- const int kPageID = 1;
+ std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- kPageID, form,
- autofill_manager_->PackGUIDs(std::string(),
- "00000000-0000-0000-0000-000000000001")));
+ kDefaultPageID, form, form.fields[0],
+ autofill_manager_->PackGUIDs(std::string(), guid)));
int page_id = 0;
FormData results;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
- EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name);
- EXPECT_EQ(ASCIIToUTF16("POST"), results.method);
- EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin);
- EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action);
- EXPECT_TRUE(results.user_submitted);
- ASSERT_EQ(5U, results.fields.size());
-
- autofill_test::CreateTestFormField(
- "First Name", "firstname", "Elvis", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
- autofill_test::CreateTestFormField(
- "Middle Name", "middlename", "Aaron", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
- autofill_test::CreateTestFormField(
- "Last Name", "lastname", "Presley", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
- autofill_test::CreateTestFormField(
- "Phone Number", "phonenumber", "", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
- autofill_test::CreateTestFormField(
- "Email", "email", "theking@gmail.com", "text", &field);
- EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4]));
+ ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false);
}
TEST_F(AutoFillManagerTest, HiddenFields) {
@@ -1632,7 +1482,7 @@ TEST_F(AutoFillManagerTest, HiddenFields) {
form.action = GURL("http://myform.com/submit.html");
form.user_submitted = true;
- webkit_glue::FormField field;
+ FormField field;
autofill_test::CreateTestFormField(
"E-mail", "one", "one", "hidden", &field);
form.fields.push_back(field);
@@ -1643,7 +1493,7 @@ TEST_F(AutoFillManagerTest, HiddenFields) {
"E-mail", "three", "three", "hidden", &field);
form.fields.push_back(field);
- // Set up our FormStructures.
+ // Set up our form data.
std::vector<FormData> forms;
forms.push_back(form);
autofill_manager_->FormsSeen(forms);