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_
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
#include "components/sync/engine/sync_engine_switches.h" #include "components/sync/engine/sync_engine_switches.h"
#include "components/sync/engine_impl/backoff_delay_provider.h" #include "components/sync/engine_impl/backoff_delay_provider.h"
#include "components/sync/engine_impl/cancelation_signal.h" #include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/cycle/test_util.h"
#include "components/sync/test/callback_counter.h" #include "components/sync/test/callback_counter.h"
#include "components/sync/test/engine/mock_connection_manager.h" #include "components/sync/test/engine/mock_connection_manager.h"
#include "components/sync/test/engine/mock_nudge_handler.h" #include "components/sync/test/engine/mock_nudge_handler.h"
#include "components/sync/test/fake_sync_encryption_handler.h" #include "components/sync/test/fake_sync_encryption_handler.h"
#include "components/sync/test/mock_invalidation.h" #include "components/sync/test/mock_invalidation.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -54,6 +54,124 @@ using testing::WithoutArgs; ...@@ -54,6 +54,124 @@ using testing::WithoutArgs;
namespace syncer { namespace syncer {
namespace {
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));
}
ACTION_P(SimulateThrottled, throttle) {
SyncCycle* cycle = arg0;
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SERVER_RETURN_THROTTLED));
cycle->delegate()->OnThrottled(throttle);
}
ACTION_P2(SimulateTypesThrottled, types, throttle) {
SyncCycle* cycle = arg0;
cycle->mutable_status_controller()->set_commit_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->delegate()->OnTypesThrottled(types, throttle);
}
ACTION_P(SimulatePartialFailure, types) {
SyncCycle* cycle = arg0;
cycle->mutable_status_controller()->set_commit_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->delegate()->OnTypesBackedOff(types);
}
ACTION_P(SimulatePollIntervalUpdate, new_poll) {
const ModelTypeSet requested_types = arg0;
SyncCycle* cycle = arg1;
SimulatePollSuccess(requested_types, cycle);
cycle->delegate()->OnReceivedPollIntervalUpdate(new_poll);
}
ACTION_P(SimulateGuRetryDelayCommand, delay) {
SyncCycle* cycle = arg0;
cycle->mutable_status_controller()->set_last_download_updates_result(
SyncerError(SyncerError::SYNCER_OK));
cycle->delegate()->OnReceivedGuRetryDelay(delay);
}
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));
}
class MockSyncer : public Syncer { class MockSyncer : public Syncer {
public: public:
MockSyncer(); MockSyncer();
...@@ -106,6 +224,8 @@ void PumpLoop() { ...@@ -106,6 +224,8 @@ void PumpLoop() {
static const size_t kMinNumSamples = 5; static const size_t kMinNumSamples = 5;
} // namespace
// Test harness for the SyncScheduler. Test the delays and backoff timers used // Test harness for the SyncScheduler. Test the delays and backoff timers used
// in response to various events. Mock time is used to avoid flakes. // in response to various events. Mock time is used to avoid flakes.
class SyncSchedulerImplTest : public testing::Test { class SyncSchedulerImplTest : public testing::Test {
...@@ -380,8 +500,8 @@ TEST_F(SyncSchedulerImplTest, Nudge) { ...@@ -380,8 +500,8 @@ TEST_F(SyncSchedulerImplTest, Nudge) {
ModelTypeSet model_types(THEMES); ModelTypeSet model_types(THEMES);
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))) DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -396,8 +516,8 @@ TEST_F(SyncSchedulerImplTest, Nudge) { ...@@ -396,8 +516,8 @@ TEST_F(SyncSchedulerImplTest, Nudge) {
model_types.Remove(THEMES); model_types.Remove(THEMES);
model_types.Put(TYPED_URLS); model_types.Put(TYPED_URLS);
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times2, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times2, true)));
scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); scheduler()->ScheduleLocalNudge(model_types, FROM_HERE);
RunLoop(); RunLoop();
} }
...@@ -417,8 +537,7 @@ TEST_F(SyncSchedulerImplTest, NudgeForDisabledType) { ...@@ -417,8 +537,7 @@ TEST_F(SyncSchedulerImplTest, NudgeForDisabledType) {
SyncShareTimes times; SyncShareTimes times;
NudgeTracker* nudge_tracker = nullptr; NudgeTracker* nudge_tracker = nullptr;
EXPECT_CALL(*syncer(), NormalSyncShare(context()->GetEnabledTypes(), _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(context()->GetEnabledTypes(), _, _))
.WillOnce(DoAll(SaveArg<1>(&nudge_tracker), .WillOnce(DoAll(SaveArg<1>(&nudge_tracker), Invoke(SimulateNormalSuccess),
Invoke(test_util::SimulateNormalSuccess),
RecordSyncShare(&times, true))); RecordSyncShare(&times, true)));
RunLoop(); RunLoop();
...@@ -436,7 +555,7 @@ TEST_F(SyncSchedulerImplTest, Config) { ...@@ -436,7 +555,7 @@ TEST_F(SyncSchedulerImplTest, Config) {
const ModelTypeSet model_types(THEMES); const ModelTypeSet model_types(THEMES);
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), .WillOnce(DoAll(Invoke(SimulateConfigureSuccess),
RecordSyncShare(&times, true))); RecordSyncShare(&times, true)));
StartSyncConfiguration(); StartSyncConfiguration();
...@@ -461,9 +580,9 @@ TEST_F(SyncSchedulerImplTest, ConfigWithBackingOff) { ...@@ -461,9 +580,9 @@ TEST_F(SyncSchedulerImplTest, ConfigWithBackingOff) {
StartSyncConfiguration(); StartSyncConfiguration();
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), .WillOnce(DoAll(Invoke(SimulateConfigureFailed),
RecordSyncShare(&times, false))) RecordSyncShare(&times, false)))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), .WillOnce(DoAll(Invoke(SimulateConfigureFailed),
RecordSyncShare(&times, false))); RecordSyncShare(&times, false)));
CallbackCounter ready_counter; CallbackCounter ready_counter;
...@@ -482,7 +601,7 @@ TEST_F(SyncSchedulerImplTest, ConfigWithBackingOff) { ...@@ -482,7 +601,7 @@ TEST_F(SyncSchedulerImplTest, ConfigWithBackingOff) {
Mock::VerifyAndClearExpectations(syncer()); Mock::VerifyAndClearExpectations(syncer());
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), .WillOnce(DoAll(Invoke(SimulateConfigureSuccess),
RecordSyncShare(&times, true))); RecordSyncShare(&times, true)));
RunLoop(); RunLoop();
...@@ -503,7 +622,7 @@ TEST_F(SyncSchedulerImplTest, ConfigWithStop) { ...@@ -503,7 +622,7 @@ TEST_F(SyncSchedulerImplTest, ConfigWithStop) {
// Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call
// retry_task or dereference configuration params. // retry_task or dereference configuration params.
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), .WillOnce(DoAll(Invoke(SimulateConfigureFailed),
StopScheduler(scheduler()), StopScheduler(scheduler()),
RecordSyncShare(&times, false))); RecordSyncShare(&times, false)));
...@@ -544,7 +663,7 @@ TEST_F(SyncSchedulerImplTest, ConfigNoAccessTokenLocalSync) { ...@@ -544,7 +663,7 @@ TEST_F(SyncSchedulerImplTest, ConfigNoAccessTokenLocalSync) {
connection()->ResetAccessToken(); connection()->ResetAccessToken();
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), .WillOnce(DoAll(Invoke(SimulateConfigureSuccess),
RecordSyncShare(&times, true))); RecordSyncShare(&times, true)));
StartSyncConfiguration(); StartSyncConfiguration();
...@@ -571,7 +690,7 @@ TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { ...@@ -571,7 +690,7 @@ TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) {
// Request a configure and make sure it fails. // Request a configure and make sure it fails.
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), .WillOnce(DoAll(Invoke(SimulateConfigureFailed),
RecordSyncShare(&times, false))); RecordSyncShare(&times, false)));
CallbackCounter ready_counter; CallbackCounter ready_counter;
ConfigurationParams params(sync_pb::SyncEnums::RECONFIGURATION, model_types, ConfigurationParams params(sync_pb::SyncEnums::RECONFIGURATION, model_types,
...@@ -584,7 +703,7 @@ TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { ...@@ -584,7 +703,7 @@ TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) {
// Ask for a nudge while dealing with repeated configure failure. // Ask for a nudge while dealing with repeated configure failure.
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), .WillOnce(DoAll(Invoke(SimulateConfigureFailed),
RecordSyncShare(&times, false))); RecordSyncShare(&times, false)));
scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); scheduler()->ScheduleLocalNudge(model_types, FROM_HERE);
RunLoop(); RunLoop();
...@@ -596,14 +715,14 @@ TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { ...@@ -596,14 +715,14 @@ TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) {
// Let the next configure retry succeed. // Let the next configure retry succeed.
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), .WillOnce(DoAll(Invoke(SimulateConfigureSuccess),
RecordSyncShare(&times, true))); RecordSyncShare(&times, true)));
RunLoop(); RunLoop();
// Now change the mode so nudge can execute. // Now change the mode so nudge can execute.
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
PumpLoop(); PumpLoop();
} }
...@@ -614,8 +733,8 @@ TEST_F(SyncSchedulerImplTest, NudgeCoalescing) { ...@@ -614,8 +733,8 @@ TEST_F(SyncSchedulerImplTest, NudgeCoalescing) {
SyncShareTimes times; SyncShareTimes times;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
const ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3(THEMES); const ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3(THEMES);
TimeTicks optimal_time = TimeTicks::Now() + default_delay(); TimeTicks optimal_time = TimeTicks::Now() + default_delay();
scheduler()->ScheduleLocalNudge(types1, FROM_HERE); scheduler()->ScheduleLocalNudge(types1, FROM_HERE);
...@@ -629,8 +748,8 @@ TEST_F(SyncSchedulerImplTest, NudgeCoalescing) { ...@@ -629,8 +748,8 @@ TEST_F(SyncSchedulerImplTest, NudgeCoalescing) {
SyncShareTimes times2; SyncShareTimes times2;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times2, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times2, true)));
scheduler()->ScheduleLocalNudge(types3, FROM_HERE); scheduler()->ScheduleLocalNudge(types3, FROM_HERE);
RunLoop(); RunLoop();
} }
...@@ -641,8 +760,8 @@ TEST_F(SyncSchedulerImplTest, NudgeCoalescingWithDifferentTimings) { ...@@ -641,8 +760,8 @@ TEST_F(SyncSchedulerImplTest, NudgeCoalescingWithDifferentTimings) {
SyncShareTimes times; SyncShareTimes times;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3; ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3;
// Create a huge time delay. // Create a huge time delay.
...@@ -672,8 +791,8 @@ TEST_F(SyncSchedulerImplTest, NudgeWithStates) { ...@@ -672,8 +791,8 @@ TEST_F(SyncSchedulerImplTest, NudgeWithStates) {
SyncShareTimes times1; SyncShareTimes times1;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times1, true))) DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times1, true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"),
FROM_HERE); FROM_HERE);
...@@ -684,8 +803,8 @@ TEST_F(SyncSchedulerImplTest, NudgeWithStates) { ...@@ -684,8 +803,8 @@ TEST_F(SyncSchedulerImplTest, NudgeWithStates) {
// Make sure a second, later, nudge is unaffected by first (no coalescing). // Make sure a second, later, nudge is unaffected by first (no coalescing).
SyncShareTimes times2; SyncShareTimes times2;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times2, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times2, true)));
scheduler()->ScheduleInvalidationNudge( scheduler()->ScheduleInvalidationNudge(
TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE); TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE);
RunLoop(); RunLoop();
...@@ -698,7 +817,7 @@ TEST_F(SyncSchedulerImplTest, Polling) { ...@@ -698,7 +817,7 @@ TEST_F(SyncSchedulerImplTest, Polling) {
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.Times(AtLeast(kMinNumSamples)) .Times(AtLeast(kMinNumSamples))
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulatePollSuccess), DoAll(Invoke(SimulatePollSuccess),
RecordSyncShareMultiple(&times, kMinNumSamples, true))); RecordSyncShareMultiple(&times, kMinNumSamples, true)));
scheduler()->OnReceivedPollIntervalUpdate(poll_interval); scheduler()->OnReceivedPollIntervalUpdate(poll_interval);
...@@ -723,7 +842,7 @@ TEST_F(SyncSchedulerImplTest, ShouldUseInitialPollIntervalFromContext) { ...@@ -723,7 +842,7 @@ TEST_F(SyncSchedulerImplTest, ShouldUseInitialPollIntervalFromContext) {
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.Times(AtLeast(kMinNumSamples)) .Times(AtLeast(kMinNumSamples))
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulatePollSuccess), DoAll(Invoke(SimulatePollSuccess),
RecordSyncShareMultiple(&times, kMinNumSamples, true))); RecordSyncShareMultiple(&times, kMinNumSamples, true)));
TimeTicks optimal_start = TimeTicks::Now() + poll_interval; TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
...@@ -747,7 +866,7 @@ TEST_F(SyncSchedulerImplTest, PollingPersistence) { ...@@ -747,7 +866,7 @@ TEST_F(SyncSchedulerImplTest, PollingPersistence) {
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.Times(AtLeast(kMinNumSamples)) .Times(AtLeast(kMinNumSamples))
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulatePollSuccess), DoAll(Invoke(SimulatePollSuccess),
RecordSyncShareMultiple(&times, kMinNumSamples, true))); RecordSyncShareMultiple(&times, kMinNumSamples, true)));
scheduler()->OnReceivedPollIntervalUpdate(poll_interval); scheduler()->OnReceivedPollIntervalUpdate(poll_interval);
...@@ -771,7 +890,7 @@ TEST_F(SyncSchedulerImplTest, PollingPersistenceBadClock) { ...@@ -771,7 +890,7 @@ TEST_F(SyncSchedulerImplTest, PollingPersistenceBadClock) {
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.Times(AtLeast(kMinNumSamples)) .Times(AtLeast(kMinNumSamples))
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulatePollSuccess), DoAll(Invoke(SimulatePollSuccess),
RecordSyncShareMultiple(&times, kMinNumSamples, true))); RecordSyncShareMultiple(&times, kMinNumSamples, true)));
scheduler()->OnReceivedPollIntervalUpdate(poll_interval); scheduler()->OnReceivedPollIntervalUpdate(poll_interval);
...@@ -795,11 +914,10 @@ TEST_F(SyncSchedulerImplTest, PollIntervalUpdate) { ...@@ -795,11 +914,10 @@ TEST_F(SyncSchedulerImplTest, PollIntervalUpdate) {
scheduler()->OnReceivedPollIntervalUpdate(poll1); scheduler()->OnReceivedPollIntervalUpdate(poll1);
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.Times(AtLeast(kMinNumSamples)) .Times(AtLeast(kMinNumSamples))
.WillOnce( .WillOnce(DoAll(WithArgs<0, 1>(SimulatePollIntervalUpdate(poll2)),
DoAll(WithArgs<0, 1>(test_util::SimulatePollIntervalUpdate(poll2)),
Return(true))) Return(true)))
.WillRepeatedly(DoAll( .WillRepeatedly(DoAll(
Invoke(test_util::SimulatePollSuccess), Invoke(SimulatePollSuccess),
WithArg<1>(RecordSyncShareMultiple(&times, kMinNumSamples, true)))); WithArg<1>(RecordSyncShareMultiple(&times, kMinNumSamples, true))));
TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2;
...@@ -820,8 +938,7 @@ TEST_F(SyncSchedulerImplTest, ThrottlingDoesThrottle) { ...@@ -820,8 +938,7 @@ TEST_F(SyncSchedulerImplTest, ThrottlingDoesThrottle) {
scheduler()->OnReceivedPollIntervalUpdate(poll); scheduler()->OnReceivedPollIntervalUpdate(poll);
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle)), .WillOnce(DoAll(WithArg<2>(SimulateThrottled(throttle)), Return(false)))
Return(false)))
.WillRepeatedly(AddFailureAndQuitLoopNow()); .WillRepeatedly(AddFailureAndQuitLoopNow());
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -848,12 +965,11 @@ TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromPoll) { ...@@ -848,12 +965,11 @@ TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromPoll) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.WillOnce(DoAll(WithArg<1>(test_util::SimulateThrottled(throttle1)), .WillOnce(DoAll(WithArg<1>(SimulateThrottled(throttle1)), Return(false)))
Return(false)))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulatePollSuccess), DoAll(Invoke(SimulatePollSuccess),
RecordSyncShareMultiple(&times, kMinNumSamples, true))); RecordSyncShareMultiple(&times, kMinNumSamples, true)));
TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1;
...@@ -874,12 +990,10 @@ TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromNudge) { ...@@ -874,12 +990,10 @@ TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromNudge) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), .WillOnce(DoAll(WithArg<2>(SimulateThrottled(throttle1)), Return(false)))
Return(false)))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(DoAll(Invoke(SimulateNormalSuccess), QuitLoopNowAction(true)));
QuitLoopNowAction(true)));
const ModelTypeSet types(THEMES); const ModelTypeSet types(THEMES);
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -902,12 +1016,11 @@ TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromConfigure) { ...@@ -902,12 +1016,11 @@ TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromConfigure) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), .WillOnce(DoAll(WithArg<2>(SimulateThrottled(throttle1)), Return(false)))
Return(false)))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), .WillOnce(
QuitLoopNowAction(true))); DoAll(Invoke(SimulateConfigureSuccess), QuitLoopNowAction(true)));
const ModelTypeSet types(THEMES); const ModelTypeSet types(THEMES);
StartSyncConfiguration(); StartSyncConfiguration();
...@@ -936,8 +1049,7 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingBlocksNudge) { ...@@ -936,8 +1049,7 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingBlocksNudge) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(WithArg<2>(SimulateTypesThrottled(types, throttle1)),
DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)),
Return(true))) Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -967,8 +1079,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffBlocksNudge) { ...@@ -967,8 +1079,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffBlocksNudge) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), .WillOnce(DoAll(WithArg<2>(SimulatePartialFailure(types)), Return(true)))
Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -997,8 +1108,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffWillExpire) { ...@@ -997,8 +1108,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffWillExpire) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), .WillOnce(DoAll(WithArg<2>(SimulatePartialFailure(types)), Return(true)))
Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -1011,8 +1121,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffWillExpire) { ...@@ -1011,8 +1121,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffWillExpire) {
SyncShareTimes times; SyncShareTimes times;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillRepeatedly(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
PumpLoop(); // To get PerformDelayedNudge called. PumpLoop(); // To get PerformDelayedNudge called.
PumpLoop(); // To get TrySyncCycleJob called PumpLoop(); // To get TrySyncCycleJob called
EXPECT_FALSE(IsAnyTypeBlocked()); EXPECT_FALSE(IsAnyTypeBlocked());
...@@ -1033,8 +1143,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) { ...@@ -1033,8 +1143,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), .WillOnce(DoAll(WithArg<2>(SimulatePartialFailure(types)), Return(true)))
Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -1049,8 +1158,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) { ...@@ -1049,8 +1158,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) {
TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), .WillOnce(DoAll(WithArg<2>(SimulateThrottled(throttle1)), Return(false)))
Return(false)))
.RetiresOnSaturation(); .RetiresOnSaturation();
// Sync still can throttle. // Sync still can throttle.
...@@ -1067,8 +1175,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) { ...@@ -1067,8 +1175,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) {
// Unthrottled client, but the backingoff datatype is still in backoff and // Unthrottled client, but the backingoff datatype is still in backoff and
// scheduled. // scheduled.
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(DoAll(Invoke(SimulateNormalSuccess), QuitLoopNowAction(true)));
QuitLoopNowAction(true)));
RunLoop(); RunLoop();
EXPECT_FALSE(scheduler()->IsGlobalThrottle()); EXPECT_FALSE(scheduler()->IsGlobalThrottle());
EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); EXPECT_TRUE(GetBackedOffTypes().HasAll(types));
...@@ -1089,8 +1196,8 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingBackingOffBlocksNudge) { ...@@ -1089,8 +1196,8 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingBackingOffBlocksNudge) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( .WillOnce(
throttled_types, throttle)), DoAll(WithArg<2>(SimulateTypesThrottled(throttled_types, throttle)),
Return(true))) Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -1102,8 +1209,7 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingBackingOffBlocksNudge) { ...@@ -1102,8 +1209,7 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingBackingOffBlocksNudge) {
const ModelTypeSet backed_off_types(TYPED_URLS); const ModelTypeSet backed_off_types(TYPED_URLS);
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(WithArg<2>(SimulatePartialFailure(backed_off_types)),
DoAll(WithArg<2>(test_util::SimulatePartialFailure(backed_off_types)),
Return(true))) Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -1141,8 +1247,8 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) { ...@@ -1141,8 +1247,8 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( .WillOnce(
throttled_types, throttle1)), DoAll(WithArg<2>(SimulateTypesThrottled(throttled_types, throttle1)),
Return(true))) Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -1167,8 +1273,8 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) { ...@@ -1167,8 +1273,8 @@ TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) {
// Local nudges for non-throttled types will trigger a sync. // Local nudges for non-throttled types will trigger a sync.
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillRepeatedly(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE);
RunLoop(); RunLoop();
Mock::VerifyAndClearExpectations(syncer()); Mock::VerifyAndClearExpectations(syncer());
...@@ -1189,8 +1295,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffDoesBlockOtherSources) { ...@@ -1189,8 +1295,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffDoesBlockOtherSources) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(WithArg<2>(SimulatePartialFailure(backed_off_types)),
DoAll(WithArg<2>(test_util::SimulatePartialFailure(backed_off_types)),
Return(true))) Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -1215,8 +1320,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffDoesBlockOtherSources) { ...@@ -1215,8 +1320,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffDoesBlockOtherSources) {
// Local nudges for non-backed off types will trigger a sync. // Local nudges for non-backed off types will trigger a sync.
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillRepeatedly(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
scheduler()->ScheduleLocalNudge(unbacked_off_types, FROM_HERE); scheduler()->ScheduleLocalNudge(unbacked_off_types, FROM_HERE);
RunLoop(); RunLoop();
Mock::VerifyAndClearExpectations(syncer()); Mock::VerifyAndClearExpectations(syncer());
...@@ -1239,7 +1344,7 @@ TEST_F(SyncSchedulerImplTest, ConfigurationMode) { ...@@ -1239,7 +1344,7 @@ TEST_F(SyncSchedulerImplTest, ConfigurationMode) {
const ModelTypeSet config_types(THEMES); const ModelTypeSet config_types(THEMES);
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), .WillOnce(DoAll(Invoke(SimulateConfigureSuccess),
RecordSyncShare(&times, true))) RecordSyncShare(&times, true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
CallbackCounter ready_counter; CallbackCounter ready_counter;
...@@ -1256,8 +1361,8 @@ TEST_F(SyncSchedulerImplTest, ConfigurationMode) { ...@@ -1256,8 +1361,8 @@ TEST_F(SyncSchedulerImplTest, ConfigurationMode) {
scheduler()->OnReceivedPollIntervalUpdate(TimeDelta::FromDays(1)); scheduler()->OnReceivedPollIntervalUpdate(TimeDelta::FromDays(1));
SyncShareTimes times2; SyncShareTimes times2;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times2, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times2, true)));
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -1283,8 +1388,7 @@ class BackoffTriggersSyncSchedulerImplTest : public SyncSchedulerImplTest { ...@@ -1283,8 +1388,7 @@ class BackoffTriggersSyncSchedulerImplTest : public SyncSchedulerImplTest {
// backoff. // backoff.
TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnce) { TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnce) {
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), .WillOnce(DoAll(Invoke(SimulateCommitFailed), QuitLoopNowAction(false)));
QuitLoopNowAction(false)));
EXPECT_TRUE(RunAndGetBackoff()); EXPECT_TRUE(RunAndGetBackoff());
} }
...@@ -1292,10 +1396,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnce) { ...@@ -1292,10 +1396,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnce) {
// retry. Expect that this clears the backoff state. // retry. Expect that this clears the backoff state.
TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadOnceThenSucceed) { TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadOnceThenSucceed) {
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), .WillOnce(DoAll(Invoke(SimulateDownloadUpdatesFailed), Return(false)))
Return(false))) .WillOnce(DoAll(Invoke(SimulateNormalSuccess), QuitLoopNowAction(true)));
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess),
QuitLoopNowAction(true)));
EXPECT_FALSE(RunAndGetBackoff()); EXPECT_FALSE(RunAndGetBackoff());
} }
...@@ -1303,9 +1405,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadOnceThenSucceed) { ...@@ -1303,9 +1405,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadOnceThenSucceed) {
// that this clears the backoff state. // that this clears the backoff state.
TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnceThenSucceed) { TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnceThenSucceed) {
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), Return(false))) .WillOnce(DoAll(Invoke(SimulateCommitFailed), Return(false)))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(DoAll(Invoke(SimulateNormalSuccess), QuitLoopNowAction(true)));
QuitLoopNowAction(true)));
EXPECT_FALSE(RunAndGetBackoff()); EXPECT_FALSE(RunAndGetBackoff());
} }
...@@ -1313,9 +1414,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnceThenSucceed) { ...@@ -1313,9 +1414,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnceThenSucceed) {
// Expect this will leave the scheduler in backoff. // Expect this will leave the scheduler in backoff.
TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadTwice) { TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadTwice) {
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), .WillOnce(DoAll(Invoke(SimulateDownloadUpdatesFailed), Return(false)))
Return(false))) .WillRepeatedly(DoAll(Invoke(SimulateDownloadUpdatesFailed),
.WillRepeatedly(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed),
QuitLoopNowAction(false))); QuitLoopNowAction(false)));
EXPECT_TRUE(RunAndGetBackoff()); EXPECT_TRUE(RunAndGetBackoff());
} }
...@@ -1324,9 +1424,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadTwice) { ...@@ -1324,9 +1424,8 @@ TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadTwice) {
// updates. Expect this will leave the scheduler in backoff. // updates. Expect this will leave the scheduler in backoff.
TEST_F(BackoffTriggersSyncSchedulerImplTest, FailGetEncryptionKey) { TEST_F(BackoffTriggersSyncSchedulerImplTest, FailGetEncryptionKey) {
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), .WillOnce(DoAll(Invoke(SimulateGetEncryptionKeyFailed), Return(false)))
Return(false))) .WillRepeatedly(DoAll(Invoke(SimulateGetEncryptionKeyFailed),
.WillRepeatedly(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed),
QuitLoopNowAction(false))); QuitLoopNowAction(false)));
StartSyncConfiguration(); StartSyncConfiguration();
...@@ -1350,7 +1449,7 @@ TEST_F(SyncSchedulerImplTest, BackoffDropsJobs) { ...@@ -1350,7 +1449,7 @@ TEST_F(SyncSchedulerImplTest, BackoffDropsJobs) {
UseMockDelayProvider(); UseMockDelayProvider();
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), .WillOnce(DoAll(Invoke(SimulateCommitFailed),
RecordSyncShareMultiple(&times, 1U, false))); RecordSyncShareMultiple(&times, 1U, false)));
EXPECT_CALL(*delay(), GetDelay(_)) EXPECT_CALL(*delay(), GetDelay(_))
.WillRepeatedly(Return(TimeDelta::FromDays(1))); .WillRepeatedly(Return(TimeDelta::FromDays(1)));
...@@ -1395,7 +1494,7 @@ TEST_F(SyncSchedulerImplTest, BackoffElevation) { ...@@ -1395,7 +1494,7 @@ TEST_F(SyncSchedulerImplTest, BackoffElevation) {
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.Times(kMinNumSamples) .Times(kMinNumSamples)
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulateCommitFailed), DoAll(Invoke(SimulateCommitFailed),
RecordSyncShareMultiple(&times, kMinNumSamples, false))); RecordSyncShareMultiple(&times, kMinNumSamples, false)));
const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds);
...@@ -1446,8 +1545,8 @@ TEST_F(SyncSchedulerImplTest, BackoffRelief) { ...@@ -1446,8 +1545,8 @@ TEST_F(SyncSchedulerImplTest, BackoffRelief) {
// Kick off the test with a failed nudge. // Kick off the test with a failed nudge.
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), .WillOnce(
RecordSyncShare(&times, false))); DoAll(Invoke(SimulateCommitFailed), RecordSyncShare(&times, false)));
scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE);
RunLoop(); RunLoop();
Mock::VerifyAndClearExpectations(syncer()); Mock::VerifyAndClearExpectations(syncer());
...@@ -1457,8 +1556,8 @@ TEST_F(SyncSchedulerImplTest, BackoffRelief) { ...@@ -1457,8 +1556,8 @@ TEST_F(SyncSchedulerImplTest, BackoffRelief) {
// The retry succeeds. // The retry succeeds.
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
RunLoop(); RunLoop();
Mock::VerifyAndClearExpectations(syncer()); Mock::VerifyAndClearExpectations(syncer());
optimal_job_time = optimal_job_time + backoff; optimal_job_time = optimal_job_time + backoff;
...@@ -1468,7 +1567,7 @@ TEST_F(SyncSchedulerImplTest, BackoffRelief) { ...@@ -1468,7 +1567,7 @@ TEST_F(SyncSchedulerImplTest, BackoffRelief) {
// Now let the Poll timer do its thing. // Now let the Poll timer do its thing.
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulatePollSuccess), DoAll(Invoke(SimulatePollSuccess),
RecordSyncShareMultiple(&times, kMinNumSamples, true))); RecordSyncShareMultiple(&times, kMinNumSamples, true)));
const TimeDelta poll(TimeDelta::FromMilliseconds(10)); const TimeDelta poll(TimeDelta::FromMilliseconds(10));
scheduler()->OnReceivedPollIntervalUpdate(poll); scheduler()->OnReceivedPollIntervalUpdate(poll);
...@@ -1499,10 +1598,10 @@ TEST_F(SyncSchedulerImplTest, TransientPollFailure) { ...@@ -1499,10 +1598,10 @@ TEST_F(SyncSchedulerImplTest, TransientPollFailure) {
.WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0)));
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.WillOnce(DoAll(Invoke(test_util::SimulatePollFailed), .WillOnce(
RecordSyncShare(&times, false))) DoAll(Invoke(SimulatePollFailed), RecordSyncShare(&times, false)))
.WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulatePollSuccess), RecordSyncShare(&times, true)));
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -1521,9 +1620,8 @@ TEST_F(SyncSchedulerImplTest, StartWhenNotConnected) { ...@@ -1521,9 +1620,8 @@ TEST_F(SyncSchedulerImplTest, StartWhenNotConnected) {
connection()->SetServerNotReachable(); connection()->SetServerNotReachable();
connection()->UpdateConnectionStatus(); connection()->UpdateConnectionStatus();
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(Invoke(SimulateConnectionFailure), Return(false)))
DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) .WillOnce(DoAll(Invoke(SimulateNormalSuccess), Return(true)));
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true)));
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE);
...@@ -1546,8 +1644,7 @@ TEST_F(SyncSchedulerImplTest, SyncShareNotCalledWhenDisconnected) { ...@@ -1546,8 +1644,7 @@ TEST_F(SyncSchedulerImplTest, SyncShareNotCalledWhenDisconnected) {
connection()->UpdateConnectionStatus(); connection()->UpdateConnectionStatus();
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.Times(1) .Times(1)
.WillOnce( .WillOnce(DoAll(Invoke(SimulateConnectionFailure), Return(false)));
DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false)));
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE);
...@@ -1571,9 +1668,8 @@ TEST_F(SyncSchedulerImplTest, ServerConnectionChangeDuringBackoff) { ...@@ -1571,9 +1668,8 @@ TEST_F(SyncSchedulerImplTest, ServerConnectionChangeDuringBackoff) {
connection()->UpdateConnectionStatus(); connection()->UpdateConnectionStatus();
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(Invoke(SimulateConnectionFailure), Return(false)))
DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) .WillOnce(DoAll(Invoke(SimulateNormalSuccess), Return(true)));
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true)));
scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE);
PumpLoop(); // To get PerformDelayedNudge called. PumpLoop(); // To get PerformDelayedNudge called.
...@@ -1601,11 +1697,9 @@ TEST_F(SyncSchedulerImplTest, ConnectionChangeCanaryPreemptedByNudge) { ...@@ -1601,11 +1697,9 @@ TEST_F(SyncSchedulerImplTest, ConnectionChangeCanaryPreemptedByNudge) {
connection()->UpdateConnectionStatus(); connection()->UpdateConnectionStatus();
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(Invoke(SimulateConnectionFailure), Return(false)))
DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) .WillOnce(DoAll(Invoke(SimulateNormalSuccess), Return(true)))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))) .WillOnce(DoAll(Invoke(SimulateNormalSuccess), QuitLoopNowAction(true)));
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess),
QuitLoopNowAction(true)));
scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE);
...@@ -1627,8 +1721,8 @@ TEST_F(SyncSchedulerImplTest, ConnectionChangeCanaryPreemptedByNudge) { ...@@ -1627,8 +1721,8 @@ TEST_F(SyncSchedulerImplTest, ConnectionChangeCanaryPreemptedByNudge) {
// extra connection status change notifications. See crbug.com/190085. // extra connection status change notifications. See crbug.com/190085.
TEST_F(SyncSchedulerImplTest, DoubleCanaryInConfigure) { TEST_F(SyncSchedulerImplTest, DoubleCanaryInConfigure) {
EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _))
.WillRepeatedly(DoAll( .WillRepeatedly(
Invoke(test_util::SimulateConfigureConnectionFailure), Return(true))); DoAll(Invoke(SimulateConfigureConnectionFailure), Return(true)));
StartSyncConfiguration(); StartSyncConfiguration();
connection()->SetServerNotReachable(); connection()->SetServerNotReachable();
connection()->UpdateConnectionStatus(); connection()->UpdateConnectionStatus();
...@@ -1656,7 +1750,7 @@ TEST_F(SyncSchedulerImplTest, PollFromCanaryAfterAuthError) { ...@@ -1656,7 +1750,7 @@ TEST_F(SyncSchedulerImplTest, PollFromCanaryAfterAuthError) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.WillRepeatedly( .WillRepeatedly(
DoAll(Invoke(test_util::SimulatePollSuccess), DoAll(Invoke(SimulatePollSuccess),
RecordSyncShareMultiple(&times, kMinNumSamples, true))); RecordSyncShareMultiple(&times, kMinNumSamples, true)));
connection()->SetServerResponse( connection()->SetServerResponse(
...@@ -1670,8 +1764,8 @@ TEST_F(SyncSchedulerImplTest, PollFromCanaryAfterAuthError) { ...@@ -1670,8 +1764,8 @@ TEST_F(SyncSchedulerImplTest, PollFromCanaryAfterAuthError) {
// but after poll finished with auth error from poll timer it should retry // but after poll finished with auth error from poll timer it should retry
// poll once more // poll once more
EXPECT_CALL(*syncer(), PollSyncShare(_, _)) EXPECT_CALL(*syncer(), PollSyncShare(_, _))
.WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulatePollSuccess), RecordSyncShare(&times, true)));
scheduler()->OnCredentialsUpdated(); scheduler()->OnCredentialsUpdated();
connection()->SetServerResponse(HttpResponse::ForSuccess()); connection()->SetServerResponse(HttpResponse::ForSuccess());
RunLoop(); RunLoop();
...@@ -1687,8 +1781,8 @@ TEST_F(SyncSchedulerImplTest, SuccessfulRetry) { ...@@ -1687,8 +1781,8 @@ TEST_F(SyncSchedulerImplTest, SuccessfulRetry) {
EXPECT_EQ(delay, GetRetryTimerDelay()); EXPECT_EQ(delay, GetRetryTimerDelay());
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
// Run to wait for retrying. // Run to wait for retrying.
RunLoop(); RunLoop();
...@@ -1709,7 +1803,7 @@ TEST_F(SyncSchedulerImplTest, FailedRetry) { ...@@ -1709,7 +1803,7 @@ TEST_F(SyncSchedulerImplTest, FailedRetry) {
scheduler()->OnReceivedGuRetryDelay(delay); scheduler()->OnReceivedGuRetryDelay(delay);
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), .WillOnce(DoAll(Invoke(SimulateDownloadUpdatesFailed),
RecordSyncShare(&times, false))); RecordSyncShare(&times, false)));
// Run to wait for retrying. // Run to wait for retrying.
...@@ -1717,8 +1811,8 @@ TEST_F(SyncSchedulerImplTest, FailedRetry) { ...@@ -1717,8 +1811,8 @@ TEST_F(SyncSchedulerImplTest, FailedRetry) {
EXPECT_TRUE(scheduler()->IsGlobalBackoff()); EXPECT_TRUE(scheduler()->IsGlobalBackoff());
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
// Run to wait for second retrying. // Run to wait for second retrying.
RunLoop(); RunLoop();
...@@ -1742,9 +1836,8 @@ TEST_F(SyncSchedulerImplTest, ReceiveNewRetryDelay) { ...@@ -1742,9 +1836,8 @@ TEST_F(SyncSchedulerImplTest, ReceiveNewRetryDelay) {
EXPECT_EQ(delay1, GetRetryTimerDelay()); EXPECT_EQ(delay1, GetRetryTimerDelay());
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(WithoutArgs(VerifyRetryTimerDelay(this, delay1)),
DoAll(WithoutArgs(VerifyRetryTimerDelay(this, delay1)), WithArg<2>(SimulateGuRetryDelayCommand(delay2)),
WithArg<2>(test_util::SimulateGuRetryDelayCommand(delay2)),
RecordSyncShare(&times, true))); RecordSyncShare(&times, true)));
// Run nudge GU. // Run nudge GU.
...@@ -1752,8 +1845,8 @@ TEST_F(SyncSchedulerImplTest, ReceiveNewRetryDelay) { ...@@ -1752,8 +1845,8 @@ TEST_F(SyncSchedulerImplTest, ReceiveNewRetryDelay) {
EXPECT_EQ(delay2, GetRetryTimerDelay()); EXPECT_EQ(delay2, GetRetryTimerDelay());
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
// Run to wait for retrying. // Run to wait for retrying.
RunLoop(); RunLoop();
...@@ -1769,8 +1862,8 @@ TEST_F(SyncSchedulerImplTest, PartialFailureWillExponentialBackoff) { ...@@ -1769,8 +1862,8 @@ TEST_F(SyncSchedulerImplTest, PartialFailureWillExponentialBackoff) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillRepeatedly(DoAll( .WillRepeatedly(
WithArg<2>(test_util::SimulatePartialFailure(types)), Return(true))) DoAll(WithArg<2>(SimulatePartialFailure(types)), Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -1815,8 +1908,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackoffAndSuccessfulSync) { ...@@ -1815,8 +1908,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackoffAndSuccessfulSync) {
// Set backoff datatype. // Set backoff datatype.
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), .WillOnce(DoAll(WithArg<2>(SimulatePartialFailure(types)), Return(true)))
Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -1830,8 +1922,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackoffAndSuccessfulSync) { ...@@ -1830,8 +1922,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackoffAndSuccessfulSync) {
SyncShareTimes times; SyncShareTimes times;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillOnce(
RecordSyncShare(&times, true))) DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
// Do a successful Sync. // Do a successful Sync.
...@@ -1865,8 +1957,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndFailureSync) { ...@@ -1865,8 +1957,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndFailureSync) {
::testing::InSequence seq; ::testing::InSequence seq;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(
DoAll(WithArg<2>(test_util::SimulatePartialFailure(themes_types)), DoAll(WithArg<2>(SimulatePartialFailure(themes_types)), Return(true)))
Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
StartSyncScheduler(base::Time()); StartSyncScheduler(base::Time());
...@@ -1881,8 +1972,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndFailureSync) { ...@@ -1881,8 +1972,7 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndFailureSync) {
// Set anther backoff datatype. // Set anther backoff datatype.
const ModelTypeSet typed_urls_types(TYPED_URLS); const ModelTypeSet typed_urls_types(TYPED_URLS);
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce( .WillOnce(DoAll(WithArg<2>(SimulatePartialFailure(typed_urls_types)),
DoAll(WithArg<2>(test_util::SimulatePartialFailure(typed_urls_types)),
Return(true))) Return(true)))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*delay(), GetDelay(_)) EXPECT_CALL(*delay(), GetDelay(_))
...@@ -1902,8 +1992,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndFailureSync) { ...@@ -1902,8 +1992,8 @@ TEST_F(SyncSchedulerImplTest, TypeBackingOffAndFailureSync) {
// Unblock one datatype. // Unblock one datatype.
SyncShareTimes times; SyncShareTimes times;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), .WillRepeatedly(
RecordSyncShare(&times, true))); DoAll(Invoke(SimulateNormalSuccess), RecordSyncShare(&times, true)));
EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay()));
PumpLoop(); // TO get OnTypesUnblocked called. PumpLoop(); // TO get OnTypesUnblocked called.
...@@ -1943,8 +2033,8 @@ TEST_F(SyncSchedulerImplTest, InterleavedNudgesStillRestart) { ...@@ -1943,8 +2033,8 @@ TEST_F(SyncSchedulerImplTest, InterleavedNudgesStillRestart) {
// Setup mock as we're about to attempt to sync. // Setup mock as we're about to attempt to sync.
SyncShareTimes times; SyncShareTimes times;
EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _))
.WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), .WillOnce(
RecordSyncShare(&times, false))); DoAll(Invoke(SimulateCommitFailed), RecordSyncShare(&times, false)));
// Triggers the THEMES TrySyncCycleJobImpl(), which we've setup to fail. Its // Triggers the THEMES TrySyncCycleJobImpl(), which we've setup to fail. Its
// RestartWaiting won't schedule a delayed retry, as the TYPED_URLS nudge has // RestartWaiting won't schedule a delayed retry, as the TYPED_URLS nudge has
// a smaller delay. We verify this by making sure the delay is still zero. // a smaller delay. We verify this by making sure the delay is still zero.
......
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