Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
|
akalin
2011/01/25 06:09:53
Can you move the bodies of these functions into a
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // Utils to simulate various outcomes of a sync session. | |
| 6 #ifndef CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_ | |
| 7 #define CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_ | |
| 8 #pragma once | |
| 9 | |
| 10 #include "chrome/browser/sync/sessions/sync_session.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 | |
| 14 namespace browser_sync { | |
| 15 namespace sessions { | |
| 16 namespace test_util { | |
| 17 | |
| 18 void SimulateHasMoreToSync(sessions::SyncSession* session) { | |
| 19 session->status_controller()->update_conflicts_resolved(true); | |
| 20 ASSERT_TRUE(session->HasMoreToSync()); | |
| 21 } | |
| 22 | |
| 23 void SimulateDownloadUpdatesFailed(sessions::SyncSession* session) { | |
| 24 // Note that a non-zero value of changes_remaining once a session has | |
| 25 // completed implies that the Syncer was unable to exhaust this count during | |
| 26 // the GetUpdates cycle. This is an indication that an error occurred. | |
| 27 session->status_controller()->set_num_server_changes_remaining(1); | |
| 28 } | |
| 29 | |
| 30 void SimulateCommitFailed(sessions::SyncSession* session) { | |
| 31 // Note that a non-zero number of unsynced handles once a session has | |
| 32 // completed implies that the Syncer was unable to make forward progress | |
| 33 // during a commit, indicating an error occurred. | |
| 34 // See implementation of SyncSession::HasMoreToSync. | |
| 35 std::vector<int64> handles; | |
| 36 handles.push_back(1); | |
| 37 session->status_controller()->set_unsynced_handles(handles); | |
| 38 } | |
| 39 | |
| 40 void SimulateSuccess(sessions::SyncSession* session) { | |
| 41 if (session->HasMoreToSync()) { | |
| 42 ADD_FAILURE() << "Shouldn't have more to sync"; | |
| 43 } | |
| 44 ASSERT_EQ(0, session->status_controller()->num_server_changes_remaining()); | |
| 45 ASSERT_EQ(0, session->status_controller()->unsynced_handles().size()); | |
| 46 } | |
| 47 | |
| 48 void SimulateThrottledImpl(sessions::SyncSession* session, | |
| 49 const base::TimeDelta& delta) { | |
| 50 session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + delta); | |
| 51 } | |
| 52 | |
| 53 ACTION_P(SimulateThrottled, throttle) { | |
| 54 SimulateThrottledImpl(arg0, throttle); | |
| 55 } | |
| 56 | |
| 57 void SimulatePollIntervalUpdateImpl(sessions::SyncSession* session, | |
| 58 const base::TimeDelta& new_poll) { | |
| 59 session->delegate()->OnReceivedLongPollIntervalUpdate(new_poll); | |
| 60 } | |
| 61 | |
| 62 ACTION_P(SimulatePollIntervalUpdate, poll) { | |
| 63 SimulatePollIntervalUpdateImpl(arg0, poll); | |
| 64 } | |
| 65 | |
| 66 } // namespace test_util | |
| 67 } // namespace sessions | |
| 68 } // namespace browser_sync | |
| 69 | |
| 70 #endif // CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_ | |
| OLD | NEW |