Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 3055 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 else if (form.fields[i].name == ASCIIToUTF16("state")) 3066 else if (form.fields[i].name == ASCIIToUTF16("state"))
3067 form.fields[i].value = ASCIIToUTF16("Texas"); 3067 form.fields[i].value = ASCIIToUTF16("Texas");
3068 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) 3068 else if (form.fields[i].name == ASCIIToUTF16("zipcode"))
3069 form.fields[i].value = ASCIIToUTF16("77401"); 3069 form.fields[i].value = ASCIIToUTF16("77401");
3070 else if (form.fields[i].name == ASCIIToUTF16("country")) 3070 else if (form.fields[i].name == ASCIIToUTF16("country"))
3071 form.fields[i].value = ASCIIToUTF16("US"); 3071 form.fields[i].value = ASCIIToUTF16("US");
3072 } 3072 }
3073 autofill_manager_->OnFormSubmitted(form); 3073 autofill_manager_->OnFormSubmitted(form);
3074 } 3074 }
3075 3075
3076 // Verify that typing "gmail" will match "theking@gmail.com" and
3077 // "buddy@gmail.com" when substring matching is enabled.
3078 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
3079 // Token matching is currently behind a flag.
3080 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3081 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3082
3083 // Set up our form data.
3084 FormData form;
3085 test::CreateTestAddressFormData(&form);
3086 std::vector<FormData> forms(1, form);
3087 FormsSeen(forms);
3088
3089 FormFieldData field;
3090 test::CreateTestFormField("Email", "email", "gmail", "email", &field);
3091 GetAutofillSuggestions(form, field);
3092 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3093
3094 external_delegate_->CheckSuggestions(
3095 kDefaultPageID,
3096 Suggestion("theking@gmail.com", "3734 Elvis Presley Blvd.", "", 1),
3097 Suggestion("buddy@gmail.com", "123 Apple St.", "", 2));
3098 }
3099
3100 // Verify that typing "apple" will match "123 Apple St." when substring matching
3101 // is enabled.
3102 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) {
3103 // Token matching is currently behind a flag.
3104 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3105 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3106
3107 // Set up our form data.
3108 FormData form;
3109 test::CreateTestAddressFormData(&form);
3110 std::vector<FormData> forms(1, form);
3111 FormsSeen(forms);
3112
3113 FormFieldData field;
3114 test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field);
3115 GetAutofillSuggestions(form, field);
3116 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3117
3118 external_delegate_->CheckSuggestions(
3119 kDefaultPageID,
3120 Suggestion("123 Apple St., unit 6", "123 Apple St.", "", 1));
3121 }
3122
3123 // Verify that typing "mail" will not match any of the "@gmail.com" email
3124 // addresses when substring matching is enabled.
3125 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
3126 // Token matching is currently behind a flag.
3127 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3128 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3129
3130 // Set up our form data.
3131 FormData form;
3132 test::CreateTestAddressFormData(&form);
3133 std::vector<FormData> forms(1, form);
3134 FormsSeen(forms);
3135
3136 FormFieldData field;
3137 test::CreateTestFormField("Email", "email", "mail", "email", &field);
3138 GetAutofillSuggestions(form, field);
3139 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3140 }
3141
3142 // Verify that typing "pres" will match "Elvis Presley" when substring matching
3143 // is enabled.
3144 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) {
3145 // Token matching is currently behind a flag.
3146 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3147 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3148
3149 // Set up our form data.
3150 FormData form;
3151 CreateTestCreditCardFormData(&form, true, false);
3152 std::vector<FormData> forms(1, form);
3153 FormsSeen(forms);
3154
3155 FormFieldData field;
3156 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text",
3157 &field);
3158 GetAutofillSuggestions(form, field);
3159
3160 // No suggestions provided, so send an empty vector as the results.
3161 // This triggers the combined message send.
3162 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3163
3164 external_delegate_->CheckSuggestions(
3165 kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard,
3166 autofill_manager_->GetPackedCreditCardID(4)));
3167 }
3168
3169 // Verify that typing "lvis" will not match any of the credit card name when
3170 // substring matching is enabled.
3171 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) {
3172 // Token matching is currently behind a flag.
3173 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3174 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3175
3176 // Set up our form data.
3177 FormData form;
3178 CreateTestCreditCardFormData(&form, true, false);
3179 std::vector<FormData> forms(1, form);
3180 FormsSeen(forms);
3181
3182 FormFieldData field;
3183 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
3184 &field);
3185 GetAutofillSuggestions(form, field);
3186 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3187 }
3188
3189 // Verify that typing "S" into the middle name field will match and order middle
3190 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by
3191 // substring matched.
3192 TEST_F(AutofillManagerTest,
3193 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
3194 // Token matching is currently behind a flag.
3195 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3196 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3197
3198 // Set up our form data.
3199 FormData form;
3200 test::CreateTestAddressFormData(&form);
3201 std::vector<FormData> forms(1, form);
3202 FormsSeen(forms);
3203
3204 AutofillProfile* profile1 = new AutofillProfile;
3205 profile1->set_guid("00000000-0000-0000-0000-000000000103");
3206 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US");
3207 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"),
3208 "en-US");
3209 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
3210 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
3211 ASCIIToUTF16("1234 Smith Blvd."), "en-US");
3212 autofill_manager_->AddProfile(profile1);
3213
3214 AutofillProfile* profile2 = new AutofillProfile;
3215 profile2->set_guid("00000000-0000-0000-0000-000000000124");
3216 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US");
3217 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"),
3218 "en-US");
3219 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
3220 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
3221 ASCIIToUTF16("1234 Smith Blvd."), "en-US");
3222 autofill_manager_->AddProfile(profile2);
3223
3224 FormFieldData field;
3225 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field);
3226 GetAutofillSuggestions(form, field);
3227
3228 // No suggestions provided, so send an empty vector as the results.
3229 // This triggers the combined message send.
3230 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3231
3232 external_delegate_->CheckSuggestions(
3233 kDefaultPageID,
3234 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "",
3235 1),
3236 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "",
3237 2));
3238 }
3239
3076 } // namespace autofill 3240 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698