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

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

Issue 10933075: FYI: Remove PerModelSafeGroupState + move ConflictResolution (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months 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
« no previous file with comments | « sync/sessions/sync_session.cc ('k') | sync/sessions/test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/sessions/sync_session.h" 5 #include "sync/sessions/sync_session.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "sync/engine/conflict_resolver.h" 11 #include "sync/engine/conflict_resolver.h"
12 #include "sync/engine/syncer_types.h" 12 #include "sync/engine/syncer_types.h"
13 #include "sync/engine/throttled_data_type_tracker.h" 13 #include "sync/engine/throttled_data_type_tracker.h"
14 #include "sync/internal_api/public/base/model_type.h" 14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/base/model_type_state_map_test_util.h" 15 #include "sync/internal_api/public/base/model_type_state_map_test_util.h"
16 #include "sync/sessions/session_state.h"
17 #include "sync/sessions/status_controller.h" 16 #include "sync/sessions/status_controller.h"
18 #include "sync/syncable/syncable_id.h" 17 #include "sync/syncable/syncable_id.h"
19 #include "sync/syncable/write_transaction.h" 18 #include "sync/syncable/write_transaction.h"
20 #include "sync/test/engine/fake_model_worker.h" 19 #include "sync/test/engine/fake_model_worker.h"
21 #include "sync/test/engine/test_directory_setter_upper.h" 20 #include "sync/test/engine/test_directory_setter_upper.h"
22 #include "sync/test/fake_extensions_activity_monitor.h" 21 #include "sync/test/fake_extensions_activity_monitor.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 23
25 namespace syncer { 24 namespace syncer {
26 25
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 154
156 TEST_F(SyncSessionTest, EnabledGroups) { 155 TEST_F(SyncSessionTest, EnabledGroups) {
157 scoped_ptr<SyncSession> session(MakeSession()); 156 scoped_ptr<SyncSession> session(MakeSession());
158 std::set<ModelSafeGroup> expected_enabled_groups; 157 std::set<ModelSafeGroup> expected_enabled_groups;
159 expected_enabled_groups.insert(GROUP_PASSIVE); 158 expected_enabled_groups.insert(GROUP_PASSIVE);
160 expected_enabled_groups.insert(GROUP_UI); 159 expected_enabled_groups.insert(GROUP_UI);
161 expected_enabled_groups.insert(GROUP_DB); 160 expected_enabled_groups.insert(GROUP_DB);
162 EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups()); 161 EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups());
163 } 162 }
164 163
165 TEST_F(SyncSessionTest, EnabledGroupsWithConflictsEmpty) {
166 scoped_ptr<SyncSession> session(MakeSession());
167 // Auto-create conflict progress. This shouldn't put that group in
168 // conflict.
169 session->mutable_status_controller()->
170 GetUnrestrictedMutableConflictProgressForTest(GROUP_PASSIVE);
171 EXPECT_TRUE(session->GetEnabledGroupsWithConflicts().empty());
172 }
173
174 TEST_F(SyncSessionTest, EnabledGroupsWithConflicts) {
175 scoped_ptr<SyncSession> session(MakeSession());
176 // Put GROUP_UI in conflict.
177 session->mutable_status_controller()->
178 GetUnrestrictedMutableConflictProgressForTest(GROUP_UI)->
179 AddSimpleConflictingItemById(syncable::Id());
180 std::set<ModelSafeGroup> expected_enabled_groups_with_conflicts;
181 expected_enabled_groups_with_conflicts.insert(GROUP_UI);
182 EXPECT_EQ(expected_enabled_groups_with_conflicts,
183 session->GetEnabledGroupsWithConflicts());
184 }
185
186 TEST_F(SyncSessionTest, ScopedContextHelpers) { 164 TEST_F(SyncSessionTest, ScopedContextHelpers) {
187 ConflictResolver resolver; 165 ConflictResolver resolver;
188 EXPECT_FALSE(context_->resolver()); 166 EXPECT_FALSE(context_->resolver());
189 { 167 {
190 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver); 168 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver);
191 EXPECT_EQ(&resolver, context_->resolver()); 169 EXPECT_EQ(&resolver, context_->resolver());
192 } 170 }
193 EXPECT_FALSE(context_->resolver()); 171 EXPECT_FALSE(context_->resolver());
194 } 172 }
195 173
(...skipping 12 matching lines...) Expand all
208 } 186 }
209 187
210 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { 188 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) {
211 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); 189 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes());
212 190
213 status()->set_last_download_updates_result(NETWORK_IO_ERROR); 191 status()->set_last_download_updates_result(NETWORK_IO_ERROR);
214 192
215 // When DownloadUpdatesCommand fails, these should be false. 193 // When DownloadUpdatesCommand fails, these should be false.
216 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); 194 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload());
217 EXPECT_FALSE(status()->download_updates_succeeded()); 195 EXPECT_FALSE(status()->download_updates_succeeded());
218
219 // Download updates has its own loop in the syncer; it shouldn't factor
220 // into HasMoreToSync.
221 EXPECT_FALSE(session_->HasMoreToSync());
222 } 196 }
223 197
224 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { 198 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) {
225 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); 199 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes());
226 200
227 // When the server returns changes_remaining, that means there's 201 // When the server returns changes_remaining, that means there's
228 // more to download. 202 // more to download.
229 status()->set_last_download_updates_result(SYNCER_OK); 203 status()->set_last_download_updates_result(SYNCER_OK);
230 status()->mutable_updates_response()->mutable_get_updates() 204 status()->mutable_updates_response()->mutable_get_updates()
231 ->set_changes_remaining(1000L); 205 ->set_changes_remaining(1000L);
232 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); 206 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload());
233 EXPECT_TRUE(status()->download_updates_succeeded()); 207 EXPECT_TRUE(status()->download_updates_succeeded());
234
235 // Download updates has its own loop in the syncer; it shouldn't factor
236 // into HasMoreToSync.
237 EXPECT_FALSE(session_->HasMoreToSync());
238 } 208 }
239 209
240 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { 210 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) {
241 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); 211 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes());
242 212
243 status()->set_last_download_updates_result(SYNCER_OK); 213 status()->set_last_download_updates_result(SYNCER_OK);
244 status()->mutable_updates_response()->mutable_get_updates() 214 status()->mutable_updates_response()->mutable_get_updates()
245 ->set_changes_remaining(0); 215 ->set_changes_remaining(0);
246 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); 216 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload());
247 EXPECT_TRUE(status()->download_updates_succeeded()); 217 EXPECT_TRUE(status()->download_updates_succeeded());
248
249 // Download updates has its own loop in the syncer; it shouldn't factor
250 // into HasMoreToSync.
251 EXPECT_FALSE(session_->HasMoreToSync());
252 }
253
254 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) {
255 // Conflict resolution happens after get updates and commit,
256 // so we need to loop back and get updates / commit again now
257 // that we have made forward progress.
258 status()->update_conflicts_resolved(true);
259 EXPECT_TRUE(session_->HasMoreToSync());
260 }
261
262 TEST_F(SyncSessionTest, ResetTransientState) {
263 status()->update_conflicts_resolved(true);
264 status()->increment_num_successful_commits();
265 EXPECT_TRUE(session_->HasMoreToSync());
266 session_->PrepareForAnotherSyncCycle();
267 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION,
268 session_->source().updates_source);
269 EXPECT_FALSE(status()->conflicts_resolved());
270 EXPECT_FALSE(session_->HasMoreToSync());
271 } 218 }
272 219
273 TEST_F(SyncSessionTest, Coalesce) { 220 TEST_F(SyncSessionTest, Coalesce) {
274 std::vector<ModelSafeWorker*> workers_one, workers_two; 221 std::vector<ModelSafeWorker*> workers_one, workers_two;
275 ModelSafeRoutingInfo routes_one, routes_two; 222 ModelSafeRoutingInfo routes_one, routes_two;
276 ModelTypeStateMap one_type = 223 ModelTypeStateMap one_type =
277 ModelTypeSetToStateMap( 224 ModelTypeSetToStateMap(
278 ParamsMeaningJustOneEnabledType(), 225 ParamsMeaningJustOneEnabledType(),
279 std::string()); 226 std::string());
280 ModelTypeStateMap all_types = 227 ModelTypeStateMap all_types =
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 444
498 ASSERT_EQ(3U, type_state_map.size()); 445 ASSERT_EQ(3U, type_state_map.size());
499 EXPECT_EQ(type_state_map[BOOKMARKS].payload, payload); 446 EXPECT_EQ(type_state_map[BOOKMARKS].payload, payload);
500 EXPECT_EQ(type_state_map[PASSWORDS].payload, payload); 447 EXPECT_EQ(type_state_map[PASSWORDS].payload, payload);
501 EXPECT_EQ(type_state_map[AUTOFILL].payload, payload); 448 EXPECT_EQ(type_state_map[AUTOFILL].payload, payload);
502 } 449 }
503 450
504 } // namespace 451 } // namespace
505 } // namespace sessions 452 } // namespace sessions
506 } // namespace syncer 453 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/sync_session.cc ('k') | sync/sessions/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698