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.
5 #include "sync/sessions/test_util.h"
11 void SimulateGetEncryptionKeyFailed(sessions::SyncSession
* session
,
12 SyncerStep begin
, SyncerStep end
) {
13 session
->mutable_status_controller()->set_last_get_key_result(
14 SERVER_RESPONSE_VALIDATION_FAILED
);
15 session
->mutable_status_controller()->set_last_download_updates_result(
19 void SimulateDownloadUpdatesFailed(sessions::SyncSession
* session
,
20 SyncerStep begin
, SyncerStep end
) {
21 session
->mutable_status_controller()->set_last_get_key_result(SYNCER_OK
);
22 session
->mutable_status_controller()->set_last_download_updates_result(
23 SERVER_RETURN_TRANSIENT_ERROR
);
26 void SimulateCommitFailed(sessions::SyncSession
* session
,
27 SyncerStep begin
, SyncerStep end
) {
28 session
->mutable_status_controller()->set_last_get_key_result(SYNCER_OK
);
29 session
->mutable_status_controller()->set_last_download_updates_result(
31 session
->mutable_status_controller()->set_commit_result(
32 SERVER_RETURN_TRANSIENT_ERROR
);
35 void SimulateConnectionFailure(sessions::SyncSession
* session
,
36 SyncerStep begin
, SyncerStep end
) {
37 session
->mutable_status_controller()->set_last_download_updates_result(
38 NETWORK_CONNECTION_UNAVAILABLE
);
41 void SimulateSuccess(sessions::SyncSession
* session
,
42 SyncerStep begin
, SyncerStep end
) {
43 ASSERT_EQ(0U, session
->status_controller().num_server_changes_remaining());
46 session
->mutable_status_controller()->set_commit_result(SYNCER_OK
);
49 DCHECK_EQ(end
== APPLY_UPDATES
, session
->source().updates_source
==
50 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION
);
51 session
->mutable_status_controller()->set_last_get_key_result(SYNCER_OK
);
52 session
->mutable_status_controller()->set_last_download_updates_result(
56 ADD_FAILURE() << "Not a valid END state.";
60 void SimulateThrottledImpl(sessions::SyncSession
* session
,
61 const base::TimeDelta
& delta
) {
62 session
->mutable_status_controller()->set_last_download_updates_result(
63 SERVER_RETURN_THROTTLED
);
64 session
->delegate()->OnSilencedUntil(base::TimeTicks::Now() + delta
);
67 void SimulatePollIntervalUpdateImpl(sessions::SyncSession
* session
,
68 const base::TimeDelta
& new_poll
) {
69 SimulateSuccess(session
, SYNCER_BEGIN
, SYNCER_END
);
70 session
->delegate()->OnReceivedLongPollIntervalUpdate(new_poll
);
73 void SimulateSessionsCommitDelayUpdateImpl(sessions::SyncSession
* session
,
74 const base::TimeDelta
& new_delay
) {
75 SimulateSuccess(session
, SYNCER_BEGIN
, SYNCER_END
);
76 session
->delegate()->OnReceivedSessionsCommitDelay(new_delay
);
79 } // namespace test_util
80 } // namespace sessions