1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/sessions/test_util.h"
namespace syncer {
namespace sessions {
namespace test_util {
void SimulateGetEncryptionKeyFailed(sessions::SyncSession* session,
SyncerStep begin, SyncerStep end) {
session->mutable_status_controller()->set_last_get_key_result(
SERVER_RESPONSE_VALIDATION_FAILED);
session->mutable_status_controller()->set_last_download_updates_result(
SYNCER_OK);
}
void SimulateDownloadUpdatesFailed(sessions::SyncSession* session,
SyncerStep begin, SyncerStep end) {
session->mutable_status_controller()->set_last_get_key_result(SYNCER_OK);
session->mutable_status_controller()->set_last_download_updates_result(
SERVER_RETURN_TRANSIENT_ERROR);
}
void SimulateCommitFailed(sessions::SyncSession* session,
SyncerStep begin, SyncerStep end) {
session->mutable_status_controller()->set_last_get_key_result(SYNCER_OK);
session->mutable_status_controller()->set_last_download_updates_result(
SYNCER_OK);
session->mutable_status_controller()->set_commit_result(
SERVER_RETURN_TRANSIENT_ERROR);
}
void SimulateConnectionFailure(sessions::SyncSession* session,
SyncerStep begin, SyncerStep end) {
session->mutable_status_controller()->set_last_download_updates_result(
NETWORK_CONNECTION_UNAVAILABLE);
}
void SimulateSuccess(sessions::SyncSession* session,
SyncerStep begin, SyncerStep end) {
ASSERT_EQ(0U, session->status_controller().num_server_changes_remaining());
switch(end) {
case SYNCER_END:
session->mutable_status_controller()->set_commit_result(SYNCER_OK);
// Fall through.
case APPLY_UPDATES:
DCHECK_EQ(end == APPLY_UPDATES, session->source().updates_source ==
sync_pb::GetUpdatesCallerInfo::RECONFIGURATION);
session->mutable_status_controller()->set_last_get_key_result(SYNCER_OK);
session->mutable_status_controller()->set_last_download_updates_result(
SYNCER_OK);
break;
default:
ADD_FAILURE() << "Not a valid END state.";
}
}
void SimulateThrottledImpl(sessions::SyncSession* session,
const base::TimeDelta& delta) {
session->mutable_status_controller()->set_last_download_updates_result(
SERVER_RETURN_THROTTLED);
session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + delta);
}
void SimulatePollIntervalUpdateImpl(sessions::SyncSession* session,
const base::TimeDelta& new_poll) {
SimulateSuccess(session, SYNCER_BEGIN, SYNCER_END);
session->delegate()->OnReceivedLongPollIntervalUpdate(new_poll);
}
void SimulateSessionsCommitDelayUpdateImpl(sessions::SyncSession* session,
const base::TimeDelta& new_delay) {
SimulateSuccess(session, SYNCER_BEGIN, SYNCER_END);
session->delegate()->OnReceivedSessionsCommitDelay(new_delay);
}
} // namespace test_util
} // namespace sessions
} // namespace syncer
|