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

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

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

Powered by Google App Engine
This is Rietveld 408576698