Chromium Code Reviews| 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 092f624531afeb95f9dd78e862be78caae6ab8e7..7b459d00aa52cdc2e93756db3c0cc890b0e8960b 100644 |
| --- a/components/autofill/core/browser/autofill_manager_unittest.cc |
| +++ b/components/autofill/core/browser/autofill_manager_unittest.cc |
| @@ -3073,4 +3073,186 @@ TEST_F(AutofillManagerTest, DontOfferToSaveWalletCard) { |
| autofill_manager_->OnFormSubmitted(form); |
| } |
| +// Verify that typing "gmail" will match "theking@gmail.com" and |
| +// "buddy@gmail.com" when substring matching is enabled. |
| +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 email field contents "gmail", check |
| + // that matching emails "theking@gmail.com" and "buddy@gmail.com" are |
| + // displayed in suggestion list. |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + 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", "3734 Elvis Presley Blvd.", "", 1), |
| + Suggestion("buddy@gmail.com", "123 Apple St.", "", 2)); |
| +} |
| + |
| +// Verify that typing "apple" will match "123 Apple St." when substring matching |
| +// is enabled. |
| +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 address field contents "apple", check |
| + // that matching address "123 Apple St., unit 6" is displayed in the |
| + // suggestion list. |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + 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", "123 Apple St.", "", 1)); |
| +} |
| + |
| +// Verify that typing "mail" will not match any of the "@gmail.com" email |
| +// addresses when substring matching is enabled. |
| +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 of the emails emails "theking@gmail.com" or |
| + // "buddy@gmail.com" has a token with a prefix "mail". |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + FormFieldData field; |
| + test::CreateTestFormField("Email", "email", "mail", "email", &field); |
| + GetAutofillSuggestions(form, field); |
| + EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| +} |
| + |
| +// Verify that typing "pres" will match "Elvis Presley" when substring matching |
| +// is enabled. |
| +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 credit card name field contents "pres", |
| + // check that matching name "Elvis Presley" is displayed in the suggestion |
| + // list. |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + external_delegate_->CheckSuggestions( |
| + kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard, |
| + autofill_manager_->GetPackedCreditCardID(4))); |
| +} |
| + |
| +// Verify that typing "lvis" will not match any of the credit card name when |
| +// substring matching is enabled. |
| +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 card names "Elvis Presley" or "Buddy Holly" has a |
| + // token with a prefix "lvis". |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + FormFieldData field; |
| + test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", |
| + &field); |
| + GetAutofillSuggestions(form, field); |
| + EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| +} |
| + |
| +// Verify that typing "S" into the middle name field will match and order middle |
| +// names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by |
| +// 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 middle name field contents "S", check |
| + // that matching ones are displayed with prefix matched suggestion "Shawn |
| + // Smith" placed before the substring matched suggestion "Adam Smith". |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + 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 |