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 3235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3246 else if (form.fields[i].name == ASCIIToUTF16("state")) | 3246 else if (form.fields[i].name == ASCIIToUTF16("state")) |
3247 form.fields[i].value = ASCIIToUTF16("Texas"); | 3247 form.fields[i].value = ASCIIToUTF16("Texas"); |
3248 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) | 3248 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) |
3249 form.fields[i].value = ASCIIToUTF16("77401"); | 3249 form.fields[i].value = ASCIIToUTF16("77401"); |
3250 else if (form.fields[i].name == ASCIIToUTF16("country")) | 3250 else if (form.fields[i].name == ASCIIToUTF16("country")) |
3251 form.fields[i].value = ASCIIToUTF16("US"); | 3251 form.fields[i].value = ASCIIToUTF16("US"); |
3252 } | 3252 } |
3253 autofill_manager_->OnFormSubmitted(form); | 3253 autofill_manager_->OnFormSubmitted(form); |
3254 } | 3254 } |
3255 | 3255 |
| 3256 // Test that suggestion tokens (substrings separated by characters from " |
| 3257 // .,-_@") are matched against field contents. |
| 3258 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { |
| 3259 // Token matching is currently behind a flag. |
| 3260 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3261 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3262 |
| 3263 // Set up our form data. |
| 3264 FormData form; |
| 3265 test::CreateTestAddressFormData(&form); |
| 3266 std::vector<FormData> forms(1, form); |
| 3267 FormsSeen(forms); |
| 3268 |
| 3269 // Simulate displaying suggestions for field contents "gmail", check that |
| 3270 // matching ones are displayed. |
| 3271 FormFieldData field; |
| 3272 test::CreateTestFormField("Email", "email", "gmail", "email", &field); |
| 3273 GetAutofillSuggestions(form, field); |
| 3274 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3275 |
| 3276 external_delegate_->CheckSuggestions( |
| 3277 kDefaultPageID, |
| 3278 Suggestion("theking@gmail.com", "Elvis Aaron Presley", "", 1), |
| 3279 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 2)); |
| 3280 } |
| 3281 |
| 3282 // Test that suggestion tokens (substrings separated by characters from " |
| 3283 // .,-_@") are matched against field contents ignoring their case. |
| 3284 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) { |
| 3285 // Token matching is currently behind a flag. |
| 3286 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3287 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3288 |
| 3289 // Set up our form data. |
| 3290 FormData form; |
| 3291 test::CreateTestAddressFormData(&form); |
| 3292 std::vector<FormData> forms(1, form); |
| 3293 FormsSeen(forms); |
| 3294 |
| 3295 // Simulate displaying suggestions for field contents "apple", check that |
| 3296 // matching one is displayed. |
| 3297 FormFieldData field; |
| 3298 test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field); |
| 3299 GetAutofillSuggestions(form, field); |
| 3300 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3301 |
| 3302 external_delegate_->CheckSuggestions( |
| 3303 kDefaultPageID, |
| 3304 Suggestion("123 Apple St., unit 6", "Charles Hardin Holley", "", 1)); |
| 3305 } |
| 3306 |
| 3307 // Test that suggestions which do not have a prefix match or prefix-token match |
| 3308 // with the field contents are not matched. |
| 3309 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) { |
| 3310 // Token matching is currently behind a flag. |
| 3311 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3312 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3313 |
| 3314 // Set up our form data. |
| 3315 FormData form; |
| 3316 test::CreateTestAddressFormData(&form); |
| 3317 std::vector<FormData> forms(1, form); |
| 3318 FormsSeen(forms); |
| 3319 |
| 3320 // Simulate displaying suggestions for field contents "mail". Check that none |
| 3321 // appear, because none has a token with a prefix "mail". |
| 3322 FormFieldData field; |
| 3323 test::CreateTestFormField("Email", "email", "mail", "email", &field); |
| 3324 GetAutofillSuggestions(form, field); |
| 3325 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3326 } |
| 3327 |
| 3328 // Test that the credit card holder name suggestion tokens (substrings separated |
| 3329 // by characters from " .,-_@") are matched against field contents. |
| 3330 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) { |
| 3331 // Token matching is currently behind a flag. |
| 3332 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3333 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3334 |
| 3335 // Set up our form data. |
| 3336 FormData form; |
| 3337 CreateTestCreditCardFormData(&form, true, false); |
| 3338 std::vector<FormData> forms(1, form); |
| 3339 FormsSeen(forms); |
| 3340 |
| 3341 FormFieldData field; |
| 3342 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", |
| 3343 &field); |
| 3344 GetAutofillSuggestions(form, field); |
| 3345 |
| 3346 // No suggestions provided, so send an empty vector as the results. |
| 3347 // This triggers the combined message send. |
| 3348 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3349 |
| 3350 // Simulate displaying suggestions for field contents "pres", check that |
| 3351 // matching one is displayed. |
| 3352 external_delegate_->CheckSuggestions( |
| 3353 kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard, |
| 3354 autofill_manager_->GetPackedCreditCardID(4))); |
| 3355 } |
| 3356 |
| 3357 // Test that the credit card holder name suggestions which do not have a prefix |
| 3358 // match or prefix-token match with the field contents are not matched. |
| 3359 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) { |
| 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 // Simulate displaying suggestions for field contents "lvis". Check that none |
| 3371 // appear, because none has a token with a prefix "lvis". |
| 3372 FormFieldData field; |
| 3373 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", |
| 3374 &field); |
| 3375 GetAutofillSuggestions(form, field); |
| 3376 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3377 } |
| 3378 |
3256 } // namespace autofill | 3379 } // namespace autofill |
OLD | NEW |