| 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 24f1ba86fe058f8e12ee114df58fb0b6a23768db..c95805b6cd176b8c7930f46039a1f22845ba8592 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 "
|
| +// .,-_@") 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());
|
| +}
|
| +
|
| +// 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
|
|
|