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

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: 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 273
274 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { 274 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() {
275 base::DictionaryValue dict; 275 base::DictionaryValue dict;
276 scoped_ptr<base::ListValue> list(new base::ListValue()); 276 scoped_ptr<base::ListValue> list(new base::ListValue());
277 list->AppendString("verify_cvv"); 277 list->AppendString("verify_cvv");
278 dict.Set("required_action", list.release()); 278 dict.Set("required_action", list.release());
279 return wallet::FullWallet::CreateFullWallet(dict); 279 return wallet::FullWallet::CreateFullWallet(dict);
280 } 280 }
281 281
282 void SetUpWallet() { 282 void SetUpWallet() {
283 controller()->MenuModelForAccountChooser()->ActivatedAt(
284 AccountChooserModel::kWalletItemId);
285 controller()->OnUserNameFetchSuccess("user@example.com"); 283 controller()->OnUserNameFetchSuccess("user@example.com");
284 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser();
285 ASSERT_TRUE(account_model);
286 account_model->ActivatedAt(AccountChooserModel::kActiveWalletItemId);
286 } 287 }
287 288
288 TestAutofillDialogController* controller() { return controller_; } 289 TestAutofillDialogController* controller() { return controller_; }
289 290
290 TestingProfile* profile() { return &profile_; } 291 TestingProfile* profile() { return &profile_; }
291 292
292 private: 293 private:
293 void FinishedCallback(const FormStructure* form_structure, 294 void FinishedCallback(const FormStructure* form_structure,
294 const std::string& google_transaction_id) {} 295 const std::string& google_transaction_id) {}
295 296
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 623 wallet_items->AddAddress(wallet::GetTestShippingAddress());
623 controller()->OnDidGetWalletItems(wallet_items.Pass()); 624 controller()->OnDidGetWalletItems(wallet_items.Pass());
624 controller()->OnAccept(); 625 controller()->OnAccept();
625 626
626 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 627 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
627 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 628 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
628 629
629 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); 630 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser();
630 ASSERT_TRUE(account_menu); 631 ASSERT_TRUE(account_menu);
631 ASSERT_GE(2, account_menu->GetItemCount()); 632 ASSERT_GE(2, account_menu->GetItemCount());
632 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); 633 account_menu->ActivatedAt(AccountChooserModel::kActiveWalletItemId);
633 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); 634 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId);
634 635
635 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 636 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
636 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 637 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
637 } 638 }
638 639
639 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { 640 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) {
640 SetUpWallet(); 641 SetUpWallet();
641 642
642 EXPECT_CALL(*controller()->GetTestingWalletClient(), 643 EXPECT_CALL(*controller()->GetTestingWalletClient(),
(...skipping 28 matching lines...) Expand all
671 controller()->OnDidGetWalletItems(wallet_items.Pass()); 672 controller()->OnDidGetWalletItems(wallet_items.Pass());
672 controller()->OnAccept(); 673 controller()->OnAccept();
673 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); 674 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv());
674 675
675 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 676 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
676 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 677 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
677 678
678 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); 679 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser();
679 ASSERT_TRUE(account_menu); 680 ASSERT_TRUE(account_menu);
680 ASSERT_GE(2, account_menu->GetItemCount()); 681 ASSERT_GE(2, account_menu->GetItemCount());
681 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); 682 account_menu->ActivatedAt(AccountChooserModel::kActiveWalletItemId);
682 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); 683 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId);
683 684
684 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 685 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
685 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 686 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
686 } 687 }
687 688
688 // Test that when a wallet error happens only an error is shown (and no other 689 // Test that when a wallet error happens only an error is shown (and no other
689 // Wallet-related notifications). 690 // Wallet-related notifications).
690 TEST_F(AutofillDialogControllerTest, WalletErrorNotification) { 691 TEST_F(AutofillDialogControllerTest, WalletErrorNotification) {
691 SetUpWallet(); 692 SetUpWallet();
(...skipping 26 matching lines...) Expand all
718 DialogNotification::EXPLANATORY_MESSAGE).size()); 719 DialogNotification::EXPLANATORY_MESSAGE).size());
719 720
720 // Wallet notifications are mutually exclusive. 721 // Wallet notifications are mutually exclusive.
721 EXPECT_TRUE(NotificationsOfType( 722 EXPECT_TRUE(NotificationsOfType(
722 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); 723 DialogNotification::WALLET_USAGE_CONFIRMATION).empty());
723 EXPECT_TRUE(NotificationsOfType( 724 EXPECT_TRUE(NotificationsOfType(
724 DialogNotification::WALLET_SIGNIN_PROMO).empty()); 725 DialogNotification::WALLET_SIGNIN_PROMO).empty());
725 726
726 // Switch to using Autofill, no explanatory message should show. 727 // Switch to using Autofill, no explanatory message should show.
727 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); 728 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser();
729 ASSERT_TRUE(account_menu);
728 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); 730 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId);
729 EXPECT_TRUE(NotificationsOfType( 731 EXPECT_TRUE(NotificationsOfType(
730 DialogNotification::EXPLANATORY_MESSAGE).empty()); 732 DialogNotification::EXPLANATORY_MESSAGE).empty());
731 733
732 // Switch to Wallet, pretend this isn't first run. No message should show. 734 // Switch to Wallet, pretend this isn't first run. No message should show.
733 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); 735 account_menu->ActivatedAt(AccountChooserModel::kActiveWalletItemId);
734 controller()->set_is_first_run(false); 736 controller()->set_is_first_run(false);
735 EXPECT_TRUE(NotificationsOfType( 737 EXPECT_TRUE(NotificationsOfType(
736 DialogNotification::EXPLANATORY_MESSAGE).empty()); 738 DialogNotification::EXPLANATORY_MESSAGE).empty());
737 } 739 }
738 740
739 // Verifies that the "[X] Save details in wallet" notification shows on first 741 // 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 742 // 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 743 // 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. 744 // wallet is incomplete. This also tests that submitting disables interactivity.
743 TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) { 745 TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) {
(...skipping 10 matching lines...) Expand all
754 EXPECT_TRUE(notifications.front().interactive()); 756 EXPECT_TRUE(notifications.front().interactive());
755 757
756 // Wallet notifications are mutually exclusive. 758 // Wallet notifications are mutually exclusive.
757 EXPECT_TRUE(NotificationsOfType( 759 EXPECT_TRUE(NotificationsOfType(
758 DialogNotification::WALLET_SIGNIN_PROMO).empty()); 760 DialogNotification::WALLET_SIGNIN_PROMO).empty());
759 EXPECT_TRUE(NotificationsOfType( 761 EXPECT_TRUE(NotificationsOfType(
760 DialogNotification::EXPLANATORY_MESSAGE).empty()); 762 DialogNotification::EXPLANATORY_MESSAGE).empty());
761 763
762 // Using Autofill on second run, show an interactive, unchecked checkbox. 764 // Using Autofill on second run, show an interactive, unchecked checkbox.
763 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser(); 765 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser();
766 ASSERT_TRUE(account_model);
764 account_model->ActivatedAt(AccountChooserModel::kAutofillItemId); 767 account_model->ActivatedAt(AccountChooserModel::kAutofillItemId);
765 controller()->set_is_first_run(false); 768 controller()->set_is_first_run(false);
766 769
767 notifications = 770 notifications =
768 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); 771 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION);
769 EXPECT_EQ(1U, notifications.size()); 772 EXPECT_EQ(1U, notifications.size());
770 EXPECT_FALSE(notifications.front().checked()); 773 EXPECT_FALSE(notifications.front().checked());
771 EXPECT_TRUE(notifications.front().interactive()); 774 EXPECT_TRUE(notifications.front().interactive());
772 775
773 // Notifications shouldn't be interactive while submitting. 776 // Notifications shouldn't be interactive while submitting.
774 account_model->ActivatedAt(AccountChooserModel::kWalletItemId); 777 account_model->ActivatedAt(AccountChooserModel::kActiveWalletItemId);
775 controller()->OnAccept(); 778 controller()->OnAccept();
776 EXPECT_FALSE(NotificationsOfType( 779 EXPECT_FALSE(NotificationsOfType(
777 DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive()); 780 DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive());
778 } 781 }
779 782
780 // Verifies that no Wallet notifications are shown after first run (i.e. no 783 // 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 784 // "[X] Save details to wallet" or "These details are from your Wallet") when
782 // the user has a complete wallet. 785 // the user has a complete wallet.
783 TEST_F(AutofillDialogControllerTest, NoWalletNotifications) { 786 TEST_F(AutofillDialogControllerTest, NoWalletNotifications) {
784 SetUpWallet(); 787 SetUpWallet();
785 controller()->set_is_first_run(false); 788 controller()->set_is_first_run(false);
786 789
787 // Simulate a complete wallet. 790 // Simulate a complete wallet.
788 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 791 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
789 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 792 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
790 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 793 wallet_items->AddAddress(wallet::GetTestShippingAddress());
791 controller()->OnDidGetWalletItems(wallet_items.Pass()); 794 controller()->OnDidGetWalletItems(wallet_items.Pass());
792 795
793 EXPECT_TRUE(NotificationsOfType( 796 EXPECT_TRUE(NotificationsOfType(
794 DialogNotification::EXPLANATORY_MESSAGE).empty()); 797 DialogNotification::EXPLANATORY_MESSAGE).empty());
795 EXPECT_TRUE(NotificationsOfType( 798 EXPECT_TRUE(NotificationsOfType(
796 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); 799 DialogNotification::WALLET_USAGE_CONFIRMATION).empty());
797 } 800 }
798 801
799 } // namespace autofill 802 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698