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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 4318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4329 ASSERT_TRUE(tag2.GetId().ServerKnows()); | 4329 ASSERT_TRUE(tag2.GetId().ServerKnows()); |
4330 ASSERT_TRUE(id4 == tag2.GetId()); | 4330 ASSERT_TRUE(id4 == tag2.GetId()); |
4331 EXPECT_FALSE(tag2.GetIsDel()); | 4331 EXPECT_FALSE(tag2.GetIsDel()); |
4332 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); | 4332 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); |
4333 EXPECT_FALSE(tag2.GetIsUnsynced()); | 4333 EXPECT_FALSE(tag2.GetIsUnsynced()); |
4334 EXPECT_EQ(11, tag2.GetBaseVersion()); | 4334 EXPECT_EQ(11, tag2.GetBaseVersion()); |
4335 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); | 4335 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); |
4336 tag2_metahandle = tag2.GetMetahandle(); | 4336 tag2_metahandle = tag2.GetMetahandle(); |
4337 | 4337 |
4338 // Preferences type root should have been created by the updates above. | 4338 // Preferences type root should have been created by the updates above. |
| 4339 ASSERT_TRUE(directory()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 4340 |
4339 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); | 4341 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
4340 ASSERT_TRUE(pref_root.good()); | 4342 ASSERT_TRUE(pref_root.good()); |
4341 | 4343 |
4342 syncable::Directory::Metahandles children; | 4344 syncable::Directory::Metahandles children; |
4343 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); | 4345 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); |
4344 ASSERT_EQ(2U, children.size()); | 4346 ASSERT_EQ(2U, children.size()); |
4345 } | 4347 } |
4346 | 4348 |
4347 syncable::Id id2 = TestIdFactory::MakeServer("2"); | 4349 syncable::Id id2 = TestIdFactory::MakeServer("2"); |
4348 mock_server_->AddUpdatePref(id2.GetServerId(), "", "tag1", 12, 120); | 4350 mock_server_->AddUpdatePref(id2.GetServerId(), "", "tag1", 12, 120); |
(...skipping 22 matching lines...) Expand all Loading... |
4371 ASSERT_EQ(id3, tag2.GetId()) | 4373 ASSERT_EQ(id3, tag2.GetId()) |
4372 << "ID 3 should be kept, since it was less than ID 4."; | 4374 << "ID 3 should be kept, since it was less than ID 4."; |
4373 EXPECT_FALSE(tag2.GetIsDel()); | 4375 EXPECT_FALSE(tag2.GetIsDel()); |
4374 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); | 4376 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); |
4375 EXPECT_FALSE(tag2.GetIsUnsynced()); | 4377 EXPECT_FALSE(tag2.GetIsUnsynced()); |
4376 EXPECT_EQ(13, tag2.GetBaseVersion()); | 4378 EXPECT_EQ(13, tag2.GetBaseVersion()); |
4377 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); | 4379 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); |
4378 EXPECT_EQ(tag2_metahandle, tag2.GetMetahandle()); | 4380 EXPECT_EQ(tag2_metahandle, tag2.GetMetahandle()); |
4379 | 4381 |
4380 // Preferences type root should have been created by the updates above. | 4382 // Preferences type root should have been created by the updates above. |
| 4383 ASSERT_TRUE(directory()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 4384 |
4381 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); | 4385 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
4382 ASSERT_TRUE(pref_root.good()); | 4386 ASSERT_TRUE(pref_root.good()); |
4383 | 4387 |
4384 syncable::Directory::Metahandles children; | 4388 syncable::Directory::Metahandles children; |
4385 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); | 4389 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); |
4386 ASSERT_EQ(2U, children.size()); | 4390 ASSERT_EQ(2U, children.size()); |
4387 } | 4391 } |
4388 } | 4392 } |
4389 | 4393 |
4390 TEST_F(SyncerTest, ClientTagClashWithinBatchOfUpdates) { | 4394 TEST_F(SyncerTest, ClientTagClashWithinBatchOfUpdates) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4453 ASSERT_TRUE(tag_c.good()); | 4457 ASSERT_TRUE(tag_c.good()); |
4454 EXPECT_TRUE(tag_c.GetId().ServerKnows()); | 4458 EXPECT_TRUE(tag_c.GetId().ServerKnows()); |
4455 EXPECT_EQ(ids_.FromNumber(201), tag_c.GetId()); | 4459 EXPECT_EQ(ids_.FromNumber(201), tag_c.GetId()); |
4456 EXPECT_FALSE(tag_c.GetIsDel()); | 4460 EXPECT_FALSE(tag_c.GetIsDel()); |
4457 EXPECT_FALSE(tag_c.GetIsUnappliedUpdate()); | 4461 EXPECT_FALSE(tag_c.GetIsUnappliedUpdate()); |
4458 EXPECT_FALSE(tag_c.GetIsUnsynced()); | 4462 EXPECT_FALSE(tag_c.GetIsUnsynced()); |
4459 EXPECT_EQ(21, tag_c.GetBaseVersion()); | 4463 EXPECT_EQ(21, tag_c.GetBaseVersion()); |
4460 EXPECT_EQ("tag c", tag_c.GetUniqueClientTag()); | 4464 EXPECT_EQ("tag c", tag_c.GetUniqueClientTag()); |
4461 | 4465 |
4462 // Preferences type root should have been created by the updates above. | 4466 // Preferences type root should have been created by the updates above. |
| 4467 ASSERT_TRUE(directory()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 4468 |
4463 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); | 4469 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
4464 ASSERT_TRUE(pref_root.good()); | 4470 ASSERT_TRUE(pref_root.good()); |
4465 | 4471 |
4466 // Verify that we have exactly 3 tagged nodes under the type root. | 4472 // Verify that we have exactly 3 tagged nodes under the type root. |
4467 syncable::Directory::Metahandles children; | 4473 syncable::Directory::Metahandles children; |
4468 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); | 4474 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); |
4469 ASSERT_EQ(3U, children.size()); | 4475 ASSERT_EQ(3U, children.size()); |
4470 } | 4476 } |
4471 } | 4477 } |
4472 | 4478 |
4473 // This verifies transition to implicit permanent folders. | 4479 // This verifies transition to implicit permanent folders. |
4474 TEST_F(SyncerTest, EntryWithParentIdUpdatedWithEntryWithoutParentId) { | 4480 TEST_F(SyncerTest, EntryWithParentIdUpdatedWithEntryWithoutParentId) { |
4475 // Make sure SPECIFICS root exists so that we can get its parent ID. | 4481 // Make sure SPECIFICS root exists so that we can get its parent ID. |
4476 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1, | 4482 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1, |
4477 DefaultPreferencesSpecifics()); | 4483 DefaultPreferencesSpecifics()); |
4478 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); | 4484 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); |
4479 EXPECT_TRUE(SyncShareNudge()); | 4485 EXPECT_TRUE(SyncShareNudge()); |
4480 | 4486 |
4481 Id pref_root_id; | 4487 Id pref_root_id; |
4482 { | 4488 { |
4483 // Preferences type root should have been created by the update above. | 4489 // Preferences type root should have been created by the update above. |
4484 // We need it in order to get its ID. | 4490 // We need it in order to get its ID. |
4485 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4491 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 4492 |
| 4493 ASSERT_TRUE(directory()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 4494 |
4486 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); | 4495 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
4487 ASSERT_TRUE(pref_root.good()); | 4496 ASSERT_TRUE(pref_root.good()); |
4488 pref_root_id = pref_root.GetId(); | 4497 pref_root_id = pref_root.GetId(); |
4489 } | 4498 } |
4490 | 4499 |
4491 // Add a preference item with explicit parent ID. | 4500 // Add a preference item with explicit parent ID. |
4492 { | 4501 { |
4493 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 4502 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
4494 MutableEntry entry(&trans, CREATE, PREFERENCES, pref_root_id, "tag"); | 4503 MutableEntry entry(&trans, CREATE, PREFERENCES, pref_root_id, "tag"); |
4495 ASSERT_TRUE(entry.good()); | 4504 ASSERT_TRUE(entry.good()); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4668 mock_server_->ClearUpdatesQueue(); | 4677 mock_server_->ClearUpdatesQueue(); |
4669 } | 4678 } |
4670 | 4679 |
4671 // Downloads two updates and applies them successfully. | 4680 // Downloads two updates and applies them successfully. |
4672 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates. | 4681 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates. |
4673 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) { | 4682 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) { |
4674 syncable::Id node1 = ids_.NewServerId(); | 4683 syncable::Id node1 = ids_.NewServerId(); |
4675 syncable::Id node2 = ids_.NewServerId(); | 4684 syncable::Id node2 = ids_.NewServerId(); |
4676 | 4685 |
4677 // Construct the first GetUpdates response. | 4686 // Construct the first GetUpdates response. |
4678 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10, | 4687 mock_server_->AddUpdatePref(node1.GetServerId(), "", "one", 1, 10); |
4679 foreign_cache_guid(), "-2"); | |
4680 mock_server_->SetChangesRemaining(1); | 4688 mock_server_->SetChangesRemaining(1); |
4681 mock_server_->NextUpdateBatch(); | 4689 mock_server_->NextUpdateBatch(); |
4682 | 4690 |
4683 // Construct the second GetUpdates response. | 4691 // Construct the second GetUpdates response. |
4684 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20, | 4692 mock_server_->AddUpdatePref(node2.GetServerId(), "", "two", 2, 20); |
4685 foreign_cache_guid(), "-2"); | |
4686 | 4693 |
4687 SyncShareConfigure(); | 4694 SyncShareConfigure(); |
4688 | 4695 |
| 4696 // The type should now be marked as having the initial sync completed. |
| 4697 EXPECT_TRUE(directory()->InitialSyncEndedForType(PREFERENCES)); |
| 4698 |
4689 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4699 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4690 // Both nodes should be downloaded and applied. | 4700 // Both nodes should be downloaded and applied. |
4691 | 4701 |
4692 Entry n1(&trans, GET_BY_ID, node1); | 4702 Entry n1(&trans, GET_BY_ID, node1); |
4693 ASSERT_TRUE(n1.good()); | 4703 ASSERT_TRUE(n1.good()); |
4694 EXPECT_FALSE(n1.GetIsUnappliedUpdate()); | 4704 EXPECT_FALSE(n1.GetIsUnappliedUpdate()); |
4695 | 4705 |
4696 Entry n2(&trans, GET_BY_ID, node2); | 4706 Entry n2(&trans, GET_BY_ID, node2); |
4697 ASSERT_TRUE(n2.good()); | 4707 ASSERT_TRUE(n2.good()); |
4698 EXPECT_FALSE(n2.GetIsUnappliedUpdate()); | 4708 EXPECT_FALSE(n2.GetIsUnappliedUpdate()); |
4699 } | 4709 } |
4700 | 4710 |
4701 // Same as the above case, but this time the second batch fails to download. | 4711 // Same as the above case, but this time the second batch fails to download. |
4702 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { | 4712 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { |
4703 syncable::Id node1 = ids_.NewServerId(); | 4713 syncable::Id node1 = ids_.NewServerId(); |
4704 syncable::Id node2 = ids_.NewServerId(); | 4714 syncable::Id node2 = ids_.NewServerId(); |
4705 | 4715 |
4706 // The scenario: we have two batches of updates with one update each. A | 4716 // The scenario: we have two batches of updates with one update each. A |
4707 // normal confgure step would download all the updates one batch at a time and | 4717 // normal confgure step would download all the updates one batch at a time and |
4708 // apply them. This configure will succeed in downloading the first batch | 4718 // apply them. This configure will succeed in downloading the first batch |
4709 // then fail when downloading the second. | 4719 // then fail when downloading the second. |
4710 mock_server_->FailNthPostBufferToPathCall(2); | 4720 mock_server_->FailNthPostBufferToPathCall(2); |
4711 | 4721 |
4712 // Construct the first GetUpdates response. | 4722 // Construct the first GetUpdates response. |
4713 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10, | 4723 mock_server_->AddUpdatePref(node1.GetServerId(), "", "one", 1, 10); |
4714 foreign_cache_guid(), "-1"); | |
4715 mock_server_->SetChangesRemaining(1); | 4724 mock_server_->SetChangesRemaining(1); |
4716 mock_server_->NextUpdateBatch(); | 4725 mock_server_->NextUpdateBatch(); |
4717 | 4726 |
4718 // Consutrct the second GetUpdates response. | 4727 // Construct the second GetUpdates response. |
4719 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20, | 4728 mock_server_->AddUpdatePref(node2.GetServerId(), "", "two", 2, 20); |
4720 foreign_cache_guid(), "-2"); | |
4721 | 4729 |
4722 SyncShareConfigure(); | 4730 SyncShareConfigure(); |
4723 | 4731 |
| 4732 // The type shouldn't be marked as having the initial sync completed. |
| 4733 EXPECT_FALSE(directory()->InitialSyncEndedForType(PREFERENCES)); |
| 4734 |
4724 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4735 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4725 | 4736 |
4726 // The first node was downloaded, but not applied. | 4737 // The first node was downloaded, but not applied. |
4727 Entry n1(&trans, GET_BY_ID, node1); | 4738 Entry n1(&trans, GET_BY_ID, node1); |
4728 ASSERT_TRUE(n1.good()); | 4739 ASSERT_TRUE(n1.good()); |
4729 EXPECT_TRUE(n1.GetIsUnappliedUpdate()); | 4740 EXPECT_TRUE(n1.GetIsUnappliedUpdate()); |
4730 | 4741 |
4731 // The second node was not downloaded. | 4742 // The second node was not downloaded. |
4732 Entry n2(&trans, GET_BY_ID, node2); | 4743 Entry n2(&trans, GET_BY_ID, node2); |
4733 EXPECT_FALSE(n2.good()); | 4744 EXPECT_FALSE(n2.good()); |
(...skipping 26 matching lines...) Expand all Loading... |
4760 mock_server_->SetKeystoreKey(std::string()); | 4771 mock_server_->SetKeystoreKey(std::string()); |
4761 SyncShareConfigure(); | 4772 SyncShareConfigure(); |
4762 | 4773 |
4763 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK); | 4774 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK); |
4764 { | 4775 { |
4765 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 4776 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
4766 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); | 4777 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); |
4767 } | 4778 } |
4768 } | 4779 } |
4769 | 4780 |
| 4781 // Trigger an update that contains a progress marker only and verify that |
| 4782 // the type's permanent folder is created and the type is marked as having |
| 4783 // initial sync complete. |
| 4784 TEST_F(SyncerTest, ProgressMarkerOnlyUpdateCreatesRootFolder) { |
| 4785 EXPECT_FALSE(directory()->InitialSyncEndedForType(PREFERENCES)); |
| 4786 sync_pb::DataTypeProgressMarker* marker = |
| 4787 mock_server_->AddUpdateProgressMarker(); |
| 4788 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(PREFERENCES)); |
| 4789 marker->set_token("foobar"); |
| 4790 |
| 4791 SyncShareNudge(); |
| 4792 |
| 4793 { |
| 4794 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 4795 syncable::Entry root(&trans, syncable::GET_TYPE_ROOT, PREFERENCES); |
| 4796 EXPECT_TRUE(root.good()); |
| 4797 } |
| 4798 |
| 4799 EXPECT_TRUE(directory()->InitialSyncEndedForType(PREFERENCES)); |
| 4800 } |
| 4801 |
4770 // Tests specifically related to bookmark (and therefore no client tags) sync | 4802 // Tests specifically related to bookmark (and therefore no client tags) sync |
4771 // logic. Entities without client tags have custom logic in parts of the code, | 4803 // logic. Entities without client tags have custom logic in parts of the code, |
4772 // and hence are not covered by e.g. the Undeletion tests below. | 4804 // and hence are not covered by e.g. the Undeletion tests below. |
4773 class SyncerBookmarksTest : public SyncerTest { | 4805 class SyncerBookmarksTest : public SyncerTest { |
4774 public: | 4806 public: |
4775 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) { | 4807 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) { |
4776 } | 4808 } |
4777 | 4809 |
4778 void Create() { | 4810 void Create() { |
4779 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 4811 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5597 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5629 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5598 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5630 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5599 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5631 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5600 } else { | 5632 } else { |
5601 EXPECT_TRUE(final_monitor_records.empty()) | 5633 EXPECT_TRUE(final_monitor_records.empty()) |
5602 << "Should not restore records after successful bookmark commit."; | 5634 << "Should not restore records after successful bookmark commit."; |
5603 } | 5635 } |
5604 } | 5636 } |
5605 | 5637 |
5606 } // namespace syncer | 5638 } // namespace syncer |
OLD | NEW |