Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 13331007: Multi-account AccountChooser for interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 class TestAccountChooserModel : public AccountChooserModel {
146 public:
147 TestAccountChooserModel(AccountChooserModelDelegate* delegate,
148 PrefService* prefs)
149 : AccountChooserModel(delegate, prefs) {
150 }
151
152 using AccountChooserModel::kActiveWalletItemId;
153 using AccountChooserModel::kAutofillItemId;
154 };
155
145 class TestAutofillDialogController : public AutofillDialogControllerImpl { 156 class TestAutofillDialogController : public AutofillDialogControllerImpl {
146 public: 157 public:
147 TestAutofillDialogController( 158 TestAutofillDialogController(
148 content::WebContents* contents, 159 content::WebContents* contents,
149 const FormData& form_structure, 160 const FormData& form_structure,
150 const GURL& source_url, 161 const GURL& source_url,
151 const AutofillMetrics& metric_logger, 162 const AutofillMetrics& metric_logger,
152 const DialogType dialog_type, 163 const DialogType dialog_type,
153 const base::Callback<void(const FormStructure*, 164 const base::Callback<void(const FormStructure*,
154 const std::string&)>& callback) 165 const std::string&)>& callback)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 284
274 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { 285 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() {
275 base::DictionaryValue dict; 286 base::DictionaryValue dict;
276 scoped_ptr<base::ListValue> list(new base::ListValue()); 287 scoped_ptr<base::ListValue> list(new base::ListValue());
277 list->AppendString("verify_cvv"); 288 list->AppendString("verify_cvv");
278 dict.Set("required_action", list.release()); 289 dict.Set("required_action", list.release());
279 return wallet::FullWallet::CreateFullWallet(dict); 290 return wallet::FullWallet::CreateFullWallet(dict);
280 } 291 }
281 292
282 void SetUpWallet() { 293 void SetUpWallet() {
283 controller()->MenuModelForAccountChooser()->ActivatedAt(
284 AccountChooserModel::kWalletItemId);
285 controller()->OnUserNameFetchSuccess("user@example.com"); 294 controller()->OnUserNameFetchSuccess("user@example.com");
295 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser();
296 ASSERT_TRUE(account_model);
297 account_model->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId);
286 } 298 }
287 299
288 TestAutofillDialogController* controller() { return controller_; } 300 TestAutofillDialogController* controller() { return controller_; }
289 301
290 TestingProfile* profile() { return &profile_; } 302 TestingProfile* profile() { return &profile_; }
291 303
292 private: 304 private:
293 void FinishedCallback(const FormStructure* form_structure, 305 void FinishedCallback(const FormStructure* form_structure,
294 const std::string& google_transaction_id) {} 306 const std::string& google_transaction_id) {}
295 307
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 634 wallet_items->AddAddress(wallet::GetTestShippingAddress());
623 controller()->OnDidGetWalletItems(wallet_items.Pass()); 635 controller()->OnDidGetWalletItems(wallet_items.Pass());
624 controller()->OnAccept(); 636 controller()->OnAccept();
625 637
626 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 638 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
627 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 639 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
628 640
629 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); 641 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser();
630 ASSERT_TRUE(account_menu); 642 ASSERT_TRUE(account_menu);
631 ASSERT_GE(2, account_menu->GetItemCount()); 643 ASSERT_GE(2, account_menu->GetItemCount());
632 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); 644 account_menu->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId);
633 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); 645 account_menu->ActivatedAt(TestAccountChooserModel::kAutofillItemId);
634 646
635 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 647 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
636 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 648 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
637 } 649 }
638 650
639 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { 651 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) {
640 SetUpWallet(); 652 SetUpWallet();
641 653
642 EXPECT_CALL(*controller()->GetTestingWalletClient(), 654 EXPECT_CALL(*controller()->GetTestingWalletClient(),
643 GetFullWallet(_)).Times(1); 655 GetFullWallet(_)).Times(1);
(...skipping 27 matching lines...) Expand all
671 controller()->OnDidGetWalletItems(wallet_items.Pass()); 683 controller()->OnDidGetWalletItems(wallet_items.Pass());
672 controller()->OnAccept(); 684 controller()->OnAccept();
673 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); 685 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv());
674 686
675 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 687 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
676 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 688 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
677 689
678 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); 690 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser();
679 ASSERT_TRUE(account_menu); 691 ASSERT_TRUE(account_menu);
680 ASSERT_GE(2, account_menu->GetItemCount()); 692 ASSERT_GE(2, account_menu->GetItemCount());
681 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); 693 account_menu->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId);
682 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); 694 account_menu->ActivatedAt(TestAccountChooserModel::kAutofillItemId);
683 695
684 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 696 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
685 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 697 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
686 } 698 }
687 699
688 // Test that when a wallet error happens only an error is shown (and no other 700 // Test that when a wallet error happens only an error is shown (and no other
689 // Wallet-related notifications). 701 // Wallet-related notifications).
690 TEST_F(AutofillDialogControllerTest, WalletErrorNotification) { 702 TEST_F(AutofillDialogControllerTest, WalletErrorNotification) {
691 SetUpWallet(); 703 SetUpWallet();
692 704
(...skipping 25 matching lines...) Expand all
718 DialogNotification::EXPLANATORY_MESSAGE).size()); 730 DialogNotification::EXPLANATORY_MESSAGE).size());
719 731
720 // Wallet notifications are mutually exclusive. 732 // Wallet notifications are mutually exclusive.
721 EXPECT_TRUE(NotificationsOfType( 733 EXPECT_TRUE(NotificationsOfType(
722 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); 734 DialogNotification::WALLET_USAGE_CONFIRMATION).empty());
723 EXPECT_TRUE(NotificationsOfType( 735 EXPECT_TRUE(NotificationsOfType(
724 DialogNotification::WALLET_SIGNIN_PROMO).empty()); 736 DialogNotification::WALLET_SIGNIN_PROMO).empty());
725 737
726 // Switch to using Autofill, no explanatory message should show. 738 // Switch to using Autofill, no explanatory message should show.
727 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); 739 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser();
728 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); 740 ASSERT_TRUE(account_menu);
741 account_menu->ActivatedAt(TestAccountChooserModel::kAutofillItemId);
729 EXPECT_TRUE(NotificationsOfType( 742 EXPECT_TRUE(NotificationsOfType(
730 DialogNotification::EXPLANATORY_MESSAGE).empty()); 743 DialogNotification::EXPLANATORY_MESSAGE).empty());
731 744
732 // Switch to Wallet, pretend this isn't first run. No message should show. 745 // Switch to Wallet, pretend this isn't first run. No message should show.
733 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); 746 account_menu->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId);
734 controller()->set_is_first_run(false); 747 controller()->set_is_first_run(false);
735 EXPECT_TRUE(NotificationsOfType( 748 EXPECT_TRUE(NotificationsOfType(
736 DialogNotification::EXPLANATORY_MESSAGE).empty()); 749 DialogNotification::EXPLANATORY_MESSAGE).empty());
737 } 750 }
738 751
739 // Verifies that the "[X] Save details in wallet" notification shows on first 752 // 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 753 // 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 754 // 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. 755 // wallet is incomplete. This also tests that submitting disables interactivity.
743 TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) { 756 TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) {
(...skipping 10 matching lines...) Expand all
754 EXPECT_TRUE(notifications.front().interactive()); 767 EXPECT_TRUE(notifications.front().interactive());
755 768
756 // Wallet notifications are mutually exclusive. 769 // Wallet notifications are mutually exclusive.
757 EXPECT_TRUE(NotificationsOfType( 770 EXPECT_TRUE(NotificationsOfType(
758 DialogNotification::WALLET_SIGNIN_PROMO).empty()); 771 DialogNotification::WALLET_SIGNIN_PROMO).empty());
759 EXPECT_TRUE(NotificationsOfType( 772 EXPECT_TRUE(NotificationsOfType(
760 DialogNotification::EXPLANATORY_MESSAGE).empty()); 773 DialogNotification::EXPLANATORY_MESSAGE).empty());
761 774
762 // Using Autofill on second run, show an interactive, unchecked checkbox. 775 // Using Autofill on second run, show an interactive, unchecked checkbox.
763 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser(); 776 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser();
764 account_model->ActivatedAt(AccountChooserModel::kAutofillItemId); 777 ASSERT_TRUE(account_model);
778 account_model->ActivatedAt(TestAccountChooserModel::kAutofillItemId);
765 controller()->set_is_first_run(false); 779 controller()->set_is_first_run(false);
766 780
767 notifications = 781 notifications =
768 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); 782 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION);
769 EXPECT_EQ(1U, notifications.size()); 783 EXPECT_EQ(1U, notifications.size());
770 EXPECT_FALSE(notifications.front().checked()); 784 EXPECT_FALSE(notifications.front().checked());
771 EXPECT_TRUE(notifications.front().interactive()); 785 EXPECT_TRUE(notifications.front().interactive());
772 786
773 // Notifications shouldn't be interactive while submitting. 787 // Notifications shouldn't be interactive while submitting.
774 account_model->ActivatedAt(AccountChooserModel::kWalletItemId); 788 account_model->ActivatedAt(TestAccountChooserModel::kActiveWalletItemId);
775 controller()->OnAccept(); 789 controller()->OnAccept();
776 EXPECT_FALSE(NotificationsOfType( 790 EXPECT_FALSE(NotificationsOfType(
777 DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive()); 791 DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive());
778 } 792 }
779 793
780 // Verifies that no Wallet notifications are shown after first run (i.e. no 794 // 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 795 // "[X] Save details to wallet" or "These details are from your Wallet") when
782 // the user has a complete wallet. 796 // the user has a complete wallet.
783 TEST_F(AutofillDialogControllerTest, NoWalletNotifications) { 797 TEST_F(AutofillDialogControllerTest, NoWalletNotifications) {
784 SetUpWallet(); 798 SetUpWallet();
785 controller()->set_is_first_run(false); 799 controller()->set_is_first_run(false);
786 800
787 // Simulate a complete wallet. 801 // Simulate a complete wallet.
788 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 802 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
789 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 803 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
790 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 804 wallet_items->AddAddress(wallet::GetTestShippingAddress());
791 controller()->OnDidGetWalletItems(wallet_items.Pass()); 805 controller()->OnDidGetWalletItems(wallet_items.Pass());
792 806
793 EXPECT_TRUE(NotificationsOfType( 807 EXPECT_TRUE(NotificationsOfType(
794 DialogNotification::EXPLANATORY_MESSAGE).empty()); 808 DialogNotification::EXPLANATORY_MESSAGE).empty());
795 EXPECT_TRUE(NotificationsOfType( 809 EXPECT_TRUE(NotificationsOfType(
796 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); 810 DialogNotification::WALLET_USAGE_CONFIRMATION).empty());
797 } 811 }
798 812
799 } // namespace autofill 813 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698