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 8778990ef781f579cee6028a5f533b66b8159ee0..1dc1bb17c45168f57fa2f77e05bc3348b3131669 100644 |
--- a/components/autofill/core/browser/autofill_manager_unittest.cc |
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc |
@@ -3176,4 +3176,78 @@ 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 are not matched when the field contents spans multiple |
+// tokens (substrings separated by characters from " .,-_@"). |
+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 suggestion tokens (substrings separated by characters from " |
+// .,-_@") are matched against field contents containing tokens along the token |
+// separators. |
+TEST_F(AutofillManagerTest, |
+ DisplaySuggestionsWithMatchingTokensAndContentsHaveSeperator) { |
+ // 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 "buddy@gma", check that |
+ // matching ones are displayed. |
+ FormFieldData field; |
+ test::CreateTestFormField("Email", "email", "buddy@gma", "email", &field); |
+ GetAutofillSuggestions(form, field); |
+ AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
+ |
+ external_delegate_->CheckSuggestions( |
+ kDefaultPageID, |
+ Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 1)); |
+} |
+ |
} // namespace autofill |