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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 9699057: [Sync] Move 'sync' target to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Tim's comments Created 8 years, 9 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/engine/syncer_types.cc ('k') | sync/engine/syncer_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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/message_loop.h" 21 #include "base/message_loop.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
24 #include "base/time.h" 24 #include "base/time.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "chrome/browser/sync/engine/get_commit_ids_command.h" 26 #include "sync/engine/get_commit_ids_command.h"
27 #include "chrome/browser/sync/engine/model_safe_worker.h" 27 #include "sync/engine/model_safe_worker.h"
28 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 28 #include "sync/engine/net/server_connection_manager.h"
29 #include "chrome/browser/sync/engine/nigori_util.h" 29 #include "sync/engine/nigori_util.h"
30 #include "chrome/browser/sync/engine/process_updates_command.h" 30 #include "sync/engine/process_updates_command.h"
31 #include "chrome/browser/sync/engine/syncer.h" 31 #include "sync/engine/syncer.h"
32 #include "chrome/browser/sync/engine/syncer_proto_util.h" 32 #include "sync/engine/syncer_proto_util.h"
33 #include "chrome/browser/sync/engine/syncer_util.h" 33 #include "sync/engine/syncer_util.h"
34 #include "chrome/browser/sync/engine/syncproto.h" 34 #include "sync/engine/syncproto.h"
35 #include "chrome/browser/sync/sessions/sync_session_context.h"
36 #include "chrome/browser/sync/syncable/model_type.h"
37 #include "chrome/browser/sync/syncable/syncable.h"
38 #include "chrome/browser/sync/test/engine/fake_model_worker.h"
39 #include "chrome/browser/sync/test/engine/mock_connection_manager.h"
40 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h"
41 #include "chrome/browser/sync/test/engine/test_id_factory.h"
42 #include "chrome/browser/sync/test/engine/test_syncable_utils.h"
43 #include "chrome/browser/sync/test/fake_encryptor.h"
44 #include "chrome/browser/sync/test/fake_extensions_activity_monitor.h"
45 #include "chrome/browser/sync/util/cryptographer.h"
46 #include "chrome/browser/sync/util/time.h"
47 #include "sync/protocol/bookmark_specifics.pb.h" 35 #include "sync/protocol/bookmark_specifics.pb.h"
48 #include "sync/protocol/nigori_specifics.pb.h" 36 #include "sync/protocol/nigori_specifics.pb.h"
49 #include "sync/protocol/preference_specifics.pb.h" 37 #include "sync/protocol/preference_specifics.pb.h"
50 #include "sync/protocol/sync.pb.h" 38 #include "sync/protocol/sync.pb.h"
39 #include "sync/sessions/sync_session_context.h"
40 #include "sync/syncable/model_type.h"
41 #include "sync/syncable/syncable.h"
42 #include "sync/test/engine/fake_model_worker.h"
43 #include "sync/test/engine/mock_connection_manager.h"
44 #include "sync/test/engine/test_directory_setter_upper.h"
45 #include "sync/test/engine/test_id_factory.h"
46 #include "sync/test/engine/test_syncable_utils.h"
47 #include "sync/test/fake_encryptor.h"
48 #include "sync/test/fake_extensions_activity_monitor.h"
49 #include "sync/util/cryptographer.h"
50 #include "sync/util/time.h"
51 #include "testing/gtest/include/gtest/gtest.h" 51 #include "testing/gtest/include/gtest/gtest.h"
52 52
53 using base::TimeDelta; 53 using base::TimeDelta;
54 54
55 using std::map; 55 using std::map;
56 using std::multimap; 56 using std::multimap;
57 using std::set; 57 using std::set;
58 using std::string; 58 using std::string;
59 59
60 namespace browser_sync { 60 namespace browser_sync {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 }; 283 };
284 284
285 struct CommitOrderingTest { 285 struct CommitOrderingTest {
286 // expected commit index. 286 // expected commit index.
287 int commit_index; 287 int commit_index;
288 // Details about the item 288 // Details about the item
289 syncable::Id id; 289 syncable::Id id;
290 syncable::Id parent_id; 290 syncable::Id parent_id;
291 EntryFeature features[10]; 291 EntryFeature features[10];
292 292
293 static const CommitOrderingTest LAST_COMMIT_ITEM; 293 static CommitOrderingTest MakeLastCommitItem() {
294 CommitOrderingTest last_commit_item;
295 last_commit_item.commit_index = -1;
296 last_commit_item.id = TestIdFactory::root();
297 return last_commit_item;
298 }
294 }; 299 };
295 300
296 void RunCommitOrderingTest(CommitOrderingTest* test) { 301 void RunCommitOrderingTest(CommitOrderingTest* test) {
297 map<int, syncable::Id> expected_positions; 302 map<int, syncable::Id> expected_positions;
298 { // Transaction scope. 303 { // Transaction scope.
299 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 304 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
300 while (!test->id.IsRoot()) { 305 while (!test->id.IsRoot()) {
301 if (test->commit_index >= 0) { 306 if (test->commit_index >= 0) {
302 map<int, syncable::Id>::value_type entry(test->commit_index, 307 map<int, syncable::Id>::value_type entry(test->commit_index,
303 test->id); 308 test->id);
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 ReadTransaction rt(FROM_HERE, directory()); 1162 ReadTransaction rt(FROM_HERE, directory());
1158 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); 1163 Entry entry(&rt, syncable::GET_BY_ID, parent_id_);
1159 ASSERT_FALSE(entry.good()); 1164 ASSERT_FALSE(entry.good());
1160 } 1165 }
1161 } 1166 }
1162 1167
1163 TEST_F(SyncerTest, TestCommitListOrderingTwoItemsTall) { 1168 TEST_F(SyncerTest, TestCommitListOrderingTwoItemsTall) {
1164 CommitOrderingTest items[] = { 1169 CommitOrderingTest items[] = {
1165 {1, ids_.FromNumber(-1001), ids_.FromNumber(-1000)}, 1170 {1, ids_.FromNumber(-1001), ids_.FromNumber(-1000)},
1166 {0, ids_.FromNumber(-1000), ids_.FromNumber(0)}, 1171 {0, ids_.FromNumber(-1000), ids_.FromNumber(0)},
1167 CommitOrderingTest::LAST_COMMIT_ITEM, 1172 CommitOrderingTest::MakeLastCommitItem(),
1168 }; 1173 };
1169 RunCommitOrderingTest(items); 1174 RunCommitOrderingTest(items);
1170 } 1175 }
1171 1176
1172 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTall) { 1177 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTall) {
1173 CommitOrderingTest items[] = { 1178 CommitOrderingTest items[] = {
1174 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, 1179 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)},
1175 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, 1180 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)},
1176 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, 1181 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)},
1177 CommitOrderingTest::LAST_COMMIT_ITEM, 1182 CommitOrderingTest::MakeLastCommitItem(),
1178 }; 1183 };
1179 RunCommitOrderingTest(items); 1184 RunCommitOrderingTest(items);
1180 } 1185 }
1181 1186
1182 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTallLimitedSize) { 1187 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTallLimitedSize) {
1183 context_->set_max_commit_batch_size(2); 1188 context_->set_max_commit_batch_size(2);
1184 CommitOrderingTest items[] = { 1189 CommitOrderingTest items[] = {
1185 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, 1190 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)},
1186 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, 1191 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)},
1187 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, 1192 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)},
1188 CommitOrderingTest::LAST_COMMIT_ITEM, 1193 CommitOrderingTest::MakeLastCommitItem(),
1189 }; 1194 };
1190 RunCommitOrderingTest(items); 1195 RunCommitOrderingTest(items);
1191 } 1196 }
1192 1197
1193 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItem) { 1198 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItem) {
1194 CommitOrderingTest items[] = { 1199 CommitOrderingTest items[] = {
1195 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, 1200 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}},
1196 CommitOrderingTest::LAST_COMMIT_ITEM, 1201 CommitOrderingTest::MakeLastCommitItem(),
1197 }; 1202 };
1198 RunCommitOrderingTest(items); 1203 RunCommitOrderingTest(items);
1199 } 1204 }
1200 1205
1201 TEST_F(SyncerTest, TestCommitListOrderingSingleUncommittedDeletedItem) { 1206 TEST_F(SyncerTest, TestCommitListOrderingSingleUncommittedDeletedItem) {
1202 CommitOrderingTest items[] = { 1207 CommitOrderingTest items[] = {
1203 {-1, ids_.FromNumber(-1000), ids_.FromNumber(0), {DELETED}}, 1208 {-1, ids_.FromNumber(-1000), ids_.FromNumber(0), {DELETED}},
1204 CommitOrderingTest::LAST_COMMIT_ITEM, 1209 CommitOrderingTest::MakeLastCommitItem(),
1205 }; 1210 };
1206 RunCommitOrderingTest(items); 1211 RunCommitOrderingTest(items);
1207 } 1212 }
1208 1213
1209 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItemWithUnroll) { 1214 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItemWithUnroll) {
1210 CommitOrderingTest items[] = { 1215 CommitOrderingTest items[] = {
1211 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, 1216 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}},
1212 CommitOrderingTest::LAST_COMMIT_ITEM, 1217 CommitOrderingTest::MakeLastCommitItem(),
1213 }; 1218 };
1214 RunCommitOrderingTest(items); 1219 RunCommitOrderingTest(items);
1215 } 1220 }
1216 1221
1217 TEST_F(SyncerTest, 1222 TEST_F(SyncerTest,
1218 TestCommitListOrderingSingleLongDeletedItemWithUnroll) { 1223 TestCommitListOrderingSingleLongDeletedItemWithUnroll) {
1219 CommitOrderingTest items[] = { 1224 CommitOrderingTest items[] = {
1220 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1225 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1221 CommitOrderingTest::LAST_COMMIT_ITEM, 1226 CommitOrderingTest::MakeLastCommitItem(),
1222 }; 1227 };
1223 RunCommitOrderingTest(items); 1228 RunCommitOrderingTest(items);
1224 } 1229 }
1225 1230
1226 TEST_F(SyncerTest, TestCommitListOrderingTwoLongDeletedItemWithUnroll) { 1231 TEST_F(SyncerTest, TestCommitListOrderingTwoLongDeletedItemWithUnroll) {
1227 CommitOrderingTest items[] = { 1232 CommitOrderingTest items[] = {
1228 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1233 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1229 {-1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, 1234 {-1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}},
1230 CommitOrderingTest::LAST_COMMIT_ITEM, 1235 CommitOrderingTest::MakeLastCommitItem(),
1231 }; 1236 };
1232 RunCommitOrderingTest(items); 1237 RunCommitOrderingTest(items);
1233 } 1238 }
1234 1239
1235 TEST_F(SyncerTest, TestCommitListOrdering3LongDeletedItemsWithSizeLimit) { 1240 TEST_F(SyncerTest, TestCommitListOrdering3LongDeletedItemsWithSizeLimit) {
1236 context_->set_max_commit_batch_size(2); 1241 context_->set_max_commit_batch_size(2);
1237 CommitOrderingTest items[] = { 1242 CommitOrderingTest items[] = {
1238 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1243 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1239 {1, ids_.FromNumber(1001), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1244 {1, ids_.FromNumber(1001), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1240 {2, ids_.FromNumber(1002), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1245 {2, ids_.FromNumber(1002), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1241 CommitOrderingTest::LAST_COMMIT_ITEM, 1246 CommitOrderingTest::MakeLastCommitItem(),
1242 }; 1247 };
1243 RunCommitOrderingTest(items); 1248 RunCommitOrderingTest(items);
1244 } 1249 }
1245 1250
1246 TEST_F(SyncerTest, TestCommitListOrderingTwoDeletedItemsWithUnroll) { 1251 TEST_F(SyncerTest, TestCommitListOrderingTwoDeletedItemsWithUnroll) {
1247 CommitOrderingTest items[] = { 1252 CommitOrderingTest items[] = {
1248 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, 1253 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}},
1249 {-1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED}}, 1254 {-1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED}},
1250 CommitOrderingTest::LAST_COMMIT_ITEM, 1255 CommitOrderingTest::MakeLastCommitItem(),
1251 }; 1256 };
1252 RunCommitOrderingTest(items); 1257 RunCommitOrderingTest(items);
1253 } 1258 }
1254 1259
1255 TEST_F(SyncerTest, TestCommitListOrderingComplexDeletionScenario) { 1260 TEST_F(SyncerTest, TestCommitListOrderingComplexDeletionScenario) {
1256 CommitOrderingTest items[] = { 1261 CommitOrderingTest items[] = {
1257 { 0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1262 { 0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1258 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, 1263 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}},
1259 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, 1264 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}},
1260 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, 1265 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}},
1261 {2, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, 1266 {2, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}},
1262 CommitOrderingTest::LAST_COMMIT_ITEM, 1267 CommitOrderingTest::MakeLastCommitItem(),
1263 }; 1268 };
1264 RunCommitOrderingTest(items); 1269 RunCommitOrderingTest(items);
1265 } 1270 }
1266 1271
1267 TEST_F(SyncerTest, 1272 TEST_F(SyncerTest,
1268 TestCommitListOrderingComplexDeletionScenarioWith2RecentDeletes) { 1273 TestCommitListOrderingComplexDeletionScenarioWith2RecentDeletes) {
1269 CommitOrderingTest items[] = { 1274 CommitOrderingTest items[] = {
1270 { 0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1275 { 0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1271 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, 1276 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}},
1272 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, 1277 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}},
1273 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, 1278 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}},
1274 {2, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, 1279 {2, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}},
1275 {3, ids_.FromNumber(1005), ids_.FromNumber(1003), {DELETED}}, 1280 {3, ids_.FromNumber(1005), ids_.FromNumber(1003), {DELETED}},
1276 CommitOrderingTest::LAST_COMMIT_ITEM, 1281 CommitOrderingTest::MakeLastCommitItem(),
1277 }; 1282 };
1278 RunCommitOrderingTest(items); 1283 RunCommitOrderingTest(items);
1279 } 1284 }
1280 1285
1281 TEST_F(SyncerTest, TestCommitListOrderingDeleteMovedItems) { 1286 TEST_F(SyncerTest, TestCommitListOrderingDeleteMovedItems) {
1282 CommitOrderingTest items[] = { 1287 CommitOrderingTest items[] = {
1283 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, 1288 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}},
1284 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME, 1289 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME,
1285 MOVED_FROM_ROOT}}, 1290 MOVED_FROM_ROOT}},
1286 CommitOrderingTest::LAST_COMMIT_ITEM, 1291 CommitOrderingTest::MakeLastCommitItem(),
1287 }; 1292 };
1288 RunCommitOrderingTest(items); 1293 RunCommitOrderingTest(items);
1289 } 1294 }
1290 1295
1291 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { 1296 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) {
1292 const base::Time& now_minus_2h = 1297 const base::Time& now_minus_2h =
1293 base::Time::Now() - base::TimeDelta::FromHours(2); 1298 base::Time::Now() - base::TimeDelta::FromHours(2);
1294 { 1299 {
1295 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1300 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1296 { 1301 {
(...skipping 3211 matching lines...) Expand 10 before | Expand all | Expand 10 after
4508 } 4513 }
4509 4514
4510 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4515 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4511 Add(mid_id_); 4516 Add(mid_id_);
4512 Add(low_id_); 4517 Add(low_id_);
4513 Add(high_id_); 4518 Add(high_id_);
4514 SyncShareAsDelegate(); 4519 SyncShareAsDelegate();
4515 ExpectLocalOrderIsByServerId(); 4520 ExpectLocalOrderIsByServerId();
4516 } 4521 }
4517 4522
4518 const SyncerTest::CommitOrderingTest
4519 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()};
4520
4521 } // namespace browser_sync 4523 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/engine/syncer_types.cc ('k') | sync/engine/syncer_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698