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

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

Issue 7967024: Profile shouldn't own PersonalDataManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addresses isherman #11 Created 9 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 | 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
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/task.h" 18 #include "base/task.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/autofill/autofill_common_test.h" 21 #include "chrome/browser/autofill/autofill_common_test.h"
22 #include "chrome/browser/autofill/personal_data_manager.h"
23 #include "chrome/browser/autofill/personal_data_manager_factory.h"
22 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 24 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
23 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" 25 #include "chrome/browser/sync/engine/model_changing_syncer_command.h"
24 #include "chrome/browser/sync/glue/autofill_change_processor.h" 26 #include "chrome/browser/sync/glue/autofill_change_processor.h"
25 #include "chrome/browser/sync/glue/autofill_data_type_controller.h" 27 #include "chrome/browser/sync/glue/autofill_data_type_controller.h"
26 #include "chrome/browser/sync/glue/autofill_model_associator.h" 28 #include "chrome/browser/sync/glue/autofill_model_associator.h"
27 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" 29 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
28 #include "chrome/browser/sync/glue/autofill_profile_syncable_service.h" 30 #include "chrome/browser/sync/glue/autofill_profile_syncable_service.h"
29 #include "chrome/browser/sync/glue/data_type_controller.h" 31 #include "chrome/browser/sync/glue/data_type_controller.h"
30 #include "chrome/browser/sync/glue/generic_change_processor.h" 32 #include "chrome/browser/sync/glue/generic_change_processor.h"
31 #include "chrome/browser/sync/glue/syncable_service_adapter.h" 33 #include "chrome/browser/sync/glue/syncable_service_adapter.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 159 }
158 160
159 virtual WebDatabase* GetDatabase() { 161 virtual WebDatabase* GetDatabase() {
160 return web_database_; 162 return web_database_;
161 } 163 }
162 164
163 private: 165 private:
164 WebDatabase* web_database_; 166 WebDatabase* web_database_;
165 }; 167 };
166 168
167 ACTION_P4(MakeAutofillSyncComponents, service, wd, pdm, dtc) { 169 ACTION_P3(MakeAutofillSyncComponents, service, wd, dtc) {
168 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 170 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
169 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) 171 if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
170 return ProfileSyncFactory::SyncComponents(NULL, NULL); 172 return ProfileSyncFactory::SyncComponents(NULL, NULL);
171 AutofillModelAssociator* model_associator = 173 AutofillModelAssociator* model_associator =
172 new AutofillModelAssociator(service, wd, pdm); 174 new AutofillModelAssociator(service, wd, service->profile());
173 AutofillChangeProcessor* change_processor = 175 AutofillChangeProcessor* change_processor =
174 new AutofillChangeProcessor(model_associator, wd, pdm, dtc); 176 new AutofillChangeProcessor(model_associator, wd,
177 service->profile(), dtc);
175 return ProfileSyncFactory::SyncComponents(model_associator, 178 return ProfileSyncFactory::SyncComponents(model_associator,
176 change_processor); 179 change_processor);
177 } 180 }
178 181
179 ACTION_P4(MakeAutofillProfileSyncComponents, service, wd, pdm, dtc) { 182 ACTION_P3(MakeAutofillProfileSyncComponents, service, wd, dtc) {
180 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 183 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
181 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) 184 if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
182 return ProfileSyncFactory::SyncComponents(NULL, NULL); 185 return ProfileSyncFactory::SyncComponents(NULL, NULL);
183 AutofillProfileSyncableService* sync_service = 186 AutofillProfileSyncableService* sync_service =
184 new AutofillProfileSyncableService(wd, pdm, service->profile()); 187 new AutofillProfileSyncableService(wd, service->profile());
185 sync_api::UserShare* user_share = service->GetUserShare(); 188 sync_api::UserShare* user_share = service->GetUserShare();
186 GenericChangeProcessor* change_processor = 189 GenericChangeProcessor* change_processor =
187 new GenericChangeProcessor(sync_service, dtc, user_share); 190 new GenericChangeProcessor(sync_service, dtc, user_share);
188 SyncableServiceAdapter* sync_service_adapter = 191 SyncableServiceAdapter* sync_service_adapter =
189 new SyncableServiceAdapter(syncable::AUTOFILL_PROFILE, 192 new SyncableServiceAdapter(syncable::AUTOFILL_PROFILE,
190 sync_service, 193 sync_service,
191 change_processor); 194 change_processor);
192 return ProfileSyncFactory::SyncComponents(sync_service_adapter, 195 return ProfileSyncFactory::SyncComponents(sync_service_adapter,
193 change_processor); 196 change_processor);
194 } 197 }
195 198
196 class AbstractAutofillFactory { 199 class AbstractAutofillFactory {
197 public: 200 public:
198 virtual AutofillDataTypeController* CreateDataTypeController( 201 virtual AutofillDataTypeController* CreateDataTypeController(
199 ProfileSyncFactory* factory, 202 ProfileSyncFactory* factory,
200 ProfileMock* profile, 203 ProfileMock* profile,
201 ProfileSyncService* service) = 0; 204 ProfileSyncService* service) = 0;
202 virtual void SetExpectation(ProfileSyncFactoryMock* factory, 205 virtual void SetExpectation(ProfileSyncFactoryMock* factory,
203 ProfileSyncService* service, 206 ProfileSyncService* service,
204 WebDatabase* wd, 207 WebDatabase* wd,
205 PersonalDataManager* pdm,
206 DataTypeController* dtc) = 0; 208 DataTypeController* dtc) = 0;
207 virtual ~AbstractAutofillFactory() {} 209 virtual ~AbstractAutofillFactory() {}
208 }; 210 };
209 211
210 class AutofillEntryFactory : public AbstractAutofillFactory { 212 class AutofillEntryFactory : public AbstractAutofillFactory {
211 public: 213 public:
212 browser_sync::AutofillDataTypeController* CreateDataTypeController( 214 browser_sync::AutofillDataTypeController* CreateDataTypeController(
213 ProfileSyncFactory* factory, 215 ProfileSyncFactory* factory,
214 ProfileMock* profile, 216 ProfileMock* profile,
215 ProfileSyncService* service) { 217 ProfileSyncService* service) {
216 return new AutofillDataTypeController(factory, 218 return new AutofillDataTypeController(factory,
217 profile); 219 profile);
218 } 220 }
219 221
220 void SetExpectation(ProfileSyncFactoryMock* factory, 222 void SetExpectation(ProfileSyncFactoryMock* factory,
221 ProfileSyncService* service, 223 ProfileSyncService* service,
222 WebDatabase* wd, 224 WebDatabase* wd,
223 PersonalDataManager* pdm,
224 DataTypeController* dtc) { 225 DataTypeController* dtc) {
225 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_,_)). 226 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_)).
226 WillOnce(MakeAutofillSyncComponents(service, wd, pdm, dtc)); 227 WillOnce(MakeAutofillSyncComponents(service, wd, dtc));
227 } 228 }
228 }; 229 };
229 230
230 class AutofillProfileFactory : public AbstractAutofillFactory { 231 class AutofillProfileFactory : public AbstractAutofillFactory {
231 public: 232 public:
232 browser_sync::AutofillDataTypeController* CreateDataTypeController( 233 browser_sync::AutofillDataTypeController* CreateDataTypeController(
233 ProfileSyncFactory* factory, 234 ProfileSyncFactory* factory,
234 ProfileMock* profile, 235 ProfileMock* profile,
235 ProfileSyncService* service) { 236 ProfileSyncService* service) {
236 return new AutofillProfileDataTypeController(factory, 237 return new AutofillProfileDataTypeController(factory,
237 profile); 238 profile);
238 } 239 }
239 240
240 void SetExpectation(ProfileSyncFactoryMock* factory, 241 void SetExpectation(ProfileSyncFactoryMock* factory,
241 ProfileSyncService* service, 242 ProfileSyncService* service,
242 WebDatabase* wd, 243 WebDatabase* wd,
243 PersonalDataManager* pdm,
244 DataTypeController* dtc) { 244 DataTypeController* dtc) {
245 EXPECT_CALL(*factory, CreateAutofillProfileSyncComponents(_,_,_,_)). 245 EXPECT_CALL(*factory, CreateAutofillProfileSyncComponents(_,_,_)).
246 WillOnce(MakeAutofillProfileSyncComponents(service, wd, pdm, dtc)); 246 WillOnce(MakeAutofillProfileSyncComponents(service, wd, dtc));
247 } 247 }
248 }; 248 };
249 249
250 class PersonalDataManagerMock: public PersonalDataManager { 250 class PersonalDataManagerMock: public PersonalDataManager {
251 public: 251 public:
252 static ProfileKeyedService* Build(Profile* profile) {
253 return new PersonalDataManagerMock;
254 }
255
252 MOCK_CONST_METHOD0(IsDataLoaded, bool()); 256 MOCK_CONST_METHOD0(IsDataLoaded, bool());
253 MOCK_METHOD0(LoadProfiles, void()); 257 MOCK_METHOD0(LoadProfiles, void());
254 MOCK_METHOD0(LoadCreditCards, void()); 258 MOCK_METHOD0(LoadCreditCards, void());
255 MOCK_METHOD0(Refresh, void()); 259 MOCK_METHOD0(Refresh, void());
256 }; 260 };
257 template <class T> class AddAutofillTask; 261 template <class T> class AddAutofillTask;
258 262
259 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { 263 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
260 protected: 264 protected:
261 ProfileSyncServiceAutofillTest() {} 265 ProfileSyncServiceAutofillTest() {}
262 266
263 AutofillProfileFactory profile_factory_; 267 AutofillProfileFactory profile_factory_;
264 AutofillEntryFactory entry_factory_; 268 AutofillEntryFactory entry_factory_;
265 269
266 AbstractAutofillFactory* GetFactory(syncable::ModelType type) { 270 AbstractAutofillFactory* GetFactory(syncable::ModelType type) {
267 if (type == syncable::AUTOFILL) { 271 if (type == syncable::AUTOFILL) {
268 return &entry_factory_; 272 return &entry_factory_;
269 } else if (type == syncable::AUTOFILL_PROFILE) { 273 } else if (type == syncable::AUTOFILL_PROFILE) {
270 return &profile_factory_; 274 return &profile_factory_;
271 } else { 275 } else {
272 NOTREACHED(); 276 NOTREACHED();
273 return NULL; 277 return NULL;
274 } 278 }
275 } 279 }
280
276 virtual void SetUp() { 281 virtual void SetUp() {
277 AbstractProfileSyncServiceTest::SetUp(); 282 AbstractProfileSyncServiceTest::SetUp();
278 profile_.CreateRequestContext(); 283 profile_.CreateRequestContext();
279 web_database_.reset(new WebDatabaseFake(&autofill_table_)); 284 web_database_.reset(new WebDatabaseFake(&autofill_table_));
280 web_data_service_ = new WebDataServiceFake(web_database_.get()); 285 web_data_service_ = new WebDataServiceFake(web_database_.get());
281 personal_data_manager_ = new PersonalDataManagerMock(); 286 personal_data_manager_ = static_cast<PersonalDataManagerMock*>(
287 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse(
288 &profile_, PersonalDataManagerMock::Build));
282 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); 289 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1);
283 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); 290 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1);
291 EXPECT_CALL(profile_, GetWebDataService(_)).
292 // TokenService::Initialize
293 // AutofillDataTypeController::StartModels()
294 // In some tests:
295 // AutofillProfileSyncableService::AutofillProfileSyncableService()
296 WillRepeatedly(Return(web_data_service_.get()));
284 personal_data_manager_->Init(&profile_); 297 personal_data_manager_->Init(&profile_);
285 298
286 notification_service_ = new ThreadNotificationService(&db_thread_); 299 notification_service_ = new ThreadNotificationService(&db_thread_);
287 notification_service_->Init(); 300 notification_service_->Init();
288 } 301 }
289 302
290 virtual void TearDown() { 303 virtual void TearDown() {
291 service_.reset(); 304 service_.reset();
292 notification_service_->TearDown(); 305 notification_service_->TearDown();
293 profile_.ResetRequestContext(); 306 profile_.ResetRequestContext();
(...skipping 12 matching lines...) Expand all
306 AutofillDataTypeController* data_type_controller = 319 AutofillDataTypeController* data_type_controller =
307 factory->CreateDataTypeController(&factory_, 320 factory->CreateDataTypeController(&factory_,
308 &profile_, 321 &profile_,
309 service_.get()); 322 service_.get());
310 SyncBackendHostForProfileSyncTest:: 323 SyncBackendHostForProfileSyncTest::
311 SetDefaultExpectationsForWorkerCreation(&profile_); 324 SetDefaultExpectationsForWorkerCreation(&profile_);
312 325
313 factory->SetExpectation(&factory_, 326 factory->SetExpectation(&factory_,
314 service_.get(), 327 service_.get(),
315 web_database_.get(), 328 web_database_.get(),
316 personal_data_manager_.get(),
317 data_type_controller); 329 data_type_controller);
318 330
319 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). 331 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).
320 WillOnce(ReturnNewDataTypeManager()); 332 WillOnce(ReturnNewDataTypeManager());
321 333
322 EXPECT_CALL(profile_, GetWebDataService(_)).
323 // TokenService::Initialize
324 // AutofillDataTypeController::StartModels()
325 // In some tests:
326 // AutofillProfileSyncableService::AutofillProfileSyncableService()
327 WillRepeatedly(Return(web_data_service_.get()));
328
329 EXPECT_CALL(profile_, GetPersonalDataManager()).
330 WillRepeatedly(Return(personal_data_manager_.get()));
331
332 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). 334 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()).
333 WillRepeatedly(Return(true)); 335 WillRepeatedly(Return(true));
334 336
335 // We need tokens to get the tests going 337 // We need tokens to get the tests going
336 token_service_->IssueAuthTokenForTest( 338 token_service_->IssueAuthTokenForTest(
337 GaiaConstants::kSyncService, "token"); 339 GaiaConstants::kSyncService, "token");
338 340
339 EXPECT_CALL(profile_, GetTokenService()). 341 EXPECT_CALL(profile_, GetTokenService()).
340 WillRepeatedly(Return(token_service_.get())); 342 WillRepeatedly(Return(token_service_.get()));
341 343
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 friend class AddAutofillTask<AutofillEntry>; 470 friend class AddAutofillTask<AutofillEntry>;
469 friend class AddAutofillTask<AutofillProfile>; 471 friend class AddAutofillTask<AutofillProfile>;
470 friend class FakeServerUpdater; 472 friend class FakeServerUpdater;
471 473
472 scoped_refptr<ThreadNotificationService> notification_service_; 474 scoped_refptr<ThreadNotificationService> notification_service_;
473 475
474 ProfileMock profile_; 476 ProfileMock profile_;
475 AutofillTableMock autofill_table_; 477 AutofillTableMock autofill_table_;
476 scoped_ptr<WebDatabaseFake> web_database_; 478 scoped_ptr<WebDatabaseFake> web_database_;
477 scoped_refptr<WebDataService> web_data_service_; 479 scoped_refptr<WebDataService> web_data_service_;
478 scoped_refptr<PersonalDataManagerMock> personal_data_manager_; 480 PersonalDataManagerMock* personal_data_manager_;
479 }; 481 };
480 482
481 template <class T> 483 template <class T>
482 class AddAutofillTask : public Task { 484 class AddAutofillTask : public Task {
483 public: 485 public:
484 AddAutofillTask(ProfileSyncServiceAutofillTest* test, 486 AddAutofillTask(ProfileSyncServiceAutofillTest* test,
485 const std::vector<T>& entries) 487 const std::vector<T>& entries)
486 : test_(test), entries_(entries), success_(false) { 488 : test_(test), entries_(entries), success_(false) {
487 } 489 }
488 490
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 std::vector<AutofillEntry> sync_entries; 1093 std::vector<AutofillEntry> sync_entries;
1092 std::vector<AutofillProfile> sync_profiles; 1094 std::vector<AutofillProfile> sync_profiles;
1093 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1095 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1094 EXPECT_EQ(3U, sync_entries.size()); 1096 EXPECT_EQ(3U, sync_entries.size());
1095 EXPECT_EQ(0U, sync_profiles.size()); 1097 EXPECT_EQ(0U, sync_profiles.size());
1096 for (size_t i = 0; i < sync_entries.size(); i++) { 1098 for (size_t i = 0; i < sync_entries.size(); i++) {
1097 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1099 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1098 << ", " << sync_entries[i].key().value(); 1100 << ", " << sync_entries[i].key().value();
1099 } 1101 }
1100 } 1102 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_factory_mock.h ('k') | chrome/browser/sync/test/integration/autofill_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698