OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 virtual ~TestAutofillDialogController() {} | 116 virtual ~TestAutofillDialogController() {} |
117 | 117 |
118 virtual void ViewClosed() OVERRIDE { | 118 virtual void ViewClosed() OVERRIDE { |
119 message_loop_runner_->Quit(); | 119 message_loop_runner_->Quit(); |
120 AutofillDialogControllerImpl::ViewClosed(); | 120 AutofillDialogControllerImpl::ViewClosed(); |
121 } | 121 } |
122 | 122 |
123 virtual string16 InputValidityMessage( | 123 virtual string16 InputValidityMessage( |
124 DialogSection section, | 124 DialogSection section, |
125 AutofillFieldType type, | 125 ServerFieldType type, |
126 const string16& value) OVERRIDE { | 126 const string16& value) OVERRIDE { |
127 if (!use_validation_) | 127 if (!use_validation_) |
128 return string16(); | 128 return string16(); |
129 return AutofillDialogControllerImpl::InputValidityMessage( | 129 return AutofillDialogControllerImpl::InputValidityMessage( |
130 section, type, value); | 130 section, type, value); |
131 } | 131 } |
132 | 132 |
133 virtual ValidityData InputsAreValid( | 133 virtual ValidityData InputsAreValid( |
134 DialogSection section, | 134 DialogSection section, |
135 const DetailOutputMap& inputs, | 135 const DetailOutputMap& inputs, |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 view->SetTextContentsOfInput(triggering_input, | 490 view->SetTextContentsOfInput(triggering_input, |
491 value.substr(0, value.size() / 2)); | 491 value.substr(0, value.size() / 2)); |
492 view->ActivateInput(triggering_input); | 492 view->ActivateInput(triggering_input); |
493 | 493 |
494 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 494 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
495 controller()->DidAcceptSuggestion(string16(), 0); | 495 controller()->DidAcceptSuggestion(string16(), 0); |
496 | 496 |
497 // All inputs should be filled. | 497 // All inputs should be filled. |
498 AutofillProfileWrapper wrapper(&full_profile, 0); | 498 AutofillProfileWrapper wrapper(&full_profile, 0); |
499 for (size_t i = 0; i < inputs.size(); ++i) { | 499 for (size_t i = 0; i < inputs.size(); ++i) { |
500 EXPECT_EQ(wrapper.GetInfo(inputs[i].type), | 500 EXPECT_EQ(wrapper.GetInfo(AutofillType(inputs[i].type)), |
501 view->GetTextContentsOfInput(inputs[i])); | 501 view->GetTextContentsOfInput(inputs[i])); |
502 } | 502 } |
503 | 503 |
504 // Now simulate some user edits and try again. | 504 // Now simulate some user edits and try again. |
505 std::vector<string16> expectations; | 505 std::vector<string16> expectations; |
506 for (size_t i = 0; i < inputs.size(); ++i) { | 506 for (size_t i = 0; i < inputs.size(); ++i) { |
507 string16 users_input = i % 2 == 0 ? string16() : ASCIIToUTF16("dummy"); | 507 string16 users_input = i % 2 == 0 ? string16() : ASCIIToUTF16("dummy"); |
508 view->SetTextContentsOfInput(inputs[i], users_input); | 508 view->SetTextContentsOfInput(inputs[i], users_input); |
509 // Empty inputs should be filled, others should be left alone. | 509 // Empty inputs should be filled, others should be left alone. |
510 string16 expectation = | 510 string16 expectation = |
511 &inputs[i] == &triggering_input || users_input.empty() ? | 511 &inputs[i] == &triggering_input || users_input.empty() ? |
512 wrapper.GetInfo(inputs[i].type) : | 512 wrapper.GetInfo(AutofillType(inputs[i].type)) : |
513 users_input; | 513 users_input; |
514 expectations.push_back(expectation); | 514 expectations.push_back(expectation); |
515 } | 515 } |
516 | 516 |
517 view->SetTextContentsOfInput(triggering_input, | 517 view->SetTextContentsOfInput(triggering_input, |
518 value.substr(0, value.size() / 2)); | 518 value.substr(0, value.size() / 2)); |
519 view->ActivateInput(triggering_input); | 519 view->ActivateInput(triggering_input); |
520 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 520 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
521 controller()->DidAcceptSuggestion(string16(), 0); | 521 controller()->DidAcceptSuggestion(string16(), 0); |
522 | 522 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 view->SetTextContentsOfInput(triggering_input, | 583 view->SetTextContentsOfInput(triggering_input, |
584 value.substr(0, value.size() / 2)); | 584 value.substr(0, value.size() / 2)); |
585 view->ActivateInput(triggering_input); | 585 view->ActivateInput(triggering_input); |
586 | 586 |
587 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 587 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
588 controller()->DidAcceptSuggestion(string16(), 0); | 588 controller()->DidAcceptSuggestion(string16(), 0); |
589 | 589 |
590 // All inputs should be filled. | 590 // All inputs should be filled. |
591 AutofillCreditCardWrapper wrapper1(&card1); | 591 AutofillCreditCardWrapper wrapper1(&card1); |
592 for (size_t i = 0; i < inputs.size(); ++i) { | 592 for (size_t i = 0; i < inputs.size(); ++i) { |
593 EXPECT_EQ(wrapper1.GetInfo(inputs[i].type), | 593 EXPECT_EQ(wrapper1.GetInfo(AutofillType(inputs[i].type)), |
594 view->GetTextContentsOfInput(inputs[i])); | 594 view->GetTextContentsOfInput(inputs[i])); |
595 } | 595 } |
596 | 596 |
597 // Try again with different data. Only expiration date and the triggering | 597 // Try again with different data. Only expiration date and the triggering |
598 // input should be overwritten. | 598 // input should be overwritten. |
599 value = card2.GetRawInfo(triggering_input.type); | 599 value = card2.GetRawInfo(triggering_input.type); |
600 view->SetTextContentsOfInput(triggering_input, | 600 view->SetTextContentsOfInput(triggering_input, |
601 value.substr(0, value.size() / 2)); | 601 value.substr(0, value.size() / 2)); |
602 view->ActivateInput(triggering_input); | 602 view->ActivateInput(triggering_input); |
603 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 603 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
604 controller()->DidAcceptSuggestion(string16(), 0); | 604 controller()->DidAcceptSuggestion(string16(), 0); |
605 | 605 |
606 AutofillCreditCardWrapper wrapper2(&card2); | 606 AutofillCreditCardWrapper wrapper2(&card2); |
607 for (size_t i = 0; i < inputs.size(); ++i) { | 607 for (size_t i = 0; i < inputs.size(); ++i) { |
608 const DetailInput& input = inputs[i]; | 608 const DetailInput& input = inputs[i]; |
609 if (&input == &triggering_input || | 609 if (&input == &triggering_input || |
610 input.type == CREDIT_CARD_EXP_MONTH || | 610 input.type == CREDIT_CARD_EXP_MONTH || |
611 input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { | 611 input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { |
612 EXPECT_EQ(wrapper2.GetInfo(input.type), | 612 EXPECT_EQ(wrapper2.GetInfo(AutofillType(input.type)), |
613 view->GetTextContentsOfInput(input)); | 613 view->GetTextContentsOfInput(input)); |
614 } else if (input.type == CREDIT_CARD_VERIFICATION_CODE) { | 614 } else if (input.type == CREDIT_CARD_VERIFICATION_CODE) { |
615 EXPECT_TRUE(view->GetTextContentsOfInput(input).empty()); | 615 EXPECT_TRUE(view->GetTextContentsOfInput(input).empty()); |
616 } else { | 616 } else { |
617 EXPECT_EQ(wrapper1.GetInfo(input.type), | 617 EXPECT_EQ(wrapper1.GetInfo(AutofillType(input.type)), |
618 view->GetTextContentsOfInput(input)); | 618 view->GetTextContentsOfInput(input)); |
619 } | 619 } |
620 } | 620 } |
621 | 621 |
622 // Now fill from a profile. It should not overwrite any CC info. | 622 // Now fill from a profile. It should not overwrite any CC info. |
623 const DetailInputs& billing_inputs = | 623 const DetailInputs& billing_inputs = |
624 controller()->RequestedFieldsForSection(SECTION_BILLING); | 624 controller()->RequestedFieldsForSection(SECTION_BILLING); |
625 const DetailInput& billing_triggering_input = billing_inputs[0]; | 625 const DetailInput& billing_triggering_input = billing_inputs[0]; |
626 value = full_profile.GetRawInfo(triggering_input.type); | 626 value = full_profile.GetRawInfo(triggering_input.type); |
627 view->SetTextContentsOfInput(billing_triggering_input, | 627 view->SetTextContentsOfInput(billing_triggering_input, |
628 value.substr(0, value.size() / 2)); | 628 value.substr(0, value.size() / 2)); |
629 view->ActivateInput(billing_triggering_input); | 629 view->ActivateInput(billing_triggering_input); |
630 | 630 |
631 ASSERT_EQ(&billing_triggering_input, controller()->input_showing_popup()); | 631 ASSERT_EQ(&billing_triggering_input, controller()->input_showing_popup()); |
632 controller()->DidAcceptSuggestion(string16(), 0); | 632 controller()->DidAcceptSuggestion(string16(), 0); |
633 | 633 |
634 for (size_t i = 0; i < inputs.size(); ++i) { | 634 for (size_t i = 0; i < inputs.size(); ++i) { |
635 const DetailInput& input = inputs[i]; | 635 const DetailInput& input = inputs[i]; |
636 if (&input == &triggering_input || | 636 if (&input == &triggering_input || |
637 input.type == CREDIT_CARD_EXP_MONTH || | 637 input.type == CREDIT_CARD_EXP_MONTH || |
638 input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { | 638 input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { |
639 EXPECT_EQ(wrapper2.GetInfo(input.type), | 639 EXPECT_EQ(wrapper2.GetInfo(AutofillType(input.type)), |
640 view->GetTextContentsOfInput(input)); | 640 view->GetTextContentsOfInput(input)); |
641 } else if (input.type == CREDIT_CARD_VERIFICATION_CODE) { | 641 } else if (input.type == CREDIT_CARD_VERIFICATION_CODE) { |
642 EXPECT_TRUE(view->GetTextContentsOfInput(input).empty()); | 642 EXPECT_TRUE(view->GetTextContentsOfInput(input).empty()); |
643 } else { | 643 } else { |
644 EXPECT_EQ(wrapper1.GetInfo(input.type), | 644 EXPECT_EQ(wrapper1.GetInfo(AutofillType(input.type)), |
645 view->GetTextContentsOfInput(input)); | 645 view->GetTextContentsOfInput(input)); |
646 } | 646 } |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 // Tests that credit card number is disabled while editing a Wallet instrument. | 650 // Tests that credit card number is disabled while editing a Wallet instrument. |
651 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, WalletCreditCardDisabled) { | 651 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, WalletCreditCardDisabled) { |
652 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 652 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
653 controller()->OnUserNameFetchSuccess("user@example.com"); | 653 controller()->OnUserNameFetchSuccess("user@example.com"); |
654 | 654 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 EXPECT_EQ(cc_number.type, new_cc_number.type); | 868 EXPECT_EQ(cc_number.type, new_cc_number.type); |
869 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), | 869 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), |
870 view->GetTextContentsOfInput(new_cc_number)); | 870 view->GetTextContentsOfInput(new_cc_number)); |
871 | 871 |
872 EXPECT_NE(ASCIIToUTF16("shipping name"), | 872 EXPECT_NE(ASCIIToUTF16("shipping name"), |
873 view->GetTextContentsOfInput(shipping_zip)); | 873 view->GetTextContentsOfInput(shipping_zip)); |
874 } | 874 } |
875 #endif // defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) | 875 #endif // defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) |
876 | 876 |
877 } // namespace autofill | 877 } // namespace autofill |
OLD | NEW |