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

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

Issue 13331007: Multi-account AccountChooser for interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase after https://chromiumcodereview.appspot.com/13870019 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/ui/autofill/account_chooser_model.h"
7 #include "chrome/common/pref_names.h" 8 #include "chrome/common/pref_names.h"
8 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
9 #include "components/autofill/browser/autofill_metrics.h" 10 #include "components/autofill/browser/autofill_metrics.h"
10 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace autofill { 14 namespace autofill {
14 15
15 namespace { 16 namespace {
16 17
17 class TestAccountChooserModel : public AccountChooserModel { 18 class TestAccountChooserModel : public AccountChooserModel {
18 public: 19 public:
19 TestAccountChooserModel(AccountChooserModelDelegate* delegate, 20 TestAccountChooserModel(AccountChooserModelDelegate* delegate,
20 PrefService* prefs, 21 PrefService* prefs,
21 const AutofillMetrics& metric_logger) 22 const AutofillMetrics& metric_logger)
22 : AccountChooserModel(delegate, prefs, metric_logger, 23 : AccountChooserModel(delegate, prefs, metric_logger,
23 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {} 24 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {}
24 virtual ~TestAccountChooserModel() {} 25 virtual ~TestAccountChooserModel() {}
25 26
27 using AccountChooserModel::kActiveWalletItemId;
28 using AccountChooserModel::kAutofillItemId;
29
26 private: 30 private:
27 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel); 31 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel);
28 }; 32 };
29 33
30 class MockAccountChooserModelDelegate : public AccountChooserModelDelegate { 34 class MockAccountChooserModelDelegate : public AccountChooserModelDelegate {
31 public: 35 public:
32 MockAccountChooserModelDelegate() {} 36 MockAccountChooserModelDelegate() {}
33 virtual ~MockAccountChooserModelDelegate() {} 37 virtual ~MockAccountChooserModelDelegate() {}
34 38
35 MOCK_METHOD0(AccountChoiceChanged, void()); 39 MOCK_METHOD0(AccountChoiceChanged, void());
40 MOCK_METHOD0(UpdateAccountChooserView, void());
36 }; 41 };
37 42
38 class AccountChooserModelTest : public testing::Test { 43 class AccountChooserModelTest : public testing::Test {
39 public: 44 public:
40 AccountChooserModelTest() 45 AccountChooserModelTest()
41 : model_(&delegate_, profile_.GetPrefs(), metric_logger_) {} 46 : model_(&delegate_, profile_.GetPrefs(), metric_logger_) {}
42 virtual ~AccountChooserModelTest() {} 47 virtual ~AccountChooserModelTest() {}
43 48
44 Profile* profile() { return &profile_; } 49 Profile* profile() { return &profile_; }
45 MockAccountChooserModelDelegate* delegate() { return &delegate_; } 50 MockAccountChooserModelDelegate* delegate() { return &delegate_; }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Check that nothing changes while this dialog is running if a pref changes 87 // Check that nothing changes while this dialog is running if a pref changes
83 // (this could cause subtle bugs or annoyances if a user closes another 88 // (this could cause subtle bugs or annoyances if a user closes another
84 // running dialog). 89 // running dialog).
85 profile()->GetPrefs()->SetBoolean( 90 profile()->GetPrefs()->SetBoolean(
86 ::prefs::kAutofillDialogPayWithoutWallet, true); 91 ::prefs::kAutofillDialogPayWithoutWallet, true);
87 EXPECT_TRUE(model()->WalletIsSelected()); 92 EXPECT_TRUE(model()->WalletIsSelected());
88 } 93 }
89 94
90 TEST_F(AccountChooserModelTest, HandlesError) { 95 TEST_F(AccountChooserModelTest, HandlesError) {
91 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1); 96 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1);
97 EXPECT_CALL(*delegate(), UpdateAccountChooserView()).Times(1);
92 98
93 ASSERT_TRUE(model()->WalletIsSelected()); 99 ASSERT_TRUE(model()->WalletIsSelected());
94 ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); 100 ASSERT_TRUE(model()->IsCommandIdEnabled(
101 TestAccountChooserModel::kActiveWalletItemId));
95 102
96 model()->SetHadWalletError(); 103 model()->SetHadWalletError();
97 EXPECT_FALSE(model()->WalletIsSelected()); 104 EXPECT_FALSE(model()->WalletIsSelected());
98 EXPECT_FALSE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); 105 EXPECT_FALSE(model()->IsCommandIdEnabled(
106 TestAccountChooserModel::kActiveWalletItemId));
99 } 107 }
100 108
101 TEST_F(AccountChooserModelTest, HandlesSigninError) { 109 TEST_F(AccountChooserModelTest, HandlesSigninError) {
102 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1); 110 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1);
111 EXPECT_CALL(*delegate(), UpdateAccountChooserView()).Times(2);
103 112
113 // 0. "Unknown" wallet account, we don't know if the user is signed-in yet.
104 ASSERT_TRUE(model()->WalletIsSelected()); 114 ASSERT_TRUE(model()->WalletIsSelected());
105 ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); 115 ASSERT_TRUE(model()->IsCommandIdEnabled(
116 TestAccountChooserModel::kActiveWalletItemId));
117 ASSERT_TRUE(model()->IsActiveWalletAccountSelected());
118 ASSERT_FALSE(model()->HasAccountsToChoose());
119 ASSERT_EQ(2, model()->GetItemCount());
120 EXPECT_EQ(string16(), model()->active_wallet_account_name());
106 121
122 // 1. "Known" wallet account (e.g. after active/passive/automatic sign-in).
123 // Calls UpdateAccountChooserView.
124 const string16 kAccount1 = ASCIIToUTF16("john.doe@gmail.com");
125 model()->SetActiveWalletAccountName(kAccount1);
126 ASSERT_TRUE(model()->WalletIsSelected());
127 ASSERT_TRUE(model()->IsCommandIdEnabled(
128 TestAccountChooserModel::kActiveWalletItemId));
129 ASSERT_TRUE(model()->IsActiveWalletAccountSelected());
130 ASSERT_TRUE(model()->HasAccountsToChoose());
131 EXPECT_EQ(2, model()->GetItemCount());
132 EXPECT_EQ(kAccount1, model()->active_wallet_account_name());
133
134 // 2. Sign-in failure.
135 // Autofill data should be selected and be the only valid choice.
136 // Calls UpdateAccountChooserView.
137 // Calls AccountChoiceChanged.
107 model()->SetHadWalletSigninError(); 138 model()->SetHadWalletSigninError();
108 EXPECT_FALSE(model()->WalletIsSelected()); 139 EXPECT_FALSE(model()->WalletIsSelected());
109 EXPECT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); 140 EXPECT_TRUE(model()->IsCommandIdEnabled(
141 TestAccountChooserModel::kActiveWalletItemId));
142 EXPECT_FALSE(model()->IsActiveWalletAccountSelected());
143 EXPECT_FALSE(model()->HasAccountsToChoose());
144 EXPECT_EQ(1, model()->GetItemCount());
145 EXPECT_EQ(string16(), model()->active_wallet_account_name());
110 } 146 }
111 147
112 TEST_F(AccountChooserModelTest, RespectsUserChoice) { 148 TEST_F(AccountChooserModelTest, RespectsUserChoice) {
113 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2); 149 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
114 150
115 model()->ExecuteCommand(AccountChooserModel::kAutofillItemId, 0); 151 model()->ExecuteCommand(TestAccountChooserModel::kAutofillItemId, 0);
116 EXPECT_FALSE(model()->WalletIsSelected()); 152 EXPECT_FALSE(model()->WalletIsSelected());
117 153
118 model()->ExecuteCommand(AccountChooserModel::kWalletItemId, 0); 154 model()->ExecuteCommand(TestAccountChooserModel::kActiveWalletItemId, 0);
119 EXPECT_TRUE(model()->WalletIsSelected()); 155 EXPECT_TRUE(model()->WalletIsSelected());
120 } 156 }
121 157
122 } // namespace autofill 158 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/account_chooser_model.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698