Commit ed16c5f9 authored by Rushan Suleymanov's avatar Rushan Suleymanov Committed by Commit Bot

[Sync] Move test_util functions to the appropriate unit test

This file is used by only one unit test for SyncScheduleImpl. All its
functions are moved to the appropriate unit test file. It's not worth
holding the dedicated file for only one test.

Bug: 948661
Change-Id: Ia3975ddfa4ff472bf43b0df4d5ed26a77b50195a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2502475Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Rushan Suleymanov <rushans@google.com>
Cr-Commit-Position: refs/heads/master@{#821294}
parent cd65c12e
...@@ -320,8 +320,6 @@ static_library("test_support_engine") { ...@@ -320,8 +320,6 @@ static_library("test_support_engine") {
"engine/test_engine_components_factory.h", "engine/test_engine_components_factory.h",
"engine_impl/cycle/mock_debug_info_getter.cc", "engine_impl/cycle/mock_debug_info_getter.cc",
"engine_impl/cycle/mock_debug_info_getter.h", "engine_impl/cycle/mock_debug_info_getter.h",
"engine_impl/cycle/test_util.cc",
"engine_impl/cycle/test_util.h",
"test/engine/fake_sync_scheduler.cc", "test/engine/fake_sync_scheduler.cc",
"test/engine/fake_sync_scheduler.h", "test/engine/fake_sync_scheduler.h",
"test/engine/mock_connection_manager.cc", "test/engine/mock_connection_manager.cc",
......
// 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 "components/sync/engine_impl/cycle/test_util.h"
#include "net/base/net_errors.h"
namespace syncer {
namespace test_util {
void SimulateGetEncryptionKeyFailed(ModelTypeSet requsted_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_get_key_result(
SyncerError(SyncerError::SERVER_RESPONSE_VALIDATION_FAILED));
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SYNCER_OK));
}
void SimulateConfigureSuccess(ModelTypeSet requsted_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_get_key_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SYNCER_OK));
}
void SimulateConfigureFailed(ModelTypeSet requsted_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_get_key_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR));
}
void SimulateConfigureConnectionFailure(
ModelTypeSet requsted_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_get_key_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError::NetworkConnectionUnavailable(net::ERR_FAILED));
}
void SimulateNormalSuccess(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_commit_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SYNCER_OK));
}
void SimulateDownloadUpdatesFailed(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR));
}
void SimulateCommitFailed(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_get_key_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->mutable_status_controller()->set_commit_result(
SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR));
}
void SimulateConnectionFailure(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError::NetworkConnectionUnavailable(net::ERR_FAILED));
}
void SimulatePollSuccess(ModelTypeSet requested_types, SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SYNCER_OK));
}
void SimulatePollFailed(ModelTypeSet requested_types, SyncCycle* cycle) {
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR));
}
void SimulateThrottledImpl(SyncCycle* cycle, const base::TimeDelta& delta) {
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SERVER_RETURN_THROTTLED));
cycle->delegate()->OnThrottled(delta);
}
void SimulateTypesThrottledImpl(SyncCycle* cycle,
ModelTypeSet types,
const base::TimeDelta& delta) {
cycle->mutable_status_controller()->set_commit_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->delegate()->OnTypesThrottled(types, delta);
}
void SimulatePartialFailureImpl(SyncCycle* cycle, ModelTypeSet types) {
cycle->mutable_status_controller()->set_commit_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->delegate()->OnTypesBackedOff(types);
}
void SimulatePollIntervalUpdateImpl(ModelTypeSet requested_types,
SyncCycle* cycle,
const base::TimeDelta& new_poll) {
SimulatePollSuccess(requested_types, cycle);
cycle->delegate()->OnReceivedPollIntervalUpdate(new_poll);
}
void SimulateGuRetryDelayCommandImpl(SyncCycle* cycle, base::TimeDelta delay) {
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->delegate()->OnReceivedGuRetryDelay(delay);
}
} // namespace test_util
} // namespace syncer
// 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.
#ifndef COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_TEST_UTIL_H_
#define COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_TEST_UTIL_H_
#include "components/sync/engine_impl/cycle/sync_cycle.h"
#include "components/sync/engine_impl/syncer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace test_util {
// Utils to simulate various outcomes of a sync cycle.
// Configure sync cycle successes and failures.
void SimulateGetEncryptionKeyFailed(ModelTypeSet requested_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle);
void SimulateConfigureSuccess(ModelTypeSet requested_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle);
void SimulateConfigureFailed(ModelTypeSet requested_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle);
void SimulateConfigureConnectionFailure(
ModelTypeSet requested_types,
sync_pb::SyncEnums::GetUpdatesOrigin origin,
SyncCycle* cycle);
// Normal mode sync cycle successes and failures.
void SimulateNormalSuccess(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle);
void SimulateDownloadUpdatesFailed(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle);
void SimulateCommitFailed(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle);
void SimulateConnectionFailure(ModelTypeSet requested_types,
NudgeTracker* nudge_tracker,
SyncCycle* cycle);
// Poll successes and failures.
// TODO(tschumann): Move poll simulations into the only call site,
// sync_scheduler_impl_unittest.cc.
void SimulatePollSuccess(ModelTypeSet requested_types, SyncCycle* cycle);
void SimulatePollFailed(ModelTypeSet requested_types, SyncCycle* cycle);
void SimulateGuRetryDelayCommandImpl(SyncCycle* cycle, base::TimeDelta delay);
void SimulateThrottledImpl(SyncCycle* cycle, const base::TimeDelta& delta);
void SimulateTypesThrottledImpl(SyncCycle* cycle,
ModelTypeSet types,
const base::TimeDelta& delta);
void SimulatePartialFailureImpl(SyncCycle* cycle, ModelTypeSet types);
// Works with poll cycles.
void SimulatePollIntervalUpdateImpl(ModelTypeSet requested_types,
SyncCycle* cycle,
const base::TimeDelta& new_poll);
// TODO(tschumann): Most of these actions are only used by
// sync_scheduler_impl_unittest.cc. Move them there to avoid unneccesary
// redirection and keep the context in one place.
ACTION_P(SimulateThrottled, throttle) {
SimulateThrottledImpl(arg0, throttle);
}
ACTION_P2(SimulateTypesThrottled, types, throttle) {
SimulateTypesThrottledImpl(arg0, types, throttle);
}
ACTION_P(SimulatePartialFailure, types) {
SimulatePartialFailureImpl(arg0, types);
}
ACTION_P(SimulatePollIntervalUpdate, poll) {
SimulatePollIntervalUpdateImpl(arg0, arg1, poll);
}
ACTION_P(SimulateGuRetryDelayCommand, delay) {
SimulateGuRetryDelayCommandImpl(arg0, delay);
}
} // namespace test_util
} // namespace syncer
#endif // COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_TEST_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment