OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 15 #include "base/callback.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
21 #include "base/time.h" | |
22 #include "build/build_config.h" | 21 #include "build/build_config.h" |
23 #include "chrome/browser/sync/engine/conflict_resolver.h" | 22 #include "chrome/browser/sync/engine/conflict_resolver.h" |
24 #include "chrome/browser/sync/engine/get_commit_ids_command.h" | 23 #include "chrome/browser/sync/engine/get_commit_ids_command.h" |
25 #include "chrome/browser/sync/engine/model_safe_worker.h" | 24 #include "chrome/browser/sync/engine/model_safe_worker.h" |
26 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 25 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
27 #include "chrome/browser/sync/engine/process_updates_command.h" | 26 #include "chrome/browser/sync/engine/process_updates_command.h" |
28 #include "chrome/browser/sync/engine/nigori_util.h" | 27 #include "chrome/browser/sync/engine/nigori_util.h" |
29 #include "chrome/browser/sync/engine/syncer.h" | 28 #include "chrome/browser/sync/engine/syncer.h" |
30 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 29 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
31 #include "chrome/browser/sync/engine/syncer_util.h" | 30 #include "chrome/browser/sync/engine/syncer_util.h" |
32 #include "chrome/browser/sync/engine/syncproto.h" | 31 #include "chrome/browser/sync/engine/syncproto.h" |
33 #include "chrome/browser/sync/protocol/sync.pb.h" | 32 #include "chrome/browser/sync/protocol/sync.pb.h" |
34 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 33 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
35 #include "chrome/browser/sync/sessions/sync_session_context.h" | 34 #include "chrome/browser/sync/sessions/sync_session_context.h" |
36 #include "chrome/browser/sync/syncable/directory_manager.h" | 35 #include "chrome/browser/sync/syncable/directory_manager.h" |
37 #include "chrome/browser/sync/syncable/model_type.h" | 36 #include "chrome/browser/sync/syncable/model_type.h" |
38 #include "chrome/browser/sync/syncable/syncable.h" | 37 #include "chrome/browser/sync/syncable/syncable.h" |
39 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" | 38 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" |
40 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" | 39 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" |
41 #include "chrome/browser/sync/test/engine/test_id_factory.h" | 40 #include "chrome/browser/sync/test/engine/test_id_factory.h" |
42 #include "chrome/browser/sync/test/engine/test_syncable_utils.h" | 41 #include "chrome/browser/sync/test/engine/test_syncable_utils.h" |
43 #include "chrome/browser/sync/util/time.h" | |
44 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
45 | 43 |
46 using base::TimeDelta; | 44 using base::TimeDelta; |
47 | 45 |
48 using std::map; | 46 using std::map; |
49 using std::multimap; | 47 using std::multimap; |
50 using std::set; | 48 using std::set; |
51 using std::string; | 49 using std::string; |
52 | 50 |
53 namespace browser_sync { | 51 namespace browser_sync { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (test->id.ServerKnows()) { | 307 if (test->id.ServerKnows()) { |
310 entry.Put(BASE_VERSION, 5); | 308 entry.Put(BASE_VERSION, 5); |
311 entry.Put(SERVER_VERSION, 5); | 309 entry.Put(SERVER_VERSION, 5); |
312 entry.Put(SERVER_PARENT_ID, test->parent_id); | 310 entry.Put(SERVER_PARENT_ID, test->parent_id); |
313 } | 311 } |
314 entry.Put(syncable::IS_DIR, true); | 312 entry.Put(syncable::IS_DIR, true); |
315 entry.Put(syncable::IS_UNSYNCED, true); | 313 entry.Put(syncable::IS_UNSYNCED, true); |
316 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 314 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
317 // Set the time to 30 seconds in the future to reduce the chance of | 315 // Set the time to 30 seconds in the future to reduce the chance of |
318 // flaky tests. | 316 // flaky tests. |
319 const base::Time& now_plus_30s = | 317 int64 now_server_time = ClientTimeToServerTime(syncable::Now()); |
320 base::Time::Now() + base::TimeDelta::FromSeconds(30); | 318 int64 now_plus_30s = ServerTimeToClientTime(now_server_time + 30000); |
321 const base::Time& now_minus_2h = | 319 int64 now_minus_2h = ServerTimeToClientTime(now_server_time - 7200000); |
322 base::Time::Now() - base::TimeDelta::FromHours(2); | |
323 entry.Put(syncable::MTIME, now_plus_30s); | 320 entry.Put(syncable::MTIME, now_plus_30s); |
324 for (size_t i = 0 ; i < arraysize(test->features) ; ++i) { | 321 for (size_t i = 0 ; i < arraysize(test->features) ; ++i) { |
325 switch (test->features[i]) { | 322 switch (test->features[i]) { |
326 case LIST_END: | 323 case LIST_END: |
327 break; | 324 break; |
328 case SYNCED: | 325 case SYNCED: |
329 entry.Put(syncable::IS_UNSYNCED, false); | 326 entry.Put(syncable::IS_UNSYNCED, false); |
330 break; | 327 break; |
331 case DELETED: | 328 case DELETED: |
332 entry.Put(syncable::IS_DEL, true); | 329 entry.Put(syncable::IS_DEL, true); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME, | 887 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME, |
891 MOVED_FROM_ROOT}}, | 888 MOVED_FROM_ROOT}}, |
892 CommitOrderingTest::LAST_COMMIT_ITEM, | 889 CommitOrderingTest::LAST_COMMIT_ITEM, |
893 }; | 890 }; |
894 RunCommitOrderingTest(items); | 891 RunCommitOrderingTest(items); |
895 } | 892 } |
896 | 893 |
897 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { | 894 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { |
898 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 895 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
899 ASSERT_TRUE(dir.good()); | 896 ASSERT_TRUE(dir.good()); |
900 const base::Time& now_minus_2h = | 897 int64 now_server_time = ClientTimeToServerTime(syncable::Now()); |
901 base::Time::Now() - base::TimeDelta::FromHours(2); | 898 int64 now_minus_2h = ServerTimeToClientTime(now_server_time - 7200000); |
| 899 |
902 { | 900 { |
903 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 901 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
904 { | 902 { |
905 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 903 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), |
906 "Bob"); | 904 "Bob"); |
907 ASSERT_TRUE(parent.good()); | 905 ASSERT_TRUE(parent.good()); |
908 parent.Put(syncable::IS_UNSYNCED, true); | 906 parent.Put(syncable::IS_UNSYNCED, true); |
909 parent.Put(syncable::IS_DIR, true); | 907 parent.Put(syncable::IS_DIR, true); |
910 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 908 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
911 parent.Put(syncable::ID, ids_.FromNumber(100)); | 909 parent.Put(syncable::ID, ids_.FromNumber(100)); |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 // Only one entry, since we just overwrite one. | 1963 // Only one entry, since we just overwrite one. |
1966 EXPECT_TRUE(1 == children.size()); | 1964 EXPECT_TRUE(1 == children.size()); |
1967 saw_syncer_event_ = false; | 1965 saw_syncer_event_ = false; |
1968 } | 1966 } |
1969 | 1967 |
1970 // We got this repro case when someone was editing bookmarks while sync was | 1968 // We got this repro case when someone was editing bookmarks while sync was |
1971 // occuring. The entry had changed out underneath the user. | 1969 // occuring. The entry had changed out underneath the user. |
1972 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { | 1970 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { |
1973 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1971 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
1974 CHECK(dir.good()); | 1972 CHECK(dir.good()); |
1975 const base::Time& test_time = ProtoTimeToTime(123456); | 1973 int64 test_time = 123456; |
1976 int64 entry_metahandle; | 1974 int64 entry_metahandle; |
1977 { | 1975 { |
1978 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 1976 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
1979 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); | 1977 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); |
1980 ASSERT_TRUE(entry.good()); | 1978 ASSERT_TRUE(entry.good()); |
1981 EXPECT_FALSE(entry.Get(ID).ServerKnows()); | 1979 EXPECT_FALSE(entry.Get(ID).ServerKnows()); |
1982 entry.Put(syncable::IS_DIR, true); | 1980 entry.Put(syncable::IS_DIR, true); |
1983 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1981 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1984 entry.Put(syncable::IS_UNSYNCED, true); | 1982 entry.Put(syncable::IS_UNSYNCED, true); |
1985 entry.Put(syncable::MTIME, test_time); | 1983 entry.Put(syncable::MTIME, test_time); |
(...skipping 3260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5246 Add(low_id_); | 5244 Add(low_id_); |
5247 Add(high_id_); | 5245 Add(high_id_); |
5248 SyncShareAsDelegate(); | 5246 SyncShareAsDelegate(); |
5249 ExpectLocalOrderIsByServerId(); | 5247 ExpectLocalOrderIsByServerId(); |
5250 } | 5248 } |
5251 | 5249 |
5252 const SyncerTest::CommitOrderingTest | 5250 const SyncerTest::CommitOrderingTest |
5253 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 5251 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
5254 | 5252 |
5255 } // namespace browser_sync | 5253 } // namespace browser_sync |
OLD | NEW |