| 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 cf418342df54c7b545d9c75121d4631859f11ffa..ff25129e7f8e4d2dc3ccc407ca348db3bc72436b 100644
|
| --- a/components/autofill/core/browser/autofill_manager_unittest.cc
|
| +++ b/components/autofill/core/browser/autofill_manager_unittest.cc
|
| @@ -3176,4 +3176,91 @@ 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", Check that
|
| + // none appear, because none has a token with a prefix "gmail.co". Please also
|
| + // note here that field contents contains token separator '.',
|
| + // |IsContentsPrefixOfSuggestionToken()| only picks suggestions that pass the
|
| + // constrain that |field_contents| prefixes some token in |field_suggestion|.
|
| + // Field contents "gmal.co" rather spans multiple tokens. In our test case,
|
| + // none of the suggestions pass this constrain and apparently we could see
|
| + // none in matching suggestion list.
|
| + 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", check that
|
| + // matching one is displayed. Please note here that field contents "buddy@gm"
|
| + // spans to multiple tokens and none of the suggestions pass
|
| + // |IsContentsPrefixOfSuggestionToken()|'s constrain. However; unlike our
|
| + // previous test; the field contents whole-text prefixes the "buddy@gmail.com"
|
| + // suggestion and we could see it in suggestion list.
|
| + 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
|
|
|