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

Side by Side Diff: components/autofill/core/browser/options_util_unittest.cc

Issue 1138373002: Autofill: Fix WalletIntegrationAvailable() regression. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pay_07_check_wallet_available_03
Patch Set: Add missing dep for GN build. Created 5 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2015 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_registry_simple.h"
6 #include "base/prefs/testing_pref_service.h"
7 #include "components/autofill/core/browser/autofill_test_utils.h"
8 #include "components/autofill/core/browser/options_util.h"
9 #include "components/autofill/core/browser/test_personal_data_manager.h"
10 #include "components/autofill/core/common/autofill_pref_names.h"
11 #include "components/sync_driver/data_type_manager.h"
12 #include "components/sync_driver/sync_service.h"
13 #include "google_apis/gaia/google_service_auth_error.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15
16 using testing::Return;
17
18 namespace autofill {
19
20 namespace {
21
22 class SyncServiceMock : public sync_driver::SyncService {
23 public:
24 MOCK_CONST_METHOD0(HasSyncSetupCompleted, bool());
25 MOCK_CONST_METHOD0(SyncActive, bool());
26 MOCK_CONST_METHOD0(GetActiveDataTypes, syncer::ModelTypeSet());
27 MOCK_METHOD1(AddObserver, void(sync_driver::SyncServiceObserver*));
28 MOCK_METHOD1(RemoveObserver, void(sync_driver::SyncServiceObserver*));
29 MOCK_CONST_METHOD1(HasObserver,
30 bool(const sync_driver::SyncServiceObserver*));
31 MOCK_METHOD0(IsSyncEnabledAndLoggedIn, bool());
32 MOCK_METHOD0(DisableForUser, void());
33 MOCK_METHOD0(StopAndSuppress, void());
34 MOCK_METHOD0(UnsuppressAndStart, void());
35 MOCK_CONST_METHOD0(GetPreferredDataTypes, syncer::ModelTypeSet());
36 MOCK_METHOD2(OnUserChoseDatatypes,
37 void(bool sync_everything, syncer::ModelTypeSet chosen_types));
38 MOCK_METHOD0(SetSyncSetupCompleted, void());
39 MOCK_CONST_METHOD0(FirstSetupInProgress, bool());
40 MOCK_METHOD1(SetSetupInProgress, void(bool));
41 MOCK_CONST_METHOD0(setup_in_progress, bool());
42 MOCK_CONST_METHOD0(ConfigurationDone, bool());
43 MOCK_CONST_METHOD0(GetAuthError, const GoogleServiceAuthError&());
44 MOCK_CONST_METHOD0(HasUnrecoverableError, bool());
45 MOCK_CONST_METHOD0(backend_initialized, bool());
46 MOCK_CONST_METHOD0(IsPassphraseRequiredForDecryption, bool());
47 MOCK_CONST_METHOD0(GetExplicitPassphraseTime, base::Time());
48 MOCK_CONST_METHOD0(IsUsingSecondaryPassphrase, bool());
49 MOCK_METHOD0(EnableEncryptEverything, void());
50 MOCK_METHOD2(SetEncryptionPassphrase,
51 void(const std::string& passphrase, PassphraseType type));
52 MOCK_METHOD1(SetDecryptionPassphrase, bool(const std::string& passphrase));
53
54 // DataTypeEncryptionHandler mocks.
55 MOCK_CONST_METHOD0(IsPassphraseRequired, bool());
56 MOCK_CONST_METHOD0(GetEncryptedDataTypes, syncer::ModelTypeSet());
57 };
58
59 scoped_ptr<SyncServiceMock> CreateSyncService(bool has_autofill_profile,
60 bool has_autofill_wallet_data,
61 bool is_enabled_and_logged_in) {
62 scoped_ptr<SyncServiceMock> sync(new SyncServiceMock());
63
64 syncer::ModelTypeSet type_set;
65 if (has_autofill_profile)
66 type_set.Put(syncer::AUTOFILL_PROFILE);
67 if (has_autofill_wallet_data)
68 type_set.Put(syncer::AUTOFILL_WALLET_DATA);
69 ON_CALL(*sync, GetActiveDataTypes()).WillByDefault(Return(type_set));
70 ON_CALL(*sync, GetPreferredDataTypes()).WillByDefault(Return(type_set));
71
72 ON_CALL(*sync, IsSyncEnabledAndLoggedIn())
73 .WillByDefault(Return(is_enabled_and_logged_in));
74
75 return sync;
76 }
77
78 scoped_ptr<TestingPrefServiceSimple> CreatePrefService(
79 bool autofill_enabled,
80 bool autofill_wallet_import_enabled,
81 bool autofill_wallet_sync_experiment_enabled) {
82 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple());
83 prefs->registry()->RegisterBooleanPref(prefs::kAutofillEnabled,
84 autofill_enabled);
85 prefs->registry()->RegisterBooleanPref(prefs::kAutofillWalletImportEnabled,
86 autofill_wallet_import_enabled);
87 prefs->registry()->RegisterBooleanPref(
88 prefs::kAutofillWalletSyncExperimentEnabled,
89 autofill_wallet_sync_experiment_enabled);
90
91 return prefs;
92 }
93
94 scoped_ptr<TestPersonalDataManager> CreatePersonalDataManager(
95 PrefService* prefs,
96 bool has_server_data) {
97 scoped_ptr<TestPersonalDataManager> pdm(new TestPersonalDataManager());
98 pdm->SetTestingPrefService(prefs);
99 if (has_server_data) {
100 // This will cause pdm->HasServerData() to return true.
101 pdm->AddTestingServerCreditCard(test::GetVerifiedCreditCard());
102 }
103
104 return pdm;
105 }
106
107 } // namespace
108
109 // Verify that true is returned when all inputs are complete.
110 TEST(WalletIntegrationAvailableTest, AllInputsComplete) {
111 scoped_ptr<SyncServiceMock> sync = CreateSyncService(true, true, true);
112 scoped_ptr<TestingPrefServiceSimple> prefs =
113 CreatePrefService(true, true, true);
114 scoped_ptr<TestPersonalDataManager> pdm =
115 CreatePersonalDataManager(prefs.get(), true);
116
117 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
118 }
119
120 // Verify that false is returned when SyncService is missing or incomplete.
121 TEST(WalletIntegrationAvailableTest, MissingOrIncompleteSyncService) {
122 // Setup |prefs| and |pdm| to do their part to make
123 // WalletIntegrationAvailable() return true.
124 scoped_ptr<TestingPrefServiceSimple> prefs =
125 CreatePrefService(true, true, true);
126 scoped_ptr<TestPersonalDataManager> pdm =
127 CreatePersonalDataManager(prefs.get(), true);
128
129 // Incomplete SyncService data should return false.
130 EXPECT_FALSE(WalletIntegrationAvailable(NULL, *prefs, *pdm));
131
132 scoped_ptr<SyncServiceMock> sync = CreateSyncService(false, false, false);
133 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
134
135 sync = CreateSyncService(false, false, true);
136 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
137
138 sync = CreateSyncService(true, false, false);
139 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
140
141 // Complete SyncService data should return true.
142 sync = CreateSyncService(true, true, true);
143 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
144 }
145
146 // Verify that false is returned when
147 // !prefs::kAutofillWalletSyncExperimentEnabled.
148 TEST(WalletIntegrationAvailableTest, ExperimentalWalletIntegrationDisabled) {
149 scoped_ptr<SyncServiceMock> sync = CreateSyncService(true, true, true);
150 // Set kAutofillWalletSyncExperimentEnabled to false.
151 scoped_ptr<TestingPrefServiceSimple> prefs =
152 CreatePrefService(true, true, false);
153 scoped_ptr<TestPersonalDataManager> pdm =
154 CreatePersonalDataManager(prefs.get(), true);
155
156 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
157 }
158
159 // Verify that false is returned if server data is missing.
160 TEST(WalletIntegrationAvailableTest, NoServerData) {
161 scoped_ptr<SyncServiceMock> sync = CreateSyncService(true, true, true);
162 scoped_ptr<TestingPrefServiceSimple> prefs =
163 CreatePrefService(true, true, true);
164 // Set server data as missing.
165 scoped_ptr<TestPersonalDataManager> pdm =
166 CreatePersonalDataManager(prefs.get(), false);
167
168 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
169 }
170
171 // Verify that true is returned when !prefs::kAutofillWalletImportEnabled,
172 // even if server data is missing.
173 TEST(WalletIntegrationAvailableTest, WalletImportDisabled) {
174 scoped_ptr<SyncServiceMock> sync = CreateSyncService(true, true, true);
175 // Set kAutofillWalletImportEnabled to false.
176 scoped_ptr<TestingPrefServiceSimple> prefs =
177 CreatePrefService(true, false, true);
178 // Set server data as missing.
179 scoped_ptr<TestPersonalDataManager> pdm =
180 CreatePersonalDataManager(prefs.get(), false);
181
182 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
183 }
184
185 // Verify that true is returned when data hasn't been synced yet, even if
186 // server data is missing.
187 TEST(WalletIntegrationAvailableTest, WalletDataNotSyncedYet) {
188 // Set wallet data as not synced yet.
189 scoped_ptr<SyncServiceMock> sync = CreateSyncService(true, false, true);
190 scoped_ptr<TestingPrefServiceSimple> prefs =
191 CreatePrefService(true, true, true);
192 // Set server data as missing.
193 scoped_ptr<TestPersonalDataManager> pdm =
194 CreatePersonalDataManager(prefs.get(), false);
195
196 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm));
197 }
198
199 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/options_util.cc ('k') | components/autofill/core/browser/test_personal_data_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698