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 3 // found in the LICENSE file. 4 5 #include "sync/sessions/test_util.h" 6 7 namespace syncer { 8 namespace sessions { 9 namespace test_util { 10 11 void SimulateGetEncryptionKeyFailed( 12 ModelTypeSet requsted_types, 13 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 14 sessions::SyncSession* session) { 15 session->mutable_status_controller()->set_last_get_key_result( 16 SERVER_RESPONSE_VALIDATION_FAILED); 17 session->mutable_status_controller()->set_last_download_updates_result( 18 SYNCER_OK); 19 } 20 21 void SimulateConfigureSuccess( 22 ModelTypeSet requsted_types, 23 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 24 sessions::SyncSession* session) { 25 ASSERT_EQ(0U, session->status_controller().num_server_changes_remaining()); 26 session->mutable_status_controller()->set_last_get_key_result(SYNCER_OK); 27 session->mutable_status_controller()->set_last_download_updates_result( 28 SYNCER_OK); 29 } 30 31 void SimulateConfigureFailed( 32 ModelTypeSet requsted_types, 33 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 34 sessions::SyncSession* session) { 35 session->mutable_status_controller()->set_last_get_key_result(SYNCER_OK); 36 session->mutable_status_controller()->set_last_download_updates_result( 37 SERVER_RETURN_TRANSIENT_ERROR); 38 } 39 40 void SimulateConfigureConnectionFailure( 41 ModelTypeSet requsted_types, 42 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 43 sessions::SyncSession* session) { 44 session->mutable_status_controller()->set_last_get_key_result(SYNCER_OK); 45 session->mutable_status_controller()->set_last_download_updates_result( 46 NETWORK_CONNECTION_UNAVAILABLE); 47 } 48 49 void SimulateNormalSuccess(ModelTypeSet requested_types, 50 const sessions::NudgeTracker& nudge_tracker, 51 sessions::SyncSession* session) { 52 ASSERT_EQ(0U, session->status_controller().num_server_changes_remaining()); 53 session->mutable_status_controller()->set_commit_result(SYNCER_OK); 54 session->mutable_status_controller()->set_last_download_updates_result( 55 SYNCER_OK); 56 } 57 58 void SimulateDownloadUpdatesFailed( 59 ModelTypeSet requested_types, 60 const sessions::NudgeTracker& nudge_tracker, 61 sessions::SyncSession* session) { 62 session->mutable_status_controller()->set_last_download_updates_result( 63 SERVER_RETURN_TRANSIENT_ERROR); 64 } 65 66 void SimulateCommitFailed(ModelTypeSet requested_types, 67 const sessions::NudgeTracker& nudge_tracker, 68 sessions::SyncSession* session) { 69 session->mutable_status_controller()->set_last_get_key_result(SYNCER_OK); 70 session->mutable_status_controller()->set_last_download_updates_result( 71 SYNCER_OK); 72 session->mutable_status_controller()->set_commit_result( 73 SERVER_RETURN_TRANSIENT_ERROR); 74 } 75 76 void SimulateConnectionFailure( 77 ModelTypeSet requested_types, 78 const sessions::NudgeTracker& nudge_tracker, 79 sessions::SyncSession* session) { 80 session->mutable_status_controller()->set_last_download_updates_result( 81 NETWORK_CONNECTION_UNAVAILABLE); 82 } 83 84 void SimulatePollSuccess(ModelTypeSet requested_types, 85 sessions::SyncSession* session) { 86 ASSERT_EQ(0U, session->status_controller().num_server_changes_remaining()); 87 session->mutable_status_controller()->set_last_download_updates_result( 88 SYNCER_OK); 89 } 90 91 void SimulatePollFailed(ModelTypeSet requested_types, 92 sessions::SyncSession* session) { 93 ASSERT_EQ(0U, session->status_controller().num_server_changes_remaining()); 94 session->mutable_status_controller()->set_last_download_updates_result( 95 SERVER_RETURN_TRANSIENT_ERROR); 96 } 97 98 void SimulateThrottledImpl( 99 sessions::SyncSession* session, 100 const base::TimeDelta& delta) { 101 session->mutable_status_controller()->set_last_download_updates_result( 102 SERVER_RETURN_THROTTLED); 103 session->delegate()->OnThrottled(delta); 104 } 105 106 void SimulateTypesThrottledImpl( 107 sessions::SyncSession* session, 108 ModelTypeSet types, 109 const base::TimeDelta& delta) { 110 session->mutable_status_controller()->set_last_download_updates_result( 111 SERVER_RETURN_THROTTLED); 112 session->delegate()->OnTypesThrottled(types, delta); 113 } 114 115 void SimulatePollIntervalUpdateImpl( 116 ModelTypeSet requested_types, 117 sessions::SyncSession* session, 118 const base::TimeDelta& new_poll) { 119 SimulatePollSuccess(requested_types, session); 120 session->delegate()->OnReceivedLongPollIntervalUpdate(new_poll); 121 } 122 123 void SimulateSessionsCommitDelayUpdateImpl( 124 ModelTypeSet requested_types, 125 const sessions::NudgeTracker& nudge_tracker, 126 sessions::SyncSession* session, 127 const base::TimeDelta& new_delay) { 128 SimulateNormalSuccess(requested_types, nudge_tracker, session); 129 session->delegate()->OnReceivedSessionsCommitDelay(new_delay); 130 } 131 132 } // namespace test_util 133 } // namespace sessions 134 } // namespace syncer 135