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

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

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