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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // Note: The tear down order is important. | 391 // Note: The tear down order is important. |
392 service_.reset(); | 392 service_.reset(); |
393 web_data_service_->ShutdownSyncableService(); | 393 web_data_service_->ShutdownSyncableService(); |
394 profile_->ResetRequestContext(); | 394 profile_->ResetRequestContext(); |
395 // To prevent a leak, fully release TestURLRequestContext to ensure its | 395 // To prevent a leak, fully release TestURLRequestContext to ensure its |
396 // destruction on the IO message loop. | 396 // destruction on the IO message loop. |
397 profile_.reset(); | 397 profile_.reset(); |
398 AbstractProfileSyncServiceTest::TearDown(); | 398 AbstractProfileSyncServiceTest::TearDown(); |
399 } | 399 } |
400 | 400 |
401 void StartSyncService(const base::Closure& callback, | 401 void StartSyncService( |
402 bool will_fail_association, | 402 const base::Callback<void(syncer::UserShare*)>& callback, |
403 syncer::ModelType type) { | 403 bool will_fail_association, |
| 404 syncer::ModelType type) { |
404 AbstractAutofillFactory* factory = GetFactory(type); | 405 AbstractAutofillFactory* factory = GetFactory(type); |
405 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); | 406 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); |
406 signin->SetAuthenticatedUsername("test_user"); | 407 signin->SetAuthenticatedUsername("test_user"); |
407 ProfileSyncComponentsFactoryMock* components_factory = | 408 ProfileSyncComponentsFactoryMock* components_factory = |
408 new ProfileSyncComponentsFactoryMock(); | 409 new ProfileSyncComponentsFactoryMock(); |
409 service_.reset( | 410 service_.reset( |
410 new TestProfileSyncService(components_factory, | 411 new TestProfileSyncService(components_factory, |
411 profile_.get(), | 412 profile_.get(), |
412 signin, | 413 signin, |
413 ProfileSyncService::AUTO_START, | 414 ProfileSyncService::AUTO_START, |
(...skipping 16 matching lines...) Expand all Loading... |
430 WillRepeatedly(Return(true)); | 431 WillRepeatedly(Return(true)); |
431 | 432 |
432 // We need tokens to get the tests going | 433 // We need tokens to get the tests going |
433 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token"); | 434 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token"); |
434 | 435 |
435 service_->RegisterDataTypeController(data_type_controller); | 436 service_->RegisterDataTypeController(data_type_controller); |
436 service_->Initialize(); | 437 service_->Initialize(); |
437 MessageLoop::current()->Run(); | 438 MessageLoop::current()->Run(); |
438 } | 439 } |
439 | 440 |
440 bool AddAutofillSyncNode(const AutofillEntry& entry) { | 441 bool AddAutofillSyncNode( |
441 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 442 const AutofillEntry& entry, |
| 443 syncer::UserShare* user_share) { |
| 444 syncer::WriteTransaction trans(FROM_HERE, user_share); |
442 syncer::ReadNode autofill_root(&trans); | 445 syncer::ReadNode autofill_root(&trans); |
443 if (autofill_root.InitByTagLookup( | 446 if (autofill_root.InitByTagLookup( |
444 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) != | 447 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) != |
445 BaseNode::INIT_OK) { | 448 BaseNode::INIT_OK) { |
446 return false; | 449 return false; |
447 } | 450 } |
448 | 451 |
449 syncer::WriteNode node(&trans); | 452 syncer::WriteNode node(&trans); |
450 std::string tag = AutocompleteSyncableService::KeyToTag( | 453 std::string tag = AutocompleteSyncableService::KeyToTag( |
451 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value())); | 454 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value())); |
452 syncer::WriteNode::InitUniqueByCreationResult result = | 455 syncer::WriteNode::InitUniqueByCreationResult result = |
453 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag); | 456 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag); |
454 if (result != syncer::WriteNode::INIT_SUCCESS) | 457 if (result != syncer::WriteNode::INIT_SUCCESS) |
455 return false; | 458 return false; |
456 | 459 |
457 sync_pb::EntitySpecifics specifics; | 460 sync_pb::EntitySpecifics specifics; |
458 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); | 461 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); |
459 sync_pb::AutofillSpecifics* autofill_specifics = | 462 sync_pb::AutofillSpecifics* autofill_specifics = |
460 specifics.mutable_autofill(); | 463 specifics.mutable_autofill(); |
461 node.SetAutofillSpecifics(*autofill_specifics); | 464 node.SetAutofillSpecifics(*autofill_specifics); |
462 return true; | 465 return true; |
463 } | 466 } |
464 | 467 |
465 bool AddAutofillSyncNode(const AutofillProfile& profile) { | 468 bool AddAutofillSyncNode(const AutofillProfile& profile, |
466 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 469 syncer::UserShare* user_share) { |
| 470 syncer::WriteTransaction trans(FROM_HERE, user_share); |
467 syncer::ReadNode autofill_root(&trans); | 471 syncer::ReadNode autofill_root(&trans); |
468 if (autofill_root.InitByTagLookup(kAutofillProfileTag) != | 472 if (autofill_root.InitByTagLookup(kAutofillProfileTag) != |
469 BaseNode::INIT_OK) { | 473 BaseNode::INIT_OK) { |
470 return false; | 474 return false; |
471 } | 475 } |
472 syncer::WriteNode node(&trans); | 476 syncer::WriteNode node(&trans); |
473 std::string tag = profile.guid(); | 477 std::string tag = profile.guid(); |
474 syncer::WriteNode::InitUniqueByCreationResult result = | 478 syncer::WriteNode::InitUniqueByCreationResult result = |
475 node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE, | 479 node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE, |
476 autofill_root, tag); | 480 autofill_root, tag); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 class AddAutofillHelper { | 600 class AddAutofillHelper { |
597 public: | 601 public: |
598 AddAutofillHelper(ProfileSyncServiceAutofillTest* test, | 602 AddAutofillHelper(ProfileSyncServiceAutofillTest* test, |
599 const std::vector<T>& entries) | 603 const std::vector<T>& entries) |
600 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( | 604 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( |
601 base::Bind(&AddAutofillHelper::AddAutofillCallback, | 605 base::Bind(&AddAutofillHelper::AddAutofillCallback, |
602 base::Unretained(this), test, entries))), | 606 base::Unretained(this), test, entries))), |
603 success_(false) { | 607 success_(false) { |
604 } | 608 } |
605 | 609 |
606 const base::Closure& callback() const { return callback_; } | 610 const base::Callback<void(syncer::UserShare* user_share)>& callback() const { |
607 bool success() { return success_; } | 611 return callback_; |
| 612 } |
| 613 |
| 614 bool success() { |
| 615 return success_; |
| 616 } |
608 | 617 |
609 private: | 618 private: |
610 void AddAutofillCallback(ProfileSyncServiceAutofillTest* test, | 619 void AddAutofillCallback(ProfileSyncServiceAutofillTest* test, |
611 const std::vector<T>& entries) { | 620 const std::vector<T>& entries, |
612 if (!test->CreateRoot(GetModelType<T>())) | 621 syncer::UserShare* user_share) { |
| 622 if (!test->CreateRoot(GetModelType<T>(), user_share)) |
613 return; | 623 return; |
614 | 624 |
615 for (size_t i = 0; i < entries.size(); ++i) { | 625 for (size_t i = 0; i < entries.size(); ++i) { |
616 if (!test->AddAutofillSyncNode(entries[i])) | 626 if (!test->AddAutofillSyncNode(entries[i], user_share)) |
617 return; | 627 return; |
618 } | 628 } |
619 success_ = true; | 629 success_ = true; |
620 } | 630 } |
621 | 631 |
622 base::Closure callback_; | 632 base::Callback<void(syncer::UserShare* user_share)> callback_; |
623 bool success_; | 633 bool success_; |
624 }; | 634 }; |
625 | 635 |
626 // Overload write transaction to use custom NotifyTransactionComplete | 636 // Overload write transaction to use custom NotifyTransactionComplete |
627 class WriteTransactionTest: public WriteTransaction { | 637 class WriteTransactionTest: public WriteTransaction { |
628 public: | 638 public: |
629 WriteTransactionTest(const tracked_objects::Location& from_here, | 639 WriteTransactionTest(const tracked_objects::Location& from_here, |
630 WriterTag writer, | 640 WriterTag writer, |
631 syncer::syncable::Directory* directory, | 641 syncer::syncable::Directory* directory, |
632 scoped_ptr<WaitableEvent>* wait_for_syncapi) | 642 scoped_ptr<WaitableEvent>* wait_for_syncapi) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 } | 775 } |
766 | 776 |
767 }; | 777 }; |
768 | 778 |
769 // TODO(skrul): Test abort startup. | 779 // TODO(skrul): Test abort startup. |
770 // TODO(skrul): Test processing of cloud changes. | 780 // TODO(skrul): Test processing of cloud changes. |
771 // TODO(tim): Add autofill data type controller test, and a case to cover | 781 // TODO(tim): Add autofill data type controller test, and a case to cover |
772 // waiting for the PersonalDataManager. | 782 // waiting for the PersonalDataManager. |
773 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { | 783 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { |
774 // Don't create the root autofill node so startup fails. | 784 // Don't create the root autofill node so startup fails. |
775 StartSyncService(base::Closure(), true, syncer::AUTOFILL); | 785 StartSyncService(TestProfileSyncService::NullCallback(), true, |
| 786 syncer::AUTOFILL); |
776 EXPECT_TRUE(service_->HasUnrecoverableError()); | 787 EXPECT_TRUE(service_->HasUnrecoverableError()); |
777 } | 788 } |
778 | 789 |
779 TEST_F(ProfileSyncServiceAutofillTest, EmptyNativeEmptySync) { | 790 TEST_F(ProfileSyncServiceAutofillTest, EmptyNativeEmptySync) { |
780 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); | 791 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); |
781 SetIdleChangeProcessorExpectations(); | 792 SetIdleChangeProcessorExpectations(); |
782 CreateRootHelper create_root(this, syncer::AUTOFILL); | 793 CreateRootHelper create_root(this, syncer::AUTOFILL); |
783 EXPECT_CALL(*personal_data_manager_, Refresh()); | 794 EXPECT_CALL(*personal_data_manager_, Refresh()); |
784 StartSyncService(create_root.callback(), false, syncer::AUTOFILL); | 795 StartSyncService(create_root.callback(), false, syncer::AUTOFILL); |
785 EXPECT_TRUE(create_root.success()); | 796 EXPECT_TRUE(create_root.success()); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 scoped_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false)); | 1238 scoped_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false)); |
1228 scoped_ptr<WaitableEvent> wait_for_syncapi(new WaitableEvent(true, false)); | 1239 scoped_ptr<WaitableEvent> wait_for_syncapi(new WaitableEvent(true, false)); |
1229 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater( | 1240 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater( |
1230 service_.get(), &wait_for_start, &wait_for_syncapi)); | 1241 service_.get(), &wait_for_start, &wait_for_syncapi)); |
1231 | 1242 |
1232 // This server side update will stall waiting for CommitWaiter. | 1243 // This server side update will stall waiting for CommitWaiter. |
1233 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1)); | 1244 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1)); |
1234 wait_for_start->Wait(); | 1245 wait_for_start->Wait(); |
1235 | 1246 |
1236 AutofillEntry syncapi_entry(MakeAutofillEntry("syncapi", "entry", 2)); | 1247 AutofillEntry syncapi_entry(MakeAutofillEntry("syncapi", "entry", 2)); |
1237 ASSERT_TRUE(AddAutofillSyncNode(syncapi_entry)); | 1248 ASSERT_TRUE(AddAutofillSyncNode(syncapi_entry, service_->GetUserShare())); |
1238 DVLOG(1) << "Syncapi update finished."; | 1249 DVLOG(1) << "Syncapi update finished."; |
1239 | 1250 |
1240 // If we reach here, it means syncapi succeeded and we didn't deadlock. Yay! | 1251 // If we reach here, it means syncapi succeeded and we didn't deadlock. Yay! |
1241 // Signal FakeServerUpdater that it can complete. | 1252 // Signal FakeServerUpdater that it can complete. |
1242 wait_for_syncapi->Signal(); | 1253 wait_for_syncapi->Signal(); |
1243 | 1254 |
1244 // Make another entry to ensure nothing broke afterwards and wait for finish | 1255 // Make another entry to ensure nothing broke afterwards and wait for finish |
1245 // to clean up. | 1256 // to clean up. |
1246 updater->CreateNewEntryAndWait(MakeAutofillEntry("server2", "entry2", 3)); | 1257 updater->CreateNewEntryAndWait(MakeAutofillEntry("server2", "entry2", 3)); |
1247 | 1258 |
1248 std::vector<AutofillEntry> sync_entries; | 1259 std::vector<AutofillEntry> sync_entries; |
1249 std::vector<AutofillProfile> sync_profiles; | 1260 std::vector<AutofillProfile> sync_profiles; |
1250 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1261 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1251 EXPECT_EQ(3U, sync_entries.size()); | 1262 EXPECT_EQ(3U, sync_entries.size()); |
1252 EXPECT_EQ(0U, sync_profiles.size()); | 1263 EXPECT_EQ(0U, sync_profiles.size()); |
1253 for (size_t i = 0; i < sync_entries.size(); i++) { | 1264 for (size_t i = 0; i < sync_entries.size(); i++) { |
1254 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1265 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1255 << ", " << sync_entries[i].key().value(); | 1266 << ", " << sync_entries[i].key().value(); |
1256 } | 1267 } |
1257 } | 1268 } |
OLD | NEW |