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

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 Evan's review inputs. Created 5 years, 8 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 3121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 AutocompleteSuggestionsReturned(std::vector<base::string16>()); 3132 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3133 3133
3134 external_delegate_->CheckSuggestions( 3134 external_delegate_->CheckSuggestions(
3135 kDefaultPageID, 3135 kDefaultPageID,
3136 Suggestion( 3136 Suggestion(
3137 "Visa\xC2\xA0\xE2\x8B\xAF" 3137 "Visa\xC2\xA0\xE2\x8B\xAF"
3138 "3456", 3138 "3456",
3139 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); 3139 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)));
3140 } 3140 }
3141 3141
3142 // Test that suggestion tokens (substrings separated by characters from "
3143 // .,-_@") are matched against field contents.
3144 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
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 test::CreateTestAddressFormData(&form);
3152 std::vector<FormData> forms(1, form);
3153 FormsSeen(forms);
3154
3155 // Simulate displaying suggestions for field contents "gmail", check that
3156 // matching ones are displayed.
3157 FormFieldData field;
3158 test::CreateTestFormField("Email", "email", "gmail", "email", &field);
3159 GetAutofillSuggestions(form, field);
3160 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3161
3162 external_delegate_->CheckSuggestions(
3163 kDefaultPageID,
3164 Suggestion("theking@gmail.com", "Elvis Aaron Presley", "", 1),
3165 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 2));
3166 }
3167
3168 // Test that suggestions which do not have a prefix match or prefix-token match
3169 // with the field contents are not matched.
3170 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
3171 // Token matching is currently behind a flag.
3172 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3173 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3174
3175 // Set up our form data.
3176 FormData form;
3177 test::CreateTestAddressFormData(&form);
3178 std::vector<FormData> forms(1, form);
3179 FormsSeen(forms);
3180
3181 // Simulate displaying suggestions for field contents "mail". Check that none
3182 // appear, because none has a token with a prefix "mail".
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 // Test matching when field contents contains suggestion token separators.
3190 TEST_F(AutofillManagerTest, MatchingContentsWithSuggestionTokenSeparator) {
3191 // Token matching is currently behind a flag.
3192 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3193 autofill::switches::kEnableSuggestionsWithSubstringMatch);
3194
3195 // Set up our form data.
3196 FormData form;
3197 test::CreateTestAddressFormData(&form);
3198 std::vector<FormData> forms(1, form);
3199 FormsSeen(forms);
3200
3201 // Simulate displaying suggestions for field contents "gmail.co". Because "@"
3202 // is a token separator, the field contents cannot be a prefix of any
3203 // suggestion token. Moreover, no suggestion starts with "gmail.co".
3204 // Therefore, no suggestions should match.
3205 FormFieldData field;
3206 test::CreateTestFormField("Email", "email", "gmail.co", "email", &field);
3207 GetAutofillSuggestions(form, field);
3208 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3209
3210 // Simulate displaying suggestions for field contents "buddy@gm". Because "@"
3211 // is a token separator, the field contents cannot be a prefix of any
3212 // suggestion token. However, the suggestion "buddy@gmail.com starts with
3213 // "buddy@gm". That suggestion should be the only match.
3214 test::CreateTestFormField("Email", "email", "buddy@gm", "email", &field);
3215 GetAutofillSuggestions(form, field);
3216 AutocompleteSuggestionsReturned(std::vector<base::string16>());
3217
3218 external_delegate_->CheckSuggestions(
3219 kDefaultPageID,
3220 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 1));
3221 }
3222
3142 } // namespace autofill 3223 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698