| OLD | NEW |
| 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 Loading... |
| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return syncable::AUTOFILL; | 153 return syncable::AUTOFILL; |
| 152 } | 154 } |
| 153 | 155 |
| 154 template<> | 156 template<> |
| 155 syncable::ModelType GetModelType<AutofillProfile>() { | 157 syncable::ModelType GetModelType<AutofillProfile>() { |
| 156 return syncable::AUTOFILL_PROFILE; | 158 return syncable::AUTOFILL_PROFILE; |
| 157 } | 159 } |
| 158 | 160 |
| 159 class WebDataServiceFake : public WebDataService { | 161 class WebDataServiceFake : public WebDataService { |
| 160 public: | 162 public: |
| 161 explicit WebDataServiceFake(WebDatabase* web_database) | 163 WebDataServiceFake() |
| 162 : web_database_(web_database), | 164 : web_database_(NULL), |
| 163 syncable_service_created_or_destroyed_(false, false) { | 165 syncable_service_created_or_destroyed_(false, false) { |
| 164 } | 166 } |
| 165 | 167 |
| 168 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) { |
| 169 return new WebDataServiceFake; |
| 170 } |
| 171 |
| 172 void SetDatabase(WebDatabase* web_database) { |
| 173 web_database_ = web_database; |
| 174 } |
| 175 |
| 166 void StartSyncableService() { | 176 void StartSyncableService() { |
| 167 // The |autofill_profile_syncable_service_| must be constructed on the DB | 177 // The |autofill_profile_syncable_service_| must be constructed on the DB |
| 168 // thread. | 178 // thread. |
| 169 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 179 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 170 base::Bind(&WebDataServiceFake::CreateSyncableService, | 180 base::Bind(&WebDataServiceFake::CreateSyncableService, |
| 171 base::Unretained(this))); | 181 base::Unretained(this))); |
| 172 syncable_service_created_or_destroyed_.Wait(); | 182 syncable_service_created_or_destroyed_.Wait(); |
| 173 } | 183 } |
| 174 | 184 |
| 175 void ShutdownSyncableService() { | 185 void ShutdownSyncableService() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 220 } |
| 211 | 221 |
| 212 virtual AutofillProfileSyncableService* | 222 virtual AutofillProfileSyncableService* |
| 213 GetAutofillProfileSyncableService() const OVERRIDE { | 223 GetAutofillProfileSyncableService() const OVERRIDE { |
| 214 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 224 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 215 EXPECT_TRUE(autofill_profile_syncable_service_); | 225 EXPECT_TRUE(autofill_profile_syncable_service_); |
| 216 | 226 |
| 217 return autofill_profile_syncable_service_; | 227 return autofill_profile_syncable_service_; |
| 218 } | 228 } |
| 219 | 229 |
| 230 virtual void ShutdownOnUIThread() OVERRIDE {} |
| 231 |
| 220 private: | 232 private: |
| 221 void CreateSyncableService() { | 233 void CreateSyncableService() { |
| 222 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 234 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 223 // These services are deleted in DestroySyncableService(). | 235 // These services are deleted in DestroySyncableService(). |
| 224 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); | 236 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); |
| 225 autofill_profile_syncable_service_ = | 237 autofill_profile_syncable_service_ = |
| 226 new AutofillProfileSyncableService(this); | 238 new AutofillProfileSyncableService(this); |
| 227 syncable_service_created_or_destroyed_.Signal(); | 239 syncable_service_created_or_destroyed_.Signal(); |
| 228 } | 240 } |
| 229 | 241 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 MOCK_METHOD0(LoadProfiles, void()); | 346 MOCK_METHOD0(LoadProfiles, void()); |
| 335 MOCK_METHOD0(LoadCreditCards, void()); | 347 MOCK_METHOD0(LoadCreditCards, void()); |
| 336 MOCK_METHOD0(Refresh, void()); | 348 MOCK_METHOD0(Refresh, void()); |
| 337 }; | 349 }; |
| 338 template <class T> class AddAutofillHelper; | 350 template <class T> class AddAutofillHelper; |
| 339 | 351 |
| 340 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { | 352 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { |
| 341 protected: | 353 protected: |
| 342 ProfileSyncServiceAutofillTest() { | 354 ProfileSyncServiceAutofillTest() { |
| 343 } | 355 } |
| 356 virtual ~ProfileSyncServiceAutofillTest() { |
| 357 } |
| 344 | 358 |
| 345 AutofillProfileFactory profile_factory_; | 359 AutofillProfileFactory profile_factory_; |
| 346 AutofillEntryFactory entry_factory_; | 360 AutofillEntryFactory entry_factory_; |
| 347 | 361 |
| 348 AbstractAutofillFactory* GetFactory(syncable::ModelType type) { | 362 AbstractAutofillFactory* GetFactory(syncable::ModelType type) { |
| 349 if (type == syncable::AUTOFILL) { | 363 if (type == syncable::AUTOFILL) { |
| 350 return &entry_factory_; | 364 return &entry_factory_; |
| 351 } else if (type == syncable::AUTOFILL_PROFILE) { | 365 } else if (type == syncable::AUTOFILL_PROFILE) { |
| 352 return &profile_factory_; | 366 return &profile_factory_; |
| 353 } else { | 367 } else { |
| 354 NOTREACHED(); | 368 NOTREACHED(); |
| 355 return NULL; | 369 return NULL; |
| 356 } | 370 } |
| 357 } | 371 } |
| 358 | 372 |
| 359 virtual void SetUp() OVERRIDE { | 373 virtual void SetUp() OVERRIDE { |
| 360 AbstractProfileSyncServiceTest::SetUp(); | 374 AbstractProfileSyncServiceTest::SetUp(); |
| 361 profile_.CreateRequestContext(); | 375 profile_.CreateRequestContext(); |
| 362 web_database_.reset(new WebDatabaseFake(&autofill_table_)); | 376 web_database_.reset(new WebDatabaseFake(&autofill_table_)); |
| 363 web_data_service_ = new WebDataServiceFake(web_database_.get()); | 377 web_data_service_ = static_cast<WebDataServiceFake*>( |
| 378 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 379 &profile_, WebDataServiceFake::Build).get()); |
| 380 web_data_service_->SetDatabase(web_database_.get()); |
| 364 personal_data_manager_ = static_cast<PersonalDataManagerMock*>( | 381 personal_data_manager_ = static_cast<PersonalDataManagerMock*>( |
| 365 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 382 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 366 &profile_, PersonalDataManagerMock::Build)); | 383 &profile_, PersonalDataManagerMock::Build)); |
| 367 token_service_ = static_cast<TokenService*>( | 384 token_service_ = static_cast<TokenService*>( |
| 368 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 385 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 369 &profile_, BuildTokenService)); | 386 &profile_, BuildTokenService)); |
| 370 // GetHistoryService() gets called indirectly, but the result is ignored, so | 387 // GetHistoryService() gets called indirectly, but the result is ignored, so |
| 371 // it is safe to return NULL. | 388 // it is safe to return NULL. |
| 372 EXPECT_CALL(profile_, GetHistoryService(_)). | 389 EXPECT_CALL(profile_, GetHistoryService(_)). |
| 373 WillRepeatedly(Return(static_cast<HistoryService*>(NULL))); | 390 WillRepeatedly(Return(static_cast<HistoryService*>(NULL))); |
| 374 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); | 391 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); |
| 375 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); | 392 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); |
| 376 EXPECT_CALL(profile_, GetWebDataService(_)). | 393 |
| 377 // TokenService::Initialize | |
| 378 // AutofillDataTypeController::StartModels() | |
| 379 // In some tests: | |
| 380 // AutofillProfileSyncableService::AutofillProfileSyncableService() | |
| 381 WillRepeatedly(Return(web_data_service_.get())); | |
| 382 personal_data_manager_->Init(&profile_); | 394 personal_data_manager_->Init(&profile_); |
| 383 | 395 |
| 384 // Note: This must be called *after* the notification service is created. | 396 // Note: This must be called *after* the notification service is created. |
| 385 web_data_service_->StartSyncableService(); | 397 web_data_service_->StartSyncableService(); |
| 386 } | 398 } |
| 387 | 399 |
| 388 virtual void TearDown() OVERRIDE { | 400 virtual void TearDown() OVERRIDE { |
| 389 // Note: The tear down order is important. | 401 // Note: The tear down order is important. |
| 390 service_.reset(); | 402 service_.reset(); |
| 391 web_data_service_->ShutdownSyncableService(); | 403 web_data_service_->ShutdownSyncableService(); |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 std::vector<AutofillEntry> sync_entries; | 1237 std::vector<AutofillEntry> sync_entries; |
| 1226 std::vector<AutofillProfile> sync_profiles; | 1238 std::vector<AutofillProfile> sync_profiles; |
| 1227 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1239 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1228 EXPECT_EQ(3U, sync_entries.size()); | 1240 EXPECT_EQ(3U, sync_entries.size()); |
| 1229 EXPECT_EQ(0U, sync_profiles.size()); | 1241 EXPECT_EQ(0U, sync_profiles.size()); |
| 1230 for (size_t i = 0; i < sync_entries.size(); i++) { | 1242 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1231 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1243 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1232 << ", " << sync_entries[i].key().value(); | 1244 << ", " << sync_entries[i].key().value(); |
| 1233 } | 1245 } |
| 1234 } | 1246 } |
| OLD | NEW |