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

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

Issue 9834056: Moved WebDataService to ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: upload rebase Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 28 matching lines...) Expand all
39 #include "chrome/browser/sync/profile_sync_components_factory.h" 39 #include "chrome/browser/sync/profile_sync_components_factory.h"
40 #include "chrome/browser/sync/profile_sync_service.h" 40 #include "chrome/browser/sync/profile_sync_service.h"
41 #include "chrome/browser/sync/profile_sync_test_util.h" 41 #include "chrome/browser/sync/profile_sync_test_util.h"
42 #include "chrome/browser/sync/test_profile_sync_service.h" 42 #include "chrome/browser/sync/test_profile_sync_service.h"
43 #include "chrome/browser/webdata/autocomplete_syncable_service.h" 43 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
44 #include "chrome/browser/webdata/autofill_change.h" 44 #include "chrome/browser/webdata/autofill_change.h"
45 #include "chrome/browser/webdata/autofill_entry.h" 45 #include "chrome/browser/webdata/autofill_entry.h"
46 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 46 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
47 #include "chrome/browser/webdata/autofill_table.h" 47 #include "chrome/browser/webdata/autofill_table.h"
48 #include "chrome/browser/webdata/web_database.h" 48 #include "chrome/browser/webdata/web_database.h"
49 #include "chrome/browser/webdata/web_data_service.h"
50 #include "chrome/browser/webdata/web_data_service_factory.h"
49 #include "chrome/common/chrome_notification_types.h" 51 #include "chrome/common/chrome_notification_types.h"
50 #include "chrome/common/net/gaia/gaia_constants.h" 52 #include "chrome/common/net/gaia/gaia_constants.h"
51 #include "content/public/browser/notification_source.h" 53 #include "content/public/browser/notification_source.h"
52 #include "content/test/test_browser_thread.h" 54 #include "content/test/test_browser_thread.h"
53 #include "sync/engine/model_changing_syncer_command.h" 55 #include "sync/engine/model_changing_syncer_command.h"
54 #include "sync/protocol/autofill_specifics.pb.h" 56 #include "sync/protocol/autofill_specifics.pb.h"
55 #include "sync/syncable/model_type.h" 57 #include "sync/syncable/model_type.h"
56 #include "sync/syncable/syncable.h" 58 #include "sync/syncable/syncable.h"
57 #include "sync/test/engine/test_id_factory.h" 59 #include "sync/test/engine/test_id_factory.h"
58 #include "testing/gmock/include/gmock/gmock.h" 60 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return syncable::AUTOFILL; 154 return syncable::AUTOFILL;
153 } 155 }
154 156
155 template<> 157 template<>
156 syncable::ModelType GetModelType<AutofillProfile>() { 158 syncable::ModelType GetModelType<AutofillProfile>() {
157 return syncable::AUTOFILL_PROFILE; 159 return syncable::AUTOFILL_PROFILE;
158 } 160 }
159 161
160 class WebDataServiceFake : public WebDataService { 162 class WebDataServiceFake : public WebDataService {
161 public: 163 public:
162 explicit WebDataServiceFake(WebDatabase* web_database) 164 WebDataServiceFake()
163 : web_database_(web_database), 165 : web_database_(NULL),
164 syncable_service_created_or_destroyed_(false, false) { 166 syncable_service_created_or_destroyed_(false, false) {
165 } 167 }
166 168
169 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) {
170 return new WebDataServiceFake;
171 }
172
173 void SetDatabase(WebDatabase* web_database) {
174 web_database_ = web_database;
175 }
176
167 void StartSyncableService() { 177 void StartSyncableService() {
168 // The |autofill_profile_syncable_service_| must be constructed on the DB 178 // The |autofill_profile_syncable_service_| must be constructed on the DB
169 // thread. 179 // thread.
170 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 180 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
171 base::Bind(&WebDataServiceFake::CreateSyncableService, 181 base::Bind(&WebDataServiceFake::CreateSyncableService,
172 base::Unretained(this))); 182 base::Unretained(this)));
173 syncable_service_created_or_destroyed_.Wait(); 183 syncable_service_created_or_destroyed_.Wait();
174 } 184 }
175 185
176 void ShutdownSyncableService() { 186 void ShutdownSyncableService() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 221 }
212 222
213 virtual AutofillProfileSyncableService* 223 virtual AutofillProfileSyncableService*
214 GetAutofillProfileSyncableService() const OVERRIDE { 224 GetAutofillProfileSyncableService() const OVERRIDE {
215 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 225 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
216 EXPECT_TRUE(autofill_profile_syncable_service_); 226 EXPECT_TRUE(autofill_profile_syncable_service_);
217 227
218 return autofill_profile_syncable_service_; 228 return autofill_profile_syncable_service_;
219 } 229 }
220 230
231 virtual void ShutdownOnUIThread() OVERRIDE {}
232
221 private: 233 private:
222 void CreateSyncableService() { 234 void CreateSyncableService() {
223 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 235 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
224 // These services are deleted in DestroySyncableService(). 236 // These services are deleted in DestroySyncableService().
225 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); 237 autocomplete_syncable_service_ = new AutocompleteSyncableService(this);
226 autofill_profile_syncable_service_ = 238 autofill_profile_syncable_service_ =
227 new AutofillProfileSyncableService(this); 239 new AutofillProfileSyncableService(this);
228 syncable_service_created_or_destroyed_.Signal(); 240 syncable_service_created_or_destroyed_.Signal();
229 } 241 }
230 242
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 MOCK_METHOD0(LoadProfiles, void()); 347 MOCK_METHOD0(LoadProfiles, void());
336 MOCK_METHOD0(LoadCreditCards, void()); 348 MOCK_METHOD0(LoadCreditCards, void());
337 MOCK_METHOD0(Refresh, void()); 349 MOCK_METHOD0(Refresh, void());
338 }; 350 };
339 template <class T> class AddAutofillHelper; 351 template <class T> class AddAutofillHelper;
340 352
341 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { 353 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
342 protected: 354 protected:
343 ProfileSyncServiceAutofillTest() { 355 ProfileSyncServiceAutofillTest() {
344 } 356 }
357 virtual ~ProfileSyncServiceAutofillTest() {
358 }
345 359
346 AutofillProfileFactory profile_factory_; 360 AutofillProfileFactory profile_factory_;
347 AutofillEntryFactory entry_factory_; 361 AutofillEntryFactory entry_factory_;
348 362
349 AbstractAutofillFactory* GetFactory(syncable::ModelType type) { 363 AbstractAutofillFactory* GetFactory(syncable::ModelType type) {
350 if (type == syncable::AUTOFILL) { 364 if (type == syncable::AUTOFILL) {
351 return &entry_factory_; 365 return &entry_factory_;
352 } else if (type == syncable::AUTOFILL_PROFILE) { 366 } else if (type == syncable::AUTOFILL_PROFILE) {
353 return &profile_factory_; 367 return &profile_factory_;
354 } else { 368 } else {
355 NOTREACHED(); 369 NOTREACHED();
356 return NULL; 370 return NULL;
357 } 371 }
358 } 372 }
359 373
360 virtual void SetUp() OVERRIDE { 374 virtual void SetUp() OVERRIDE {
361 AbstractProfileSyncServiceTest::SetUp(); 375 AbstractProfileSyncServiceTest::SetUp();
362 profile_.CreateRequestContext(); 376 profile_.CreateRequestContext();
363 web_database_.reset(new WebDatabaseFake(&autofill_table_)); 377 web_database_.reset(new WebDatabaseFake(&autofill_table_));
364 web_data_service_ = new WebDataServiceFake(web_database_.get()); 378 web_data_service_ = static_cast<WebDataServiceFake*>(
379 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse(
380 &profile_, WebDataServiceFake::Build).get());
381 web_data_service_->SetDatabase(web_database_.get());
365 personal_data_manager_ = static_cast<PersonalDataManagerMock*>( 382 personal_data_manager_ = static_cast<PersonalDataManagerMock*>(
366 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( 383 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse(
367 &profile_, PersonalDataManagerMock::Build)); 384 &profile_, PersonalDataManagerMock::Build));
368 token_service_ = static_cast<TokenService*>( 385 token_service_ = static_cast<TokenService*>(
369 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( 386 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
370 &profile_, BuildTokenService)); 387 &profile_, BuildTokenService));
371 // GetHistoryService() gets called indirectly, but the result is ignored, so 388 // GetHistoryService() gets called indirectly, but the result is ignored, so
372 // it is safe to return NULL. 389 // it is safe to return NULL.
373 EXPECT_CALL(profile_, GetHistoryService(_)). 390 EXPECT_CALL(profile_, GetHistoryService(_)).
374 WillRepeatedly(Return(static_cast<HistoryService*>(NULL))); 391 WillRepeatedly(Return(static_cast<HistoryService*>(NULL)));
375 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); 392 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1);
376 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); 393 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1);
377 EXPECT_CALL(profile_, GetWebDataService(_)). 394
378 // TokenService::Initialize
379 // AutofillDataTypeController::StartModels()
380 // In some tests:
381 // AutofillProfileSyncableService::AutofillProfileSyncableService()
382 WillRepeatedly(Return(web_data_service_.get()));
383 personal_data_manager_->Init(&profile_); 395 personal_data_manager_->Init(&profile_);
384 396
385 // Note: This must be called *after* the notification service is created. 397 // Note: This must be called *after* the notification service is created.
386 web_data_service_->StartSyncableService(); 398 web_data_service_->StartSyncableService();
387 } 399 }
388 400
389 virtual void TearDown() OVERRIDE { 401 virtual void TearDown() OVERRIDE {
390 // Note: The tear down order is important. 402 // Note: The tear down order is important.
391 service_.reset(); 403 service_.reset();
392 web_data_service_->ShutdownSyncableService(); 404 web_data_service_->ShutdownSyncableService();
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 std::vector<AutofillEntry> sync_entries; 1242 std::vector<AutofillEntry> sync_entries;
1231 std::vector<AutofillProfile> sync_profiles; 1243 std::vector<AutofillProfile> sync_profiles;
1232 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1244 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1233 EXPECT_EQ(3U, sync_entries.size()); 1245 EXPECT_EQ(3U, sync_entries.size());
1234 EXPECT_EQ(0U, sync_profiles.size()); 1246 EXPECT_EQ(0U, sync_profiles.size());
1235 for (size_t i = 0; i < sync_entries.size(); i++) { 1247 for (size_t i = 0; i < sync_entries.size(); i++) {
1236 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1248 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1237 << ", " << sync_entries[i].key().value(); 1249 << ", " << sync_entries[i].key().value();
1238 } 1250 }
1239 } 1251 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_components_factory_impl.cc ('k') | chrome/browser/sync/profile_sync_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698