Index: chrome/browser/ui/autofill/account_chooser_model_unittest.cc |
diff --git a/chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc b/chrome/browser/ui/autofill/account_chooser_model_unittest.cc |
similarity index 53% |
copy from chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc |
copy to chrome/browser/ui/autofill/account_chooser_model_unittest.cc |
index 726fd52e47cfd077ef7c22ae05fda884ff31f41b..0ace0416dc69cceb2496605dd5905baeaa37d7da 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc |
+++ b/chrome/browser/ui/autofill/account_chooser_model_unittest.cc |
@@ -3,7 +3,8 @@ |
// found in the LICENSE file. |
#include "base/prefs/pref_service.h" |
-#include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
+#include "base/utf_string_conversions.h" |
+#include "chrome/browser/ui/autofill/account_chooser_model.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/testing_profile.h" |
#include "testing/gmock/include/gmock/gmock.h" |
@@ -19,8 +20,22 @@ class MockAccountChooserModelDelegate : public AccountChooserModelDelegate { |
virtual ~MockAccountChooserModelDelegate() {} |
MOCK_METHOD0(AccountChoiceChanged, void()); |
+ MOCK_METHOD0(UpdateAccountChooserView, void()); |
}; |
+class TestAccountChooserModel : public AccountChooserModel { |
+public: |
+ TestAccountChooserModel(AccountChooserModelDelegate* delegate, |
+ PrefService* prefs) |
+ : AccountChooserModel(delegate, prefs) { |
+ } |
+ |
+ using AccountChooserModel::kActiveWalletItemId; |
+ using AccountChooserModel::kAutofillItemId; |
+}; |
+ |
+} // namespace |
+ |
class AccountChooserModelTest : public testing::Test { |
public: |
AccountChooserModelTest() : model_(&delegate_, profile_.GetPrefs()) {} |
@@ -28,16 +43,14 @@ class AccountChooserModelTest : public testing::Test { |
Profile* profile() { return &profile_; } |
MockAccountChooserModelDelegate* delegate() { return &delegate_; } |
- AccountChooserModel* model() { return &model_; } |
+ TestAccountChooserModel* model() { return &model_; } |
private: |
TestingProfile profile_; |
MockAccountChooserModelDelegate delegate_; |
- AccountChooserModel model_; |
+ TestAccountChooserModel model_; |
}; |
-} // namespace |
- |
TEST_F(AccountChooserModelTest, ObeysPref) { |
// When "Pay without wallet" is false, use Wallet by default. |
{ |
@@ -70,33 +83,64 @@ TEST_F(AccountChooserModelTest, IgnoresPrefChanges) { |
TEST_F(AccountChooserModelTest, HandlesError) { |
EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1); |
+ EXPECT_CALL(*delegate(), UpdateAccountChooserView()).Times(1); |
ASSERT_TRUE(model()->WalletIsSelected()); |
- ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
+ ASSERT_TRUE(model()->IsCommandIdEnabled( |
+ TestAccountChooserModel::kActiveWalletItemId)); |
model()->SetHadWalletError(); |
EXPECT_FALSE(model()->WalletIsSelected()); |
- EXPECT_FALSE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
+ EXPECT_FALSE(model()->IsCommandIdEnabled( |
+ TestAccountChooserModel::kActiveWalletItemId)); |
} |
TEST_F(AccountChooserModelTest, HandlesSigninError) { |
EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1); |
+ EXPECT_CALL(*delegate(), UpdateAccountChooserView()).Times(2); |
+ // 0. "Unknown" wallet account, we don't know if the user is signed-in yet. |
ASSERT_TRUE(model()->WalletIsSelected()); |
- ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
- |
+ ASSERT_TRUE(model()->IsCommandIdEnabled( |
+ TestAccountChooserModel::kActiveWalletItemId)); |
+ ASSERT_TRUE(model()->IsActiveWalletAccountSelected()); |
+ ASSERT_FALSE(model()->HasAccountsToChoose()); |
+ ASSERT_EQ(2, model()->GetItemCount()); |
+ EXPECT_EQ(string16(), model()->active_wallet_account_name()); |
+ |
+ // 1. "Known" wallet account (e.g. after active/passive/automatic sign-in). |
+ // Calls UpdateAccountChooserView. |
+ const string16 kAccount1 = ASCIIToUTF16("john.doe@gmail.com"); |
+ model()->SetActiveWalletAccountName(kAccount1); |
+ ASSERT_TRUE(model()->WalletIsSelected()); |
+ ASSERT_TRUE(model()->IsCommandIdEnabled( |
+ TestAccountChooserModel::kActiveWalletItemId)); |
+ ASSERT_TRUE(model()->IsActiveWalletAccountSelected()); |
+ ASSERT_TRUE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(2, model()->GetItemCount()); |
+ EXPECT_EQ(kAccount1, model()->active_wallet_account_name()); |
+ |
+ // 2. Sign-in failure. |
+ // Autofill data should be selected and be the only valid choice. |
+ // Calls UpdateAccountChooserView. |
+ // Calls AccountChoiceChanged. |
model()->SetHadWalletSigninError(); |
EXPECT_FALSE(model()->WalletIsSelected()); |
- EXPECT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
+ EXPECT_TRUE(model()->IsCommandIdEnabled( |
+ TestAccountChooserModel::kActiveWalletItemId)); |
+ EXPECT_FALSE(model()->IsActiveWalletAccountSelected()); |
+ EXPECT_FALSE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(1, model()->GetItemCount()); |
+ EXPECT_EQ(string16(), model()->active_wallet_account_name()); |
} |
TEST_F(AccountChooserModelTest, RespectsUserChoice) { |
EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2); |
- model()->ExecuteCommand(AccountChooserModel::kAutofillItemId, 0); |
+ model()->ExecuteCommand(TestAccountChooserModel::kAutofillItemId, 0); |
EXPECT_FALSE(model()->WalletIsSelected()); |
- model()->ExecuteCommand(AccountChooserModel::kWalletItemId, 0); |
+ model()->ExecuteCommand(TestAccountChooserModel::kActiveWalletItemId, 0); |
EXPECT_TRUE(model()->WalletIsSelected()); |
} |