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 are not matched when the field contents spans multiple |
| 3206 // tokens (substrings separated by characters from " .,-_@"). |
| 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 that suggestion tokens (substrings separated by characters from " |
| 3227 // .,-_@") are matched against field contents containing tokens along the token |
| 3228 // separators. |
| 3229 TEST_F(AutofillManagerTest, |
| 3230 DisplaySuggestionsWithMatchingTokensAndContentsHaveSeperator) { |
| 3231 // Token matching is currently behind a flag. |
| 3232 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3233 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3234 |
| 3235 // Set up our form data. |
| 3236 FormData form; |
| 3237 test::CreateTestAddressFormData(&form); |
| 3238 std::vector<FormData> forms(1, form); |
| 3239 FormsSeen(forms); |
| 3240 |
| 3241 // Simulate displaying suggestions for field contents "buddy@gma", check that |
| 3242 // matching ones are displayed. |
| 3243 FormFieldData field; |
| 3244 test::CreateTestFormField("Email", "email", "buddy@gma", "email", &field); |
| 3245 GetAutofillSuggestions(form, field); |
| 3246 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3247 |
| 3248 external_delegate_->CheckSuggestions( |
| 3249 kDefaultPageID, |
| 3250 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 1)); |
| 3251 } |
| 3252 |
3179 } // namespace autofill | 3253 } // namespace autofill |
OLD | NEW |