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

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

Issue 12805007: wd5-syncableServices for try only (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wd5-syncableServices with debug test fix Created 7 years, 9 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 24 matching lines...) Expand all
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_change.h" 39 #include "chrome/browser/webdata/autofill_change.h"
40 #include "chrome/browser/webdata/autofill_entry.h" 40 #include "chrome/browser/webdata/autofill_entry.h"
41 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 41 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
42 #include "chrome/browser/webdata/autofill_table.h" 42 #include "chrome/browser/webdata/autofill_table.h"
43 #include "chrome/browser/webdata/web_data_service.h" 43 #include "chrome/browser/webdata/web_data_service.h"
44 #include "chrome/browser/webdata/web_data_service_factory.h" 44 #include "chrome/browser/webdata/web_data_service_factory.h"
45 #include "chrome/browser/webdata/web_data_service_test_util.h"
45 #include "chrome/browser/webdata/web_database.h" 46 #include "chrome/browser/webdata/web_database.h"
46 #include "chrome/common/chrome_notification_types.h" 47 #include "chrome/common/chrome_notification_types.h"
47 #include "components/autofill/browser/autofill_common_test.h" 48 #include "components/autofill/browser/autofill_common_test.h"
48 #include "components/autofill/browser/personal_data_manager.h" 49 #include "components/autofill/browser/personal_data_manager.h"
49 #include "content/public/browser/notification_source.h" 50 #include "content/public/browser/notification_source.h"
50 #include "content/public/test/test_browser_thread.h" 51 #include "content/public/test/test_browser_thread.h"
51 #include "google_apis/gaia/gaia_constants.h" 52 #include "google_apis/gaia/gaia_constants.h"
52 #include "sync/internal_api/public/base/model_type.h" 53 #include "sync/internal_api/public/base/model_type.h"
53 #include "sync/internal_api/public/read_node.h" 54 #include "sync/internal_api/public/read_node.h"
54 #include "sync/internal_api/public/read_transaction.h" 55 #include "sync/internal_api/public/read_transaction.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 using testing::Return; 88 using testing::Return;
88 89
89 namespace syncable { 90 namespace syncable {
90 class Id; 91 class Id;
91 } 92 }
92 93
93 class HistoryService; 94 class HistoryService;
94 95
95 class AutofillTableMock : public AutofillTable { 96 class AutofillTableMock : public AutofillTable {
96 public: 97 public:
97 AutofillTableMock() : AutofillTable(NULL, NULL) {} 98 AutofillTableMock() : AutofillTable() {}
98 MOCK_METHOD2(RemoveFormElement, 99 MOCK_METHOD2(RemoveFormElement,
99 bool(const string16& name, const string16& value)); // NOLINT 100 bool(const string16& name, const string16& value)); // NOLINT
100 MOCK_METHOD1(GetAllAutofillEntries, 101 MOCK_METHOD1(GetAllAutofillEntries,
101 bool(std::vector<AutofillEntry>* entries)); // NOLINT 102 bool(std::vector<AutofillEntry>* entries)); // NOLINT
102 MOCK_METHOD3(GetAutofillTimestamps, 103 MOCK_METHOD3(GetAutofillTimestamps,
103 bool(const string16& name, // NOLINT 104 bool(const string16& name, // NOLINT
104 const string16& value, 105 const string16& value,
105 std::vector<base::Time>* timestamps)); 106 std::vector<base::Time>* timestamps));
106 MOCK_METHOD1(UpdateAutofillEntries, 107 MOCK_METHOD1(UpdateAutofillEntries,
107 bool(const std::vector<AutofillEntry>&)); // NOLINT 108 bool(const std::vector<AutofillEntry>&)); // NOLINT
108 MOCK_METHOD1(GetAutofillProfiles, 109 MOCK_METHOD1(GetAutofillProfiles,
109 bool(std::vector<AutofillProfile*>*)); // NOLINT 110 bool(std::vector<AutofillProfile*>*)); // NOLINT
110 MOCK_METHOD1(UpdateAutofillProfileMulti, 111 MOCK_METHOD1(UpdateAutofillProfileMulti,
111 bool(const AutofillProfile&)); // NOLINT 112 bool(const AutofillProfile&)); // NOLINT
112 MOCK_METHOD1(AddAutofillProfile, 113 MOCK_METHOD1(AddAutofillProfile,
113 bool(const AutofillProfile&)); // NOLINT 114 bool(const AutofillProfile&)); // NOLINT
114 MOCK_METHOD1(RemoveAutofillProfile, 115 MOCK_METHOD1(RemoveAutofillProfile,
115 bool(const std::string&)); // NOLINT 116 bool(const std::string&)); // NOLINT
116 }; 117 };
117 118
118 MATCHER_P(MatchProfiles, profile, "") { 119 MATCHER_P(MatchProfiles, profile, "") {
119 return (profile.Compare(arg) == 0); 120 return (profile.Compare(arg) == 0);
120 } 121 }
121 122
122
123 class WebDatabaseFake : public WebDatabase { 123 class WebDatabaseFake : public WebDatabase {
124 public: 124 public:
125 explicit WebDatabaseFake(AutofillTable* autofill_table) 125 explicit WebDatabaseFake(AutofillTable* autofill_table) {
126 : autofill_table_(autofill_table) {} 126 AddTable(autofill_table);
127
128 virtual AutofillTable* GetAutofillTable() OVERRIDE {
129 return autofill_table_;
130 } 127 }
131
132 private:
133 AutofillTable* autofill_table_;
134 }; 128 };
135 129
136 class ProfileSyncServiceAutofillTest; 130 class ProfileSyncServiceAutofillTest;
137 131
138 template<class AutofillProfile> 132 template<class AutofillProfile>
139 syncer::ModelType GetModelType() { 133 syncer::ModelType GetModelType() {
140 return syncer::UNSPECIFIED; 134 return syncer::UNSPECIFIED;
141 } 135 }
142 136
143 template<> 137 template<>
144 syncer::ModelType GetModelType<AutofillEntry>() { 138 syncer::ModelType GetModelType<AutofillEntry>() {
145 return syncer::AUTOFILL; 139 return syncer::AUTOFILL;
146 } 140 }
147 141
148 template<> 142 template<>
149 syncer::ModelType GetModelType<AutofillProfile>() { 143 syncer::ModelType GetModelType<AutofillProfile>() {
150 return syncer::AUTOFILL_PROFILE; 144 return syncer::AUTOFILL_PROFILE;
151 } 145 }
152 146
153 class WebDataServiceFake : public WebDataService { 147 class WebDataServiceFake : public WebDataService {
154 public: 148 public:
155 WebDataServiceFake() 149 WebDataServiceFake()
156 : web_database_(NULL), 150 : web_database_(NULL),
157 syncable_service_created_or_destroyed_(false, false) { 151 syncable_service_created_or_destroyed_(false, false) {
158 } 152 }
159 153
160 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) {
161 return new WebDataServiceFake;
162 }
163
164 void SetDatabase(WebDatabase* web_database) { 154 void SetDatabase(WebDatabase* web_database) {
165 web_database_ = web_database; 155 web_database_ = web_database;
166 } 156 }
167 157
168 void StartSyncableService() { 158 void StartSyncableService() {
169 // The |autofill_profile_syncable_service_| must be constructed on the DB 159 // The |autofill_profile_syncable_service_| must be constructed on the DB
170 // thread. 160 // thread.
171 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 161 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
172 base::Bind(&WebDataServiceFake::CreateSyncableService, 162 base::Bind(&WebDataServiceFake::CreateSyncableService,
173 base::Unretained(this))); 163 base::Unretained(this)));
(...skipping 22 matching lines...) Expand all
196 // TODO(tim): It would be nice if WebDataService was injected on 186 // TODO(tim): It would be nice if WebDataService was injected on
197 // construction of TokenService rather than fetched by Initialize so that 187 // construction of TokenService rather than fetched by Initialize so that
198 // this isn't necessary (we could pass a NULL service). We currently do 188 // this isn't necessary (we could pass a NULL service). We currently do
199 // return it via EXPECT_CALLs, but without depending on order-of- 189 // return it via EXPECT_CALLs, but without depending on order-of-
200 // initialization (which seems way more fragile) we can't tell which 190 // initialization (which seems way more fragile) we can't tell which
201 // component is asking at what time, and some components in these Autofill 191 // component is asking at what time, and some components in these Autofill
202 // tests require a WebDataService. 192 // tests require a WebDataService.
203 return 0; 193 return 0;
204 } 194 }
205 195
206 virtual AutocompleteSyncableService*
207 GetAutocompleteSyncableService() const OVERRIDE {
208 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
209 EXPECT_TRUE(autocomplete_syncable_service_);
210
211 return autocomplete_syncable_service_;
212 }
213
214 virtual AutofillProfileSyncableService*
215 GetAutofillProfileSyncableService() const OVERRIDE {
216 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
217 EXPECT_TRUE(autofill_profile_syncable_service_);
218
219 return autofill_profile_syncable_service_;
220 }
221
222 virtual void ShutdownOnUIThread() OVERRIDE {} 196 virtual void ShutdownOnUIThread() OVERRIDE {}
223 197
224 private: 198 private:
225 virtual ~WebDataServiceFake() {} 199 virtual ~WebDataServiceFake() {}
226 200
227 void CreateSyncableService() { 201 void CreateSyncableService() {
228 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 202 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
229 // These services are deleted in DestroySyncableService(). 203 // These services are deleted in DestroySyncableService().
230 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); 204 AutocompleteSyncableService::CreateForWebDataService(this);
231 autofill_profile_syncable_service_ = 205 AutofillProfileSyncableService::CreateForWebDataService(this);
232 new AutofillProfileSyncableService(this);
233 syncable_service_created_or_destroyed_.Signal(); 206 syncable_service_created_or_destroyed_.Signal();
234 } 207 }
235 208
236 void DestroySyncableService() { 209 void DestroySyncableService() {
237 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 210 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
238 delete autofill_profile_syncable_service_; 211 WebDataServiceBase::ShutdownOnDBThread();
239 delete autocomplete_syncable_service_;
240 syncable_service_created_or_destroyed_.Signal(); 212 syncable_service_created_or_destroyed_.Signal();
241 } 213 }
242 214
243 WebDatabase* web_database_; 215 WebDatabase* web_database_;
244 216
245 // We own the syncable services, but don't use a |scoped_ptr| because the
246 // lifetime must be managed on the DB thread.
247 AutocompleteSyncableService* autocomplete_syncable_service_;
248 AutofillProfileSyncableService* autofill_profile_syncable_service_;
249 WaitableEvent syncable_service_created_or_destroyed_; 217 WaitableEvent syncable_service_created_or_destroyed_;
250 }; 218 };
251 219
220 ProfileKeyedService* BuildMockWebDataServiceWrapper(Profile* profile) {
221 return new MockWebDataServiceWrapper(new WebDataServiceFake());
222 }
223
252 ACTION_P(MakeAutocompleteSyncComponents, wds) { 224 ACTION_P(MakeAutocompleteSyncComponents, wds) {
253 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 225 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
254 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) 226 if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
255 return base::WeakPtr<syncer::SyncableService>(); 227 return base::WeakPtr<syncer::SyncableService>();
256 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); 228 return AutocompleteSyncableService::FromWebDataService(wds)->AsWeakPtr();
257 } 229 }
258 230
259 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { 231 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) {
260 return new browser_sync::DataTypeManagerImpl( 232 return new browser_sync::DataTypeManagerImpl(
261 debug_listener, 233 debug_listener,
262 arg1, 234 arg1,
263 arg2, 235 arg2,
264 arg3, 236 arg3,
265 arg4); 237 arg4);
266 } 238 }
267 239
268 ACTION(MakeGenericChangeProcessor) { 240 ACTION(MakeGenericChangeProcessor) {
269 syncer::UserShare* user_share = arg0->GetUserShare(); 241 syncer::UserShare* user_share = arg0->GetUserShare();
270 return new GenericChangeProcessor( 242 return new GenericChangeProcessor(
271 arg1, 243 arg1,
272 arg2, 244 arg2,
273 arg3, 245 arg3,
274 user_share); 246 user_share);
275 } 247 }
276 248
277 ACTION(MakeSharedChangeProcessor) { 249 ACTION(MakeSharedChangeProcessor) {
278 return new SharedChangeProcessor(); 250 return new SharedChangeProcessor();
279 } 251 }
280 252
281 ACTION_P(MakeAutofillProfileSyncComponents, wds) { 253 ACTION_P(MakeAutofillProfileSyncComponents, wds) {
282 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 254 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
283 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) 255 if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
284 return base::WeakPtr<syncer::SyncableService>();; 256 return base::WeakPtr<syncer::SyncableService>();;
285 return wds->GetAutofillProfileSyncableService()->AsWeakPtr(); 257 return AutofillProfileSyncableService::FromWebDataService(wds)->AsWeakPtr();
286 } 258 }
287 259
288 class AbstractAutofillFactory { 260 class AbstractAutofillFactory {
289 public: 261 public:
290 virtual DataTypeController* CreateDataTypeController( 262 virtual DataTypeController* CreateDataTypeController(
291 ProfileSyncComponentsFactory* factory, 263 ProfileSyncComponentsFactory* factory,
292 ProfileMock* profile, 264 ProfileMock* profile,
293 ProfileSyncService* service) = 0; 265 ProfileSyncService* service) = 0;
294 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, 266 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory,
295 ProfileSyncService* service, 267 ProfileSyncService* service,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 NOTREACHED(); 375 NOTREACHED();
404 return NULL; 376 return NULL;
405 } 377 }
406 } 378 }
407 379
408 virtual void SetUp() OVERRIDE { 380 virtual void SetUp() OVERRIDE {
409 AbstractProfileSyncServiceTest::SetUp(); 381 AbstractProfileSyncServiceTest::SetUp();
410 profile_.reset(new ProfileMock()); 382 profile_.reset(new ProfileMock());
411 profile_->CreateRequestContext(); 383 profile_->CreateRequestContext();
412 web_database_.reset(new WebDatabaseFake(&autofill_table_)); 384 web_database_.reset(new WebDatabaseFake(&autofill_table_));
413 web_data_service_ = static_cast<WebDataServiceFake*>( 385 MockWebDataServiceWrapper* wrapper =
414 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( 386 static_cast<MockWebDataServiceWrapper*>(
415 profile_.get(), WebDataServiceFake::Build).get()); 387 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse(
388 profile_.get(), BuildMockWebDataServiceWrapper));
389 web_data_service_ =
390 static_cast<WebDataServiceFake*>(wrapper->GetWebData().get());
416 web_data_service_->SetDatabase(web_database_.get()); 391 web_data_service_->SetDatabase(web_database_.get());
417 392
418 MockPersonalDataManagerService* personal_data_manager_service = 393 MockPersonalDataManagerService* personal_data_manager_service =
419 static_cast<MockPersonalDataManagerService*>( 394 static_cast<MockPersonalDataManagerService*>(
420 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( 395 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse(
421 profile_.get(), MockPersonalDataManagerService::Build)); 396 profile_.get(), MockPersonalDataManagerService::Build));
422 personal_data_manager_ = 397 personal_data_manager_ =
423 personal_data_manager_service->GetPersonalDataManager(); 398 personal_data_manager_service->GetPersonalDataManager();
424 399
425 token_service_ = static_cast<TokenService*>( 400 token_service_ = static_cast<TokenService*>(
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 std::vector<AutofillEntry> sync_entries; 1293 std::vector<AutofillEntry> sync_entries;
1319 std::vector<AutofillProfile> sync_profiles; 1294 std::vector<AutofillProfile> sync_profiles;
1320 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1295 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1321 EXPECT_EQ(3U, sync_entries.size()); 1296 EXPECT_EQ(3U, sync_entries.size());
1322 EXPECT_EQ(0U, sync_profiles.size()); 1297 EXPECT_EQ(0U, sync_profiles.size());
1323 for (size_t i = 0; i < sync_entries.size(); i++) { 1298 for (size_t i = 0; i < sync_entries.size(); i++) {
1324 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1299 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1325 << ", " << sync_entries[i].key().value(); 1300 << ", " << sync_entries[i].key().value();
1326 } 1301 }
1327 } 1302 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_components_factory_impl.cc ('k') | chrome/browser/sync/test/integration/autofill_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698