OLD | NEW |
---|---|
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 3158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3169 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 3169 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
3170 | 3170 |
3171 external_delegate_->CheckSuggestions( | 3171 external_delegate_->CheckSuggestions( |
3172 kDefaultPageID, | 3172 kDefaultPageID, |
3173 Suggestion( | 3173 Suggestion( |
3174 "Visa \xE2\x8B\xAF" | 3174 "Visa \xE2\x8B\xAF" |
3175 "3456", | 3175 "3456", |
3176 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); | 3176 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); |
3177 } | 3177 } |
3178 | 3178 |
3179 // Test that suggestion tokens (substrings separated by characters from " | |
3180 // .,-_@") are matched against field contents. | |
3181 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { | |
3182 // Token matching is currently behind a flag. | |
3183 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3184 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3185 | |
3186 // Set up our form data. | |
3187 FormData form; | |
3188 test::CreateTestAddressFormData(&form); | |
3189 std::vector<FormData> forms(1, form); | |
3190 FormsSeen(forms); | |
3191 | |
3192 // Simulate displaying suggestions for field contents "gmail", check that | |
3193 // matching ones are displayed. | |
3194 FormFieldData field; | |
3195 test::CreateTestFormField("Email", "email", "gmail", "email", &field); | |
3196 GetAutofillSuggestions(form, field); | |
3197 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3198 | |
3199 external_delegate_->CheckSuggestions( | |
3200 kDefaultPageID, | |
3201 Suggestion("theking@gmail.com", "Elvis Aaron Presley", "", 1), | |
3202 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 2)); | |
3203 } | |
3204 | |
3205 // Test that suggestions which do not have a prefix match or prefix-token match | |
3206 // with the field contents are not matched. | |
3207 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) { | |
3208 // Token matching is currently behind a flag. | |
3209 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3210 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3211 | |
3212 // Set up our form data. | |
3213 FormData form; | |
3214 test::CreateTestAddressFormData(&form); | |
3215 std::vector<FormData> forms(1, form); | |
3216 FormsSeen(forms); | |
3217 | |
3218 // Simulate displaying suggestions for field contents "mail". Check that none | |
3219 // appear, because none has a token with a prefix "mail". | |
3220 FormFieldData field; | |
3221 test::CreateTestFormField("Email", "email", "mail", "email", &field); | |
3222 GetAutofillSuggestions(form, field); | |
3223 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | |
3224 } | |
3225 | |
3226 // Test matching when field contents contains suggestion token separators. | |
3227 TEST_F(AutofillManagerTest, MatchingContentsWithSuggestionTokenSeparator) { | |
3228 // Token matching is currently behind a flag. | |
3229 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3230 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3231 | |
3232 // Set up our form data. | |
3233 FormData form; | |
3234 test::CreateTestAddressFormData(&form); | |
3235 std::vector<FormData> forms(1, form); | |
3236 FormsSeen(forms); | |
3237 | |
3238 // Simulate displaying suggestions for field contents "buddy@gma", check that | |
3239 // matching one is displayed. Please also note here that field contents | |
3240 // contains token separators '@', |IsContentsPrefixOfSuggestionToken()| only | |
3241 // picks suggestions that passes the constrain that |field_contents| prefix | |
vabr (Chromium)
2015/03/31 09:38:07
grammar:
passes -> pass (suggestions are plural)
p
Pritam Nikam
2015/03/31 14:26:11
Done.
| |
3242 // some token in |field_suggestion|. In our test case, only "buddy@gmail.com" | |
3243 // passes both the constrains and apparently we could see only that in | |
vabr (Chromium)
2015/03/31 09:38:07
The comment confuses me. It says "both the constra
Pritam Nikam
2015/03/31 14:26:11
I've corrected this and chosen "gmail.co" as field
| |
3244 // matching suggestion list. | |
3245 FormFieldData field; | |
3246 test::CreateTestFormField("Email", "email", "buddy@gma", "email", &field); | |
3247 GetAutofillSuggestions(form, field); | |
3248 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3249 | |
3250 external_delegate_->CheckSuggestions( | |
3251 kDefaultPageID, | |
3252 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 1)); | |
3253 } | |
3254 | |
3179 } // namespace autofill | 3255 } // namespace autofill |
OLD | NEW |