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\xC2\xA0\xE2\x8B\xAF" | 3174 "Visa\xC2\xA0\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 "gmail.co", Check that |
| 3239 // none appear, because none has a token with a prefix "gmail.co". Please also |
| 3240 // note here that field contents contains token separator '.', |
| 3241 // |IsContentsPrefixOfSuggestionToken()| only picks suggestions that pass the |
| 3242 // constrain that |field_contents| prefixes some token in |field_suggestion|. |
| 3243 // Field contents "gmal.co" rather spans multiple tokens. In our test case, |
| 3244 // none of the suggestions pass this constrain and apparently we could see |
| 3245 // none in matching suggestion list. |
| 3246 FormFieldData field; |
| 3247 test::CreateTestFormField("Email", "email", "gmail.co", "email", &field); |
| 3248 GetAutofillSuggestions(form, field); |
| 3249 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3250 |
| 3251 // Simulate displaying suggestions for field contents "buddy@gm", check that |
| 3252 // matching one is displayed. Please note here that field contents "buddy@gm" |
| 3253 // spans to multiple tokens and none of the suggestions pass |
| 3254 // |IsContentsPrefixOfSuggestionToken()|'s constrain. However; unlike our |
| 3255 // previous test; the field contents whole-text prefixes the "buddy@gmail.com" |
| 3256 // suggestion and we could see it in suggestion list. |
| 3257 test::CreateTestFormField("Email", "email", "buddy@gm", "email", &field); |
| 3258 GetAutofillSuggestions(form, field); |
| 3259 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3260 |
| 3261 external_delegate_->CheckSuggestions( |
| 3262 kDefaultPageID, |
| 3263 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 1)); |
| 3264 } |
| 3265 |
3179 } // namespace autofill | 3266 } // namespace autofill |
OLD | NEW |