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

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: Rebase after https://chromiumcodereview.appspot.com/13870019 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
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_models.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 5 #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 "components/autofill/browser/autofill_metrics.h"
10 #include "testing/gmock/include/gmock/gmock.h" 6 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
12 8
13 namespace autofill { 9 namespace autofill {
14 10
15 namespace {
16
17 class TestAccountChooserModel : public AccountChooserModel {
18 public:
19 TestAccountChooserModel(AccountChooserModelDelegate* delegate,
20 PrefService* prefs,
21 const AutofillMetrics& metric_logger)
22 : AccountChooserModel(delegate, prefs, metric_logger,
23 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {}
24 virtual ~TestAccountChooserModel() {}
25
26 private:
27 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel);
28 };
29
30 class MockAccountChooserModelDelegate : public AccountChooserModelDelegate {
31 public:
32 MockAccountChooserModelDelegate() {}
33 virtual ~MockAccountChooserModelDelegate() {}
34
35 MOCK_METHOD0(AccountChoiceChanged, void());
36 };
37
38 class AccountChooserModelTest : public testing::Test {
39 public:
40 AccountChooserModelTest()
41 : model_(&delegate_, profile_.GetPrefs(), metric_logger_) {}
42 virtual ~AccountChooserModelTest() {}
43
44 Profile* profile() { return &profile_; }
45 MockAccountChooserModelDelegate* delegate() { return &delegate_; }
46 TestAccountChooserModel* model() { return &model_; }
47 const AutofillMetrics& metric_logger() { return metric_logger_; }
48
49 private:
50 TestingProfile profile_;
51 MockAccountChooserModelDelegate delegate_;
52 TestAccountChooserModel model_;
53 AutofillMetrics metric_logger_;
54 };
55
56 } // namespace
57
58 TEST_F(AccountChooserModelTest, ObeysPref) {
59 // When "Pay without wallet" is false, use Wallet by default.
60 {
61 profile()->GetPrefs()->SetBoolean(
62 ::prefs::kAutofillDialogPayWithoutWallet, false);
63 TestAccountChooserModel model(delegate(), profile()->GetPrefs(),
64 metric_logger());
65 EXPECT_TRUE(model.WalletIsSelected());
66 }
67 // When the user chose to "Pay without wallet", use Autofill.
68 {
69 profile()->GetPrefs()->SetBoolean(
70 ::prefs::kAutofillDialogPayWithoutWallet, true);
71 TestAccountChooserModel model(delegate(), profile()->GetPrefs(),
72 metric_logger());
73 EXPECT_FALSE(model.WalletIsSelected());
74 }
75 }
76
77 TEST_F(AccountChooserModelTest, IgnoresPrefChanges) {
78 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
79 ::prefs::kAutofillDialogPayWithoutWallet));
80 EXPECT_TRUE(model()->WalletIsSelected());
81
82 // Check that nothing changes while this dialog is running if a pref changes
83 // (this could cause subtle bugs or annoyances if a user closes another
84 // running dialog).
85 profile()->GetPrefs()->SetBoolean(
86 ::prefs::kAutofillDialogPayWithoutWallet, true);
87 EXPECT_TRUE(model()->WalletIsSelected());
88 }
89
90 TEST_F(AccountChooserModelTest, HandlesError) {
91 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1);
92
93 ASSERT_TRUE(model()->WalletIsSelected());
94 ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId));
95
96 model()->SetHadWalletError();
97 EXPECT_FALSE(model()->WalletIsSelected());
98 EXPECT_FALSE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId));
99 }
100
101 TEST_F(AccountChooserModelTest, HandlesSigninError) {
102 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1);
103
104 ASSERT_TRUE(model()->WalletIsSelected());
105 ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId));
106
107 model()->SetHadWalletSigninError();
108 EXPECT_FALSE(model()->WalletIsSelected());
109 EXPECT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId));
110 }
111
112 TEST_F(AccountChooserModelTest, RespectsUserChoice) {
113 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2);
114
115 model()->ExecuteCommand(AccountChooserModel::kAutofillItemId, 0);
116 EXPECT_FALSE(model()->WalletIsSelected());
117
118 model()->ExecuteCommand(AccountChooserModel::kWalletItemId, 0);
119 EXPECT_TRUE(model()->WalletIsSelected());
120 }
121
122 } // namespace autofill 11 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_models.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698