| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 #include "base/bind.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/location.h" | 13 #include "base/location.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 16 #include "base/string16.h" | 17 #include "base/string16.h" |
| 17 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/task.h" | 19 #include "base/task.h" |
| 19 #include "base/time.h" | 20 #include "base/time.h" |
| 20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "content/browser/browser_thread.h" | 54 #include "content/browser/browser_thread.h" |
| 54 #include "content/common/notification_source.h" | 55 #include "content/common/notification_source.h" |
| 55 #include "testing/gmock/include/gmock/gmock.h" | 56 #include "testing/gmock/include/gmock/gmock.h" |
| 56 | 57 |
| 57 using base::Time; | 58 using base::Time; |
| 58 using base::WaitableEvent; | 59 using base::WaitableEvent; |
| 59 using browser_sync::AutofillChangeProcessor; | 60 using browser_sync::AutofillChangeProcessor; |
| 60 using browser_sync::AutofillDataTypeController; | 61 using browser_sync::AutofillDataTypeController; |
| 61 using browser_sync::AutofillModelAssociator; | 62 using browser_sync::AutofillModelAssociator; |
| 62 using browser_sync::AutofillProfileDataTypeController; | 63 using browser_sync::AutofillProfileDataTypeController; |
| 63 using browser_sync::AutofillProfileSyncableService; | |
| 64 using browser_sync::DataTypeController; | 64 using browser_sync::DataTypeController; |
| 65 using browser_sync::GenericChangeProcessor; | 65 using browser_sync::GenericChangeProcessor; |
| 66 using browser_sync::SyncableServiceAdapter; | 66 using browser_sync::SyncableServiceAdapter; |
| 67 using browser_sync::GROUP_DB; | 67 using browser_sync::GROUP_DB; |
| 68 using browser_sync::kAutofillTag; | 68 using browser_sync::kAutofillTag; |
| 69 using browser_sync::SyncBackendHostForProfileSyncTest; | 69 using browser_sync::SyncBackendHostForProfileSyncTest; |
| 70 using browser_sync::UnrecoverableErrorHandler; | 70 using browser_sync::UnrecoverableErrorHandler; |
| 71 using syncable::CREATE_NEW_UPDATE_ITEM; | 71 using syncable::CREATE_NEW_UPDATE_ITEM; |
| 72 using syncable::AUTOFILL; | 72 using syncable::AUTOFILL; |
| 73 using syncable::BASE_VERSION; | 73 using syncable::BASE_VERSION; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 146 } |
| 147 | 147 |
| 148 template<> | 148 template<> |
| 149 syncable::ModelType GetModelType<AutofillProfile>() { | 149 syncable::ModelType GetModelType<AutofillProfile>() { |
| 150 return syncable::AUTOFILL_PROFILE; | 150 return syncable::AUTOFILL_PROFILE; |
| 151 } | 151 } |
| 152 | 152 |
| 153 class WebDataServiceFake : public WebDataService { | 153 class WebDataServiceFake : public WebDataService { |
| 154 public: | 154 public: |
| 155 explicit WebDataServiceFake(WebDatabase* web_database) | 155 explicit WebDataServiceFake(WebDatabase* web_database) |
| 156 : web_database_(web_database) {} | 156 : web_database_(web_database), |
| 157 syncable_service_created_or_destroyed_(false, false) { |
| 158 } |
| 159 |
| 160 void StartSyncableService() { |
| 161 // The |autofill_profile_syncable_service_| must be constructed on the DB |
| 162 // thread. |
| 163 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 164 base::Bind(&WebDataServiceFake::CreateSyncableService, |
| 165 base::Unretained(this))); |
| 166 EXPECT_TRUE(syncable_service_created_or_destroyed_.Wait()); |
| 167 } |
| 168 |
| 169 void ShutdownSyncableService() { |
| 170 // The |autofill_profile_syncable_service_| must be destructed on the DB |
| 171 // thread. |
| 172 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 173 base::Bind(&WebDataServiceFake::DestroySyncableService, |
| 174 base::Unretained(this))); |
| 175 EXPECT_TRUE(syncable_service_created_or_destroyed_.Wait()); |
| 176 } |
| 177 |
| 157 virtual bool IsDatabaseLoaded() { | 178 virtual bool IsDatabaseLoaded() { |
| 158 return true; | 179 return true; |
| 159 } | 180 } |
| 160 | 181 |
| 161 virtual WebDatabase* GetDatabase() { | 182 virtual WebDatabase* GetDatabase() { |
| 162 return web_database_; | 183 return web_database_; |
| 163 } | 184 } |
| 164 | 185 |
| 186 virtual AutofillProfileSyncableService* |
| 187 GetAutofillProfileSyncableService() const OVERRIDE { |
| 188 return autofill_profile_syncable_service_; |
| 189 } |
| 190 |
| 165 private: | 191 private: |
| 192 void CreateSyncableService() { |
| 193 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 194 autofill_profile_syncable_service_ = |
| 195 new AutofillProfileSyncableService(this); |
| 196 syncable_service_created_or_destroyed_.Signal(); |
| 197 } |
| 198 |
| 199 void DestroySyncableService() { |
| 200 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 201 delete autofill_profile_syncable_service_; |
| 202 syncable_service_created_or_destroyed_.Signal(); |
| 203 } |
| 204 |
| 166 WebDatabase* web_database_; | 205 WebDatabase* web_database_; |
| 206 |
| 207 // We own the syncable service, but don't use a |scoped_ptr| because the |
| 208 // lifetime must be managed on the DB thread. |
| 209 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
| 210 WaitableEvent syncable_service_created_or_destroyed_; |
| 167 }; | 211 }; |
| 168 | 212 |
| 169 ACTION_P3(MakeAutofillSyncComponents, service, wd, dtc) { | 213 ACTION_P3(MakeAutofillSyncComponents, service, wd, dtc) { |
| 170 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 214 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 171 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 215 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
| 172 return ProfileSyncFactory::SyncComponents(NULL, NULL); | 216 return ProfileSyncFactory::SyncComponents(NULL, NULL); |
| 173 AutofillModelAssociator* model_associator = | 217 AutofillModelAssociator* model_associator = |
| 174 new AutofillModelAssociator(service, wd, service->profile()); | 218 new AutofillModelAssociator(service, wd, service->profile()); |
| 175 AutofillChangeProcessor* change_processor = | 219 AutofillChangeProcessor* change_processor = |
| 176 new AutofillChangeProcessor(model_associator, wd, | 220 new AutofillChangeProcessor(model_associator, wd, |
| 177 service->profile(), dtc); | 221 service->profile(), dtc); |
| 178 return ProfileSyncFactory::SyncComponents(model_associator, | 222 return ProfileSyncFactory::SyncComponents(model_associator, |
| 179 change_processor); | 223 change_processor); |
| 180 } | 224 } |
| 181 | 225 |
| 182 ACTION_P3(MakeAutofillProfileSyncComponents, service, wds, dtc) { | 226 ACTION_P3(MakeAutofillProfileSyncComponents, service, wds, dtc) { |
| 183 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 227 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 184 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 228 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
| 185 return ProfileSyncFactory::SyncComponents(NULL, NULL); | 229 return ProfileSyncFactory::SyncComponents(NULL, NULL); |
| 186 AutofillProfileSyncableService* sync_service = | 230 AutofillProfileSyncableService* sync_service = |
| 187 new AutofillProfileSyncableService(wds); | 231 wds->GetAutofillProfileSyncableService(); |
| 188 sync_api::UserShare* user_share = service->GetUserShare(); | 232 sync_api::UserShare* user_share = service->GetUserShare(); |
| 189 GenericChangeProcessor* change_processor = | 233 GenericChangeProcessor* change_processor = |
| 190 new GenericChangeProcessor(sync_service, dtc, user_share); | 234 new GenericChangeProcessor(sync_service, dtc, user_share); |
| 191 SyncableServiceAdapter* sync_service_adapter = | 235 SyncableServiceAdapter* sync_service_adapter = |
| 192 new SyncableServiceAdapter(syncable::AUTOFILL_PROFILE, | 236 new SyncableServiceAdapter(syncable::AUTOFILL_PROFILE, |
| 193 sync_service, | 237 sync_service, |
| 194 change_processor); | 238 change_processor); |
| 195 return ProfileSyncFactory::SyncComponents(sync_service_adapter, | 239 return ProfileSyncFactory::SyncComponents(sync_service_adapter, |
| 196 change_processor); | 240 change_processor); |
| 197 } | 241 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 208 DataTypeController* dtc) = 0; | 252 DataTypeController* dtc) = 0; |
| 209 virtual ~AbstractAutofillFactory() {} | 253 virtual ~AbstractAutofillFactory() {} |
| 210 }; | 254 }; |
| 211 | 255 |
| 212 class AutofillEntryFactory : public AbstractAutofillFactory { | 256 class AutofillEntryFactory : public AbstractAutofillFactory { |
| 213 public: | 257 public: |
| 214 browser_sync::AutofillDataTypeController* CreateDataTypeController( | 258 browser_sync::AutofillDataTypeController* CreateDataTypeController( |
| 215 ProfileSyncFactory* factory, | 259 ProfileSyncFactory* factory, |
| 216 ProfileMock* profile, | 260 ProfileMock* profile, |
| 217 ProfileSyncService* service) { | 261 ProfileSyncService* service) { |
| 218 return new AutofillDataTypeController(factory, | 262 return new AutofillDataTypeController(factory, profile); |
| 219 profile); | |
| 220 } | 263 } |
| 221 | 264 |
| 222 void SetExpectation(ProfileSyncFactoryMock* factory, | 265 void SetExpectation(ProfileSyncFactoryMock* factory, |
| 223 ProfileSyncService* service, | 266 ProfileSyncService* service, |
| 224 WebDataService* wds, | 267 WebDataService* wds, |
| 225 DataTypeController* dtc) { | 268 DataTypeController* dtc) { |
| 226 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_)). | 269 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_)). |
| 227 WillOnce(MakeAutofillSyncComponents(service, wds->GetDatabase(), dtc)); | 270 WillOnce(MakeAutofillSyncComponents(service, wds->GetDatabase(), dtc)); |
| 228 } | 271 } |
| 229 }; | 272 }; |
| 230 | 273 |
| 231 class AutofillProfileFactory : public AbstractAutofillFactory { | 274 class AutofillProfileFactory : public AbstractAutofillFactory { |
| 232 public: | 275 public: |
| 233 browser_sync::AutofillDataTypeController* CreateDataTypeController( | 276 browser_sync::AutofillDataTypeController* CreateDataTypeController( |
| 234 ProfileSyncFactory* factory, | 277 ProfileSyncFactory* factory, |
| 235 ProfileMock* profile, | 278 ProfileMock* profile, |
| 236 ProfileSyncService* service) { | 279 ProfileSyncService* service) { |
| 237 return new AutofillProfileDataTypeController(factory, | 280 return new AutofillProfileDataTypeController(factory, profile); |
| 238 profile); | |
| 239 } | 281 } |
| 240 | 282 |
| 241 void SetExpectation(ProfileSyncFactoryMock* factory, | 283 void SetExpectation(ProfileSyncFactoryMock* factory, |
| 242 ProfileSyncService* service, | 284 ProfileSyncService* service, |
| 243 WebDataService* wds, | 285 WebDataService* wds, |
| 244 DataTypeController* dtc) { | 286 DataTypeController* dtc) { |
| 245 EXPECT_CALL(*factory, CreateAutofillProfileSyncComponents(_,_,_)). | 287 EXPECT_CALL(*factory, CreateAutofillProfileSyncComponents(_,_,_)). |
| 246 WillOnce(MakeAutofillProfileSyncComponents(service, wds, dtc)); | 288 WillOnce(MakeAutofillProfileSyncComponents(service, wds, dtc)); |
| 247 } | 289 } |
| 248 }; | 290 }; |
| 249 | 291 |
| 250 class PersonalDataManagerMock: public PersonalDataManager { | 292 class PersonalDataManagerMock: public PersonalDataManager { |
| 251 public: | 293 public: |
| 252 static ProfileKeyedService* Build(Profile* profile) { | 294 static ProfileKeyedService* Build(Profile* profile) { |
| 253 return new PersonalDataManagerMock; | 295 return new PersonalDataManagerMock; |
| 254 } | 296 } |
| 255 | 297 |
| 256 MOCK_CONST_METHOD0(IsDataLoaded, bool()); | 298 MOCK_CONST_METHOD0(IsDataLoaded, bool()); |
| 257 MOCK_METHOD0(LoadProfiles, void()); | 299 MOCK_METHOD0(LoadProfiles, void()); |
| 258 MOCK_METHOD0(LoadCreditCards, void()); | 300 MOCK_METHOD0(LoadCreditCards, void()); |
| 259 MOCK_METHOD0(Refresh, void()); | 301 MOCK_METHOD0(Refresh, void()); |
| 260 }; | 302 }; |
| 261 template <class T> class AddAutofillTask; | 303 template <class T> class AddAutofillTask; |
| 262 | 304 |
| 263 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { | 305 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { |
| 264 protected: | 306 protected: |
| 265 ProfileSyncServiceAutofillTest() {} | 307 ProfileSyncServiceAutofillTest() { |
| 308 } |
| 266 | 309 |
| 267 AutofillProfileFactory profile_factory_; | 310 AutofillProfileFactory profile_factory_; |
| 268 AutofillEntryFactory entry_factory_; | 311 AutofillEntryFactory entry_factory_; |
| 269 | 312 |
| 270 AbstractAutofillFactory* GetFactory(syncable::ModelType type) { | 313 AbstractAutofillFactory* GetFactory(syncable::ModelType type) { |
| 271 if (type == syncable::AUTOFILL) { | 314 if (type == syncable::AUTOFILL) { |
| 272 return &entry_factory_; | 315 return &entry_factory_; |
| 273 } else if (type == syncable::AUTOFILL_PROFILE) { | 316 } else if (type == syncable::AUTOFILL_PROFILE) { |
| 274 return &profile_factory_; | 317 return &profile_factory_; |
| 275 } else { | 318 } else { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 291 EXPECT_CALL(profile_, GetWebDataService(_)). | 334 EXPECT_CALL(profile_, GetWebDataService(_)). |
| 292 // TokenService::Initialize | 335 // TokenService::Initialize |
| 293 // AutofillDataTypeController::StartModels() | 336 // AutofillDataTypeController::StartModels() |
| 294 // In some tests: | 337 // In some tests: |
| 295 // AutofillProfileSyncableService::AutofillProfileSyncableService() | 338 // AutofillProfileSyncableService::AutofillProfileSyncableService() |
| 296 WillRepeatedly(Return(web_data_service_.get())); | 339 WillRepeatedly(Return(web_data_service_.get())); |
| 297 personal_data_manager_->Init(&profile_); | 340 personal_data_manager_->Init(&profile_); |
| 298 | 341 |
| 299 notification_service_ = new ThreadNotificationService(&db_thread_); | 342 notification_service_ = new ThreadNotificationService(&db_thread_); |
| 300 notification_service_->Init(); | 343 notification_service_->Init(); |
| 344 |
| 345 // Note: This must be called *after* the notification service is created. |
| 346 web_data_service_->StartSyncableService(); |
| 301 } | 347 } |
| 302 | 348 |
| 303 virtual void TearDown() { | 349 virtual void TearDown() { |
| 350 // Note: The tear down order is important. |
| 304 service_.reset(); | 351 service_.reset(); |
| 352 web_data_service_->ShutdownSyncableService(); |
| 305 notification_service_->TearDown(); | 353 notification_service_->TearDown(); |
| 306 profile_.ResetRequestContext(); | 354 profile_.ResetRequestContext(); |
| 307 AbstractProfileSyncServiceTest::TearDown(); | 355 AbstractProfileSyncServiceTest::TearDown(); |
| 308 } | 356 } |
| 309 | 357 |
| 310 void StartSyncService(Task* task, | 358 void StartSyncService(Task* task, |
| 311 bool will_fail_association, | 359 bool will_fail_association, |
| 312 syncable::ModelType type) { | 360 syncable::ModelType type) { |
| 313 AbstractAutofillFactory* factory = GetFactory(type); | 361 AbstractAutofillFactory* factory = GetFactory(type); |
| 314 service_.reset( | 362 service_.reset( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 328 web_data_service_.get(), | 376 web_data_service_.get(), |
| 329 data_type_controller); | 377 data_type_controller); |
| 330 | 378 |
| 331 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 379 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
| 332 WillOnce(ReturnNewDataTypeManager()); | 380 WillOnce(ReturnNewDataTypeManager()); |
| 333 | 381 |
| 334 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). | 382 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). |
| 335 WillRepeatedly(Return(true)); | 383 WillRepeatedly(Return(true)); |
| 336 | 384 |
| 337 // We need tokens to get the tests going | 385 // We need tokens to get the tests going |
| 338 token_service_->IssueAuthTokenForTest( | 386 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token"); |
| 339 GaiaConstants::kSyncService, "token"); | |
| 340 | 387 |
| 341 EXPECT_CALL(profile_, GetTokenService()). | 388 EXPECT_CALL(profile_, GetTokenService()). |
| 342 WillRepeatedly(Return(token_service_.get())); | 389 WillRepeatedly(Return(token_service_.get())); |
| 343 | 390 |
| 344 service_->RegisterDataTypeController(data_type_controller); | 391 service_->RegisterDataTypeController(data_type_controller); |
| 345 service_->Initialize(); | 392 service_->Initialize(); |
| 346 MessageLoop::current()->Run(); | 393 MessageLoop::current()->Run(); |
| 347 } | 394 } |
| 348 | 395 |
| 349 bool AddAutofillSyncNode(const AutofillEntry& entry) { | 396 bool AddAutofillSyncNode(const AutofillEntry& entry) { |
| 350 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 397 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 351 sync_api::ReadNode autofill_root(&trans); | 398 sync_api::ReadNode autofill_root(&trans); |
| 352 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) | 399 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) |
| 353 return false; | 400 return false; |
| 354 | 401 |
| 355 sync_api::WriteNode node(&trans); | 402 sync_api::WriteNode node(&trans); |
| 356 std::string tag = AutofillModelAssociator::KeyToTag(entry.key().name(), | 403 std::string tag = AutofillModelAssociator::KeyToTag(entry.key().name(), |
| 357 entry.key().value()); | 404 entry.key().value()); |
| 358 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) | 405 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) |
| 359 return false; | 406 return false; |
| 360 | 407 |
| 361 AutofillChangeProcessor::WriteAutofillEntry(entry, &node); | 408 AutofillChangeProcessor::WriteAutofillEntry(entry, &node); |
| 362 return true; | 409 return true; |
| 363 } | 410 } |
| 364 | 411 |
| 365 bool AddAutofillSyncNode(const AutofillProfile& profile) { | 412 bool AddAutofillSyncNode(const AutofillProfile& profile) { |
| 366 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 413 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 367 sync_api::ReadNode autofill_root(&trans); | 414 sync_api::ReadNode autofill_root(&trans); |
| 368 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 415 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) |
| 369 return false; | 416 return false; |
| 370 sync_api::WriteNode node(&trans); | 417 sync_api::WriteNode node(&trans); |
| 371 std::string tag = profile.guid(); | 418 std::string tag = profile.guid(); |
| 372 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, | 419 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, |
| 373 autofill_root, tag)) | 420 autofill_root, tag)) |
| 374 return false; | 421 return false; |
| 375 sync_pb::EntitySpecifics specifics; | 422 sync_pb::EntitySpecifics specifics; |
| 376 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); | 423 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); |
| 377 sync_pb::AutofillProfileSpecifics* profile_specifics = | 424 sync_pb::AutofillProfileSpecifics* profile_specifics = |
| 378 specifics.MutableExtension(sync_pb::autofill_profile); | 425 specifics.MutableExtension(sync_pb::autofill_profile); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 461 } |
| 415 child_id = child_node.GetSuccessorId(); | 462 child_id = child_node.GetSuccessorId(); |
| 416 } | 463 } |
| 417 return true; | 464 return true; |
| 418 } | 465 } |
| 419 | 466 |
| 420 bool GetAutofillProfilesFromSyncDBUnderProfileNode( | 467 bool GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 421 std::vector<AutofillProfile>* profiles) { | 468 std::vector<AutofillProfile>* profiles) { |
| 422 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 469 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 423 sync_api::ReadNode autofill_root(&trans); | 470 sync_api::ReadNode autofill_root(&trans); |
| 424 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 471 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) |
| 425 return false; | 472 return false; |
| 426 | 473 |
| 427 int64 child_id = autofill_root.GetFirstChildId(); | 474 int64 child_id = autofill_root.GetFirstChildId(); |
| 428 while (child_id != sync_api::kInvalidId) { | 475 while (child_id != sync_api::kInvalidId) { |
| 429 sync_api::ReadNode child_node(&trans); | 476 sync_api::ReadNode child_node(&trans); |
| 430 if (!child_node.InitByIdLookup(child_id)) | 477 if (!child_node.InitByIdLookup(child_id)) |
| 431 return false; | 478 return false; |
| 432 | 479 |
| 433 const sync_pb::AutofillProfileSpecifics& autofill( | 480 const sync_pb::AutofillProfileSpecifics& autofill( |
| 434 child_node.GetAutofillProfileSpecifics()); | 481 child_node.GetAutofillProfileSpecifics()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 516 |
| 470 friend class AddAutofillTask<AutofillEntry>; | 517 friend class AddAutofillTask<AutofillEntry>; |
| 471 friend class AddAutofillTask<AutofillProfile>; | 518 friend class AddAutofillTask<AutofillProfile>; |
| 472 friend class FakeServerUpdater; | 519 friend class FakeServerUpdater; |
| 473 | 520 |
| 474 scoped_refptr<ThreadNotificationService> notification_service_; | 521 scoped_refptr<ThreadNotificationService> notification_service_; |
| 475 | 522 |
| 476 ProfileMock profile_; | 523 ProfileMock profile_; |
| 477 AutofillTableMock autofill_table_; | 524 AutofillTableMock autofill_table_; |
| 478 scoped_ptr<WebDatabaseFake> web_database_; | 525 scoped_ptr<WebDatabaseFake> web_database_; |
| 479 scoped_refptr<WebDataService> web_data_service_; | 526 scoped_refptr<WebDataServiceFake> web_data_service_; |
| 480 PersonalDataManagerMock* personal_data_manager_; | 527 PersonalDataManagerMock* personal_data_manager_; |
| 481 }; | 528 }; |
| 482 | 529 |
| 483 template <class T> | 530 template <class T> |
| 484 class AddAutofillTask : public Task { | 531 class AddAutofillTask : public Task { |
| 485 public: | 532 public: |
| 486 AddAutofillTask(ProfileSyncServiceAutofillTest* test, | 533 AddAutofillTask(ProfileSyncServiceAutofillTest* test, |
| 487 const std::vector<T>& entries) | 534 const std::vector<T>& entries) |
| 488 : test_(test), entries_(entries), success_(false) { | 535 : test_(test), entries_(entries), success_(false) { |
| 489 } | 536 } |
| 490 | 537 |
| 491 virtual void Run() { | 538 virtual void Run() { |
| 492 if (!test_->CreateRoot(GetModelType<T>())) | 539 if (!test_->CreateRoot(GetModelType<T>())) |
| 493 return; | 540 return; |
| 494 for (size_t i = 0; i < entries_.size(); ++i) { | 541 for (size_t i = 0; i < entries_.size(); ++i) { |
| 495 if (!test_->AddAutofillSyncNode(entries_[i])) | 542 if (!test_->AddAutofillSyncNode(entries_[i])) |
| 496 return; | 543 return; |
| 497 } | 544 } |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 std::vector<AutofillEntry> sync_entries; | 1140 std::vector<AutofillEntry> sync_entries; |
| 1094 std::vector<AutofillProfile> sync_profiles; | 1141 std::vector<AutofillProfile> sync_profiles; |
| 1095 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1142 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1096 EXPECT_EQ(3U, sync_entries.size()); | 1143 EXPECT_EQ(3U, sync_entries.size()); |
| 1097 EXPECT_EQ(0U, sync_profiles.size()); | 1144 EXPECT_EQ(0U, sync_profiles.size()); |
| 1098 for (size_t i = 0; i < sync_entries.size(); i++) { | 1145 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1099 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1146 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1100 << ", " << sync_entries[i].key().value(); | 1147 << ", " << sync_entries[i].key().value(); |
| 1101 } | 1148 } |
| 1102 } | 1149 } |
| OLD | NEW |