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

Unified Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comments in autocomplete_history_manager.cc. Created 5 years, 6 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
Index: components/autofill/core/browser/autofill_manager_unittest.cc
diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc
index 092f624531afeb95f9dd78e862be78caae6ab8e7..0a721effbd79ec042a06039e8647c45cf68ec2bd 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -3073,4 +3073,179 @@ TEST_F(AutofillManagerTest, DontOfferToSaveWalletCard) {
autofill_manager_->OnFormSubmitted(form);
}
+// Test that suggestion tokens (substrings separated by characters from "
please use gerrit instead 2015/06/29 22:06:29 Please be more specific. For example, 'Verify that
Pritam Nikam 2015/06/30 15:05:50 Done.
+// .,-_@") are matched against field contents.
+TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
+ // Token matching is currently behind a flag.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ autofill::switches::kEnableSuggestionsWithSubstringMatch);
+
+ // Set up our form data.
+ FormData form;
+ test::CreateTestAddressFormData(&form);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ // Simulate displaying suggestions for field contents "gmail", check that
+ // matching ones are displayed.
+ FormFieldData field;
+ test::CreateTestFormField("Email", "email", "gmail", "email", &field);
+ GetAutofillSuggestions(form, field);
+ AutocompleteSuggestionsReturned(std::vector<base::string16>());
+
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID,
+ Suggestion("theking@gmail.com", "3734 Elvis Presley Blvd.", "", 1),
+ Suggestion("buddy@gmail.com", "123 Apple St.", "", 2));
+}
+
+// Test that suggestion tokens (substrings separated by characters from "
+// .,-_@") are matched against field contents ignoring their case.
please use gerrit instead 2015/06/29 22:06:29 Please be more specific. For example, 'Verify that
Pritam Nikam 2015/06/30 15:05:50 Done.
+TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) {
+ // Token matching is currently behind a flag.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ autofill::switches::kEnableSuggestionsWithSubstringMatch);
+
+ // Set up our form data.
+ FormData form;
+ test::CreateTestAddressFormData(&form);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ // Simulate displaying suggestions for field contents "apple", check that
+ // matching one is displayed.
+ FormFieldData field;
+ test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field);
+ GetAutofillSuggestions(form, field);
+ AutocompleteSuggestionsReturned(std::vector<base::string16>());
+
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID,
+ Suggestion("123 Apple St., unit 6", "123 Apple St.", "", 1));
+}
+
+// Test that suggestions which do not have a prefix match or prefix-token match
please use gerrit instead 2015/06/29 22:06:29 Please be more specific. For example, 'Verify that
Pritam Nikam 2015/06/30 15:05:50 Done.
+// with the field contents are not matched.
+TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
+ // Token matching is currently behind a flag.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ autofill::switches::kEnableSuggestionsWithSubstringMatch);
+
+ // Set up our form data.
+ FormData form;
+ test::CreateTestAddressFormData(&form);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ // Simulate displaying suggestions for field contents "mail". Check that none
+ // appear, because none has a token with a prefix "mail".
+ FormFieldData field;
+ test::CreateTestFormField("Email", "email", "mail", "email", &field);
+ GetAutofillSuggestions(form, field);
+ EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
+}
+
+// Test that the credit card holder name suggestion tokens (substrings separated
+// by characters from " .,-_@") are matched against field contents.
+TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) {
+ // Token matching is currently behind a flag.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ autofill::switches::kEnableSuggestionsWithSubstringMatch);
+
+ // Set up our form data.
+ FormData form;
+ CreateTestCreditCardFormData(&form, true, false);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ FormFieldData field;
+ test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text",
+ &field);
+ GetAutofillSuggestions(form, field);
+
+ // No suggestions provided, so send an empty vector as the results.
+ // This triggers the combined message send.
+ AutocompleteSuggestionsReturned(std::vector<base::string16>());
+
+ // Simulate displaying suggestions for field contents "pres", check that
+ // matching one is displayed.
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard,
+ autofill_manager_->GetPackedCreditCardID(4)));
+}
+
+// Test that the credit card holder name suggestions which do not have a prefix
+// match or prefix-token match with the field contents are not matched.
+TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) {
+ // Token matching is currently behind a flag.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ autofill::switches::kEnableSuggestionsWithSubstringMatch);
+
+ // Set up our form data.
+ FormData form;
+ CreateTestCreditCardFormData(&form, true, false);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ // Simulate displaying suggestions for field contents "lvis". Check that none
+ // appear, because none has a token with a prefix "lvis".
+ FormFieldData field;
+ test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
+ &field);
+ GetAutofillSuggestions(form, field);
+ EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
+}
+
+// Test that suggestion tokens (substrings separated by characters from
+// " .,-_@") are ordered prefixes precede substring matched.
+TEST_F(AutofillManagerTest,
+ DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
+ // Token matching is currently behind a flag.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ autofill::switches::kEnableSuggestionsWithSubstringMatch);
+
+ // Set up our form data.
+ FormData form;
+ test::CreateTestAddressFormData(&form);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ AutofillProfile* profile1 = new AutofillProfile;
+ profile1->set_guid("00000000-0000-0000-0000-000000000103");
+ profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US");
+ profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"),
+ "en-US");
+ profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
+ profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
+ ASCIIToUTF16("1234 Smith Blvd."), "en-US");
+ autofill_manager_->AddProfile(profile1);
+
+ AutofillProfile* profile2 = new AutofillProfile;
+ profile2->set_guid("00000000-0000-0000-0000-000000000124");
+ profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US");
+ profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"),
+ "en-US");
+ profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
+ profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
+ ASCIIToUTF16("1234 Smith Blvd."), "en-US");
+ autofill_manager_->AddProfile(profile2);
+
+ // Simulate displaying suggestions for field contents "S", check that
+ // matching ones are displayed.
+ FormFieldData field;
+ test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field);
+ GetAutofillSuggestions(form, field);
+
+ // No suggestions provided, so send an empty vector as the results.
+ // This triggers the combined message send.
+ AutocompleteSuggestionsReturned(std::vector<base::string16>());
+
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID,
+ Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "",
+ 1),
+ Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "",
+ 2));
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698