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

Unified 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: Indent fix. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/account_chooser_model_unittest.cc
diff --git a/chrome/browser/ui/autofill/account_chooser_model_unittest.cc b/chrome/browser/ui/autofill/account_chooser_model_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..df4606cab7f78e6ee982f9b8e5acbb2dfaf1d069
--- /dev/null
+++ b/chrome/browser/ui/autofill/account_chooser_model_unittest.cc
@@ -0,0 +1,158 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/prefs/pref_service.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"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+namespace {
+
+class MockAccountChooserModelDelegate : public AccountChooserModelDelegate {
+ public:
+ MockAccountChooserModelDelegate() {}
+ virtual ~MockAccountChooserModelDelegate() {}
+
+ MOCK_METHOD0(AccountChoiceChanged, void());
+};
+
+class AccountChooserModelTest : public testing::Test {
+ public:
+ AccountChooserModelTest() : model_(&delegate_, profile_.GetPrefs()) {}
+ virtual ~AccountChooserModelTest() {}
+
+ Profile* profile() { return &profile_; }
+ MockAccountChooserModelDelegate* delegate() { return &delegate_; }
+ AccountChooserModel* model() { return &model_; }
+
+ private:
+ TestingProfile profile_;
+ MockAccountChooserModelDelegate delegate_;
+ AccountChooserModel model_;
+};
+
+} // namespace
+
+TEST_F(AccountChooserModelTest, ObeysPref) {
+ EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
+
+ profile()->GetPrefs()->SetBoolean(
+ prefs::kAutofillDialogPayWithoutWallet, false);
+ EXPECT_TRUE(model()->WalletIsSelected());
+
+ profile()->GetPrefs()->SetBoolean(
+ prefs::kAutofillDialogPayWithoutWallet, true);
+ EXPECT_FALSE(model()->WalletIsSelected());
+}
+
+TEST_F(AccountChooserModelTest, HandlesError) {
+ EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
+
+ profile()->GetPrefs()->SetBoolean(
+ prefs::kAutofillDialogPayWithoutWallet, false);
+ EXPECT_TRUE(model()->WalletIsSelected());
+
+ model()->SetHadWalletError();
+ EXPECT_FALSE(model()->WalletIsSelected());
+ EXPECT_FALSE(model()->IsCommandIdEnabled(0));
+}
+
+TEST_F(AccountChooserModelTest, HandlesSigninError) {
+ EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
+
+ profile()->GetPrefs()->SetBoolean(
+ prefs::kAutofillDialogPayWithoutWallet, false);
+ EXPECT_TRUE(model()->WalletIsSelected());
+
+ model()->SetHadWalletSigninError();
+ EXPECT_FALSE(model()->WalletIsSelected());
+ EXPECT_TRUE(model()->IsCommandIdEnabled(0));
+}
+
+TEST_F(AccountChooserModelTest, RespectsUserChoice) {
+ EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(3);
+
+ profile()->GetPrefs()->SetBoolean(
+ prefs::kAutofillDialogPayWithoutWallet, false);
+ EXPECT_TRUE(model()->WalletIsSelected());
+
+ model()->ExecuteCommand(1, 0);
+ EXPECT_FALSE(model()->WalletIsSelected());
+
+ model()->ExecuteCommand(0, 0);
+ 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()->ForceSelectWalletAccount();
+ 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()->ForceSelectWalletAccount();
+ 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()->ForceSelectWalletAccount();
+ 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

Powered by Google App Engine
This is Rietveld 408576698