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 3055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3066 else if (form.fields[i].name == ASCIIToUTF16("state")) | 3066 else if (form.fields[i].name == ASCIIToUTF16("state")) |
3067 form.fields[i].value = ASCIIToUTF16("Texas"); | 3067 form.fields[i].value = ASCIIToUTF16("Texas"); |
3068 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) | 3068 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) |
3069 form.fields[i].value = ASCIIToUTF16("77401"); | 3069 form.fields[i].value = ASCIIToUTF16("77401"); |
3070 else if (form.fields[i].name == ASCIIToUTF16("country")) | 3070 else if (form.fields[i].name == ASCIIToUTF16("country")) |
3071 form.fields[i].value = ASCIIToUTF16("US"); | 3071 form.fields[i].value = ASCIIToUTF16("US"); |
3072 } | 3072 } |
3073 autofill_manager_->OnFormSubmitted(form); | 3073 autofill_manager_->OnFormSubmitted(form); |
3074 } | 3074 } |
3075 | 3075 |
| 3076 // Test that suggestion tokens (substrings separated by characters from " |
| 3077 // .,-_@") are matched against field contents. |
| 3078 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { |
| 3079 // Token matching is currently behind a flag. |
| 3080 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3081 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3082 |
| 3083 // Set up our form data. |
| 3084 FormData form; |
| 3085 test::CreateTestAddressFormData(&form); |
| 3086 std::vector<FormData> forms(1, form); |
| 3087 FormsSeen(forms); |
| 3088 |
| 3089 // Simulate displaying suggestions for field contents "gmail", check that |
| 3090 // matching ones are displayed. |
| 3091 FormFieldData field; |
| 3092 test::CreateTestFormField("Email", "email", "gmail", "email", &field); |
| 3093 GetAutofillSuggestions(form, field); |
| 3094 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3095 |
| 3096 external_delegate_->CheckSuggestions( |
| 3097 kDefaultPageID, |
| 3098 Suggestion("theking@gmail.com", "Elvis Aaron Presley", "", 1), |
| 3099 Suggestion("buddy@gmail.com", "Charles Hardin Holley", "", 2)); |
| 3100 } |
| 3101 |
| 3102 // Test that suggestion tokens (substrings separated by characters from " |
| 3103 // .,-_@") are matched against field contents ignoring their case. |
| 3104 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) { |
| 3105 // Token matching is currently behind a flag. |
| 3106 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3107 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3108 |
| 3109 // Set up our form data. |
| 3110 FormData form; |
| 3111 test::CreateTestAddressFormData(&form); |
| 3112 std::vector<FormData> forms(1, form); |
| 3113 FormsSeen(forms); |
| 3114 |
| 3115 // Simulate displaying suggestions for field contents "apple", check that |
| 3116 // matching one is displayed. |
| 3117 FormFieldData field; |
| 3118 test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field); |
| 3119 GetAutofillSuggestions(form, field); |
| 3120 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3121 |
| 3122 external_delegate_->CheckSuggestions( |
| 3123 kDefaultPageID, |
| 3124 Suggestion("123 Apple St., unit 6", "Charles Hardin Holley", "", 1)); |
| 3125 } |
| 3126 |
| 3127 // Test that suggestions which do not have a prefix match or prefix-token match |
| 3128 // with the field contents are not matched. |
| 3129 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) { |
| 3130 // Token matching is currently behind a flag. |
| 3131 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3132 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3133 |
| 3134 // Set up our form data. |
| 3135 FormData form; |
| 3136 test::CreateTestAddressFormData(&form); |
| 3137 std::vector<FormData> forms(1, form); |
| 3138 FormsSeen(forms); |
| 3139 |
| 3140 // Simulate displaying suggestions for field contents "mail". Check that none |
| 3141 // appear, because none has a token with a prefix "mail". |
| 3142 FormFieldData field; |
| 3143 test::CreateTestFormField("Email", "email", "mail", "email", &field); |
| 3144 GetAutofillSuggestions(form, field); |
| 3145 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3146 } |
| 3147 |
| 3148 // Test that the credit card holder name suggestion tokens (substrings separated |
| 3149 // by characters from " .,-_@") are matched against field contents. |
| 3150 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) { |
| 3151 // Token matching is currently behind a flag. |
| 3152 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3153 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3154 |
| 3155 // Set up our form data. |
| 3156 FormData form; |
| 3157 CreateTestCreditCardFormData(&form, true, false); |
| 3158 std::vector<FormData> forms(1, form); |
| 3159 FormsSeen(forms); |
| 3160 |
| 3161 FormFieldData field; |
| 3162 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", |
| 3163 &field); |
| 3164 GetAutofillSuggestions(form, field); |
| 3165 |
| 3166 // No suggestions provided, so send an empty vector as the results. |
| 3167 // This triggers the combined message send. |
| 3168 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3169 |
| 3170 // Simulate displaying suggestions for field contents "pres", check that |
| 3171 // matching one is displayed. |
| 3172 external_delegate_->CheckSuggestions( |
| 3173 kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard, |
| 3174 autofill_manager_->GetPackedCreditCardID(4))); |
| 3175 } |
| 3176 |
| 3177 // Test that the credit card holder name suggestions which do not have a prefix |
| 3178 // match or prefix-token match with the field contents are not matched. |
| 3179 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) { |
| 3180 // Token matching is currently behind a flag. |
| 3181 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3182 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3183 |
| 3184 // Set up our form data. |
| 3185 FormData form; |
| 3186 CreateTestCreditCardFormData(&form, true, false); |
| 3187 std::vector<FormData> forms(1, form); |
| 3188 FormsSeen(forms); |
| 3189 |
| 3190 // Simulate displaying suggestions for field contents "lvis". Check that none |
| 3191 // appear, because none has a token with a prefix "lvis". |
| 3192 FormFieldData field; |
| 3193 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", |
| 3194 &field); |
| 3195 GetAutofillSuggestions(form, field); |
| 3196 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3197 } |
| 3198 |
| 3199 // Test that suggestion tokens (substrings separated by characters from |
| 3200 // " .,-_@") are ordered prefixes precede substring matched. |
| 3201 TEST_F(AutofillManagerTest, |
| 3202 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { |
| 3203 // Token matching is currently behind a flag. |
| 3204 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3205 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 3206 |
| 3207 // Set up our form data. |
| 3208 FormData form; |
| 3209 test::CreateTestAddressFormData(&form); |
| 3210 std::vector<FormData> forms(1, form); |
| 3211 FormsSeen(forms); |
| 3212 |
| 3213 AutofillProfile* profile1 = new AutofillProfile; |
| 3214 profile1->set_guid("00000000-0000-0000-0000-000000000103"); |
| 3215 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); |
| 3216 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"), |
| 3217 "en-US"); |
| 3218 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 3219 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 3220 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 3221 autofill_manager_->AddProfile(profile1); |
| 3222 |
| 3223 AutofillProfile* profile2 = new AutofillProfile; |
| 3224 profile2->set_guid("00000000-0000-0000-0000-000000000124"); |
| 3225 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); |
| 3226 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"), |
| 3227 "en-US"); |
| 3228 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 3229 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 3230 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 3231 autofill_manager_->AddProfile(profile2); |
| 3232 |
| 3233 // Simulate displaying suggestions for field contents "S", check that |
| 3234 // matching ones are displayed. |
| 3235 FormFieldData field; |
| 3236 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field); |
| 3237 GetAutofillSuggestions(form, field); |
| 3238 |
| 3239 // No suggestions provided, so send an empty vector as the results. |
| 3240 // This triggers the combined message send. |
| 3241 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3242 |
| 3243 external_delegate_->CheckSuggestions( |
| 3244 kDefaultPageID, |
| 3245 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", |
| 3246 1), |
| 3247 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", |
| 3248 2)); |
| 3249 } |
| 3250 |
3076 } // namespace autofill | 3251 } // namespace autofill |
OLD | NEW |