| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/sync/glue/autofill_model_associator.h" | 28 #include "chrome/browser/sync/glue/autofill_model_associator.h" |
| 29 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" | 29 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" |
| 30 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" | 30 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" |
| 31 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" | 31 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" |
| 32 #include "chrome/browser/sync/glue/data_type_controller.h" | 32 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 33 #include "chrome/browser/sync/profile_sync_factory.h" | 33 #include "chrome/browser/sync/profile_sync_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_test_util.h" | 35 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 36 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 36 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 37 #include "chrome/browser/sync/syncable/autofill_migration.h" | 37 #include "chrome/browser/sync/syncable/autofill_migration.h" |
| 38 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 38 #include "chrome/browser/sync/syncable/syncable.h" | 39 #include "chrome/browser/sync/syncable/syncable.h" |
| 39 #include "chrome/browser/sync/syncable/model_type.h" | 40 #include "chrome/browser/sync/syncable/model_type.h" |
| 40 #include "chrome/browser/sync/test_profile_sync_service.h" | 41 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 41 #include "chrome/browser/webdata/autofill_change.h" | 42 #include "chrome/browser/webdata/autofill_change.h" |
| 42 #include "chrome/browser/webdata/autofill_entry.h" | 43 #include "chrome/browser/webdata/autofill_entry.h" |
| 43 #include "chrome/browser/webdata/web_database.h" | 44 #include "chrome/browser/webdata/web_database.h" |
| 44 #include "chrome/common/net/gaia/gaia_constants.h" | 45 #include "chrome/common/net/gaia/gaia_constants.h" |
| 45 #include "chrome/common/notification_source.h" | 46 #include "chrome/common/notification_source.h" |
| 46 #include "chrome/common/notification_type.h" | 47 #include "chrome/common/notification_type.h" |
| 47 #include "chrome/test/profile_mock.h" | 48 #include "chrome/test/profile_mock.h" |
| 48 #include "chrome/test/sync/engine/test_id_factory.h" | 49 #include "chrome/test/sync/engine/test_id_factory.h" |
| 49 #include "testing/gmock/include/gmock/gmock.h" | 50 #include "testing/gmock/include/gmock/gmock.h" |
| 50 | 51 |
| 51 using base::Time; | 52 using base::Time; |
| 52 using base::WaitableEvent; | 53 using base::WaitableEvent; |
| 53 using browser_sync::AutofillChangeProcessor; | 54 using browser_sync::AutofillChangeProcessor; |
| 54 using browser_sync::AutofillDataTypeController; | 55 using browser_sync::AutofillDataTypeController; |
| 55 using browser_sync::AutofillModelAssociator; | 56 using browser_sync::AutofillModelAssociator; |
| 56 using browser_sync::AutofillProfileChangeProcessor; | 57 using browser_sync::AutofillProfileChangeProcessor; |
| 57 using browser_sync::AutofillProfileDataTypeController; | 58 using browser_sync::AutofillProfileDataTypeController; |
| 58 using browser_sync::AutofillProfileModelAssociator; | 59 using browser_sync::AutofillProfileModelAssociator; |
| 59 using browser_sync::DataTypeController; | 60 using browser_sync::DataTypeController; |
| 60 using browser_sync::GROUP_DB; | 61 using browser_sync::GROUP_DB; |
| 61 using browser_sync::kAutofillTag; | 62 using browser_sync::kAutofillTag; |
| 62 using browser_sync::SyncBackendHostForProfileSyncTest; | 63 using browser_sync::SyncBackendHostForProfileSyncTest; |
| 63 using browser_sync::SyncerUtil; | 64 using browser_sync::SyncerUtil; |
| 64 using browser_sync::UnrecoverableErrorHandler; | 65 using browser_sync::UnrecoverableErrorHandler; |
| 65 using syncable::CREATE_NEW_UPDATE_ITEM; | 66 using syncable::CREATE_NEW_UPDATE_ITEM; |
| 66 using syncable::AUTOFILL; | 67 using syncable::AUTOFILL; |
| 68 using syncable::BASE_VERSION; |
| 69 using syncable::CREATE; |
| 67 using syncable::DirectoryChangeEvent; | 70 using syncable::DirectoryChangeEvent; |
| 68 using syncable::GET_BY_SERVER_TAG; | 71 using syncable::GET_BY_SERVER_TAG; |
| 69 using syncable::INVALID; | 72 using syncable::INVALID; |
| 73 using syncable::MutableEntry; |
| 74 using syncable::OriginalEntries; |
| 70 using syncable::SERVER_PARENT_ID; | 75 using syncable::SERVER_PARENT_ID; |
| 71 using syncable::SERVER_SPECIFICS; | 76 using syncable::SERVER_SPECIFICS; |
| 72 using syncable::OriginalEntries; | 77 using syncable::SPECIFICS; |
| 78 using syncable::UNITTEST; |
| 73 using syncable::WriterTag; | 79 using syncable::WriterTag; |
| 74 using syncable::WriteTransaction; | 80 using syncable::WriteTransaction; |
| 75 using testing::_; | 81 using testing::_; |
| 76 using testing::DoAll; | 82 using testing::DoAll; |
| 77 using testing::DoDefault; | 83 using testing::DoDefault; |
| 78 using testing::ElementsAre; | 84 using testing::ElementsAre; |
| 79 using testing::Eq; | 85 using testing::Eq; |
| 80 using testing::Invoke; | 86 using testing::Invoke; |
| 81 using testing::Mock; | 87 using testing::Mock; |
| 82 using testing::Return; | 88 using testing::Return; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 EXPECT_CALL(profile_, GetTokenService()). | 313 EXPECT_CALL(profile_, GetTokenService()). |
| 308 WillRepeatedly(Return(&token_service_)); | 314 WillRepeatedly(Return(&token_service_)); |
| 309 | 315 |
| 310 service_->set_num_expected_resumes(will_fail_association ? 0 : 1); | 316 service_->set_num_expected_resumes(will_fail_association ? 0 : 1); |
| 311 service_->RegisterDataTypeController(data_type_controller); | 317 service_->RegisterDataTypeController(data_type_controller); |
| 312 service_->Initialize(); | 318 service_->Initialize(); |
| 313 MessageLoop::current()->Run(); | 319 MessageLoop::current()->Run(); |
| 314 } | 320 } |
| 315 | 321 |
| 316 bool AddAutofillSyncNode(const AutofillEntry& entry) { | 322 bool AddAutofillSyncNode(const AutofillEntry& entry) { |
| 317 sync_api::WriteTransaction trans( | 323 sync_api::WriteTransaction trans(service_->GetUserShare()); |
| 318 service_->backend()->GetUserShareHandle()); | |
| 319 sync_api::ReadNode autofill_root(&trans); | 324 sync_api::ReadNode autofill_root(&trans); |
| 320 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) | 325 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) |
| 321 return false; | 326 return false; |
| 322 | 327 |
| 323 sync_api::WriteNode node(&trans); | 328 sync_api::WriteNode node(&trans); |
| 324 std::string tag = AutofillModelAssociator::KeyToTag(entry.key().name(), | 329 std::string tag = AutofillModelAssociator::KeyToTag(entry.key().name(), |
| 325 entry.key().value()); | 330 entry.key().value()); |
| 326 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) | 331 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) |
| 327 return false; | 332 return false; |
| 328 | 333 |
| 329 AutofillChangeProcessor::WriteAutofillEntry(entry, &node); | 334 AutofillChangeProcessor::WriteAutofillEntry(entry, &node); |
| 330 return true; | 335 return true; |
| 331 } | 336 } |
| 332 | 337 |
| 333 bool AddAutofillSyncNode(const AutoFillProfile& profile) { | 338 bool AddAutofillSyncNode(const AutoFillProfile& profile) { |
| 334 sync_api::WriteTransaction trans( | 339 sync_api::WriteTransaction trans(service_->GetUserShare()); |
| 335 service_->backend()->GetUserShareHandle()); | |
| 336 sync_api::ReadNode autofill_root(&trans); | 340 sync_api::ReadNode autofill_root(&trans); |
| 337 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 341 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) |
| 338 return false; | 342 return false; |
| 339 sync_api::WriteNode node(&trans); | 343 sync_api::WriteNode node(&trans); |
| 340 std::string tag = profile.guid(); | 344 std::string tag = profile.guid(); |
| 341 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, | 345 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, |
| 342 autofill_root, tag)) | 346 autofill_root, tag)) |
| 343 return false; | 347 return false; |
| 344 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); | 348 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); |
| 345 return true; | 349 return true; |
| 346 } | 350 } |
| 347 | 351 |
| 348 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, | 352 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, |
| 349 std::vector<AutoFillProfile>* profiles) { | 353 std::vector<AutoFillProfile>* profiles) { |
| 350 sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle()); | 354 sync_api::ReadTransaction trans(service_->GetUserShare()); |
| 351 sync_api::ReadNode autofill_root(&trans); | 355 sync_api::ReadNode autofill_root(&trans); |
| 352 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) | 356 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) |
| 353 return false; | 357 return false; |
| 354 | 358 |
| 355 int64 child_id = autofill_root.GetFirstChildId(); | 359 int64 child_id = autofill_root.GetFirstChildId(); |
| 356 while (child_id != sync_api::kInvalidId) { | 360 while (child_id != sync_api::kInvalidId) { |
| 357 sync_api::ReadNode child_node(&trans); | 361 sync_api::ReadNode child_node(&trans); |
| 358 if (!child_node.InitByIdLookup(child_id)) | 362 if (!child_node.InitByIdLookup(child_id)) |
| 359 return false; | 363 return false; |
| 360 | 364 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 377 autofill.profile()); | 381 autofill.profile()); |
| 378 profiles->push_back(p); | 382 profiles->push_back(p); |
| 379 } | 383 } |
| 380 child_id = child_node.GetSuccessorId(); | 384 child_id = child_node.GetSuccessorId(); |
| 381 } | 385 } |
| 382 return true; | 386 return true; |
| 383 } | 387 } |
| 384 | 388 |
| 385 bool GetAutofillProfilesFromSyncDBUnderProfileNode( | 389 bool GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 386 std::vector<AutoFillProfile>* profiles) { | 390 std::vector<AutoFillProfile>* profiles) { |
| 387 sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle()); | 391 sync_api::ReadTransaction trans(service_->GetUserShare()); |
| 388 sync_api::ReadNode autofill_root(&trans); | 392 sync_api::ReadNode autofill_root(&trans); |
| 389 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 393 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) |
| 390 return false; | 394 return false; |
| 391 | 395 |
| 392 int64 child_id = autofill_root.GetFirstChildId(); | 396 int64 child_id = autofill_root.GetFirstChildId(); |
| 393 while (child_id != sync_api::kInvalidId) { | 397 while (child_id != sync_api::kInvalidId) { |
| 394 sync_api::ReadNode child_node(&trans); | 398 sync_api::ReadNode child_node(&trans); |
| 395 if (!child_node.InitByIdLookup(child_id)) | 399 if (!child_node.InitByIdLookup(child_id)) |
| 396 return false; | 400 return false; |
| 397 | 401 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 private: | 471 private: |
| 468 ProfileSyncServiceAutofillTest* test_; | 472 ProfileSyncServiceAutofillTest* test_; |
| 469 const std::vector<T>& entries_; | 473 const std::vector<T>& entries_; |
| 470 bool success_; | 474 bool success_; |
| 471 }; | 475 }; |
| 472 | 476 |
| 473 // Overload write transaction to use custom NotifyTransactionComplete | 477 // Overload write transaction to use custom NotifyTransactionComplete |
| 474 static const bool kLoggingInfo = true; | 478 static const bool kLoggingInfo = true; |
| 475 class WriteTransactionTest: public WriteTransaction { | 479 class WriteTransactionTest: public WriteTransaction { |
| 476 public: | 480 public: |
| 477 WriteTransactionTest(const ScopedDirLookup& directory, | 481 WriteTransactionTest(const syncable::ScopedDirLookup& directory, |
| 478 WriterTag writer, const char* source_file, | 482 WriterTag writer, const char* source_file, |
| 479 int line, | 483 int line, |
| 480 scoped_ptr<WaitableEvent> *wait_for_syncapi) | 484 scoped_ptr<WaitableEvent> *wait_for_syncapi) |
| 481 : WriteTransaction(directory, writer, source_file, line), | 485 : WriteTransaction(directory, writer, source_file, line), |
| 482 wait_for_syncapi_(wait_for_syncapi) { } | 486 wait_for_syncapi_(wait_for_syncapi) { } |
| 483 | 487 |
| 484 virtual void NotifyTransactionComplete() { | 488 virtual void NotifyTransactionComplete() { |
| 485 // This is where we differ. Force a thread change here, giving another | 489 // This is where we differ. Force a thread change here, giving another |
| 486 // thread a chance to create a WriteTransaction | 490 // thread a chance to create a WriteTransaction |
| 487 (*wait_for_syncapi_)->Wait(); | 491 (*wait_for_syncapi_)->Wait(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 503 : entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)), | 507 : entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)), |
| 504 service_(service), | 508 service_(service), |
| 505 wait_for_start_(wait_for_start), | 509 wait_for_start_(wait_for_start), |
| 506 wait_for_syncapi_(wait_for_syncapi), | 510 wait_for_syncapi_(wait_for_syncapi), |
| 507 is_finished_(false, false) { } | 511 is_finished_(false, false) { } |
| 508 | 512 |
| 509 void Update() { | 513 void Update() { |
| 510 // This gets called in a modelsafeworker thread. | 514 // This gets called in a modelsafeworker thread. |
| 511 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 515 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 512 | 516 |
| 513 UserShare* user_share = service_->backend()->GetUserShareHandle(); | 517 sync_api::UserShare* user_share = service_->GetUserShare(); |
| 514 DirectoryManager* dir_manager = user_share->dir_manager.get(); | 518 syncable::DirectoryManager* dir_manager = user_share->dir_manager.get(); |
| 515 ScopedDirLookup dir(dir_manager, user_share->name); | 519 syncable::ScopedDirLookup dir(dir_manager, user_share->name); |
| 516 ASSERT_TRUE(dir.good()); | 520 ASSERT_TRUE(dir.good()); |
| 517 | 521 |
| 518 // Create autofill protobuf | 522 // Create autofill protobuf |
| 519 std::string tag = AutofillModelAssociator::KeyToTag(entry_.key().name(), | 523 std::string tag = AutofillModelAssociator::KeyToTag(entry_.key().name(), |
| 520 entry_.key().value()); | 524 entry_.key().value()); |
| 521 sync_pb::AutofillSpecifics new_autofill; | 525 sync_pb::AutofillSpecifics new_autofill; |
| 522 new_autofill.set_name(UTF16ToUTF8(entry_.key().name())); | 526 new_autofill.set_name(UTF16ToUTF8(entry_.key().name())); |
| 523 new_autofill.set_value(UTF16ToUTF8(entry_.key().value())); | 527 new_autofill.set_value(UTF16ToUTF8(entry_.key().value())); |
| 524 const std::vector<base::Time>& ts(entry_.timestamps()); | 528 const std::vector<base::Time>& ts(entry_.timestamps()); |
| 525 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 529 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 556 } | 560 } |
| 557 VLOG(1) << "FakeServerUpdater finishing."; | 561 VLOG(1) << "FakeServerUpdater finishing."; |
| 558 is_finished_.Signal(); | 562 is_finished_.Signal(); |
| 559 } | 563 } |
| 560 | 564 |
| 561 void CreateNewEntry(const AutofillEntry& entry) { | 565 void CreateNewEntry(const AutofillEntry& entry) { |
| 562 entry_ = entry; | 566 entry_ = entry; |
| 563 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this, | 567 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this, |
| 564 &FakeServerUpdater::Update)); | 568 &FakeServerUpdater::Update)); |
| 565 std::vector<browser_sync::ModelSafeWorker*> workers; | 569 std::vector<browser_sync::ModelSafeWorker*> workers; |
| 566 service_->backend()->GetWorkers(&workers); | 570 service_->GetBackendForTest()->GetWorkers(&workers); |
| 567 | 571 |
| 568 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 572 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 569 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 573 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 570 NewRunnableMethod(this, &FakeServerUpdater::Update))) { | 574 NewRunnableMethod(this, &FakeServerUpdater::Update))) { |
| 571 NOTREACHED() << "Failed to post task to the db thread."; | 575 NOTREACHED() << "Failed to post task to the db thread."; |
| 572 return; | 576 return; |
| 573 } | 577 } |
| 574 } | 578 } |
| 575 | 579 |
| 576 void CreateNewEntryAndWait(const AutofillEntry& entry) { | 580 void CreateNewEntryAndWait(const AutofillEntry& entry) { |
| 577 entry_ = entry; | 581 entry_ = entry; |
| 578 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this, | 582 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this, |
| 579 &FakeServerUpdater::Update)); | 583 &FakeServerUpdater::Update)); |
| 580 std::vector<browser_sync::ModelSafeWorker*> workers; | 584 std::vector<browser_sync::ModelSafeWorker*> workers; |
| 581 service_->backend()->GetWorkers(&workers); | 585 service_->GetBackendForTest()->GetWorkers(&workers); |
| 582 | 586 |
| 583 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 587 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 584 is_finished_.Reset(); | 588 is_finished_.Reset(); |
| 585 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 589 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 586 NewRunnableMethod(this, &FakeServerUpdater::Update))) { | 590 NewRunnableMethod(this, &FakeServerUpdater::Update))) { |
| 587 NOTREACHED() << "Failed to post task to the db thread."; | 591 NOTREACHED() << "Failed to post task to the db thread."; |
| 588 return; | 592 return; |
| 589 } | 593 } |
| 590 is_finished_.Wait(); | 594 is_finished_.Wait(); |
| 591 } | 595 } |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 std::vector<AutofillEntry> sync_entries; | 1071 std::vector<AutofillEntry> sync_entries; |
| 1068 std::vector<AutoFillProfile> sync_profiles; | 1072 std::vector<AutoFillProfile> sync_profiles; |
| 1069 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1073 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1070 EXPECT_EQ(3U, sync_entries.size()); | 1074 EXPECT_EQ(3U, sync_entries.size()); |
| 1071 EXPECT_EQ(0U, sync_profiles.size()); | 1075 EXPECT_EQ(0U, sync_profiles.size()); |
| 1072 for (size_t i = 0; i < sync_entries.size(); i++) { | 1076 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1073 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1077 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1074 << ", " << sync_entries[i].key().value(); | 1078 << ", " << sync_entries[i].key().value(); |
| 1075 } | 1079 } |
| 1076 } | 1080 } |
| OLD | NEW |