1 // Copyright (c) 2011 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 "chrome/browser/sync/sessions/test_util.h"
6
7 namespace browser_sync {
8 namespace sessions {
9 namespace test_util {
10
SimulateHasMoreToSync(sessions::SyncSession * session,SyncerStep begin,SyncerStep end)11 void SimulateHasMoreToSync(sessions::SyncSession* session,
12 SyncerStep begin, SyncerStep end) {
13 session->status_controller()->update_conflicts_resolved(true);
14 ASSERT_TRUE(session->HasMoreToSync());
15 }
16
SimulateDownloadUpdatesFailed(sessions::SyncSession * session,SyncerStep begin,SyncerStep end)17 void SimulateDownloadUpdatesFailed(sessions::SyncSession* session,
18 SyncerStep begin, SyncerStep end) {
19 // Note that a non-zero value of changes_remaining once a session has
20 // completed implies that the Syncer was unable to exhaust this count during
21 // the GetUpdates cycle. This is an indication that an error occurred.
22 session->status_controller()->set_num_server_changes_remaining(1);
23 }
24
SimulateCommitFailed(sessions::SyncSession * session,SyncerStep begin,SyncerStep end)25 void SimulateCommitFailed(sessions::SyncSession* session,
26 SyncerStep begin, SyncerStep end) {
27 // Note that a non-zero number of unsynced handles once a session has
28 // completed implies that the Syncer was unable to make forward progress
29 // during a commit, indicating an error occurred.
30 // See implementation of SyncSession::HasMoreToSync.
31 std::vector<int64> handles;
32 handles.push_back(1);
33 session->status_controller()->set_unsynced_handles(handles);
34 }
35
SimulateSuccess(sessions::SyncSession * session,SyncerStep begin,SyncerStep end)36 void SimulateSuccess(sessions::SyncSession* session,
37 SyncerStep begin, SyncerStep end) {
38 if (session->HasMoreToSync()) {
39 ADD_FAILURE() << "Shouldn't have more to sync";
40 }
41 ASSERT_EQ(0U, session->status_controller()->num_server_changes_remaining());
42 ASSERT_EQ(0U, session->status_controller()->unsynced_handles().size());
43 }
44
SimulateThrottledImpl(sessions::SyncSession * session,const base::TimeDelta & delta)45 void SimulateThrottledImpl(sessions::SyncSession* session,
46 const base::TimeDelta& delta) {
47 session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + delta);
48 }
49
SimulatePollIntervalUpdateImpl(sessions::SyncSession * session,const base::TimeDelta & new_poll)50 void SimulatePollIntervalUpdateImpl(sessions::SyncSession* session,
51 const base::TimeDelta& new_poll) {
52 session->delegate()->OnReceivedLongPollIntervalUpdate(new_poll);
53 }
54
55 } // namespace test_util
56 } // namespace sessions
57 } // namespace browser_sync
58