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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc

Issue 12502004: autofill: Add tests for the account chooser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test on linux 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
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_models.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..9cd4b108549a5b378c4ed7760fcd921bc76c8093
--- /dev/null
+++ b/chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc
@@ -0,0 +1,79 @@
+// 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/autofill_dialog_models.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, RespectsUserChoice) {
+ EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(3);
+
+ profile()->GetPrefs()->SetBoolean(
+ prefs::kAutofillDialogPayWithoutWallet, false);
+ EXPECT_TRUE(model()->WalletIsSelected());
+
+ model()->ExecuteCommand(1);
+ EXPECT_FALSE(model()->WalletIsSelected());
+
+ model()->ExecuteCommand(0);
+ EXPECT_TRUE(model()->WalletIsSelected());
+}
+
+} // namespace autofill
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_models.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698