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/guid.h" | 5 #include "base/guid.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 MOCK_METHOD4(SaveInstrumentAndAddress, | 135 MOCK_METHOD4(SaveInstrumentAndAddress, |
136 void(const wallet::Instrument& instrument, | 136 void(const wallet::Instrument& instrument, |
137 const wallet::Address& address, | 137 const wallet::Address& address, |
138 const std::string& obfuscated_gaia_id, | 138 const std::string& obfuscated_gaia_id, |
139 const GURL& source_url)); | 139 const GURL& source_url)); |
140 | 140 |
141 private: | 141 private: |
142 DISALLOW_COPY_AND_ASSIGN(TestWalletClient); | 142 DISALLOW_COPY_AND_ASSIGN(TestWalletClient); |
143 }; | 143 }; |
144 | 144 |
| 145 // Bring over command-ids from AccountChooserModel. |
| 146 class TestAccountChooserModel : public AccountChooserModel { |
| 147 public: |
| 148 TestAccountChooserModel(AccountChooserModelDelegate* delegate, |
| 149 PrefService* prefs, |
| 150 const AutofillMetrics& metric_logger) |
| 151 : AccountChooserModel(delegate, prefs, metric_logger, |
| 152 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {} |
| 153 virtual ~TestAccountChooserModel() {} |
| 154 |
| 155 using AccountChooserModel::kActiveWalletItemId; |
| 156 using AccountChooserModel::kAutofillItemId; |
| 157 |
| 158 private: |
| 159 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel); |
| 160 }; |
| 161 |
145 class TestAutofillDialogController : public AutofillDialogControllerImpl { | 162 class TestAutofillDialogController : public AutofillDialogControllerImpl { |
146 public: | 163 public: |
147 TestAutofillDialogController( | 164 TestAutofillDialogController( |
148 content::WebContents* contents, | 165 content::WebContents* contents, |
149 const FormData& form_structure, | 166 const FormData& form_structure, |
150 const GURL& source_url, | 167 const GURL& source_url, |
151 const AutofillMetrics& metric_logger, | 168 const AutofillMetrics& metric_logger, |
152 const DialogType dialog_type, | 169 const DialogType dialog_type, |
153 const base::Callback<void(const FormStructure*, | 170 const base::Callback<void(const FormStructure*, |
154 const std::string&)>& callback) | 171 const std::string&)>& callback) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 290 |
274 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { | 291 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { |
275 base::DictionaryValue dict; | 292 base::DictionaryValue dict; |
276 scoped_ptr<base::ListValue> list(new base::ListValue()); | 293 scoped_ptr<base::ListValue> list(new base::ListValue()); |
277 list->AppendString("verify_cvv"); | 294 list->AppendString("verify_cvv"); |
278 dict.Set("required_action", list.release()); | 295 dict.Set("required_action", list.release()); |
279 return wallet::FullWallet::CreateFullWallet(dict); | 296 return wallet::FullWallet::CreateFullWallet(dict); |
280 } | 297 } |
281 | 298 |
282 void SetUpWallet() { | 299 void SetUpWallet() { |
283 controller()->MenuModelForAccountChooser()->ActivatedAt( | |
284 AccountChooserModel::kWalletItemId); | |
285 controller()->OnUserNameFetchSuccess("user@example.com"); | 300 controller()->OnUserNameFetchSuccess("user@example.com"); |
| 301 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser(); |
| 302 ASSERT_TRUE(account_model); |
| 303 account_model->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId); |
286 } | 304 } |
287 | 305 |
288 TestAutofillDialogController* controller() { return controller_; } | 306 TestAutofillDialogController* controller() { return controller_; } |
289 | 307 |
290 TestingProfile* profile() { return &profile_; } | 308 TestingProfile* profile() { return &profile_; } |
291 | 309 |
292 private: | 310 private: |
293 void FinishedCallback(const FormStructure* form_structure, | 311 void FinishedCallback(const FormStructure* form_structure, |
294 const std::string& google_transaction_id) {} | 312 const std::string& google_transaction_id) {} |
295 | 313 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 640 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
623 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 641 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
624 controller()->OnAccept(); | 642 controller()->OnAccept(); |
625 | 643 |
626 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 644 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
627 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 645 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
628 | 646 |
629 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); | 647 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
630 ASSERT_TRUE(account_menu); | 648 ASSERT_TRUE(account_menu); |
631 ASSERT_GE(2, account_menu->GetItemCount()); | 649 ASSERT_GE(2, account_menu->GetItemCount()); |
632 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); | 650 account_menu->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId); |
633 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); | 651 account_menu->ActivatedAt(TestAccountChooserModel::kAutofillItemId); |
634 | 652 |
635 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 653 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
636 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 654 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
637 } | 655 } |
638 | 656 |
639 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { | 657 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { |
640 SetUpWallet(); | 658 SetUpWallet(); |
641 | 659 |
642 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 660 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
643 GetFullWallet(_)).Times(1); | 661 GetFullWallet(_)).Times(1); |
(...skipping 27 matching lines...) Expand all Loading... |
671 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 689 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
672 controller()->OnAccept(); | 690 controller()->OnAccept(); |
673 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 691 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
674 | 692 |
675 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 693 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
676 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 694 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
677 | 695 |
678 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); | 696 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
679 ASSERT_TRUE(account_menu); | 697 ASSERT_TRUE(account_menu); |
680 ASSERT_GE(2, account_menu->GetItemCount()); | 698 ASSERT_GE(2, account_menu->GetItemCount()); |
681 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); | 699 account_menu->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId); |
682 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); | 700 account_menu->ActivatedAt(TestAccountChooserModel::kAutofillItemId); |
683 | 701 |
684 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 702 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
685 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 703 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
686 } | 704 } |
687 | 705 |
688 // Test that when a wallet error happens only an error is shown (and no other | 706 // Test that when a wallet error happens only an error is shown (and no other |
689 // Wallet-related notifications). | 707 // Wallet-related notifications). |
690 TEST_F(AutofillDialogControllerTest, WalletErrorNotification) { | 708 TEST_F(AutofillDialogControllerTest, WalletErrorNotification) { |
691 SetUpWallet(); | 709 SetUpWallet(); |
692 | 710 |
(...skipping 25 matching lines...) Expand all Loading... |
718 DialogNotification::EXPLANATORY_MESSAGE).size()); | 736 DialogNotification::EXPLANATORY_MESSAGE).size()); |
719 | 737 |
720 // Wallet notifications are mutually exclusive. | 738 // Wallet notifications are mutually exclusive. |
721 EXPECT_TRUE(NotificationsOfType( | 739 EXPECT_TRUE(NotificationsOfType( |
722 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); | 740 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
723 EXPECT_TRUE(NotificationsOfType( | 741 EXPECT_TRUE(NotificationsOfType( |
724 DialogNotification::WALLET_SIGNIN_PROMO).empty()); | 742 DialogNotification::WALLET_SIGNIN_PROMO).empty()); |
725 | 743 |
726 // Switch to using Autofill, no explanatory message should show. | 744 // Switch to using Autofill, no explanatory message should show. |
727 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); | 745 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
728 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); | 746 ASSERT_TRUE(account_menu); |
| 747 account_menu->ActivatedAt(TestAccountChooserModel::kAutofillItemId); |
729 EXPECT_TRUE(NotificationsOfType( | 748 EXPECT_TRUE(NotificationsOfType( |
730 DialogNotification::EXPLANATORY_MESSAGE).empty()); | 749 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
731 | 750 |
732 // Switch to Wallet, pretend this isn't first run. No message should show. | 751 // Switch to Wallet, pretend this isn't first run. No message should show. |
733 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); | 752 account_menu->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId); |
734 controller()->set_is_first_run(false); | 753 controller()->set_is_first_run(false); |
735 EXPECT_TRUE(NotificationsOfType( | 754 EXPECT_TRUE(NotificationsOfType( |
736 DialogNotification::EXPLANATORY_MESSAGE).empty()); | 755 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
737 } | 756 } |
738 | 757 |
739 // Verifies that the "[X] Save details in wallet" notification shows on first | 758 // Verifies that the "[X] Save details in wallet" notification shows on first |
740 // run with an incomplete profile, stays showing when switching to Autofill in | 759 // run with an incomplete profile, stays showing when switching to Autofill in |
741 // the account chooser, and continues to show on second+ run when a user's | 760 // the account chooser, and continues to show on second+ run when a user's |
742 // wallet is incomplete. This also tests that submitting disables interactivity. | 761 // wallet is incomplete. This also tests that submitting disables interactivity. |
743 TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) { | 762 TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) { |
(...skipping 10 matching lines...) Expand all Loading... |
754 EXPECT_TRUE(notifications.front().interactive()); | 773 EXPECT_TRUE(notifications.front().interactive()); |
755 | 774 |
756 // Wallet notifications are mutually exclusive. | 775 // Wallet notifications are mutually exclusive. |
757 EXPECT_TRUE(NotificationsOfType( | 776 EXPECT_TRUE(NotificationsOfType( |
758 DialogNotification::WALLET_SIGNIN_PROMO).empty()); | 777 DialogNotification::WALLET_SIGNIN_PROMO).empty()); |
759 EXPECT_TRUE(NotificationsOfType( | 778 EXPECT_TRUE(NotificationsOfType( |
760 DialogNotification::EXPLANATORY_MESSAGE).empty()); | 779 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
761 | 780 |
762 // Using Autofill on second run, show an interactive, unchecked checkbox. | 781 // Using Autofill on second run, show an interactive, unchecked checkbox. |
763 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser(); | 782 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser(); |
764 account_model->ActivatedAt(AccountChooserModel::kAutofillItemId); | 783 ASSERT_TRUE(account_model); |
| 784 account_model->ActivatedAt(TestAccountChooserModel::kAutofillItemId); |
765 controller()->set_is_first_run(false); | 785 controller()->set_is_first_run(false); |
766 | 786 |
767 notifications = | 787 notifications = |
768 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); | 788 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); |
769 EXPECT_EQ(1U, notifications.size()); | 789 EXPECT_EQ(1U, notifications.size()); |
770 EXPECT_FALSE(notifications.front().checked()); | 790 EXPECT_FALSE(notifications.front().checked()); |
771 EXPECT_TRUE(notifications.front().interactive()); | 791 EXPECT_TRUE(notifications.front().interactive()); |
772 | 792 |
773 // Notifications shouldn't be interactive while submitting. | 793 // Notifications shouldn't be interactive while submitting. |
774 account_model->ActivatedAt(AccountChooserModel::kWalletItemId); | 794 account_model->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId); |
775 controller()->OnAccept(); | 795 controller()->OnAccept(); |
776 EXPECT_FALSE(NotificationsOfType( | 796 EXPECT_FALSE(NotificationsOfType( |
777 DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive()); | 797 DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive()); |
778 } | 798 } |
779 | 799 |
780 // Verifies that no Wallet notifications are shown after first run (i.e. no | 800 // Verifies that no Wallet notifications are shown after first run (i.e. no |
781 // "[X] Save details to wallet" or "These details are from your Wallet") when | 801 // "[X] Save details to wallet" or "These details are from your Wallet") when |
782 // the user has a complete wallet. | 802 // the user has a complete wallet. |
783 TEST_F(AutofillDialogControllerTest, NoWalletNotifications) { | 803 TEST_F(AutofillDialogControllerTest, NoWalletNotifications) { |
784 SetUpWallet(); | 804 SetUpWallet(); |
785 controller()->set_is_first_run(false); | 805 controller()->set_is_first_run(false); |
786 | 806 |
787 // Simulate a complete wallet. | 807 // Simulate a complete wallet. |
788 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 808 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
789 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 809 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
790 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 810 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
791 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 811 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
792 | 812 |
793 EXPECT_TRUE(NotificationsOfType( | 813 EXPECT_TRUE(NotificationsOfType( |
794 DialogNotification::EXPLANATORY_MESSAGE).empty()); | 814 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
795 EXPECT_TRUE(NotificationsOfType( | 815 EXPECT_TRUE(NotificationsOfType( |
796 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); | 816 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
797 } | 817 } |
798 | 818 |
799 } // namespace autofill | 819 } // namespace autofill |
OLD | NEW |