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 bcdbb8dfbc3e6e7a67ab1c8dac9c8eac6422d144..3958cab35876e6ad3a1c14c9b8895f8ad2c2d1e4 100644 |
--- a/components/autofill/core/browser/autofill_manager_unittest.cc |
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc |
@@ -3282,4 +3282,127 @@ TEST_F(AutofillManagerTest, DontOfferToSaveWalletCard) { |
autofill_manager_->OnFormSubmitted(form); |
} |
+// 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 suggestion tokens (substrings separated by characters from " |
+// .,-_@") are matched against field contents ignoring their case. |
+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", "Charles Hardin Holley", "", 1)); |
+} |
+ |
+// 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 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()); |
+} |
+ |
} // namespace autofill |