Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: chrome/browser/sync/sessions/sync_session_unittest.cc

Issue 386030: Relieve SyncerSession,SyncCycleState, SyncProcessState, SyncerSession, Syncer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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.
4
5 #include "chrome/browser/sync/sessions/sync_session.h"
6
7 #include "chrome/browser/sync/engine/conflict_resolver.h"
8 #include "chrome/browser/sync/engine/syncer_types.h"
9 #include "chrome/browser/sync/engine/syncer_util.h"
10 #include "chrome/browser/sync/syncable/directory_manager.h"
11 #include "chrome/browser/sync/syncable/syncable.h"
12 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using syncable::WriteTransaction;
16
17 namespace browser_sync {
18 namespace sessions {
19 namespace {
20
21 class SyncSessionTest : public testing::Test,
22 public SyncSession::Delegate {
23 public:
24 SyncSessionTest() : controller_invocations_allowed_(false) {}
25 virtual void SetUp() {
26 context_.reset(new SyncSessionContext(NULL, NULL, NULL));
27 session_.reset(new SyncSession(context_.get(), this));
28 }
29 virtual void TearDown() {
30 session_.reset();
31 context_.reset();
32 }
33
34 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) {
35 FailControllerInvocationIfDisabled("OnSilencedUntil");
36 }
37 virtual bool IsSyncingCurrentlySilenced() {
38 FailControllerInvocationIfDisabled("IsSyncingCurrentlySilenced");
39 return false;
40 }
41 virtual void OnReceivedLongPollIntervalUpdate(
42 const base::TimeDelta& new_interval) {
43 FailControllerInvocationIfDisabled("OnReceivedLongPollIntervalUpdate");
44 }
45 virtual void OnReceivedShortPollIntervalUpdate(
46 const base::TimeDelta& new_interval) {
47 FailControllerInvocationIfDisabled("OnReceivedShortPollIntervalUpdate");
48 }
49
50 StatusController* status() { return session_->status_controller(); }
51 protected:
52 void FailControllerInvocationIfDisabled(const std::string& msg) {
53 if (!controller_invocations_allowed_)
54 FAIL() << msg;
55 }
56 bool controller_invocations_allowed_;
57 scoped_ptr<SyncSession> session_;
58 scoped_ptr<SyncSessionContext> context_;
59 };
60
61 TEST_F(SyncSessionTest, ScopedContextHelpers) {
62 ConflictResolver resolver;
63 SyncerEventChannel* channel = new SyncerEventChannel(
64 SyncerEvent(SyncerEvent::SHUTDOWN_USE_WITH_CARE));
65 EXPECT_FALSE(context_->resolver());
66 EXPECT_FALSE(context_->syncer_event_channel());
67 {
68 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver);
69 ScopedSessionContextSyncerEventChannel s_channel(context_.get(), channel);
70 EXPECT_EQ(&resolver, context_->resolver());
71 EXPECT_EQ(channel, context_->syncer_event_channel());
72 }
73 EXPECT_FALSE(context_->resolver());
74 EXPECT_FALSE(context_->syncer_event_channel());
75 }
76
77 TEST_F(SyncSessionTest, SetWriteTransaction) {
78 TestDirectorySetterUpper db;
79 db.SetUp();
80 session_.reset(NULL);
81 context_.reset(new SyncSessionContext(NULL, db.manager(), NULL));
82 session_.reset(new SyncSession(context_.get(), this));
83 context_->set_account_name(db.name());
84 syncable::ScopedDirLookup dir(context_->directory_manager(),
85 context_->account_name());
86 ASSERT_TRUE(dir.good());
87
88 SyncSession session(context_.get(), this);
89 EXPECT_TRUE(NULL == session.write_transaction());
90 {
91 WriteTransaction trans(dir, syncable::UNITTEST, __FILE__, __LINE__);
92 sessions::ScopedSetSessionWriteTransaction set_trans(&session, &trans);
93 EXPECT_TRUE(&trans == session.write_transaction());
94 }
95 db.TearDown();
96 }
97
98 TEST_F(SyncSessionTest, MoreToSyncIfUnsyncedGreaterThanCommitted) {
99 // If any forward progress was made during the session, and the number of
100 // unsynced handles still exceeds the number of commit ids we added, there is
101 // more to sync. For example, this occurs if we had more commit ids
102 // than could fit in a single commit batch.
103 EXPECT_FALSE(session_->HasMoreToSync());
104 std::vector<syncable::Id> commit_ids;
105 commit_ids.push_back(syncable::Id());
106 status()->set_commit_ids(commit_ids);
107 EXPECT_FALSE(session_->HasMoreToSync());
108
109 std::vector<int64> unsynced_handles;
110 unsynced_handles.push_back(1);
111 unsynced_handles.push_back(2);
112 status()->set_unsynced_handles(unsynced_handles);
113 EXPECT_FALSE(session_->HasMoreToSync());
114 status()->increment_num_successful_commits();
115 EXPECT_TRUE(session_->HasMoreToSync());
116 status()->ResetTransientState();
117 EXPECT_FALSE(session_->HasMoreToSync());
118 }
119
120 TEST_F(SyncSessionTest, MoreToSyncIfConflictSetsBuilt) {
121 // If we built conflict sets, then we need to loop back and try
122 // to get updates & commit again.
123 status()->set_conflict_sets_built(true);
124 EXPECT_TRUE(session_->HasMoreToSync());
125 status()->ResetTransientState();
126 EXPECT_FALSE(session_->HasMoreToSync());
127 }
128
129 TEST_F(SyncSessionTest, MoreToSyncIfDidNotGetZeroUpdates) {
130 // We're not done getting updates until we get an empty response.
131 ClientToServerResponse response;
132 response.mutable_get_updates()->add_entries();
133 status()->mutable_updates_response()->CopyFrom(response);
134 EXPECT_TRUE(session_->HasMoreToSync());
135 status()->mutable_updates_response()->Clear();
136 EXPECT_FALSE(session_->HasMoreToSync());
137 status()->mutable_updates_response()->CopyFrom(response);
138 EXPECT_TRUE(session_->HasMoreToSync());
139 status()->ResetTransientState();
140 EXPECT_FALSE(session_->HasMoreToSync());
141 }
142
143 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) {
144 // Conflict resolution happens after get updates and commit,
145 // so we need to loop back and get updates / commit again now
146 // that we have made forward progress.
147 status()->set_conflicts_resolved(true);
148 EXPECT_TRUE(session_->HasMoreToSync());
149 status()->ResetTransientState();
150 EXPECT_FALSE(session_->HasMoreToSync());
151 }
152
153 TEST_F(SyncSessionTest, MoreToSyncIfTimestampDirty) {
154 // If there are more changes on the server that weren't processed during this
155 // GetUpdates request, the client should send another GetUpdates request and
156 // use new_timestamp as the from_timestamp value within GetUpdatesMessage.
157 status()->set_timestamp_dirty(true);
158 status()->set_conflicts_resolved(true);
159 EXPECT_TRUE(session_->HasMoreToSync());
160 status()->ResetTransientState();
161 EXPECT_FALSE(session_->HasMoreToSync());
162 }
163
164
165 } // namespace
166 } // namespace sessions
167 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/sync_session_context.h ('k') | chrome/browser/sync/syncable/blob.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698