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

Side by Side Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 8065016: [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try harder trybot (rebase). Created 9 years, 2 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/autofill/personal_data_manager.h" 22 #include "chrome/browser/autofill/personal_data_manager.h"
23 #include "chrome/browser/autofill/personal_data_manager_factory.h" 23 #include "chrome/browser/autofill/personal_data_manager_factory.h"
24 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 24 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
25 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" 25 #include "chrome/browser/sync/engine/model_changing_syncer_command.h"
26 #include "chrome/browser/sync/glue/autofill_change_processor.h" 26 #include "chrome/browser/sync/glue/autofill_change_processor.h"
27 #include "chrome/browser/sync/glue/autofill_data_type_controller.h" 27 #include "chrome/browser/sync/glue/autofill_data_type_controller.h"
28 #include "chrome/browser/sync/glue/autofill_model_associator.h" 28 #include "chrome/browser/sync/glue/autofill_model_associator.h"
29 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" 29 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
30 #include "chrome/browser/sync/glue/data_type_controller.h" 30 #include "chrome/browser/sync/glue/data_type_controller.h"
31 #include "chrome/browser/sync/glue/generic_change_processor.h" 31 #include "chrome/browser/sync/glue/generic_change_processor.h"
32 #include "chrome/browser/sync/glue/shared_change_processor.h"
32 #include "chrome/browser/sync/glue/syncable_service_adapter.h" 33 #include "chrome/browser/sync/glue/syncable_service_adapter.h"
33 #include "chrome/browser/sync/internal_api/read_node.h" 34 #include "chrome/browser/sync/internal_api/read_node.h"
34 #include "chrome/browser/sync/internal_api/read_transaction.h" 35 #include "chrome/browser/sync/internal_api/read_transaction.h"
35 #include "chrome/browser/sync/internal_api/write_node.h" 36 #include "chrome/browser/sync/internal_api/write_node.h"
36 #include "chrome/browser/sync/internal_api/write_transaction.h" 37 #include "chrome/browser/sync/internal_api/write_transaction.h"
37 #include "chrome/browser/sync/profile_sync_factory.h" 38 #include "chrome/browser/sync/profile_sync_factory.h"
38 #include "chrome/browser/sync/profile_sync_service.h" 39 #include "chrome/browser/sync/profile_sync_service.h"
39 #include "chrome/browser/sync/profile_sync_test_util.h" 40 #include "chrome/browser/sync/profile_sync_test_util.h"
40 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" 41 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
41 #include "chrome/browser/sync/syncable/directory_manager.h" 42 #include "chrome/browser/sync/syncable/directory_manager.h"
(...skipping 14 matching lines...) Expand all
56 57
57 using base::Time; 58 using base::Time;
58 using base::WaitableEvent; 59 using base::WaitableEvent;
59 using browser_sync::AutofillChangeProcessor; 60 using browser_sync::AutofillChangeProcessor;
60 using browser_sync::AutofillDataTypeController; 61 using browser_sync::AutofillDataTypeController;
61 using browser_sync::AutofillModelAssociator; 62 using browser_sync::AutofillModelAssociator;
62 using browser_sync::AutofillProfileDataTypeController; 63 using browser_sync::AutofillProfileDataTypeController;
63 using browser_sync::AutofillProfileSyncableService; 64 using browser_sync::AutofillProfileSyncableService;
64 using browser_sync::DataTypeController; 65 using browser_sync::DataTypeController;
65 using browser_sync::GenericChangeProcessor; 66 using browser_sync::GenericChangeProcessor;
67 using browser_sync::SharedChangeProcessor;
66 using browser_sync::SyncableServiceAdapter; 68 using browser_sync::SyncableServiceAdapter;
67 using browser_sync::GROUP_DB; 69 using browser_sync::GROUP_DB;
68 using browser_sync::kAutofillTag; 70 using browser_sync::kAutofillTag;
69 using browser_sync::SyncBackendHostForProfileSyncTest; 71 using browser_sync::SyncBackendHostForProfileSyncTest;
70 using browser_sync::UnrecoverableErrorHandler; 72 using browser_sync::UnrecoverableErrorHandler;
71 using syncable::CREATE_NEW_UPDATE_ITEM; 73 using syncable::CREATE_NEW_UPDATE_ITEM;
72 using syncable::AUTOFILL; 74 using syncable::AUTOFILL;
73 using syncable::BASE_VERSION; 75 using syncable::BASE_VERSION;
74 using syncable::CREATE; 76 using syncable::CREATE;
75 using syncable::GET_BY_SERVER_TAG; 77 using syncable::GET_BY_SERVER_TAG;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return ProfileSyncFactory::SyncComponents(NULL, NULL); 174 return ProfileSyncFactory::SyncComponents(NULL, NULL);
173 AutofillModelAssociator* model_associator = 175 AutofillModelAssociator* model_associator =
174 new AutofillModelAssociator(service, wd, service->profile()); 176 new AutofillModelAssociator(service, wd, service->profile());
175 AutofillChangeProcessor* change_processor = 177 AutofillChangeProcessor* change_processor =
176 new AutofillChangeProcessor(model_associator, wd, 178 new AutofillChangeProcessor(model_associator, wd,
177 service->profile(), dtc); 179 service->profile(), dtc);
178 return ProfileSyncFactory::SyncComponents(model_associator, 180 return ProfileSyncFactory::SyncComponents(model_associator,
179 change_processor); 181 change_processor);
180 } 182 }
181 183
182 ACTION_P3(MakeAutofillProfileSyncComponents, service, wds, dtc) { 184 ACTION(MakeGenericChangeProcessor) {
185 sync_api::UserShare* user_share = arg0->GetUserShare();
186 return new GenericChangeProcessor(arg1, arg2, user_share);
187 }
188
189 ACTION(MakeSharedChangeProcessor) {
190 return new SharedChangeProcessor();
191 }
192
193 ACTION_P(MakeAutofillProfileSyncComponents, wds) {
183 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 194 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
184 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) 195 if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
185 return ProfileSyncFactory::SyncComponents(NULL, NULL); 196 return base::WeakPtr<SyncableService>();
186 AutofillProfileSyncableService* sync_service = 197 return (new AutofillProfileSyncableService(wds))->AsWeakPtr();
akalin 2011/10/12 19:54:21 leak? :/ probably need rebase
Nicolas Zea 2011/10/12 23:47:43 Done.
187 new AutofillProfileSyncableService(wds);
188 sync_api::UserShare* user_share = service->GetUserShare();
189 GenericChangeProcessor* change_processor =
190 new GenericChangeProcessor(sync_service, dtc, user_share);
191 SyncableServiceAdapter* sync_service_adapter =
192 new SyncableServiceAdapter(syncable::AUTOFILL_PROFILE,
193 sync_service,
194 change_processor);
195 return ProfileSyncFactory::SyncComponents(sync_service_adapter,
196 change_processor);
197 } 198 }
198 199
199 class AbstractAutofillFactory { 200 class AbstractAutofillFactory {
200 public: 201 public:
201 virtual AutofillDataTypeController* CreateDataTypeController( 202 virtual DataTypeController* CreateDataTypeController(
202 ProfileSyncFactory* factory, 203 ProfileSyncFactory* factory,
203 ProfileMock* profile, 204 ProfileMock* profile,
204 ProfileSyncService* service) = 0; 205 ProfileSyncService* service) = 0;
205 virtual void SetExpectation(ProfileSyncFactoryMock* factory, 206 virtual void SetExpectation(ProfileSyncFactoryMock* factory,
206 ProfileSyncService* service, 207 ProfileSyncService* service,
207 WebDataService* wds, 208 WebDataService* wds,
208 DataTypeController* dtc) = 0; 209 DataTypeController* dtc) = 0;
209 virtual ~AbstractAutofillFactory() {} 210 virtual ~AbstractAutofillFactory() {}
210 }; 211 };
211 212
212 class AutofillEntryFactory : public AbstractAutofillFactory { 213 class AutofillEntryFactory : public AbstractAutofillFactory {
213 public: 214 public:
214 browser_sync::AutofillDataTypeController* CreateDataTypeController( 215 browser_sync::DataTypeController* CreateDataTypeController(
215 ProfileSyncFactory* factory, 216 ProfileSyncFactory* factory,
216 ProfileMock* profile, 217 ProfileMock* profile,
217 ProfileSyncService* service) { 218 ProfileSyncService* service) {
218 return new AutofillDataTypeController(factory, 219 return new AutofillDataTypeController(factory, profile);
219 profile);
220 } 220 }
221 221
222 void SetExpectation(ProfileSyncFactoryMock* factory, 222 void SetExpectation(ProfileSyncFactoryMock* factory,
223 ProfileSyncService* service, 223 ProfileSyncService* service,
224 WebDataService* wds, 224 WebDataService* wds,
225 DataTypeController* dtc) { 225 DataTypeController* dtc) {
226 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_)). 226 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_)).
227 WillOnce(MakeAutofillSyncComponents(service, wds->GetDatabase(), dtc)); 227 WillOnce(MakeAutofillSyncComponents(service, wds->GetDatabase(), dtc));
228 } 228 }
229 }; 229 };
230 230
231 class AutofillProfileFactory : public AbstractAutofillFactory { 231 class AutofillProfileFactory : public AbstractAutofillFactory {
232 public: 232 public:
233 browser_sync::AutofillDataTypeController* CreateDataTypeController( 233 browser_sync::DataTypeController* CreateDataTypeController(
234 ProfileSyncFactory* factory, 234 ProfileSyncFactory* factory,
235 ProfileMock* profile, 235 ProfileMock* profile,
236 ProfileSyncService* service) { 236 ProfileSyncService* service) {
237 return new AutofillProfileDataTypeController(factory, 237 return new AutofillProfileDataTypeController(factory, profile);
238 profile);
239 } 238 }
240 239
241 void SetExpectation(ProfileSyncFactoryMock* factory, 240 void SetExpectation(ProfileSyncFactoryMock* factory,
242 ProfileSyncService* service, 241 ProfileSyncService* service,
243 WebDataService* wds, 242 WebDataService* wds,
244 DataTypeController* dtc) { 243 DataTypeController* dtc) {
245 EXPECT_CALL(*factory, CreateAutofillProfileSyncComponents(_,_,_)). 244 EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)).
246 WillOnce(MakeAutofillProfileSyncComponents(service, wds, dtc)); 245 WillOnce(MakeGenericChangeProcessor());
246 EXPECT_CALL(*factory, CreateSharedChangeProcessor()).
247 WillOnce(MakeSharedChangeProcessor());
248 EXPECT_CALL(*factory, GetAutofillProfileSyncableService(_)).
249 WillOnce(MakeAutofillProfileSyncComponents(wds));
247 } 250 }
248 }; 251 };
249 252
250 class PersonalDataManagerMock: public PersonalDataManager { 253 class PersonalDataManagerMock: public PersonalDataManager {
251 public: 254 public:
252 static ProfileKeyedService* Build(Profile* profile) { 255 static ProfileKeyedService* Build(Profile* profile) {
253 return new PersonalDataManagerMock; 256 return new PersonalDataManagerMock;
254 } 257 }
255 258
256 MOCK_CONST_METHOD0(IsDataLoaded, bool()); 259 MOCK_CONST_METHOD0(IsDataLoaded, bool());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 312
310 void StartSyncService(Task* task, 313 void StartSyncService(Task* task,
311 bool will_fail_association, 314 bool will_fail_association,
312 syncable::ModelType type) { 315 syncable::ModelType type) {
313 AbstractAutofillFactory* factory = GetFactory(type); 316 AbstractAutofillFactory* factory = GetFactory(type);
314 service_.reset( 317 service_.reset(
315 new TestProfileSyncService(&factory_, &profile_, "test_user", false, 318 new TestProfileSyncService(&factory_, &profile_, "test_user", false,
316 task)); 319 task));
317 EXPECT_CALL(profile_, GetProfileSyncService()).WillRepeatedly( 320 EXPECT_CALL(profile_, GetProfileSyncService()).WillRepeatedly(
318 Return(service_.get())); 321 Return(service_.get()));
319 AutofillDataTypeController* data_type_controller = 322 DataTypeController* data_type_controller =
320 factory->CreateDataTypeController(&factory_, 323 factory->CreateDataTypeController(&factory_,
321 &profile_, 324 &profile_,
322 service_.get()); 325 service_.get());
323 SyncBackendHostForProfileSyncTest:: 326 SyncBackendHostForProfileSyncTest::
324 SetDefaultExpectationsForWorkerCreation(&profile_); 327 SetDefaultExpectationsForWorkerCreation(&profile_);
325 328
326 factory->SetExpectation(&factory_, 329 factory->SetExpectation(&factory_,
327 service_.get(), 330 service_.get(),
328 web_data_service_.get(), 331 web_data_service_.get(),
329 data_type_controller); 332 data_type_controller);
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 std::vector<AutofillEntry> sync_entries; 1096 std::vector<AutofillEntry> sync_entries;
1094 std::vector<AutofillProfile> sync_profiles; 1097 std::vector<AutofillProfile> sync_profiles;
1095 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1098 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1096 EXPECT_EQ(3U, sync_entries.size()); 1099 EXPECT_EQ(3U, sync_entries.size());
1097 EXPECT_EQ(0U, sync_profiles.size()); 1100 EXPECT_EQ(0U, sync_profiles.size());
1098 for (size_t i = 0; i < sync_entries.size(); i++) { 1101 for (size_t i = 0; i < sync_entries.size(); i++) {
1099 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1102 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1100 << ", " << sync_entries[i].key().value(); 1103 << ", " << sync_entries[i].key().value();
1101 } 1104 }
1102 } 1105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698