Index: chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc |
diff --git a/chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc |
index f361db1208e5ee88e758b269ae7d03ea54de034a..e84f859f75affaa33aa11eff7b9cef562346a0d6 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc |
@@ -19,6 +19,7 @@ class MockAccountChooserModelDelegate : public AccountChooserModelDelegate { |
virtual ~MockAccountChooserModelDelegate() {} |
MOCK_METHOD0(AccountChoiceChanged, void()); |
+ MOCK_METHOD0(UpdateAccountChooserView, void()); |
}; |
class AccountChooserModelTest : public testing::Test { |
@@ -88,4 +89,71 @@ TEST_F(AccountChooserModelTest, RespectsUserChoice) { |
EXPECT_TRUE(model()->WalletIsSelected()); |
} |
+TEST_F(AccountChooserModelTest, HandlesMultipleAccounts) { |
+ EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(7); |
+ |
+ // 1. Initial state -- autofill data only. |
+ profile()->GetPrefs()->SetBoolean( |
+ prefs::kAutofillDialogPayWithoutWallet, true); |
+ EXPECT_FALSE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_FALSE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(1, model()->GetItemCount()); |
+ |
+ const std::string kAccount1 = "john.doe@gmail.com"; |
+ const std::string kAccount2 = "john.android@gmail.com"; |
+ |
+ // 2. Sign-in to the content area. |
+ model()->ForceWalletAccountSelected(); |
+ model()->SetCurrentlySignedInAccount(kAccount1); |
+ EXPECT_TRUE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_TRUE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(2, model()->GetItemCount()); |
+ EXPECT_EQ(kAccount1, model()->GetCurrentlySignedInAccount()); |
+ |
+ // 3. Some sort of sign-in error happened. |
+ model()->SetHadWalletSigninError(); |
+ EXPECT_FALSE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_FALSE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(1, model()->GetItemCount()); |
+ |
+ // An unrelated available accounts change. |
+ // Note that it does NOT send AccountChoiceChanged. |
+ std::vector<std::string> accounts; |
+ accounts.push_back(kAccount2); |
+ model()->SetAvailableAccounts(accounts); |
+ EXPECT_FALSE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_TRUE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(2, model()->GetItemCount()); |
+ |
+ // 4. Sign-in with the new account. |
+ model()->ForceWalletAccountSelected(); |
+ model()->SetCurrentlySignedInAccount(kAccount2); |
+ EXPECT_TRUE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_TRUE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(2, model()->GetItemCount()); |
+ EXPECT_EQ(kAccount2, model()->GetCurrentlySignedInAccount()); |
+ |
+ // 5. Switch to the autofill. |
+ model()->ExecuteCommand(1, 0); |
+ EXPECT_TRUE(model()->HasAccountsToChoose()); |
+ EXPECT_FALSE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_TRUE(model()->IsCommandIdEnabled(0)); // accounts are available. |
+ EXPECT_TRUE(model()->IsCommandIdEnabled(2)); // accounts are available. |
+ |
+ // 6. Sign-in with an old account. |
+ model()->ForceWalletAccountSelected(); |
+ model()->SetCurrentlySignedInAccount(kAccount1); |
+ EXPECT_TRUE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_TRUE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(3, model()->GetItemCount()); |
+ EXPECT_EQ(kAccount1, model()->GetCurrentlySignedInAccount()); |
+ |
+ // 7. Some wallet error. |
+ model()->SetHadWalletError(); |
+ EXPECT_FALSE(model()->IsCurrentlySignedInAccountSelected()); |
+ EXPECT_FALSE(model()->HasAccountsToChoose()); |
+ EXPECT_EQ(2, model()->GetItemCount()); |
+ EXPECT_FALSE(model()->IsCommandIdEnabled(2)); // no available accounts. |
+} |
+ |
} // namespace autofill |