This source file includes following definitions.
- IsExitConditionSatisfied
- GetDebugMessage
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include "chrome/browser/sync/test/integration/retry_verifier.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
namespace {
using bookmarks_helper::AddFolder;
using bookmarks_helper::ModelMatchesVerifier;
using syncer::sessions::SyncSessionSnapshot;
using sync_integration_test_util::AwaitCommitActivityCompletion;
class SyncExponentialBackoffTest : public SyncTest {
public:
SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT_LEGACY) {}
virtual ~SyncExponentialBackoffTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest);
};
class ExponentialBackoffChecker : public SingleClientStatusChangeChecker {
public:
explicit ExponentialBackoffChecker(ProfileSyncService* pss)
: SingleClientStatusChangeChecker(pss) {
const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot();
retry_verifier_.Initialize(snap);
}
virtual ~ExponentialBackoffChecker() {}
virtual bool IsExitConditionSatisfied() OVERRIDE {
const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot();
retry_verifier_.VerifyRetryInterval(snap);
return (retry_verifier_.done() && retry_verifier_.Succeeded());
}
virtual std::string GetDebugMessage() const OVERRIDE {
return base::StringPrintf("Verifying backoff intervals (%d/%d)",
retry_verifier_.retry_count(),
RetryVerifier::kMaxRetry);
}
private:
RetryVerifier retry_verifier_;
DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker);
};
IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(AddFolder(0, 0, L"folder1"));
ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
DisableNetwork(GetProfile(0));
ASSERT_TRUE(AddFolder(0, 0, L"folder2"));
ExponentialBackoffChecker exponential_backoff_checker(
GetSyncService((0)));
exponential_backoff_checker.Wait();
ASSERT_FALSE(exponential_backoff_checker.TimedOut());
EnableNetwork(GetProfile(0));
ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
ASSERT_TRUE(ModelMatchesVerifier(0));
}
IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(AddFolder(0, 0, L"folder1"));
ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
TriggerTransientError();
ASSERT_TRUE(AddFolder(0, 0, L"folder2"));
ExponentialBackoffChecker exponential_backoff_checker(
GetSyncService((0)));
exponential_backoff_checker.Wait();
ASSERT_FALSE(exponential_backoff_checker.TimedOut());
}
}