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 "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/scoped_vector.h" | 8 #include "base/scoped_vector.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/tuple.h" | 10 #include "base/tuple.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 profile = new AutoFillProfile; | 52 profile = new AutoFillProfile; |
53 autofill_unittest::SetProfileInfo(profile, "Empty", "", "", "", "", "", "", | 53 autofill_unittest::SetProfileInfo(profile, "Empty", "", "", "", "", "", "", |
54 "", "", "", "", "", "", ""); | 54 "", "", "", "", "", "", ""); |
55 profiles->push_back(profile); | 55 profiles->push_back(profile); |
56 } | 56 } |
57 | 57 |
58 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { | 58 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { |
59 CreditCard* credit_card = new CreditCard; | 59 CreditCard* credit_card = new CreditCard; |
60 autofill_unittest::SetCreditCardInfo(credit_card, "First", "Elvis Presley", | 60 autofill_unittest::SetCreditCardInfo(credit_card, "First", "Elvis Presley", |
61 "Visa", "1234567890123456", "04", | 61 "Visa", "1234567890123456", "04", |
62 "2012", "456", "", ""); | 62 "2012", "456", "Home", ""); |
63 credit_cards->push_back(credit_card); | 63 credit_cards->push_back(credit_card); |
64 credit_card = new CreditCard; | 64 credit_card = new CreditCard; |
65 autofill_unittest::SetCreditCardInfo(credit_card, "Second", "Buddy Holly", | 65 autofill_unittest::SetCreditCardInfo(credit_card, "Second", "Buddy Holly", |
66 "Mastercard", "0987654321098765", "10", | 66 "Mastercard", "0987654321098765", "10", |
67 "2014", "678", "", ""); | 67 "2014", "678", "", ""); |
68 credit_cards->push_back(credit_card); | 68 credit_cards->push_back(credit_card); |
69 credit_card = new CreditCard; | 69 credit_card = new CreditCard; |
70 autofill_unittest::SetCreditCardInfo(credit_card, "Empty", "", "", "", "", | 70 autofill_unittest::SetCreditCardInfo(credit_card, "Empty", "", "", "", "", |
71 "", "", "", ""); | 71 "", "", "", ""); |
72 credit_cards->push_back(credit_card); | 72 credit_cards->push_back(credit_card); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); | 130 CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
131 form->fields.push_back(field); | 131 form->fields.push_back(field); |
132 CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 132 CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
133 form->fields.push_back(field); | 133 form->fields.push_back(field); |
134 CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); | 134 CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); |
135 form->fields.push_back(field); | 135 form->fields.push_back(field); |
136 CreateTestFormField("", "ccyear", "", "text", &field); | 136 CreateTestFormField("", "ccyear", "", "text", &field); |
137 form->fields.push_back(field); | 137 form->fields.push_back(field); |
138 } | 138 } |
139 | 139 |
140 void CreateTestFormDataWithValues(FormData* form) { | 140 void CreateTestFormDataBilling(FormData* form) { |
141 CreateTestFormData(form); | 141 form->name = ASCIIToUTF16("MyForm"); |
142 form->fields[0].set_value(ASCIIToUTF16("Elvis")); | 142 form->method = ASCIIToUTF16("POST"); |
143 form->fields[1].set_value(ASCIIToUTF16("Aaron")); | 143 form->origin = GURL("http://myform.com/form.html"); |
144 form->fields[2].set_value(ASCIIToUTF16("Presely")); | 144 form->action = GURL("http://myform.com/submit.html"); |
145 form->fields[3].set_value(ASCIIToUTF16("3734 Elvis Presley Blvd.")); | 145 |
146 form->fields[4].set_value(ASCIIToUTF16("Apt. 10")); | 146 webkit_glue::FormField field; |
147 form->fields[5].set_value(ASCIIToUTF16("Memphis")); | 147 CreateTestFormField("First Name", "firstname", "", "text", &field); |
148 form->fields[6].set_value(ASCIIToUTF16("Tennessee")); | 148 form->fields.push_back(field); |
149 form->fields[7].set_value(ASCIIToUTF16("38116")); | 149 CreateTestFormField("Middle Name", "middlename", "", "text", &field); |
150 form->fields[8].set_value(ASCIIToUTF16("USA")); | 150 form->fields.push_back(field); |
151 form->fields[9].set_value(ASCIIToUTF16("12345678901")); | 151 CreateTestFormField("Last Name", "lastname", "", "text", &field); |
152 form->fields[10].set_value(ASCIIToUTF16("theking@gmail.com")); | 152 form->fields.push_back(field); |
153 form->fields[11].set_value(ASCIIToUTF16("Elvis Presley")); | 153 CreateTestFormField("Address Line 1", "billingAddr1", "", "text", &field); |
154 form->fields[12].set_value(ASCIIToUTF16("1234567890123456")); | 154 form->fields.push_back(field); |
155 form->fields[13].set_value(ASCIIToUTF16("04")); | 155 CreateTestFormField("Address Line 2", "billingAddr2", "", "text", &field); |
156 form->fields[14].set_value(ASCIIToUTF16("2012")); | 156 form->fields.push_back(field); |
| 157 CreateTestFormField("City", "billingCity", "", "text", &field); |
| 158 form->fields.push_back(field); |
| 159 CreateTestFormField("State", "billingState", "", "text", &field); |
| 160 form->fields.push_back(field); |
| 161 CreateTestFormField("Postal Code", "billingZipcode", "", "text", &field); |
| 162 form->fields.push_back(field); |
| 163 CreateTestFormField("Country", "billingCountry", "", "text", &field); |
| 164 form->fields.push_back(field); |
| 165 CreateTestFormField("Phone Number", "phonenumber", "", "text", &field); |
| 166 form->fields.push_back(field); |
| 167 CreateTestFormField("Email", "email", "", "text", &field); |
| 168 form->fields.push_back(field); |
| 169 CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 170 form->fields.push_back(field); |
| 171 CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 172 form->fields.push_back(field); |
| 173 CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); |
| 174 form->fields.push_back(field); |
| 175 CreateTestFormField("", "ccyear", "", "text", &field); |
| 176 form->fields.push_back(field); |
157 } | 177 } |
158 | 178 |
159 class AutoFillManagerTest : public RenderViewHostTestHarness { | 179 class AutoFillManagerTest : public RenderViewHostTestHarness { |
160 public: | 180 public: |
161 AutoFillManagerTest() {} | 181 AutoFillManagerTest() {} |
162 | 182 |
163 virtual void SetUp() { | 183 virtual void SetUp() { |
164 RenderViewHostTestHarness::SetUp(); | 184 RenderViewHostTestHarness::SetUp(); |
165 autofill_manager_.reset(new TestAutoFillManager(contents())); | 185 autofill_manager_.reset(new TestAutoFillManager(contents())); |
166 } | 186 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 CreateTestFormData(&form); | 394 CreateTestFormData(&form); |
375 | 395 |
376 // Set up our FormStructures. | 396 // Set up our FormStructures. |
377 std::vector<FormData> forms; | 397 std::vector<FormData> forms; |
378 forms.push_back(form); | 398 forms.push_back(form); |
379 autofill_manager_->FormsSeen(forms); | 399 autofill_manager_->FormsSeen(forms); |
380 | 400 |
381 // The page ID sent to the AutoFillManager from the RenderView, used to send | 401 // The page ID sent to the AutoFillManager from the RenderView, used to send |
382 // an IPC message back to the renderer. | 402 // an IPC message back to the renderer. |
383 const int kPageID = 1; | 403 const int kPageID = 1; |
384 | |
385 webkit_glue::FormField field; | |
386 CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | |
387 | |
388 FormData values; | |
389 CreateTestFormDataWithValues(&values); | |
390 EXPECT_TRUE( | 404 EXPECT_TRUE( |
391 autofill_manager_->FillAutoFillFormData(kPageID, | 405 autofill_manager_->FillAutoFillFormData(kPageID, |
392 values, | 406 form, |
393 ASCIIToUTF16("cardnumber"), | 407 ASCIIToUTF16("cardnumber"), |
394 ASCIIToUTF16("First"))); | 408 ASCIIToUTF16("First"))); |
395 | 409 |
396 int page_id = 0; | 410 int page_id = 0; |
397 FormData results; | 411 FormData results; |
398 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 412 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
399 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); | 413 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
400 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); | 414 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
401 EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin); | 415 EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin); |
402 EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action); | 416 EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action); |
403 ASSERT_EQ(15U, results.fields.size()); | 417 ASSERT_EQ(15U, results.fields.size()); |
| 418 |
| 419 webkit_glue::FormField field; |
404 CreateTestFormField("First Name", "firstname", "", "text", &field); | 420 CreateTestFormField("First Name", "firstname", "", "text", &field); |
405 EXPECT_EQ(field, results.fields[0]); | 421 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); |
406 CreateTestFormField("Middle Name", "middlename", "", "text", &field); | 422 CreateTestFormField("Middle Name", "middlename", "", "text", &field); |
407 EXPECT_EQ(field, results.fields[1]); | 423 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); |
408 CreateTestFormField("Last Name", "lastname", "", "text", &field); | 424 CreateTestFormField("Last Name", "lastname", "", "text", &field); |
409 EXPECT_EQ(field, results.fields[2]); | 425 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); |
410 CreateTestFormField("Address Line 1", "addr1", "", "text", &field); | 426 CreateTestFormField("Address Line 1", "addr1", "", "text", &field); |
411 EXPECT_EQ(field, results.fields[3]); | 427 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); |
412 CreateTestFormField("Address Line 2", "addr2", "", "text", &field); | 428 CreateTestFormField("Address Line 2", "addr2", "", "text", &field); |
413 EXPECT_EQ(field, results.fields[4]); | 429 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4])); |
414 CreateTestFormField("City", "city", "", "text", &field); | 430 CreateTestFormField("City", "city", "", "text", &field); |
415 EXPECT_EQ(field, results.fields[5]); | 431 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5])); |
416 CreateTestFormField("State", "state", "", "text", &field); | 432 CreateTestFormField("State", "state", "", "text", &field); |
417 EXPECT_EQ(field, results.fields[6]); | 433 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6])); |
418 CreateTestFormField("Postal Code", "zipcode", "", "text", &field); | 434 CreateTestFormField("Postal Code", "zipcode", "", "text", &field); |
419 EXPECT_EQ(field, results.fields[7]); | 435 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7])); |
420 CreateTestFormField("Country", "country", "", "text", &field); | 436 CreateTestFormField("Country", "country", "", "text", &field); |
421 EXPECT_EQ(field, results.fields[8]); | 437 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8])); |
422 CreateTestFormField("Phone Number", "phonenumber", "", "text", &field); | 438 CreateTestFormField("Phone Number", "phonenumber", "", "text", &field); |
423 EXPECT_EQ(field, results.fields[9]); | 439 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9])); |
424 CreateTestFormField("Email", "email", "", "text", &field); | 440 CreateTestFormField("Email", "email", "", "text", &field); |
425 EXPECT_EQ(field, results.fields[10]); | 441 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10])); |
426 CreateTestFormField( | 442 CreateTestFormField( |
427 "Name on Card", "nameoncard", "Elvis Presley", "text", &field); | 443 "Name on Card", "nameoncard", "Elvis Presley", "text", &field); |
428 EXPECT_EQ(field, results.fields[11]); | 444 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11])); |
429 CreateTestFormField( | 445 CreateTestFormField( |
430 "Card Number", "cardnumber", "1234567890123456", "text", &field); | 446 "Card Number", "cardnumber", "1234567890123456", "text", &field); |
431 EXPECT_EQ(field, results.fields[12]); | 447 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12])); |
432 CreateTestFormField("Expiration Date", "ccmonth", "04", "text", &field); | 448 CreateTestFormField("Expiration Date", "ccmonth", "04", "text", &field); |
433 EXPECT_EQ(field, results.fields[13]); | 449 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13])); |
434 CreateTestFormField("", "ccyear", "2012", "text", &field); | 450 CreateTestFormField("", "ccyear", "2012", "text", &field); |
435 EXPECT_EQ(field, results.fields[14]); | 451 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14])); |
| 452 } |
| 453 |
| 454 TEST_F(AutoFillManagerTest, FillCreditCardFormWithBilling) { |
| 455 FormData form; |
| 456 CreateTestFormDataBilling(&form); |
| 457 |
| 458 // Set up our FormStructures. |
| 459 std::vector<FormData> forms; |
| 460 forms.push_back(form); |
| 461 autofill_manager_->FormsSeen(forms); |
| 462 |
| 463 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 464 // an IPC message back to the renderer. |
| 465 const int kPageID = 1; |
| 466 EXPECT_TRUE( |
| 467 autofill_manager_->FillAutoFillFormData(kPageID, |
| 468 form, |
| 469 ASCIIToUTF16("cardnumber"), |
| 470 ASCIIToUTF16("First"))); |
| 471 |
| 472 int page_id = 0; |
| 473 FormData results; |
| 474 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
| 475 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
| 476 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
| 477 EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin); |
| 478 EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action); |
| 479 ASSERT_EQ(15U, results.fields.size()); |
| 480 |
| 481 webkit_glue::FormField field; |
| 482 CreateTestFormField("First Name", "firstname", "", "text", &field); |
| 483 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); |
| 484 CreateTestFormField("Middle Name", "middlename", "", "text", &field); |
| 485 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); |
| 486 CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 487 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); |
| 488 CreateTestFormField( |
| 489 "Address Line 1", "billingAddr1", "3734 Elvis Presley Blvd.", "text", |
| 490 &field); |
| 491 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); |
| 492 CreateTestFormField( |
| 493 "Address Line 2", "billingAddr2", "Apt. 10", "text", &field); |
| 494 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4])); |
| 495 CreateTestFormField("City", "billingCity", "Memphis", "text", &field); |
| 496 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5])); |
| 497 CreateTestFormField("State", "billingState", "Tennessee", "text", &field); |
| 498 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6])); |
| 499 CreateTestFormField("Postal Code", "billingZipcode", "38116", "text", &field); |
| 500 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7])); |
| 501 CreateTestFormField("Country", "billingCountry", "USA", "text", &field); |
| 502 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8])); |
| 503 CreateTestFormField( |
| 504 "Phone Number", "phonenumber", "", "text", &field); |
| 505 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9])); |
| 506 CreateTestFormField( |
| 507 "Email", "email", "", "text", &field); |
| 508 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10])); |
| 509 CreateTestFormField( |
| 510 "Name on Card", "nameoncard", "Elvis Presley", "text", &field); |
| 511 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11])); |
| 512 CreateTestFormField( |
| 513 "Card Number", "cardnumber", "1234567890123456", "text", &field); |
| 514 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12])); |
| 515 CreateTestFormField("Expiration Date", "ccmonth", "04", "text", &field); |
| 516 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13])); |
| 517 CreateTestFormField("", "ccyear", "2012", "text", &field); |
| 518 EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14])); |
436 } | 519 } |
437 | 520 |
438 } // namespace | 521 } // namespace |
OLD | NEW |