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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4692 Entry n1(&trans, GET_BY_ID, node1); | 4701 Entry n1(&trans, GET_BY_ID, node1); |
4693 ASSERT_TRUE(n1.good()); | 4702 ASSERT_TRUE(n1.good()); |
4694 EXPECT_FALSE(n1.GetIsUnappliedUpdate()); | 4703 EXPECT_FALSE(n1.GetIsUnappliedUpdate()); |
4695 | 4704 |
4696 Entry n2(&trans, GET_BY_ID, node2); | 4705 Entry n2(&trans, GET_BY_ID, node2); |
4697 ASSERT_TRUE(n2.good()); | 4706 ASSERT_TRUE(n2.good()); |
4698 EXPECT_FALSE(n2.GetIsUnappliedUpdate()); | 4707 EXPECT_FALSE(n2.GetIsUnappliedUpdate()); |
4699 } | 4708 } |
4700 | 4709 |
4701 // Same as the above case, but this time the second batch fails to download. | 4710 // Same as the above case, but this time the second batch fails to download. |
4702 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { | 4711 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { |
Nicolas Zea
2015/10/13 17:51:37
Should this be updated? AFAICT you're now actually
stanisc
2015/10/13 21:23:12
Good point. I removed the extra sync cycle from th
| |
4703 syncable::Id node1 = ids_.NewServerId(); | 4712 syncable::Id node1 = ids_.NewServerId(); |
4704 syncable::Id node2 = ids_.NewServerId(); | 4713 syncable::Id node2 = ids_.NewServerId(); |
4705 | 4714 |
4706 // The scenario: we have two batches of updates with one update each. A | 4715 // 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 | 4716 // 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 | 4717 // apply them. This configure will succeed in downloading the first batch |
4709 // then fail when downloading the second. | 4718 // then fail when downloading the second. |
4710 mock_server_->FailNthPostBufferToPathCall(2); | 4719 mock_server_->FailNthPostBufferToPathCall(2); |
4711 | 4720 |
4712 // Construct the first GetUpdates response. | 4721 // Construct the first GetUpdates response. |
4713 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10, | 4722 mock_server_->AddUpdatePref(node1.GetServerId(), "", "one", 1, 10); |
4714 foreign_cache_guid(), "-1"); | |
4715 mock_server_->SetChangesRemaining(1); | 4723 mock_server_->SetChangesRemaining(1); |
4716 mock_server_->NextUpdateBatch(); | 4724 mock_server_->NextUpdateBatch(); |
4717 | 4725 |
4718 // Consutrct the second GetUpdates response. | 4726 // Construct the second GetUpdates response. |
4719 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20, | 4727 mock_server_->AddUpdatePref(node2.GetServerId(), "", "two", 2, 20); |
4720 foreign_cache_guid(), "-2"); | |
4721 | 4728 |
4722 SyncShareConfigure(); | 4729 SyncShareConfigure(); |
4723 | 4730 |
4724 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4731 // The type shouldn't be marked as having the initial sync completed. |
4732 EXPECT_FALSE(directory()->InitialSyncEndedForType(PREFERENCES)); | |
4725 | 4733 |
4726 // The first node was downloaded, but not applied. | 4734 { |
4727 Entry n1(&trans, GET_BY_ID, node1); | 4735 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4728 ASSERT_TRUE(n1.good()); | |
4729 EXPECT_TRUE(n1.GetIsUnappliedUpdate()); | |
4730 | 4736 |
4731 // The second node was not downloaded. | 4737 // The first node was downloaded, but not applied. |
4732 Entry n2(&trans, GET_BY_ID, node2); | 4738 Entry n1(&trans, GET_BY_ID, node1); |
4733 EXPECT_FALSE(n2.good()); | 4739 ASSERT_TRUE(n1.good()); |
4740 EXPECT_TRUE(n1.GetIsUnappliedUpdate()); | |
4734 | 4741 |
4735 // One update remains undownloaded. | 4742 // The second node was not downloaded. |
4736 mock_server_->ClearUpdatesQueue(); | 4743 Entry n2(&trans, GET_BY_ID, node2); |
4744 EXPECT_FALSE(n2.good()); | |
4745 } | |
4746 | |
4747 // Finish the download and verify that the type is now marked as | |
4748 // having the initial sync completed. | |
4749 SyncShareNudge(); | |
4750 | |
4751 EXPECT_TRUE(directory()->InitialSyncEndedForType(PREFERENCES)); | |
4737 } | 4752 } |
4738 | 4753 |
4739 TEST_F(SyncerTest, GetKeySuccess) { | 4754 TEST_F(SyncerTest, GetKeySuccess) { |
4740 { | 4755 { |
4741 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 4756 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
4742 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); | 4757 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); |
4743 } | 4758 } |
4744 | 4759 |
4745 SyncShareConfigure(); | 4760 SyncShareConfigure(); |
4746 | 4761 |
(...skipping 13 matching lines...) Expand all Loading... | |
4760 mock_server_->SetKeystoreKey(std::string()); | 4775 mock_server_->SetKeystoreKey(std::string()); |
4761 SyncShareConfigure(); | 4776 SyncShareConfigure(); |
4762 | 4777 |
4763 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK); | 4778 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK); |
4764 { | 4779 { |
4765 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 4780 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
4766 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); | 4781 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); |
4767 } | 4782 } |
4768 } | 4783 } |
4769 | 4784 |
4785 // Trigger an update that contains a progress marker only and verify that | |
4786 // the type gets marked as having initial sync complete. | |
4787 TEST_F(SyncerTest, ProgressMarkerOnlyUpdate) { | |
Nicolas Zea
2015/10/13 17:51:37
This is to test the the implicit permanent folder
stanisc
2015/10/13 21:23:11
Right. Added a comment. Also added a check that ve
| |
4788 EXPECT_FALSE(directory()->InitialSyncEndedForType(PREFERENCES)); | |
4789 sync_pb::DataTypeProgressMarker* marker = | |
4790 mock_server_->AddUpdateProgressMarker(); | |
4791 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(PREFERENCES)); | |
4792 marker->set_token("foobar"); | |
4793 | |
4794 SyncShareNudge(); | |
4795 | |
4796 EXPECT_TRUE(directory()->InitialSyncEndedForType(PREFERENCES)); | |
4797 } | |
4798 | |
4770 // Tests specifically related to bookmark (and therefore no client tags) sync | 4799 // 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, | 4800 // 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. | 4801 // and hence are not covered by e.g. the Undeletion tests below. |
4773 class SyncerBookmarksTest : public SyncerTest { | 4802 class SyncerBookmarksTest : public SyncerTest { |
4774 public: | 4803 public: |
4775 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) { | 4804 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) { |
4776 } | 4805 } |
4777 | 4806 |
4778 void Create() { | 4807 void Create() { |
4779 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 4808 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); | 5626 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5598 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5627 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5599 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5628 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5600 } else { | 5629 } else { |
5601 EXPECT_TRUE(final_monitor_records.empty()) | 5630 EXPECT_TRUE(final_monitor_records.empty()) |
5602 << "Should not restore records after successful bookmark commit."; | 5631 << "Should not restore records after successful bookmark commit."; |
5603 } | 5632 } |
5604 } | 5633 } |
5605 | 5634 |
5606 } // namespace syncer | 5635 } // namespace syncer |
OLD | NEW |