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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const char kTestCCNumberMaster[] = "5555555555554444"; | 87 const char kTestCCNumberMaster[] = "5555555555554444"; |
88 const char kTestCCNumberDiscover[] = "6011111111111117"; | 88 const char kTestCCNumberDiscover[] = "6011111111111117"; |
89 const char kTestCCNumberIncomplete[] = "4111111111"; | 89 const char kTestCCNumberIncomplete[] = "4111111111"; |
90 // Credit card number fails Luhn check. | 90 // Credit card number fails Luhn check. |
91 const char kTestCCNumberInvalid[] = "4111111111111112"; | 91 const char kTestCCNumberInvalid[] = "4111111111111112"; |
92 | 92 |
93 // Sets the value of |type| in |outputs| to |value|. | 93 // Sets the value of |type| in |outputs| to |value|. |
94 void SetOutputValue(const DetailInputs& inputs, | 94 void SetOutputValue(const DetailInputs& inputs, |
95 ServerFieldType type, | 95 ServerFieldType type, |
96 const base::string16& value, | 96 const base::string16& value, |
97 DetailOutputMap* outputs) { | 97 FieldValueMap* outputs) { |
98 for (size_t i = 0; i < inputs.size(); ++i) { | 98 for (size_t i = 0; i < inputs.size(); ++i) { |
99 const DetailInput& input = inputs[i]; | 99 if (inputs[i].type == type) |
100 if (input.type == type) | 100 (*outputs)[type] = value; |
101 (*outputs)[&input] = value; | |
102 } | 101 } |
103 } | 102 } |
104 | 103 |
105 // Copies the initial values from |inputs| into |outputs|. | 104 // Copies the initial values from |inputs| into |outputs|. |
106 void CopyInitialValues(const DetailInputs& inputs, DetailOutputMap* outputs) { | 105 void CopyInitialValues(const DetailInputs& inputs, FieldValueMap* outputs) { |
107 for (size_t i = 0; i < inputs.size(); ++i) { | 106 for (size_t i = 0; i < inputs.size(); ++i) { |
108 const DetailInput& input = inputs[i]; | 107 const DetailInput& input = inputs[i]; |
109 (*outputs)[&input] = input.initial_value; | 108 (*outputs)[input.type] = input.initial_value; |
110 } | 109 } |
111 } | 110 } |
112 | 111 |
113 scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { | 112 scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { |
114 scoped_ptr<wallet::WalletItems> items = | 113 scoped_ptr<wallet::WalletItems> items = |
115 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 114 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
116 items->AddInstrument(wallet::GetTestMaskedInstrument()); | 115 items->AddInstrument(wallet::GetTestMaskedInstrument()); |
117 items->AddAddress(wallet::GetTestShippingAddress()); | 116 items->AddAddress(wallet::GetTestShippingAddress()); |
118 return items.Pass(); | 117 return items.Pass(); |
119 } | 118 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 virtual void UpdateSection(DialogSection section) OVERRIDE { | 175 virtual void UpdateSection(DialogSection section) OVERRIDE { |
177 EXPECT_GE(updates_started_, 1); | 176 EXPECT_GE(updates_started_, 1); |
178 } | 177 } |
179 | 178 |
180 virtual void UpdateErrorBubble() OVERRIDE { | 179 virtual void UpdateErrorBubble() OVERRIDE { |
181 EXPECT_GE(updates_started_, 1); | 180 EXPECT_GE(updates_started_, 1); |
182 } | 181 } |
183 | 182 |
184 virtual void FillSection(DialogSection section, | 183 virtual void FillSection(DialogSection section, |
185 const DetailInput& originating_input) OVERRIDE {}; | 184 const DetailInput& originating_input) OVERRIDE {}; |
186 virtual void GetUserInput(DialogSection section, DetailOutputMap* output) | 185 virtual void GetUserInput(DialogSection section, FieldValueMap* output) |
187 OVERRIDE { | 186 OVERRIDE { |
188 *output = outputs_[section]; | 187 *output = outputs_[section]; |
189 } | 188 } |
190 virtual TestableAutofillDialogView* GetTestableView() OVERRIDE { | 189 virtual TestableAutofillDialogView* GetTestableView() OVERRIDE { |
191 return NULL; | 190 return NULL; |
192 } | 191 } |
193 | 192 |
194 virtual string16 GetCvc() OVERRIDE { return string16(); } | 193 virtual string16 GetCvc() OVERRIDE { return string16(); } |
195 virtual bool HitTestInput(const DetailInput& input, | 194 virtual bool HitTestInput(const DetailInput& input, |
196 const gfx::Point& screen_point) OVERRIDE { | 195 const gfx::Point& screen_point) OVERRIDE { |
197 return false; | 196 return false; |
198 } | 197 } |
199 | 198 |
200 virtual bool SaveDetailsLocally() OVERRIDE { | 199 virtual bool SaveDetailsLocally() OVERRIDE { |
201 return save_details_locally_checked_; | 200 return save_details_locally_checked_; |
202 } | 201 } |
203 | 202 |
204 virtual const content::NavigationController* ShowSignIn() OVERRIDE { | 203 virtual const content::NavigationController* ShowSignIn() OVERRIDE { |
205 return NULL; | 204 return NULL; |
206 } | 205 } |
207 virtual void HideSignIn() OVERRIDE {} | 206 virtual void HideSignIn() OVERRIDE {} |
208 | 207 |
209 MOCK_METHOD0(ModelChanged, void()); | 208 MOCK_METHOD0(ModelChanged, void()); |
210 MOCK_METHOD0(UpdateForErrors, void()); | 209 MOCK_METHOD0(UpdateForErrors, void()); |
211 | 210 |
212 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} | 211 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} |
213 | 212 |
214 void SetUserInput(DialogSection section, const DetailOutputMap& map) { | 213 void SetUserInput(DialogSection section, const FieldValueMap& map) { |
215 outputs_[section] = map; | 214 outputs_[section] = map; |
216 } | 215 } |
217 | 216 |
218 void CheckSaveDetailsLocallyCheckbox(bool checked) { | 217 void CheckSaveDetailsLocallyCheckbox(bool checked) { |
219 save_details_locally_checked_ = checked; | 218 save_details_locally_checked_ = checked; |
220 } | 219 } |
221 | 220 |
222 private: | 221 private: |
223 std::map<DialogSection, DetailOutputMap> outputs_; | 222 std::map<DialogSection, FieldValueMap> outputs_; |
224 | 223 |
225 int updates_started_; | 224 int updates_started_; |
226 bool save_details_locally_checked_; | 225 bool save_details_locally_checked_; |
227 | 226 |
228 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); | 227 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); |
229 }; | 228 }; |
230 | 229 |
231 class TestAutofillDialogController | 230 class TestAutofillDialogController |
232 : public AutofillDialogControllerImpl, | 231 : public AutofillDialogControllerImpl, |
233 public base::SupportsWeakPtr<TestAutofillDialogController> { | 232 public base::SupportsWeakPtr<TestAutofillDialogController> { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (!profile()->GetPrefs()->GetBoolean( | 433 if (!profile()->GetPrefs()->GetBoolean( |
435 ::prefs::kAutofillDialogPayWithoutWallet)) { | 434 ::prefs::kAutofillDialogPayWithoutWallet)) { |
436 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); | 435 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); |
437 controller_->OnDidFetchWalletCookieValue(std::string()); | 436 controller_->OnDidFetchWalletCookieValue(std::string()); |
438 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 437 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
439 } | 438 } |
440 } | 439 } |
441 | 440 |
442 // Fills the inputs in SECTION_CC with data. | 441 // Fills the inputs in SECTION_CC with data. |
443 void FillCreditCardInputs() { | 442 void FillCreditCardInputs() { |
444 DetailOutputMap cc_outputs; | 443 FieldValueMap cc_outputs; |
445 const DetailInputs& cc_inputs = | 444 const DetailInputs& cc_inputs = |
446 controller()->RequestedFieldsForSection(SECTION_CC); | 445 controller()->RequestedFieldsForSection(SECTION_CC); |
447 for (size_t i = 0; i < cc_inputs.size(); ++i) { | 446 for (size_t i = 0; i < cc_inputs.size(); ++i) { |
448 cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NUMBER ? | 447 cc_outputs[cc_inputs[i].type] = cc_inputs[i].type == CREDIT_CARD_NUMBER ? |
449 ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11"); | 448 ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11"); |
450 } | 449 } |
451 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); | 450 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); |
452 } | 451 } |
453 | 452 |
454 // Fills the inputs in SECTION_CC_BILLING with valid data. | 453 // Fills the inputs in SECTION_CC_BILLING with valid data. |
455 void FillCCBillingInputs() { | 454 void FillCCBillingInputs() { |
456 DetailOutputMap outputs; | 455 FieldValueMap outputs; |
457 const DetailInputs& inputs = | 456 const DetailInputs& inputs = |
458 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | 457 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); |
459 AutofillProfile full_profile(test::GetVerifiedProfile()); | 458 AutofillProfile full_profile(test::GetVerifiedProfile()); |
460 CreditCard full_card(test::GetCreditCard()); | 459 CreditCard full_card(test::GetCreditCard()); |
461 for (size_t i = 0; i < inputs.size(); ++i) { | 460 for (size_t i = 0; i < inputs.size(); ++i) { |
462 const DetailInput& input = inputs[i]; | 461 const ServerFieldType type = inputs[i].type; |
463 outputs[&input] = full_profile.GetInfo(AutofillType(input.type), | 462 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); |
464 "en-US"); | |
465 | 463 |
466 if (outputs[&input].empty()) | 464 if (outputs[type].empty()) |
467 outputs[&input] = full_card.GetInfo(AutofillType(input.type), "en-US"); | 465 outputs[type] = full_card.GetInfo(AutofillType(type), "en-US"); |
468 } | 466 } |
469 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 467 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
470 } | 468 } |
471 | 469 |
472 // Activates the 'Add new foo' option from the |section|'s suggestions | 470 // Activates the 'Add new foo' option from the |section|'s suggestions |
473 // dropdown and fills the |section|'s inputs with the data from the | 471 // dropdown and fills the |section|'s inputs with the data from the |
474 // |data_model|. If |section| is SECTION_CC, also fills in '123' for the CVC. | 472 // |data_model|. If |section| is SECTION_CC, also fills in '123' for the CVC. |
475 void FillInputs(DialogSection section, const AutofillDataModel& data_model) { | 473 void FillInputs(DialogSection section, const AutofillDataModel& data_model) { |
476 // Select the 'Add new foo' option. | 474 // Select the 'Add new foo' option. |
477 ui::MenuModel* model = GetMenuModelForSection(section); | 475 ui::MenuModel* model = GetMenuModelForSection(section); |
478 if (model) | 476 if (model) |
479 model->ActivatedAt(model->GetItemCount() - 2); | 477 model->ActivatedAt(model->GetItemCount() - 2); |
480 | 478 |
481 // Fill the inputs. | 479 // Fill the inputs. |
482 DetailOutputMap outputs; | 480 FieldValueMap outputs; |
483 const DetailInputs& inputs = | 481 const DetailInputs& inputs = |
484 controller()->RequestedFieldsForSection(section); | 482 controller()->RequestedFieldsForSection(section); |
485 for (size_t i = 0; i < inputs.size(); ++i) { | 483 for (size_t i = 0; i < inputs.size(); ++i) { |
486 ServerFieldType type = inputs[i].type; | 484 ServerFieldType type = inputs[i].type; |
487 base::string16 output; | 485 base::string16 output; |
488 if (type == CREDIT_CARD_VERIFICATION_CODE) | 486 if (type == CREDIT_CARD_VERIFICATION_CODE) |
489 output = ASCIIToUTF16("123"); | 487 output = ASCIIToUTF16("123"); |
490 else | 488 else |
491 output = data_model.GetInfo(AutofillType(type), "en-US"); | 489 output = data_model.GetInfo(AutofillType(type), "en-US"); |
492 outputs[&inputs[i]] = output; | 490 outputs[inputs[i].type] = output; |
493 } | 491 } |
494 controller()->GetView()->SetUserInput(section, outputs); | 492 controller()->GetView()->SetUserInput(section, outputs); |
495 } | 493 } |
496 | 494 |
497 std::vector<DialogNotification> NotificationsOfType( | 495 std::vector<DialogNotification> NotificationsOfType( |
498 DialogNotification::Type type) { | 496 DialogNotification::Type type) { |
499 std::vector<DialogNotification> right_type; | 497 std::vector<DialogNotification> right_type; |
500 const std::vector<DialogNotification>& notifications = | 498 const std::vector<DialogNotification>& notifications = |
501 controller()->CurrentNotifications(); | 499 controller()->CurrentNotifications(); |
502 for (size_t i = 0; i < notifications.size(); ++i) { | 500 for (size_t i = 0; i < notifications.size(); ++i) { |
(...skipping 16 matching lines...) Expand all Loading... |
519 controller_->SimulateSigninError(); | 517 controller_->SimulateSigninError(); |
520 } | 518 } |
521 | 519 |
522 void UseBillingForShipping() { | 520 void UseBillingForShipping() { |
523 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); | 521 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); |
524 } | 522 } |
525 | 523 |
526 void ValidateCCNumber(DialogSection section, | 524 void ValidateCCNumber(DialogSection section, |
527 const std::string& cc_number, | 525 const std::string& cc_number, |
528 bool should_pass) { | 526 bool should_pass) { |
529 DetailOutputMap outputs; | 527 FieldValueMap outputs; |
530 const DetailInputs& inputs = | 528 const DetailInputs& inputs = |
531 controller()->RequestedFieldsForSection(section); | 529 controller()->RequestedFieldsForSection(section); |
532 | 530 |
533 SetOutputValue(inputs, CREDIT_CARD_NUMBER, | 531 SetOutputValue(inputs, CREDIT_CARD_NUMBER, |
534 ASCIIToUTF16(cc_number), &outputs); | 532 ASCIIToUTF16(cc_number), &outputs); |
535 ValidityMessages messages = | 533 ValidityMessages messages = |
536 controller()->InputsAreValid(section, outputs); | 534 controller()->InputsAreValid(section, outputs); |
537 EXPECT_EQ(should_pass, !messages.HasSureError(CREDIT_CARD_NUMBER)); | 535 EXPECT_EQ(should_pass, !messages.HasSureError(CREDIT_CARD_NUMBER)); |
538 } | 536 } |
539 | 537 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 controller()->RequestedFieldsForSection(section); | 635 controller()->RequestedFieldsForSection(section); |
638 for (DetailInputs::const_iterator iter = shipping_inputs.begin(); | 636 for (DetailInputs::const_iterator iter = shipping_inputs.begin(); |
639 iter != shipping_inputs.end(); ++iter) { | 637 iter != shipping_inputs.end(); ++iter) { |
640 controller()->InputValidityMessage(section, iter->type, string16()); | 638 controller()->InputValidityMessage(section, iter->type, string16()); |
641 } | 639 } |
642 } | 640 } |
643 } | 641 } |
644 | 642 |
645 // Test for phone number validation. | 643 // Test for phone number validation. |
646 TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) { | 644 TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) { |
647 // Construct DetailOutputMap from existing data. | 645 // Construct FieldValueMap from existing data. |
648 SwitchToAutofill(); | 646 SwitchToAutofill(); |
649 | 647 |
650 for (size_t i = 0; i < 2; ++i) { | 648 for (size_t i = 0; i < 2; ++i) { |
651 ServerFieldType phone = i == 0 ? PHONE_HOME_WHOLE_NUMBER : | 649 ServerFieldType phone = i == 0 ? PHONE_HOME_WHOLE_NUMBER : |
652 PHONE_BILLING_WHOLE_NUMBER; | 650 PHONE_BILLING_WHOLE_NUMBER; |
653 ServerFieldType address = i == 0 ? ADDRESS_HOME_COUNTRY : | 651 ServerFieldType address = i == 0 ? ADDRESS_HOME_COUNTRY : |
654 ADDRESS_BILLING_COUNTRY; | 652 ADDRESS_BILLING_COUNTRY; |
655 DialogSection section = i == 0 ? SECTION_SHIPPING : SECTION_BILLING; | 653 DialogSection section = i == 0 ? SECTION_SHIPPING : SECTION_BILLING; |
656 | 654 |
657 DetailOutputMap outputs; | 655 FieldValueMap outputs; |
658 const DetailInputs& inputs = | 656 const DetailInputs& inputs = |
659 controller()->RequestedFieldsForSection(section); | 657 controller()->RequestedFieldsForSection(section); |
660 AutofillProfile full_profile(test::GetVerifiedProfile()); | 658 AutofillProfile full_profile(test::GetVerifiedProfile()); |
661 for (size_t i = 0; i < inputs.size(); ++i) { | 659 for (size_t i = 0; i < inputs.size(); ++i) { |
662 const DetailInput& input = inputs[i]; | 660 const ServerFieldType type = inputs[i].type; |
663 outputs[&input] = full_profile.GetInfo(AutofillType(input.type), | 661 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); |
664 "en-US"); | |
665 } | 662 } |
666 | 663 |
667 // Make sure country is United States. | 664 // Make sure country is United States. |
668 SetOutputValue(inputs, address, ASCIIToUTF16("United States"), &outputs); | 665 SetOutputValue(inputs, address, ASCIIToUTF16("United States"), &outputs); |
669 | 666 |
670 // Existing data should have no errors. | 667 // Existing data should have no errors. |
671 ValidityMessages messages = controller()->InputsAreValid(section, outputs); | 668 ValidityMessages messages = controller()->InputsAreValid(section, outputs); |
672 EXPECT_FALSE(HasAnyError(messages, phone)); | 669 EXPECT_FALSE(HasAnyError(messages, phone)); |
673 | 670 |
674 // Input an empty phone number. | 671 // Input an empty phone number. |
(...skipping 23 matching lines...) Expand all Loading... |
698 | 695 |
699 // Input an invalid international phone number. | 696 // Input an invalid international phone number. |
700 SetOutputValue(inputs, phone, | 697 SetOutputValue(inputs, phone, |
701 ASCIIToUTF16("+112333 892 70 12 39"), &outputs); | 698 ASCIIToUTF16("+112333 892 70 12 39"), &outputs); |
702 messages = controller()->InputsAreValid(section, outputs); | 699 messages = controller()->InputsAreValid(section, outputs); |
703 EXPECT_TRUE(messages.HasSureError(phone)); | 700 EXPECT_TRUE(messages.HasSureError(phone)); |
704 } | 701 } |
705 } | 702 } |
706 | 703 |
707 TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) { | 704 TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) { |
708 DetailOutputMap outputs; | 705 FieldValueMap outputs; |
709 const DetailInputs& inputs = | 706 const DetailInputs& inputs = |
710 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | 707 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); |
711 | 708 |
712 ui::ComboboxModel* exp_year_model = | 709 ui::ComboboxModel* exp_year_model = |
713 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 710 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
714 ui::ComboboxModel* exp_month_model = | 711 ui::ComboboxModel* exp_month_model = |
715 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH); | 712 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH); |
716 | 713 |
717 base::string16 default_year_value = | 714 base::string16 default_year_value = |
718 exp_year_model->GetItemAt(exp_year_model->GetDefaultIndex()); | 715 exp_year_model->GetItemAt(exp_year_model->GetDefaultIndex()); |
(...skipping 27 matching lines...) Expand all Loading... |
746 // Expiration date with default year fails. | 743 // Expiration date with default year fails. |
747 SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, other_month_value, &outputs); | 744 SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, other_month_value, &outputs); |
748 SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 745 SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, |
749 default_year_value, &outputs); | 746 default_year_value, &outputs); |
750 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); | 747 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); |
751 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 748 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
752 EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); | 749 EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); |
753 } | 750 } |
754 | 751 |
755 TEST_F(AutofillDialogControllerTest, BillingNameValidation) { | 752 TEST_F(AutofillDialogControllerTest, BillingNameValidation) { |
756 // Construct DetailOutputMap from AutofillProfile data. | 753 // Construct FieldValueMap from AutofillProfile data. |
757 SwitchToAutofill(); | 754 SwitchToAutofill(); |
758 | 755 |
759 DetailOutputMap outputs; | 756 FieldValueMap outputs; |
760 const DetailInputs& inputs = | 757 const DetailInputs& inputs = |
761 controller()->RequestedFieldsForSection(SECTION_BILLING); | 758 controller()->RequestedFieldsForSection(SECTION_BILLING); |
762 | 759 |
763 // Input an empty billing name. | 760 // Input an empty billing name. |
764 SetOutputValue(inputs, NAME_BILLING_FULL, base::string16(), &outputs); | 761 SetOutputValue(inputs, NAME_BILLING_FULL, base::string16(), &outputs); |
765 ValidityMessages messages = controller()->InputsAreValid(SECTION_BILLING, | 762 ValidityMessages messages = controller()->InputsAreValid(SECTION_BILLING, |
766 outputs); | 763 outputs); |
767 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); | 764 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); |
768 | 765 |
769 // Input a non-empty billing name. | 766 // Input a non-empty billing name. |
770 SetOutputValue(inputs, NAME_BILLING_FULL, ASCIIToUTF16("Bob"), &outputs); | 767 SetOutputValue(inputs, NAME_BILLING_FULL, ASCIIToUTF16("Bob"), &outputs); |
771 messages = controller()->InputsAreValid(SECTION_BILLING, outputs); | 768 messages = controller()->InputsAreValid(SECTION_BILLING, outputs); |
772 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); | 769 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); |
773 | 770 |
774 // Switch to Wallet which only considers names with with at least two names to | 771 // Switch to Wallet which only considers names with with at least two names to |
775 // be valid. | 772 // be valid. |
776 SwitchToWallet(); | 773 SwitchToWallet(); |
777 | 774 |
778 // Setup some wallet state. | 775 // Setup some wallet state. |
779 scoped_ptr<wallet::WalletItems> wallet_items = | 776 scoped_ptr<wallet::WalletItems> wallet_items = |
780 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 777 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
781 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 778 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
782 | 779 |
783 DetailOutputMap wallet_outputs; | 780 FieldValueMap wallet_outputs; |
784 const DetailInputs& wallet_inputs = | 781 const DetailInputs& wallet_inputs = |
785 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | 782 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); |
786 | 783 |
787 // Input an empty billing name. Data source should not change this behavior. | 784 // Input an empty billing name. Data source should not change this behavior. |
788 SetOutputValue(wallet_inputs, NAME_BILLING_FULL, | 785 SetOutputValue(wallet_inputs, NAME_BILLING_FULL, |
789 base::string16(), &wallet_outputs); | 786 base::string16(), &wallet_outputs); |
790 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); | 787 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); |
791 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); | 788 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); |
792 | 789 |
793 // Input a one name billing name. Wallet does not currently support this. | 790 // Input a one name billing name. Wallet does not currently support this. |
(...skipping 18 matching lines...) Expand all Loading... |
812 // Input a billing name with lots of crazy whitespace. | 809 // Input a billing name with lots of crazy whitespace. |
813 SetOutputValue( | 810 SetOutputValue( |
814 wallet_inputs, NAME_BILLING_FULL, | 811 wallet_inputs, NAME_BILLING_FULL, |
815 ASCIIToUTF16(" \\n\\r John \\n Jacob Jingleheimer \\t Schmidt "), | 812 ASCIIToUTF16(" \\n\\r John \\n Jacob Jingleheimer \\t Schmidt "), |
816 &wallet_outputs); | 813 &wallet_outputs); |
817 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); | 814 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); |
818 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); | 815 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); |
819 } | 816 } |
820 | 817 |
821 TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) { | 818 TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) { |
822 // Construct DetailOutputMap from AutofillProfile data. | 819 // Construct FieldValueMap from AutofillProfile data. |
823 SwitchToAutofill(); | 820 SwitchToAutofill(); |
824 | 821 |
825 // Should accept AMEX, Visa, Master and Discover. | 822 // Should accept AMEX, Visa, Master and Discover. |
826 ValidateCCNumber(SECTION_CC, kTestCCNumberVisa, true); | 823 ValidateCCNumber(SECTION_CC, kTestCCNumberVisa, true); |
827 ValidateCCNumber(SECTION_CC, kTestCCNumberMaster, true); | 824 ValidateCCNumber(SECTION_CC, kTestCCNumberMaster, true); |
828 ValidateCCNumber(SECTION_CC, kTestCCNumberDiscover, true); | 825 ValidateCCNumber(SECTION_CC, kTestCCNumberDiscover, true); |
829 ValidateCCNumber(SECTION_CC, kTestCCNumberAmex, true); | 826 ValidateCCNumber(SECTION_CC, kTestCCNumberAmex, true); |
830 ValidateCCNumber(SECTION_CC, kTestCCNumberIncomplete, false); | 827 ValidateCCNumber(SECTION_CC, kTestCCNumberIncomplete, false); |
831 ValidateCCNumber(SECTION_CC, kTestCCNumberInvalid, false); | 828 ValidateCCNumber(SECTION_CC, kTestCCNumberInvalid, false); |
832 | 829 |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1578 // the user has selected "Same as billing". | 1575 // the user has selected "Same as billing". |
1579 TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) { | 1576 TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) { |
1580 scoped_ptr<wallet::WalletItems> wallet_items = | 1577 scoped_ptr<wallet::WalletItems> wallet_items = |
1581 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 1578 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
1582 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1579 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1583 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1580 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1584 | 1581 |
1585 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_CC_BILLING); | 1582 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_CC_BILLING); |
1586 model->ActivatedAt(model->GetItemCount() - 2); | 1583 model->ActivatedAt(model->GetItemCount() - 2); |
1587 | 1584 |
1588 DetailOutputMap outputs; | 1585 FieldValueMap outputs; |
1589 const DetailInputs& inputs = | 1586 const DetailInputs& inputs = |
1590 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | 1587 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); |
1591 AutofillProfile full_profile(test::GetVerifiedProfile()); | 1588 AutofillProfile full_profile(test::GetVerifiedProfile()); |
1592 CreditCard full_card(test::GetCreditCard()); | 1589 CreditCard full_card(test::GetCreditCard()); |
1593 for (size_t i = 0; i < inputs.size(); ++i) { | 1590 for (size_t i = 0; i < inputs.size(); ++i) { |
1594 const DetailInput& input = inputs[i]; | 1591 const ServerFieldType type = inputs[i].type; |
1595 if (input.type == ADDRESS_BILLING_LINE1) { | 1592 if (type == ADDRESS_BILLING_LINE1) |
1596 outputs[&input] = ASCIIToUTF16(kEditedBillingAddress); | 1593 outputs[type] = ASCIIToUTF16(kEditedBillingAddress); |
1597 } else { | 1594 else |
1598 outputs[&input] = full_profile.GetInfo(AutofillType(input.type), | 1595 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); |
1599 "en-US"); | |
1600 } | |
1601 | 1596 |
1602 if (outputs[&input].empty()) | 1597 if (outputs[type].empty()) |
1603 outputs[&input] = full_card.GetInfo(AutofillType(input.type), "en-US"); | 1598 outputs[type] = full_card.GetInfo(AutofillType(type), "en-US"); |
1604 } | 1599 } |
1605 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 1600 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
1606 | 1601 |
1607 controller()->OnAccept(); | 1602 controller()->OnAccept(); |
1608 | 1603 |
1609 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1604 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1610 SaveToWalletMock(testing::NotNull(), UsesLocalBillingAddress())); | 1605 SaveToWalletMock(testing::NotNull(), UsesLocalBillingAddress())); |
1611 AcceptAndLoadFakeFingerprint(); | 1606 AcceptAndLoadFakeFingerprint(); |
1612 } | 1607 } |
1613 | 1608 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 AutofillProfile full_profile(test::GetVerifiedProfile()); | 1658 AutofillProfile full_profile(test::GetVerifiedProfile()); |
1664 CreditCard credit_card(test::GetVerifiedCreditCard()); | 1659 CreditCard credit_card(test::GetVerifiedCreditCard()); |
1665 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 1660 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
1666 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 1661 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
1667 | 1662 |
1668 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING); | 1663 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING); |
1669 // Activate the "Add billing address" menu item. | 1664 // Activate the "Add billing address" menu item. |
1670 model->ActivatedAt(model->GetItemCount() - 2); | 1665 model->ActivatedAt(model->GetItemCount() - 2); |
1671 | 1666 |
1672 // Fill in the inputs from the profile. | 1667 // Fill in the inputs from the profile. |
1673 DetailOutputMap outputs; | 1668 FieldValueMap outputs; |
1674 const DetailInputs& inputs = | 1669 const DetailInputs& inputs = |
1675 controller()->RequestedFieldsForSection(SECTION_BILLING); | 1670 controller()->RequestedFieldsForSection(SECTION_BILLING); |
1676 AutofillProfile full_profile2(test::GetVerifiedProfile2()); | 1671 AutofillProfile full_profile2(test::GetVerifiedProfile2()); |
1677 for (size_t i = 0; i < inputs.size(); ++i) { | 1672 for (size_t i = 0; i < inputs.size(); ++i) { |
1678 const DetailInput& input = inputs[i]; | 1673 const ServerFieldType type = inputs[i].type; |
1679 outputs[&input] = full_profile2.GetInfo(AutofillType(input.type), "en-US"); | 1674 outputs[type] = full_profile2.GetInfo(AutofillType(type), "en-US"); |
1680 } | 1675 } |
1681 controller()->GetView()->SetUserInput(SECTION_BILLING, outputs); | 1676 controller()->GetView()->SetUserInput(SECTION_BILLING, outputs); |
1682 | 1677 |
1683 controller()->OnAccept(); | 1678 controller()->OnAccept(); |
1684 const AutofillProfile& added_profile = | 1679 const AutofillProfile& added_profile = |
1685 controller()->GetTestingManager()->imported_profile(); | 1680 controller()->GetTestingManager()->imported_profile(); |
1686 | 1681 |
1687 const DetailInputs& shipping_inputs = | 1682 const DetailInputs& shipping_inputs = |
1688 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | 1683 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
1689 for (size_t i = 0; i < shipping_inputs.size(); ++i) { | 1684 for (size_t i = 0; i < shipping_inputs.size(); ++i) { |
1690 const DetailInput& input = shipping_inputs[i]; | 1685 const ServerFieldType type = shipping_inputs[i].type; |
1691 EXPECT_EQ(full_profile2.GetInfo(AutofillType(input.type), "en-US"), | 1686 EXPECT_EQ(full_profile2.GetInfo(AutofillType(type), "en-US"), |
1692 added_profile.GetInfo(AutofillType(input.type), "en-US")); | 1687 added_profile.GetInfo(AutofillType(type), "en-US")); |
1693 } | 1688 } |
1694 } | 1689 } |
1695 | 1690 |
1696 TEST_F(AutofillDialogControllerTest, VerifyCvv) { | 1691 TEST_F(AutofillDialogControllerTest, VerifyCvv) { |
1697 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetFullWallet(_)); | 1692 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetFullWallet(_)); |
1698 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1693 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1699 AuthenticateInstrument(_, _)); | 1694 AuthenticateInstrument(_, _)); |
1700 | 1695 |
1701 SubmitWithWalletItems(CompleteAndValidWalletItems()); | 1696 SubmitWithWalletItems(CompleteAndValidWalletItems()); |
1702 | 1697 |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 scoped_ptr<wallet::WalletItems> wallet_items = | 2190 scoped_ptr<wallet::WalletItems> wallet_items = |
2196 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 2191 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
2197 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); | 2192 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); |
2198 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 2193 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
2199 | 2194 |
2200 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); | 2195 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); |
2201 | 2196 |
2202 // Use |SetOutputValue()| to put the right ServerFieldTypes into the map. | 2197 // Use |SetOutputValue()| to put the right ServerFieldTypes into the map. |
2203 const DetailInputs& inputs = | 2198 const DetailInputs& inputs = |
2204 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | 2199 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); |
2205 DetailOutputMap outputs; | 2200 FieldValueMap outputs; |
2206 CopyInitialValues(inputs, &outputs); | 2201 CopyInitialValues(inputs, &outputs); |
2207 SetOutputValue(inputs, COMPANY_NAME, ASCIIToUTF16("Bluth Company"), &outputs); | 2202 SetOutputValue(inputs, COMPANY_NAME, ASCIIToUTF16("Bluth Company"), &outputs); |
2208 | 2203 |
2209 // The local inputs are invalid because the server said so. They'll | 2204 // The local inputs are invalid because the server said so. They'll |
2210 // stay invalid until they differ from the remotely fetched model. | 2205 // stay invalid until they differ from the remotely fetched model. |
2211 ValidityMessages messages = controller()->InputsAreValid(SECTION_CC_BILLING, | 2206 ValidityMessages messages = controller()->InputsAreValid(SECTION_CC_BILLING, |
2212 outputs); | 2207 outputs); |
2213 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_MONTH)); | 2208 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_MONTH)); |
2214 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 2209 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
2215 | 2210 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2602 // Expired instrument: CC number + CVV are not editable. | 2597 // Expired instrument: CC number + CVV are not editable. |
2603 items = wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 2598 items = wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
2604 scoped_ptr<wallet::WalletItems::MaskedInstrument> expired_instrument = | 2599 scoped_ptr<wallet::WalletItems::MaskedInstrument> expired_instrument = |
2605 wallet::GetTestMaskedInstrumentExpired(); | 2600 wallet::GetTestMaskedInstrumentExpired(); |
2606 items->AddInstrument(expired_instrument.Pass()); | 2601 items->AddInstrument(expired_instrument.Pass()); |
2607 controller()->OnDidGetWalletItems(items.Pass()); | 2602 controller()->OnDidGetWalletItems(items.Pass()); |
2608 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); | 2603 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); |
2609 | 2604 |
2610 const DetailInputs& inputs = | 2605 const DetailInputs& inputs = |
2611 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | 2606 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); |
2612 DetailOutputMap outputs; | 2607 FieldValueMap outputs; |
2613 CopyInitialValues(inputs, &outputs); | 2608 CopyInitialValues(inputs, &outputs); |
2614 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 2609 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
2615 | 2610 |
2616 for (size_t i = 0; i < arraysize(sections); ++i) { | 2611 for (size_t i = 0; i < arraysize(sections); ++i) { |
2617 const DetailInputs& inputs = | 2612 const DetailInputs& inputs = |
2618 controller()->RequestedFieldsForSection(sections[i]); | 2613 controller()->RequestedFieldsForSection(sections[i]); |
2619 for (size_t j = 0; j < inputs.size(); ++j) { | 2614 for (size_t j = 0; j < inputs.size(); ++j) { |
2620 if (inputs[j].type == CREDIT_CARD_NUMBER || | 2615 if (inputs[j].type == CREDIT_CARD_NUMBER || |
2621 inputs[j].type == CREDIT_CARD_VERIFICATION_CODE) { | 2616 inputs[j].type == CREDIT_CARD_VERIFICATION_CODE) { |
2622 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); | 2617 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2693 EXPECT_EQ(0U, controller()->GetTestingWalletClient()->user_index()); | 2688 EXPECT_EQ(0U, controller()->GetTestingWalletClient()->user_index()); |
2694 | 2689 |
2695 // GetWalletItems should be called when the user switches accounts. | 2690 // GetWalletItems should be called when the user switches accounts. |
2696 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); | 2691 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); |
2697 controller()->MenuModelForAccountChooser()->ActivatedAt(1); | 2692 controller()->MenuModelForAccountChooser()->ActivatedAt(1); |
2698 // The wallet client should be updated to the new user index. | 2693 // The wallet client should be updated to the new user index. |
2699 EXPECT_EQ(1U, controller()->GetTestingWalletClient()->user_index()); | 2694 EXPECT_EQ(1U, controller()->GetTestingWalletClient()->user_index()); |
2700 } | 2695 } |
2701 | 2696 |
2702 } // namespace autofill | 2697 } // namespace autofill |
OLD | NEW |