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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 return false; | 205 return false; |
206 } | 206 } |
207 virtual void OnReceivedLongPollIntervalUpdate( | 207 virtual void OnReceivedLongPollIntervalUpdate( |
208 const base::TimeDelta& new_interval) OVERRIDE { | 208 const base::TimeDelta& new_interval) OVERRIDE { |
209 last_long_poll_interval_received_ = new_interval; | 209 last_long_poll_interval_received_ = new_interval; |
210 } | 210 } |
211 virtual void OnReceivedShortPollIntervalUpdate( | 211 virtual void OnReceivedShortPollIntervalUpdate( |
212 const base::TimeDelta& new_interval) OVERRIDE { | 212 const base::TimeDelta& new_interval) OVERRIDE { |
213 last_short_poll_interval_received_ = new_interval; | 213 last_short_poll_interval_received_ = new_interval; |
214 } | 214 } |
215 virtual void OnReceivedSessionsCommitDelay( | 215 virtual void OnReceivedCustomNudgeDelays( |
216 const base::TimeDelta& new_delay) OVERRIDE { | 216 const std::map<ModelType, base::TimeDelta>& delay_map) OVERRIDE { |
217 last_sessions_commit_delay_seconds_ = new_delay; | 217 std::map<ModelType, base::TimeDelta>::const_iterator iter = |
| 218 delay_map.find(SESSIONS); |
| 219 if (iter != delay_map.end() && iter->second > base::TimeDelta()) |
| 220 last_sessions_commit_delay_ = iter->second; |
| 221 iter = delay_map.find(BOOKMARKS); |
| 222 if (iter != delay_map.end() && iter->second > base::TimeDelta()) |
| 223 last_bookmarks_commit_delay_ = iter->second; |
218 } | 224 } |
219 virtual void OnReceivedClientInvalidationHintBufferSize( | 225 virtual void OnReceivedClientInvalidationHintBufferSize( |
220 int size) OVERRIDE { | 226 int size) OVERRIDE { |
221 last_client_invalidation_hint_buffer_size_ = size; | 227 last_client_invalidation_hint_buffer_size_ = size; |
222 } | 228 } |
223 virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) OVERRIDE {} | 229 virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) OVERRIDE {} |
224 virtual void OnReceivedMigrationRequest(ModelTypeSet types) OVERRIDE {} | 230 virtual void OnReceivedMigrationRequest(ModelTypeSet types) OVERRIDE {} |
225 virtual void OnProtocolEvent(const ProtocolEvent& event) OVERRIDE {} | 231 virtual void OnProtocolEvent(const ProtocolEvent& event) OVERRIDE {} |
226 virtual void OnSyncProtocolError(const SyncProtocolError& error) OVERRIDE {} | 232 virtual void OnSyncProtocolError(const SyncProtocolError& error) OVERRIDE {} |
227 | 233 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 Syncer* syncer_; | 591 Syncer* syncer_; |
586 | 592 |
587 scoped_ptr<SyncSession> session_; | 593 scoped_ptr<SyncSession> session_; |
588 TypeDebugInfoCache debug_info_cache_; | 594 TypeDebugInfoCache debug_info_cache_; |
589 MockNudgeHandler mock_nudge_handler_; | 595 MockNudgeHandler mock_nudge_handler_; |
590 scoped_ptr<ModelTypeRegistry> model_type_registry_; | 596 scoped_ptr<ModelTypeRegistry> model_type_registry_; |
591 scoped_ptr<SyncSessionContext> context_; | 597 scoped_ptr<SyncSessionContext> context_; |
592 bool saw_syncer_event_; | 598 bool saw_syncer_event_; |
593 base::TimeDelta last_short_poll_interval_received_; | 599 base::TimeDelta last_short_poll_interval_received_; |
594 base::TimeDelta last_long_poll_interval_received_; | 600 base::TimeDelta last_long_poll_interval_received_; |
595 base::TimeDelta last_sessions_commit_delay_seconds_; | 601 base::TimeDelta last_sessions_commit_delay_; |
| 602 base::TimeDelta last_bookmarks_commit_delay_; |
596 int last_client_invalidation_hint_buffer_size_; | 603 int last_client_invalidation_hint_buffer_size_; |
597 std::vector<scoped_refptr<ModelSafeWorker> > workers_; | 604 std::vector<scoped_refptr<ModelSafeWorker> > workers_; |
598 | 605 |
599 ModelTypeSet enabled_datatypes_; | 606 ModelTypeSet enabled_datatypes_; |
600 sessions::NudgeTracker nudge_tracker_; | 607 sessions::NudgeTracker nudge_tracker_; |
601 scoped_ptr<MockDebugInfoGetter> debug_info_getter_; | 608 scoped_ptr<MockDebugInfoGetter> debug_info_getter_; |
602 | 609 |
603 DISALLOW_COPY_AND_ASSIGN(SyncerTest); | 610 DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
604 }; | 611 }; |
605 | 612 |
(...skipping 2993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 } | 3606 } |
3600 } | 3607 } |
3601 | 3608 |
3602 TEST_F(SyncerTest, TestClientCommandDuringUpdate) { | 3609 TEST_F(SyncerTest, TestClientCommandDuringUpdate) { |
3603 using sync_pb::ClientCommand; | 3610 using sync_pb::ClientCommand; |
3604 | 3611 |
3605 ClientCommand* command = new ClientCommand(); | 3612 ClientCommand* command = new ClientCommand(); |
3606 command->set_set_sync_poll_interval(8); | 3613 command->set_set_sync_poll_interval(8); |
3607 command->set_set_sync_long_poll_interval(800); | 3614 command->set_set_sync_long_poll_interval(800); |
3608 command->set_sessions_commit_delay_seconds(3141); | 3615 command->set_sessions_commit_delay_seconds(3141); |
| 3616 sync_pb::CustomNudgeDelay* bookmark_delay = |
| 3617 command->add_custom_nudge_delays(); |
| 3618 bookmark_delay->set_datatype_id( |
| 3619 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); |
| 3620 bookmark_delay->set_delay_ms(950); |
3609 command->set_client_invalidation_hint_buffer_size(11); | 3621 command->set_client_invalidation_hint_buffer_size(11); |
3610 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1, | 3622 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1, |
3611 foreign_cache_guid(), "-1"); | 3623 foreign_cache_guid(), "-1"); |
3612 mock_server_->SetGUClientCommand(command); | 3624 mock_server_->SetGUClientCommand(command); |
3613 SyncShareNudge(); | 3625 SyncShareNudge(); |
3614 | 3626 |
3615 EXPECT_TRUE(TimeDelta::FromSeconds(8) == | 3627 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_); |
3616 last_short_poll_interval_received_); | 3628 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_); |
3617 EXPECT_TRUE(TimeDelta::FromSeconds(800) == | 3629 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_); |
3618 last_long_poll_interval_received_); | 3630 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_); |
3619 EXPECT_TRUE(TimeDelta::FromSeconds(3141) == | |
3620 last_sessions_commit_delay_seconds_); | |
3621 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); | 3631 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); |
3622 | 3632 |
3623 command = new ClientCommand(); | 3633 command = new ClientCommand(); |
3624 command->set_set_sync_poll_interval(180); | 3634 command->set_set_sync_poll_interval(180); |
3625 command->set_set_sync_long_poll_interval(190); | 3635 command->set_set_sync_long_poll_interval(190); |
3626 command->set_sessions_commit_delay_seconds(2718); | 3636 command->set_sessions_commit_delay_seconds(2718); |
| 3637 bookmark_delay = command->add_custom_nudge_delays(); |
| 3638 bookmark_delay->set_datatype_id( |
| 3639 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); |
| 3640 bookmark_delay->set_delay_ms(1050); |
3627 command->set_client_invalidation_hint_buffer_size(9); | 3641 command->set_client_invalidation_hint_buffer_size(9); |
3628 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1, | 3642 mock_server_->AddUpdateDirectory( |
3629 foreign_cache_guid(), "-1"); | 3643 1, 0, "in_root", 1, 1, foreign_cache_guid(), "-1"); |
3630 mock_server_->SetGUClientCommand(command); | 3644 mock_server_->SetGUClientCommand(command); |
3631 SyncShareNudge(); | 3645 SyncShareNudge(); |
3632 | 3646 |
3633 EXPECT_TRUE(TimeDelta::FromSeconds(180) == | 3647 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_); |
3634 last_short_poll_interval_received_); | 3648 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_); |
3635 EXPECT_TRUE(TimeDelta::FromSeconds(190) == | 3649 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); |
3636 last_long_poll_interval_received_); | 3650 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); |
3637 EXPECT_TRUE(TimeDelta::FromSeconds(2718) == | |
3638 last_sessions_commit_delay_seconds_); | |
3639 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); | 3651 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); |
3640 } | 3652 } |
3641 | 3653 |
3642 TEST_F(SyncerTest, TestClientCommandDuringCommit) { | 3654 TEST_F(SyncerTest, TestClientCommandDuringCommit) { |
3643 using sync_pb::ClientCommand; | 3655 using sync_pb::ClientCommand; |
3644 | 3656 |
3645 ClientCommand* command = new ClientCommand(); | 3657 ClientCommand* command = new ClientCommand(); |
3646 command->set_set_sync_poll_interval(8); | 3658 command->set_set_sync_poll_interval(8); |
3647 command->set_set_sync_long_poll_interval(800); | 3659 command->set_set_sync_long_poll_interval(800); |
3648 command->set_sessions_commit_delay_seconds(3141); | 3660 command->set_sessions_commit_delay_seconds(3141); |
| 3661 sync_pb::CustomNudgeDelay* bookmark_delay = |
| 3662 command->add_custom_nudge_delays(); |
| 3663 bookmark_delay->set_datatype_id( |
| 3664 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); |
| 3665 bookmark_delay->set_delay_ms(950); |
3649 command->set_client_invalidation_hint_buffer_size(11); | 3666 command->set_client_invalidation_hint_buffer_size(11); |
3650 CreateUnsyncedDirectory("X", "id_X"); | 3667 CreateUnsyncedDirectory("X", "id_X"); |
3651 mock_server_->SetCommitClientCommand(command); | 3668 mock_server_->SetCommitClientCommand(command); |
3652 SyncShareNudge(); | 3669 SyncShareNudge(); |
3653 | 3670 |
3654 EXPECT_TRUE(TimeDelta::FromSeconds(8) == | 3671 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_); |
3655 last_short_poll_interval_received_); | 3672 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_); |
3656 EXPECT_TRUE(TimeDelta::FromSeconds(800) == | 3673 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_); |
3657 last_long_poll_interval_received_); | 3674 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_); |
3658 EXPECT_TRUE(TimeDelta::FromSeconds(3141) == | |
3659 last_sessions_commit_delay_seconds_); | |
3660 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); | 3675 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); |
3661 | 3676 |
3662 command = new ClientCommand(); | 3677 command = new ClientCommand(); |
3663 command->set_set_sync_poll_interval(180); | 3678 command->set_set_sync_poll_interval(180); |
3664 command->set_set_sync_long_poll_interval(190); | 3679 command->set_set_sync_long_poll_interval(190); |
3665 command->set_sessions_commit_delay_seconds(2718); | 3680 command->set_sessions_commit_delay_seconds(2718); |
| 3681 bookmark_delay = command->add_custom_nudge_delays(); |
| 3682 bookmark_delay->set_datatype_id( |
| 3683 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); |
| 3684 bookmark_delay->set_delay_ms(1050); |
3666 command->set_client_invalidation_hint_buffer_size(9); | 3685 command->set_client_invalidation_hint_buffer_size(9); |
3667 CreateUnsyncedDirectory("Y", "id_Y"); | 3686 CreateUnsyncedDirectory("Y", "id_Y"); |
3668 mock_server_->SetCommitClientCommand(command); | 3687 mock_server_->SetCommitClientCommand(command); |
3669 SyncShareNudge(); | 3688 SyncShareNudge(); |
3670 | 3689 |
3671 EXPECT_TRUE(TimeDelta::FromSeconds(180) == | 3690 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_); |
3672 last_short_poll_interval_received_); | 3691 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_); |
3673 EXPECT_TRUE(TimeDelta::FromSeconds(190) == | 3692 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); |
3674 last_long_poll_interval_received_); | 3693 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); |
3675 EXPECT_TRUE(TimeDelta::FromSeconds(2718) == | |
3676 last_sessions_commit_delay_seconds_); | |
3677 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); | 3694 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); |
3678 } | 3695 } |
3679 | 3696 |
3680 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { | 3697 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { |
3681 syncable::Id folder_one_id = ids_.FromNumber(1); | 3698 syncable::Id folder_one_id = ids_.FromNumber(1); |
3682 syncable::Id folder_two_id = ids_.FromNumber(2); | 3699 syncable::Id folder_two_id = ids_.FromNumber(2); |
3683 | 3700 |
3684 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), | 3701 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), |
3685 "folder_one", 1, 1, foreign_cache_guid(), "-1"); | 3702 "folder_one", 1, 1, foreign_cache_guid(), "-1"); |
3686 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), | 3703 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), |
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5031 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5048 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5032 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5049 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5033 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5050 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5034 } else { | 5051 } else { |
5035 EXPECT_TRUE(final_monitor_records.empty()) | 5052 EXPECT_TRUE(final_monitor_records.empty()) |
5036 << "Should not restore records after successful bookmark commit."; | 5053 << "Should not restore records after successful bookmark commit."; |
5037 } | 5054 } |
5038 } | 5055 } |
5039 | 5056 |
5040 } // namespace syncer | 5057 } // namespace syncer |
OLD | NEW |