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 // 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 EXPECT_FALSE(client_status.hierarchy_conflict_detected()); | 290 EXPECT_FALSE(client_status.hierarchy_conflict_detected()); |
291 } | 291 } |
292 | 292 |
293 void VerifyHierarchyConflictsUnspecified( | 293 void VerifyHierarchyConflictsUnspecified( |
294 const sync_pb::ClientToServerMessage& message) { | 294 const sync_pb::ClientToServerMessage& message) { |
295 // Our request should have neither confirmed nor denied hierarchy conflicts. | 295 // Our request should have neither confirmed nor denied hierarchy conflicts. |
296 const sync_pb::ClientStatus& client_status = message.client_status(); | 296 const sync_pb::ClientStatus& client_status = message.client_status(); |
297 EXPECT_FALSE(client_status.has_hierarchy_conflict_detected()); | 297 EXPECT_FALSE(client_status.has_hierarchy_conflict_detected()); |
298 } | 298 } |
299 | 299 |
300 bool initial_sync_ended_for_type(ModelType type) { | |
301 return directory()->initial_sync_ended_for_type(type); | |
302 } | |
303 | |
304 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { | 300 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { |
305 // We should trigger after less than 6 syncs, but extra does no harm. | 301 // We should trigger after less than 6 syncs, but extra does no harm. |
306 for (int i = 0 ; i < 6 ; ++i) | 302 for (int i = 0 ; i < 6 ; ++i) |
307 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); | 303 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); |
308 } | 304 } |
309 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { | 305 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { |
310 // We should trigger after less than 10 syncs, but we want to avoid brittle | 306 // We should trigger after less than 10 syncs, but we want to avoid brittle |
311 // tests. | 307 // tests. |
312 for (int i = 0 ; i < 12 ; ++i) | 308 for (int i = 0 ; i < 12 ; ++i) |
313 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); | 309 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); |
(...skipping 3631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3945 EXPECT_TRUE(committed.Get(IS_UNSYNCED)); | 3941 EXPECT_TRUE(committed.Get(IS_UNSYNCED)); |
3946 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE)); | 3942 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE)); |
3947 | 3943 |
3948 // Inform the Mock we won't be fetching all updates. | 3944 // Inform the Mock we won't be fetching all updates. |
3949 mock_server_->ClearUpdatesQueue(); | 3945 mock_server_->ClearUpdatesQueue(); |
3950 } | 3946 } |
3951 | 3947 |
3952 // Downloads two updates and applies them successfully. | 3948 // Downloads two updates and applies them successfully. |
3953 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates. | 3949 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates. |
3954 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) { | 3950 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) { |
3955 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS)); | |
3956 | |
3957 syncable::Id node1 = ids_.NewServerId(); | 3951 syncable::Id node1 = ids_.NewServerId(); |
3958 syncable::Id node2 = ids_.NewServerId(); | 3952 syncable::Id node2 = ids_.NewServerId(); |
3959 | 3953 |
3960 // Construct the first GetUpdates response. | 3954 // Construct the first GetUpdates response. |
3961 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10); | 3955 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10); |
3962 mock_server_->SetChangesRemaining(1); | 3956 mock_server_->SetChangesRemaining(1); |
3963 mock_server_->NextUpdateBatch(); | 3957 mock_server_->NextUpdateBatch(); |
3964 | 3958 |
3965 // Construct the second GetUpdates response. | 3959 // Construct the second GetUpdates response. |
3966 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20); | 3960 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20); |
3967 | 3961 |
3968 SyncShareConfigure(); | 3962 SyncShareConfigure(); |
3969 | 3963 |
3970 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3964 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3971 // Both nodes should be downloaded and applied. | 3965 // Both nodes should be downloaded and applied. |
3972 | 3966 |
3973 Entry n1(&trans, GET_BY_ID, node1); | 3967 Entry n1(&trans, GET_BY_ID, node1); |
3974 ASSERT_TRUE(n1.good()); | 3968 ASSERT_TRUE(n1.good()); |
3975 EXPECT_FALSE(n1.Get(IS_UNAPPLIED_UPDATE)); | 3969 EXPECT_FALSE(n1.Get(IS_UNAPPLIED_UPDATE)); |
3976 | 3970 |
3977 Entry n2(&trans, GET_BY_ID, node2); | 3971 Entry n2(&trans, GET_BY_ID, node2); |
3978 ASSERT_TRUE(n2.good()); | 3972 ASSERT_TRUE(n2.good()); |
3979 EXPECT_FALSE(n2.Get(IS_UNAPPLIED_UPDATE)); | 3973 EXPECT_FALSE(n2.Get(IS_UNAPPLIED_UPDATE)); |
3980 | |
3981 EXPECT_TRUE(initial_sync_ended_for_type(BOOKMARKS)); | |
3982 } | 3974 } |
3983 | 3975 |
3984 // Same as the above case, but this time the second batch fails to download. | 3976 // Same as the above case, but this time the second batch fails to download. |
3985 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { | 3977 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { |
3986 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS)); | |
3987 | |
3988 syncable::Id node1 = ids_.NewServerId(); | 3978 syncable::Id node1 = ids_.NewServerId(); |
3989 syncable::Id node2 = ids_.NewServerId(); | 3979 syncable::Id node2 = ids_.NewServerId(); |
3990 | 3980 |
3991 // The scenario: we have two batches of updates with one update each. A | 3981 // The scenario: we have two batches of updates with one update each. A |
3992 // normal confgure step would download all the updates one batch at a time and | 3982 // normal confgure step would download all the updates one batch at a time and |
3993 // apply them. This configure will succeed in downloading the first batch | 3983 // apply them. This configure will succeed in downloading the first batch |
3994 // then fail when downloading the second. | 3984 // then fail when downloading the second. |
3995 mock_server_->FailNthPostBufferToPathCall(2); | 3985 mock_server_->FailNthPostBufferToPathCall(2); |
3996 | 3986 |
3997 // Construct the first GetUpdates response. | 3987 // Construct the first GetUpdates response. |
(...skipping 12 matching lines...) Expand all Loading... |
4010 Entry n1(&trans, GET_BY_ID, node1); | 4000 Entry n1(&trans, GET_BY_ID, node1); |
4011 ASSERT_TRUE(n1.good()); | 4001 ASSERT_TRUE(n1.good()); |
4012 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE)); | 4002 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE)); |
4013 | 4003 |
4014 // The second node was not downloaded. | 4004 // The second node was not downloaded. |
4015 Entry n2(&trans, GET_BY_ID, node2); | 4005 Entry n2(&trans, GET_BY_ID, node2); |
4016 EXPECT_FALSE(n2.good()); | 4006 EXPECT_FALSE(n2.good()); |
4017 | 4007 |
4018 // One update remains undownloaded. | 4008 // One update remains undownloaded. |
4019 mock_server_->ClearUpdatesQueue(); | 4009 mock_server_->ClearUpdatesQueue(); |
4020 | |
4021 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS)); | |
4022 } | 4010 } |
4023 | 4011 |
4024 TEST_F(SyncerTest, GetKeySuccess) { | 4012 TEST_F(SyncerTest, GetKeySuccess) { |
4025 { | 4013 { |
4026 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 4014 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
4027 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); | 4015 EXPECT_TRUE(directory()->GetNigoriHandler()->NeedKeystoreKey(&rtrans)); |
4028 } | 4016 } |
4029 | 4017 |
4030 SyncShareConfigure(); | 4018 SyncShareConfigure(); |
4031 | 4019 |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4711 | 4699 |
4712 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4700 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
4713 Add(mid_id_); | 4701 Add(mid_id_); |
4714 Add(low_id_); | 4702 Add(low_id_); |
4715 Add(high_id_); | 4703 Add(high_id_); |
4716 SyncShareNudge(); | 4704 SyncShareNudge(); |
4717 ExpectLocalOrderIsByServerId(); | 4705 ExpectLocalOrderIsByServerId(); |
4718 } | 4706 } |
4719 | 4707 |
4720 } // namespace syncer | 4708 } // namespace syncer |
OLD | NEW |