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

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: Modified to resolve bot breakages. 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 3083 matching lines...) Expand 10 before | Expand all | Expand 10 after
3094 else if (form.fields[i].name == ASCIIToUTF16("state")) 3094 else if (form.fields[i].name == ASCIIToUTF16("state"))
3095 form.fields[i].value = ASCIIToUTF16("Texas"); 3095 form.fields[i].value = ASCIIToUTF16("Texas");
3096 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) 3096 else if (form.fields[i].name == ASCIIToUTF16("zipcode"))
3097 form.fields[i].value = ASCIIToUTF16("77401"); 3097 form.fields[i].value = ASCIIToUTF16("77401");
3098 else if (form.fields[i].name == ASCIIToUTF16("country")) 3098 else if (form.fields[i].name == ASCIIToUTF16("country"))
3099 form.fields[i].value = ASCIIToUTF16("US"); 3099 form.fields[i].value = ASCIIToUTF16("US");
3100 } 3100 }
3101 autofill_manager_->OnFormSubmitted(form); 3101 autofill_manager_->OnFormSubmitted(form);
3102 } 3102 }
3103 3103
3104 // Verify that typing "gmail" will match "theking@gmail.com" and
3105 // "buddy@gmail.com" when substring matching is enabled.
3106 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
3107 // Token matching is currently behind a flag.
3108 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3109 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3110
3111 // Set up our form data.
3112 FormData form;
3113 test::CreateTestAddressFormData(&form);
3114 std::vector<FormData> forms(1, form);
3115 FormsSeen(forms);
3116
3117 FormFieldData field;
3118 test::CreateTestFormField("Email", "email", "gmail", "email", &field);
3119 GetAutofillSuggestions(form, field);
3120 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3121
3122 external_delegate_->CheckSuggestions(
3123 kDefaultPageID,
3124 Suggestion("theking@gmail.com", "3734 Elvis Presley Blvd.", "", 1),
3125 Suggestion("buddy@gmail.com", "123 Apple St.", "", 2));
3126 }
3127
3128 // Verify that typing "apple" will match "123 Apple St." when substring matching
3129 // is enabled.
3130 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) {
3131 // Token matching is currently behind a flag.
3132 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3133 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3134
3135 // Set up our form data.
3136 FormData form;
3137 test::CreateTestAddressFormData(&form);
3138 std::vector<FormData> forms(1, form);
3139 FormsSeen(forms);
3140
3141 FormFieldData field;
3142 test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field);
3143 GetAutofillSuggestions(form, field);
3144 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3145
3146 external_delegate_->CheckSuggestions(
3147 kDefaultPageID,
3148 Suggestion("123 Apple St., unit 6", "123 Apple St.", "", 1));
3149 }
3150
3151 // Verify that typing "mail" will not match any of the "@gmail.com" email
3152 // addresses when substring matching is enabled.
3153 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
3154 // Token matching is currently behind a flag.
3155 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3156 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3157
3158 // Set up our form data.
3159 FormData form;
3160 test::CreateTestAddressFormData(&form);
3161 std::vector<FormData> forms(1, form);
3162 FormsSeen(forms);
3163
3164 FormFieldData field;
3165 test::CreateTestFormField("Email", "email", "mail", "email", &field);
3166 GetAutofillSuggestions(form, field);
3167 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3168 }
3169
3170 // Verify that typing "pres" will match "Elvis Presley" when substring matching
3171 // is enabled.
3172 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) {
3173 // Token matching is currently behind a flag.
3174 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3175 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3176
3177 // Set up our form data.
3178 FormData form;
3179 CreateTestCreditCardFormData(&form, true, false);
3180 std::vector<FormData> forms(1, form);
3181 FormsSeen(forms);
3182
3183 FormFieldData field;
3184 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text",
3185 &field);
3186 GetAutofillSuggestions(form, field);
3187
3188 // No suggestions provided, so send an empty vector as the results.
3189 // This triggers the combined message send.
3190 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3191
3192 external_delegate_->CheckSuggestions(
3193 kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard,
3194 autofill_manager_->GetPackedCreditCardID(4)));
3195 }
3196
3197 // Verify that typing "lvis" will not match any of the credit card name when
3198 // substring matching is enabled.
3199 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) {
3200 // Token matching is currently behind a flag.
3201 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3202 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3203
3204 // Set up our form data.
3205 FormData form;
3206 CreateTestCreditCardFormData(&form, true, false);
3207 std::vector<FormData> forms(1, form);
3208 FormsSeen(forms);
3209
3210 FormFieldData field;
3211 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
3212 &field);
3213 GetAutofillSuggestions(form, field);
3214 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3215 }
3216
3217 // Verify that typing "S" into the middle name field will match and order middle
3218 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by
3219 // substring matched.
3220 TEST_F(AutofillManagerTest,
3221 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
3222 // Token matching is currently behind a flag.
3223 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3224 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3225
3226 // Set up our form data.
3227 FormData form;
3228 test::CreateTestAddressFormData(&form);
3229 std::vector<FormData> forms(1, form);
3230 FormsSeen(forms);
3231
3232 AutofillProfile* profile1 = new AutofillProfile;
3233 profile1->set_guid("00000000-0000-0000-0000-000000000103");
3234 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US");
3235 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"),
3236 "en-US");
3237 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
3238 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
3239 ASCIIToUTF16("1234 Smith Blvd."), "en-US");
3240 autofill_manager_->AddProfile(profile1);
3241
3242 AutofillProfile* profile2 = new AutofillProfile;
3243 profile2->set_guid("00000000-0000-0000-0000-000000000124");
3244 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US");
3245 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"),
3246 "en-US");
3247 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
3248 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
3249 ASCIIToUTF16("1234 Smith Blvd."), "en-US");
3250 autofill_manager_->AddProfile(profile2);
3251
3252 FormFieldData field;
3253 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field);
3254 GetAutofillSuggestions(form, field);
3255
3256 // No suggestions provided, so send an empty vector as the results.
3257 // This triggers the combined message send.
3258 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3259
3260 external_delegate_->CheckSuggestions(
3261 kDefaultPageID,
3262 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "",
3263 1),
3264 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "",
3265 2));
3266 }
3267
3104 } // namespace autofill 3268 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698