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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_models_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, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
7 #include "chrome/common/pref_names.h" 7 #include "chrome/common/pref_names.h"
8 #include "chrome/test/base/testing_profile.h" 8 #include "chrome/test/base/testing_profile.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace autofill { 12 namespace autofill {
13 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, HandlesSigninError) {
66 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
67
68 profile()->GetPrefs()->SetBoolean(
69 prefs::kAutofillDialogPayWithoutWallet, false);
70 EXPECT_TRUE(model()->WalletIsSelected());
71
72 model()->SetHadWalletSigninError();
73 EXPECT_FALSE(model()->WalletIsSelected());
74 EXPECT_TRUE(model()->IsCommandIdEnabled(0));
75 }
76
77 TEST_F(AccountChooserModelTest, RespectsUserChoice) {
78 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(3);
79
80 profile()->GetPrefs()->SetBoolean(
81 prefs::kAutofillDialogPayWithoutWallet, false);
82 EXPECT_TRUE(model()->WalletIsSelected());
83
84 model()->ExecuteCommand(1, 0);
85 EXPECT_FALSE(model()->WalletIsSelected());
86
87 model()->ExecuteCommand(0, 0);
88 EXPECT_TRUE(model()->WalletIsSelected());
89 }
90
91 } // namespace autofill 14 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698