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

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: Incorporated Evan's review inputs. Created 5 years, 8 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 238b205d3a09156ba011d3fdfc813f6f6bba2c3a..21dd87e80d4157c4092848867a11541ba29cf427 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -3139,4 +3139,85 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) {
"04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)));
}
+// Test that suggestion tokens (substrings separated by characters from "
+// .,-_@") 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", "Elvis Aaron Presley", "", 1),
+ Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 2));
+}
+
+// Test that suggestions which do not have a prefix match or prefix-token match
+// 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 matching when field contents contains suggestion token separators.
+TEST_F(AutofillManagerTest, MatchingContentsWithSuggestionTokenSeparator) {
+ // 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.co". Because "@"
+ // is a token separator, the field contents cannot be a prefix of any
+ // suggestion token. Moreover, no suggestion starts with "gmail.co".
+ // Therefore, no suggestions should match.
+ FormFieldData field;
+ test::CreateTestFormField("Email", "email", "gmail.co", "email", &field);
+ GetAutofillSuggestions(form, field);
+ EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
+
+ // Simulate displaying suggestions for field contents "buddy@gm". Because "@"
+ // is a token separator, the field contents cannot be a prefix of any
+ // suggestion token. However, the suggestion "buddy@gmail.com starts with
+ // "buddy@gm". That suggestion should be the only match.
+ test::CreateTestFormField("Email", "email", "buddy@gm", "email", &field);
+ GetAutofillSuggestions(form, field);
+ AutocompleteSuggestionsReturned(std::vector<base::string16>());
+
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID,
+ Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 1));
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698