Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/scoped_vector.h" | 10 #include "base/scoped_vector.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 const int kDefaultPageID = 137; | 41 const int kDefaultPageID = 137; |
| 42 | 42 |
| 43 typedef Tuple5<int, | 43 typedef Tuple5<int, |
| 44 std::vector<string16>, | 44 std::vector<string16>, |
| 45 std::vector<string16>, | 45 std::vector<string16>, |
| 46 std::vector<string16>, | 46 std::vector<string16>, |
| 47 std::vector<int> > AutoFillParam; | 47 std::vector<int> > AutoFillParam; |
| 48 | 48 |
| 49 class TestPersonalDataManager : public PersonalDataManager { | 49 class TestPersonalDataManager : public PersonalDataManager { |
| 50 public: | 50 public: |
| 51 TestPersonalDataManager() { | 51 explicit TestPersonalDataManager(bool four_credit_cards) { |
| 52 CreateTestAutoFillProfiles(&web_profiles_); | 52 CreateTestAutoFillProfiles(&web_profiles_); |
| 53 CreateTestCreditCards(&credit_cards_); | 53 CreateTestCreditCards(&credit_cards_, four_credit_cards); |
| 54 } | 54 } |
| 55 | 55 |
| 56 virtual void InitializeIfNeeded() {} | 56 virtual void InitializeIfNeeded() {} |
| 57 virtual void SaveImportedFormData() {} | 57 virtual void SaveImportedFormData() {} |
| 58 virtual bool IsDataLoaded() const { return true; } | 58 virtual bool IsDataLoaded() const { return true; } |
| 59 | 59 |
| 60 AutoFillProfile* GetLabeledProfile(const char* label) { | 60 AutoFillProfile* GetLabeledProfile(const char* label) { |
| 61 for (std::vector<AutoFillProfile *>::iterator it = web_profiles_.begin(); | 61 for (std::vector<AutoFillProfile *>::iterator it = web_profiles_.begin(); |
| 62 it != web_profiles_.end(); ++it) { | 62 it != web_profiles_.end(); ++it) { |
| 63 if (!(*it)->Label().compare(ASCIIToUTF16(label))) | 63 if (!(*it)->Label().compare(ASCIIToUTF16(label))) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 ""); | 105 ""); |
| 106 profile->set_guid("00000000-0000-0000-0000-000000000002"); | 106 profile->set_guid("00000000-0000-0000-0000-000000000002"); |
| 107 profiles->push_back(profile); | 107 profiles->push_back(profile); |
| 108 profile = new AutoFillProfile; | 108 profile = new AutoFillProfile; |
| 109 autofill_test::SetProfileInfo(profile, "Empty", "", "", "", "", "", "", "", | 109 autofill_test::SetProfileInfo(profile, "Empty", "", "", "", "", "", "", "", |
| 110 "", "", "", "", "", ""); | 110 "", "", "", "", "", ""); |
| 111 profile->set_guid("00000000-0000-0000-0000-000000000003"); | 111 profile->set_guid("00000000-0000-0000-0000-000000000003"); |
| 112 profiles->push_back(profile); | 112 profiles->push_back(profile); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { | 115 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards, |
| 116 CreditCard* credit_card = new CreditCard; | 116 bool four_credit_cards) { |
| 117 autofill_test::SetCreditCardInfo(credit_card, "First", "Elvis Presley", | 117 if (!four_credit_cards) { |
| 118 "4234567890123456", // Visa | 118 CreditCard* credit_card = new CreditCard; |
| 119 "04", "2012"); | 119 autofill_test::SetCreditCardInfo(credit_card, "First", "Elvis Presley", |
| 120 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); | 120 "4234567890123456", // Visa |
|
dhollowa
2011/01/07 20:43:39
nit: indentation should be at open paren. And bel
| |
| 121 credit_cards->push_back(credit_card); | 121 "04", "2012"); |
| 122 credit_card = new CreditCard; | 122 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| 123 autofill_test::SetCreditCardInfo(credit_card, "Second", "Buddy Holly", | 123 credit_cards->push_back(credit_card); |
| 124 "5187654321098765", // Mastercard | 124 credit_card = new CreditCard; |
| 125 "10", "2014"); | 125 autofill_test::SetCreditCardInfo(credit_card, "Second", "Buddy Holly", |
| 126 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 126 "5187654321098765", // Mastercard |
| 127 credit_cards->push_back(credit_card); | 127 "10", "2014"); |
| 128 credit_card = new CreditCard; | 128 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| 129 autofill_test::SetCreditCardInfo(credit_card, "Empty", "", "", "", ""); | 129 credit_cards->push_back(credit_card); |
| 130 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 130 credit_card = new CreditCard; |
| 131 credit_cards->push_back(credit_card); | 131 autofill_test::SetCreditCardInfo(credit_card, "Empty", "", "", "", ""); |
| 132 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | |
| 133 credit_cards->push_back(credit_card); | |
| 134 } else { | |
| 135 // Create four credit cards with year month combination as following, | |
| 136 // 1. year empty, month empty | |
| 137 CreditCard* credit_card = new CreditCard; | |
| 138 autofill_test::SetCreditCardInfo(credit_card, "Miku0", | |
| 139 "Miku Hatsune", | |
| 140 "4234567890654321", // Visa | |
| 141 "", ""); | |
| 142 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | |
| 143 credit_cards->push_back(credit_card); | |
| 144 // 2. year empty, month non-empty | |
| 145 credit_card = new CreditCard; | |
| 146 autofill_test::SetCreditCardInfo(credit_card, "Miku1", | |
| 147 "Miku Hatsune", | |
| 148 "4234567890654321", // Visa | |
| 149 "04", ""); | |
| 150 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | |
| 151 credit_cards->push_back(credit_card); | |
| 152 // 3. year non-empty, month empty | |
| 153 credit_card = new CreditCard; | |
| 154 autofill_test::SetCreditCardInfo(credit_card, "Miku2", | |
| 155 "Miku Hatsune", | |
| 156 "4234567890654321", // Visa | |
| 157 "", "2012"); | |
| 158 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); | |
| 159 credit_cards->push_back(credit_card); | |
| 160 // 4. both non-empty | |
| 161 credit_card = new CreditCard; | |
| 162 autofill_test::SetCreditCardInfo(credit_card, "Miku3", | |
| 163 "Miku Hatsune", | |
| 164 "4234567890654321", // Visa | |
| 165 "04", "2012"); | |
| 166 credit_card->set_guid("00000000-0000-0000-0000-000000000010"); | |
| 167 credit_cards->push_back(credit_card); | |
| 168 } | |
| 132 } | 169 } |
| 133 | 170 |
| 134 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 171 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 135 }; | 172 }; |
| 136 | 173 |
| 137 // Populates |form| with data corresponding to a simple address form. | 174 // Populates |form| with data corresponding to a simple address form. |
| 138 // Note that this actually appends fields to the form data, which can be useful | 175 // Note that this actually appends fields to the form data, which can be useful |
| 139 // for building up more complex test forms. | 176 // for building up more complex test forms. |
| 140 void CreateTestAddressFormData(FormData* form) { | 177 void CreateTestAddressFormData(FormData* form) { |
| 141 form->name = ASCIIToUTF16("MyForm"); | 178 form->name = ASCIIToUTF16("MyForm"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 form->fields.push_back(field); | 211 form->fields.push_back(field); |
| 175 autofill_test::CreateTestFormField( | 212 autofill_test::CreateTestFormField( |
| 176 "Phone Number", "phonenumber", "", "text", &field); | 213 "Phone Number", "phonenumber", "", "text", &field); |
| 177 form->fields.push_back(field); | 214 form->fields.push_back(field); |
| 178 autofill_test::CreateTestFormField( | 215 autofill_test::CreateTestFormField( |
| 179 "Fax", "fax", "", "text", &field); | 216 "Fax", "fax", "", "text", &field); |
| 180 form->fields.push_back(field); | 217 form->fields.push_back(field); |
| 181 autofill_test::CreateTestFormField( | 218 autofill_test::CreateTestFormField( |
| 182 "Email", "email", "", "text", &field); | 219 "Email", "email", "", "text", &field); |
| 183 form->fields.push_back(field); | 220 form->fields.push_back(field); |
| 184 } | 221 autofill_test::CreateTestFormField( |
| 222 "Email", "email2", "", "email", &field); | |
| 223 form->fields.push_back(field); | |
| 224 autofill_test::CreateTestFormField( | |
| 225 "Phone Number", "phonenumber2", "", "tel", &field); | |
| 226 form->fields.push_back(field); | |
| 227 } | |
| 185 | 228 |
| 186 // Populates |form| with data corresponding to a simple credit card form. | 229 // Populates |form| with data corresponding to a simple credit card form. |
| 187 // Note that this actually appends fields to the form data, which can be useful | 230 // Note that this actually appends fields to the form data, which can be useful |
| 188 // for building up more complex test forms. | 231 // for building up more complex test forms. |
| 189 void CreateTestCreditCardFormData(FormData* form, bool is_https) { | 232 void CreateTestCreditCardFormData(FormData* form, |
| 233 bool is_https, | |
| 234 bool use_month_type) { | |
| 190 form->name = ASCIIToUTF16("MyForm"); | 235 form->name = ASCIIToUTF16("MyForm"); |
| 191 form->method = ASCIIToUTF16("POST"); | 236 form->method = ASCIIToUTF16("POST"); |
| 192 if (is_https) { | 237 if (is_https) { |
| 193 form->origin = GURL("https://myform.com/form.html"); | 238 form->origin = GURL("https://myform.com/form.html"); |
| 194 form->action = GURL("https://myform.com/submit.html"); | 239 form->action = GURL("https://myform.com/submit.html"); |
| 195 } else { | 240 } else { |
| 196 form->origin = GURL("http://myform.com/form.html"); | 241 form->origin = GURL("http://myform.com/form.html"); |
| 197 form->action = GURL("http://myform.com/submit.html"); | 242 form->action = GURL("http://myform.com/submit.html"); |
| 198 } | 243 } |
| 199 form->user_submitted = true; | 244 form->user_submitted = true; |
| 200 | 245 |
| 201 FormField field; | 246 FormField field; |
| 202 autofill_test::CreateTestFormField( | 247 autofill_test::CreateTestFormField( |
| 203 "Name on Card", "nameoncard", "", "text", &field); | 248 "Name on Card", "nameoncard", "", "text", &field); |
| 204 form->fields.push_back(field); | 249 form->fields.push_back(field); |
| 205 autofill_test::CreateTestFormField( | 250 autofill_test::CreateTestFormField( |
| 206 "Card Number", "cardnumber", "", "text", &field); | 251 "Card Number", "cardnumber", "", "text", &field); |
| 207 form->fields.push_back(field); | 252 form->fields.push_back(field); |
| 208 autofill_test::CreateTestFormField( | 253 if (use_month_type) { |
| 209 "Expiration Date", "ccmonth", "", "text", &field); | 254 autofill_test::CreateTestFormField( |
| 210 form->fields.push_back(field); | 255 "Expiration Date", "ccmonth", "", "month", &field); |
| 211 autofill_test::CreateTestFormField( | 256 form->fields.push_back(field); |
| 212 "", "ccyear", "", "text", &field); | 257 } else { |
| 213 form->fields.push_back(field); | 258 autofill_test::CreateTestFormField( |
| 259 "Expiration Date", "ccmonth", "", "text", &field); | |
| 260 form->fields.push_back(field); | |
| 261 autofill_test::CreateTestFormField( | |
| 262 "", "ccyear", "", "text", &field); | |
| 263 form->fields.push_back(field); | |
| 264 } | |
| 214 } | 265 } |
| 215 | 266 |
| 216 void ExpectSuggestions(int page_id, | 267 void ExpectSuggestions(int page_id, |
| 217 const std::vector<string16>& values, | 268 const std::vector<string16>& values, |
| 218 const std::vector<string16>& labels, | 269 const std::vector<string16>& labels, |
| 219 const std::vector<string16>& icons, | 270 const std::vector<string16>& icons, |
| 220 const std::vector<int>& unique_ids, | 271 const std::vector<int>& unique_ids, |
| 221 int expected_page_id, | 272 int expected_page_id, |
| 222 size_t expected_num_suggestions, | 273 size_t expected_num_suggestions, |
| 223 const string16 expected_values[], | 274 const string16 expected_values[], |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 234 EXPECT_EQ(expected_values[i], values[i]); | 285 EXPECT_EQ(expected_values[i], values[i]); |
| 235 EXPECT_EQ(expected_labels[i], labels[i]); | 286 EXPECT_EQ(expected_labels[i], labels[i]); |
| 236 EXPECT_EQ(expected_icons[i], icons[i]); | 287 EXPECT_EQ(expected_icons[i], icons[i]); |
| 237 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); | 288 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); |
| 238 } | 289 } |
| 239 } | 290 } |
| 240 | 291 |
| 241 // Verifies that the |filled_form| has been filled with the given data. | 292 // Verifies that the |filled_form| has been filled with the given data. |
| 242 // Verifies address fields if |has_address_fields| is true, and verifies | 293 // Verifies address fields if |has_address_fields| is true, and verifies |
| 243 // credit card fields if |has_credit_card_fields| is true. Verifies both if both | 294 // credit card fields if |has_credit_card_fields| is true. Verifies both if both |
| 244 // are true. | 295 // are true. |use_month_type| is used for credit card input month type. |
| 245 void ExpectFilledForm(int page_id, | 296 void ExpectFilledForm(int page_id, |
| 246 const FormData& filled_form, | 297 const FormData& filled_form, |
| 247 int expected_page_id, | 298 int expected_page_id, |
| 248 const char* first, | 299 const char* first, |
| 249 const char* middle, | 300 const char* middle, |
| 250 const char* last, | 301 const char* last, |
| 251 const char* address1, | 302 const char* address1, |
| 252 const char* address2, | 303 const char* address2, |
| 253 const char* city, | 304 const char* city, |
| 254 const char* state, | 305 const char* state, |
| 255 const char* postal_code, | 306 const char* postal_code, |
| 256 const char* country, | 307 const char* country, |
| 257 const char* phone, | 308 const char* phone, |
| 258 const char* fax, | 309 const char* fax, |
| 259 const char* email, | 310 const char* email, |
| 260 const char* name_on_card, | 311 const char* name_on_card, |
| 261 const char* card_number, | 312 const char* card_number, |
| 262 const char* expiration_month, | 313 const char* expiration_month, |
| 263 const char* expiration_year, | 314 const char* expiration_year, |
| 264 bool has_address_fields, | 315 bool has_address_fields, |
| 265 bool has_credit_card_fields) { | 316 bool has_credit_card_fields, |
| 317 int use_month_type) { | |
| 266 // The number of fields in the address and credit card forms created above. | 318 // The number of fields in the address and credit card forms created above. |
| 267 const size_t kAddressFormSize = 12; | 319 const size_t kAddressFormSize = 14; |
| 268 const size_t kCreditCardFormSize = 4; | 320 const size_t kCreditCardFormSize = use_month_type ? 3 : 4; |
| 269 | 321 |
| 270 EXPECT_EQ(expected_page_id, page_id); | 322 EXPECT_EQ(expected_page_id, page_id); |
| 271 EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name); | 323 EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name); |
| 272 EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method); | 324 EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method); |
| 273 if (has_credit_card_fields) { | 325 if (has_credit_card_fields) { |
| 274 EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin); | 326 EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin); |
| 275 EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action); | 327 EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action); |
| 276 } else { | 328 } else { |
| 277 EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin); | 329 EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin); |
| 278 EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action); | 330 EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); | 369 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); |
| 318 autofill_test::CreateTestFormField( | 370 autofill_test::CreateTestFormField( |
| 319 "Phone Number", "phonenumber", phone, "text", &field); | 371 "Phone Number", "phonenumber", phone, "text", &field); |
| 320 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); | 372 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); |
| 321 autofill_test::CreateTestFormField( | 373 autofill_test::CreateTestFormField( |
| 322 "Fax", "fax", fax, "text", &field); | 374 "Fax", "fax", fax, "text", &field); |
| 323 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); | 375 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); |
| 324 autofill_test::CreateTestFormField( | 376 autofill_test::CreateTestFormField( |
| 325 "Email", "email", email, "text", &field); | 377 "Email", "email", email, "text", &field); |
| 326 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); | 378 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); |
| 327 } | 379 autofill_test::CreateTestFormField( |
| 380 "Email", "email2", email, "email", &field); | |
| 381 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[12])); | |
| 382 autofill_test::CreateTestFormField( | |
| 383 "Phone Number", "phonenumber2", phone, "tel", &field); | |
| 384 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[13])); | |
| 385 } | |
| 328 | 386 |
| 329 if (has_credit_card_fields) { | 387 if (has_credit_card_fields) { |
| 330 size_t offset = has_address_fields? kAddressFormSize : 0; | 388 size_t offset = has_address_fields? kAddressFormSize : 0; |
| 331 autofill_test::CreateTestFormField( | 389 autofill_test::CreateTestFormField( |
| 332 "Name on Card", "nameoncard", name_on_card, "text", &field); | 390 "Name on Card", "nameoncard", name_on_card, "text", &field); |
| 333 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); | 391 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); |
| 334 autofill_test::CreateTestFormField( | 392 autofill_test::CreateTestFormField( |
| 335 "Card Number", "cardnumber", card_number, "text", &field); | 393 "Card Number", "cardnumber", card_number, "text", &field); |
| 336 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); | 394 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); |
| 337 autofill_test::CreateTestFormField( | 395 if (use_month_type) { |
| 338 "Expiration Date", "ccmonth", expiration_month, "text", &field); | 396 std::string exp_year = expiration_year; |
| 339 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | 397 std::string exp_month = expiration_month; |
| 340 autofill_test::CreateTestFormField( | 398 std::string year_month; |
| 341 "", "ccyear", expiration_year, "text", &field); | 399 if (!exp_year.empty() && !exp_month.empty()) |
| 342 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); | 400 year_month = exp_year + "-" + exp_month; |
| 401 autofill_test::CreateTestFormField("Expiration Date", "ccmonth", | |
| 402 year_month.c_str(), "month", &field); | |
| 403 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | |
| 404 } else { | |
| 405 autofill_test::CreateTestFormField( | |
| 406 "Expiration Date", "ccmonth", expiration_month, "text", &field); | |
| 407 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | |
| 408 autofill_test::CreateTestFormField( | |
| 409 "", "ccyear", expiration_year, "text", &field); | |
| 410 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); | |
| 411 } | |
| 343 } | 412 } |
| 344 } | 413 } |
| 345 | 414 |
| 346 void ExpectFilledAddressFormElvis(int page_id, | 415 void ExpectFilledAddressFormElvis(int page_id, |
| 347 const FormData& filled_form, | 416 const FormData& filled_form, |
| 348 int expected_page_id, | 417 int expected_page_id, |
| 349 bool has_credit_card_fields) { | 418 bool has_credit_card_fields) { |
| 350 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", | 419 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", |
| 351 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", | 420 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", |
| 352 "Tennessee", "38116", "USA", "12345678901", "", | 421 "Tennessee", "38116", "USA", "12345678901", "", |
| 353 "theking@gmail.com", "", "", "", "", true, | 422 "theking@gmail.com", "", "", "", "", true, |
| 354 has_credit_card_fields); | 423 has_credit_card_fields, false); |
| 355 } | 424 } |
| 356 | 425 |
| 357 void ExpectFilledCreditCardFormElvis(int page_id, | 426 void ExpectFilledCreditCardFormElvis(int page_id, |
| 358 const FormData& filled_form, | 427 const FormData& filled_form, |
| 359 int expected_page_id, | 428 int expected_page_id, |
| 360 bool has_address_fields) { | 429 bool has_address_fields) { |
| 361 ExpectFilledForm(page_id, filled_form, expected_page_id, | 430 ExpectFilledForm(page_id, filled_form, expected_page_id, |
| 362 "", "", "", "", "", "", "", "", "", "", "", "", | 431 "", "", "", "", "", "", "", "", "", "", "", "", |
| 363 "Elvis Presley", "4234567890123456", "04", "2012", | 432 "Elvis Presley", "4234567890123456", "04", "2012", |
| 364 has_address_fields, true); | 433 has_address_fields, true, false); |
| 434 } | |
| 435 | |
| 436 void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id, | |
| 437 const FormData& filled_form, | |
| 438 int expected_page_id, | |
| 439 bool has_address_fields, | |
| 440 const char* year, | |
| 441 const char* month) { | |
| 442 ExpectFilledForm(page_id, filled_form, expected_page_id, | |
| 443 "", "", "", "", "", "", "", "", "", "", "", "", | |
| 444 "Miku Hatsune", "4234567890654321", month, year, | |
| 445 has_address_fields, true, true); | |
| 365 } | 446 } |
| 366 | 447 |
| 367 class TestAutoFillManager : public AutoFillManager { | 448 class TestAutoFillManager : public AutoFillManager { |
| 368 public: | 449 public: |
| 369 TestAutoFillManager(TabContents* tab_contents, | 450 TestAutoFillManager(TabContents* tab_contents, |
| 370 TestPersonalDataManager* personal_manager) | 451 TestPersonalDataManager* personal_manager) |
| 371 : AutoFillManager(tab_contents, personal_manager), | 452 : AutoFillManager(tab_contents, personal_manager), |
| 372 autofill_enabled_(true) { | 453 autofill_enabled_(true) { |
| 373 test_personal_data_ = personal_manager; | 454 test_personal_data_ = personal_manager; |
| 374 } | 455 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 AutoFillManagerTest() {} | 507 AutoFillManagerTest() {} |
| 427 virtual ~AutoFillManagerTest() { | 508 virtual ~AutoFillManagerTest() { |
| 428 // Order of destruction is important as AutoFillManager relies on | 509 // Order of destruction is important as AutoFillManager relies on |
| 429 // PersonalDataManager to be around when it gets destroyed. | 510 // PersonalDataManager to be around when it gets destroyed. |
| 430 autofill_manager_.reset(NULL); | 511 autofill_manager_.reset(NULL); |
| 431 test_personal_data_ = NULL; | 512 test_personal_data_ = NULL; |
| 432 } | 513 } |
| 433 | 514 |
| 434 virtual void SetUp() { | 515 virtual void SetUp() { |
| 435 RenderViewHostTestHarness::SetUp(); | 516 RenderViewHostTestHarness::SetUp(); |
| 436 test_personal_data_ = new TestPersonalDataManager(); | 517 test_personal_data_ = new TestPersonalDataManager(false); |
| 437 autofill_manager_.reset(new TestAutoFillManager(contents(), | 518 autofill_manager_.reset(new TestAutoFillManager(contents(), |
| 438 test_personal_data_.get())); | 519 test_personal_data_.get())); |
| 439 } | 520 } |
| 440 | 521 |
| 441 Profile* profile() { return contents()->profile(); } | 522 Profile* profile() { return contents()->profile(); } |
| 442 | 523 |
| 443 bool GetAutoFillSuggestionsMessage(int* page_id, | 524 bool GetAutoFillSuggestionsMessage(int* page_id, |
| 444 std::vector<string16>* values, | 525 std::vector<string16>* values, |
| 445 std::vector<string16>* labels, | 526 std::vector<string16>* labels, |
| 446 std::vector<string16>* icons, | 527 std::vector<string16>* icons, |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 // Now clear the test profiles and try again -- we shouldn't return a warning. | 807 // Now clear the test profiles and try again -- we shouldn't return a warning. |
| 727 test_personal_data_->ClearAutoFillProfiles(); | 808 test_personal_data_->ClearAutoFillProfiles(); |
| 728 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 809 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 729 } | 810 } |
| 730 | 811 |
| 731 // Test that we return all credit card profile suggestions when all form fields | 812 // Test that we return all credit card profile suggestions when all form fields |
| 732 // are empty. | 813 // are empty. |
| 733 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 814 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { |
| 734 // Set up our form data. | 815 // Set up our form data. |
| 735 FormData form; | 816 FormData form; |
| 736 CreateTestCreditCardFormData(&form, true); | 817 CreateTestCreditCardFormData(&form, true, false); |
| 737 std::vector<FormData> forms(1, form); | 818 std::vector<FormData> forms(1, form); |
| 738 autofill_manager_->FormsSeen(forms); | 819 autofill_manager_->FormsSeen(forms); |
| 739 | 820 |
| 740 FormField field = form.fields[1]; | 821 FormField field = form.fields[1]; |
| 741 rvh()->ResetAutoFillState(kDefaultPageID); | 822 rvh()->ResetAutoFillState(kDefaultPageID); |
| 742 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 823 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 743 | 824 |
| 744 // No suggestions provided, so send an empty vector as the results. | 825 // No suggestions provided, so send an empty vector as the results. |
| 745 // This triggers the combined message send. | 826 // This triggers the combined message send. |
| 746 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 827 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 770 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 851 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 771 kDefaultPageID, arraysize(expected_values), expected_values, | 852 kDefaultPageID, arraysize(expected_values), expected_values, |
| 772 expected_labels, expected_icons, expected_unique_ids); | 853 expected_labels, expected_icons, expected_unique_ids); |
| 773 } | 854 } |
| 774 | 855 |
| 775 // Test that we return only matching credit card profile suggestions when the | 856 // Test that we return only matching credit card profile suggestions when the |
| 776 // selected form field has been partially filled out. | 857 // selected form field has been partially filled out. |
| 777 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 858 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
| 778 // Set up our form data. | 859 // Set up our form data. |
| 779 FormData form; | 860 FormData form; |
| 780 CreateTestCreditCardFormData(&form, true); | 861 CreateTestCreditCardFormData(&form, true, false); |
| 781 std::vector<FormData> forms(1, form); | 862 std::vector<FormData> forms(1, form); |
| 782 autofill_manager_->FormsSeen(forms); | 863 autofill_manager_->FormsSeen(forms); |
| 783 | 864 |
| 784 FormField field; | 865 FormField field; |
| 785 autofill_test::CreateTestFormField( | 866 autofill_test::CreateTestFormField( |
| 786 "Card Number", "cardnumber", "4", "text", &field); | 867 "Card Number", "cardnumber", "4", "text", &field); |
| 787 rvh()->ResetAutoFillState(kDefaultPageID); | 868 rvh()->ResetAutoFillState(kDefaultPageID); |
| 788 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 869 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 789 | 870 |
| 790 // No suggestions provided, so send an empty vector as the results. | 871 // No suggestions provided, so send an empty vector as the results. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 807 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 888 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 808 kDefaultPageID, arraysize(expected_values), expected_values, | 889 kDefaultPageID, arraysize(expected_values), expected_values, |
| 809 expected_labels, expected_icons, expected_unique_ids); | 890 expected_labels, expected_icons, expected_unique_ids); |
| 810 } | 891 } |
| 811 | 892 |
| 812 // Test that we return credit card profile suggestions when the selected form | 893 // Test that we return credit card profile suggestions when the selected form |
| 813 // field is not the credit card number field. | 894 // field is not the credit card number field. |
| 814 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { | 895 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { |
| 815 // Set up our form data. | 896 // Set up our form data. |
| 816 FormData form; | 897 FormData form; |
| 817 CreateTestCreditCardFormData(&form, true); | 898 CreateTestCreditCardFormData(&form, true, false); |
| 818 std::vector<FormData> forms(1, form); | 899 std::vector<FormData> forms(1, form); |
| 819 autofill_manager_->FormsSeen(forms); | 900 autofill_manager_->FormsSeen(forms); |
| 820 | 901 |
| 821 const FormField& field = form.fields[0]; | 902 const FormField& field = form.fields[0]; |
| 822 rvh()->ResetAutoFillState(kDefaultPageID); | 903 rvh()->ResetAutoFillState(kDefaultPageID); |
| 823 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 904 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 824 | 905 |
| 825 // No suggestions provided, so send an empty vector as the results. | 906 // No suggestions provided, so send an empty vector as the results. |
| 826 // This triggers the combined message send. | 907 // This triggers the combined message send. |
| 827 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 908 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 851 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 932 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 852 kDefaultPageID, arraysize(expected_values), expected_values, | 933 kDefaultPageID, arraysize(expected_values), expected_values, |
| 853 expected_labels, expected_icons, expected_unique_ids); | 934 expected_labels, expected_icons, expected_unique_ids); |
| 854 } | 935 } |
| 855 | 936 |
| 856 // Test that we return a warning explaining that credit card profile suggestions | 937 // Test that we return a warning explaining that credit card profile suggestions |
| 857 // are unavailable when the form is not https. | 938 // are unavailable when the form is not https. |
| 858 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 939 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
| 859 // Set up our form data. | 940 // Set up our form data. |
| 860 FormData form; | 941 FormData form; |
| 861 CreateTestCreditCardFormData(&form, false); | 942 CreateTestCreditCardFormData(&form, false, false); |
| 862 std::vector<FormData> forms(1, form); | 943 std::vector<FormData> forms(1, form); |
| 863 autofill_manager_->FormsSeen(forms); | 944 autofill_manager_->FormsSeen(forms); |
| 864 | 945 |
| 865 const FormField& field = form.fields[0]; | 946 const FormField& field = form.fields[0]; |
| 866 rvh()->ResetAutoFillState(kDefaultPageID); | 947 rvh()->ResetAutoFillState(kDefaultPageID); |
| 867 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 948 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 868 | 949 |
| 869 // No suggestions provided, so send an empty vector as the results. | 950 // No suggestions provided, so send an empty vector as the results. |
| 870 // This triggers the combined message send. | 951 // This triggers the combined message send. |
| 871 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 952 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 918 // Clear the test credit cards and try again -- we shouldn't return a warning. | 999 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 919 test_personal_data_->ClearCreditCards(); | 1000 test_personal_data_->ClearCreditCards(); |
| 920 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 1001 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 921 } | 1002 } |
| 922 | 1003 |
| 923 // Test that we return profile and credit card suggestions for combined forms. | 1004 // Test that we return profile and credit card suggestions for combined forms. |
| 924 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { | 1005 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 925 // Set up our form data. | 1006 // Set up our form data. |
| 926 FormData form; | 1007 FormData form; |
| 927 CreateTestAddressFormData(&form); | 1008 CreateTestAddressFormData(&form); |
| 928 CreateTestCreditCardFormData(&form, true); | 1009 CreateTestCreditCardFormData(&form, true, false); |
| 929 std::vector<FormData> forms(1, form); | 1010 std::vector<FormData> forms(1, form); |
| 930 autofill_manager_->FormsSeen(forms); | 1011 autofill_manager_->FormsSeen(forms); |
| 931 | 1012 |
| 932 FormField field = form.fields[0]; | 1013 FormField field = form.fields[0]; |
| 933 rvh()->ResetAutoFillState(kDefaultPageID); | 1014 rvh()->ResetAutoFillState(kDefaultPageID); |
| 934 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 1015 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 935 | 1016 |
| 936 // No suggestions provided, so send an empty vector as the results. | 1017 // No suggestions provided, so send an empty vector as the results. |
| 937 // This triggers the combined message send. | 1018 // This triggers the combined message send. |
| 938 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 1019 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 995 } | 1076 } |
| 996 | 1077 |
| 997 // Test that for non-https forms with both address and credit card fields, we | 1078 // Test that for non-https forms with both address and credit card fields, we |
| 998 // only return address suggestions. Instead of credit card suggestions, we | 1079 // only return address suggestions. Instead of credit card suggestions, we |
| 999 // should return a warning explaining that credit card profile suggestions are | 1080 // should return a warning explaining that credit card profile suggestions are |
| 1000 // unavailable when the form is not https. | 1081 // unavailable when the form is not https. |
| 1001 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1082 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 1002 // Set up our form data. | 1083 // Set up our form data. |
| 1003 FormData form; | 1084 FormData form; |
| 1004 CreateTestAddressFormData(&form); | 1085 CreateTestAddressFormData(&form); |
| 1005 CreateTestCreditCardFormData(&form, false); | 1086 CreateTestCreditCardFormData(&form, false, false); |
| 1006 std::vector<FormData> forms(1, form); | 1087 std::vector<FormData> forms(1, form); |
| 1007 autofill_manager_->FormsSeen(forms); | 1088 autofill_manager_->FormsSeen(forms); |
| 1008 | 1089 |
| 1009 FormField field = form.fields[0]; | 1090 FormField field = form.fields[0]; |
| 1010 rvh()->ResetAutoFillState(kDefaultPageID); | 1091 rvh()->ResetAutoFillState(kDefaultPageID); |
| 1011 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 1092 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 1012 | 1093 |
| 1013 // No suggestions provided, so send an empty vector as the results. | 1094 // No suggestions provided, so send an empty vector as the results. |
| 1014 // This triggers the combined message send. | 1095 // This triggers the combined message send. |
| 1015 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 1096 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1261 int page_id = 0; | 1342 int page_id = 0; |
| 1262 FormData results; | 1343 FormData results; |
| 1263 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1344 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
| 1264 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 1345 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); |
| 1265 } | 1346 } |
| 1266 | 1347 |
| 1267 // Test that we correctly fill a credit card form. | 1348 // Test that we correctly fill a credit card form. |
| 1268 TEST_F(AutoFillManagerTest, FillCreditCardForm) { | 1349 TEST_F(AutoFillManagerTest, FillCreditCardForm) { |
| 1269 // Set up our form data. | 1350 // Set up our form data. |
| 1270 FormData form; | 1351 FormData form; |
| 1271 CreateTestCreditCardFormData(&form, true); | 1352 CreateTestCreditCardFormData(&form, true, false); |
| 1272 std::vector<FormData> forms(1, form); | 1353 std::vector<FormData> forms(1, form); |
| 1273 autofill_manager_->FormsSeen(forms); | 1354 autofill_manager_->FormsSeen(forms); |
| 1274 | 1355 |
| 1275 std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); | 1356 std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); |
| 1276 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1357 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
| 1277 kDefaultPageID, form, *form.fields.begin(), | 1358 kDefaultPageID, form, *form.fields.begin(), |
| 1278 autofill_manager_->PackGUIDs(guid, std::string()))); | 1359 autofill_manager_->PackGUIDs(guid, std::string()))); |
| 1279 | 1360 |
| 1280 int page_id = 0; | 1361 int page_id = 0; |
| 1281 FormData results; | 1362 FormData results; |
| 1282 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1363 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
| 1283 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); | 1364 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); |
| 1284 } | 1365 } |
| 1285 | 1366 |
| 1367 // Test that we correctly fill a credit card form with month input type. | |
| 1368 // 1. year empty, month empty | |
| 1369 TEST_F(AutoFillManagerTest, FillCreditCardFormNoYearNoMonth) { | |
| 1370 // Same as the SetUp(), but generate 4 credit cards with year month | |
| 1371 // combination. | |
| 1372 RenderViewHostTestHarness::SetUp(); | |
| 1373 test_personal_data_ = new TestPersonalDataManager(true); | |
| 1374 autofill_manager_.reset(new TestAutoFillManager(contents(), | |
| 1375 test_personal_data_.get())); | |
| 1376 // Set up our form data. | |
| 1377 FormData form; | |
| 1378 CreateTestCreditCardFormData(&form, true, true); | |
| 1379 std::vector<FormData> forms(1, form); | |
| 1380 autofill_manager_->FormsSeen(forms); | |
| 1381 | |
| 1382 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku0")->guid(); | |
| 1383 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | |
| 1384 kDefaultPageID, form, *form.fields.begin(), | |
| 1385 autofill_manager_->PackGUIDs(guid, std::string()))); | |
| 1386 | |
| 1387 int page_id = 0; | |
| 1388 FormData results; | |
| 1389 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | |
| 1390 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 1391 kDefaultPageID, false, "", ""); | |
| 1392 } | |
| 1393 | |
| 1394 // Test that we correctly fill a credit card form with month input type. | |
| 1395 // 2. year empty, month non-empty | |
| 1396 TEST_F(AutoFillManagerTest, FillCreditCardFormNoYearMonth) { | |
| 1397 // Same as the SetUp(), but generate 4 credit cards with year month | |
| 1398 // combination. | |
| 1399 RenderViewHostTestHarness::SetUp(); | |
| 1400 test_personal_data_ = new TestPersonalDataManager(true); | |
| 1401 autofill_manager_.reset(new TestAutoFillManager(contents(), | |
| 1402 test_personal_data_.get())); | |
| 1403 // Set up our form data. | |
| 1404 FormData form; | |
| 1405 CreateTestCreditCardFormData(&form, true, true); | |
| 1406 std::vector<FormData> forms(1, form); | |
| 1407 autofill_manager_->FormsSeen(forms); | |
| 1408 | |
| 1409 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku1")->guid(); | |
| 1410 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | |
| 1411 kDefaultPageID, form, *form.fields.begin(), | |
| 1412 autofill_manager_->PackGUIDs(guid, std::string()))); | |
| 1413 | |
| 1414 int page_id = 0; | |
| 1415 FormData results; | |
| 1416 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | |
| 1417 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 1418 kDefaultPageID, false, "", "04"); | |
| 1419 } | |
| 1420 | |
| 1421 // Test that we correctly fill a credit card form with month input type. | |
| 1422 // 3. year non-empty, month empty | |
| 1423 TEST_F(AutoFillManagerTest, FillCreditCardFormYearNoMonth) { | |
| 1424 // Same as the SetUp(), but generate 4 credit cards with year month | |
| 1425 // combination. | |
| 1426 RenderViewHostTestHarness::SetUp(); | |
| 1427 test_personal_data_ = new TestPersonalDataManager(true); | |
| 1428 autofill_manager_.reset(new TestAutoFillManager(contents(), | |
| 1429 test_personal_data_.get())); | |
| 1430 // Set up our form data. | |
| 1431 FormData form; | |
| 1432 CreateTestCreditCardFormData(&form, true, true); | |
| 1433 std::vector<FormData> forms(1, form); | |
| 1434 autofill_manager_->FormsSeen(forms); | |
| 1435 | |
| 1436 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku2")->guid(); | |
| 1437 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | |
| 1438 kDefaultPageID, form, *form.fields.begin(), | |
| 1439 autofill_manager_->PackGUIDs(guid, std::string()))); | |
| 1440 | |
| 1441 int page_id = 0; | |
| 1442 FormData results; | |
| 1443 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | |
| 1444 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 1445 kDefaultPageID, false, "2012", ""); | |
| 1446 } | |
| 1447 | |
| 1448 // Test that we correctly fill a credit card form with month input type. | |
| 1449 // 4. year non-empty, month empty | |
| 1450 TEST_F(AutoFillManagerTest, FillCreditCardFormYearMonth) { | |
| 1451 // Same as the SetUp(), but generate 4 credit cards with year month | |
| 1452 // combination. | |
| 1453 RenderViewHostTestHarness::SetUp(); | |
| 1454 test_personal_data_ = new TestPersonalDataManager(true); | |
| 1455 autofill_manager_.reset(new TestAutoFillManager(contents(), | |
| 1456 test_personal_data_.get())); | |
| 1457 // Set up our form data. | |
| 1458 FormData form; | |
| 1459 CreateTestCreditCardFormData(&form, true, true); | |
| 1460 std::vector<FormData> forms(1, form); | |
| 1461 autofill_manager_->FormsSeen(forms); | |
| 1462 | |
| 1463 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku3")->guid(); | |
| 1464 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | |
| 1465 kDefaultPageID, form, *form.fields.begin(), | |
| 1466 autofill_manager_->PackGUIDs(guid, std::string()))); | |
| 1467 | |
| 1468 int page_id = 0; | |
| 1469 FormData results; | |
| 1470 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | |
| 1471 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 1472 kDefaultPageID, false, "2012", "04"); | |
| 1473 } | |
| 1474 | |
| 1286 // Test that we correctly fill a combined address and credit card form. | 1475 // Test that we correctly fill a combined address and credit card form. |
| 1287 TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) { | 1476 TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) { |
| 1288 // Set up our form data. | 1477 // Set up our form data. |
| 1289 FormData form; | 1478 FormData form; |
| 1290 CreateTestAddressFormData(&form); | 1479 CreateTestAddressFormData(&form); |
| 1291 CreateTestCreditCardFormData(&form, true); | 1480 CreateTestCreditCardFormData(&form, true, false); |
| 1292 std::vector<FormData> forms(1, form); | 1481 std::vector<FormData> forms(1, form); |
| 1293 autofill_manager_->FormsSeen(forms); | 1482 autofill_manager_->FormsSeen(forms); |
| 1294 | 1483 |
| 1295 // First fill the address data. | 1484 // First fill the address data. |
| 1296 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); | 1485 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); |
| 1297 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1486 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
| 1298 kDefaultPageID, form, form.fields[0], | 1487 kDefaultPageID, form, form.fields[0], |
| 1299 autofill_manager_->PackGUIDs(std::string(), guid))); | 1488 autofill_manager_->PackGUIDs(std::string(), guid))); |
| 1300 | 1489 |
| 1301 int page_id = 0; | 1490 int page_id = 0; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1322 } | 1511 } |
| 1323 } | 1512 } |
| 1324 | 1513 |
| 1325 // Test that we correctly fill a previously auto-filled form. | 1514 // Test that we correctly fill a previously auto-filled form. |
| 1326 TEST_F(AutoFillManagerTest, FillAutoFilledForm) { | 1515 TEST_F(AutoFillManagerTest, FillAutoFilledForm) { |
| 1327 // Set up our form data. | 1516 // Set up our form data. |
| 1328 FormData form; | 1517 FormData form; |
| 1329 CreateTestAddressFormData(&form); | 1518 CreateTestAddressFormData(&form); |
| 1330 // Mark one of the address fields as autofilled. | 1519 // Mark one of the address fields as autofilled. |
| 1331 form.fields[4].set_autofilled(true); | 1520 form.fields[4].set_autofilled(true); |
| 1332 CreateTestCreditCardFormData(&form, true); | 1521 CreateTestCreditCardFormData(&form, true, false); |
| 1333 std::vector<FormData> forms(1, form); | 1522 std::vector<FormData> forms(1, form); |
| 1334 autofill_manager_->FormsSeen(forms); | 1523 autofill_manager_->FormsSeen(forms); |
| 1335 | 1524 |
| 1336 // First fill the address data. | 1525 // First fill the address data. |
| 1337 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); | 1526 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); |
| 1338 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1527 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
| 1339 kDefaultPageID, form, *form.fields.begin(), | 1528 kDefaultPageID, form, *form.fields.begin(), |
| 1340 autofill_manager_->PackGUIDs(std::string(), guid))); | 1529 autofill_manager_->PackGUIDs(std::string(), guid))); |
| 1341 | 1530 |
| 1342 int page_id = 0; | 1531 int page_id = 0; |
| 1343 FormData results; | 1532 FormData results; |
| 1344 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1533 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
| 1345 { | 1534 { |
| 1346 SCOPED_TRACE("Address"); | 1535 SCOPED_TRACE("Address"); |
| 1347 ExpectFilledForm(page_id, results, kDefaultPageID, | 1536 ExpectFilledForm(page_id, results, kDefaultPageID, |
| 1348 "Elvis", "", "", "", "", "", "", "", "", "", "", "", | 1537 "Elvis", "", "", "", "", "", "", "", "", "", "", "", |
| 1349 "", "", "", "", true, true); | 1538 "", "", "", "", true, true, false); |
| 1350 } | 1539 } |
| 1351 | 1540 |
| 1352 // Now fill the credit card data. | 1541 // Now fill the credit card data. |
| 1353 process()->sink().ClearMessages(); | 1542 process()->sink().ClearMessages(); |
| 1354 const int kPageID2 = 2; | 1543 const int kPageID2 = 2; |
| 1355 guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); | 1544 guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); |
| 1356 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1545 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
| 1357 kPageID2, form, form.fields.back(), | 1546 kPageID2, form, form.fields.back(), |
| 1358 autofill_manager_->PackGUIDs(guid, std::string()))); | 1547 autofill_manager_->PackGUIDs(guid, std::string()))); |
| 1359 | 1548 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1377 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1566 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
| 1378 kPageID3, form, *form.fields.rbegin(), | 1567 kPageID3, form, *form.fields.rbegin(), |
| 1379 autofill_manager_->PackGUIDs(guid, std::string()))); | 1568 autofill_manager_->PackGUIDs(guid, std::string()))); |
| 1380 | 1569 |
| 1381 page_id = 0; | 1570 page_id = 0; |
| 1382 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1571 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
| 1383 { | 1572 { |
| 1384 SCOPED_TRACE("Credit card 2"); | 1573 SCOPED_TRACE("Credit card 2"); |
| 1385 ExpectFilledForm(page_id, results, kPageID3, | 1574 ExpectFilledForm(page_id, results, kPageID3, |
| 1386 "", "", "", "", "", "", "", "", "", "", "", "", | 1575 "", "", "", "", "", "", "", "", "", "", "", "", |
| 1387 "", "", "", "2012", true, true); | 1576 "", "", "", "2012", true, true, false); |
| 1388 } | 1577 } |
| 1389 } | 1578 } |
| 1390 | 1579 |
| 1391 // Test that we correctly fill a phone number split across multiple fields. | 1580 // Test that we correctly fill a phone number split across multiple fields. |
| 1392 TEST_F(AutoFillManagerTest, FillPhoneNumber) { | 1581 TEST_F(AutoFillManagerTest, FillPhoneNumber) { |
| 1393 // Set up our form data. | 1582 // Set up our form data. |
| 1394 FormData form; | 1583 FormData form; |
| 1395 form.name = ASCIIToUTF16("MyPhoneForm"); | 1584 form.name = ASCIIToUTF16("MyPhoneForm"); |
| 1396 form.method = ASCIIToUTF16("POST"); | 1585 form.method = ASCIIToUTF16("POST"); |
| 1397 form.origin = GURL("http://myform.com/phone_form.html"); | 1586 form.origin = GURL("http://myform.com/phone_form.html"); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1563 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1752 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1564 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1753 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
| 1565 profile()->GetPrefs()->SetBoolean( | 1754 profile()->GetPrefs()->SetBoolean( |
| 1566 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1755 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
| 1567 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1756 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
| 1568 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1757 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1569 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1758 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
| 1570 #endif | 1759 #endif |
| 1571 } | 1760 } |
| 1572 | 1761 |
| OLD | NEW |