OLD | NEW |
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> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "sync/engine/get_commit_ids_command.h" | 26 #include "sync/engine/get_commit_ids_command.h" |
27 #include "sync/engine/net/server_connection_manager.h" | 27 #include "sync/engine/net/server_connection_manager.h" |
28 #include "sync/engine/process_updates_command.h" | 28 #include "sync/engine/process_updates_command.h" |
29 #include "sync/engine/sync_scheduler_impl.h" | 29 #include "sync/engine/sync_scheduler_impl.h" |
30 #include "sync/engine/syncer.h" | 30 #include "sync/engine/syncer.h" |
31 #include "sync/engine/syncer_proto_util.h" | 31 #include "sync/engine/syncer_proto_util.h" |
32 #include "sync/engine/throttled_data_type_tracker.h" | 32 #include "sync/engine/throttled_data_type_tracker.h" |
33 #include "sync/engine/traffic_recorder.h" | 33 #include "sync/engine/traffic_recorder.h" |
34 #include "sync/internal_api/public/base/model_type.h" | 34 #include "sync/internal_api/public/base/model_type.h" |
35 #include "sync/internal_api/public/engine/model_safe_worker.h" | 35 #include "sync/internal_api/public/engine/model_safe_worker.h" |
36 #include "sync/internal_api/public/base/node_ordinal.h" | |
37 #include "sync/protocol/bookmark_specifics.pb.h" | 36 #include "sync/protocol/bookmark_specifics.pb.h" |
38 #include "sync/protocol/nigori_specifics.pb.h" | 37 #include "sync/protocol/nigori_specifics.pb.h" |
39 #include "sync/protocol/preference_specifics.pb.h" | 38 #include "sync/protocol/preference_specifics.pb.h" |
40 #include "sync/protocol/sync.pb.h" | 39 #include "sync/protocol/sync.pb.h" |
41 #include "sync/sessions/sync_session_context.h" | 40 #include "sync/sessions/sync_session_context.h" |
42 #include "sync/syncable/mutable_entry.h" | 41 #include "sync/syncable/mutable_entry.h" |
43 #include "sync/syncable/nigori_util.h" | 42 #include "sync/syncable/nigori_util.h" |
44 #include "sync/syncable/read_transaction.h" | 43 #include "sync/syncable/read_transaction.h" |
45 #include "sync/syncable/syncable_util.h" | 44 #include "sync/syncable/syncable_util.h" |
46 #include "sync/syncable/write_transaction.h" | 45 #include "sync/syncable/write_transaction.h" |
47 #include "sync/test/engine/fake_model_worker.h" | 46 #include "sync/test/engine/fake_model_worker.h" |
48 #include "sync/test/engine/mock_connection_manager.h" | 47 #include "sync/test/engine/mock_connection_manager.h" |
49 #include "sync/test/engine/test_directory_setter_upper.h" | 48 #include "sync/test/engine/test_directory_setter_upper.h" |
50 #include "sync/test/engine/test_id_factory.h" | 49 #include "sync/test/engine/test_id_factory.h" |
51 #include "sync/test/engine/test_syncable_utils.h" | 50 #include "sync/test/engine/test_syncable_utils.h" |
52 #include "sync/test/fake_encryptor.h" | 51 #include "sync/test/fake_encryptor.h" |
53 #include "sync/test/fake_extensions_activity_monitor.h" | 52 #include "sync/test/fake_extensions_activity_monitor.h" |
54 #include "sync/test/fake_sync_encryption_handler.h" | 53 #include "sync/test/fake_sync_encryption_handler.h" |
55 #include "sync/util/cryptographer.h" | 54 #include "sync/util/cryptographer.h" |
56 #include "sync/util/time.h" | 55 #include "sync/util/time.h" |
57 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
58 | 57 |
59 using base::TimeDelta; | 58 using base::TimeDelta; |
60 | 59 |
| 60 using std::count; |
61 using std::map; | 61 using std::map; |
62 using std::multimap; | 62 using std::multimap; |
63 using std::set; | 63 using std::set; |
64 using std::string; | 64 using std::string; |
| 65 using std::vector; |
65 | 66 |
66 namespace syncer { | 67 namespace syncer { |
67 | 68 |
68 using syncable::BaseTransaction; | 69 using syncable::BaseTransaction; |
69 using syncable::Blob; | 70 using syncable::Blob; |
70 using syncable::CountEntriesWithName; | 71 using syncable::CountEntriesWithName; |
71 using syncable::Directory; | 72 using syncable::Directory; |
72 using syncable::Entry; | 73 using syncable::Entry; |
73 using syncable::GetFirstEntryWithName; | 74 using syncable::GetFirstEntryWithName; |
74 using syncable::GetOnlyEntryWithName; | 75 using syncable::GetOnlyEntryWithName; |
75 using syncable::Id; | 76 using syncable::Id; |
76 using syncable::kEncryptedString; | 77 using syncable::kEncryptedString; |
77 using syncable::MutableEntry; | 78 using syncable::MutableEntry; |
78 using syncable::WriteTransaction; | 79 using syncable::WriteTransaction; |
79 | 80 |
80 using syncable::BASE_VERSION; | 81 using syncable::BASE_VERSION; |
81 using syncable::CREATE; | 82 using syncable::CREATE_BOOKMARK; |
| 83 using syncable::CREATE_UNIQUE; |
82 using syncable::GET_BY_HANDLE; | 84 using syncable::GET_BY_HANDLE; |
83 using syncable::GET_BY_ID; | 85 using syncable::GET_BY_ID; |
84 using syncable::GET_BY_CLIENT_TAG; | 86 using syncable::GET_BY_CLIENT_TAG; |
85 using syncable::GET_BY_SERVER_TAG; | 87 using syncable::GET_BY_SERVER_TAG; |
86 using syncable::ID; | 88 using syncable::ID; |
87 using syncable::IS_DEL; | 89 using syncable::IS_DEL; |
88 using syncable::IS_DIR; | 90 using syncable::IS_DIR; |
89 using syncable::IS_UNAPPLIED_UPDATE; | 91 using syncable::IS_UNAPPLIED_UPDATE; |
90 using syncable::IS_UNSYNCED; | 92 using syncable::IS_UNSYNCED; |
91 using syncable::META_HANDLE; | 93 using syncable::META_HANDLE; |
92 using syncable::MTIME; | 94 using syncable::MTIME; |
93 using syncable::NEXT_ID; | |
94 using syncable::NON_UNIQUE_NAME; | 95 using syncable::NON_UNIQUE_NAME; |
95 using syncable::PARENT_ID; | 96 using syncable::PARENT_ID; |
96 using syncable::PREV_ID; | |
97 using syncable::BASE_SERVER_SPECIFICS; | 97 using syncable::BASE_SERVER_SPECIFICS; |
98 using syncable::SERVER_IS_DEL; | 98 using syncable::SERVER_IS_DEL; |
99 using syncable::SERVER_PARENT_ID; | 99 using syncable::SERVER_PARENT_ID; |
100 using syncable::SERVER_ORDINAL_IN_PARENT; | |
101 using syncable::SERVER_SPECIFICS; | 100 using syncable::SERVER_SPECIFICS; |
102 using syncable::SERVER_VERSION; | 101 using syncable::SERVER_VERSION; |
103 using syncable::UNIQUE_CLIENT_TAG; | 102 using syncable::UNIQUE_CLIENT_TAG; |
104 using syncable::UNIQUE_SERVER_TAG; | 103 using syncable::UNIQUE_SERVER_TAG; |
105 using syncable::SPECIFICS; | 104 using syncable::SPECIFICS; |
106 using syncable::SYNCING; | 105 using syncable::SYNCING; |
107 using syncable::UNITTEST; | 106 using syncable::UNITTEST; |
108 | 107 |
109 using sessions::ScopedSetSessionWriteTransaction; | 108 using sessions::ScopedSetSessionWriteTransaction; |
110 using sessions::StatusController; | 109 using sessions::StatusController; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 349 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
351 while (!test->id.IsRoot()) { | 350 while (!test->id.IsRoot()) { |
352 if (test->commit_index >= 0) { | 351 if (test->commit_index >= 0) { |
353 map<int, syncable::Id>::value_type entry(test->commit_index, | 352 map<int, syncable::Id>::value_type entry(test->commit_index, |
354 test->id); | 353 test->id); |
355 bool double_position = !expected_positions.insert(entry).second; | 354 bool double_position = !expected_positions.insert(entry).second; |
356 ASSERT_FALSE(double_position) << "Two id's expected at one position"; | 355 ASSERT_FALSE(double_position) << "Two id's expected at one position"; |
357 } | 356 } |
358 string utf8_name = test->id.GetServerId(); | 357 string utf8_name = test->id.GetServerId(); |
359 string name(utf8_name.begin(), utf8_name.end()); | 358 string name(utf8_name.begin(), utf8_name.end()); |
360 MutableEntry entry(&trans, CREATE, test->parent_id, name); | 359 MutableEntry entry(&trans, CREATE_BOOKMARK, test->parent_id, name); |
361 | 360 |
362 entry.Put(syncable::ID, test->id); | 361 entry.Put(syncable::ID, test->id); |
363 if (test->id.ServerKnows()) { | 362 if (test->id.ServerKnows()) { |
364 entry.Put(BASE_VERSION, 5); | 363 entry.Put(BASE_VERSION, 5); |
365 entry.Put(SERVER_VERSION, 5); | 364 entry.Put(SERVER_VERSION, 5); |
366 entry.Put(SERVER_PARENT_ID, test->parent_id); | 365 entry.Put(SERVER_PARENT_ID, test->parent_id); |
367 } | 366 } |
368 entry.Put(syncable::IS_DIR, true); | 367 entry.Put(syncable::IS_DIR, true); |
369 entry.Put(syncable::IS_UNSYNCED, true); | 368 entry.Put(syncable::IS_UNSYNCED, true); |
370 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 369 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 452 |
454 int64 CreateUnsyncedDirectory(const string& entry_name, | 453 int64 CreateUnsyncedDirectory(const string& entry_name, |
455 const string& idstring) { | 454 const string& idstring) { |
456 return CreateUnsyncedDirectory(entry_name, | 455 return CreateUnsyncedDirectory(entry_name, |
457 syncable::Id::CreateFromServerId(idstring)); | 456 syncable::Id::CreateFromServerId(idstring)); |
458 } | 457 } |
459 | 458 |
460 int64 CreateUnsyncedDirectory(const string& entry_name, | 459 int64 CreateUnsyncedDirectory(const string& entry_name, |
461 const syncable::Id& id) { | 460 const syncable::Id& id) { |
462 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 461 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
463 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), | 462 MutableEntry entry(&wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), |
464 entry_name); | 463 entry_name); |
465 EXPECT_TRUE(entry.good()); | 464 EXPECT_TRUE(entry.good()); |
466 entry.Put(syncable::IS_UNSYNCED, true); | 465 entry.Put(syncable::IS_UNSYNCED, true); |
467 entry.Put(syncable::IS_DIR, true); | 466 entry.Put(syncable::IS_DIR, true); |
468 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 467 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
469 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); | 468 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); |
470 entry.Put(syncable::ID, id); | 469 entry.Put(syncable::ID, id); |
471 return entry.Get(META_HANDLE); | 470 return entry.Get(META_HANDLE); |
472 } | 471 } |
473 | 472 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 // have pending keys. | 842 // have pending keys. |
844 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 843 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
845 sync_pb::EntitySpecifics specifics; | 844 sync_pb::EntitySpecifics specifics; |
846 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 845 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
847 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); | 846 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
848 dir_maker_.encryption_handler()->EnableEncryptEverything(); | 847 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
849 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); | 848 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); |
850 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); | 849 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); |
851 } | 850 } |
852 | 851 |
853 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); | 852 // We need to remember the exact position of our local items, so we can |
854 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); | 853 // make updates that do not modify those positions. |
855 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); | 854 UniquePosition pos1; |
| 855 UniquePosition pos2; |
| 856 UniquePosition pos3; |
| 857 |
| 858 mock_server_->AddBookmarkUpdateSpecifics( |
| 859 1, 0, "A", 10, 10, true, 0, bookmark); |
| 860 mock_server_->AddBookmarkUpdateSpecifics( |
| 861 2, 1, "B", 10, 10, false, 2, bookmark); |
| 862 mock_server_->AddBookmarkUpdateSpecifics( |
| 863 3, 1, "C", 10, 10, false, 1, bookmark); |
856 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); | 864 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); |
857 SyncShareNudge(); | 865 SyncShareNudge(); |
858 { | 866 { |
859 // Initial state. Everything is normal. | 867 // Initial state. Everything is normal. |
860 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 868 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
861 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); | 869 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); |
862 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); | 870 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); |
863 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); | 871 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); |
864 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); | 872 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); |
| 873 |
| 874 Entry entry1(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
| 875 ASSERT_TRUE(entry1.Get(syncable::UNIQUE_POSITION).Equals( |
| 876 entry1.Get(syncable::SERVER_UNIQUE_POSITION))); |
| 877 pos1 = entry1.Get(syncable::UNIQUE_POSITION); |
| 878 Entry entry2(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); |
| 879 pos2 = entry2.Get(syncable::UNIQUE_POSITION); |
| 880 Entry entry3(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(3)); |
| 881 pos3 = entry3.Get(syncable::UNIQUE_POSITION); |
865 } | 882 } |
866 | 883 |
867 // Server side encryption will not be applied due to undecryptable data. | 884 // Server side encryption will not be applied due to undecryptable data. |
868 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items. | 885 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items. |
869 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, | 886 mock_server_->AddBookmarkUpdateSpecifics( |
870 encrypted_bookmark); | 887 1, 0, kEncryptedString, 20, 20, true, pos1, encrypted_bookmark); |
871 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, | 888 mock_server_->AddBookmarkUpdateSpecifics( |
872 encrypted_bookmark); | 889 2, 1, kEncryptedString, 20, 20, false, pos2, encrypted_bookmark); |
873 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, | 890 mock_server_->AddBookmarkUpdateSpecifics( |
874 encrypted_bookmark); | 891 3, 1, kEncryptedString, 20, 20, false, pos3, encrypted_bookmark); |
875 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, | 892 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, |
876 encrypted_pref); | 893 encrypted_pref); |
877 SyncShareNudge(); | 894 SyncShareNudge(); |
878 { | 895 { |
879 // All should be unapplied due to being undecryptable and have a valid | 896 // All should be unapplied due to being undecryptable and have a valid |
880 // BASE_SERVER_SPECIFICS. | 897 // BASE_SERVER_SPECIFICS. |
881 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 898 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
882 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); | 899 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); |
883 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); | 900 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); |
884 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); | 901 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); |
885 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); | 902 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); |
886 } | 903 } |
887 | 904 |
888 // Server side change that don't modify anything should not affect | 905 // Server side change that don't modify anything should not affect |
889 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). | 906 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). |
890 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, | 907 mock_server_->AddBookmarkUpdateSpecifics( |
891 encrypted_bookmark); | 908 1, 0, kEncryptedString, 30, 30, true, pos1, encrypted_bookmark); |
892 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, | 909 mock_server_->AddBookmarkUpdateSpecifics( |
893 encrypted_bookmark); | 910 2, 1, kEncryptedString, 30, 30, false, pos2, encrypted_bookmark); |
894 // Item 3 doesn't change. | 911 // Item 3 doesn't change. |
895 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, | 912 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, |
896 encrypted_pref); | 913 encrypted_pref); |
897 SyncShareNudge(); | 914 SyncShareNudge(); |
898 { | 915 { |
899 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. | 916 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. |
900 // All should remain unapplied due to be undecryptable. | 917 // All should remain unapplied due to be undecryptable. |
901 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 918 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
902 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); | 919 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); |
903 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); | 920 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); |
904 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); | 921 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); |
905 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); | 922 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); |
906 } | 923 } |
907 | 924 |
908 // Positional changes, parent changes, and specifics changes should reset | 925 // Positional changes, parent changes, and specifics changes should reset |
909 // BASE_SERVER_SPECIFICS. | 926 // BASE_SERVER_SPECIFICS. |
910 // Became unencrypted. | 927 // Became unencrypted. |
911 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark); | 928 mock_server_->AddBookmarkUpdateSpecifics( |
| 929 1, 0, "A", 40, 40, true, 0, bookmark); |
912 // Reordered to after item 2. | 930 // Reordered to after item 2. |
913 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, | 931 mock_server_->AddBookmarkUpdateSpecifics( |
914 encrypted_bookmark); | 932 3, 1, kEncryptedString, 30, 30, false, 3, encrypted_bookmark); |
915 SyncShareNudge(); | 933 SyncShareNudge(); |
916 { | 934 { |
917 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. | 935 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. |
918 // Items 1 is now unencrypted, so should have applied normally. | 936 // Items 1 is now unencrypted, so should have applied normally. |
919 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 937 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
920 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); | 938 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); |
921 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); | 939 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); |
922 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); | 940 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); |
923 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); | 941 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); |
924 } | 942 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); | 1000 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); |
983 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); | 1001 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); |
984 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); | 1002 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); |
985 } | 1003 } |
986 | 1004 |
987 #undef VERIFY_ENTRY | 1005 #undef VERIFY_ENTRY |
988 | 1006 |
989 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { | 1007 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { |
990 { | 1008 { |
991 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1009 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
992 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 1010 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), |
993 "Pete"); | 1011 "Pete"); |
994 ASSERT_TRUE(parent.good()); | 1012 ASSERT_TRUE(parent.good()); |
995 parent.Put(syncable::IS_UNSYNCED, true); | 1013 parent.Put(syncable::IS_UNSYNCED, true); |
996 parent.Put(syncable::IS_DIR, true); | 1014 parent.Put(syncable::IS_DIR, true); |
997 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1015 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
998 parent.Put(syncable::BASE_VERSION, 1); | 1016 parent.Put(syncable::BASE_VERSION, 1); |
999 parent.Put(syncable::ID, parent_id_); | 1017 parent.Put(syncable::ID, parent_id_); |
1000 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); | 1018 MutableEntry child(&wtrans, syncable::CREATE_BOOKMARK, parent_id_, "Pete"); |
1001 ASSERT_TRUE(child.good()); | 1019 ASSERT_TRUE(child.good()); |
1002 child.Put(syncable::ID, child_id_); | 1020 child.Put(syncable::ID, child_id_); |
1003 child.Put(syncable::BASE_VERSION, 1); | 1021 child.Put(syncable::BASE_VERSION, 1); |
1004 WriteTestDataToEntry(&wtrans, &child); | 1022 WriteTestDataToEntry(&wtrans, &child); |
1005 } | 1023 } |
1006 | 1024 |
1007 SyncShareNudge(); | 1025 SyncShareNudge(); |
1008 ASSERT_EQ(2u, mock_server_->committed_ids().size()); | 1026 ASSERT_EQ(2u, mock_server_->committed_ids().size()); |
1009 // If this test starts failing, be aware other sort orders could be valid. | 1027 // If this test starts failing, be aware other sort orders could be valid. |
1010 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 1028 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); |
1011 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 1029 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); |
1012 { | 1030 { |
1013 syncable::ReadTransaction rt(FROM_HERE, directory()); | 1031 syncable::ReadTransaction rt(FROM_HERE, directory()); |
1014 Entry entry(&rt, syncable::GET_BY_ID, child_id_); | 1032 Entry entry(&rt, syncable::GET_BY_ID, child_id_); |
1015 ASSERT_TRUE(entry.good()); | 1033 ASSERT_TRUE(entry.good()); |
1016 VerifyTestDataInEntry(&rt, &entry); | 1034 VerifyTestDataInEntry(&rt, &entry); |
1017 } | 1035 } |
1018 } | 1036 } |
1019 | 1037 |
1020 TEST_F(SyncerTest, TestPurgeWhileUnsynced) { | 1038 TEST_F(SyncerTest, TestPurgeWhileUnsynced) { |
1021 // Similar to above, but throw a purge operation into the mix. Bug 49278. | 1039 // Similar to above, but throw a purge operation into the mix. Bug 49278. |
1022 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim"); | 1040 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim"); |
1023 { | 1041 { |
1024 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1042 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1025 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); | 1043 MutableEntry parent( |
| 1044 &wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), "Pete"); |
1026 ASSERT_TRUE(parent.good()); | 1045 ASSERT_TRUE(parent.good()); |
1027 parent.Put(syncable::IS_UNSYNCED, true); | 1046 parent.Put(syncable::IS_UNSYNCED, true); |
1028 parent.Put(syncable::IS_DIR, true); | 1047 parent.Put(syncable::IS_DIR, true); |
1029 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1048 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1030 parent.Put(syncable::BASE_VERSION, 1); | 1049 parent.Put(syncable::BASE_VERSION, 1); |
1031 parent.Put(syncable::ID, parent_id_); | 1050 parent.Put(syncable::ID, parent_id_); |
1032 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); | 1051 MutableEntry child(&wtrans, syncable::CREATE_BOOKMARK, parent_id_, "Pete"); |
1033 ASSERT_TRUE(child.good()); | 1052 ASSERT_TRUE(child.good()); |
1034 child.Put(syncable::ID, child_id_); | 1053 child.Put(syncable::ID, child_id_); |
1035 child.Put(syncable::BASE_VERSION, 1); | 1054 child.Put(syncable::BASE_VERSION, 1); |
1036 WriteTestDataToEntry(&wtrans, &child); | 1055 WriteTestDataToEntry(&wtrans, &child); |
1037 | 1056 |
1038 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim"); | 1057 MutableEntry parent2( |
| 1058 &wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), "Tim"); |
1039 ASSERT_TRUE(parent2.good()); | 1059 ASSERT_TRUE(parent2.good()); |
1040 parent2.Put(syncable::IS_UNSYNCED, true); | 1060 parent2.Put(syncable::IS_UNSYNCED, true); |
1041 parent2.Put(syncable::IS_DIR, true); | 1061 parent2.Put(syncable::IS_DIR, true); |
1042 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); | 1062 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); |
1043 parent2.Put(syncable::BASE_VERSION, 1); | 1063 parent2.Put(syncable::BASE_VERSION, 1); |
1044 parent2.Put(syncable::ID, pref_node_id); | 1064 parent2.Put(syncable::ID, pref_node_id); |
1045 } | 1065 } |
1046 | 1066 |
1047 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES)); | 1067 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES)); |
1048 | 1068 |
(...skipping 13 matching lines...) Expand all Loading... |
1062 syncable::ReadTransaction rt(FROM_HERE, directory()); | 1082 syncable::ReadTransaction rt(FROM_HERE, directory()); |
1063 Entry entry(&rt, syncable::GET_BY_ID, pref_node_id); | 1083 Entry entry(&rt, syncable::GET_BY_ID, pref_node_id); |
1064 ASSERT_FALSE(entry.good()); | 1084 ASSERT_FALSE(entry.good()); |
1065 } | 1085 } |
1066 } | 1086 } |
1067 | 1087 |
1068 TEST_F(SyncerTest, TestPurgeWhileUnapplied) { | 1088 TEST_F(SyncerTest, TestPurgeWhileUnapplied) { |
1069 // Similar to above, but for unapplied items. Bug 49278. | 1089 // Similar to above, but for unapplied items. Bug 49278. |
1070 { | 1090 { |
1071 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1091 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1072 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); | 1092 MutableEntry parent( |
| 1093 &wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), "Pete"); |
1073 ASSERT_TRUE(parent.good()); | 1094 ASSERT_TRUE(parent.good()); |
1074 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 1095 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
1075 parent.Put(syncable::IS_DIR, true); | 1096 parent.Put(syncable::IS_DIR, true); |
1076 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1097 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1077 parent.Put(syncable::BASE_VERSION, 1); | 1098 parent.Put(syncable::BASE_VERSION, 1); |
1078 parent.Put(syncable::ID, parent_id_); | 1099 parent.Put(syncable::ID, parent_id_); |
1079 } | 1100 } |
1080 | 1101 |
1081 directory()->PurgeEntriesWithTypeIn( | 1102 directory()->PurgeEntriesWithTypeIn( |
1082 ModelTypeSet(BOOKMARKS)); | 1103 ModelTypeSet(BOOKMARKS)); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 }; | 1238 }; |
1218 RunCommitOrderingTest(items); | 1239 RunCommitOrderingTest(items); |
1219 } | 1240 } |
1220 | 1241 |
1221 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { | 1242 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { |
1222 const base::Time& now_minus_2h = | 1243 const base::Time& now_minus_2h = |
1223 base::Time::Now() - base::TimeDelta::FromHours(2); | 1244 base::Time::Now() - base::TimeDelta::FromHours(2); |
1224 { | 1245 { |
1225 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1246 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1226 { | 1247 { |
1227 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 1248 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), |
1228 "Bob"); | 1249 "Bob"); |
1229 ASSERT_TRUE(parent.good()); | 1250 ASSERT_TRUE(parent.good()); |
1230 parent.Put(syncable::IS_UNSYNCED, true); | 1251 parent.Put(syncable::IS_UNSYNCED, true); |
1231 parent.Put(syncable::IS_DIR, true); | 1252 parent.Put(syncable::IS_DIR, true); |
1232 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1253 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1233 parent.Put(syncable::ID, ids_.FromNumber(100)); | 1254 parent.Put(syncable::ID, ids_.FromNumber(100)); |
1234 parent.Put(syncable::BASE_VERSION, 1); | 1255 parent.Put(syncable::BASE_VERSION, 1); |
1235 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(100), | 1256 MutableEntry child( |
1236 "Bob"); | 1257 &wtrans, syncable::CREATE_BOOKMARK, ids_.FromNumber(100), "Bob"); |
1237 ASSERT_TRUE(child.good()); | 1258 ASSERT_TRUE(child.good()); |
1238 child.Put(syncable::IS_UNSYNCED, true); | 1259 child.Put(syncable::IS_UNSYNCED, true); |
1239 child.Put(syncable::IS_DIR, true); | 1260 child.Put(syncable::IS_DIR, true); |
1240 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1261 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1241 child.Put(syncable::ID, ids_.FromNumber(101)); | 1262 child.Put(syncable::ID, ids_.FromNumber(101)); |
1242 child.Put(syncable::BASE_VERSION, 1); | 1263 child.Put(syncable::BASE_VERSION, 1); |
1243 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(101), | 1264 MutableEntry grandchild( |
1244 "Bob"); | 1265 &wtrans, syncable::CREATE_BOOKMARK, ids_.FromNumber(101), "Bob"); |
1245 ASSERT_TRUE(grandchild.good()); | 1266 ASSERT_TRUE(grandchild.good()); |
1246 grandchild.Put(syncable::ID, ids_.FromNumber(102)); | 1267 grandchild.Put(syncable::ID, ids_.FromNumber(102)); |
1247 grandchild.Put(syncable::IS_UNSYNCED, true); | 1268 grandchild.Put(syncable::IS_UNSYNCED, true); |
1248 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1269 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1249 grandchild.Put(syncable::BASE_VERSION, 1); | 1270 grandchild.Put(syncable::BASE_VERSION, 1); |
1250 } | 1271 } |
1251 { | 1272 { |
1252 // Create three deleted items which deletions we expect to be sent to the | 1273 // Create three deleted items which deletions we expect to be sent to the |
1253 // server. | 1274 // server. |
1254 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 1275 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), |
1255 "Pete"); | 1276 "Pete"); |
1256 ASSERT_TRUE(parent.good()); | 1277 ASSERT_TRUE(parent.good()); |
1257 parent.Put(syncable::ID, ids_.FromNumber(103)); | 1278 parent.Put(syncable::ID, ids_.FromNumber(103)); |
1258 parent.Put(syncable::IS_UNSYNCED, true); | 1279 parent.Put(syncable::IS_UNSYNCED, true); |
1259 parent.Put(syncable::IS_DIR, true); | 1280 parent.Put(syncable::IS_DIR, true); |
1260 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1281 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1261 parent.Put(syncable::IS_DEL, true); | 1282 parent.Put(syncable::IS_DEL, true); |
1262 parent.Put(syncable::BASE_VERSION, 1); | 1283 parent.Put(syncable::BASE_VERSION, 1); |
1263 parent.Put(syncable::MTIME, now_minus_2h); | 1284 parent.Put(syncable::MTIME, now_minus_2h); |
1264 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(103), | 1285 MutableEntry child( |
1265 "Pete"); | 1286 &wtrans, syncable::CREATE_BOOKMARK, ids_.FromNumber(103), "Pete"); |
1266 ASSERT_TRUE(child.good()); | 1287 ASSERT_TRUE(child.good()); |
1267 child.Put(syncable::ID, ids_.FromNumber(104)); | 1288 child.Put(syncable::ID, ids_.FromNumber(104)); |
1268 child.Put(syncable::IS_UNSYNCED, true); | 1289 child.Put(syncable::IS_UNSYNCED, true); |
1269 child.Put(syncable::IS_DIR, true); | 1290 child.Put(syncable::IS_DIR, true); |
1270 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1291 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1271 child.Put(syncable::IS_DEL, true); | 1292 child.Put(syncable::IS_DEL, true); |
1272 child.Put(syncable::BASE_VERSION, 1); | 1293 child.Put(syncable::BASE_VERSION, 1); |
1273 child.Put(syncable::MTIME, now_minus_2h); | 1294 child.Put(syncable::MTIME, now_minus_2h); |
1274 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(104), | 1295 MutableEntry grandchild( |
1275 "Pete"); | 1296 &wtrans, syncable::CREATE_BOOKMARK, ids_.FromNumber(104), "Pete"); |
1276 ASSERT_TRUE(grandchild.good()); | 1297 ASSERT_TRUE(grandchild.good()); |
1277 grandchild.Put(syncable::ID, ids_.FromNumber(105)); | 1298 grandchild.Put(syncable::ID, ids_.FromNumber(105)); |
1278 grandchild.Put(syncable::IS_UNSYNCED, true); | 1299 grandchild.Put(syncable::IS_UNSYNCED, true); |
1279 grandchild.Put(syncable::IS_DEL, true); | 1300 grandchild.Put(syncable::IS_DEL, true); |
1280 grandchild.Put(syncable::IS_DIR, false); | 1301 grandchild.Put(syncable::IS_DIR, false); |
1281 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1302 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1282 grandchild.Put(syncable::BASE_VERSION, 1); | 1303 grandchild.Put(syncable::BASE_VERSION, 1); |
1283 grandchild.Put(syncable::MTIME, now_minus_2h); | 1304 grandchild.Put(syncable::MTIME, now_minus_2h); |
1284 } | 1305 } |
1285 } | 1306 } |
1286 | 1307 |
1287 SyncShareNudge(); | 1308 SyncShareNudge(); |
1288 ASSERT_EQ(6u, mock_server_->committed_ids().size()); | 1309 ASSERT_EQ(6u, mock_server_->committed_ids().size()); |
1289 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set. | 1310 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set. |
1290 // It will treat these like moves. | 1311 // It will treat these like moves. |
1291 vector<syncable::Id> commit_ids(mock_server_->committed_ids()); | 1312 vector<syncable::Id> commit_ids(mock_server_->committed_ids()); |
1292 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]); | 1313 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]); |
1293 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]); | 1314 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]); |
1294 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]); | 1315 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]); |
1295 // We don't guarantee the delete orders in this test, only that they occur | 1316 // We don't guarantee the delete orders in this test, only that they occur |
1296 // at the end. | 1317 // at the end. |
1297 std::sort(commit_ids.begin() + 3, commit_ids.end()); | 1318 std::sort(commit_ids.begin() + 3, commit_ids.end()); |
1298 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]); | 1319 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]); |
1299 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]); | 1320 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]); |
1300 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]); | 1321 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]); |
1301 } | 1322 } |
1302 | 1323 |
1303 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { | 1324 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { |
| 1325 syncable::Id parent1_id = ids_.MakeServer("p1"); |
| 1326 syncable::Id parent2_id = ids_.MakeServer("p2"); |
| 1327 |
1304 { | 1328 { |
1305 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1329 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1306 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "1"); | 1330 MutableEntry parent( |
| 1331 &wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), "1"); |
1307 ASSERT_TRUE(parent.good()); | 1332 ASSERT_TRUE(parent.good()); |
1308 parent.Put(syncable::IS_UNSYNCED, true); | 1333 parent.Put(syncable::IS_UNSYNCED, true); |
1309 parent.Put(syncable::IS_DIR, true); | 1334 parent.Put(syncable::IS_DIR, true); |
1310 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1335 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1311 parent.Put(syncable::ID, parent_id_); | 1336 parent.Put(syncable::ID, parent1_id); |
1312 MutableEntry child(&wtrans, syncable::CREATE, wtrans.root_id(), "2"); | 1337 MutableEntry child( |
| 1338 &wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), "2"); |
1313 ASSERT_TRUE(child.good()); | 1339 ASSERT_TRUE(child.good()); |
1314 child.Put(syncable::IS_UNSYNCED, true); | 1340 child.Put(syncable::IS_UNSYNCED, true); |
1315 child.Put(syncable::IS_DIR, true); | 1341 child.Put(syncable::IS_DIR, true); |
1316 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1342 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1317 child.Put(syncable::ID, child_id_); | 1343 child.Put(syncable::ID, parent2_id); |
1318 parent.Put(syncable::BASE_VERSION, 1); | 1344 parent.Put(syncable::BASE_VERSION, 1); |
1319 child.Put(syncable::BASE_VERSION, 1); | 1345 child.Put(syncable::BASE_VERSION, 1); |
1320 } | 1346 } |
1321 { | 1347 { |
1322 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1348 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1323 MutableEntry parent(&wtrans, syncable::CREATE, parent_id_, "A"); | 1349 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, parent1_id, "A"); |
1324 ASSERT_TRUE(parent.good()); | 1350 ASSERT_TRUE(parent.good()); |
1325 parent.Put(syncable::IS_UNSYNCED, true); | 1351 parent.Put(syncable::IS_UNSYNCED, true); |
1326 parent.Put(syncable::IS_DIR, true); | 1352 parent.Put(syncable::IS_DIR, true); |
1327 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1353 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1328 parent.Put(syncable::ID, ids_.FromNumber(102)); | 1354 parent.Put(syncable::ID, ids_.FromNumber(102)); |
1329 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "B"); | 1355 MutableEntry child(&wtrans, syncable::CREATE_BOOKMARK, parent1_id, "B"); |
1330 ASSERT_TRUE(child.good()); | 1356 ASSERT_TRUE(child.good()); |
1331 child.Put(syncable::IS_UNSYNCED, true); | 1357 child.Put(syncable::IS_UNSYNCED, true); |
1332 child.Put(syncable::IS_DIR, true); | 1358 child.Put(syncable::IS_DIR, true); |
1333 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1359 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1334 child.Put(syncable::ID, ids_.FromNumber(-103)); | 1360 child.Put(syncable::ID, ids_.FromNumber(-103)); |
1335 parent.Put(syncable::BASE_VERSION, 1); | 1361 parent.Put(syncable::BASE_VERSION, 1); |
1336 } | 1362 } |
1337 { | 1363 { |
1338 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1364 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1339 MutableEntry parent(&wtrans, syncable::CREATE, child_id_, "A"); | 1365 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, parent2_id, "A"); |
1340 ASSERT_TRUE(parent.good()); | 1366 ASSERT_TRUE(parent.good()); |
1341 parent.Put(syncable::IS_UNSYNCED, true); | 1367 parent.Put(syncable::IS_UNSYNCED, true); |
1342 parent.Put(syncable::IS_DIR, true); | 1368 parent.Put(syncable::IS_DIR, true); |
1343 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1369 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1344 parent.Put(syncable::ID, ids_.FromNumber(-104)); | 1370 parent.Put(syncable::ID, ids_.FromNumber(-104)); |
1345 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B"); | 1371 MutableEntry child(&wtrans, syncable::CREATE_BOOKMARK, parent2_id, "B"); |
1346 ASSERT_TRUE(child.good()); | 1372 ASSERT_TRUE(child.good()); |
1347 child.Put(syncable::IS_UNSYNCED, true); | 1373 child.Put(syncable::IS_UNSYNCED, true); |
1348 child.Put(syncable::IS_DIR, true); | 1374 child.Put(syncable::IS_DIR, true); |
1349 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1375 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1350 child.Put(syncable::ID, ids_.FromNumber(105)); | 1376 child.Put(syncable::ID, ids_.FromNumber(105)); |
1351 child.Put(syncable::BASE_VERSION, 1); | 1377 child.Put(syncable::BASE_VERSION, 1); |
1352 } | 1378 } |
1353 | 1379 |
1354 SyncShareNudge(); | 1380 SyncShareNudge(); |
1355 ASSERT_EQ(6u, mock_server_->committed_ids().size()); | 1381 ASSERT_EQ(6u, mock_server_->committed_ids().size()); |
1356 // If this test starts failing, be aware other sort orders could be valid. | 1382 |
1357 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 1383 // This strange iteration and std::count() usage is to allow the order to |
1358 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 1384 // vary. All we really care about is that parent1_id and parent2_id are the |
1359 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); | 1385 // first two IDs, and that the children make up the next four. Other than |
1360 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); | 1386 // that, ordering doesn't matter. |
1361 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); | 1387 |
1362 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); | 1388 vector<syncable::Id>::const_iterator i = |
| 1389 mock_server_->committed_ids().begin(); |
| 1390 vector<syncable::Id>::const_iterator parents_begin = i; |
| 1391 i++; |
| 1392 i++; |
| 1393 vector<syncable::Id>::const_iterator parents_end = i; |
| 1394 vector<syncable::Id>::const_iterator children_begin = i; |
| 1395 vector<syncable::Id>::const_iterator children_end = |
| 1396 mock_server_->committed_ids().end(); |
| 1397 |
| 1398 EXPECT_EQ(1, count(parents_begin, parents_end, parent1_id)); |
| 1399 EXPECT_EQ(1, count(parents_begin, parents_end, parent2_id)); |
| 1400 |
| 1401 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(-103))); |
| 1402 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(102))); |
| 1403 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(105))); |
| 1404 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(-104))); |
1363 } | 1405 } |
1364 | 1406 |
1365 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { | 1407 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { |
1366 syncable::Id child2_id = ids_.NewServerId(); | 1408 syncable::Id child2_id = ids_.NewServerId(); |
1367 | 1409 |
1368 { | 1410 { |
1369 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1411 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1370 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "P"); | 1412 MutableEntry parent( |
| 1413 &wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), "P"); |
1371 ASSERT_TRUE(parent.good()); | 1414 ASSERT_TRUE(parent.good()); |
1372 parent.Put(syncable::IS_UNSYNCED, true); | 1415 parent.Put(syncable::IS_UNSYNCED, true); |
1373 parent.Put(syncable::IS_DIR, true); | 1416 parent.Put(syncable::IS_DIR, true); |
1374 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1417 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1375 parent.Put(syncable::ID, parent_id_); | 1418 parent.Put(syncable::ID, parent_id_); |
1376 MutableEntry child1(&wtrans, syncable::CREATE, parent_id_, "1"); | 1419 MutableEntry child1(&wtrans, syncable::CREATE_BOOKMARK, parent_id_, "1"); |
1377 ASSERT_TRUE(child1.good()); | 1420 ASSERT_TRUE(child1.good()); |
1378 child1.Put(syncable::IS_UNSYNCED, true); | 1421 child1.Put(syncable::IS_UNSYNCED, true); |
1379 child1.Put(syncable::ID, child_id_); | 1422 child1.Put(syncable::ID, child_id_); |
1380 child1.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1423 child1.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1381 MutableEntry child2(&wtrans, syncable::CREATE, parent_id_, "2"); | 1424 MutableEntry child2(&wtrans, syncable::CREATE_BOOKMARK, parent_id_, "2"); |
1382 ASSERT_TRUE(child2.good()); | 1425 ASSERT_TRUE(child2.good()); |
1383 child2.Put(syncable::IS_UNSYNCED, true); | 1426 child2.Put(syncable::IS_UNSYNCED, true); |
1384 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1427 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1385 child2.Put(syncable::ID, child2_id); | 1428 child2.Put(syncable::ID, child2_id); |
1386 | 1429 |
1387 parent.Put(syncable::BASE_VERSION, 1); | 1430 parent.Put(syncable::BASE_VERSION, 1); |
1388 child1.Put(syncable::BASE_VERSION, 1); | 1431 child1.Put(syncable::BASE_VERSION, 1); |
1389 child2.Put(syncable::BASE_VERSION, 1); | 1432 child2.Put(syncable::BASE_VERSION, 1); |
1390 } | 1433 } |
1391 | 1434 |
1392 SyncShareNudge(); | 1435 SyncShareNudge(); |
1393 ASSERT_EQ(3u, mock_server_->committed_ids().size()); | 1436 ASSERT_EQ(3u, mock_server_->committed_ids().size()); |
1394 // If this test starts failing, be aware other sort orders could be valid. | |
1395 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 1437 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); |
1396 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 1438 // There are two possible valid orderings. |
1397 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); | 1439 if (child2_id == mock_server_->committed_ids()[1]) { |
| 1440 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[1]); |
| 1441 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[2]); |
| 1442 } else { |
| 1443 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); |
| 1444 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); |
| 1445 } |
1398 } | 1446 } |
1399 | 1447 |
1400 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { | 1448 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { |
1401 string parent1_name = "1"; | 1449 string parent1_name = "1"; |
1402 string parent2_name = "A"; | 1450 string parent2_name = "A"; |
1403 string child_name = "B"; | 1451 string child_name = "B"; |
1404 | 1452 |
1405 { | 1453 { |
1406 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1454 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1407 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 1455 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), |
1408 parent1_name); | 1456 parent1_name); |
1409 ASSERT_TRUE(parent.good()); | 1457 ASSERT_TRUE(parent.good()); |
1410 parent.Put(syncable::IS_UNSYNCED, true); | 1458 parent.Put(syncable::IS_UNSYNCED, true); |
1411 parent.Put(syncable::IS_DIR, true); | 1459 parent.Put(syncable::IS_DIR, true); |
1412 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1460 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1413 parent.Put(syncable::ID, parent_id_); | 1461 parent.Put(syncable::ID, parent_id_); |
1414 parent.Put(syncable::BASE_VERSION, 1); | 1462 parent.Put(syncable::BASE_VERSION, 1); |
1415 } | 1463 } |
1416 | 1464 |
1417 syncable::Id parent2_id = ids_.NewLocalId(); | 1465 syncable::Id parent2_id = ids_.NewLocalId(); |
1418 syncable::Id child_id = ids_.NewServerId(); | 1466 syncable::Id child_id = ids_.NewServerId(); |
1419 { | 1467 { |
1420 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1468 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1421 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); | 1469 MutableEntry parent2( |
| 1470 &wtrans, syncable::CREATE_BOOKMARK, parent_id_, parent2_name); |
1422 ASSERT_TRUE(parent2.good()); | 1471 ASSERT_TRUE(parent2.good()); |
1423 parent2.Put(syncable::IS_UNSYNCED, true); | 1472 parent2.Put(syncable::IS_UNSYNCED, true); |
1424 parent2.Put(syncable::IS_DIR, true); | 1473 parent2.Put(syncable::IS_DIR, true); |
1425 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1474 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1426 parent2.Put(syncable::ID, parent2_id); | 1475 parent2.Put(syncable::ID, parent2_id); |
1427 | 1476 |
1428 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name); | 1477 MutableEntry child( |
| 1478 &wtrans, syncable::CREATE_BOOKMARK, parent2_id, child_name); |
1429 ASSERT_TRUE(child.good()); | 1479 ASSERT_TRUE(child.good()); |
1430 child.Put(syncable::IS_UNSYNCED, true); | 1480 child.Put(syncable::IS_UNSYNCED, true); |
1431 child.Put(syncable::IS_DIR, true); | 1481 child.Put(syncable::IS_DIR, true); |
1432 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1482 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1433 child.Put(syncable::ID, child_id); | 1483 child.Put(syncable::ID, child_id); |
1434 child.Put(syncable::BASE_VERSION, 1); | 1484 child.Put(syncable::BASE_VERSION, 1); |
1435 } | 1485 } |
1436 | 1486 |
1437 SyncShareNudge(); | 1487 SyncShareNudge(); |
1438 ASSERT_EQ(3u, mock_server_->committed_ids().size()); | 1488 ASSERT_EQ(3u, mock_server_->committed_ids().size()); |
(...skipping 26 matching lines...) Expand all Loading... |
1465 } | 1515 } |
1466 | 1516 |
1467 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { | 1517 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { |
1468 string parent_name = "1"; | 1518 string parent_name = "1"; |
1469 string parent2_name = "A"; | 1519 string parent2_name = "A"; |
1470 string child_name = "B"; | 1520 string child_name = "B"; |
1471 | 1521 |
1472 { | 1522 { |
1473 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1523 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1474 MutableEntry parent(&wtrans, | 1524 MutableEntry parent(&wtrans, |
1475 syncable::CREATE, | 1525 syncable::CREATE_BOOKMARK, |
1476 wtrans.root_id(), | 1526 wtrans.root_id(), |
1477 parent_name); | 1527 parent_name); |
1478 ASSERT_TRUE(parent.good()); | 1528 ASSERT_TRUE(parent.good()); |
1479 parent.Put(syncable::IS_UNSYNCED, true); | 1529 parent.Put(syncable::IS_UNSYNCED, true); |
1480 parent.Put(syncable::IS_DIR, true); | 1530 parent.Put(syncable::IS_DIR, true); |
1481 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1531 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1482 parent.Put(syncable::ID, parent_id_); | 1532 parent.Put(syncable::ID, parent_id_); |
1483 parent.Put(syncable::BASE_VERSION, 1); | 1533 parent.Put(syncable::BASE_VERSION, 1); |
1484 } | 1534 } |
1485 | 1535 |
1486 int64 meta_handle_b; | 1536 int64 meta_handle_b; |
1487 const Id parent2_local_id = ids_.NewLocalId(); | 1537 const Id parent2_local_id = ids_.NewLocalId(); |
1488 const Id child_local_id = ids_.NewLocalId(); | 1538 const Id child_local_id = ids_.NewLocalId(); |
1489 { | 1539 { |
1490 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1540 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1491 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); | 1541 MutableEntry parent2( |
| 1542 &wtrans, syncable::CREATE_BOOKMARK, parent_id_, parent2_name); |
1492 ASSERT_TRUE(parent2.good()); | 1543 ASSERT_TRUE(parent2.good()); |
1493 parent2.Put(syncable::IS_UNSYNCED, true); | 1544 parent2.Put(syncable::IS_UNSYNCED, true); |
1494 parent2.Put(syncable::IS_DIR, true); | 1545 parent2.Put(syncable::IS_DIR, true); |
1495 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1546 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1496 | 1547 |
1497 parent2.Put(syncable::ID, parent2_local_id); | 1548 parent2.Put(syncable::ID, parent2_local_id); |
1498 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name); | 1549 MutableEntry child( |
| 1550 &wtrans, syncable::CREATE_BOOKMARK, parent2_local_id, child_name); |
1499 ASSERT_TRUE(child.good()); | 1551 ASSERT_TRUE(child.good()); |
1500 child.Put(syncable::IS_UNSYNCED, true); | 1552 child.Put(syncable::IS_UNSYNCED, true); |
1501 child.Put(syncable::IS_DIR, true); | 1553 child.Put(syncable::IS_DIR, true); |
1502 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1554 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1503 child.Put(syncable::ID, child_local_id); | 1555 child.Put(syncable::ID, child_local_id); |
1504 meta_handle_b = child.Get(syncable::META_HANDLE); | 1556 meta_handle_b = child.Get(syncable::META_HANDLE); |
1505 } | 1557 } |
1506 | 1558 |
1507 SyncShareNudge(); | 1559 SyncShareNudge(); |
1508 ASSERT_EQ(3u, mock_server_->committed_ids().size()); | 1560 ASSERT_EQ(3u, mock_server_->committed_ids().size()); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 EXPECT_EQ(4, status().num_hierarchy_conflicts()); | 1758 EXPECT_EQ(4, status().num_hierarchy_conflicts()); |
1707 } | 1759 } |
1708 | 1760 |
1709 TEST_F(SyncerTest, CommitTimeRename) { | 1761 TEST_F(SyncerTest, CommitTimeRename) { |
1710 int64 metahandle_folder; | 1762 int64 metahandle_folder; |
1711 int64 metahandle_new_entry; | 1763 int64 metahandle_new_entry; |
1712 | 1764 |
1713 // Create a folder and an entry. | 1765 // Create a folder and an entry. |
1714 { | 1766 { |
1715 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1767 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1716 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); | 1768 MutableEntry parent(&trans, CREATE_BOOKMARK, root_id_, "Folder"); |
1717 ASSERT_TRUE(parent.good()); | 1769 ASSERT_TRUE(parent.good()); |
1718 parent.Put(IS_DIR, true); | 1770 parent.Put(IS_DIR, true); |
1719 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1771 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1720 parent.Put(IS_UNSYNCED, true); | 1772 parent.Put(IS_UNSYNCED, true); |
1721 metahandle_folder = parent.Get(META_HANDLE); | 1773 metahandle_folder = parent.Get(META_HANDLE); |
1722 | 1774 |
1723 MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry"); | 1775 MutableEntry entry(&trans, CREATE_BOOKMARK, parent.Get(ID), "new_entry"); |
1724 ASSERT_TRUE(entry.good()); | 1776 ASSERT_TRUE(entry.good()); |
1725 metahandle_new_entry = entry.Get(META_HANDLE); | 1777 metahandle_new_entry = entry.Get(META_HANDLE); |
1726 WriteTestDataToEntry(&trans, &entry); | 1778 WriteTestDataToEntry(&trans, &entry); |
1727 } | 1779 } |
1728 | 1780 |
1729 // Mix in a directory creation too for later. | 1781 // Mix in a directory creation too for later. |
1730 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10); | 1782 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10); |
1731 mock_server_->SetCommitTimeRename("renamed_"); | 1783 mock_server_->SetCommitTimeRename("renamed_"); |
1732 SyncShareNudge(); | 1784 SyncShareNudge(); |
1733 | 1785 |
(...skipping 20 matching lines...) Expand all Loading... |
1754 TEST_F(SyncerTest, CommitTimeRenameI18N) { | 1806 TEST_F(SyncerTest, CommitTimeRenameI18N) { |
1755 // This is utf-8 for the diacritized Internationalization. | 1807 // This is utf-8 for the diacritized Internationalization. |
1756 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1" | 1808 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1" |
1757 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae" | 1809 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae" |
1758 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1"; | 1810 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1"; |
1759 | 1811 |
1760 int64 metahandle; | 1812 int64 metahandle; |
1761 // Create a folder, expect a commit time rename. | 1813 // Create a folder, expect a commit time rename. |
1762 { | 1814 { |
1763 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1815 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1764 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); | 1816 MutableEntry parent(&trans, CREATE_BOOKMARK, root_id_, "Folder"); |
1765 ASSERT_TRUE(parent.good()); | 1817 ASSERT_TRUE(parent.good()); |
1766 parent.Put(IS_DIR, true); | 1818 parent.Put(IS_DIR, true); |
1767 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 1819 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
1768 parent.Put(IS_UNSYNCED, true); | 1820 parent.Put(IS_UNSYNCED, true); |
1769 metahandle = parent.Get(META_HANDLE); | 1821 metahandle = parent.Get(META_HANDLE); |
1770 } | 1822 } |
1771 | 1823 |
1772 mock_server_->SetCommitTimeRename(i18nString); | 1824 mock_server_->SetCommitTimeRename(i18nString); |
1773 SyncShareNudge(); | 1825 SyncShareNudge(); |
1774 | 1826 |
(...skipping 10 matching lines...) Expand all Loading... |
1785 } | 1837 } |
1786 } | 1838 } |
1787 | 1839 |
1788 // A commit with a lost response produces an update that has to be reunited with | 1840 // A commit with a lost response produces an update that has to be reunited with |
1789 // its parent. | 1841 // its parent. |
1790 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { | 1842 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { |
1791 // Create a folder in the root. | 1843 // Create a folder in the root. |
1792 int64 metahandle_folder; | 1844 int64 metahandle_folder; |
1793 { | 1845 { |
1794 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1846 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1795 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_folder"); | 1847 MutableEntry entry(&trans, CREATE_BOOKMARK, trans.root_id(), "new_folder"); |
1796 ASSERT_TRUE(entry.good()); | 1848 ASSERT_TRUE(entry.good()); |
1797 entry.Put(IS_DIR, true); | 1849 entry.Put(IS_DIR, true); |
1798 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 1850 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
1799 entry.Put(IS_UNSYNCED, true); | 1851 entry.Put(IS_UNSYNCED, true); |
1800 metahandle_folder = entry.Get(META_HANDLE); | 1852 metahandle_folder = entry.Get(META_HANDLE); |
1801 } | 1853 } |
1802 | 1854 |
1803 // Verify it and pull the ID out of the folder. | 1855 // Verify it and pull the ID out of the folder. |
1804 syncable::Id folder_id; | 1856 syncable::Id folder_id; |
1805 int64 metahandle_entry; | 1857 int64 metahandle_entry; |
1806 { | 1858 { |
1807 syncable::ReadTransaction trans(FROM_HERE, directory()); | 1859 syncable::ReadTransaction trans(FROM_HERE, directory()); |
1808 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder); | 1860 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder); |
1809 ASSERT_TRUE(entry.good()); | 1861 ASSERT_TRUE(entry.good()); |
1810 folder_id = entry.Get(ID); | 1862 folder_id = entry.Get(ID); |
1811 ASSERT_TRUE(!folder_id.ServerKnows()); | 1863 ASSERT_TRUE(!folder_id.ServerKnows()); |
1812 } | 1864 } |
1813 | 1865 |
1814 // Create an entry in the newly created folder. | 1866 // Create an entry in the newly created folder. |
1815 { | 1867 { |
1816 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1868 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1817 MutableEntry entry(&trans, CREATE, folder_id, "new_entry"); | 1869 MutableEntry entry(&trans, CREATE_BOOKMARK, folder_id, "new_entry"); |
1818 ASSERT_TRUE(entry.good()); | 1870 ASSERT_TRUE(entry.good()); |
1819 metahandle_entry = entry.Get(META_HANDLE); | 1871 metahandle_entry = entry.Get(META_HANDLE); |
1820 WriteTestDataToEntry(&trans, &entry); | 1872 WriteTestDataToEntry(&trans, &entry); |
1821 } | 1873 } |
1822 | 1874 |
1823 // Verify it and pull the ID out of the entry. | 1875 // Verify it and pull the ID out of the entry. |
1824 syncable::Id entry_id; | 1876 syncable::Id entry_id; |
1825 { | 1877 { |
1826 syncable::ReadTransaction trans(FROM_HERE, directory()); | 1878 syncable::ReadTransaction trans(FROM_HERE, directory()); |
1827 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); | 1879 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 } | 1928 } |
1877 } | 1929 } |
1878 | 1930 |
1879 // A commit with a lost response produces an update that has to be reunited with | 1931 // A commit with a lost response produces an update that has to be reunited with |
1880 // its parent. | 1932 // its parent. |
1881 TEST_F(SyncerTest, CommitReuniteUpdate) { | 1933 TEST_F(SyncerTest, CommitReuniteUpdate) { |
1882 // Create an entry in the root. | 1934 // Create an entry in the root. |
1883 int64 entry_metahandle; | 1935 int64 entry_metahandle; |
1884 { | 1936 { |
1885 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1937 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1886 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); | 1938 MutableEntry entry(&trans, CREATE_BOOKMARK, trans.root_id(), "new_entry"); |
1887 ASSERT_TRUE(entry.good()); | 1939 ASSERT_TRUE(entry.good()); |
1888 entry_metahandle = entry.Get(META_HANDLE); | 1940 entry_metahandle = entry.Get(META_HANDLE); |
1889 WriteTestDataToEntry(&trans, &entry); | 1941 WriteTestDataToEntry(&trans, &entry); |
1890 } | 1942 } |
1891 | 1943 |
1892 // Verify it and pull the ID out. | 1944 // Verify it and pull the ID out. |
1893 syncable::Id entry_id; | 1945 syncable::Id entry_id; |
1894 { | 1946 { |
1895 syncable::ReadTransaction trans(FROM_HERE, directory()); | 1947 syncable::ReadTransaction trans(FROM_HERE, directory()); |
1896 | 1948 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1930 // A commit with a lost response must work even if the local entry was deleted | 1982 // A commit with a lost response must work even if the local entry was deleted |
1931 // before the update is applied. We should not duplicate the local entry in | 1983 // before the update is applied. We should not duplicate the local entry in |
1932 // this case, but just create another one alongside. We may wish to examine | 1984 // this case, but just create another one alongside. We may wish to examine |
1933 // this behavior in the future as it can create hanging uploads that never | 1985 // this behavior in the future as it can create hanging uploads that never |
1934 // finish, that must be cleaned up on the server side after some time. | 1986 // finish, that must be cleaned up on the server side after some time. |
1935 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { | 1987 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { |
1936 // Create a entry in the root. | 1988 // Create a entry in the root. |
1937 int64 entry_metahandle; | 1989 int64 entry_metahandle; |
1938 { | 1990 { |
1939 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1991 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1940 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); | 1992 MutableEntry entry(&trans, CREATE_BOOKMARK, trans.root_id(), "new_entry"); |
1941 ASSERT_TRUE(entry.good()); | 1993 ASSERT_TRUE(entry.good()); |
1942 entry_metahandle = entry.Get(META_HANDLE); | 1994 entry_metahandle = entry.Get(META_HANDLE); |
1943 WriteTestDataToEntry(&trans, &entry); | 1995 WriteTestDataToEntry(&trans, &entry); |
1944 } | 1996 } |
1945 // Verify it and pull the ID out. | 1997 // Verify it and pull the ID out. |
1946 syncable::Id entry_id; | 1998 syncable::Id entry_id; |
1947 { | 1999 { |
1948 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2000 syncable::ReadTransaction trans(FROM_HERE, directory()); |
1949 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); | 2001 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); |
1950 ASSERT_TRUE(entry.good()); | 2002 ASSERT_TRUE(entry.good()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2094 public: | 2146 public: |
2095 void CreateFolderInBob() { | 2147 void CreateFolderInBob() { |
2096 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2148 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2097 MutableEntry bob(&trans, | 2149 MutableEntry bob(&trans, |
2098 syncable::GET_BY_ID, | 2150 syncable::GET_BY_ID, |
2099 GetOnlyEntryWithName(&trans, | 2151 GetOnlyEntryWithName(&trans, |
2100 TestIdFactory::root(), | 2152 TestIdFactory::root(), |
2101 "bob")); | 2153 "bob")); |
2102 CHECK(bob.good()); | 2154 CHECK(bob.good()); |
2103 | 2155 |
2104 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), | 2156 MutableEntry entry2( |
2105 "bob"); | 2157 &trans, syncable::CREATE_BOOKMARK, bob.Get(syncable::ID), "bob"); |
2106 CHECK(entry2.good()); | 2158 CHECK(entry2.good()); |
2107 entry2.Put(syncable::IS_DIR, true); | 2159 entry2.Put(syncable::IS_DIR, true); |
2108 entry2.Put(syncable::IS_UNSYNCED, true); | 2160 entry2.Put(syncable::IS_UNSYNCED, true); |
2109 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 2161 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
2110 } | 2162 } |
2111 }; | 2163 }; |
2112 | 2164 |
2113 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { | 2165 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { |
2114 { | 2166 { |
2115 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2167 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2116 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), | 2168 MutableEntry entry(&trans, syncable::CREATE_BOOKMARK, trans.root_id(), |
2117 "bob"); | 2169 "bob"); |
2118 ASSERT_TRUE(entry.good()); | 2170 ASSERT_TRUE(entry.good()); |
2119 entry.Put(syncable::IS_DIR, true); | 2171 entry.Put(syncable::IS_DIR, true); |
2120 entry.Put(syncable::IS_UNSYNCED, true); | 2172 entry.Put(syncable::IS_UNSYNCED, true); |
2121 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 2173 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
2122 } | 2174 } |
2123 | 2175 |
2124 mock_server_->SetMidCommitCallback( | 2176 mock_server_->SetMidCommitCallback( |
2125 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, | 2177 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, |
2126 base::Unretained(this))); | 2178 base::Unretained(this))); |
(...skipping 18 matching lines...) Expand all Loading... |
2145 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); | 2197 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); |
2146 SyncShareNudge(); | 2198 SyncShareNudge(); |
2147 // The negative id would make us CHECK! | 2199 // The negative id would make us CHECK! |
2148 } | 2200 } |
2149 | 2201 |
2150 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { | 2202 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { |
2151 int64 metahandle_fred; | 2203 int64 metahandle_fred; |
2152 { | 2204 { |
2153 // Create an item. | 2205 // Create an item. |
2154 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2206 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2155 MutableEntry fred_match(&trans, CREATE, trans.root_id(), | 2207 MutableEntry fred_match(&trans, CREATE_BOOKMARK, trans.root_id(), |
2156 "fred_match"); | 2208 "fred_match"); |
2157 ASSERT_TRUE(fred_match.good()); | 2209 ASSERT_TRUE(fred_match.good()); |
2158 metahandle_fred = fred_match.Get(META_HANDLE); | 2210 metahandle_fred = fred_match.Get(META_HANDLE); |
2159 WriteTestDataToEntry(&trans, &fred_match); | 2211 WriteTestDataToEntry(&trans, &fred_match); |
2160 } | 2212 } |
2161 // Commit it. | 2213 // Commit it. |
2162 SyncShareNudge(); | 2214 SyncShareNudge(); |
2163 EXPECT_EQ(1u, mock_server_->committed_ids().size()); | 2215 EXPECT_EQ(1u, mock_server_->committed_ids().size()); |
2164 mock_server_->set_conflict_all_commits(true); | 2216 mock_server_->set_conflict_all_commits(true); |
2165 syncable::Id fred_match_id; | 2217 syncable::Id fred_match_id; |
(...skipping 15 matching lines...) Expand all Loading... |
2181 | 2233 |
2182 /** | 2234 /** |
2183 * In the event that we have a double changed entry, that is changed on both | 2235 * In the event that we have a double changed entry, that is changed on both |
2184 * the client and the server, the conflict resolver should just drop one of | 2236 * the client and the server, the conflict resolver should just drop one of |
2185 * them and accept the other. | 2237 * them and accept the other. |
2186 */ | 2238 */ |
2187 | 2239 |
2188 TEST_F(SyncerTest, DoublyChangedWithResolver) { | 2240 TEST_F(SyncerTest, DoublyChangedWithResolver) { |
2189 { | 2241 { |
2190 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2242 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2191 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "Folder"); | 2243 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, root_id_, "Folder"); |
2192 ASSERT_TRUE(parent.good()); | 2244 ASSERT_TRUE(parent.good()); |
2193 parent.Put(syncable::IS_DIR, true); | 2245 parent.Put(syncable::IS_DIR, true); |
2194 parent.Put(syncable::ID, parent_id_); | 2246 parent.Put(syncable::ID, parent_id_); |
2195 parent.Put(syncable::BASE_VERSION, 5); | 2247 parent.Put(syncable::BASE_VERSION, 5); |
2196 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 2248 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
2197 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm"); | 2249 MutableEntry child( |
| 2250 &wtrans, syncable::CREATE_BOOKMARK, parent_id_, "Pete.htm"); |
2198 ASSERT_TRUE(child.good()); | 2251 ASSERT_TRUE(child.good()); |
2199 child.Put(syncable::ID, child_id_); | 2252 child.Put(syncable::ID, child_id_); |
2200 child.Put(syncable::BASE_VERSION, 10); | 2253 child.Put(syncable::BASE_VERSION, 10); |
2201 WriteTestDataToEntry(&wtrans, &child); | 2254 WriteTestDataToEntry(&wtrans, &child); |
2202 } | 2255 } |
2203 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10); | 2256 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10); |
2204 mock_server_->set_conflict_all_commits(true); | 2257 mock_server_->set_conflict_all_commits(true); |
2205 SyncShareNudge(); | 2258 SyncShareNudge(); |
2206 syncable::Directory::ChildHandles children; | 2259 syncable::Directory::ChildHandles children; |
2207 { | 2260 { |
(...skipping 14 matching lines...) Expand all Loading... |
2222 saw_syncer_event_ = false; | 2275 saw_syncer_event_ = false; |
2223 } | 2276 } |
2224 | 2277 |
2225 // We got this repro case when someone was editing bookmarks while sync was | 2278 // We got this repro case when someone was editing bookmarks while sync was |
2226 // occuring. The entry had changed out underneath the user. | 2279 // occuring. The entry had changed out underneath the user. |
2227 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { | 2280 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { |
2228 const base::Time& test_time = ProtoTimeToTime(123456); | 2281 const base::Time& test_time = ProtoTimeToTime(123456); |
2229 int64 entry_metahandle; | 2282 int64 entry_metahandle; |
2230 { | 2283 { |
2231 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2284 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2232 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); | 2285 MutableEntry entry(&wtrans, syncable::CREATE_BOOKMARK, root_id_, "Pete"); |
2233 ASSERT_TRUE(entry.good()); | 2286 ASSERT_TRUE(entry.good()); |
2234 EXPECT_FALSE(entry.Get(ID).ServerKnows()); | 2287 EXPECT_FALSE(entry.Get(ID).ServerKnows()); |
2235 entry.Put(syncable::IS_DIR, true); | 2288 entry.Put(syncable::IS_DIR, true); |
2236 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 2289 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
2237 entry.Put(syncable::IS_UNSYNCED, true); | 2290 entry.Put(syncable::IS_UNSYNCED, true); |
2238 entry.Put(syncable::MTIME, test_time); | 2291 entry.Put(syncable::MTIME, test_time); |
2239 entry_metahandle = entry.Get(META_HANDLE); | 2292 entry_metahandle = entry.Get(META_HANDLE); |
2240 } | 2293 } |
2241 SyncShareNudge(); | 2294 SyncShareNudge(); |
2242 syncable::Id id; | 2295 syncable::Id id; |
2243 int64 version; | 2296 int64 version; |
2244 NodeOrdinal server_ordinal_in_parent; | |
2245 { | 2297 { |
2246 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2298 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2247 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle); | 2299 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle); |
2248 ASSERT_TRUE(entry.good()); | 2300 ASSERT_TRUE(entry.good()); |
2249 id = entry.Get(ID); | 2301 id = entry.Get(ID); |
2250 EXPECT_TRUE(id.ServerKnows()); | 2302 EXPECT_TRUE(id.ServerKnows()); |
2251 version = entry.Get(BASE_VERSION); | 2303 version = entry.Get(BASE_VERSION); |
2252 server_ordinal_in_parent = entry.Get(SERVER_ORDINAL_IN_PARENT); | |
2253 } | 2304 } |
2254 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); | 2305 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); |
2255 EXPECT_EQ("Pete", update->name()); | 2306 EXPECT_EQ("Pete", update->name()); |
2256 EXPECT_EQ(id.GetServerId(), update->id_string()); | 2307 EXPECT_EQ(id.GetServerId(), update->id_string()); |
2257 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string()); | 2308 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string()); |
2258 EXPECT_EQ(version, update->version()); | 2309 EXPECT_EQ(version, update->version()); |
2259 EXPECT_EQ( | |
2260 NodeOrdinalToInt64(server_ordinal_in_parent), | |
2261 update->position_in_parent()); | |
2262 SyncShareNudge(); | 2310 SyncShareNudge(); |
2263 { | 2311 { |
2264 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2312 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2265 Entry entry(&trans, syncable::GET_BY_ID, id); | 2313 Entry entry(&trans, syncable::GET_BY_ID, id); |
2266 ASSERT_TRUE(entry.good()); | 2314 ASSERT_TRUE(entry.good()); |
2267 EXPECT_TRUE(entry.Get(MTIME) == test_time); | 2315 EXPECT_TRUE(entry.Get(MTIME) == test_time); |
2268 } | 2316 } |
2269 } | 2317 } |
2270 | 2318 |
2271 TEST_F(SyncerTest, ParentAndChildBothMatch) { | 2319 TEST_F(SyncerTest, ParentAndChildBothMatch) { |
2272 const FullModelTypeSet all_types = FullModelTypeSet::All(); | 2320 const FullModelTypeSet all_types = FullModelTypeSet::All(); |
2273 syncable::Id parent_id = ids_.NewServerId(); | 2321 syncable::Id parent_id = ids_.NewServerId(); |
2274 syncable::Id child_id = ids_.NewServerId(); | 2322 syncable::Id child_id = ids_.NewServerId(); |
2275 | 2323 |
2276 { | 2324 { |
2277 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2325 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2278 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); | 2326 MutableEntry parent(&wtrans, CREATE_BOOKMARK, root_id_, "Folder"); |
2279 ASSERT_TRUE(parent.good()); | 2327 ASSERT_TRUE(parent.good()); |
2280 parent.Put(IS_DIR, true); | 2328 parent.Put(IS_DIR, true); |
2281 parent.Put(IS_UNSYNCED, true); | 2329 parent.Put(IS_UNSYNCED, true); |
2282 parent.Put(ID, parent_id); | 2330 parent.Put(ID, parent_id); |
2283 parent.Put(BASE_VERSION, 1); | 2331 parent.Put(BASE_VERSION, 1); |
2284 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2332 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2285 | 2333 |
2286 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm"); | 2334 MutableEntry child(&wtrans, CREATE_BOOKMARK, parent.Get(ID), "test.htm"); |
2287 ASSERT_TRUE(child.good()); | 2335 ASSERT_TRUE(child.good()); |
2288 child.Put(ID, child_id); | 2336 child.Put(ID, child_id); |
2289 child.Put(BASE_VERSION, 1); | 2337 child.Put(BASE_VERSION, 1); |
2290 child.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2338 child.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2291 WriteTestDataToEntry(&wtrans, &child); | 2339 WriteTestDataToEntry(&wtrans, &child); |
2292 } | 2340 } |
2293 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); | 2341 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); |
2294 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); | 2342 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); |
2295 mock_server_->set_conflict_all_commits(true); | 2343 mock_server_->set_conflict_all_commits(true); |
2296 SyncShareNudge(); | 2344 SyncShareNudge(); |
(...skipping 12 matching lines...) Expand all Loading... |
2309 syncable::Directory::UnsyncedMetaHandles unsynced; | 2357 syncable::Directory::UnsyncedMetaHandles unsynced; |
2310 directory()->GetUnsyncedMetaHandles(&trans, &unsynced); | 2358 directory()->GetUnsyncedMetaHandles(&trans, &unsynced); |
2311 EXPECT_EQ(0u, unsynced.size()); | 2359 EXPECT_EQ(0u, unsynced.size()); |
2312 saw_syncer_event_ = false; | 2360 saw_syncer_event_ = false; |
2313 } | 2361 } |
2314 } | 2362 } |
2315 | 2363 |
2316 TEST_F(SyncerTest, CommittingNewDeleted) { | 2364 TEST_F(SyncerTest, CommittingNewDeleted) { |
2317 { | 2365 { |
2318 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2366 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2319 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); | 2367 MutableEntry entry(&trans, CREATE_BOOKMARK, trans.root_id(), "bob"); |
2320 entry.Put(IS_UNSYNCED, true); | 2368 entry.Put(IS_UNSYNCED, true); |
2321 entry.Put(IS_DEL, true); | 2369 entry.Put(IS_DEL, true); |
2322 } | 2370 } |
2323 SyncShareNudge(); | 2371 SyncShareNudge(); |
2324 EXPECT_EQ(0u, mock_server_->committed_ids().size()); | 2372 EXPECT_EQ(0u, mock_server_->committed_ids().size()); |
2325 } | 2373 } |
2326 | 2374 |
2327 // Original problem synopsis: | 2375 // Original problem synopsis: |
2328 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION) | 2376 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION) |
2329 // Client creates entry, client finishes committing entry. Between | 2377 // Client creates entry, client finishes committing entry. Between |
2330 // commit and getting update back, we delete the entry. | 2378 // commit and getting update back, we delete the entry. |
2331 // We get the update for the entry, but the local one was modified | 2379 // We get the update for the entry, but the local one was modified |
2332 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. | 2380 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. |
2333 // We commit deletion and get a new version number. | 2381 // We commit deletion and get a new version number. |
2334 // We apply unapplied updates again before we get the update about the deletion. | 2382 // We apply unapplied updates again before we get the update about the deletion. |
2335 // This means we have an unapplied update where server_version < base_version. | 2383 // This means we have an unapplied update where server_version < base_version. |
2336 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { | 2384 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { |
2337 // This test is a little fake. | 2385 // This test is a little fake. |
2338 { | 2386 { |
2339 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2387 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2340 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); | 2388 MutableEntry entry(&trans, CREATE_BOOKMARK, trans.root_id(), "bob"); |
2341 entry.Put(ID, ids_.FromNumber(20)); | 2389 entry.Put(ID, ids_.FromNumber(20)); |
2342 entry.Put(BASE_VERSION, 1); | 2390 entry.Put(BASE_VERSION, 1); |
2343 entry.Put(SERVER_VERSION, 1); | 2391 entry.Put(SERVER_VERSION, 1); |
2344 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. | 2392 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. |
2345 entry.Put(IS_UNSYNCED, true); | 2393 entry.Put(IS_UNSYNCED, true); |
2346 entry.Put(IS_UNAPPLIED_UPDATE, true); | 2394 entry.Put(IS_UNAPPLIED_UPDATE, true); |
2347 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2395 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2348 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); | 2396 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); |
2349 entry.Put(IS_DEL, false); | 2397 entry.Put(IS_DEL, false); |
2350 } | 2398 } |
(...skipping 11 matching lines...) Expand all Loading... |
2362 // make a new folder fred | 2410 // make a new folder fred |
2363 // move bob into fred | 2411 // move bob into fred |
2364 // remove bob | 2412 // remove bob |
2365 // remove fred | 2413 // remove fred |
2366 // if no syncing occured midway, bob will have an illegal parent | 2414 // if no syncing occured midway, bob will have an illegal parent |
2367 TEST_F(SyncerTest, DeletingEntryInFolder) { | 2415 TEST_F(SyncerTest, DeletingEntryInFolder) { |
2368 // This test is a little fake. | 2416 // This test is a little fake. |
2369 int64 existing_metahandle; | 2417 int64 existing_metahandle; |
2370 { | 2418 { |
2371 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2419 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2372 MutableEntry entry(&trans, CREATE, trans.root_id(), "existing"); | 2420 MutableEntry entry(&trans, CREATE_BOOKMARK, trans.root_id(), "existing"); |
2373 ASSERT_TRUE(entry.good()); | 2421 ASSERT_TRUE(entry.good()); |
2374 entry.Put(IS_DIR, true); | 2422 entry.Put(IS_DIR, true); |
2375 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2423 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2376 entry.Put(IS_UNSYNCED, true); | 2424 entry.Put(IS_UNSYNCED, true); |
2377 existing_metahandle = entry.Get(META_HANDLE); | 2425 existing_metahandle = entry.Get(META_HANDLE); |
2378 } | 2426 } |
2379 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); | 2427 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
2380 { | 2428 { |
2381 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2429 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2382 MutableEntry newfolder(&trans, CREATE, trans.root_id(), "new"); | 2430 MutableEntry newfolder(&trans, CREATE_BOOKMARK, trans.root_id(), "new"); |
2383 ASSERT_TRUE(newfolder.good()); | 2431 ASSERT_TRUE(newfolder.good()); |
2384 newfolder.Put(IS_DIR, true); | 2432 newfolder.Put(IS_DIR, true); |
2385 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2433 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2386 newfolder.Put(IS_UNSYNCED, true); | 2434 newfolder.Put(IS_UNSYNCED, true); |
2387 | 2435 |
2388 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); | 2436 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); |
2389 ASSERT_TRUE(existing.good()); | 2437 ASSERT_TRUE(existing.good()); |
2390 existing.Put(PARENT_ID, newfolder.Get(ID)); | 2438 existing.Put(PARENT_ID, newfolder.Get(ID)); |
2391 existing.Put(IS_UNSYNCED, true); | 2439 existing.Put(IS_UNSYNCED, true); |
2392 EXPECT_TRUE(existing.Get(ID).ServerKnows()); | 2440 EXPECT_TRUE(existing.Get(ID).ServerKnows()); |
2393 | 2441 |
2394 newfolder.Put(IS_DEL, true); | 2442 newfolder.Put(IS_DEL, true); |
2395 existing.Put(IS_DEL, true); | 2443 existing.Put(IS_DEL, true); |
2396 } | 2444 } |
2397 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); | 2445 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
2398 EXPECT_EQ(0, status().num_server_conflicts()); | 2446 EXPECT_EQ(0, status().num_server_conflicts()); |
2399 } | 2447 } |
2400 | 2448 |
2401 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { | 2449 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { |
2402 int64 newfolder_metahandle; | 2450 int64 newfolder_metahandle; |
2403 | 2451 |
2404 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); | 2452 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); |
2405 SyncShareNudge(); | 2453 SyncShareNudge(); |
2406 { | 2454 { |
2407 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2455 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2408 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); | 2456 MutableEntry newfolder( |
| 2457 &trans, CREATE_BOOKMARK, ids_.FromNumber(1), "local"); |
2409 ASSERT_TRUE(newfolder.good()); | 2458 ASSERT_TRUE(newfolder.good()); |
2410 newfolder.Put(IS_UNSYNCED, true); | 2459 newfolder.Put(IS_UNSYNCED, true); |
2411 newfolder.Put(IS_DIR, true); | 2460 newfolder.Put(IS_DIR, true); |
2412 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2461 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2413 newfolder_metahandle = newfolder.Get(META_HANDLE); | 2462 newfolder_metahandle = newfolder.Get(META_HANDLE); |
2414 } | 2463 } |
2415 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20); | 2464 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20); |
2416 mock_server_->SetLastUpdateDeleted(); | 2465 mock_server_->SetLastUpdateDeleted(); |
2417 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES); | 2466 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES); |
2418 { | 2467 { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2489 // we post more than one commit command to the server. This test makes | 2538 // we post more than one commit command to the server. This test makes |
2490 // sure that scenario works as expected. | 2539 // sure that scenario works as expected. |
2491 TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) { | 2540 TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) { |
2492 uint32 num_batches = 3; | 2541 uint32 num_batches = 3; |
2493 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; | 2542 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; |
2494 { | 2543 { |
2495 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2544 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2496 for (uint32 i = 0; i < items_to_commit; i++) { | 2545 for (uint32 i = 0; i < items_to_commit; i++) { |
2497 string nameutf8 = base::StringPrintf("%d", i); | 2546 string nameutf8 = base::StringPrintf("%d", i); |
2498 string name(nameutf8.begin(), nameutf8.end()); | 2547 string name(nameutf8.begin(), nameutf8.end()); |
2499 MutableEntry e(&trans, CREATE, trans.root_id(), name); | 2548 MutableEntry e(&trans, CREATE_BOOKMARK, trans.root_id(), name); |
2500 e.Put(IS_UNSYNCED, true); | 2549 e.Put(IS_UNSYNCED, true); |
2501 e.Put(IS_DIR, true); | 2550 e.Put(IS_DIR, true); |
2502 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2551 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2503 } | 2552 } |
2504 } | 2553 } |
2505 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2554 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
2506 | 2555 |
2507 SyncShareNudge(); | 2556 SyncShareNudge(); |
2508 EXPECT_EQ(num_batches, mock_server_->commit_messages().size()); | 2557 EXPECT_EQ(num_batches, mock_server_->commit_messages().size()); |
2509 EXPECT_EQ(0, directory()->unsynced_entity_count()); | 2558 EXPECT_EQ(0, directory()->unsynced_entity_count()); |
2510 } | 2559 } |
2511 | 2560 |
2512 // Test that a single failure to contact the server will cause us to exit the | 2561 // Test that a single failure to contact the server will cause us to exit the |
2513 // commit loop immediately. | 2562 // commit loop immediately. |
2514 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) { | 2563 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) { |
2515 uint32 num_batches = 3; | 2564 uint32 num_batches = 3; |
2516 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; | 2565 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; |
2517 { | 2566 { |
2518 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2567 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2519 for (uint32 i = 0; i < items_to_commit; i++) { | 2568 for (uint32 i = 0; i < items_to_commit; i++) { |
2520 string nameutf8 = base::StringPrintf("%d", i); | 2569 string nameutf8 = base::StringPrintf("%d", i); |
2521 string name(nameutf8.begin(), nameutf8.end()); | 2570 string name(nameutf8.begin(), nameutf8.end()); |
2522 MutableEntry e(&trans, CREATE, trans.root_id(), name); | 2571 MutableEntry e(&trans, CREATE_BOOKMARK, trans.root_id(), name); |
2523 e.Put(IS_UNSYNCED, true); | 2572 e.Put(IS_UNSYNCED, true); |
2524 e.Put(IS_DIR, true); | 2573 e.Put(IS_DIR, true); |
2525 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2574 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2526 } | 2575 } |
2527 } | 2576 } |
2528 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2577 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
2529 | 2578 |
2530 // The second commit should fail. It will be preceded by one successful | 2579 // The second commit should fail. It will be preceded by one successful |
2531 // GetUpdate and one succesful commit. | 2580 // GetUpdate and one succesful commit. |
2532 mock_server_->FailNthPostBufferToPathCall(3); | 2581 mock_server_->FailNthPostBufferToPathCall(3); |
2533 SyncShareNudge(); | 2582 SyncShareNudge(); |
2534 | 2583 |
2535 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2584 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
2536 EXPECT_EQ(SYNC_SERVER_ERROR, | 2585 EXPECT_EQ(SYNC_SERVER_ERROR, |
2537 session_->status_controller().model_neutral_state().commit_result); | 2586 session_->status_controller().model_neutral_state().commit_result); |
2538 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, | 2587 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, |
2539 directory()->unsynced_entity_count()); | 2588 directory()->unsynced_entity_count()); |
2540 } | 2589 } |
2541 | 2590 |
2542 // Test that a single conflict response from the server will cause us to exit | 2591 // Test that a single conflict response from the server will cause us to exit |
2543 // the commit loop immediately. | 2592 // the commit loop immediately. |
2544 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { | 2593 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { |
2545 uint32 num_batches = 2; | 2594 uint32 num_batches = 2; |
2546 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; | 2595 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; |
2547 { | 2596 { |
2548 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2597 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2549 for (uint32 i = 0; i < items_to_commit; i++) { | 2598 for (uint32 i = 0; i < items_to_commit; i++) { |
2550 string nameutf8 = base::StringPrintf("%d", i); | 2599 string nameutf8 = base::StringPrintf("%d", i); |
2551 string name(nameutf8.begin(), nameutf8.end()); | 2600 string name(nameutf8.begin(), nameutf8.end()); |
2552 MutableEntry e(&trans, CREATE, trans.root_id(), name); | 2601 MutableEntry e(&trans, CREATE_BOOKMARK, trans.root_id(), name); |
2553 e.Put(IS_UNSYNCED, true); | 2602 e.Put(IS_UNSYNCED, true); |
2554 e.Put(IS_DIR, true); | 2603 e.Put(IS_DIR, true); |
2555 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2604 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2556 } | 2605 } |
2557 } | 2606 } |
2558 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2607 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
2559 | 2608 |
2560 // Return a CONFLICT response for the first item. | 2609 // Return a CONFLICT response for the first item. |
2561 mock_server_->set_conflict_n_commits(1); | 2610 mock_server_->set_conflict_n_commits(1); |
2562 SyncShareNudge(); | 2611 SyncShareNudge(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 saw_syncer_event_ = false; | 2689 saw_syncer_event_ = false; |
2641 } | 2690 } |
2642 | 2691 |
2643 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { | 2692 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { |
2644 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); | 2693 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); |
2645 SyncShareNudge(); | 2694 SyncShareNudge(); |
2646 int64 local_folder_handle; | 2695 int64 local_folder_handle; |
2647 syncable::Id local_folder_id; | 2696 syncable::Id local_folder_id; |
2648 { | 2697 { |
2649 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2698 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2650 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); | 2699 MutableEntry new_entry( |
| 2700 &wtrans, CREATE_BOOKMARK, wtrans.root_id(), "Bar.htm"); |
2651 ASSERT_TRUE(new_entry.good()); | 2701 ASSERT_TRUE(new_entry.good()); |
2652 local_folder_id = new_entry.Get(ID); | 2702 local_folder_id = new_entry.Get(ID); |
2653 local_folder_handle = new_entry.Get(META_HANDLE); | 2703 local_folder_handle = new_entry.Get(META_HANDLE); |
2654 new_entry.Put(IS_UNSYNCED, true); | 2704 new_entry.Put(IS_UNSYNCED, true); |
2655 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2705 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2656 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2706 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
2657 ASSERT_TRUE(old.good()); | 2707 ASSERT_TRUE(old.good()); |
2658 WriteTestDataToEntry(&wtrans, &old); | 2708 WriteTestDataToEntry(&wtrans, &old); |
2659 } | 2709 } |
2660 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); | 2710 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2706 | 2756 |
2707 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. | 2757 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. |
2708 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { | 2758 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { |
2709 mock_server_->set_use_legacy_bookmarks_protocol(true); | 2759 mock_server_->set_use_legacy_bookmarks_protocol(true); |
2710 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); | 2760 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); |
2711 SyncShareNudge(); | 2761 SyncShareNudge(); |
2712 int64 local_folder_handle; | 2762 int64 local_folder_handle; |
2713 syncable::Id local_folder_id; | 2763 syncable::Id local_folder_id; |
2714 { | 2764 { |
2715 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2765 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2716 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); | 2766 MutableEntry new_entry( |
| 2767 &wtrans, CREATE_BOOKMARK, wtrans.root_id(), "Bar.htm"); |
2717 ASSERT_TRUE(new_entry.good()); | 2768 ASSERT_TRUE(new_entry.good()); |
2718 local_folder_id = new_entry.Get(ID); | 2769 local_folder_id = new_entry.Get(ID); |
2719 local_folder_handle = new_entry.Get(META_HANDLE); | 2770 local_folder_handle = new_entry.Get(META_HANDLE); |
2720 new_entry.Put(IS_UNSYNCED, true); | 2771 new_entry.Put(IS_UNSYNCED, true); |
2721 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2772 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2722 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2773 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
2723 ASSERT_TRUE(old.good()); | 2774 ASSERT_TRUE(old.good()); |
2724 WriteTestDataToEntry(&wtrans, &old); | 2775 WriteTestDataToEntry(&wtrans, &old); |
2725 } | 2776 } |
2726 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); | 2777 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2878 EXPECT_EQ(2, bob.Get(BASE_VERSION)); | 2929 EXPECT_EQ(2, bob.Get(BASE_VERSION)); |
2879 } | 2930 } |
2880 saw_syncer_event_ = false; | 2931 saw_syncer_event_ = false; |
2881 } | 2932 } |
2882 | 2933 |
2883 // This test is to reproduce a check failure. Sometimes we would get a bad ID | 2934 // This test is to reproduce a check failure. Sometimes we would get a bad ID |
2884 // back when creating an entry. | 2935 // back when creating an entry. |
2885 TEST_F(SyncerTest, DuplicateIDReturn) { | 2936 TEST_F(SyncerTest, DuplicateIDReturn) { |
2886 { | 2937 { |
2887 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2938 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2888 MutableEntry folder(&trans, CREATE, trans.root_id(), "bob"); | 2939 MutableEntry folder(&trans, CREATE_BOOKMARK, trans.root_id(), "bob"); |
2889 ASSERT_TRUE(folder.good()); | 2940 ASSERT_TRUE(folder.good()); |
2890 folder.Put(IS_UNSYNCED, true); | 2941 folder.Put(IS_UNSYNCED, true); |
2891 folder.Put(IS_DIR, true); | 2942 folder.Put(IS_DIR, true); |
2892 folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2943 folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2893 MutableEntry folder2(&trans, CREATE, trans.root_id(), "fred"); | 2944 MutableEntry folder2(&trans, CREATE_BOOKMARK, trans.root_id(), "fred"); |
2894 ASSERT_TRUE(folder2.good()); | 2945 ASSERT_TRUE(folder2.good()); |
2895 folder2.Put(IS_UNSYNCED, false); | 2946 folder2.Put(IS_UNSYNCED, false); |
2896 folder2.Put(IS_DIR, true); | 2947 folder2.Put(IS_DIR, true); |
2897 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2948 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2898 folder2.Put(BASE_VERSION, 3); | 2949 folder2.Put(BASE_VERSION, 3); |
2899 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000")); | 2950 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000")); |
2900 } | 2951 } |
2901 mock_server_->set_next_new_id(10000); | 2952 mock_server_->set_next_new_id(10000); |
2902 EXPECT_EQ(1u, directory()->unsynced_entity_count()); | 2953 EXPECT_EQ(1u, directory()->unsynced_entity_count()); |
2903 // we get back a bad id in here (should never happen). | 2954 // we get back a bad id in here (should never happen). |
(...skipping 18 matching lines...) Expand all Loading... |
2922 } | 2973 } |
2923 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10); | 2974 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10); |
2924 SyncShareNudge(); | 2975 SyncShareNudge(); |
2925 SyncShareNudge(); | 2976 SyncShareNudge(); |
2926 } | 2977 } |
2927 | 2978 |
2928 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { | 2979 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { |
2929 { | 2980 { |
2930 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2981 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2931 | 2982 |
2932 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); | 2983 MutableEntry local_deleted( |
| 2984 &trans, CREATE_BOOKMARK, trans.root_id(), "name"); |
2933 local_deleted.Put(ID, ids_.FromNumber(1)); | 2985 local_deleted.Put(ID, ids_.FromNumber(1)); |
2934 local_deleted.Put(BASE_VERSION, 1); | 2986 local_deleted.Put(BASE_VERSION, 1); |
2935 local_deleted.Put(IS_DEL, true); | 2987 local_deleted.Put(IS_DEL, true); |
2936 local_deleted.Put(IS_DIR, false); | 2988 local_deleted.Put(IS_DIR, false); |
2937 local_deleted.Put(IS_UNSYNCED, true); | 2989 local_deleted.Put(IS_UNSYNCED, true); |
2938 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2990 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2939 } | 2991 } |
2940 | 2992 |
2941 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); | 2993 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); |
2942 | 2994 |
(...skipping 12 matching lines...) Expand all Loading... |
2955 } | 3007 } |
2956 } | 3008 } |
2957 | 3009 |
2958 // See what happens if the IS_DIR bit gets flipped. This can cause us | 3010 // See what happens if the IS_DIR bit gets flipped. This can cause us |
2959 // all kinds of disasters. | 3011 // all kinds of disasters. |
2960 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { | 3012 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { |
2961 // Local object: a deleted directory (container), revision 1, unsynced. | 3013 // Local object: a deleted directory (container), revision 1, unsynced. |
2962 { | 3014 { |
2963 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3015 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2964 | 3016 |
2965 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); | 3017 MutableEntry local_deleted( |
| 3018 &trans, CREATE_BOOKMARK, trans.root_id(), "name"); |
2966 local_deleted.Put(ID, ids_.FromNumber(1)); | 3019 local_deleted.Put(ID, ids_.FromNumber(1)); |
2967 local_deleted.Put(BASE_VERSION, 1); | 3020 local_deleted.Put(BASE_VERSION, 1); |
2968 local_deleted.Put(IS_DEL, true); | 3021 local_deleted.Put(IS_DEL, true); |
2969 local_deleted.Put(IS_DIR, true); | 3022 local_deleted.Put(IS_DIR, true); |
2970 local_deleted.Put(IS_UNSYNCED, true); | 3023 local_deleted.Put(IS_UNSYNCED, true); |
2971 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 3024 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2972 } | 3025 } |
2973 | 3026 |
2974 // Server update: entry-type object (not a container), revision 10. | 3027 // Server update: entry-type object (not a container), revision 10. |
2975 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); | 3028 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); |
(...skipping 17 matching lines...) Expand all Loading... |
2993 | 3046 |
2994 // Bug Synopsis: | 3047 // Bug Synopsis: |
2995 // Merge conflict resolution will merge a new local entry with another entry | 3048 // Merge conflict resolution will merge a new local entry with another entry |
2996 // that needs updates, resulting in CHECK. | 3049 // that needs updates, resulting in CHECK. |
2997 TEST_F(SyncerTest, MergingExistingItems) { | 3050 TEST_F(SyncerTest, MergingExistingItems) { |
2998 mock_server_->set_conflict_all_commits(true); | 3051 mock_server_->set_conflict_all_commits(true); |
2999 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); | 3052 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); |
3000 SyncShareNudge(); | 3053 SyncShareNudge(); |
3001 { | 3054 { |
3002 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3055 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3003 MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base"); | 3056 MutableEntry entry( |
| 3057 &trans, CREATE_BOOKMARK, trans.root_id(), "Copy of base"); |
3004 WriteTestDataToEntry(&trans, &entry); | 3058 WriteTestDataToEntry(&trans, &entry); |
3005 } | 3059 } |
3006 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); | 3060 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); |
3007 SyncRepeatedlyToTriggerConflictResolution(session_.get()); | 3061 SyncRepeatedlyToTriggerConflictResolution(session_.get()); |
3008 } | 3062 } |
3009 | 3063 |
3010 // In this test a long changelog contains a child at the start of the changelog | 3064 // In this test a long changelog contains a child at the start of the changelog |
3011 // and a parent at the end. While these updates are in progress the client would | 3065 // and a parent at the end. While these updates are in progress the client would |
3012 // appear stuck. | 3066 // appear stuck. |
3013 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { | 3067 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3183 } | 3237 } |
3184 } | 3238 } |
3185 | 3239 |
3186 TEST_F(SyncerTest, DirectoryCommitTest) { | 3240 TEST_F(SyncerTest, DirectoryCommitTest) { |
3187 syncable::Id in_root_id, in_dir_id; | 3241 syncable::Id in_root_id, in_dir_id; |
3188 int64 foo_metahandle; | 3242 int64 foo_metahandle; |
3189 int64 bar_metahandle; | 3243 int64 bar_metahandle; |
3190 | 3244 |
3191 { | 3245 { |
3192 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3246 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3193 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "foo"); | 3247 MutableEntry parent(&wtrans, syncable::CREATE_BOOKMARK, root_id_, "foo"); |
3194 ASSERT_TRUE(parent.good()); | 3248 ASSERT_TRUE(parent.good()); |
3195 parent.Put(syncable::IS_UNSYNCED, true); | 3249 parent.Put(syncable::IS_UNSYNCED, true); |
3196 parent.Put(syncable::IS_DIR, true); | 3250 parent.Put(syncable::IS_DIR, true); |
3197 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 3251 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
3198 in_root_id = parent.Get(syncable::ID); | 3252 in_root_id = parent.Get(syncable::ID); |
3199 foo_metahandle = parent.Get(META_HANDLE); | 3253 foo_metahandle = parent.Get(META_HANDLE); |
3200 | 3254 |
3201 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar"); | 3255 MutableEntry child( |
| 3256 &wtrans, syncable::CREATE_BOOKMARK, parent.Get(ID), "bar"); |
3202 ASSERT_TRUE(child.good()); | 3257 ASSERT_TRUE(child.good()); |
3203 child.Put(syncable::IS_UNSYNCED, true); | 3258 child.Put(syncable::IS_UNSYNCED, true); |
3204 child.Put(syncable::IS_DIR, true); | 3259 child.Put(syncable::IS_DIR, true); |
3205 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 3260 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
3206 bar_metahandle = child.Get(META_HANDLE); | 3261 bar_metahandle = child.Get(META_HANDLE); |
3207 in_dir_id = parent.Get(syncable::ID); | 3262 in_dir_id = parent.Get(syncable::ID); |
3208 } | 3263 } |
3209 SyncShareNudge(); | 3264 SyncShareNudge(); |
3210 { | 3265 { |
3211 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3266 syncable::ReadTransaction trans(FROM_HERE, directory()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3303 "folder_two", 1, 1); | 3358 "folder_two", 1, 1); |
3304 SyncShareNudge(); | 3359 SyncShareNudge(); |
3305 { | 3360 { |
3306 // A moved entry should send an "old parent." | 3361 // A moved entry should send an "old parent." |
3307 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3362 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3308 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); | 3363 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); |
3309 ASSERT_TRUE(entry.good()); | 3364 ASSERT_TRUE(entry.good()); |
3310 entry.Put(PARENT_ID, folder_two_id); | 3365 entry.Put(PARENT_ID, folder_two_id); |
3311 entry.Put(IS_UNSYNCED, true); | 3366 entry.Put(IS_UNSYNCED, true); |
3312 // A new entry should send no "old parent." | 3367 // A new entry should send no "old parent." |
3313 MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder"); | 3368 MutableEntry create(&trans, CREATE_BOOKMARK, trans.root_id(), "new_folder"); |
3314 create.Put(IS_UNSYNCED, true); | 3369 create.Put(IS_UNSYNCED, true); |
3315 create.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 3370 create.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
3316 } | 3371 } |
3317 SyncShareNudge(); | 3372 SyncShareNudge(); |
3318 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); | 3373 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); |
3319 ASSERT_EQ(2, commit.entries_size()); | 3374 ASSERT_EQ(2, commit.entries_size()); |
3320 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); | 3375 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); |
3321 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); | 3376 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); |
3322 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); | 3377 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); |
3323 } | 3378 } |
3324 | 3379 |
3325 TEST_F(SyncerTest, Test64BitVersionSupport) { | 3380 TEST_F(SyncerTest, Test64BitVersionSupport) { |
3326 int64 really_big_int = std::numeric_limits<int64>::max() - 12; | 3381 int64 really_big_int = std::numeric_limits<int64>::max() - 12; |
3327 const string name("ringo's dang orang ran rings around my o-ring"); | 3382 const string name("ringo's dang orang ran rings around my o-ring"); |
3328 int64 item_metahandle; | 3383 int64 item_metahandle; |
3329 | 3384 |
3330 // Try writing max int64 to the version fields of a meta entry. | 3385 // Try writing max int64 to the version fields of a meta entry. |
3331 { | 3386 { |
3332 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3387 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3333 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), name); | 3388 MutableEntry entry( |
| 3389 &wtrans, syncable::CREATE_BOOKMARK, wtrans.root_id(), name); |
3334 ASSERT_TRUE(entry.good()); | 3390 ASSERT_TRUE(entry.good()); |
3335 entry.Put(syncable::BASE_VERSION, really_big_int); | 3391 entry.Put(syncable::BASE_VERSION, really_big_int); |
3336 entry.Put(syncable::SERVER_VERSION, really_big_int); | 3392 entry.Put(syncable::SERVER_VERSION, really_big_int); |
3337 entry.Put(syncable::ID, ids_.NewServerId()); | 3393 entry.Put(syncable::ID, ids_.NewServerId()); |
3338 item_metahandle = entry.Get(META_HANDLE); | 3394 item_metahandle = entry.Get(META_HANDLE); |
3339 } | 3395 } |
3340 // Now read it back out and make sure the value is max int64. | 3396 // Now read it back out and make sure the value is max int64. |
3341 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 3397 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
3342 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle); | 3398 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle); |
3343 ASSERT_TRUE(entry.good()); | 3399 ASSERT_TRUE(entry.good()); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3534 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { | 3590 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { |
3535 int64 original_metahandle = 0; | 3591 int64 original_metahandle = 0; |
3536 | 3592 |
3537 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics()); | 3593 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics()); |
3538 local_bookmark.mutable_bookmark()->set_url("http://foo/localsite"); | 3594 local_bookmark.mutable_bookmark()->set_url("http://foo/localsite"); |
3539 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics()); | 3595 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics()); |
3540 server_bookmark.mutable_bookmark()->set_url("http://bar/serversite"); | 3596 server_bookmark.mutable_bookmark()->set_url("http://bar/serversite"); |
3541 | 3597 |
3542 { | 3598 { |
3543 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3599 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3544 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); | 3600 MutableEntry perm_folder( |
| 3601 &trans, CREATE_BOOKMARK, ids_.root(), "clientname"); |
3545 ASSERT_TRUE(perm_folder.good()); | 3602 ASSERT_TRUE(perm_folder.good()); |
3546 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); | 3603 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); |
3547 perm_folder.Put(SPECIFICS, local_bookmark); | 3604 perm_folder.Put(SPECIFICS, local_bookmark); |
3548 perm_folder.Put(IS_UNSYNCED, true); | 3605 perm_folder.Put(IS_UNSYNCED, true); |
3549 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); | 3606 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); |
3550 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); | 3607 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); |
3551 original_metahandle = perm_folder.Get(META_HANDLE); | 3608 original_metahandle = perm_folder.Get(META_HANDLE); |
3552 } | 3609 } |
3553 | 3610 |
3554 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100); | 3611 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 EXPECT_EQ(local_bookmark.SerializeAsString(), | 3656 EXPECT_EQ(local_bookmark.SerializeAsString(), |
3600 perm_folder.Get(SPECIFICS).SerializeAsString()); | 3657 perm_folder.Get(SPECIFICS).SerializeAsString()); |
3601 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); | 3658 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); |
3602 } | 3659 } |
3603 } | 3660 } |
3604 | 3661 |
3605 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { | 3662 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { |
3606 { | 3663 { |
3607 // Create a deleted local entry with a unique client tag. | 3664 // Create a deleted local entry with a unique client tag. |
3608 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3665 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3609 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); | 3666 MutableEntry perm_folder( |
| 3667 &trans, CREATE_BOOKMARK, ids_.root(), "clientname"); |
3610 ASSERT_TRUE(perm_folder.good()); | 3668 ASSERT_TRUE(perm_folder.good()); |
3611 ASSERT_FALSE(perm_folder.Get(ID).ServerKnows()); | 3669 ASSERT_FALSE(perm_folder.Get(ID).ServerKnows()); |
3612 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); | 3670 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); |
3613 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 3671 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
3614 perm_folder.Put(IS_UNSYNCED, true); | 3672 perm_folder.Put(IS_UNSYNCED, true); |
3615 | 3673 |
3616 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit. | 3674 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit. |
3617 // (We never attempt to commit server-unknown deleted items, so this | 3675 // (We never attempt to commit server-unknown deleted items, so this |
3618 // helps us clean up those entries). | 3676 // helps us clean up those entries). |
3619 perm_folder.Put(IS_DEL, true); | 3677 perm_folder.Put(IS_DEL, true); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4061 // - commitresponse - getupdates. | 4119 // - commitresponse - getupdates. |
4062 class SyncerUndeletionTest : public SyncerTest { | 4120 class SyncerUndeletionTest : public SyncerTest { |
4063 public: | 4121 public: |
4064 SyncerUndeletionTest() | 4122 SyncerUndeletionTest() |
4065 : client_tag_("foobar"), | 4123 : client_tag_("foobar"), |
4066 metahandle_(syncable::kInvalidMetaHandle) { | 4124 metahandle_(syncable::kInvalidMetaHandle) { |
4067 } | 4125 } |
4068 | 4126 |
4069 void Create() { | 4127 void Create() { |
4070 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 4128 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
4071 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); | 4129 MutableEntry perm_folder( |
| 4130 &trans, CREATE_BOOKMARK, ids_.root(), "clientname"); |
4072 ASSERT_TRUE(perm_folder.good()); | 4131 ASSERT_TRUE(perm_folder.good()); |
4073 perm_folder.Put(UNIQUE_CLIENT_TAG, client_tag_); | 4132 perm_folder.Put(UNIQUE_CLIENT_TAG, client_tag_); |
4074 perm_folder.Put(IS_UNSYNCED, true); | 4133 perm_folder.Put(IS_UNSYNCED, true); |
4075 perm_folder.Put(SYNCING, false); | 4134 perm_folder.Put(SYNCING, false); |
4076 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 4135 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
4077 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); | 4136 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); |
4078 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); | 4137 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); |
4079 metahandle_ = perm_folder.Get(META_HANDLE); | 4138 metahandle_ = perm_folder.Get(META_HANDLE); |
4080 } | 4139 } |
4081 | 4140 |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4482 Get(metahandle_, PARENT_ID), | 4541 Get(metahandle_, PARENT_ID), |
4483 "Thadeusz", 100, 1000); | 4542 "Thadeusz", 100, 1000); |
4484 mock_server_->SetLastUpdateClientTag(client_tag_); | 4543 mock_server_->SetLastUpdateClientTag(client_tag_); |
4485 SyncShareNudge(); | 4544 SyncShareNudge(); |
4486 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); | 4545 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
4487 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 4546 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
4488 ExpectSyncedAndCreated(); | 4547 ExpectSyncedAndCreated(); |
4489 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); | 4548 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); |
4490 } | 4549 } |
4491 | 4550 |
4492 // A group of tests exercising the syncer's handling of sibling ordering, as | |
4493 // represented in the sync protocol. | |
4494 class SyncerPositionUpdateTest : public SyncerTest { | |
4495 public: | |
4496 SyncerPositionUpdateTest() : next_update_id_(1), next_revision_(1) {} | |
4497 | |
4498 protected: | |
4499 void ExpectLocalItemsInServerOrder() { | |
4500 if (position_map_.empty()) | |
4501 return; | |
4502 | |
4503 syncable::ReadTransaction trans(FROM_HERE, directory()); | |
4504 | |
4505 Id prev_id; | |
4506 DCHECK(prev_id.IsRoot()); | |
4507 PosMap::iterator next = position_map_.begin(); | |
4508 for (PosMap::iterator i = next++; i != position_map_.end(); ++i) { | |
4509 Id id = i->second; | |
4510 Entry entry_with_id(&trans, GET_BY_ID, id); | |
4511 EXPECT_TRUE(entry_with_id.good()); | |
4512 EXPECT_EQ(prev_id, entry_with_id.Get(PREV_ID)); | |
4513 EXPECT_EQ( | |
4514 i->first, | |
4515 NodeOrdinalToInt64(entry_with_id.Get(SERVER_ORDINAL_IN_PARENT))); | |
4516 if (next == position_map_.end()) { | |
4517 EXPECT_EQ(Id(), entry_with_id.Get(NEXT_ID)); | |
4518 } else { | |
4519 EXPECT_EQ(next->second, entry_with_id.Get(NEXT_ID)); | |
4520 next++; | |
4521 } | |
4522 prev_id = id; | |
4523 } | |
4524 } | |
4525 | |
4526 void AddRootItemWithPosition(int64 position) { | |
4527 string id = string("ServerId") + base::Int64ToString(next_update_id_++); | |
4528 string name = "my name is my id -- " + id; | |
4529 int revision = next_revision_++; | |
4530 mock_server_->AddUpdateDirectory(id, kRootId, name, revision, revision); | |
4531 mock_server_->SetLastUpdatePosition(position); | |
4532 position_map_.insert( | |
4533 PosMap::value_type(position, Id::CreateFromServerId(id))); | |
4534 } | |
4535 private: | |
4536 typedef multimap<int64, Id> PosMap; | |
4537 PosMap position_map_; | |
4538 int next_update_id_; | |
4539 int next_revision_; | |
4540 DISALLOW_COPY_AND_ASSIGN(SyncerPositionUpdateTest); | |
4541 }; | |
4542 | |
4543 TEST_F(SyncerPositionUpdateTest, InOrderPositive) { | |
4544 // Add a bunch of items in increasing order, starting with just positive | |
4545 // position values. | |
4546 AddRootItemWithPosition(100); | |
4547 AddRootItemWithPosition(199); | |
4548 AddRootItemWithPosition(200); | |
4549 AddRootItemWithPosition(201); | |
4550 AddRootItemWithPosition(400); | |
4551 | |
4552 SyncShareNudge(); | |
4553 ExpectLocalItemsInServerOrder(); | |
4554 } | |
4555 | |
4556 TEST_F(SyncerPositionUpdateTest, InOrderNegative) { | |
4557 // Test negative position values, but in increasing order. | |
4558 AddRootItemWithPosition(-400); | |
4559 AddRootItemWithPosition(-201); | |
4560 AddRootItemWithPosition(-200); | |
4561 AddRootItemWithPosition(-150); | |
4562 AddRootItemWithPosition(100); | |
4563 | |
4564 SyncShareNudge(); | |
4565 ExpectLocalItemsInServerOrder(); | |
4566 } | |
4567 | |
4568 TEST_F(SyncerPositionUpdateTest, ReverseOrder) { | |
4569 // Test when items are sent in the reverse order. | |
4570 AddRootItemWithPosition(400); | |
4571 AddRootItemWithPosition(201); | |
4572 AddRootItemWithPosition(200); | |
4573 AddRootItemWithPosition(100); | |
4574 AddRootItemWithPosition(-150); | |
4575 AddRootItemWithPosition(-201); | |
4576 AddRootItemWithPosition(-200); | |
4577 AddRootItemWithPosition(-400); | |
4578 | |
4579 SyncShareNudge(); | |
4580 ExpectLocalItemsInServerOrder(); | |
4581 } | |
4582 | |
4583 TEST_F(SyncerPositionUpdateTest, RandomOrderInBatches) { | |
4584 // Mix it all up, interleaving position values, and try multiple batches of | |
4585 // updates. | |
4586 AddRootItemWithPosition(400); | |
4587 AddRootItemWithPosition(201); | |
4588 AddRootItemWithPosition(-400); | |
4589 AddRootItemWithPosition(100); | |
4590 | |
4591 SyncShareNudge(); | |
4592 ExpectLocalItemsInServerOrder(); | |
4593 | |
4594 AddRootItemWithPosition(-150); | |
4595 AddRootItemWithPosition(-200); | |
4596 AddRootItemWithPosition(200); | |
4597 AddRootItemWithPosition(-201); | |
4598 | |
4599 SyncShareNudge(); | |
4600 ExpectLocalItemsInServerOrder(); | |
4601 | |
4602 AddRootItemWithPosition(-144); | |
4603 | |
4604 SyncShareNudge(); | |
4605 ExpectLocalItemsInServerOrder(); | |
4606 } | |
4607 | |
4608 class SyncerPositionTiebreakingTest : public SyncerTest { | |
4609 public: | |
4610 SyncerPositionTiebreakingTest() | |
4611 : low_id_(Id::CreateFromServerId("A")), | |
4612 mid_id_(Id::CreateFromServerId("M")), | |
4613 high_id_(Id::CreateFromServerId("Z")), | |
4614 next_revision_(1) { | |
4615 DCHECK(low_id_ < mid_id_); | |
4616 DCHECK(mid_id_ < high_id_); | |
4617 DCHECK(low_id_ < high_id_); | |
4618 } | |
4619 | |
4620 // Adds the item by its Id, using a constant value for the position | |
4621 // so that the syncer has to resolve the order some other way. | |
4622 void Add(const Id& id) { | |
4623 int revision = next_revision_++; | |
4624 mock_server_->AddUpdateDirectory(id.GetServerId(), kRootId, | |
4625 id.GetServerId(), revision, revision); | |
4626 // The update position doesn't vary. | |
4627 mock_server_->SetLastUpdatePosition(90210); | |
4628 } | |
4629 | |
4630 void ExpectLocalOrderIsByServerId() { | |
4631 syncable::ReadTransaction trans(FROM_HERE, directory()); | |
4632 Id null_id; | |
4633 Entry low(&trans, GET_BY_ID, low_id_); | |
4634 Entry mid(&trans, GET_BY_ID, mid_id_); | |
4635 Entry high(&trans, GET_BY_ID, high_id_); | |
4636 EXPECT_TRUE(low.good()); | |
4637 EXPECT_TRUE(mid.good()); | |
4638 EXPECT_TRUE(high.good()); | |
4639 EXPECT_TRUE(low.Get(PREV_ID) == null_id); | |
4640 EXPECT_TRUE(mid.Get(PREV_ID) == low_id_); | |
4641 EXPECT_TRUE(high.Get(PREV_ID) == mid_id_); | |
4642 EXPECT_TRUE(high.Get(NEXT_ID) == null_id); | |
4643 EXPECT_TRUE(mid.Get(NEXT_ID) == high_id_); | |
4644 EXPECT_TRUE(low.Get(NEXT_ID) == mid_id_); | |
4645 } | |
4646 | |
4647 protected: | |
4648 // When there's a tiebreak on the numeric position, it's supposed to be | |
4649 // broken by string comparison of the ids. These ids are in increasing | |
4650 // order. | |
4651 const Id low_id_; | |
4652 const Id mid_id_; | |
4653 const Id high_id_; | |
4654 | |
4655 private: | |
4656 int next_revision_; | |
4657 DISALLOW_COPY_AND_ASSIGN(SyncerPositionTiebreakingTest); | |
4658 }; | |
4659 | |
4660 TEST_F(SyncerPositionTiebreakingTest, LowMidHigh) { | |
4661 Add(low_id_); | |
4662 Add(mid_id_); | |
4663 Add(high_id_); | |
4664 SyncShareNudge(); | |
4665 ExpectLocalOrderIsByServerId(); | |
4666 } | |
4667 | |
4668 TEST_F(SyncerPositionTiebreakingTest, LowHighMid) { | |
4669 Add(low_id_); | |
4670 Add(high_id_); | |
4671 Add(mid_id_); | |
4672 SyncShareNudge(); | |
4673 ExpectLocalOrderIsByServerId(); | |
4674 } | |
4675 | |
4676 TEST_F(SyncerPositionTiebreakingTest, HighMidLow) { | |
4677 Add(high_id_); | |
4678 Add(mid_id_); | |
4679 Add(low_id_); | |
4680 SyncShareNudge(); | |
4681 ExpectLocalOrderIsByServerId(); | |
4682 } | |
4683 | |
4684 TEST_F(SyncerPositionTiebreakingTest, HighLowMid) { | |
4685 Add(high_id_); | |
4686 Add(low_id_); | |
4687 Add(mid_id_); | |
4688 SyncShareNudge(); | |
4689 ExpectLocalOrderIsByServerId(); | |
4690 } | |
4691 | |
4692 TEST_F(SyncerPositionTiebreakingTest, MidHighLow) { | |
4693 Add(mid_id_); | |
4694 Add(high_id_); | |
4695 Add(low_id_); | |
4696 SyncShareNudge(); | |
4697 ExpectLocalOrderIsByServerId(); | |
4698 } | |
4699 | |
4700 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | |
4701 Add(mid_id_); | |
4702 Add(low_id_); | |
4703 Add(high_id_); | |
4704 SyncShareNudge(); | |
4705 ExpectLocalOrderIsByServerId(); | |
4706 } | |
4707 | |
4708 } // namespace syncer | 4551 } // namespace syncer |
OLD | NEW |