BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / sync_exponential_backoff_test.cc
blob5245ffb395d60f6542d1dea4c3ee91cddc720b5e
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
9 #include "chrome/browser/sync/test/integration/retry_verifier.h"
10 #include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
11 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
12 #include "chrome/browser/sync/test/integration/sync_test.h"
14 namespace {
16 using bookmarks_helper::AddFolder;
17 using bookmarks_helper::ModelMatchesVerifier;
18 using syncer::sessions::SyncSessionSnapshot;
19 using sync_integration_test_util::AwaitCommitActivityCompletion;
21 class SyncExponentialBackoffTest : public SyncTest {
22 public:
23 SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT) {}
24 ~SyncExponentialBackoffTest() override {}
26 private:
27 DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest);
30 // Helper class that checks if a sync client has successfully gone through
31 // exponential backoff after it encounters an error.
32 class ExponentialBackoffChecker : public SingleClientStatusChangeChecker {
33 public:
34 explicit ExponentialBackoffChecker(ProfileSyncService* pss)
35 : SingleClientStatusChangeChecker(pss) {
36 const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot();
37 retry_verifier_.Initialize(snap);
40 ~ExponentialBackoffChecker() override {}
42 // Checks if backoff is complete. Called repeatedly each time PSS notifies
43 // observers of a state change.
44 bool IsExitConditionSatisfied() override {
45 const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot();
46 retry_verifier_.VerifyRetryInterval(snap);
47 return (retry_verifier_.done() && retry_verifier_.Succeeded());
50 std::string GetDebugMessage() const override {
51 return base::StringPrintf("Verifying backoff intervals (%d/%d)",
52 retry_verifier_.retry_count(),
53 RetryVerifier::kMaxRetry);
56 private:
57 // Keeps track of the number of attempts at exponential backoff and its
58 // related bookkeeping information for verification.
59 RetryVerifier retry_verifier_;
61 DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker);
64 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) {
65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
67 // Add an item and ensure that sync is successful.
68 ASSERT_TRUE(AddFolder(0, 0, "folder1"));
69 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
71 GetFakeServer()->DisableNetwork();
73 // Add a new item to trigger another sync cycle.
74 ASSERT_TRUE(AddFolder(0, 0, "folder2"));
76 // Verify that the client goes into exponential backoff while it is unable to
77 // reach the sync server.
78 ExponentialBackoffChecker exponential_backoff_checker(
79 GetSyncService((0)));
80 exponential_backoff_checker.Wait();
81 ASSERT_FALSE(exponential_backoff_checker.TimedOut());
83 GetFakeServer()->EnableNetwork();
85 // Verify that sync was able to recover.
86 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
87 ASSERT_TRUE(ModelMatchesVerifier(0));
90 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) {
91 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
93 // Add an item and ensure that sync is successful.
94 ASSERT_TRUE(AddFolder(0, 0, "folder1"));
95 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
97 GetFakeServer()->TriggerError(sync_pb::SyncEnums::TRANSIENT_ERROR);
99 // Add a new item to trigger another sync cycle.
100 ASSERT_TRUE(AddFolder(0, 0, "folder2"));
102 // Verify that the client goes into exponential backoff while it is unable to
103 // reach the sync server.
104 ExponentialBackoffChecker exponential_backoff_checker(
105 GetSyncService((0)));
106 exponential_backoff_checker.Wait();
107 ASSERT_FALSE(exponential_backoff_checker.TimedOut());
110 } // namespace