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 // Verify that typing "gmail" will match "theking@gmail.com" and | |
3077 // "buddy@gmail.com" when substring matching is enabled. | |
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 email field contents "gmail", check | |
3090 // that matching emails "theking@gmail.com" and "buddy@gmail.com" are | |
3091 // displayed in suggestion list. | |
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
| |
3092 FormFieldData field; | |
3093 test::CreateTestFormField("Email", "email", "gmail", "email", &field); | |
3094 GetAutofillSuggestions(form, field); | |
3095 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3096 | |
3097 external_delegate_->CheckSuggestions( | |
3098 kDefaultPageID, | |
3099 Suggestion("theking@gmail.com", "3734 Elvis Presley Blvd.", "", 1), | |
3100 Suggestion("buddy@gmail.com", "123 Apple St.", "", 2)); | |
3101 } | |
3102 | |
3103 // Verify that typing "apple" will match "123 Apple St." when substring matching | |
3104 // is enabled. | |
3105 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens_CaseIgnored) { | |
3106 // Token matching is currently behind a flag. | |
3107 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3108 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3109 | |
3110 // Set up our form data. | |
3111 FormData form; | |
3112 test::CreateTestAddressFormData(&form); | |
3113 std::vector<FormData> forms(1, form); | |
3114 FormsSeen(forms); | |
3115 | |
3116 // Simulate displaying suggestions for address field contents "apple", check | |
3117 // that matching address "123 Apple St., unit 6" is displayed in the | |
3118 // suggestion list. | |
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
| |
3119 FormFieldData field; | |
3120 test::CreateTestFormField("Address Line 2", "addr2", "apple", "text", &field); | |
3121 GetAutofillSuggestions(form, field); | |
3122 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3123 | |
3124 external_delegate_->CheckSuggestions( | |
3125 kDefaultPageID, | |
3126 Suggestion("123 Apple St., unit 6", "123 Apple St.", "", 1)); | |
3127 } | |
3128 | |
3129 // Verify that typing "mail" will not match any of the "@gmail.com" email | |
3130 // addresses when substring matching is enabled. | |
3131 TEST_F(AutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) { | |
3132 // Token matching is currently behind a flag. | |
3133 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3134 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3135 | |
3136 // Set up our form data. | |
3137 FormData form; | |
3138 test::CreateTestAddressFormData(&form); | |
3139 std::vector<FormData> forms(1, form); | |
3140 FormsSeen(forms); | |
3141 | |
3142 // Simulate displaying suggestions for field contents "mail". Check that none | |
3143 // appear, because none of the emails emails "theking@gmail.com" or | |
3144 // "buddy@gmail.com" has a token with a prefix "mail". | |
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
| |
3145 FormFieldData field; | |
3146 test::CreateTestFormField("Email", "email", "mail", "email", &field); | |
3147 GetAutofillSuggestions(form, field); | |
3148 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | |
3149 } | |
3150 | |
3151 // Verify that typing "pres" will match "Elvis Presley" when substring matching | |
3152 // is enabled. | |
3153 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) { | |
3154 // Token matching is currently behind a flag. | |
3155 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3156 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3157 | |
3158 // Set up our form data. | |
3159 FormData form; | |
3160 CreateTestCreditCardFormData(&form, true, false); | |
3161 std::vector<FormData> forms(1, form); | |
3162 FormsSeen(forms); | |
3163 | |
3164 FormFieldData field; | |
3165 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", | |
3166 &field); | |
3167 GetAutofillSuggestions(form, field); | |
3168 | |
3169 // No suggestions provided, so send an empty vector as the results. | |
3170 // This triggers the combined message send. | |
3171 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3172 | |
3173 // Simulate displaying suggestions for credit card name field contents "pres", | |
3174 // check that matching name "Elvis Presley" is displayed in the suggestion | |
3175 // list. | |
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
| |
3176 external_delegate_->CheckSuggestions( | |
3177 kDefaultPageID, Suggestion("Elvis Presley", "*3456", kVisaCard, | |
3178 autofill_manager_->GetPackedCreditCardID(4))); | |
3179 } | |
3180 | |
3181 // Verify that typing "lvis" will not match any of the credit card name when | |
3182 // substring matching is enabled. | |
3183 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) { | |
3184 // Token matching is currently behind a flag. | |
3185 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3186 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3187 | |
3188 // Set up our form data. | |
3189 FormData form; | |
3190 CreateTestCreditCardFormData(&form, true, false); | |
3191 std::vector<FormData> forms(1, form); | |
3192 FormsSeen(forms); | |
3193 | |
3194 // Simulate displaying suggestions for field contents "lvis". Check that none | |
3195 // appear, because none card names "Elvis Presley" or "Buddy Holly" has a | |
3196 // token with a prefix "lvis". | |
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
| |
3197 FormFieldData field; | |
3198 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", | |
3199 &field); | |
3200 GetAutofillSuggestions(form, field); | |
3201 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | |
3202 } | |
3203 | |
3204 // Verify that typing "S" into the middle name field will match and order middle | |
3205 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by | |
3206 // substring matched. | |
3207 TEST_F(AutofillManagerTest, | |
3208 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { | |
3209 // Token matching is currently behind a flag. | |
3210 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
3211 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
3212 | |
3213 // Set up our form data. | |
3214 FormData form; | |
3215 test::CreateTestAddressFormData(&form); | |
3216 std::vector<FormData> forms(1, form); | |
3217 FormsSeen(forms); | |
3218 | |
3219 AutofillProfile* profile1 = new AutofillProfile; | |
3220 profile1->set_guid("00000000-0000-0000-0000-000000000103"); | |
3221 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); | |
3222 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"), | |
3223 "en-US"); | |
3224 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | |
3225 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | |
3226 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | |
3227 autofill_manager_->AddProfile(profile1); | |
3228 | |
3229 AutofillProfile* profile2 = new AutofillProfile; | |
3230 profile2->set_guid("00000000-0000-0000-0000-000000000124"); | |
3231 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); | |
3232 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"), | |
3233 "en-US"); | |
3234 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | |
3235 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | |
3236 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | |
3237 autofill_manager_->AddProfile(profile2); | |
3238 | |
3239 // Simulate displaying suggestions for middle name field contents "S", check | |
3240 // that matching ones are displayed with prefix matched suggestion "Shawn | |
3241 // Smith" placed before the substring matched suggestion "Adam Smith". | |
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
| |
3242 FormFieldData field; | |
3243 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field); | |
3244 GetAutofillSuggestions(form, field); | |
3245 | |
3246 // No suggestions provided, so send an empty vector as the results. | |
3247 // This triggers the combined message send. | |
3248 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3249 | |
3250 external_delegate_->CheckSuggestions( | |
3251 kDefaultPageID, | |
3252 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", | |
3253 1), | |
3254 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", | |
3255 2)); | |
3256 } | |
3257 | |
3076 } // namespace autofill | 3258 } // namespace autofill |
OLD | NEW |