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

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

Issue 14081043: Hook up Autofill Backend interface to SyncableServices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 22 matching lines...) Expand all
33 #include "chrome/browser/sync/profile_sync_components_factory.h" 33 #include "chrome/browser/sync/profile_sync_components_factory.h"
34 #include "chrome/browser/sync/profile_sync_service.h" 34 #include "chrome/browser/sync/profile_sync_service.h"
35 #include "chrome/browser/sync/profile_sync_service_factory.h" 35 #include "chrome/browser/sync/profile_sync_service_factory.h"
36 #include "chrome/browser/sync/profile_sync_test_util.h" 36 #include "chrome/browser/sync/profile_sync_test_util.h"
37 #include "chrome/browser/sync/test_profile_sync_service.h" 37 #include "chrome/browser/sync/test_profile_sync_service.h"
38 #include "chrome/browser/webdata/autocomplete_syncable_service.h" 38 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
39 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 39 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
40 #include "chrome/browser/webdata/web_data_service_factory.h" 40 #include "chrome/browser/webdata/web_data_service_factory.h"
41 #include "components/autofill/browser/autofill_common_test.h" 41 #include "components/autofill/browser/autofill_common_test.h"
42 #include "components/autofill/browser/personal_data_manager.h" 42 #include "components/autofill/browser/personal_data_manager.h"
43 #include "components/autofill/browser/webdata/autofill_backend_delegate.h"
43 #include "components/autofill/browser/webdata/autofill_change.h" 44 #include "components/autofill/browser/webdata/autofill_change.h"
44 #include "components/autofill/browser/webdata/autofill_entry.h" 45 #include "components/autofill/browser/webdata/autofill_entry.h"
45 #include "components/autofill/browser/webdata/autofill_table.h" 46 #include "components/autofill/browser/webdata/autofill_table.h"
47 #include "components/autofill/browser/webdata/autofill_webdata_backend.h"
46 #include "components/autofill/browser/webdata/autofill_webdata_service.h" 48 #include "components/autofill/browser/webdata/autofill_webdata_service.h"
47 #include "components/webdata/common/web_data_service_test_util.h" 49 #include "components/webdata/common/web_data_service_test_util.h"
48 #include "components/webdata/common/web_database.h" 50 #include "components/webdata/common/web_database.h"
49 #include "content/public/test/test_browser_thread.h" 51 #include "content/public/test/test_browser_thread.h"
50 #include "google_apis/gaia/gaia_constants.h" 52 #include "google_apis/gaia/gaia_constants.h"
51 #include "sync/internal_api/public/base/model_type.h" 53 #include "sync/internal_api/public/base/model_type.h"
52 #include "sync/internal_api/public/read_node.h" 54 #include "sync/internal_api/public/read_node.h"
53 #include "sync/internal_api/public/read_transaction.h" 55 #include "sync/internal_api/public/read_transaction.h"
54 #include "sync/internal_api/public/write_node.h" 56 #include "sync/internal_api/public/write_node.h"
55 #include "sync/internal_api/public/write_transaction.h" 57 #include "sync/internal_api/public/write_transaction.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 137
136 MATCHER_P(MatchProfiles, profile, "") { 138 MATCHER_P(MatchProfiles, profile, "") {
137 return (profile.Compare(arg) == 0); 139 return (profile.Compare(arg) == 0);
138 } 140 }
139 141
140 class WebDatabaseFake : public WebDatabase { 142 class WebDatabaseFake : public WebDatabase {
141 public: 143 public:
142 explicit WebDatabaseFake(AutofillTable* autofill_table) { 144 explicit WebDatabaseFake(AutofillTable* autofill_table) {
143 AddTable(autofill_table); 145 AddTable(autofill_table);
144 } 146 }
147
148 void DetachFromThread() {
149 weak_ptr_factory_.DetachFromThread();
150 }
151
145 }; 152 };
146 153
147 class ProfileSyncServiceAutofillTest; 154 class ProfileSyncServiceAutofillTest;
148 155
149 template<class AutofillProfile> 156 template<class AutofillProfile>
150 syncer::ModelType GetModelType() { 157 syncer::ModelType GetModelType() {
151 return syncer::UNSPECIFIED; 158 return syncer::UNSPECIFIED;
152 } 159 }
153 160
154 template<> 161 template<>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 226 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
220 base::Bind(&WebDataServiceFake::DestroySyncableService, 227 base::Bind(&WebDataServiceFake::DestroySyncableService,
221 base::Unretained(this))); 228 base::Unretained(this)));
222 syncable_service_created_or_destroyed_.Wait(); 229 syncable_service_created_or_destroyed_.Wait();
223 } 230 }
224 231
225 virtual bool IsDatabaseLoaded() OVERRIDE { 232 virtual bool IsDatabaseLoaded() OVERRIDE {
226 return true; 233 return true;
227 } 234 }
228 235
229 virtual WebDatabase* GetDatabase() OVERRIDE { 236 WebDatabase* GetDatabase() {
230 return web_database_; 237 return web_database_;
231 } 238 }
232 239
233 virtual void ShutdownOnUIThread() OVERRIDE {} 240 virtual void ShutdownOnUIThread() OVERRIDE {}
234 241
235 void OnAutofillEntriesChanged(const AutofillChangeList& changes) { 242 void OnAutofillEntriesChanged(const AutofillChangeList& changes) {
236 WaitableEvent event(true, false); 243 WaitableEvent event(true, false);
237 244
238 base::Closure notify_cb = 245 base::Closure notify_cb =
239 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged, 246 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged,
(...skipping 19 matching lines...) Expand all
259 base::Bind(&RunAndSignal, notify_cb, &event)); 266 base::Bind(&RunAndSignal, notify_cb, &event));
260 event.Wait(); 267 event.Wait();
261 } 268 }
262 269
263 private: 270 private:
264 virtual ~WebDataServiceFake() {} 271 virtual ~WebDataServiceFake() {}
265 272
266 void CreateSyncableService() { 273 void CreateSyncableService() {
267 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 274 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
268 // These services are deleted in DestroySyncableService(). 275 // These services are deleted in DestroySyncableService().
269 AutocompleteSyncableService::CreateForWebDataService(this); 276 delegate_.reset(new autofill::AutofillBackendDelegate(
270 AutofillProfileSyncableService::CreateForWebDataService(this, "en-US"); 277 GetDatabase()->AsWeakPtr(),
278 base::WeakPtr<autofill::AutofillWebDataBackend>()));
279 AutocompleteSyncableService::CreateForWebDataService(this, delegate_.get());
280 AutofillProfileSyncableService::CreateForWebDataService(
281 this, delegate_.get(), "en-US");
271 282
272 autocomplete_syncable_service_ = 283 autocomplete_syncable_service_ =
273 AutocompleteSyncableService::FromWebDataService(this); 284 AutocompleteSyncableService::FromWebDataService(this);
274 autofill_profile_syncable_service_ = 285 autofill_profile_syncable_service_ =
275 AutofillProfileSyncableService::FromWebDataService(this); 286 AutofillProfileSyncableService::FromWebDataService(this);
276 287
277 syncable_service_created_or_destroyed_.Signal(); 288 syncable_service_created_or_destroyed_.Signal();
278 } 289 }
279 290
280 void DestroySyncableService() { 291 void DestroySyncableService() {
281 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 292 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
282 AutofillWebDataService::ShutdownOnDBThread(); 293 AutofillWebDataService::ShutdownOnDBThread();
283 autocomplete_syncable_service_ = NULL; 294 autocomplete_syncable_service_ = NULL;
284 autofill_profile_syncable_service_ = NULL; 295 autofill_profile_syncable_service_ = NULL;
296 delegate_.reset();
285 syncable_service_created_or_destroyed_.Signal(); 297 syncable_service_created_or_destroyed_.Signal();
286 } 298 }
287 299
288 WebDatabase* web_database_; 300 WebDatabase* web_database_;
289 AutocompleteSyncableService* autocomplete_syncable_service_; 301 AutocompleteSyncableService* autocomplete_syncable_service_;
290 AutofillProfileSyncableService* autofill_profile_syncable_service_; 302 AutofillProfileSyncableService* autofill_profile_syncable_service_;
291 303 scoped_ptr<autofill::AutofillBackendDelegate> delegate_;
292 WaitableEvent syncable_service_created_or_destroyed_; 304 WaitableEvent syncable_service_created_or_destroyed_;
293 305
294 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake); 306 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake);
295 }; 307 };
296 308
297 ProfileKeyedService* BuildMockWebDataServiceWrapper(Profile* profile) { 309 ProfileKeyedService* BuildMockWebDataServiceWrapper(Profile* profile) {
298 return new MockWebDataServiceWrapper( 310 return new MockWebDataServiceWrapper(
299 new TokenWebDataServiceFake(), 311 new TokenWebDataServiceFake(),
300 new WebDataServiceFake()); 312 new WebDataServiceFake());
301 } 313 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 507
496 web_data_service_->StartSyncableService(); 508 web_data_service_->StartSyncableService();
497 } 509 }
498 510
499 virtual void TearDown() OVERRIDE { 511 virtual void TearDown() OVERRIDE {
500 // Note: The tear down order is important. 512 // Note: The tear down order is important.
501 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( 513 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
502 profile_.get(), NULL); 514 profile_.get(), NULL);
503 web_data_service_->ShutdownSyncableService(); 515 web_data_service_->ShutdownSyncableService();
504 web_data_service_ = NULL; 516 web_data_service_ = NULL;
517 web_database_->DetachFromThread();
505 profile_->ResetRequestContext(); 518 profile_->ResetRequestContext();
506 // To prevent a leak, fully release TestURLRequestContext to ensure its 519 // To prevent a leak, fully release TestURLRequestContext to ensure its
507 // destruction on the IO message loop. 520 // destruction on the IO message loop.
508 profile_.reset(); 521 profile_.reset();
509 AbstractProfileSyncServiceTest::TearDown(); 522 AbstractProfileSyncServiceTest::TearDown();
510 } 523 }
511 524
512 525
513 int GetSyncCount(syncer::ModelType type) { 526 int GetSyncCount(syncer::ModelType type) {
514 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 527 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 std::vector<AutofillEntry> sync_entries; 1378 std::vector<AutofillEntry> sync_entries;
1366 std::vector<AutofillProfile> sync_profiles; 1379 std::vector<AutofillProfile> sync_profiles;
1367 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1380 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1368 EXPECT_EQ(3U, sync_entries.size()); 1381 EXPECT_EQ(3U, sync_entries.size());
1369 EXPECT_EQ(0U, sync_profiles.size()); 1382 EXPECT_EQ(0U, sync_profiles.size());
1370 for (size_t i = 0; i < sync_entries.size(); i++) { 1383 for (size_t i = 0; i < sync_entries.size(); i++) {
1371 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1384 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1372 << ", " << sync_entries[i].key().value(); 1385 << ", " << sync_entries[i].key().value();
1373 } 1386 }
1374 } 1387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698