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

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: Incorporated Vaclav's review comments. 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 3102 matching lines...) Expand 10 before | Expand all | Expand 10 after
3113 autofill_manager_->OnUnmaskResponse(response); 3113 autofill_manager_->OnUnmaskResponse(response);
3114 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, 3114 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
3115 "4012888888881881"); 3115 "4012888888881881");
3116 3116
3117 EXPECT_EQ(ASCIIToUTF16("02"), autofill_manager_->unmasking_card_.GetRawInfo( 3117 EXPECT_EQ(ASCIIToUTF16("02"), autofill_manager_->unmasking_card_.GetRawInfo(
3118 CREDIT_CARD_EXP_MONTH)); 3118 CREDIT_CARD_EXP_MONTH));
3119 EXPECT_EQ(ASCIIToUTF16("2018"), autofill_manager_->unmasking_card_.GetRawInfo( 3119 EXPECT_EQ(ASCIIToUTF16("2018"), autofill_manager_->unmasking_card_.GetRawInfo(
3120 CREDIT_CARD_EXP_4_DIGIT_YEAR)); 3120 CREDIT_CARD_EXP_4_DIGIT_YEAR));
3121 } 3121 }
3122 3122
3123 // Verify that typing "gmail" will match "theking@gmail.com" and
3124 // "buddy@gmail.com" when substring matching is enabled.
3125 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
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", "gmail", "email", &field);
3138 GetAutofillSuggestions(form, field);
3139 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3140
3141 external_delegate_->CheckSuggestions(
3142 kDefaultPageID,
3143 Suggestion("theking@gmail.com", "3734 Elvis Presley Blvd.", "", 1),
3144 Suggestion("buddy@gmail.com", "123 Apple St.", "", 2));
3145 }
3146
3147 // Verify that typing "apple" will match "123 Apple St." when substring matching
3148 // is enabled.
3149 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) {
3150 // Token matching is currently behind a flag.
3151 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3152 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3153
3154 // Set up our form data.
3155 FormData form;
3156 test::CreateTestAddressFormData(&form);
3157 std::vector<FormData> forms(1, form);
3158 FormsSeen(forms);
3159
3160 FormFieldData field;
3161 test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field);
3162 GetAutofillSuggestions(form, field);
3163 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3164
3165 external_delegate_->CheckSuggestions(
3166 kDefaultPageID,
3167 Suggestion("123 Apple St., unit 6", "123 Apple St.", "", 1));
3168 }
3169
3170 // Verify that typing "mail" will not match any of the "@gmail.com" email
3171 // addresses when substring matching is enabled.
3172 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
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 test::CreateTestAddressFormData(&form);
3180 std::vector<FormData> forms(1, form);
3181 FormsSeen(forms);
3182
3183 FormFieldData field;
3184 test::CreateTestFormField("Email", "email", "mail", "email", &field);
3185 GetAutofillSuggestions(form, field);
3186 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3187 }
3188
3189 // Verify that typing "pres" will match "Elvis Presley" when substring matching
3190 // is enabled.
3191 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) {
3192 // Token matching is currently behind a flag.
3193 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3194 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3195
3196 // Set up our form data.
3197 FormData form;
3198 CreateTestCreditCardFormData(&form, true, false);
3199 std::vector<FormData> forms(1, form);
3200 FormsSeen(forms);
3201
3202 FormFieldData field;
3203 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text",
3204 &field);
3205 GetAutofillSuggestions(form, field);
3206
3207 // No suggestions provided, so send an empty vector as the results.
3208 // This triggers the combined message send.
3209 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3210
3211 #if defined(OS_ANDROID)
3212 static const char* kVisaSuggestion =
3213 "Visa\xC2\xA0\xE2\x8B\xAF"
3214 "3456";
3215 #else
3216 static const char* kVisaSuggestion = "*3456";
3217 #endif
3218
3219 external_delegate_->CheckSuggestions(
3220 kDefaultPageID, Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard,
3221 autofill_manager_->GetPackedCreditCardID(4)));
3222 }
3223
3224 // Verify that typing "lvis" will not match any of the credit card name when
3225 // substring matching is enabled.
3226 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) {
3227 // Token matching is currently behind a flag.
3228 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3229 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3230
3231 // Set up our form data.
3232 FormData form;
3233 CreateTestCreditCardFormData(&form, true, false);
3234 std::vector<FormData> forms(1, form);
3235 FormsSeen(forms);
3236
3237 FormFieldData field;
3238 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
3239 &field);
3240 GetAutofillSuggestions(form, field);
3241 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3242 }
3243
3244 // Verify that typing "S" into the middle name field will match and order middle
3245 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by
3246 // substring matched.
3247 TEST_F(AutofillManagerTest,
3248 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
3249 // Token matching is currently behind a flag.
3250 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3251 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3252
3253 // Set up our form data.
3254 FormData form;
3255 test::CreateTestAddressFormData(&form);
3256 std::vector<FormData> forms(1, form);
3257 FormsSeen(forms);
3258
3259 AutofillProfile* profile1 = new AutofillProfile;
3260 profile1->set_guid("00000000-0000-0000-0000-000000000103");
3261 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US");
3262 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"),
3263 "en-US");
3264 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
3265 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
3266 ASCIIToUTF16("1234 Smith Blvd."), "en-US");
3267 autofill_manager_->AddProfile(profile1);
3268
3269 AutofillProfile* profile2 = new AutofillProfile;
3270 profile2->set_guid("00000000-0000-0000-0000-000000000124");
3271 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US");
3272 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"),
3273 "en-US");
3274 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US");
3275 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1),
3276 ASCIIToUTF16("1234 Smith Blvd."), "en-US");
3277 autofill_manager_->AddProfile(profile2);
3278
3279 FormFieldData field;
3280 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field);
3281 GetAutofillSuggestions(form, field);
3282
3283 // No suggestions provided, so send an empty vector as the results.
3284 // This triggers the combined message send.
3285 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3286
3287 external_delegate_->CheckSuggestions(
3288 kDefaultPageID,
3289 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "",
3290 1),
3291 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "",
3292 2));
3293 }
3294
3123 } // namespace autofill 3295 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698