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

Side by Side Diff: sync/internal_api/test/test_entry_factory.cc

Issue 11863011: Revert 176340 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/internal_api/sync_manager_impl_unittest.cc ('k') | sync/internal_api/write_node.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/internal_api/public/test/test_entry_factory.h" 5 #include "sync/internal_api/public/test/test_entry_factory.h"
6 6
7 #include "sync/syncable/directory.h" 7 #include "sync/syncable/directory.h"
8 #include "sync/syncable/entry.h" 8 #include "sync/syncable/entry.h"
9 #include "sync/syncable/mutable_entry.h" 9 #include "sync/syncable/mutable_entry.h"
10 #include "sync/syncable/syncable_id.h" 10 #include "sync/syncable/syncable_id.h"
11 #include "sync/syncable/syncable_read_transaction.h" 11 #include "sync/syncable/syncable_read_transaction.h"
12 #include "sync/syncable/syncable_util.h"
13 #include "sync/syncable/syncable_write_transaction.h" 12 #include "sync/syncable/syncable_write_transaction.h"
14 #include "sync/test/engine/test_id_factory.h" 13 #include "sync/test/engine/test_id_factory.h"
15 14
16 using std::string; 15 using std::string;
17 16
18 namespace syncer { 17 namespace syncer {
19 18
20 using syncable::Id; 19 using syncable::Id;
21 using syncable::MutableEntry; 20 using syncable::MutableEntry;
22 using syncable::UNITTEST; 21 using syncable::UNITTEST;
(...skipping 16 matching lines...) Expand all
39 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); 38 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
40 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); 39 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
41 40
42 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); 41 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
43 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); 42 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id));
44 entry.Put(syncable::SERVER_IS_DIR, true); 43 entry.Put(syncable::SERVER_IS_DIR, true);
45 entry.Put(syncable::SERVER_SPECIFICS, specifics); 44 entry.Put(syncable::SERVER_SPECIFICS, specifics);
46 return entry.Get(syncable::META_HANDLE); 45 return entry.Get(syncable::META_HANDLE);
47 } 46 }
48 47
49 int64 TestEntryFactory::CreateUnappliedNewBookmarkItemWithParent(
50 const string& item_id,
51 const sync_pb::EntitySpecifics& specifics,
52 const string& parent_id) {
53 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
54 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
55 Id::CreateFromServerId(item_id));
56 DCHECK(entry.good());
57 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
58 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
59
60 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
61 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id));
62 entry.Put(syncable::SERVER_IS_DIR, true);
63 entry.Put(syncable::SERVER_SPECIFICS, specifics);
64
65 return entry.Get(syncable::META_HANDLE);
66 }
67
68 int64 TestEntryFactory::CreateUnappliedNewItem( 48 int64 TestEntryFactory::CreateUnappliedNewItem(
69 const string& item_id, 49 const string& item_id,
70 const sync_pb::EntitySpecifics& specifics, 50 const sync_pb::EntitySpecifics& specifics,
71 bool is_unique) { 51 bool is_unique) {
72 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); 52 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
73 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, 53 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
74 Id::CreateFromServerId(item_id)); 54 Id::CreateFromServerId(item_id));
75 DCHECK(entry.good()); 55 DCHECK(entry.good());
76 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); 56 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
77 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); 57 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
78 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); 58 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
79 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); 59 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId());
80 entry.Put(syncable::SERVER_IS_DIR, is_unique); 60 entry.Put(syncable::SERVER_IS_DIR, is_unique);
81 entry.Put(syncable::SERVER_SPECIFICS, specifics); 61 entry.Put(syncable::SERVER_SPECIFICS, specifics);
82 if (is_unique) { // For top-level nodes. 62 if (is_unique) { // For top-level nodes.
83 entry.Put(syncable::UNIQUE_SERVER_TAG, 63 entry.Put(syncable::UNIQUE_SERVER_TAG,
84 ModelTypeToRootTag(GetModelTypeFromSpecifics(specifics))); 64 ModelTypeToRootTag(GetModelTypeFromSpecifics(specifics)));
85 } 65 }
86 return entry.Get(syncable::META_HANDLE); 66 return entry.Get(syncable::META_HANDLE);
87 } 67 }
88 68
89 void TestEntryFactory::CreateUnsyncedItem( 69 void TestEntryFactory::CreateUnsyncedItem(
90 const Id& item_id, 70 const Id& item_id,
91 const Id& parent_id, 71 const Id& parent_id,
92 const string& name, 72 const string& name,
93 bool is_folder, 73 bool is_folder,
94 ModelType model_type, 74 ModelType model_type,
95 int64* metahandle_out) { 75 int64* metahandle_out) {
96 if (is_folder) {
97 DCHECK_EQ(model_type, BOOKMARKS);
98 }
99
100 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); 76 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
101
102 Id predecessor_id; 77 Id predecessor_id;
103 if (model_type == BOOKMARKS) { 78 DCHECK(
104 DCHECK(directory_->GetLastChildIdForTest( 79 directory_->GetLastChildIdForTest(&trans, parent_id, &predecessor_id));
105 &trans, parent_id, &predecessor_id)); 80 MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
106 }
107
108 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name);
109 DCHECK(entry.good()); 81 DCHECK(entry.good());
110 entry.Put(syncable::ID, item_id); 82 entry.Put(syncable::ID, item_id);
111 entry.Put(syncable::BASE_VERSION, 83 entry.Put(syncable::BASE_VERSION,
112 item_id.ServerKnows() ? GetNextRevision() : 0); 84 item_id.ServerKnows() ? GetNextRevision() : 0);
113 entry.Put(syncable::IS_UNSYNCED, true); 85 entry.Put(syncable::IS_UNSYNCED, true);
114 entry.Put(syncable::IS_DIR, is_folder); 86 entry.Put(syncable::IS_DIR, is_folder);
115 entry.Put(syncable::IS_DEL, false); 87 entry.Put(syncable::IS_DEL, false);
116 entry.Put(syncable::PARENT_ID, parent_id); 88 entry.Put(syncable::PARENT_ID, parent_id);
89 CHECK(entry.PutPredecessor(predecessor_id));
117 sync_pb::EntitySpecifics default_specifics; 90 sync_pb::EntitySpecifics default_specifics;
118 AddDefaultFieldValue(model_type, &default_specifics); 91 AddDefaultFieldValue(model_type, &default_specifics);
119 entry.Put(syncable::SPECIFICS, default_specifics); 92 entry.Put(syncable::SPECIFICS, default_specifics);
120
121 // Bookmarks get inserted at the end of the list.
122 if (model_type == BOOKMARKS) {
123 DCHECK(entry.PutPredecessor(predecessor_id));
124 }
125
126 if (item_id.ServerKnows()) { 93 if (item_id.ServerKnows()) {
127 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); 94 entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
128 entry.Put(syncable::SERVER_IS_DIR, false); 95 entry.Put(syncable::SERVER_IS_DIR, is_folder);
129 entry.Put(syncable::SERVER_PARENT_ID, parent_id); 96 entry.Put(syncable::SERVER_PARENT_ID, parent_id);
130 entry.Put(syncable::SERVER_IS_DEL, false); 97 entry.Put(syncable::SERVER_IS_DEL, false);
131 } 98 }
132 if (metahandle_out) 99 if (metahandle_out)
133 *metahandle_out = entry.Get(syncable::META_HANDLE); 100 *metahandle_out = entry.Get(syncable::META_HANDLE);
134 } 101 }
135 102
136 int64 TestEntryFactory::CreateUnappliedAndUnsyncedBookmarkItem( 103 int64 TestEntryFactory::CreateUnappliedAndUnsyncedItem(
137 const string& name) { 104 const string& name,
105 ModelType model_type) {
138 int64 metahandle = 0; 106 int64 metahandle = 0;
139 CreateUnsyncedItem( 107 CreateUnsyncedItem(
140 TestIdFactory::MakeServer(name), TestIdFactory::root(), 108 TestIdFactory::MakeServer(name), TestIdFactory::root(),
141 name, false, BOOKMARKS, &metahandle); 109 name, false, model_type, &metahandle);
142 110
143 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); 111 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
144 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle); 112 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle);
145 if (!entry.good()) { 113 if (!entry.good()) {
146 NOTREACHED(); 114 NOTREACHED();
147 return syncable::kInvalidMetaHandle; 115 return syncable::kInvalidMetaHandle;
148 } 116 }
149 117
150 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); 118 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
151 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); 119 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
152 120
153 return metahandle; 121 return metahandle;
154 } 122 }
155 123
156 int64 TestEntryFactory::CreateSyncedItem( 124 int64 TestEntryFactory::CreateSyncedItem(
157 const std::string& name, ModelType model_type, bool is_folder) { 125 const std::string& name, ModelType model_type, bool is_folder) {
158 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); 126 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
159 127
160 syncable::Id parent_id(TestIdFactory::root()); 128 syncable::Id parent_id(TestIdFactory::root());
161 syncable::Id item_id(TestIdFactory::MakeServer(name)); 129 syncable::Id item_id(TestIdFactory::MakeServer(name));
162 int64 version = GetNextRevision(); 130 int64 version = GetNextRevision();
163 131
164 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); 132 sync_pb::EntitySpecifics default_specifics;
133 AddDefaultFieldValue(model_type, &default_specifics);
134
135 MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
165 if (!entry.good()) { 136 if (!entry.good()) {
166 NOTREACHED(); 137 NOTREACHED();
167 return syncable::kInvalidMetaHandle; 138 return syncable::kInvalidMetaHandle;
168 } 139 }
169 140
170 entry.Put(syncable::ID, item_id); 141 entry.Put(syncable::ID, item_id);
171 entry.Put(syncable::BASE_VERSION, version); 142 entry.Put(syncable::BASE_VERSION, version);
172 entry.Put(syncable::IS_UNSYNCED, false); 143 entry.Put(syncable::IS_UNSYNCED, false);
173 entry.Put(syncable::NON_UNIQUE_NAME, name); 144 entry.Put(syncable::NON_UNIQUE_NAME, name);
174 entry.Put(syncable::IS_DIR, is_folder); 145 entry.Put(syncable::IS_DIR, is_folder);
175 entry.Put(syncable::IS_DEL, false); 146 entry.Put(syncable::IS_DEL, false);
176 entry.Put(syncable::PARENT_ID, parent_id); 147 entry.Put(syncable::PARENT_ID, parent_id);
177 148
178 // TODO(sync): Place bookmarks at the end of the list?
179 if (!entry.PutPredecessor(TestIdFactory::root())) { 149 if (!entry.PutPredecessor(TestIdFactory::root())) {
180 NOTREACHED(); 150 NOTREACHED();
181 return syncable::kInvalidMetaHandle; 151 return syncable::kInvalidMetaHandle;
182 } 152 }
153 entry.Put(syncable::SPECIFICS, default_specifics);
183 154
184 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); 155 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
185 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); 156 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
186 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, name); 157 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X");
187 entry.Put(syncable::SERVER_PARENT_ID, parent_id); 158 entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y"));
188 entry.Put(syncable::SERVER_IS_DIR, is_folder); 159 entry.Put(syncable::SERVER_IS_DIR, is_folder);
189 entry.Put(syncable::SERVER_IS_DEL, false); 160 entry.Put(syncable::SERVER_IS_DEL, false);
190 entry.Put(syncable::SERVER_SPECIFICS, entry.Get(syncable::SPECIFICS)); 161 entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
162 entry.Put(syncable::SERVER_PARENT_ID, parent_id);
191 163
192 return entry.Get(syncable::META_HANDLE); 164 return entry.Get(syncable::META_HANDLE);
193 } 165 }
194 166
195 int64 TestEntryFactory::CreateUnappliedRootNode( 167 int64 TestEntryFactory::CreateUnappliedRootNode(
196 ModelType model_type) { 168 ModelType model_type) {
197 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory_); 169 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory_);
198 sync_pb::EntitySpecifics specifics; 170 sync_pb::EntitySpecifics specifics;
199 AddDefaultFieldValue(model_type, &specifics); 171 AddDefaultFieldValue(model_type, &specifics);
200 syncable::Id node_id = TestIdFactory::MakeServer("xyz"); 172 syncable::Id node_id = TestIdFactory::MakeServer("xyz");
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return false; 246 return false;
275 } 247 }
276 return entry.Get(syncable::IS_UNAPPLIED_UPDATE); 248 return entry.Get(syncable::IS_UNAPPLIED_UPDATE);
277 } 249 }
278 250
279 int64 TestEntryFactory::GetNextRevision() { 251 int64 TestEntryFactory::GetNextRevision() {
280 return next_revision_++; 252 return next_revision_++;
281 } 253 }
282 254
283 } // namespace syncer 255 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl_unittest.cc ('k') | sync/internal_api/write_node.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698