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

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: Incorporates Evan's review comments. Created 5 years, 7 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 3264 matching lines...) Expand 10 before | Expand all | Expand 10 after
3275 else if (form.fields[i].name == ASCIIToUTF16("state")) 3275 else if (form.fields[i].name == ASCIIToUTF16("state"))
3276 form.fields[i].value = ASCIIToUTF16("Texas"); 3276 form.fields[i].value = ASCIIToUTF16("Texas");
3277 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) 3277 else if (form.fields[i].name == ASCIIToUTF16("zipcode"))
3278 form.fields[i].value = ASCIIToUTF16("77401"); 3278 form.fields[i].value = ASCIIToUTF16("77401");
3279 else if (form.fields[i].name == ASCIIToUTF16("country")) 3279 else if (form.fields[i].name == ASCIIToUTF16("country"))
3280 form.fields[i].value = ASCIIToUTF16("US"); 3280 form.fields[i].value = ASCIIToUTF16("US");
3281 } 3281 }
3282 autofill_manager_->OnFormSubmitted(form); 3282 autofill_manager_->OnFormSubmitted(form);
3283 } 3283 }
3284 3284
3285 // Test that suggestion tokens (substrings separated by characters from "
3286 // .,-_@") are matched against field contents.
3287 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
3288 // Token matching is currently behind a flag.
3289 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3290 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3291
3292 // Set up our form data.
3293 FormData form;
3294 test::CreateTestAddressFormData(&form);
3295 std::vector<FormData> forms(1, form);
3296 FormsSeen(forms);
3297
3298 // Simulate displaying suggestions for field contents "gmail", check that
3299 // matching ones are displayed.
3300 FormFieldData field;
3301 test::CreateTestFormField("Email", "email", "gmail", "email", &field);
3302 GetAutofillSuggestions(form, field);
3303 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3304
3305 external_delegate_->CheckSuggestions(
3306 kDefaultPageID,
3307 Suggestion("theking@gmail.com", "Elvis Aaron Presley", "", 1),
3308 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 2));
3309 }
3310
3311 // Test that suggestion tokens (substrings separated by characters from "
3312 // .,-_@") are matched against field contents ignoring their case.
3313 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) {
3314 // Token matching is currently behind a flag.
3315 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3316 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3317
3318 // Set up our form data.
3319 FormData form;
3320 test::CreateTestAddressFormData(&form);
3321 std::vector<FormData> forms(1, form);
3322 FormsSeen(forms);
3323
3324 // Simulate displaying suggestions for field contents "apple", check that
3325 // matching one is displayed.
3326 FormFieldData field;
3327 test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field);
3328 GetAutofillSuggestions(form, field);
3329 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3330
3331 external_delegate_->CheckSuggestions(
3332 kDefaultPageID,
3333 Suggestion("123 Apple St., unit 6", "Charles Hardin Holley", "", 1));
3334 }
3335
3336 // Test that suggestions which do not have a prefix match or prefix-token match
3337 // with the field contents are not matched.
3338 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
3339 // Token matching is currently behind a flag.
3340 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3341 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3342
3343 // Set up our form data.
3344 FormData form;
3345 test::CreateTestAddressFormData(&form);
3346 std::vector<FormData> forms(1, form);
3347 FormsSeen(forms);
3348
3349 // Simulate displaying suggestions for field contents "mail". Check that none
3350 // appear, because none has a token with a prefix "mail".
3351 FormFieldData field;
3352 test::CreateTestFormField("Email", "email", "mail", "email", &field);
3353 GetAutofillSuggestions(form, field);
3354 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3355 }
3356
3357 // Test that the credit card holder name suggestion tokens (substrings separated
3358 // by characters from " .,-_@") are matched against field contents.
3359 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) {
3360 // Token matching is currently behind a flag.
3361 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3362 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3363
3364 // Set up our form data.
3365 FormData form;
3366 CreateTestCreditCardFormData(&form, true, false);
3367 std::vector<FormData> forms(1, form);
3368 FormsSeen(forms);
3369
3370 FormFieldData field;
3371 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text",
3372 &field);
3373 GetAutofillSuggestions(form, field);
3374
3375 // No suggestions provided, so send an empty vector as the results.
3376 // This triggers the combined message send.
3377 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3378
3379 // Simulate displaying suggestions for field contents "pres", check that
3380 // matching one is displayed.
3381 external_delegate_->CheckSuggestions(
3382 kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard,
3383 autofill_manager_->GetPackedCreditCardID(4)));
3384 }
3385
3386 // Test that the credit card holder name suggestions which do not have a prefix
3387 // match or prefix-token match with the field contents are not matched.
3388 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) {
3389 // Token matching is currently behind a flag.
3390 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3391 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3392
3393 // Set up our form data.
3394 FormData form;
3395 CreateTestCreditCardFormData(&form, true, false);
3396 std::vector<FormData> forms(1, form);
3397 FormsSeen(forms);
3398
3399 // Simulate displaying suggestions for field contents "lvis". Check that none
3400 // appear, because none has a token with a prefix "lvis".
3401 FormFieldData field;
3402 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
3403 &field);
3404 GetAutofillSuggestions(form, field);
3405 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3406 }
3407
3285 } // namespace autofill 3408 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698