Chromium Code Reviews| Index: chrome/browser/sync/sessions/test_util.h |
| diff --git a/chrome/browser/sync/sessions/test_util.h b/chrome/browser/sync/sessions/test_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fbda15815d7433e8f8eeadfc9dedc7a89dde3709 |
| --- /dev/null |
| +++ b/chrome/browser/sync/sessions/test_util.h |
| @@ -0,0 +1,70 @@ |
| +// 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
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +// Utils to simulate various outcomes of a sync session. |
| +#ifndef CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_ |
| +#define CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_ |
| +#pragma once |
| + |
| +#include "chrome/browser/sync/sessions/sync_session.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| + |
| +namespace browser_sync { |
| +namespace sessions { |
| +namespace test_util { |
| + |
| +void SimulateHasMoreToSync(sessions::SyncSession* session) { |
| + session->status_controller()->update_conflicts_resolved(true); |
| + ASSERT_TRUE(session->HasMoreToSync()); |
| +} |
| + |
| +void SimulateDownloadUpdatesFailed(sessions::SyncSession* session) { |
| + // Note that a non-zero value of changes_remaining once a session has |
| + // completed implies that the Syncer was unable to exhaust this count during |
| + // the GetUpdates cycle. This is an indication that an error occurred. |
| + session->status_controller()->set_num_server_changes_remaining(1); |
| +} |
| + |
| +void SimulateCommitFailed(sessions::SyncSession* session) { |
| + // Note that a non-zero number of unsynced handles once a session has |
| + // completed implies that the Syncer was unable to make forward progress |
| + // during a commit, indicating an error occurred. |
| + // See implementation of SyncSession::HasMoreToSync. |
| + std::vector<int64> handles; |
| + handles.push_back(1); |
| + session->status_controller()->set_unsynced_handles(handles); |
| +} |
| + |
| +void SimulateSuccess(sessions::SyncSession* session) { |
| + if (session->HasMoreToSync()) { |
| + ADD_FAILURE() << "Shouldn't have more to sync"; |
| + } |
| + ASSERT_EQ(0, session->status_controller()->num_server_changes_remaining()); |
| + ASSERT_EQ(0, session->status_controller()->unsynced_handles().size()); |
| +} |
| + |
| +void SimulateThrottledImpl(sessions::SyncSession* session, |
| + const base::TimeDelta& delta) { |
| + session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + delta); |
| +} |
| + |
| +ACTION_P(SimulateThrottled, throttle) { |
| + SimulateThrottledImpl(arg0, throttle); |
| +} |
| + |
| +void SimulatePollIntervalUpdateImpl(sessions::SyncSession* session, |
| + const base::TimeDelta& new_poll) { |
| + session->delegate()->OnReceivedLongPollIntervalUpdate(new_poll); |
| +} |
| + |
| +ACTION_P(SimulatePollIntervalUpdate, poll) { |
| + SimulatePollIntervalUpdateImpl(arg0, poll); |
| +} |
| + |
| +} // namespace test_util |
| +} // namespace sessions |
| +} // namespace browser_sync |
| + |
| +#endif // CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_ |