| 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
| 6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
| 7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
| 8 | 8 |
| 9 #include "components/sync/core_impl/sync_manager_impl.h" | 9 #include "components/sync/core_impl/sync_manager_impl.h" |
| 10 | 10 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 282 } |
| 283 | 283 |
| 284 bool SyncApiTest::ReloadDir() { | 284 bool SyncApiTest::ReloadDir() { |
| 285 return test_user_share_.Reload(); | 285 return test_user_share_.Reload(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void SyncApiTest::CreateEntryWithAttachmentMetadata( | 288 void SyncApiTest::CreateEntryWithAttachmentMetadata( |
| 289 const ModelType& model_type, | 289 const ModelType& model_type, |
| 290 const std::string& client_tag, | 290 const std::string& client_tag, |
| 291 const sync_pb::AttachmentMetadata& attachment_metadata) { | 291 const sync_pb::AttachmentMetadata& attachment_metadata) { |
| 292 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 292 WriteTransaction trans(FROM_HERE, user_share()); |
| 293 syncer::ReadNode root_node(&trans); | 293 ReadNode root_node(&trans); |
| 294 root_node.InitByRootLookup(); | 294 root_node.InitByRootLookup(); |
| 295 syncer::WriteNode node(&trans); | 295 WriteNode node(&trans); |
| 296 ASSERT_EQ(node.InitUniqueByCreation(model_type, root_node, client_tag), | 296 ASSERT_EQ(node.InitUniqueByCreation(model_type, root_node, client_tag), |
| 297 syncer::WriteNode::INIT_SUCCESS); | 297 WriteNode::INIT_SUCCESS); |
| 298 node.SetAttachmentMetadata(attachment_metadata); | 298 node.SetAttachmentMetadata(attachment_metadata); |
| 299 } | 299 } |
| 300 | 300 |
| 301 BaseNode::InitByLookupResult SyncApiTest::LookupEntryByClientTag( | 301 BaseNode::InitByLookupResult SyncApiTest::LookupEntryByClientTag( |
| 302 const ModelType& model_type, | 302 const ModelType& model_type, |
| 303 const std::string& client_tag) { | 303 const std::string& client_tag) { |
| 304 syncer::ReadTransaction trans(FROM_HERE, user_share()); | 304 ReadTransaction trans(FROM_HERE, user_share()); |
| 305 syncer::ReadNode node(&trans); | 305 ReadNode node(&trans); |
| 306 return node.InitByClientTagLookup(model_type, client_tag); | 306 return node.InitByClientTagLookup(model_type, client_tag); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void SyncApiTest::ReplaceWithTombstone(const ModelType& model_type, | 309 void SyncApiTest::ReplaceWithTombstone(const ModelType& model_type, |
| 310 const std::string& client_tag) { | 310 const std::string& client_tag) { |
| 311 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 311 WriteTransaction trans(FROM_HERE, user_share()); |
| 312 syncer::WriteNode node(&trans); | 312 WriteNode node(&trans); |
| 313 ASSERT_EQ(node.InitByClientTagLookup(model_type, client_tag), | 313 ASSERT_EQ(node.InitByClientTagLookup(model_type, client_tag), |
| 314 syncer::WriteNode::INIT_OK); | 314 WriteNode::INIT_OK); |
| 315 node.Tombstone(); | 315 node.Tombstone(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 TEST_F(SyncApiTest, SanityCheckTest) { | 318 TEST_F(SyncApiTest, SanityCheckTest) { |
| 319 { | 319 { |
| 320 ReadTransaction trans(FROM_HERE, user_share()); | 320 ReadTransaction trans(FROM_HERE, user_share()); |
| 321 EXPECT_TRUE(trans.GetWrappedTrans()); | 321 EXPECT_TRUE(trans.GetWrappedTrans()); |
| 322 } | 322 } |
| 323 { | 323 { |
| 324 WriteTransaction trans(FROM_HERE, user_share()); | 324 WriteTransaction trans(FROM_HERE, user_share()); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 ignore_result(MakeBookmarkWithParent(user_share(), child1, NULL)); | 695 ignore_result(MakeBookmarkWithParent(user_share(), child1, NULL)); |
| 696 EXPECT_EQ(6, GetTotalNodeCount(user_share(), type_root)); | 696 EXPECT_EQ(6, GetTotalNodeCount(user_share(), type_root)); |
| 697 EXPECT_EQ(4, GetTotalNodeCount(user_share(), parent)); | 697 EXPECT_EQ(4, GetTotalNodeCount(user_share(), parent)); |
| 698 } | 698 } |
| 699 | 699 |
| 700 // Verify that Directory keeps track of which attachments are referenced by | 700 // Verify that Directory keeps track of which attachments are referenced by |
| 701 // which entries. | 701 // which entries. |
| 702 TEST_F(SyncApiTest, AttachmentLinking) { | 702 TEST_F(SyncApiTest, AttachmentLinking) { |
| 703 // Add an entry with an attachment. | 703 // Add an entry with an attachment. |
| 704 std::string tag1("some tag"); | 704 std::string tag1("some tag"); |
| 705 syncer::AttachmentId attachment_id(syncer::AttachmentId::Create(0, 0)); | 705 AttachmentId attachment_id(AttachmentId::Create(0, 0)); |
| 706 sync_pb::AttachmentMetadata attachment_metadata; | 706 sync_pb::AttachmentMetadata attachment_metadata; |
| 707 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 707 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
| 708 *record->mutable_id() = attachment_id.GetProto(); | 708 *record->mutable_id() = attachment_id.GetProto(); |
| 709 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 709 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
| 710 CreateEntryWithAttachmentMetadata(PREFERENCES, tag1, attachment_metadata); | 710 CreateEntryWithAttachmentMetadata(PREFERENCES, tag1, attachment_metadata); |
| 711 | 711 |
| 712 // See that the directory knows it's linked. | 712 // See that the directory knows it's linked. |
| 713 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 713 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
| 714 | 714 |
| 715 // Add a second entry referencing the same attachment. | 715 // Add a second entry referencing the same attachment. |
| 716 std::string tag2("some other tag"); | 716 std::string tag2("some other tag"); |
| 717 CreateEntryWithAttachmentMetadata(PREFERENCES, tag2, attachment_metadata); | 717 CreateEntryWithAttachmentMetadata(PREFERENCES, tag2, attachment_metadata); |
| 718 | 718 |
| 719 // See that the directory knows it's still linked. | 719 // See that the directory knows it's still linked. |
| 720 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 720 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
| 721 | 721 |
| 722 // Tombstone the first entry. | 722 // Tombstone the first entry. |
| 723 ReplaceWithTombstone(syncer::PREFERENCES, tag1); | 723 ReplaceWithTombstone(PREFERENCES, tag1); |
| 724 | 724 |
| 725 // See that the attachment is still considered linked because the entry hasn't | 725 // See that the attachment is still considered linked because the entry hasn't |
| 726 // been purged from the Directory. | 726 // been purged from the Directory. |
| 727 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 727 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
| 728 | 728 |
| 729 // Save changes and see that the entry is truly gone. | 729 // Save changes and see that the entry is truly gone. |
| 730 ASSERT_TRUE(dir()->SaveChanges()); | 730 ASSERT_TRUE(dir()->SaveChanges()); |
| 731 ASSERT_EQ(LookupEntryByClientTag(PREFERENCES, tag1), | 731 ASSERT_EQ(LookupEntryByClientTag(PREFERENCES, tag1), |
| 732 syncer::WriteNode::INIT_FAILED_ENTRY_NOT_GOOD); | 732 WriteNode::INIT_FAILED_ENTRY_NOT_GOOD); |
| 733 | 733 |
| 734 // However, the attachment is still linked. | 734 // However, the attachment is still linked. |
| 735 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 735 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
| 736 | 736 |
| 737 // Save, destroy, and recreate the directory. See that it's still linked. | 737 // Save, destroy, and recreate the directory. See that it's still linked. |
| 738 ASSERT_TRUE(ReloadDir()); | 738 ASSERT_TRUE(ReloadDir()); |
| 739 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 739 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
| 740 | 740 |
| 741 // Tombstone the second entry, save changes, see that it's truly gone. | 741 // Tombstone the second entry, save changes, see that it's truly gone. |
| 742 ReplaceWithTombstone(syncer::PREFERENCES, tag2); | 742 ReplaceWithTombstone(PREFERENCES, tag2); |
| 743 ASSERT_TRUE(dir()->SaveChanges()); | 743 ASSERT_TRUE(dir()->SaveChanges()); |
| 744 ASSERT_EQ(LookupEntryByClientTag(PREFERENCES, tag2), | 744 ASSERT_EQ(LookupEntryByClientTag(PREFERENCES, tag2), |
| 745 syncer::WriteNode::INIT_FAILED_ENTRY_NOT_GOOD); | 745 WriteNode::INIT_FAILED_ENTRY_NOT_GOOD); |
| 746 | 746 |
| 747 // Finally, the attachment is no longer linked. | 747 // Finally, the attachment is no longer linked. |
| 748 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 748 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
| 749 } | 749 } |
| 750 | 750 |
| 751 // This tests directory integrity in the case of creating a new unique node | 751 // This tests directory integrity in the case of creating a new unique node |
| 752 // with client tag matching that of an existing unapplied node with server only | 752 // with client tag matching that of an existing unapplied node with server only |
| 753 // data. See crbug.com/505761. | 753 // data. See crbug.com/505761. |
| 754 TEST_F(SyncApiTest, WriteNode_UniqueByCreation_UndeleteCase) { | 754 TEST_F(SyncApiTest, WriteNode_UniqueByCreation_UndeleteCase) { |
| 755 int64_t preferences_root = MakeTypeRoot(user_share(), PREFERENCES); | 755 int64_t preferences_root = MakeTypeRoot(user_share(), PREFERENCES); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 } | 904 } |
| 905 }; | 905 }; |
| 906 | 906 |
| 907 class SyncManagerObserverMock : public SyncManager::Observer { | 907 class SyncManagerObserverMock : public SyncManager::Observer { |
| 908 public: | 908 public: |
| 909 MOCK_METHOD1(OnSyncCycleCompleted, void(const SyncCycleSnapshot&)); // NOLINT | 909 MOCK_METHOD1(OnSyncCycleCompleted, void(const SyncCycleSnapshot&)); // NOLINT |
| 910 MOCK_METHOD4(OnInitializationComplete, | 910 MOCK_METHOD4(OnInitializationComplete, |
| 911 void(const WeakHandle<JsBackend>&, | 911 void(const WeakHandle<JsBackend>&, |
| 912 const WeakHandle<DataTypeDebugInfoListener>&, | 912 const WeakHandle<DataTypeDebugInfoListener>&, |
| 913 bool, | 913 bool, |
| 914 syncer::ModelTypeSet)); // NOLINT | 914 ModelTypeSet)); // NOLINT |
| 915 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT | 915 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT |
| 916 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | 916 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT |
| 917 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); // NOLINT | 917 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); // NOLINT |
| 918 MOCK_METHOD1(OnMigrationRequested, void(syncer::ModelTypeSet)); // NOLINT | 918 MOCK_METHOD1(OnMigrationRequested, void(ModelTypeSet)); // NOLINT |
| 919 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); // NOLINT | 919 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); // NOLINT |
| 920 }; | 920 }; |
| 921 | 921 |
| 922 class SyncEncryptionHandlerObserverMock | 922 class SyncEncryptionHandlerObserverMock |
| 923 : public SyncEncryptionHandler::Observer { | 923 : public SyncEncryptionHandler::Observer { |
| 924 public: | 924 public: |
| 925 MOCK_METHOD2(OnPassphraseRequired, | 925 MOCK_METHOD2(OnPassphraseRequired, |
| 926 void(PassphraseRequiredReason, | 926 void(PassphraseRequiredReason, |
| 927 const sync_pb::EncryptedData&)); // NOLINT | 927 const sync_pb::EncryptedData&)); // NOLINT |
| 928 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT | 928 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT |
| (...skipping 2430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3359 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3359 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3360 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3360 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3361 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3361 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3362 // task is to ensure that SyncManagerImpl reported initialization failure in | 3362 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3363 // OnInitializationComplete callback. | 3363 // OnInitializationComplete callback. |
| 3364 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3364 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3365 EXPECT_FALSE(initialization_succeeded_); | 3365 EXPECT_FALSE(initialization_succeeded_); |
| 3366 } | 3366 } |
| 3367 | 3367 |
| 3368 } // namespace syncer | 3368 } // namespace syncer |
| OLD | NEW |