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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
7 #include "chrome/common/pref_names.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace autofill {
13
14 namespace {
15
16 class MockAccountChooserModelDelegate : public AccountChooserModelDelegate {
17 public:
18 MockAccountChooserModelDelegate() {}
19 virtual ~MockAccountChooserModelDelegate() {}
20
21 MOCK_METHOD0(AccountChoiceChanged, void());
22 };
23
24 class AccountChooserModelTest : public testing::Test {
25 public:
26 AccountChooserModelTest() : model_(&delegate_, profile_.GetPrefs()) {}
27 virtual ~AccountChooserModelTest() {}
28
29 Profile* profile() { return &profile_; }
30 MockAccountChooserModelDelegate* delegate() { return &delegate_; }
31 AccountChooserModel* model() { return &model_; }
32
33 private:
34 TestingProfile profile_;
35 MockAccountChooserModelDelegate delegate_;
36 AccountChooserModel model_;
37 };
38
39 } // namespace
40
41 TEST_F(AccountChooserModelTest, ObeysPref) {
42 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
43
44 profile()->GetPrefs()->SetBoolean(
45 prefs::kAutofillDialogPayWithoutWallet, false);
46 EXPECT_TRUE(model()->WalletIsSelected());
47
48 profile()->GetPrefs()->SetBoolean(
49 prefs::kAutofillDialogPayWithoutWallet, true);
50 EXPECT_FALSE(model()->WalletIsSelected());
51 }
52
53 TEST_F(AccountChooserModelTest, HandlesError) {
54 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
55
56 profile()->GetPrefs()->SetBoolean(
57 prefs::kAutofillDialogPayWithoutWallet, false);
58 EXPECT_TRUE(model()->WalletIsSelected());
59
60 model()->SetHadWalletError();
61 EXPECT_FALSE(model()->WalletIsSelected());
62 EXPECT_FALSE(model()->IsCommandIdEnabled(0));
63 }
64
65 TEST_F(AccountChooserModelTest, RespectsUserChoice) {
66 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(3);
67
68 profile()->GetPrefs()->SetBoolean(
69 prefs::kAutofillDialogPayWithoutWallet, false);
70 EXPECT_TRUE(model()->WalletIsSelected());
71
72 model()->ExecuteCommand(1);
73 EXPECT_FALSE(model()->WalletIsSelected());
74
75 model()->ExecuteCommand(0);
76 EXPECT_TRUE(model()->WalletIsSelected());
77 }
78
79 } // namespace autofill
OLDNEW
« 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