| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/tuple.h" | 17 #include "base/tuple.h" |
| 18 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 18 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 20 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" | 20 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" |
| 21 #include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h" | 21 #include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h" |
| 22 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle
r.h" | 22 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle
r.h" |
| 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 26 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 26 #include "chrome/test/base/scoped_testing_local_state.h" | 27 #include "chrome/test/base/scoped_testing_local_state.h" |
| 27 #include "chrome/test/base/testing_browser_process.h" | 28 #include "chrome/test/base/testing_browser_process.h" |
| 28 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 29 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
| 30 #include "components/autofill/content/browser/wallet/full_wallet.h" | 31 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 31 #include "components/autofill/content/browser/wallet/instrument.h" | 32 #include "components/autofill/content/browser/wallet/instrument.h" |
| 32 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" | 33 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 }; | 84 }; |
| 84 const char kSettingsOrigin[] = "Chrome settings"; | 85 const char kSettingsOrigin[] = "Chrome settings"; |
| 85 const char kTestCCNumberAmex[] = "376200000000002"; | 86 const char kTestCCNumberAmex[] = "376200000000002"; |
| 86 const char kTestCCNumberVisa[] = "4111111111111111"; | 87 const char kTestCCNumberVisa[] = "4111111111111111"; |
| 87 const char kTestCCNumberMaster[] = "5555555555554444"; | 88 const char kTestCCNumberMaster[] = "5555555555554444"; |
| 88 const char kTestCCNumberDiscover[] = "6011111111111117"; | 89 const char kTestCCNumberDiscover[] = "6011111111111117"; |
| 89 const char kTestCCNumberIncomplete[] = "4111111111"; | 90 const char kTestCCNumberIncomplete[] = "4111111111"; |
| 90 // Credit card number fails Luhn check. | 91 // Credit card number fails Luhn check. |
| 91 const char kTestCCNumberInvalid[] = "4111111111111112"; | 92 const char kTestCCNumberInvalid[] = "4111111111111112"; |
| 92 | 93 |
| 93 // Sets the value of |type| in |outputs| to |value|. | |
| 94 void SetOutputValue(const DetailInputs& inputs, | |
| 95 ServerFieldType type, | |
| 96 const base::string16& value, | |
| 97 FieldValueMap* outputs) { | |
| 98 for (size_t i = 0; i < inputs.size(); ++i) { | |
| 99 if (inputs[i].type == type) | |
| 100 (*outputs)[type] = value; | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 // Copies the initial values from |inputs| into |outputs|. | 94 // Copies the initial values from |inputs| into |outputs|. |
| 105 void CopyInitialValues(const DetailInputs& inputs, FieldValueMap* outputs) { | 95 void CopyInitialValues(const DetailInputs& inputs, FieldValueMap* outputs) { |
| 106 for (size_t i = 0; i < inputs.size(); ++i) { | 96 for (size_t i = 0; i < inputs.size(); ++i) { |
| 107 const DetailInput& input = inputs[i]; | 97 const DetailInput& input = inputs[i]; |
| 108 (*outputs)[input.type] = input.initial_value; | 98 (*outputs)[input.type] = input.initial_value; |
| 109 } | 99 } |
| 110 } | 100 } |
| 111 | 101 |
| 112 scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { | 102 scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { |
| 113 scoped_ptr<wallet::WalletItems> items = | 103 scoped_ptr<wallet::WalletItems> items = |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 156 |
| 167 virtual void UpdateOverlay() OVERRIDE { | 157 virtual void UpdateOverlay() OVERRIDE { |
| 168 EXPECT_GE(updates_started_, 1); | 158 EXPECT_GE(updates_started_, 1); |
| 169 } | 159 } |
| 170 | 160 |
| 171 virtual void UpdateDetailArea() OVERRIDE { | 161 virtual void UpdateDetailArea() OVERRIDE { |
| 172 EXPECT_GE(updates_started_, 1); | 162 EXPECT_GE(updates_started_, 1); |
| 173 } | 163 } |
| 174 | 164 |
| 175 virtual void UpdateSection(DialogSection section) OVERRIDE { | 165 virtual void UpdateSection(DialogSection section) OVERRIDE { |
| 166 section_updates_[section]++; |
| 176 EXPECT_GE(updates_started_, 1); | 167 EXPECT_GE(updates_started_, 1); |
| 177 } | 168 } |
| 178 | 169 |
| 179 virtual void UpdateErrorBubble() OVERRIDE { | 170 virtual void UpdateErrorBubble() OVERRIDE { |
| 180 EXPECT_GE(updates_started_, 1); | 171 EXPECT_GE(updates_started_, 1); |
| 181 } | 172 } |
| 182 | 173 |
| 183 virtual void FillSection(DialogSection section, | 174 virtual void FillSection(DialogSection section, |
| 184 const DetailInput& originating_input) OVERRIDE {}; | 175 const DetailInput& originating_input) OVERRIDE {}; |
| 185 virtual void GetUserInput(DialogSection section, FieldValueMap* output) | 176 virtual void GetUserInput(DialogSection section, FieldValueMap* output) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 211 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} | 202 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} |
| 212 | 203 |
| 213 void SetUserInput(DialogSection section, const FieldValueMap& map) { | 204 void SetUserInput(DialogSection section, const FieldValueMap& map) { |
| 214 outputs_[section] = map; | 205 outputs_[section] = map; |
| 215 } | 206 } |
| 216 | 207 |
| 217 void CheckSaveDetailsLocallyCheckbox(bool checked) { | 208 void CheckSaveDetailsLocallyCheckbox(bool checked) { |
| 218 save_details_locally_checked_ = checked; | 209 save_details_locally_checked_ = checked; |
| 219 } | 210 } |
| 220 | 211 |
| 212 void ClearSectionUpdates() { |
| 213 section_updates_.clear(); |
| 214 } |
| 215 |
| 216 std::map<DialogSection, size_t> section_updates() const { |
| 217 return section_updates_; |
| 218 } |
| 219 |
| 221 private: | 220 private: |
| 222 std::map<DialogSection, FieldValueMap> outputs_; | 221 std::map<DialogSection, FieldValueMap> outputs_; |
| 222 std::map<DialogSection, size_t> section_updates_; |
| 223 | 223 |
| 224 int updates_started_; | 224 int updates_started_; |
| 225 bool save_details_locally_checked_; | 225 bool save_details_locally_checked_; |
| 226 | 226 |
| 227 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); | 227 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 class TestAutofillDialogController | 230 class TestAutofillDialogController |
| 231 : public AutofillDialogControllerImpl, | 231 : public AutofillDialogControllerImpl, |
| 232 public base::SupportsWeakPtr<TestAutofillDialogController> { | 232 public base::SupportsWeakPtr<TestAutofillDialogController> { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 ClearLastWalletItemsFetchTimestampForTesting; | 297 ClearLastWalletItemsFetchTimestampForTesting; |
| 298 | 298 |
| 299 // Returns the number of times that the submit button was delayed. | 299 // Returns the number of times that the submit button was delayed. |
| 300 int get_submit_button_delay_count() const { | 300 int get_submit_button_delay_count() const { |
| 301 return submit_button_delay_count_; | 301 return submit_button_delay_count_; |
| 302 } | 302 } |
| 303 | 303 |
| 304 MOCK_METHOD0(LoadRiskFingerprintData, void()); | 304 MOCK_METHOD0(LoadRiskFingerprintData, void()); |
| 305 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 305 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
| 306 using AutofillDialogControllerImpl::IsEditingExistingData; | 306 using AutofillDialogControllerImpl::IsEditingExistingData; |
| 307 using AutofillDialogControllerImpl::IsManuallyEditingSection; |
| 307 using AutofillDialogControllerImpl::IsSubmitPausedOn; | 308 using AutofillDialogControllerImpl::IsSubmitPausedOn; |
| 308 using AutofillDialogControllerImpl::NOT_CHECKED; | 309 using AutofillDialogControllerImpl::NOT_CHECKED; |
| 309 using AutofillDialogControllerImpl::SignedInState; | 310 using AutofillDialogControllerImpl::SignedInState; |
| 310 | 311 |
| 311 protected: | 312 protected: |
| 312 virtual PersonalDataManager* GetManager() OVERRIDE { | 313 virtual PersonalDataManager* GetManager() OVERRIDE { |
| 313 return &test_manager_; | 314 return &test_manager_; |
| 314 } | 315 } |
| 315 | 316 |
| 316 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 317 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 } | 519 } |
| 519 | 520 |
| 520 void UseBillingForShipping() { | 521 void UseBillingForShipping() { |
| 521 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); | 522 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); |
| 522 } | 523 } |
| 523 | 524 |
| 524 void ValidateCCNumber(DialogSection section, | 525 void ValidateCCNumber(DialogSection section, |
| 525 const std::string& cc_number, | 526 const std::string& cc_number, |
| 526 bool should_pass) { | 527 bool should_pass) { |
| 527 FieldValueMap outputs; | 528 FieldValueMap outputs; |
| 528 const DetailInputs& inputs = | 529 outputs[CREDIT_CARD_NUMBER] = UTF8ToUTF16(cc_number); |
| 529 controller()->RequestedFieldsForSection(section); | |
| 530 | |
| 531 SetOutputValue(inputs, CREDIT_CARD_NUMBER, | |
| 532 ASCIIToUTF16(cc_number), &outputs); | |
| 533 ValidityMessages messages = | 530 ValidityMessages messages = |
| 534 controller()->InputsAreValid(section, outputs); | 531 controller()->InputsAreValid(section, outputs); |
| 535 EXPECT_EQ(should_pass, !messages.HasSureError(CREDIT_CARD_NUMBER)); | 532 EXPECT_EQ(should_pass, !messages.HasSureError(CREDIT_CARD_NUMBER)); |
| 536 } | 533 } |
| 537 | 534 |
| 538 void SubmitWithWalletItems(scoped_ptr<wallet::WalletItems> wallet_items) { | 535 void SubmitWithWalletItems(scoped_ptr<wallet::WalletItems> wallet_items) { |
| 539 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 536 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 540 AcceptAndLoadFakeFingerprint(); | 537 AcceptAndLoadFakeFingerprint(); |
| 541 } | 538 } |
| 542 | 539 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 567 return true; | 564 return true; |
| 568 } | 565 } |
| 569 return false; | 566 return false; |
| 570 } | 567 } |
| 571 | 568 |
| 572 SuggestionsMenuModel* GetMenuModelForSection(DialogSection section) { | 569 SuggestionsMenuModel* GetMenuModelForSection(DialogSection section) { |
| 573 ui::MenuModel* model = controller()->MenuModelForSection(section); | 570 ui::MenuModel* model = controller()->MenuModelForSection(section); |
| 574 return static_cast<SuggestionsMenuModel*>(model); | 571 return static_cast<SuggestionsMenuModel*>(model); |
| 575 } | 572 } |
| 576 | 573 |
| 574 void SubmitAndVerifyShippingAndBillingResults() { |
| 575 // Test after setting use billing for shipping. |
| 576 UseBillingForShipping(); |
| 577 |
| 578 controller()->OnAccept(); |
| 579 |
| 580 ASSERT_EQ(20U, form_structure()->field_count()); |
| 581 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 582 form_structure()->field(11)->Type().GetStorableType()); |
| 583 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(11)->Type().group()); |
| 584 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 585 form_structure()->field(18)->Type().GetStorableType()); |
| 586 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(18)->Type().group()); |
| 587 string16 billing_country = form_structure()->field(11)->value; |
| 588 EXPECT_EQ(2U, billing_country.size()); |
| 589 string16 shipping_country = form_structure()->field(18)->value; |
| 590 EXPECT_EQ(2U, shipping_country.size()); |
| 591 EXPECT_FALSE(billing_country.empty()); |
| 592 EXPECT_FALSE(shipping_country.empty()); |
| 593 EXPECT_EQ(billing_country, shipping_country); |
| 594 |
| 595 EXPECT_EQ(CREDIT_CARD_NAME, |
| 596 form_structure()->field(1)->Type().GetStorableType()); |
| 597 string16 cc_name = form_structure()->field(1)->value; |
| 598 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType()); |
| 599 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); |
| 600 string16 billing_name = form_structure()->field(6)->value; |
| 601 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType()); |
| 602 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); |
| 603 string16 shipping_name = form_structure()->field(13)->value; |
| 604 |
| 605 EXPECT_FALSE(cc_name.empty()); |
| 606 EXPECT_FALSE(billing_name.empty()); |
| 607 EXPECT_FALSE(shipping_name.empty()); |
| 608 EXPECT_EQ(cc_name, billing_name); |
| 609 EXPECT_EQ(cc_name, shipping_name); |
| 610 } |
| 611 |
| 577 TestAutofillDialogController* controller() { return controller_.get(); } | 612 TestAutofillDialogController* controller() { return controller_.get(); } |
| 578 | 613 |
| 579 const FormStructure* form_structure() { return form_structure_; } | 614 const FormStructure* form_structure() { return form_structure_; } |
| 580 | 615 |
| 581 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { | 616 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { |
| 582 return test_generated_bubble_controller_; | 617 return test_generated_bubble_controller_; |
| 583 } | 618 } |
| 584 | 619 |
| 585 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { | 620 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { |
| 586 return mock_new_card_bubble_controller_.get(); | 621 return mock_new_card_bubble_controller_.get(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 FieldValueMap outputs; | 690 FieldValueMap outputs; |
| 656 const DetailInputs& inputs = | 691 const DetailInputs& inputs = |
| 657 controller()->RequestedFieldsForSection(section); | 692 controller()->RequestedFieldsForSection(section); |
| 658 AutofillProfile full_profile(test::GetVerifiedProfile()); | 693 AutofillProfile full_profile(test::GetVerifiedProfile()); |
| 659 for (size_t i = 0; i < inputs.size(); ++i) { | 694 for (size_t i = 0; i < inputs.size(); ++i) { |
| 660 const ServerFieldType type = inputs[i].type; | 695 const ServerFieldType type = inputs[i].type; |
| 661 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); | 696 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); |
| 662 } | 697 } |
| 663 | 698 |
| 664 // Make sure country is United States. | 699 // Make sure country is United States. |
| 665 SetOutputValue(inputs, address, ASCIIToUTF16("United States"), &outputs); | 700 outputs[address] = ASCIIToUTF16("United States"); |
| 666 | 701 |
| 667 // Existing data should have no errors. | 702 // Existing data should have no errors. |
| 668 ValidityMessages messages = controller()->InputsAreValid(section, outputs); | 703 ValidityMessages messages = controller()->InputsAreValid(section, outputs); |
| 669 EXPECT_FALSE(HasAnyError(messages, phone)); | 704 EXPECT_FALSE(HasAnyError(messages, phone)); |
| 670 | 705 |
| 671 // Input an empty phone number. | 706 // Input an empty phone number. |
| 672 SetOutputValue(inputs, phone, base::string16(), &outputs); | 707 outputs[phone] = base::string16(); |
| 673 messages = controller()->InputsAreValid(section, outputs); | 708 messages = controller()->InputsAreValid(section, outputs); |
| 674 EXPECT_TRUE(HasUnsureError(messages, phone)); | 709 EXPECT_TRUE(HasUnsureError(messages, phone)); |
| 675 | 710 |
| 676 // Input an invalid phone number. | 711 // Input an invalid phone number. |
| 677 SetOutputValue(inputs, phone, ASCIIToUTF16("ABC"), &outputs); | 712 outputs[phone] = ASCIIToUTF16("ABC"); |
| 678 messages = controller()->InputsAreValid(section, outputs); | 713 messages = controller()->InputsAreValid(section, outputs); |
| 679 EXPECT_TRUE(messages.HasSureError(phone)); | 714 EXPECT_TRUE(messages.HasSureError(phone)); |
| 680 | 715 |
| 681 // Input a local phone number. | 716 // Input a local phone number. |
| 682 SetOutputValue(inputs, phone, ASCIIToUTF16("2155546699"), &outputs); | 717 outputs[phone] = ASCIIToUTF16("2155546699"); |
| 683 messages = controller()->InputsAreValid(section, outputs); | 718 messages = controller()->InputsAreValid(section, outputs); |
| 684 EXPECT_FALSE(HasAnyError(messages, phone)); | 719 EXPECT_FALSE(HasAnyError(messages, phone)); |
| 685 | 720 |
| 686 // Input an invalid local phone number. | 721 // Input an invalid local phone number. |
| 687 SetOutputValue(inputs, phone, ASCIIToUTF16("215554669"), &outputs); | 722 outputs[phone] = ASCIIToUTF16("215554669"); |
| 688 messages = controller()->InputsAreValid(section, outputs); | 723 messages = controller()->InputsAreValid(section, outputs); |
| 689 EXPECT_TRUE(messages.HasSureError(phone)); | 724 EXPECT_TRUE(messages.HasSureError(phone)); |
| 690 | 725 |
| 691 // Input an international phone number. | 726 // Input an international phone number. |
| 692 SetOutputValue(inputs, phone, ASCIIToUTF16("+33 892 70 12 39"), &outputs); | 727 outputs[phone] = ASCIIToUTF16("+33 892 70 12 39"); |
| 693 messages = controller()->InputsAreValid(section, outputs); | 728 messages = controller()->InputsAreValid(section, outputs); |
| 694 EXPECT_FALSE(HasAnyError(messages, phone)); | 729 EXPECT_FALSE(HasAnyError(messages, phone)); |
| 695 | 730 |
| 696 // Input an invalid international phone number. | 731 // Input an invalid international phone number. |
| 697 SetOutputValue(inputs, phone, | 732 outputs[phone] = ASCIIToUTF16("+112333 892 70 12 39"); |
| 698 ASCIIToUTF16("+112333 892 70 12 39"), &outputs); | |
| 699 messages = controller()->InputsAreValid(section, outputs); | 733 messages = controller()->InputsAreValid(section, outputs); |
| 700 EXPECT_TRUE(messages.HasSureError(phone)); | 734 EXPECT_TRUE(messages.HasSureError(phone)); |
| 701 } | 735 } |
| 702 } | 736 } |
| 703 | 737 |
| 704 TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) { | 738 TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) { |
| 705 FieldValueMap outputs; | |
| 706 const DetailInputs& inputs = | |
| 707 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | |
| 708 | |
| 709 ui::ComboboxModel* exp_year_model = | 739 ui::ComboboxModel* exp_year_model = |
| 710 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 740 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
| 711 ui::ComboboxModel* exp_month_model = | 741 ui::ComboboxModel* exp_month_model = |
| 712 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH); | 742 controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH); |
| 713 | 743 |
| 714 base::string16 default_year_value = | 744 base::string16 default_year_value = |
| 715 exp_year_model->GetItemAt(exp_year_model->GetDefaultIndex()); | 745 exp_year_model->GetItemAt(exp_year_model->GetDefaultIndex()); |
| 716 base::string16 default_month_value = | 746 base::string16 default_month_value = |
| 717 exp_month_model->GetItemAt(exp_month_model->GetDefaultIndex()); | 747 exp_month_model->GetItemAt(exp_month_model->GetDefaultIndex()); |
| 718 | 748 |
| 719 base::string16 other_year_value = | 749 base::string16 other_year_value = |
| 720 exp_year_model->GetItemAt(exp_year_model->GetItemCount() - 1); | 750 exp_year_model->GetItemAt(exp_year_model->GetItemCount() - 1); |
| 721 base::string16 other_month_value = | 751 base::string16 other_month_value = |
| 722 exp_month_model->GetItemAt(exp_month_model->GetItemCount() - 1); | 752 exp_month_model->GetItemAt(exp_month_model->GetItemCount() - 1); |
| 723 | 753 |
| 724 SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, default_month_value, &outputs); | 754 FieldValueMap outputs; |
| 725 SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 755 outputs[CREDIT_CARD_EXP_MONTH] = default_month_value; |
| 726 default_year_value, &outputs); | 756 outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = default_year_value; |
| 727 | 757 |
| 728 // Expiration default values generate unsure validation errors (but not sure). | 758 // Expiration default values generate unsure validation errors (but not sure). |
| 729 ValidityMessages messages = controller()->InputsAreValid(SECTION_CC_BILLING, | 759 ValidityMessages messages = controller()->InputsAreValid(SECTION_CC_BILLING, |
| 730 outputs); | 760 outputs); |
| 731 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 761 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 732 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); | 762 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); |
| 733 | 763 |
| 734 // Expiration date with default month fails. | 764 // Expiration date with default month fails. |
| 735 SetOutputValue(inputs, | 765 outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = other_year_value; |
| 736 CREDIT_CARD_EXP_4_DIGIT_YEAR, | |
| 737 other_year_value, | |
| 738 &outputs); | |
| 739 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); | 766 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); |
| 740 EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 767 EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 741 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); | 768 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); |
| 742 | 769 |
| 743 // Expiration date with default year fails. | 770 // Expiration date with default year fails. |
| 744 SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, other_month_value, &outputs); | 771 outputs[CREDIT_CARD_EXP_MONTH] = other_month_value; |
| 745 SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 772 outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = default_year_value; |
| 746 default_year_value, &outputs); | |
| 747 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); | 773 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); |
| 748 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 774 EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 749 EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); | 775 EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH)); |
| 750 } | 776 } |
| 751 | 777 |
| 752 TEST_F(AutofillDialogControllerTest, BillingNameValidation) { | 778 TEST_F(AutofillDialogControllerTest, BillingNameValidation) { |
| 753 // Construct FieldValueMap from AutofillProfile data. | 779 // Construct FieldValueMap from AutofillProfile data. |
| 754 SwitchToAutofill(); | 780 SwitchToAutofill(); |
| 755 | 781 |
| 782 // Input an empty billing name. |
| 756 FieldValueMap outputs; | 783 FieldValueMap outputs; |
| 757 const DetailInputs& inputs = | 784 outputs[NAME_BILLING_FULL] = base::string16(); |
| 758 controller()->RequestedFieldsForSection(SECTION_BILLING); | |
| 759 | |
| 760 // Input an empty billing name. | |
| 761 SetOutputValue(inputs, NAME_BILLING_FULL, base::string16(), &outputs); | |
| 762 ValidityMessages messages = controller()->InputsAreValid(SECTION_BILLING, | 785 ValidityMessages messages = controller()->InputsAreValid(SECTION_BILLING, |
| 763 outputs); | 786 outputs); |
| 764 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); | 787 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); |
| 765 | 788 |
| 766 // Input a non-empty billing name. | 789 // Input a non-empty billing name. |
| 767 SetOutputValue(inputs, NAME_BILLING_FULL, ASCIIToUTF16("Bob"), &outputs); | 790 outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob"); |
| 768 messages = controller()->InputsAreValid(SECTION_BILLING, outputs); | 791 messages = controller()->InputsAreValid(SECTION_BILLING, outputs); |
| 769 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); | 792 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); |
| 770 | 793 |
| 771 // Switch to Wallet which only considers names with with at least two names to | 794 // Switch to Wallet which only considers names with with at least two names to |
| 772 // be valid. | 795 // be valid. |
| 773 SwitchToWallet(); | 796 SwitchToWallet(); |
| 774 | 797 |
| 775 // Setup some wallet state. | 798 // Setup some wallet state. |
| 776 scoped_ptr<wallet::WalletItems> wallet_items = | 799 scoped_ptr<wallet::WalletItems> wallet_items = |
| 777 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 800 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
| 778 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 801 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 779 | 802 |
| 803 // Input an empty billing name. Data source should not change this behavior. |
| 780 FieldValueMap wallet_outputs; | 804 FieldValueMap wallet_outputs; |
| 781 const DetailInputs& wallet_inputs = | 805 wallet_outputs[NAME_BILLING_FULL] = base::string16(); |
| 782 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | |
| 783 | |
| 784 // Input an empty billing name. Data source should not change this behavior. | |
| 785 SetOutputValue(wallet_inputs, NAME_BILLING_FULL, | |
| 786 base::string16(), &wallet_outputs); | |
| 787 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); | 806 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); |
| 788 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); | 807 EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); |
| 789 | 808 |
| 790 // Input a one name billing name. Wallet does not currently support this. | 809 // Input a one name billing name. Wallet does not currently support this. |
| 791 SetOutputValue(wallet_inputs, NAME_BILLING_FULL, | 810 wallet_outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob"); |
| 792 ASCIIToUTF16("Bob"), &wallet_outputs); | |
| 793 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); | 811 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); |
| 794 EXPECT_TRUE(messages.HasSureError(NAME_BILLING_FULL)); | 812 EXPECT_TRUE(messages.HasSureError(NAME_BILLING_FULL)); |
| 795 | 813 |
| 796 // Input a two name billing name. | 814 // Input a two name billing name. |
| 797 SetOutputValue(wallet_inputs, NAME_BILLING_FULL, | 815 wallet_outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob Barker"); |
| 798 ASCIIToUTF16("Bob Barker"), &wallet_outputs); | |
| 799 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); | 816 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); |
| 800 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); | 817 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); |
| 801 | 818 |
| 802 // Input a more than two name billing name. | 819 // Input a more than two name billing name. |
| 803 SetOutputValue(wallet_inputs, NAME_BILLING_FULL, | 820 wallet_outputs[NAME_BILLING_FULL] = |
| 804 ASCIIToUTF16("John Jacob Jingleheimer Schmidt"), | 821 ASCIIToUTF16("John Jacob Jingleheimer Schmidt"), |
| 805 &wallet_outputs); | |
| 806 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); | 822 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); |
| 807 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); | 823 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); |
| 808 | 824 |
| 809 // Input a billing name with lots of crazy whitespace. | 825 // Input a billing name with lots of crazy whitespace. |
| 810 SetOutputValue( | 826 wallet_outputs[NAME_BILLING_FULL] = |
| 811 wallet_inputs, NAME_BILLING_FULL, | |
| 812 ASCIIToUTF16(" \\n\\r John \\n Jacob Jingleheimer \\t Schmidt "), | 827 ASCIIToUTF16(" \\n\\r John \\n Jacob Jingleheimer \\t Schmidt "), |
| 813 &wallet_outputs); | |
| 814 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); | 828 messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); |
| 815 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); | 829 EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); |
| 816 } | 830 } |
| 817 | 831 |
| 818 TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) { | 832 TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) { |
| 819 // Construct FieldValueMap from AutofillProfile data. | 833 // Construct FieldValueMap from AutofillProfile data. |
| 820 SwitchToAutofill(); | 834 SwitchToAutofill(); |
| 821 | 835 |
| 822 // Should accept AMEX, Visa, Master and Discover. | 836 // Should accept AMEX, Visa, Master and Discover. |
| 823 ValidateCCNumber(SECTION_CC, kTestCCNumberVisa, true); | 837 ValidateCCNumber(SECTION_CC, kTestCCNumberVisa, true); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 EXPECT_FALSE(billing_name.empty()); | 1144 EXPECT_FALSE(billing_name.empty()); |
| 1131 EXPECT_FALSE(shipping_name.empty()); | 1145 EXPECT_FALSE(shipping_name.empty()); |
| 1132 // Billing name should always be the same as cardholder name. | 1146 // Billing name should always be the same as cardholder name. |
| 1133 EXPECT_EQ(cc_name, billing_name); | 1147 EXPECT_EQ(cc_name, billing_name); |
| 1134 EXPECT_NE(cc_name, shipping_name); | 1148 EXPECT_NE(cc_name, shipping_name); |
| 1135 } | 1149 } |
| 1136 | 1150 |
| 1137 // Test selecting UseBillingForShipping. | 1151 // Test selecting UseBillingForShipping. |
| 1138 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { | 1152 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { |
| 1139 SwitchToAutofill(); | 1153 SwitchToAutofill(); |
| 1154 |
| 1140 AutofillProfile full_profile(test::GetVerifiedProfile()); | 1155 AutofillProfile full_profile(test::GetVerifiedProfile()); |
| 1156 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 1157 |
| 1141 AutofillProfile full_profile2(test::GetVerifiedProfile2()); | 1158 AutofillProfile full_profile2(test::GetVerifiedProfile2()); |
| 1159 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); |
| 1160 |
| 1142 CreditCard credit_card(test::GetVerifiedCreditCard()); | 1161 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 1143 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | |
| 1144 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); | |
| 1145 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 1162 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
| 1146 | 1163 |
| 1147 // Test after setting use billing for shipping. | 1164 ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_CC)); |
| 1148 UseBillingForShipping(); | 1165 ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1149 | 1166 |
| 1150 controller()->OnAccept(); | 1167 SubmitAndVerifyShippingAndBillingResults(); |
| 1151 ASSERT_EQ(20U, form_structure()->field_count()); | 1168 } |
| 1152 EXPECT_EQ(ADDRESS_HOME_STATE, | |
| 1153 form_structure()->field(9)->Type().GetStorableType()); | |
| 1154 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); | |
| 1155 EXPECT_EQ(ADDRESS_HOME_STATE, | |
| 1156 form_structure()->field(16)->Type().GetStorableType()); | |
| 1157 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); | |
| 1158 string16 billing_state = form_structure()->field(9)->value; | |
| 1159 string16 shipping_state = form_structure()->field(16)->value; | |
| 1160 EXPECT_FALSE(billing_state.empty()); | |
| 1161 EXPECT_FALSE(shipping_state.empty()); | |
| 1162 EXPECT_EQ(billing_state, shipping_state); | |
| 1163 | 1169 |
| 1164 EXPECT_EQ(CREDIT_CARD_NAME, | 1170 TEST_F(AutofillDialogControllerTest, UseBillingAsShippingManualInput) { |
| 1165 form_structure()->field(1)->Type().GetStorableType()); | 1171 SwitchToAutofill(); |
| 1166 string16 cc_name = form_structure()->field(1)->value; | |
| 1167 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType()); | |
| 1168 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); | |
| 1169 string16 billing_name = form_structure()->field(6)->value; | |
| 1170 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType()); | |
| 1171 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); | |
| 1172 string16 shipping_name = form_structure()->field(13)->value; | |
| 1173 | 1172 |
| 1174 EXPECT_FALSE(cc_name.empty()); | 1173 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_CC)); |
| 1175 EXPECT_FALSE(billing_name.empty()); | 1174 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1176 EXPECT_FALSE(shipping_name.empty()); | 1175 |
| 1177 EXPECT_EQ(cc_name, billing_name); | 1176 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 1178 EXPECT_EQ(cc_name, shipping_name); | 1177 FillInputs(SECTION_CC, credit_card); |
| 1178 |
| 1179 AutofillProfile full_profile(test::GetVerifiedProfile()); |
| 1180 FillInputs(SECTION_BILLING, full_profile); |
| 1181 |
| 1182 SubmitAndVerifyShippingAndBillingResults(); |
| 1179 } | 1183 } |
| 1180 | 1184 |
| 1181 // Tests that shipping and billing telephone fields are supported, and filled | 1185 // Tests that shipping and billing telephone fields are supported, and filled |
| 1182 // in by their respective profiles. http://crbug.com/244515 | 1186 // in by their respective profiles. http://crbug.com/244515 |
| 1183 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { | 1187 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { |
| 1184 FormFieldData shipping_tel; | 1188 FormFieldData shipping_tel; |
| 1185 shipping_tel.autocomplete_attribute = "shipping tel"; | 1189 shipping_tel.autocomplete_attribute = "shipping tel"; |
| 1186 FormFieldData billing_tel; | 1190 FormFieldData billing_tel; |
| 1187 billing_tel.autocomplete_attribute = "billing tel"; | 1191 billing_tel.autocomplete_attribute = "billing tel"; |
| 1188 | 1192 |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2187 | 2191 |
| 2188 // Ensure Wallet instruments marked expired by the server are shown as invalid. | 2192 // Ensure Wallet instruments marked expired by the server are shown as invalid. |
| 2189 TEST_F(AutofillDialogControllerTest, WalletExpiredCard) { | 2193 TEST_F(AutofillDialogControllerTest, WalletExpiredCard) { |
| 2190 scoped_ptr<wallet::WalletItems> wallet_items = | 2194 scoped_ptr<wallet::WalletItems> wallet_items = |
| 2191 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 2195 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
| 2192 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); | 2196 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); |
| 2193 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 2197 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 2194 | 2198 |
| 2195 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); | 2199 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); |
| 2196 | 2200 |
| 2197 // Use |SetOutputValue()| to put the right ServerFieldTypes into the map. | |
| 2198 const DetailInputs& inputs = | 2201 const DetailInputs& inputs = |
| 2199 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); | 2202 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); |
| 2200 FieldValueMap outputs; | 2203 FieldValueMap outputs; |
| 2201 CopyInitialValues(inputs, &outputs); | 2204 CopyInitialValues(inputs, &outputs); |
| 2202 SetOutputValue(inputs, COMPANY_NAME, ASCIIToUTF16("Bluth Company"), &outputs); | 2205 outputs[COMPANY_NAME] = ASCIIToUTF16("Bluth Company"); |
| 2203 | 2206 |
| 2204 // The local inputs are invalid because the server said so. They'll | 2207 // The local inputs are invalid because the server said so. They'll |
| 2205 // stay invalid until they differ from the remotely fetched model. | 2208 // stay invalid until they differ from the remotely fetched model. |
| 2206 ValidityMessages messages = controller()->InputsAreValid(SECTION_CC_BILLING, | 2209 ValidityMessages messages = controller()->InputsAreValid(SECTION_CC_BILLING, |
| 2207 outputs); | 2210 outputs); |
| 2208 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_MONTH)); | 2211 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_MONTH)); |
| 2209 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 2212 EXPECT_TRUE(messages.HasSureError(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 2210 | 2213 |
| 2211 // Make the local input year differ from the instrument. | 2214 // Make the local input year differ from the instrument. |
| 2212 CopyInitialValues(inputs, &outputs); | 2215 CopyInitialValues(inputs, &outputs); |
| 2213 SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 2216 outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = ASCIIToUTF16("3002"); |
| 2214 ASCIIToUTF16("3002"), &outputs); | |
| 2215 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); | 2217 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); |
| 2216 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_MONTH)); | 2218 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_MONTH)); |
| 2217 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 2219 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 2218 | 2220 |
| 2219 // Make the local input month differ from the instrument. | 2221 // Make the local input month differ from the instrument. |
| 2220 CopyInitialValues(inputs, &outputs); | 2222 CopyInitialValues(inputs, &outputs); |
| 2221 SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06"), &outputs); | 2223 outputs[CREDIT_CARD_EXP_MONTH] = ASCIIToUTF16("06"); |
| 2222 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); | 2224 messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); |
| 2223 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_MONTH)); | 2225 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_MONTH)); |
| 2224 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 2226 EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 2225 } | 2227 } |
| 2226 | 2228 |
| 2227 TEST_F(AutofillDialogControllerTest, ChooseAnotherInstrumentOrAddress) { | 2229 TEST_F(AutofillDialogControllerTest, ChooseAnotherInstrumentOrAddress) { |
| 2228 SubmitWithWalletItems(CompleteAndValidWalletItems()); | 2230 SubmitWithWalletItems(CompleteAndValidWalletItems()); |
| 2229 | 2231 |
| 2230 EXPECT_EQ(0U, NotificationsOfType( | 2232 EXPECT_EQ(0U, NotificationsOfType( |
| 2231 DialogNotification::REQUIRED_ACTION).size()); | 2233 DialogNotification::REQUIRED_ACTION).size()); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2615 if (inputs[j].type == CREDIT_CARD_NUMBER || | 2617 if (inputs[j].type == CREDIT_CARD_NUMBER || |
| 2616 inputs[j].type == CREDIT_CARD_VERIFICATION_CODE) { | 2618 inputs[j].type == CREDIT_CARD_VERIFICATION_CODE) { |
| 2617 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); | 2619 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); |
| 2618 } else { | 2620 } else { |
| 2619 EXPECT_TRUE(controller()->InputIsEditable(inputs[j], sections[i])); | 2621 EXPECT_TRUE(controller()->InputIsEditable(inputs[j], sections[i])); |
| 2620 } | 2622 } |
| 2621 } | 2623 } |
| 2622 } | 2624 } |
| 2623 | 2625 |
| 2624 // User changes the billing address; same story. | 2626 // User changes the billing address; same story. |
| 2625 SetOutputValue(inputs, ADDRESS_BILLING_ZIP, ASCIIToUTF16("77025"), &outputs); | 2627 outputs[ADDRESS_BILLING_ZIP] = ASCIIToUTF16("77025"); |
| 2626 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 2628 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
| 2627 for (size_t i = 0; i < arraysize(sections); ++i) { | 2629 for (size_t i = 0; i < arraysize(sections); ++i) { |
| 2628 const DetailInputs& inputs = | 2630 const DetailInputs& inputs = |
| 2629 controller()->RequestedFieldsForSection(sections[i]); | 2631 controller()->RequestedFieldsForSection(sections[i]); |
| 2630 for (size_t j = 0; j < inputs.size(); ++j) { | 2632 for (size_t j = 0; j < inputs.size(); ++j) { |
| 2631 if (inputs[j].type == CREDIT_CARD_NUMBER || | 2633 if (inputs[j].type == CREDIT_CARD_NUMBER || |
| 2632 inputs[j].type == CREDIT_CARD_VERIFICATION_CODE) { | 2634 inputs[j].type == CREDIT_CARD_VERIFICATION_CODE) { |
| 2633 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); | 2635 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); |
| 2634 } else { | 2636 } else { |
| 2635 EXPECT_TRUE(controller()->InputIsEditable(inputs[j], sections[i])); | 2637 EXPECT_TRUE(controller()->InputIsEditable(inputs[j], sections[i])); |
| 2636 } | 2638 } |
| 2637 } | 2639 } |
| 2638 } | 2640 } |
| 2639 | 2641 |
| 2640 // User changes a detail of the CC itself (expiration date), CVV is now | 2642 // User changes a detail of the CC itself (expiration date), CVV is now |
| 2641 // editable (and mandatory). | 2643 // editable (and mandatory). |
| 2642 SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06"), &outputs); | 2644 outputs[CREDIT_CARD_EXP_MONTH] = ASCIIToUTF16("06"); |
| 2643 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 2645 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
| 2644 for (size_t i = 0; i < arraysize(sections); ++i) { | 2646 for (size_t i = 0; i < arraysize(sections); ++i) { |
| 2645 const DetailInputs& inputs = | 2647 const DetailInputs& inputs = |
| 2646 controller()->RequestedFieldsForSection(sections[i]); | 2648 controller()->RequestedFieldsForSection(sections[i]); |
| 2647 for (size_t j = 0; j < inputs.size(); ++j) { | 2649 for (size_t j = 0; j < inputs.size(); ++j) { |
| 2648 if (inputs[j].type == CREDIT_CARD_NUMBER) | 2650 if (inputs[j].type == CREDIT_CARD_NUMBER) |
| 2649 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); | 2651 EXPECT_FALSE(controller()->InputIsEditable(inputs[j], sections[i])); |
| 2650 else | 2652 else |
| 2651 EXPECT_TRUE(controller()->InputIsEditable(inputs[j], sections[i])); | 2653 EXPECT_TRUE(controller()->InputIsEditable(inputs[j], sections[i])); |
| 2652 } | 2654 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2697 TEST_F(AutofillDialogControllerTest, PassiveAuthFailure) { | 2699 TEST_F(AutofillDialogControllerTest, PassiveAuthFailure) { |
| 2698 controller()->OnDidGetWalletItems( | 2700 controller()->OnDidGetWalletItems( |
| 2699 wallet::GetTestWalletItemsWithRequiredAction( | 2701 wallet::GetTestWalletItemsWithRequiredAction( |
| 2700 wallet::PASSIVE_GAIA_AUTH)); | 2702 wallet::PASSIVE_GAIA_AUTH)); |
| 2701 EXPECT_TRUE(controller()->ShouldShowSpinner()); | 2703 EXPECT_TRUE(controller()->ShouldShowSpinner()); |
| 2702 controller()->OnPassiveSigninFailure(GoogleServiceAuthError( | 2704 controller()->OnPassiveSigninFailure(GoogleServiceAuthError( |
| 2703 GoogleServiceAuthError::NONE)); | 2705 GoogleServiceAuthError::NONE)); |
| 2704 EXPECT_FALSE(controller()->ShouldShowSpinner()); | 2706 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
| 2705 } | 2707 } |
| 2706 | 2708 |
| 2709 TEST_F(AutofillDialogControllerTest, CountryChangeUpdatesSection) { |
| 2710 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2711 ::switches::kEnableAutofillAddressInternationalization); |
| 2712 Reset(); |
| 2713 |
| 2714 controller()->GetView()->ClearSectionUpdates(); |
| 2715 |
| 2716 controller()->ComboboxItemSelected( |
| 2717 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY), |
| 2718 SECTION_SHIPPING, |
| 2719 3); |
| 2720 EXPECT_EQ(1U, controller()->GetView()->section_updates()[SECTION_SHIPPING]); |
| 2721 EXPECT_EQ(0U, controller()->GetView()->section_updates()[SECTION_BILLING]); |
| 2722 |
| 2723 controller()->ComboboxItemSelected( |
| 2724 controller()->ComboboxModelForAutofillType(ADDRESS_BILLING_COUNTRY), |
| 2725 SECTION_BILLING, |
| 2726 3); |
| 2727 EXPECT_EQ(1U, controller()->GetView()->section_updates()[SECTION_BILLING]); |
| 2728 EXPECT_EQ(1U, controller()->GetView()->section_updates()[SECTION_SHIPPING]); |
| 2729 } |
| 2730 |
| 2707 } // namespace autofill | 2731 } // namespace autofill |
| OLD | NEW |