Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_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/autofill_web_data_service_impl.h" | |
| 43 #include "chrome/browser/webdata/web_data_service.h" | 44 #include "chrome/browser/webdata/web_data_service.h" |
| 44 #include "chrome/browser/webdata/web_data_service_factory.h" | 45 #include "chrome/browser/webdata/web_data_service_factory.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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 } | 146 } |
| 146 | 147 |
| 147 template<> | 148 template<> |
| 148 syncer::ModelType GetModelType<AutofillProfile>() { | 149 syncer::ModelType GetModelType<AutofillProfile>() { |
| 149 return syncer::AUTOFILL_PROFILE; | 150 return syncer::AUTOFILL_PROFILE; |
| 150 } | 151 } |
| 151 | 152 |
| 152 class WebDataServiceFake : public WebDataService { | 153 class WebDataServiceFake : public WebDataService { |
| 153 public: | 154 public: |
| 154 WebDataServiceFake() | 155 WebDataServiceFake() |
| 155 : web_database_(NULL), | 156 : WebDataService(), |
| 157 web_database_(NULL), | |
| 156 syncable_service_created_or_destroyed_(false, false) { | 158 syncable_service_created_or_destroyed_(false, false) { |
| 157 } | 159 } |
| 158 | 160 |
| 159 void SetDatabase(WebDatabase* web_database) { | 161 void SetDatabase(WebDatabase* web_database) { |
| 160 web_database_ = web_database; | 162 web_database_ = web_database; |
| 161 } | 163 } |
| 162 | 164 |
| 163 void StartSyncableService() { | 165 void StartSyncableService() { |
| 164 // The |autofill_profile_syncable_service_| must be constructed on the DB | 166 // The |autofill_profile_syncable_service_| must be constructed on the DB |
| 165 // thread. | 167 // thread. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 179 } | 181 } |
| 180 | 182 |
| 181 virtual bool IsDatabaseLoaded() OVERRIDE { | 183 virtual bool IsDatabaseLoaded() OVERRIDE { |
| 182 return true; | 184 return true; |
| 183 } | 185 } |
| 184 | 186 |
| 185 virtual WebDatabase* GetDatabase() OVERRIDE { | 187 virtual WebDatabase* GetDatabase() OVERRIDE { |
| 186 return web_database_; | 188 return web_database_; |
| 187 } | 189 } |
| 188 | 190 |
| 189 virtual WebDataService::Handle GetAllTokens( | 191 /* virtual WebDataService::Handle GetAllTokens( |
| 190 WebDataServiceConsumer* consumer) OVERRIDE { | 192 WebDataServiceConsumer* consumer) OVERRIDE { |
| 191 // TODO(tim): It would be nice if WebDataService was injected on | 193 // TODO(tim): It would be nice if WebDataService was injected on |
| 192 // construction of TokenService rather than fetched by Initialize so that | 194 // construction of TokenService rather than fetched by Initialize so that |
| 193 // this isn't necessary (we could pass a NULL service). We currently do | 195 // this isn't necessary (we could pass a NULL service). We currently do |
| 194 // return it via EXPECT_CALLs, but without depending on order-of- | 196 // return it via EXPECT_CALLs, but without depending on order-of- |
| 195 // initialization (which seems way more fragile) we can't tell which | 197 // initialization (which seems way more fragile) we can't tell which |
| 196 // component is asking at what time, and some components in these Autofill | 198 // component is asking at what time, and some components in these Autofill |
| 197 // tests require a WebDataService. | 199 // tests require a WebDataService. |
| 198 return 0; | 200 return 0; |
| 199 } | 201 }*/ |
| 200 | 202 |
| 201 virtual AutocompleteSyncableService* | 203 virtual void ShutdownOnUIThread() OVERRIDE {} |
| 202 GetAutocompleteSyncableService() const OVERRIDE { | |
| 203 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 204 EXPECT_TRUE(autocomplete_syncable_service_); | |
| 205 | |
| 206 return autocomplete_syncable_service_; | |
| 207 } | |
| 208 | |
| 209 virtual AutofillProfileSyncableService* | |
| 210 GetAutofillProfileSyncableService() const OVERRIDE { | |
| 211 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 212 EXPECT_TRUE(autofill_profile_syncable_service_); | |
| 213 | |
| 214 return autofill_profile_syncable_service_; | |
| 215 } | |
| 216 | 204 |
| 217 private: | 205 private: |
| 218 virtual ~WebDataServiceFake() {} | 206 virtual ~WebDataServiceFake() {} |
| 219 | 207 |
| 220 void CreateSyncableService() { | 208 void CreateSyncableService() { |
| 221 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 209 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 222 // These services are deleted in DestroySyncableService(). | 210 // These services are deleted in DestroySyncableService(). |
| 223 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); | 211 AutocompleteSyncableService::CreateForWebDataService(this); |
| 224 autofill_profile_syncable_service_ = | 212 AutofillProfileSyncableService::CreateForWebDataService(this); |
| 225 new AutofillProfileSyncableService(this); | |
| 226 syncable_service_created_or_destroyed_.Signal(); | 213 syncable_service_created_or_destroyed_.Signal(); |
| 227 } | 214 } |
| 228 | 215 |
| 229 void DestroySyncableService() { | 216 void DestroySyncableService() { |
| 230 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 217 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 231 delete autofill_profile_syncable_service_; | 218 WebDataServiceBase::ShutdownOnDBThread(); |
| 232 delete autocomplete_syncable_service_; | |
| 233 syncable_service_created_or_destroyed_.Signal(); | 219 syncable_service_created_or_destroyed_.Signal(); |
| 234 } | 220 } |
| 235 | 221 |
| 236 WebDatabase* web_database_; | 222 WebDatabase* web_database_; |
| 237 | 223 |
| 238 // We own the syncable services, but don't use a |scoped_ptr| because the | |
| 239 // lifetime must be managed on the DB thread. | |
| 240 AutocompleteSyncableService* autocomplete_syncable_service_; | |
| 241 AutofillProfileSyncableService* autofill_profile_syncable_service_; | |
| 242 WaitableEvent syncable_service_created_or_destroyed_; | 224 WaitableEvent syncable_service_created_or_destroyed_; |
| 243 }; | 225 }; |
| 244 | 226 |
| 245 class MockWebDataServiceWrapper : public WebDataServiceWrapper { | 227 class MockWebDataServiceWrapper : public WebDataServiceWrapper { |
| 246 public: | 228 public: |
| 247 static ProfileKeyedService* Build(Profile* profile) { | 229 static ProfileKeyedService* Build(Profile* profile) { |
| 248 return new MockWebDataServiceWrapper(); | 230 return new MockWebDataServiceWrapper(); |
| 249 } | 231 } |
| 250 | 232 |
| 251 MockWebDataServiceWrapper() { | 233 MockWebDataServiceWrapper() { |
| 252 web_data_service_fake_ = new WebDataServiceFake(); | 234 web_data_service_fake_ = new WebDataServiceFake(); |
| 253 } | 235 } |
| 254 | 236 |
| 255 void Shutdown() OVERRIDE { | 237 void Shutdown() OVERRIDE { |
| 256 } | 238 } |
| 257 | 239 |
| 258 scoped_refptr<WebDataService> GetWebData() OVERRIDE { | 240 scoped_refptr<WebDataService> GetWebData() OVERRIDE { |
| 259 return web_data_service_fake_; | 241 return web_data_service_fake_; |
| 260 } | 242 } |
| 261 | 243 |
| 244 scoped_refptr<AutofillWebDataService> GetAutofillWebData() OVERRIDE { | |
|
Jói
2013/03/19 20:53:58
indent -2
Cait (Slow)
2013/03/20 22:21:10
Done.
| |
| 245 return new AutofillWebDataServiceImpl(NULL, | |
| 246 WebDataServiceBase::ProfileErrorCallback()); | |
| 247 } | |
| 248 | |
| 262 ~MockWebDataServiceWrapper() { | 249 ~MockWebDataServiceWrapper() { |
| 263 } | 250 } |
| 264 | 251 |
| 265 private: | 252 private: |
| 266 scoped_refptr<WebDataServiceFake> web_data_service_fake_; | 253 scoped_refptr<WebDataServiceFake> web_data_service_fake_; |
| 267 | 254 |
| 268 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); | 255 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); |
| 269 }; | 256 }; |
| 270 | 257 |
| 271 ACTION_P(MakeAutocompleteSyncComponents, wds) { | 258 ACTION_P(MakeAutocompleteSyncComponents, wds) { |
| 272 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 259 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 273 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 260 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
| 274 return base::WeakPtr<syncer::SyncableService>(); | 261 return base::WeakPtr<syncer::SyncableService>(); |
| 275 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); | 262 return AutocompleteSyncableService::FromWebDataService(wds)->AsWeakPtr(); |
| 276 } | 263 } |
| 277 | 264 |
| 278 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { | 265 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { |
| 279 return new browser_sync::DataTypeManagerImpl( | 266 return new browser_sync::DataTypeManagerImpl( |
| 280 debug_listener, | 267 debug_listener, |
| 281 arg1, | 268 arg1, |
| 282 arg2, | 269 arg2, |
| 283 arg3, | 270 arg3, |
| 284 arg4); | 271 arg4); |
| 285 } | 272 } |
| 286 | 273 |
| 287 ACTION(MakeGenericChangeProcessor) { | 274 ACTION(MakeGenericChangeProcessor) { |
| 288 syncer::UserShare* user_share = arg0->GetUserShare(); | 275 syncer::UserShare* user_share = arg0->GetUserShare(); |
| 289 return new GenericChangeProcessor( | 276 return new GenericChangeProcessor( |
| 290 arg1, | 277 arg1, |
| 291 arg2, | 278 arg2, |
| 292 arg3, | 279 arg3, |
| 293 user_share); | 280 user_share); |
| 294 } | 281 } |
| 295 | 282 |
| 296 ACTION(MakeSharedChangeProcessor) { | 283 ACTION(MakeSharedChangeProcessor) { |
| 297 return new SharedChangeProcessor(); | 284 return new SharedChangeProcessor(); |
| 298 } | 285 } |
| 299 | 286 |
| 300 ACTION_P(MakeAutofillProfileSyncComponents, wds) { | 287 ACTION_P(MakeAutofillProfileSyncComponents, wds) { |
| 301 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 288 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 302 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 289 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
| 303 return base::WeakPtr<syncer::SyncableService>();; | 290 return base::WeakPtr<syncer::SyncableService>();; |
| 304 return wds->GetAutofillProfileSyncableService()->AsWeakPtr(); | 291 return AutofillProfileSyncableService::FromWebDataService(wds)->AsWeakPtr(); |
| 305 } | 292 } |
| 306 | 293 |
| 307 class AbstractAutofillFactory { | 294 class AbstractAutofillFactory { |
| 308 public: | 295 public: |
| 309 virtual DataTypeController* CreateDataTypeController( | 296 virtual DataTypeController* CreateDataTypeController( |
| 310 ProfileSyncComponentsFactory* factory, | 297 ProfileSyncComponentsFactory* factory, |
| 311 ProfileMock* profile, | 298 ProfileMock* profile, |
| 312 ProfileSyncService* service) = 0; | 299 ProfileSyncService* service) = 0; |
| 313 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, | 300 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, |
| 314 ProfileSyncService* service, | 301 ProfileSyncService* service, |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1340 std::vector<AutofillEntry> sync_entries; | 1327 std::vector<AutofillEntry> sync_entries; |
| 1341 std::vector<AutofillProfile> sync_profiles; | 1328 std::vector<AutofillProfile> sync_profiles; |
| 1342 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1329 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1343 EXPECT_EQ(3U, sync_entries.size()); | 1330 EXPECT_EQ(3U, sync_entries.size()); |
| 1344 EXPECT_EQ(0U, sync_profiles.size()); | 1331 EXPECT_EQ(0U, sync_profiles.size()); |
| 1345 for (size_t i = 0; i < sync_entries.size(); i++) { | 1332 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1346 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1333 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1347 << ", " << sync_entries[i].key().value(); | 1334 << ", " << sync_entries[i].key().value(); |
| 1348 } | 1335 } |
| 1349 } | 1336 } |
| OLD | NEW |