| 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/engine_impl/sync_manager_impl.h" | 9 #include "components/sync/engine_impl/sync_manager_impl.h" |
| 10 | 10 |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 int64_t folder_id; | 429 int64_t folder_id; |
| 430 std::string test_title("test1"); | 430 std::string test_title("test1"); |
| 431 | 431 |
| 432 { | 432 { |
| 433 WriteTransaction trans(FROM_HERE, user_share()); | 433 WriteTransaction trans(FROM_HERE, user_share()); |
| 434 ReadNode root_node(&trans); | 434 ReadNode root_node(&trans); |
| 435 root_node.InitByRootLookup(); | 435 root_node.InitByRootLookup(); |
| 436 | 436 |
| 437 // we'll use this spare folder later | 437 // we'll use this spare folder later |
| 438 WriteNode folder_node(&trans); | 438 WriteNode folder_node(&trans); |
| 439 EXPECT_TRUE(folder_node.InitBookmarkByCreation(root_node, NULL)); | 439 EXPECT_TRUE(folder_node.InitBookmarkByCreation(root_node, nullptr)); |
| 440 folder_id = folder_node.GetId(); | 440 folder_id = folder_node.GetId(); |
| 441 | 441 |
| 442 WriteNode wnode(&trans); | 442 WriteNode wnode(&trans); |
| 443 WriteNode::InitUniqueByCreationResult result = | 443 WriteNode::InitUniqueByCreationResult result = |
| 444 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag"); | 444 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag"); |
| 445 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 445 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 446 wnode.SetIsFolder(false); | 446 wnode.SetIsFolder(false); |
| 447 wnode.SetTitle(test_title); | 447 wnode.SetTitle(test_title); |
| 448 | 448 |
| 449 node_id = wnode.GetId(); | 449 node_id = wnode.GetId(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 trans.GetCryptographer()->AddKey(params); | 543 trans.GetCryptographer()->AddKey(params); |
| 544 } | 544 } |
| 545 encryption_handler()->EnableEncryptEverything(); | 545 encryption_handler()->EnableEncryptEverything(); |
| 546 int bookmark_id; | 546 int bookmark_id; |
| 547 { | 547 { |
| 548 WriteTransaction trans(FROM_HERE, user_share()); | 548 WriteTransaction trans(FROM_HERE, user_share()); |
| 549 ReadNode root_node(&trans); | 549 ReadNode root_node(&trans); |
| 550 root_node.InitByRootLookup(); | 550 root_node.InitByRootLookup(); |
| 551 | 551 |
| 552 WriteNode bookmark_node(&trans); | 552 WriteNode bookmark_node(&trans); |
| 553 ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, NULL)); | 553 ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, nullptr)); |
| 554 bookmark_id = bookmark_node.GetId(); | 554 bookmark_id = bookmark_node.GetId(); |
| 555 bookmark_node.SetTitle("foo"); | 555 bookmark_node.SetTitle("foo"); |
| 556 | 556 |
| 557 WriteNode pref_node(&trans); | 557 WriteNode pref_node(&trans); |
| 558 WriteNode::InitUniqueByCreationResult result = | 558 WriteNode::InitUniqueByCreationResult result = |
| 559 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); | 559 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); |
| 560 ASSERT_EQ(WriteNode::INIT_SUCCESS, result); | 560 ASSERT_EQ(WriteNode::INIT_SUCCESS, result); |
| 561 pref_node.SetTitle("bar"); | 561 pref_node.SetTitle("bar"); |
| 562 } | 562 } |
| 563 { | 563 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 580 // results in single space title and non-unique name in internal representation. | 580 // results in single space title and non-unique name in internal representation. |
| 581 // GetTitle should still return empty string. | 581 // GetTitle should still return empty string. |
| 582 TEST_F(SyncApiTest, WriteEmptyBookmarkTitle) { | 582 TEST_F(SyncApiTest, WriteEmptyBookmarkTitle) { |
| 583 int bookmark_id; | 583 int bookmark_id; |
| 584 { | 584 { |
| 585 WriteTransaction trans(FROM_HERE, user_share()); | 585 WriteTransaction trans(FROM_HERE, user_share()); |
| 586 ReadNode root_node(&trans); | 586 ReadNode root_node(&trans); |
| 587 root_node.InitByRootLookup(); | 587 root_node.InitByRootLookup(); |
| 588 | 588 |
| 589 WriteNode bookmark_node(&trans); | 589 WriteNode bookmark_node(&trans); |
| 590 ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, NULL)); | 590 ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, nullptr)); |
| 591 bookmark_id = bookmark_node.GetId(); | 591 bookmark_id = bookmark_node.GetId(); |
| 592 bookmark_node.SetTitle(""); | 592 bookmark_node.SetTitle(""); |
| 593 } | 593 } |
| 594 { | 594 { |
| 595 ReadTransaction trans(FROM_HERE, user_share()); | 595 ReadTransaction trans(FROM_HERE, user_share()); |
| 596 | 596 |
| 597 ReadNode bookmark_node(&trans); | 597 ReadNode bookmark_node(&trans); |
| 598 ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id)); | 598 ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id)); |
| 599 EXPECT_EQ("", bookmark_node.GetTitle()); | 599 EXPECT_EQ("", bookmark_node.GetTitle()); |
| 600 EXPECT_EQ(" ", bookmark_node.GetEntitySpecifics().bookmark().title()); | 600 EXPECT_EQ(" ", bookmark_node.GetEntitySpecifics().bookmark().title()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 // Test counting nodes when the type's root node has no children. | 664 // Test counting nodes when the type's root node has no children. |
| 665 TEST_F(SyncApiTest, GetTotalNodeCountEmpty) { | 665 TEST_F(SyncApiTest, GetTotalNodeCountEmpty) { |
| 666 int64_t type_root = MakeTypeRoot(user_share(), BOOKMARKS); | 666 int64_t type_root = MakeTypeRoot(user_share(), BOOKMARKS); |
| 667 EXPECT_EQ(1, GetTotalNodeCount(user_share(), type_root)); | 667 EXPECT_EQ(1, GetTotalNodeCount(user_share(), type_root)); |
| 668 } | 668 } |
| 669 | 669 |
| 670 // Test counting nodes when there is one child beneath the type's root. | 670 // Test counting nodes when there is one child beneath the type's root. |
| 671 TEST_F(SyncApiTest, GetTotalNodeCountOneChild) { | 671 TEST_F(SyncApiTest, GetTotalNodeCountOneChild) { |
| 672 int64_t type_root = MakeTypeRoot(user_share(), BOOKMARKS); | 672 int64_t type_root = MakeTypeRoot(user_share(), BOOKMARKS); |
| 673 int64_t parent = | 673 int64_t parent = |
| 674 MakeFolderWithParent(user_share(), BOOKMARKS, type_root, NULL); | 674 MakeFolderWithParent(user_share(), BOOKMARKS, type_root, nullptr); |
| 675 EXPECT_EQ(2, GetTotalNodeCount(user_share(), type_root)); | 675 EXPECT_EQ(2, GetTotalNodeCount(user_share(), type_root)); |
| 676 EXPECT_EQ(1, GetTotalNodeCount(user_share(), parent)); | 676 EXPECT_EQ(1, GetTotalNodeCount(user_share(), parent)); |
| 677 } | 677 } |
| 678 | 678 |
| 679 // Test counting nodes when there are multiple children beneath the type root, | 679 // Test counting nodes when there are multiple children beneath the type root, |
| 680 // and one of those children has children of its own. | 680 // and one of those children has children of its own. |
| 681 TEST_F(SyncApiTest, GetTotalNodeCountMultipleChildren) { | 681 TEST_F(SyncApiTest, GetTotalNodeCountMultipleChildren) { |
| 682 int64_t type_root = MakeTypeRoot(user_share(), BOOKMARKS); | 682 int64_t type_root = MakeTypeRoot(user_share(), BOOKMARKS); |
| 683 int64_t parent = | 683 int64_t parent = |
| 684 MakeFolderWithParent(user_share(), BOOKMARKS, type_root, NULL); | 684 MakeFolderWithParent(user_share(), BOOKMARKS, type_root, nullptr); |
| 685 ignore_result(MakeFolderWithParent(user_share(), BOOKMARKS, type_root, NULL)); | 685 ignore_result( |
| 686 int64_t child1 = MakeFolderWithParent(user_share(), BOOKMARKS, parent, NULL); | 686 MakeFolderWithParent(user_share(), BOOKMARKS, type_root, nullptr)); |
| 687 ignore_result(MakeBookmarkWithParent(user_share(), parent, NULL)); | 687 int64_t child1 = |
| 688 ignore_result(MakeBookmarkWithParent(user_share(), child1, NULL)); | 688 MakeFolderWithParent(user_share(), BOOKMARKS, parent, nullptr); |
| 689 ignore_result(MakeBookmarkWithParent(user_share(), parent, nullptr)); |
| 690 ignore_result(MakeBookmarkWithParent(user_share(), child1, nullptr)); |
| 689 EXPECT_EQ(6, GetTotalNodeCount(user_share(), type_root)); | 691 EXPECT_EQ(6, GetTotalNodeCount(user_share(), type_root)); |
| 690 EXPECT_EQ(4, GetTotalNodeCount(user_share(), parent)); | 692 EXPECT_EQ(4, GetTotalNodeCount(user_share(), parent)); |
| 691 } | 693 } |
| 692 | 694 |
| 693 // Verify that Directory keeps track of which attachments are referenced by | 695 // Verify that Directory keeps track of which attachments are referenced by |
| 694 // which entries. | 696 // which entries. |
| 695 TEST_F(SyncApiTest, AttachmentLinking) { | 697 TEST_F(SyncApiTest, AttachmentLinking) { |
| 696 // Add an entry with an attachment. | 698 // Add an entry with an attachment. |
| 697 std::string tag1("some tag"); | 699 std::string tag1("some tag"); |
| 698 AttachmentId attachment_id(AttachmentId::Create(0, 0)); | 700 AttachmentId attachment_id(AttachmentId::Create(0, 0)); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); | 1286 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1285 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); | 1287 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); |
| 1286 } | 1288 } |
| 1287 | 1289 |
| 1288 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { | 1290 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { |
| 1289 size_t batch_size = 5; | 1291 size_t batch_size = 5; |
| 1290 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1292 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1291 | 1293 |
| 1292 // Create some unencrypted unsynced data. | 1294 // Create some unencrypted unsynced data. |
| 1293 int64_t folder = MakeFolderWithParent(sync_manager_.GetUserShare(), BOOKMARKS, | 1295 int64_t folder = MakeFolderWithParent(sync_manager_.GetUserShare(), BOOKMARKS, |
| 1294 GetIdForDataType(BOOKMARKS), NULL); | 1296 GetIdForDataType(BOOKMARKS), nullptr); |
| 1295 // First batch_size nodes are children of folder. | 1297 // First batch_size nodes are children of folder. |
| 1296 size_t i; | 1298 size_t i; |
| 1297 for (i = 0; i < batch_size; ++i) { | 1299 for (i = 0; i < batch_size; ++i) { |
| 1298 MakeBookmarkWithParent(sync_manager_.GetUserShare(), folder, NULL); | 1300 MakeBookmarkWithParent(sync_manager_.GetUserShare(), folder, nullptr); |
| 1299 } | 1301 } |
| 1300 // Next batch_size nodes are a different type and on their own. | 1302 // Next batch_size nodes are a different type and on their own. |
| 1301 for (; i < 2 * batch_size; ++i) { | 1303 for (; i < 2 * batch_size; ++i) { |
| 1302 MakeNodeWithRoot(sync_manager_.GetUserShare(), SESSIONS, | 1304 MakeNodeWithRoot(sync_manager_.GetUserShare(), SESSIONS, |
| 1303 base::StringPrintf("%" PRIuS "", i)); | 1305 base::StringPrintf("%" PRIuS "", i)); |
| 1304 } | 1306 } |
| 1305 // Last batch_size nodes are a third type that will not need encryption. | 1307 // Last batch_size nodes are a third type that will not need encryption. |
| 1306 for (; i < 3 * batch_size; ++i) { | 1308 for (; i < 3 * batch_size; ++i) { |
| 1307 MakeNodeWithRoot(sync_manager_.GetUserShare(), THEMES, | 1309 MakeNodeWithRoot(sync_manager_.GetUserShare(), THEMES, |
| 1308 base::StringPrintf("%" PRIuS "", i)); | 1310 base::StringPrintf("%" PRIuS "", i)); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 // set. This replicates the unique way bookmarks have of creating sync nodes. | 1802 // set. This replicates the unique way bookmarks have of creating sync nodes. |
| 1801 // See BookmarkChangeProcessor::PlaceSyncNode(..). | 1803 // See BookmarkChangeProcessor::PlaceSyncNode(..). |
| 1802 TEST_F(SyncManagerTest, CreateLocalBookmark) { | 1804 TEST_F(SyncManagerTest, CreateLocalBookmark) { |
| 1803 std::string title = "title"; | 1805 std::string title = "title"; |
| 1804 std::string url = "url"; | 1806 std::string url = "url"; |
| 1805 { | 1807 { |
| 1806 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1808 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1807 ReadNode bookmark_root(&trans); | 1809 ReadNode bookmark_root(&trans); |
| 1808 ASSERT_EQ(BaseNode::INIT_OK, bookmark_root.InitTypeRoot(BOOKMARKS)); | 1810 ASSERT_EQ(BaseNode::INIT_OK, bookmark_root.InitTypeRoot(BOOKMARKS)); |
| 1809 WriteNode node(&trans); | 1811 WriteNode node(&trans); |
| 1810 ASSERT_TRUE(node.InitBookmarkByCreation(bookmark_root, NULL)); | 1812 ASSERT_TRUE(node.InitBookmarkByCreation(bookmark_root, nullptr)); |
| 1811 node.SetIsFolder(false); | 1813 node.SetIsFolder(false); |
| 1812 node.SetTitle(title); | 1814 node.SetTitle(title); |
| 1813 | 1815 |
| 1814 sync_pb::BookmarkSpecifics bookmark_specifics(node.GetBookmarkSpecifics()); | 1816 sync_pb::BookmarkSpecifics bookmark_specifics(node.GetBookmarkSpecifics()); |
| 1815 bookmark_specifics.set_url(url); | 1817 bookmark_specifics.set_url(url); |
| 1816 node.SetBookmarkSpecifics(bookmark_specifics); | 1818 node.SetBookmarkSpecifics(bookmark_specifics); |
| 1817 } | 1819 } |
| 1818 { | 1820 { |
| 1819 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1821 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1820 ReadNode bookmark_root(&trans); | 1822 ReadNode bookmark_root(&trans); |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2562 return std::move(scheduler_to_use_); | 2564 return std::move(scheduler_to_use_); |
| 2563 } | 2565 } |
| 2564 | 2566 |
| 2565 private: | 2567 private: |
| 2566 std::unique_ptr<SyncScheduler> scheduler_to_use_; | 2568 std::unique_ptr<SyncScheduler> scheduler_to_use_; |
| 2567 SyncCycleContext** cycle_context_; | 2569 SyncCycleContext** cycle_context_; |
| 2568 }; | 2570 }; |
| 2569 | 2571 |
| 2570 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2572 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| 2571 public: | 2573 public: |
| 2572 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} | 2574 SyncManagerTestWithMockScheduler() : scheduler_(nullptr) {} |
| 2573 EngineComponentsFactory* GetFactory() override { | 2575 EngineComponentsFactory* GetFactory() override { |
| 2574 scheduler_ = new MockSyncScheduler(); | 2576 scheduler_ = new MockSyncScheduler(); |
| 2575 return new ComponentsFactory(GetSwitches(), scheduler_, &cycle_context_, | 2577 return new ComponentsFactory(GetSwitches(), scheduler_, &cycle_context_, |
| 2576 &storage_used_); | 2578 &storage_used_); |
| 2577 } | 2579 } |
| 2578 | 2580 |
| 2579 MockSyncScheduler* scheduler() { return scheduler_; } | 2581 MockSyncScheduler* scheduler() { return scheduler_; } |
| 2580 SyncCycleContext* cycle_context() { return cycle_context_; } | 2582 SyncCycleContext* cycle_context() { return cycle_context_; } |
| 2581 | 2583 |
| 2582 private: | 2584 private: |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3350 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3352 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3351 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3353 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3352 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3354 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3353 // task is to ensure that SyncManagerImpl reported initialization failure in | 3355 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3354 // OnInitializationComplete callback. | 3356 // OnInitializationComplete callback. |
| 3355 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3357 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3356 EXPECT_FALSE(initialization_succeeded_); | 3358 EXPECT_FALSE(initialization_succeeded_); |
| 3357 } | 3359 } |
| 3358 | 3360 |
| 3359 } // namespace syncer | 3361 } // namespace syncer |
| OLD | NEW |