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

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

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

Powered by Google App Engine
This is Rietveld 408576698