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

Side by Side Diff: chrome/browser/sync/syncable/syncable_unittest.cc

Issue 7190001: [Sync] Split DirectoryChangeListener for thread-safety (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix copyright Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
11 #include <limits> 11 #include <limits>
12 #include <string> 12 #include <string>
13 13
14 #if !defined(OS_WIN) 14 #if !defined(OS_WIN)
15 #define MAX_PATH PATH_MAX 15 #define MAX_PATH PATH_MAX
16 #include <ostream> 16 #include <ostream>
17 #include <stdio.h> 17 #include <stdio.h>
18 #include <sys/ipc.h> 18 #include <sys/ipc.h>
19 #include <sys/sem.h> 19 #include <sys/sem.h>
20 #include <sys/times.h> 20 #include <sys/times.h>
21 #endif // !defined(OS_WIN) 21 #endif // !defined(OS_WIN)
22 22
23 #include "base/compiler_specific.h"
23 #include "base/file_path.h" 24 #include "base/file_path.h"
24 #include "base/file_util.h" 25 #include "base/file_util.h"
25 #include "base/logging.h" 26 #include "base/logging.h"
26 #include "base/memory/scoped_ptr.h" 27 #include "base/memory/scoped_ptr.h"
27 #include "base/scoped_temp_dir.h" 28 #include "base/scoped_temp_dir.h"
28 #include "base/stringprintf.h" 29 #include "base/stringprintf.h"
29 #include "base/threading/platform_thread.h" 30 #include "base/threading/platform_thread.h"
31 #include "base/tracked.h"
30 #include "base/values.h" 32 #include "base/values.h"
31 #include "chrome/browser/sync/engine/syncproto.h" 33 #include "chrome/browser/sync/engine/syncproto.h"
32 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 34 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
33 #include "chrome/browser/sync/syncable/directory_backing_store.h" 35 #include "chrome/browser/sync/syncable/directory_backing_store.h"
36 #include "chrome/browser/sync/syncable/directory_change_delegate.h"
34 #include "chrome/browser/sync/syncable/directory_manager.h" 37 #include "chrome/browser/sync/syncable/directory_manager.h"
35 #include "chrome/common/deprecated/event_sys-inl.h" 38 #include "chrome/common/deprecated/event_sys-inl.h"
36 #include "chrome/test/sync/engine/test_id_factory.h" 39 #include "chrome/test/sync/engine/test_id_factory.h"
37 #include "chrome/test/sync/engine/test_syncable_utils.h" 40 #include "chrome/test/sync/engine/test_syncable_utils.h"
41 #include "chrome/test/sync/null_directory_change_delegate.h"
38 #include "chrome/test/values_test_util.h" 42 #include "chrome/test/values_test_util.h"
39 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
40 #include "third_party/sqlite/sqlite3.h" 44 #include "third_party/sqlite/sqlite3.h"
41 45
42 using browser_sync::TestIdFactory; 46 using browser_sync::TestIdFactory;
43 using test::ExpectDictBooleanValue; 47 using test::ExpectDictBooleanValue;
44 using test::ExpectDictStringValue; 48 using test::ExpectDictStringValue;
45 49
46 namespace syncable { 50 namespace syncable {
47 51
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 virtual void SetUp() { 97 virtual void SetUp() {
94 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 98 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
95 db_path_ = temp_dir_.path().Append( 99 db_path_ = temp_dir_.path().Append(
96 FILE_PATH_LITERAL("SyncableTest.sqlite3")); 100 FILE_PATH_LITERAL("SyncableTest.sqlite3"));
97 } 101 }
98 102
99 virtual void TearDown() { 103 virtual void TearDown() {
100 } 104 }
101 protected: 105 protected:
102 ScopedTempDir temp_dir_; 106 ScopedTempDir temp_dir_;
107 NullDirectoryChangeDelegate delegate_;
103 FilePath db_path_; 108 FilePath db_path_;
104 }; 109 };
105 110
106 TEST_F(SyncableGeneralTest, General) { 111 TEST_F(SyncableGeneralTest, General) {
107 Directory dir; 112 Directory dir;
108 dir.Open(db_path_, "SimpleTest"); 113 dir.Open(db_path_, "SimpleTest", &delegate_);
109 114
110 int64 root_metahandle; 115 int64 root_metahandle;
111 { 116 {
112 ReadTransaction rtrans(&dir, __FILE__, __LINE__); 117 ReadTransaction rtrans(&dir, FROM_HERE);
113 Entry e(&rtrans, GET_BY_ID, rtrans.root_id()); 118 Entry e(&rtrans, GET_BY_ID, rtrans.root_id());
114 ASSERT_TRUE(e.good()); 119 ASSERT_TRUE(e.good());
115 root_metahandle = e.Get(META_HANDLE); 120 root_metahandle = e.Get(META_HANDLE);
116 } 121 }
117 122
118 int64 written_metahandle; 123 int64 written_metahandle;
119 const Id id = TestIdFactory::FromNumber(99); 124 const Id id = TestIdFactory::FromNumber(99);
120 std::string name = "Jeff"; 125 std::string name = "Jeff";
121 // Test simple read operations on an empty DB. 126 // Test simple read operations on an empty DB.
122 { 127 {
123 ReadTransaction rtrans(&dir, __FILE__, __LINE__); 128 ReadTransaction rtrans(&dir, FROM_HERE);
124 Entry e(&rtrans, GET_BY_ID, id); 129 Entry e(&rtrans, GET_BY_ID, id);
125 ASSERT_FALSE(e.good()); // Hasn't been written yet. 130 ASSERT_FALSE(e.good()); // Hasn't been written yet.
126 131
127 Directory::ChildHandles child_handles; 132 Directory::ChildHandles child_handles;
128 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); 133 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles);
129 EXPECT_TRUE(child_handles.empty()); 134 EXPECT_TRUE(child_handles.empty());
130 135
131 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); 136 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles);
132 EXPECT_TRUE(child_handles.empty()); 137 EXPECT_TRUE(child_handles.empty());
133 } 138 }
134 139
135 // Test creating a new meta entry. 140 // Test creating a new meta entry.
136 { 141 {
137 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__); 142 WriteTransaction wtrans(&dir, UNITTEST, FROM_HERE);
138 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); 143 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name);
139 ASSERT_TRUE(me.good()); 144 ASSERT_TRUE(me.good());
140 me.Put(ID, id); 145 me.Put(ID, id);
141 me.Put(BASE_VERSION, 1); 146 me.Put(BASE_VERSION, 1);
142 written_metahandle = me.Get(META_HANDLE); 147 written_metahandle = me.Get(META_HANDLE);
143 } 148 }
144 149
145 // Test GetChildHandles* after something is now in the DB. 150 // Test GetChildHandles* after something is now in the DB.
146 // Also check that GET_BY_ID works. 151 // Also check that GET_BY_ID works.
147 { 152 {
148 ReadTransaction rtrans(&dir, __FILE__, __LINE__); 153 ReadTransaction rtrans(&dir, FROM_HERE);
149 Entry e(&rtrans, GET_BY_ID, id); 154 Entry e(&rtrans, GET_BY_ID, id);
150 ASSERT_TRUE(e.good()); 155 ASSERT_TRUE(e.good());
151 156
152 Directory::ChildHandles child_handles; 157 Directory::ChildHandles child_handles;
153 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); 158 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles);
154 EXPECT_EQ(1u, child_handles.size()); 159 EXPECT_EQ(1u, child_handles.size());
155 160
156 for (Directory::ChildHandles::iterator i = child_handles.begin(); 161 for (Directory::ChildHandles::iterator i = child_handles.begin();
157 i != child_handles.end(); ++i) { 162 i != child_handles.end(); ++i) {
158 EXPECT_EQ(*i, written_metahandle); 163 EXPECT_EQ(*i, written_metahandle);
159 } 164 }
160 165
161 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); 166 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles);
162 EXPECT_EQ(1u, child_handles.size()); 167 EXPECT_EQ(1u, child_handles.size());
163 168
164 for (Directory::ChildHandles::iterator i = child_handles.begin(); 169 for (Directory::ChildHandles::iterator i = child_handles.begin();
165 i != child_handles.end(); ++i) { 170 i != child_handles.end(); ++i) {
166 EXPECT_EQ(*i, written_metahandle); 171 EXPECT_EQ(*i, written_metahandle);
167 } 172 }
168 } 173 }
169 174
170 // Test writing data to an entity. Also check that GET_BY_HANDLE works. 175 // Test writing data to an entity. Also check that GET_BY_HANDLE works.
171 static const char s[] = "Hello World."; 176 static const char s[] = "Hello World.";
172 { 177 {
173 WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); 178 WriteTransaction trans(&dir, UNITTEST, FROM_HERE);
174 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); 179 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle);
175 ASSERT_TRUE(e.good()); 180 ASSERT_TRUE(e.good());
176 PutDataAsBookmarkFavicon(&trans, &e, s, sizeof(s)); 181 PutDataAsBookmarkFavicon(&trans, &e, s, sizeof(s));
177 } 182 }
178 183
179 // Test reading back the contents that we just wrote. 184 // Test reading back the contents that we just wrote.
180 { 185 {
181 WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); 186 WriteTransaction trans(&dir, UNITTEST, FROM_HERE);
182 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); 187 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle);
183 ASSERT_TRUE(e.good()); 188 ASSERT_TRUE(e.good());
184 ExpectDataFromBookmarkFaviconEquals(&trans, &e, s, sizeof(s)); 189 ExpectDataFromBookmarkFaviconEquals(&trans, &e, s, sizeof(s));
185 } 190 }
186 191
187 // Verify it exists in the folder. 192 // Verify it exists in the folder.
188 { 193 {
189 ReadTransaction rtrans(&dir, __FILE__, __LINE__); 194 ReadTransaction rtrans(&dir, FROM_HERE);
190 EXPECT_EQ(1, CountEntriesWithName(&rtrans, rtrans.root_id(), name)); 195 EXPECT_EQ(1, CountEntriesWithName(&rtrans, rtrans.root_id(), name));
191 } 196 }
192 197
193 // Now delete it. 198 // Now delete it.
194 { 199 {
195 WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); 200 WriteTransaction trans(&dir, UNITTEST, FROM_HERE);
196 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); 201 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle);
197 e.Put(IS_DEL, true); 202 e.Put(IS_DEL, true);
198 203
199 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name)); 204 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name));
200 } 205 }
201 206
202 dir.SaveChanges(); 207 dir.SaveChanges();
203 } 208 }
204 209
205 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) { 210 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) {
206 int64 written_metahandle; 211 int64 written_metahandle;
207 TestIdFactory factory; 212 TestIdFactory factory;
208 const Id id = factory.NewServerId(); 213 const Id id = factory.NewServerId();
209 std::string name = "cheesepuffs"; 214 std::string name = "cheesepuffs";
210 std::string tag = "dietcoke"; 215 std::string tag = "dietcoke";
211 216
212 // Test creating a new meta entry. 217 // Test creating a new meta entry.
213 { 218 {
214 Directory dir; 219 Directory dir;
215 dir.Open(db_path_, "IndexTest"); 220 dir.Open(db_path_, "IndexTest", &delegate_);
216 { 221 {
217 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__); 222 WriteTransaction wtrans(&dir, UNITTEST, FROM_HERE);
218 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); 223 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name);
219 ASSERT_TRUE(me.good()); 224 ASSERT_TRUE(me.good());
220 me.Put(ID, id); 225 me.Put(ID, id);
221 me.Put(BASE_VERSION, 1); 226 me.Put(BASE_VERSION, 1);
222 me.Put(UNIQUE_CLIENT_TAG, tag); 227 me.Put(UNIQUE_CLIENT_TAG, tag);
223 written_metahandle = me.Get(META_HANDLE); 228 written_metahandle = me.Get(META_HANDLE);
224 } 229 }
225 dir.SaveChanges(); 230 dir.SaveChanges();
226 } 231 }
227 232
228 // The DB was closed. Now reopen it. This will cause index regeneration. 233 // The DB was closed. Now reopen it. This will cause index regeneration.
229 { 234 {
230 Directory dir; 235 Directory dir;
231 dir.Open(db_path_, "IndexTest"); 236 dir.Open(db_path_, "IndexTest", &delegate_);
232 237
233 ReadTransaction trans(&dir, __FILE__, __LINE__); 238 ReadTransaction trans(&dir, FROM_HERE);
234 Entry me(&trans, GET_BY_CLIENT_TAG, tag); 239 Entry me(&trans, GET_BY_CLIENT_TAG, tag);
235 ASSERT_TRUE(me.good()); 240 ASSERT_TRUE(me.good());
236 EXPECT_EQ(me.Get(ID), id); 241 EXPECT_EQ(me.Get(ID), id);
237 EXPECT_EQ(me.Get(BASE_VERSION), 1); 242 EXPECT_EQ(me.Get(BASE_VERSION), 1);
238 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag); 243 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag);
239 EXPECT_EQ(me.Get(META_HANDLE), written_metahandle); 244 EXPECT_EQ(me.Get(META_HANDLE), written_metahandle);
240 } 245 }
241 } 246 }
242 247
243 TEST_F(SyncableGeneralTest, ClientIndexRebuildsDeletedProperly) { 248 TEST_F(SyncableGeneralTest, ClientIndexRebuildsDeletedProperly) {
244 TestIdFactory factory; 249 TestIdFactory factory;
245 const Id id = factory.NewServerId(); 250 const Id id = factory.NewServerId();
246 std::string tag = "dietcoke"; 251 std::string tag = "dietcoke";
247 252
248 // Test creating a deleted, unsynced, server meta entry. 253 // Test creating a deleted, unsynced, server meta entry.
249 { 254 {
250 Directory dir; 255 Directory dir;
251 dir.Open(db_path_, "IndexTest"); 256 dir.Open(db_path_, "IndexTest", &delegate_);
252 { 257 {
253 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__); 258 WriteTransaction wtrans(&dir, UNITTEST, FROM_HERE);
254 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "deleted"); 259 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "deleted");
255 ASSERT_TRUE(me.good()); 260 ASSERT_TRUE(me.good());
256 me.Put(ID, id); 261 me.Put(ID, id);
257 me.Put(BASE_VERSION, 1); 262 me.Put(BASE_VERSION, 1);
258 me.Put(UNIQUE_CLIENT_TAG, tag); 263 me.Put(UNIQUE_CLIENT_TAG, tag);
259 me.Put(IS_DEL, true); 264 me.Put(IS_DEL, true);
260 me.Put(IS_UNSYNCED, true); // Or it might be purged. 265 me.Put(IS_UNSYNCED, true); // Or it might be purged.
261 } 266 }
262 dir.SaveChanges(); 267 dir.SaveChanges();
263 } 268 }
264 269
265 // The DB was closed. Now reopen it. This will cause index regeneration. 270 // The DB was closed. Now reopen it. This will cause index regeneration.
266 // Should still be present and valid in the client tag index. 271 // Should still be present and valid in the client tag index.
267 { 272 {
268 Directory dir; 273 Directory dir;
269 dir.Open(db_path_, "IndexTest"); 274 dir.Open(db_path_, "IndexTest", &delegate_);
270 275
271 ReadTransaction trans(&dir, __FILE__, __LINE__); 276 ReadTransaction trans(&dir, FROM_HERE);
272 Entry me(&trans, GET_BY_CLIENT_TAG, tag); 277 Entry me(&trans, GET_BY_CLIENT_TAG, tag);
273 ASSERT_TRUE(me.good()); 278 ASSERT_TRUE(me.good());
274 EXPECT_EQ(me.Get(ID), id); 279 EXPECT_EQ(me.Get(ID), id);
275 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag); 280 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag);
276 EXPECT_TRUE(me.Get(IS_DEL)); 281 EXPECT_TRUE(me.Get(IS_DEL));
277 EXPECT_TRUE(me.Get(IS_UNSYNCED)); 282 EXPECT_TRUE(me.Get(IS_UNSYNCED));
278 } 283 }
279 } 284 }
280 285
281 TEST_F(SyncableGeneralTest, ToValue) { 286 TEST_F(SyncableGeneralTest, ToValue) {
282 Directory dir; 287 Directory dir;
283 dir.Open(db_path_, "SimpleTest"); 288 dir.Open(db_path_, "SimpleTest", &delegate_);
284 289
285 const Id id = TestIdFactory::FromNumber(99); 290 const Id id = TestIdFactory::FromNumber(99);
286 { 291 {
287 ReadTransaction rtrans(&dir, __FILE__, __LINE__); 292 ReadTransaction rtrans(&dir, FROM_HERE);
288 Entry e(&rtrans, GET_BY_ID, id); 293 Entry e(&rtrans, GET_BY_ID, id);
289 EXPECT_FALSE(e.good()); // Hasn't been written yet. 294 EXPECT_FALSE(e.good()); // Hasn't been written yet.
290 295
291 scoped_ptr<DictionaryValue> value(e.ToValue()); 296 scoped_ptr<DictionaryValue> value(e.ToValue());
292 ExpectDictBooleanValue(false, *value, "good"); 297 ExpectDictBooleanValue(false, *value, "good");
293 EXPECT_EQ(1u, value->size()); 298 EXPECT_EQ(1u, value->size());
294 } 299 }
295 300
296 // Test creating a new meta entry. 301 // Test creating a new meta entry.
297 { 302 {
298 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__); 303 WriteTransaction wtrans(&dir, UNITTEST, FROM_HERE);
299 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "new"); 304 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "new");
300 ASSERT_TRUE(me.good()); 305 ASSERT_TRUE(me.good());
301 me.Put(ID, id); 306 me.Put(ID, id);
302 me.Put(BASE_VERSION, 1); 307 me.Put(BASE_VERSION, 1);
303 308
304 scoped_ptr<DictionaryValue> value(me.ToValue()); 309 scoped_ptr<DictionaryValue> value(me.ToValue());
305 ExpectDictBooleanValue(true, *value, "good"); 310 ExpectDictBooleanValue(true, *value, "good");
306 EXPECT_TRUE(value->HasKey("kernel")); 311 EXPECT_TRUE(value->HasKey("kernel"));
307 ExpectDictStringValue("Unspecified", *value, "serverModelType"); 312 ExpectDictStringValue("Unspecified", *value, "serverModelType");
308 ExpectDictStringValue("Unspecified", *value, "modelType"); 313 ExpectDictStringValue("Unspecified", *value, "modelType");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 347
343 // SetUp() is called before each test case is run. 348 // SetUp() is called before each test case is run.
344 // The sqlite3 DB is deleted before each test is run. 349 // The sqlite3 DB is deleted before each test is run.
345 virtual void SetUp() { 350 virtual void SetUp() {
346 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 351 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
347 file_path_ = temp_dir_.path().Append( 352 file_path_ = temp_dir_.path().Append(
348 FILE_PATH_LITERAL("Test.sqlite3")); 353 FILE_PATH_LITERAL("Test.sqlite3"));
349 file_util::Delete(file_path_, true); 354 file_util::Delete(file_path_, true);
350 dir_.reset(new Directory()); 355 dir_.reset(new Directory());
351 ASSERT_TRUE(dir_.get()); 356 ASSERT_TRUE(dir_.get());
352 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName)); 357 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName, &delegate_));
353 ASSERT_TRUE(dir_->good()); 358 ASSERT_TRUE(dir_->good());
354 } 359 }
355 360
356 virtual void TearDown() { 361 virtual void TearDown() {
357 // This also closes file handles. 362 // This also closes file handles.
358 dir_->SaveChanges(); 363 dir_->SaveChanges();
359 dir_.reset(); 364 dir_.reset();
360 file_util::Delete(file_path_, true); 365 file_util::Delete(file_path_, true);
361 } 366 }
362 367
363 void ReloadDir() { 368 void ReloadDir() {
364 dir_.reset(new Directory()); 369 dir_.reset(new Directory());
365 ASSERT_TRUE(dir_.get()); 370 ASSERT_TRUE(dir_.get());
366 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName)); 371 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName, &delegate_));
367 } 372 }
368 373
369 void SaveAndReloadDir() { 374 void SaveAndReloadDir() {
370 dir_->SaveChanges(); 375 dir_->SaveChanges();
371 ReloadDir(); 376 ReloadDir();
372 } 377 }
373 378
374 bool IsInDirtyMetahandles(int64 metahandle) { 379 bool IsInDirtyMetahandles(int64 metahandle) {
375 return 1 == dir_->kernel_->dirty_metahandles->count(metahandle); 380 return 1 == dir_->kernel_->dirty_metahandles->count(metahandle);
376 } 381 }
377 382
378 bool IsInMetahandlesToPurge(int64 metahandle) { 383 bool IsInMetahandlesToPurge(int64 metahandle) {
379 return 1 == dir_->kernel_->metahandles_to_purge->count(metahandle); 384 return 1 == dir_->kernel_->metahandles_to_purge->count(metahandle);
380 } 385 }
381 386
382 void CheckPurgeEntriesWithTypeInSucceeded(const ModelTypeSet& types_to_purge, 387 void CheckPurgeEntriesWithTypeInSucceeded(const ModelTypeSet& types_to_purge,
383 bool before_reload) { 388 bool before_reload) {
384 SCOPED_TRACE(testing::Message("Before reload: ") << before_reload); 389 SCOPED_TRACE(testing::Message("Before reload: ") << before_reload);
385 { 390 {
386 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 391 ReadTransaction trans(dir_.get(), FROM_HERE);
387 MetahandleSet all_set; 392 MetahandleSet all_set;
388 dir_->GetAllMetaHandles(&trans, &all_set); 393 dir_->GetAllMetaHandles(&trans, &all_set);
389 EXPECT_EQ(3U, all_set.size()); 394 EXPECT_EQ(3U, all_set.size());
390 if (before_reload) 395 if (before_reload)
391 EXPECT_EQ(4U, dir_->kernel_->metahandles_to_purge->size()); 396 EXPECT_EQ(4U, dir_->kernel_->metahandles_to_purge->size());
392 for (MetahandleSet::iterator iter = all_set.begin(); 397 for (MetahandleSet::iterator iter = all_set.begin();
393 iter != all_set.end(); ++iter) { 398 iter != all_set.end(); ++iter) {
394 Entry e(&trans, GET_BY_HANDLE, *iter); 399 Entry e(&trans, GET_BY_HANDLE, *iter);
395 if ((types_to_purge.count(e.GetModelType()) || 400 if ((types_to_purge.count(e.GetModelType()) ||
396 types_to_purge.count(e.GetServerModelType()))) { 401 types_to_purge.count(e.GetServerModelType()))) {
397 FAIL() << "Illegal type should have been deleted."; 402 FAIL() << "Illegal type should have been deleted.";
398 } 403 }
399 } 404 }
400 } 405 }
401 406
402 EXPECT_FALSE(dir_->initial_sync_ended_for_type(PREFERENCES)); 407 EXPECT_FALSE(dir_->initial_sync_ended_for_type(PREFERENCES));
403 EXPECT_FALSE(dir_->initial_sync_ended_for_type(AUTOFILL)); 408 EXPECT_FALSE(dir_->initial_sync_ended_for_type(AUTOFILL));
404 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS)); 409 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS));
405 } 410 }
406 411
407 scoped_ptr<Directory> dir_; 412 scoped_ptr<Directory> dir_;
408 FilePath file_path_; 413 FilePath file_path_;
414 NullDirectoryChangeDelegate delegate_;
409 415
410 // Creates an empty entry and sets the ID field to the default kId. 416 // Creates an empty entry and sets the ID field to the default kId.
411 void CreateEntry(const std::string& entryname) { 417 void CreateEntry(const std::string& entryname) {
412 CreateEntry(entryname, kId); 418 CreateEntry(entryname, kId);
413 } 419 }
414 420
415 // Creates an empty entry and sets the ID field to id. 421 // Creates an empty entry and sets the ID field to id.
416 void CreateEntry(const std::string& entryname, const int id) { 422 void CreateEntry(const std::string& entryname, const int id) {
417 CreateEntry(entryname, TestIdFactory::FromNumber(id)); 423 CreateEntry(entryname, TestIdFactory::FromNumber(id));
418 } 424 }
419 void CreateEntry(const std::string& entryname, Id id) { 425 void CreateEntry(const std::string& entryname, Id id) {
420 WriteTransaction wtrans(dir_.get(), UNITTEST, __FILE__, __LINE__); 426 WriteTransaction wtrans(dir_.get(), UNITTEST, FROM_HERE);
421 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), entryname); 427 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), entryname);
422 ASSERT_TRUE(me.good()); 428 ASSERT_TRUE(me.good());
423 me.Put(ID, id); 429 me.Put(ID, id);
424 me.Put(IS_UNSYNCED, true); 430 me.Put(IS_UNSYNCED, true);
425 } 431 }
426 432
427 void ValidateEntry(BaseTransaction* trans, 433 void ValidateEntry(BaseTransaction* trans,
428 int64 id, 434 int64 id,
429 bool check_name, 435 bool check_name,
430 const std::string& name, 436 const std::string& name,
431 int64 base_version, 437 int64 base_version,
432 int64 server_version, 438 int64 server_version,
433 bool is_del); 439 bool is_del);
434 }; 440 };
435 441
436 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) { 442 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) {
437 const int metas_to_create = 50; 443 const int metas_to_create = 50;
438 MetahandleSet expected_purges; 444 MetahandleSet expected_purges;
439 MetahandleSet all_handles; 445 MetahandleSet all_handles;
440 { 446 {
441 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 447 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
442 for (int i = 0; i < metas_to_create; i++) { 448 for (int i = 0; i < metas_to_create; i++) {
443 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); 449 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
444 e.Put(IS_UNSYNCED, true); 450 e.Put(IS_UNSYNCED, true);
445 sync_pb::EntitySpecifics specs; 451 sync_pb::EntitySpecifics specs;
446 if (i % 2 == 0) { 452 if (i % 2 == 0) {
447 AddDefaultExtensionValue(BOOKMARKS, &specs); 453 AddDefaultExtensionValue(BOOKMARKS, &specs);
448 expected_purges.insert(e.Get(META_HANDLE)); 454 expected_purges.insert(e.Get(META_HANDLE));
449 all_handles.insert(e.Get(META_HANDLE)); 455 all_handles.insert(e.Get(META_HANDLE));
450 } else { 456 } else {
451 AddDefaultExtensionValue(PREFERENCES, &specs); 457 AddDefaultExtensionValue(PREFERENCES, &specs);
(...skipping 21 matching lines...) Expand all
473 479
474 Directory::SaveChangesSnapshot snapshot2; 480 Directory::SaveChangesSnapshot snapshot2;
475 dir_->TakeSnapshotForSaveChanges(&snapshot2); 481 dir_->TakeSnapshotForSaveChanges(&snapshot2);
476 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge); 482 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge);
477 } 483 }
478 484
479 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { 485 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) {
480 const int metahandles_to_create = 100; 486 const int metahandles_to_create = 100;
481 std::vector<int64> expected_dirty_metahandles; 487 std::vector<int64> expected_dirty_metahandles;
482 { 488 {
483 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 489 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
484 for (int i = 0; i < metahandles_to_create; i++) { 490 for (int i = 0; i < metahandles_to_create; i++) {
485 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); 491 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
486 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); 492 expected_dirty_metahandles.push_back(e.Get(META_HANDLE));
487 e.Put(IS_UNSYNCED, true); 493 e.Put(IS_UNSYNCED, true);
488 } 494 }
489 } 495 }
490 // Fake SaveChanges() and make sure we got what we expected. 496 // Fake SaveChanges() and make sure we got what we expected.
491 { 497 {
492 Directory::SaveChangesSnapshot snapshot; 498 Directory::SaveChangesSnapshot snapshot;
493 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); 499 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
494 dir_->TakeSnapshotForSaveChanges(&snapshot); 500 dir_->TakeSnapshotForSaveChanges(&snapshot);
495 // Make sure there's an entry for each new metahandle. Make sure all 501 // Make sure there's an entry for each new metahandle. Make sure all
496 // entries are marked dirty. 502 // entries are marked dirty.
497 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); 503 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size());
498 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin(); 504 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin();
499 i != snapshot.dirty_metas.end(); ++i) { 505 i != snapshot.dirty_metas.end(); ++i) {
500 ASSERT_TRUE(i->is_dirty()); 506 ASSERT_TRUE(i->is_dirty());
501 } 507 }
502 dir_->VacuumAfterSaveChanges(snapshot); 508 dir_->VacuumAfterSaveChanges(snapshot);
503 } 509 }
504 // Put a new value with existing transactions as well as adding new ones. 510 // Put a new value with existing transactions as well as adding new ones.
505 { 511 {
506 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 512 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
507 std::vector<int64> new_dirty_metahandles; 513 std::vector<int64> new_dirty_metahandles;
508 for (std::vector<int64>::const_iterator i = 514 for (std::vector<int64>::const_iterator i =
509 expected_dirty_metahandles.begin(); 515 expected_dirty_metahandles.begin();
510 i != expected_dirty_metahandles.end(); ++i) { 516 i != expected_dirty_metahandles.end(); ++i) {
511 // Change existing entries to directories to dirty them. 517 // Change existing entries to directories to dirty them.
512 MutableEntry e1(&trans, GET_BY_HANDLE, *i); 518 MutableEntry e1(&trans, GET_BY_HANDLE, *i);
513 e1.Put(IS_DIR, true); 519 e1.Put(IS_DIR, true);
514 e1.Put(IS_UNSYNCED, true); 520 e1.Put(IS_UNSYNCED, true);
515 // Add new entries 521 // Add new entries
516 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar"); 522 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar");
(...skipping 30 matching lines...) Expand all
547 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); 553 dir_->set_initial_sync_ended_for_type(PREFERENCES, true);
548 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); 554 dir_->set_initial_sync_ended_for_type(AUTOFILL, true);
549 555
550 std::set<ModelType> types_to_purge; 556 std::set<ModelType> types_to_purge;
551 types_to_purge.insert(PREFERENCES); 557 types_to_purge.insert(PREFERENCES);
552 types_to_purge.insert(AUTOFILL); 558 types_to_purge.insert(AUTOFILL);
553 559
554 TestIdFactory id_factory; 560 TestIdFactory id_factory;
555 // Create some items for each type. 561 // Create some items for each type.
556 { 562 {
557 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 563 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
558 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); 564 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item");
559 ASSERT_TRUE(item1.good()); 565 ASSERT_TRUE(item1.good());
560 item1.Put(SPECIFICS, bookmark_specs); 566 item1.Put(SPECIFICS, bookmark_specs);
561 item1.Put(SERVER_SPECIFICS, bookmark_specs); 567 item1.Put(SERVER_SPECIFICS, bookmark_specs);
562 item1.Put(IS_UNSYNCED, true); 568 item1.Put(IS_UNSYNCED, true);
563 569
564 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM, 570 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM,
565 id_factory.NewServerId()); 571 id_factory.NewServerId());
566 ASSERT_TRUE(item2.good()); 572 ASSERT_TRUE(item2.good());
567 item2.Put(SERVER_SPECIFICS, bookmark_specs); 573 item2.Put(SERVER_SPECIFICS, bookmark_specs);
(...skipping 19 matching lines...) Expand all
587 593
588 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM, 594 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM,
589 id_factory.NewServerId()); 595 id_factory.NewServerId());
590 ASSERT_TRUE(item6.good()); 596 ASSERT_TRUE(item6.good());
591 item6.Put(SERVER_SPECIFICS, autofill_specs); 597 item6.Put(SERVER_SPECIFICS, autofill_specs);
592 item6.Put(IS_UNAPPLIED_UPDATE, true); 598 item6.Put(IS_UNAPPLIED_UPDATE, true);
593 } 599 }
594 600
595 dir_->SaveChanges(); 601 dir_->SaveChanges();
596 { 602 {
597 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 603 ReadTransaction trans(dir_.get(), FROM_HERE);
598 MetahandleSet all_set; 604 MetahandleSet all_set;
599 dir_->GetAllMetaHandles(&trans, &all_set); 605 dir_->GetAllMetaHandles(&trans, &all_set);
600 ASSERT_EQ(7U, all_set.size()); 606 ASSERT_EQ(7U, all_set.size());
601 } 607 }
602 608
603 dir_->PurgeEntriesWithTypeIn(types_to_purge); 609 dir_->PurgeEntriesWithTypeIn(types_to_purge);
604 610
605 // We first query the in-memory data, and then reload the directory (without 611 // We first query the in-memory data, and then reload the directory (without
606 // saving) to verify that disk does not still have the data. 612 // saving) to verify that disk does not still have the data.
607 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, true); 613 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, true);
608 SaveAndReloadDir(); 614 SaveAndReloadDir();
609 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, false); 615 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, false);
610 } 616 }
611 617
612 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { 618 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) {
613 const int metahandles_to_create = 100; 619 const int metahandles_to_create = 100;
614 620
615 // half of 2 * metahandles_to_create 621 // half of 2 * metahandles_to_create
616 const unsigned int number_changed = 100u; 622 const unsigned int number_changed = 100u;
617 std::vector<int64> expected_dirty_metahandles; 623 std::vector<int64> expected_dirty_metahandles;
618 { 624 {
619 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 625 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
620 for (int i = 0; i < metahandles_to_create; i++) { 626 for (int i = 0; i < metahandles_to_create; i++) {
621 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); 627 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
622 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); 628 expected_dirty_metahandles.push_back(e.Get(META_HANDLE));
623 e.Put(IS_UNSYNCED, true); 629 e.Put(IS_UNSYNCED, true);
624 } 630 }
625 } 631 }
626 dir_->SaveChanges(); 632 dir_->SaveChanges();
627 // Put a new value with existing transactions as well as adding new ones. 633 // Put a new value with existing transactions as well as adding new ones.
628 { 634 {
629 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 635 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
630 std::vector<int64> new_dirty_metahandles; 636 std::vector<int64> new_dirty_metahandles;
631 for (std::vector<int64>::const_iterator i = 637 for (std::vector<int64>::const_iterator i =
632 expected_dirty_metahandles.begin(); 638 expected_dirty_metahandles.begin();
633 i != expected_dirty_metahandles.end(); ++i) { 639 i != expected_dirty_metahandles.end(); ++i) {
634 // Change existing entries to directories to dirty them. 640 // Change existing entries to directories to dirty them.
635 MutableEntry e1(&trans, GET_BY_HANDLE, *i); 641 MutableEntry e1(&trans, GET_BY_HANDLE, *i);
636 ASSERT_TRUE(e1.good()); 642 ASSERT_TRUE(e1.good());
637 e1.Put(IS_DIR, true); 643 e1.Put(IS_DIR, true);
638 e1.Put(IS_UNSYNCED, true); 644 e1.Put(IS_UNSYNCED, true);
639 // Add new entries 645 // Add new entries
640 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar"); 646 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar");
641 e2.Put(IS_UNSYNCED, true); 647 e2.Put(IS_UNSYNCED, true);
642 new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); 648 new_dirty_metahandles.push_back(e2.Get(META_HANDLE));
643 } 649 }
644 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), 650 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(),
645 new_dirty_metahandles.begin(), new_dirty_metahandles.end()); 651 new_dirty_metahandles.begin(), new_dirty_metahandles.end());
646 } 652 }
647 dir_->SaveChanges(); 653 dir_->SaveChanges();
648 // Don't make any changes whatsoever and ensure nothing comes back. 654 // Don't make any changes whatsoever and ensure nothing comes back.
649 { 655 {
650 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 656 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
651 for (std::vector<int64>::const_iterator i = 657 for (std::vector<int64>::const_iterator i =
652 expected_dirty_metahandles.begin(); 658 expected_dirty_metahandles.begin();
653 i != expected_dirty_metahandles.end(); ++i) { 659 i != expected_dirty_metahandles.end(); ++i) {
654 MutableEntry e(&trans, GET_BY_HANDLE, *i); 660 MutableEntry e(&trans, GET_BY_HANDLE, *i);
655 ASSERT_TRUE(e.good()); 661 ASSERT_TRUE(e.good());
656 // We aren't doing anything to dirty these entries. 662 // We aren't doing anything to dirty these entries.
657 } 663 }
658 } 664 }
659 // Fake SaveChanges() and make sure we got what we expected. 665 // Fake SaveChanges() and make sure we got what we expected.
660 { 666 {
661 Directory::SaveChangesSnapshot snapshot; 667 Directory::SaveChangesSnapshot snapshot;
662 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); 668 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
663 dir_->TakeSnapshotForSaveChanges(&snapshot); 669 dir_->TakeSnapshotForSaveChanges(&snapshot);
664 // Make sure there are no dirty_metahandles. 670 // Make sure there are no dirty_metahandles.
665 EXPECT_EQ(0u, snapshot.dirty_metas.size()); 671 EXPECT_EQ(0u, snapshot.dirty_metas.size());
666 dir_->VacuumAfterSaveChanges(snapshot); 672 dir_->VacuumAfterSaveChanges(snapshot);
667 } 673 }
668 { 674 {
669 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 675 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
670 bool should_change = false; 676 bool should_change = false;
671 for (std::vector<int64>::const_iterator i = 677 for (std::vector<int64>::const_iterator i =
672 expected_dirty_metahandles.begin(); 678 expected_dirty_metahandles.begin();
673 i != expected_dirty_metahandles.end(); ++i) { 679 i != expected_dirty_metahandles.end(); ++i) {
674 // Maybe change entries by flipping IS_DIR. 680 // Maybe change entries by flipping IS_DIR.
675 MutableEntry e(&trans, GET_BY_HANDLE, *i); 681 MutableEntry e(&trans, GET_BY_HANDLE, *i);
676 ASSERT_TRUE(e.good()); 682 ASSERT_TRUE(e.good());
677 should_change = !should_change; 683 should_change = !should_change;
678 if (should_change) { 684 if (should_change) {
679 bool not_dir = !e.Get(IS_DIR); 685 bool not_dir = !e.Get(IS_DIR);
(...skipping 16 matching lines...) Expand all
696 } 702 }
697 dir_->VacuumAfterSaveChanges(snapshot); 703 dir_->VacuumAfterSaveChanges(snapshot);
698 } 704 }
699 } 705 }
700 706
701 const char SyncableDirectoryTest::kName[] = "Foo"; 707 const char SyncableDirectoryTest::kName[] = "Foo";
702 const Id SyncableDirectoryTest::kId(TestIdFactory::FromNumber(-99)); 708 const Id SyncableDirectoryTest::kId(TestIdFactory::FromNumber(-99));
703 709
704 namespace { 710 namespace {
705 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) { 711 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) {
706 ReadTransaction rtrans(dir_.get(), __FILE__, __LINE__); 712 ReadTransaction rtrans(dir_.get(), FROM_HERE);
707 Entry e(&rtrans, GET_BY_ID, kId); 713 Entry e(&rtrans, GET_BY_ID, kId);
708 ASSERT_FALSE(e.good()); 714 ASSERT_FALSE(e.good());
709 } 715 }
710 716
711 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { 717 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) {
712 CreateEntry("rtc"); 718 CreateEntry("rtc");
713 ReadTransaction rtrans(dir_.get(), __FILE__, __LINE__); 719 ReadTransaction rtrans(dir_.get(), FROM_HERE);
714 Entry e(&rtrans, GET_BY_ID, kId); 720 Entry e(&rtrans, GET_BY_ID, kId);
715 ASSERT_TRUE(e.good()); 721 ASSERT_TRUE(e.good());
716 } 722 }
717 723
718 TEST_F(SyncableDirectoryTest, TestDelete) { 724 TEST_F(SyncableDirectoryTest, TestDelete) {
719 std::string name = "peanut butter jelly time"; 725 std::string name = "peanut butter jelly time";
720 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 726 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
721 MutableEntry e1(&trans, CREATE, trans.root_id(), name); 727 MutableEntry e1(&trans, CREATE, trans.root_id(), name);
722 ASSERT_TRUE(e1.good()); 728 ASSERT_TRUE(e1.good());
723 ASSERT_TRUE(e1.Put(IS_DEL, true)); 729 ASSERT_TRUE(e1.Put(IS_DEL, true));
724 MutableEntry e2(&trans, CREATE, trans.root_id(), name); 730 MutableEntry e2(&trans, CREATE, trans.root_id(), name);
725 ASSERT_TRUE(e2.good()); 731 ASSERT_TRUE(e2.good());
726 ASSERT_TRUE(e2.Put(IS_DEL, true)); 732 ASSERT_TRUE(e2.Put(IS_DEL, true));
727 MutableEntry e3(&trans, CREATE, trans.root_id(), name); 733 MutableEntry e3(&trans, CREATE, trans.root_id(), name);
728 ASSERT_TRUE(e3.good()); 734 ASSERT_TRUE(e3.good());
729 ASSERT_TRUE(e3.Put(IS_DEL, true)); 735 ASSERT_TRUE(e3.Put(IS_DEL, true));
730 736
731 ASSERT_TRUE(e1.Put(IS_DEL, false)); 737 ASSERT_TRUE(e1.Put(IS_DEL, false));
732 ASSERT_TRUE(e2.Put(IS_DEL, false)); 738 ASSERT_TRUE(e2.Put(IS_DEL, false));
733 ASSERT_TRUE(e3.Put(IS_DEL, false)); 739 ASSERT_TRUE(e3.Put(IS_DEL, false));
734 740
735 ASSERT_TRUE(e1.Put(IS_DEL, true)); 741 ASSERT_TRUE(e1.Put(IS_DEL, true));
736 ASSERT_TRUE(e2.Put(IS_DEL, true)); 742 ASSERT_TRUE(e2.Put(IS_DEL, true));
737 ASSERT_TRUE(e3.Put(IS_DEL, true)); 743 ASSERT_TRUE(e3.Put(IS_DEL, true));
738 } 744 }
739 745
740 TEST_F(SyncableDirectoryTest, TestGetUnsynced) { 746 TEST_F(SyncableDirectoryTest, TestGetUnsynced) {
741 Directory::UnsyncedMetaHandles handles; 747 Directory::UnsyncedMetaHandles handles;
742 int64 handle1, handle2; 748 int64 handle1, handle2;
743 { 749 {
744 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 750 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
745 751
746 dir_->GetUnsyncedMetaHandles(&trans, &handles); 752 dir_->GetUnsyncedMetaHandles(&trans, &handles);
747 ASSERT_TRUE(0 == handles.size()); 753 ASSERT_TRUE(0 == handles.size());
748 754
749 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); 755 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba");
750 ASSERT_TRUE(e1.good()); 756 ASSERT_TRUE(e1.good());
751 handle1 = e1.Get(META_HANDLE); 757 handle1 = e1.Get(META_HANDLE);
752 e1.Put(BASE_VERSION, 1); 758 e1.Put(BASE_VERSION, 1);
753 e1.Put(IS_DIR, true); 759 e1.Put(IS_DIR, true);
754 e1.Put(ID, TestIdFactory::FromNumber(101)); 760 e1.Put(ID, TestIdFactory::FromNumber(101));
755 761
756 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); 762 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread");
757 ASSERT_TRUE(e2.good()); 763 ASSERT_TRUE(e2.good());
758 handle2 = e2.Get(META_HANDLE); 764 handle2 = e2.Get(META_HANDLE);
759 e2.Put(BASE_VERSION, 1); 765 e2.Put(BASE_VERSION, 1);
760 e2.Put(ID, TestIdFactory::FromNumber(102)); 766 e2.Put(ID, TestIdFactory::FromNumber(102));
761 } 767 }
762 dir_->SaveChanges(); 768 dir_->SaveChanges();
763 { 769 {
764 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 770 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
765 771
766 dir_->GetUnsyncedMetaHandles(&trans, &handles); 772 dir_->GetUnsyncedMetaHandles(&trans, &handles);
767 ASSERT_TRUE(0 == handles.size()); 773 ASSERT_TRUE(0 == handles.size());
768 774
769 MutableEntry e3(&trans, GET_BY_HANDLE, handle1); 775 MutableEntry e3(&trans, GET_BY_HANDLE, handle1);
770 ASSERT_TRUE(e3.good()); 776 ASSERT_TRUE(e3.good());
771 e3.Put(IS_UNSYNCED, true); 777 e3.Put(IS_UNSYNCED, true);
772 } 778 }
773 dir_->SaveChanges(); 779 dir_->SaveChanges();
774 { 780 {
775 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 781 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
776 dir_->GetUnsyncedMetaHandles(&trans, &handles); 782 dir_->GetUnsyncedMetaHandles(&trans, &handles);
777 ASSERT_TRUE(1 == handles.size()); 783 ASSERT_TRUE(1 == handles.size());
778 ASSERT_TRUE(handle1 == handles[0]); 784 ASSERT_TRUE(handle1 == handles[0]);
779 785
780 MutableEntry e4(&trans, GET_BY_HANDLE, handle2); 786 MutableEntry e4(&trans, GET_BY_HANDLE, handle2);
781 ASSERT_TRUE(e4.good()); 787 ASSERT_TRUE(e4.good());
782 e4.Put(IS_UNSYNCED, true); 788 e4.Put(IS_UNSYNCED, true);
783 } 789 }
784 dir_->SaveChanges(); 790 dir_->SaveChanges();
785 { 791 {
786 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 792 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
787 dir_->GetUnsyncedMetaHandles(&trans, &handles); 793 dir_->GetUnsyncedMetaHandles(&trans, &handles);
788 ASSERT_TRUE(2 == handles.size()); 794 ASSERT_TRUE(2 == handles.size());
789 if (handle1 == handles[0]) { 795 if (handle1 == handles[0]) {
790 ASSERT_TRUE(handle2 == handles[1]); 796 ASSERT_TRUE(handle2 == handles[1]);
791 } else { 797 } else {
792 ASSERT_TRUE(handle2 == handles[0]); 798 ASSERT_TRUE(handle2 == handles[0]);
793 ASSERT_TRUE(handle1 == handles[1]); 799 ASSERT_TRUE(handle1 == handles[1]);
794 } 800 }
795 801
796 MutableEntry e5(&trans, GET_BY_HANDLE, handle1); 802 MutableEntry e5(&trans, GET_BY_HANDLE, handle1);
797 ASSERT_TRUE(e5.good()); 803 ASSERT_TRUE(e5.good());
798 ASSERT_TRUE(e5.Get(IS_UNSYNCED)); 804 ASSERT_TRUE(e5.Get(IS_UNSYNCED));
799 ASSERT_TRUE(e5.Put(IS_UNSYNCED, false)); 805 ASSERT_TRUE(e5.Put(IS_UNSYNCED, false));
800 ASSERT_FALSE(e5.Get(IS_UNSYNCED)); 806 ASSERT_FALSE(e5.Get(IS_UNSYNCED));
801 } 807 }
802 dir_->SaveChanges(); 808 dir_->SaveChanges();
803 { 809 {
804 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 810 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
805 dir_->GetUnsyncedMetaHandles(&trans, &handles); 811 dir_->GetUnsyncedMetaHandles(&trans, &handles);
806 ASSERT_TRUE(1 == handles.size()); 812 ASSERT_TRUE(1 == handles.size());
807 ASSERT_TRUE(handle2 == handles[0]); 813 ASSERT_TRUE(handle2 == handles[0]);
808 } 814 }
809 } 815 }
810 816
811 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { 817 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) {
812 Directory::UnappliedUpdateMetaHandles handles; 818 Directory::UnappliedUpdateMetaHandles handles;
813 int64 handle1, handle2; 819 int64 handle1, handle2;
814 { 820 {
815 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 821 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
816 822
817 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 823 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles);
818 ASSERT_TRUE(0 == handles.size()); 824 ASSERT_TRUE(0 == handles.size());
819 825
820 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); 826 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba");
821 ASSERT_TRUE(e1.good()); 827 ASSERT_TRUE(e1.good());
822 handle1 = e1.Get(META_HANDLE); 828 handle1 = e1.Get(META_HANDLE);
823 e1.Put(IS_UNAPPLIED_UPDATE, false); 829 e1.Put(IS_UNAPPLIED_UPDATE, false);
824 e1.Put(BASE_VERSION, 1); 830 e1.Put(BASE_VERSION, 1);
825 e1.Put(ID, TestIdFactory::FromNumber(101)); 831 e1.Put(ID, TestIdFactory::FromNumber(101));
826 e1.Put(IS_DIR, true); 832 e1.Put(IS_DIR, true);
827 833
828 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); 834 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread");
829 ASSERT_TRUE(e2.good()); 835 ASSERT_TRUE(e2.good());
830 handle2 = e2.Get(META_HANDLE); 836 handle2 = e2.Get(META_HANDLE);
831 e2.Put(IS_UNAPPLIED_UPDATE, false); 837 e2.Put(IS_UNAPPLIED_UPDATE, false);
832 e2.Put(BASE_VERSION, 1); 838 e2.Put(BASE_VERSION, 1);
833 e2.Put(ID, TestIdFactory::FromNumber(102)); 839 e2.Put(ID, TestIdFactory::FromNumber(102));
834 } 840 }
835 dir_->SaveChanges(); 841 dir_->SaveChanges();
836 { 842 {
837 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 843 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
838 844
839 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 845 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles);
840 ASSERT_TRUE(0 == handles.size()); 846 ASSERT_TRUE(0 == handles.size());
841 847
842 MutableEntry e3(&trans, GET_BY_HANDLE, handle1); 848 MutableEntry e3(&trans, GET_BY_HANDLE, handle1);
843 ASSERT_TRUE(e3.good()); 849 ASSERT_TRUE(e3.good());
844 e3.Put(IS_UNAPPLIED_UPDATE, true); 850 e3.Put(IS_UNAPPLIED_UPDATE, true);
845 } 851 }
846 dir_->SaveChanges(); 852 dir_->SaveChanges();
847 { 853 {
848 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 854 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
849 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 855 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles);
850 ASSERT_TRUE(1 == handles.size()); 856 ASSERT_TRUE(1 == handles.size());
851 ASSERT_TRUE(handle1 == handles[0]); 857 ASSERT_TRUE(handle1 == handles[0]);
852 858
853 MutableEntry e4(&trans, GET_BY_HANDLE, handle2); 859 MutableEntry e4(&trans, GET_BY_HANDLE, handle2);
854 ASSERT_TRUE(e4.good()); 860 ASSERT_TRUE(e4.good());
855 e4.Put(IS_UNAPPLIED_UPDATE, true); 861 e4.Put(IS_UNAPPLIED_UPDATE, true);
856 } 862 }
857 dir_->SaveChanges(); 863 dir_->SaveChanges();
858 { 864 {
859 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 865 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
860 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 866 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles);
861 ASSERT_TRUE(2 == handles.size()); 867 ASSERT_TRUE(2 == handles.size());
862 if (handle1 == handles[0]) { 868 if (handle1 == handles[0]) {
863 ASSERT_TRUE(handle2 == handles[1]); 869 ASSERT_TRUE(handle2 == handles[1]);
864 } else { 870 } else {
865 ASSERT_TRUE(handle2 == handles[0]); 871 ASSERT_TRUE(handle2 == handles[0]);
866 ASSERT_TRUE(handle1 == handles[1]); 872 ASSERT_TRUE(handle1 == handles[1]);
867 } 873 }
868 874
869 MutableEntry e5(&trans, GET_BY_HANDLE, handle1); 875 MutableEntry e5(&trans, GET_BY_HANDLE, handle1);
870 ASSERT_TRUE(e5.good()); 876 ASSERT_TRUE(e5.good());
871 e5.Put(IS_UNAPPLIED_UPDATE, false); 877 e5.Put(IS_UNAPPLIED_UPDATE, false);
872 } 878 }
873 dir_->SaveChanges(); 879 dir_->SaveChanges();
874 { 880 {
875 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 881 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
876 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 882 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles);
877 ASSERT_TRUE(1 == handles.size()); 883 ASSERT_TRUE(1 == handles.size());
878 ASSERT_TRUE(handle2 == handles[0]); 884 ASSERT_TRUE(handle2 == handles[0]);
879 } 885 }
880 } 886 }
881 887
882 888
883 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { 889 TEST_F(SyncableDirectoryTest, DeleteBug_531383) {
884 // Try to evoke a check failure... 890 // Try to evoke a check failure...
885 TestIdFactory id_factory; 891 TestIdFactory id_factory;
886 int64 grandchild_handle, twin_handle; 892 int64 grandchild_handle, twin_handle;
887 { 893 {
888 WriteTransaction wtrans(dir_.get(), UNITTEST, __FILE__, __LINE__); 894 WriteTransaction wtrans(dir_.get(), UNITTEST, FROM_HERE);
889 MutableEntry parent(&wtrans, CREATE, id_factory.root(), "Bob"); 895 MutableEntry parent(&wtrans, CREATE, id_factory.root(), "Bob");
890 ASSERT_TRUE(parent.good()); 896 ASSERT_TRUE(parent.good());
891 parent.Put(IS_DIR, true); 897 parent.Put(IS_DIR, true);
892 parent.Put(ID, id_factory.NewServerId()); 898 parent.Put(ID, id_factory.NewServerId());
893 parent.Put(BASE_VERSION, 1); 899 parent.Put(BASE_VERSION, 1);
894 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob"); 900 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob");
895 ASSERT_TRUE(child.good()); 901 ASSERT_TRUE(child.good());
896 child.Put(IS_DIR, true); 902 child.Put(IS_DIR, true);
897 child.Put(ID, id_factory.NewServerId()); 903 child.Put(ID, id_factory.NewServerId());
898 child.Put(BASE_VERSION, 1); 904 child.Put(BASE_VERSION, 1);
899 MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob"); 905 MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob");
900 ASSERT_TRUE(grandchild.good()); 906 ASSERT_TRUE(grandchild.good());
901 grandchild.Put(ID, id_factory.NewServerId()); 907 grandchild.Put(ID, id_factory.NewServerId());
902 grandchild.Put(BASE_VERSION, 1); 908 grandchild.Put(BASE_VERSION, 1);
903 ASSERT_TRUE(grandchild.Put(IS_DEL, true)); 909 ASSERT_TRUE(grandchild.Put(IS_DEL, true));
904 MutableEntry twin(&wtrans, CREATE, child.Get(ID), "Bob"); 910 MutableEntry twin(&wtrans, CREATE, child.Get(ID), "Bob");
905 ASSERT_TRUE(twin.good()); 911 ASSERT_TRUE(twin.good());
906 ASSERT_TRUE(twin.Put(IS_DEL, true)); 912 ASSERT_TRUE(twin.Put(IS_DEL, true));
907 ASSERT_TRUE(grandchild.Put(IS_DEL, false)); 913 ASSERT_TRUE(grandchild.Put(IS_DEL, false));
908 914
909 grandchild_handle = grandchild.Get(META_HANDLE); 915 grandchild_handle = grandchild.Get(META_HANDLE);
910 twin_handle = twin.Get(META_HANDLE); 916 twin_handle = twin.Get(META_HANDLE);
911 } 917 }
912 dir_->SaveChanges(); 918 dir_->SaveChanges();
913 { 919 {
914 WriteTransaction wtrans(dir_.get(), UNITTEST, __FILE__, __LINE__); 920 WriteTransaction wtrans(dir_.get(), UNITTEST, FROM_HERE);
915 MutableEntry grandchild(&wtrans, GET_BY_HANDLE, grandchild_handle); 921 MutableEntry grandchild(&wtrans, GET_BY_HANDLE, grandchild_handle);
916 grandchild.Put(IS_DEL, true); // Used to CHECK fail here. 922 grandchild.Put(IS_DEL, true); // Used to CHECK fail here.
917 } 923 }
918 } 924 }
919 925
920 static inline bool IsLegalNewParent(const Entry& a, const Entry& b) { 926 static inline bool IsLegalNewParent(const Entry& a, const Entry& b) {
921 return IsLegalNewParent(a.trans(), a.Get(ID), b.Get(ID)); 927 return IsLegalNewParent(a.trans(), a.Get(ID), b.Get(ID));
922 } 928 }
923 929
924 TEST_F(SyncableDirectoryTest, TestIsLegalNewParent) { 930 TEST_F(SyncableDirectoryTest, TestIsLegalNewParent) {
925 TestIdFactory id_factory; 931 TestIdFactory id_factory;
926 WriteTransaction wtrans(dir_.get(), UNITTEST, __FILE__, __LINE__); 932 WriteTransaction wtrans(dir_.get(), UNITTEST, FROM_HERE);
927 Entry root(&wtrans, GET_BY_ID, id_factory.root()); 933 Entry root(&wtrans, GET_BY_ID, id_factory.root());
928 ASSERT_TRUE(root.good()); 934 ASSERT_TRUE(root.good());
929 MutableEntry parent(&wtrans, CREATE, root.Get(ID), "Bob"); 935 MutableEntry parent(&wtrans, CREATE, root.Get(ID), "Bob");
930 ASSERT_TRUE(parent.good()); 936 ASSERT_TRUE(parent.good());
931 parent.Put(IS_DIR, true); 937 parent.Put(IS_DIR, true);
932 parent.Put(ID, id_factory.NewServerId()); 938 parent.Put(ID, id_factory.NewServerId());
933 parent.Put(BASE_VERSION, 1); 939 parent.Put(BASE_VERSION, 1);
934 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob"); 940 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob");
935 ASSERT_TRUE(child.good()); 941 ASSERT_TRUE(child.good());
936 child.Put(IS_DIR, true); 942 child.Put(IS_DIR, true);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 } 981 }
976 982
977 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { 983 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) {
978 // Create a subdir and an entry. 984 // Create a subdir and an entry.
979 int64 entry_handle; 985 int64 entry_handle;
980 syncable::Id folder_id; 986 syncable::Id folder_id;
981 syncable::Id entry_id; 987 syncable::Id entry_id;
982 std::string entry_name = "entry"; 988 std::string entry_name = "entry";
983 989
984 { 990 {
985 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 991 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
986 MutableEntry folder(&trans, CREATE, trans.root_id(), "folder"); 992 MutableEntry folder(&trans, CREATE, trans.root_id(), "folder");
987 ASSERT_TRUE(folder.good()); 993 ASSERT_TRUE(folder.good());
988 EXPECT_TRUE(folder.Put(IS_DIR, true)); 994 EXPECT_TRUE(folder.Put(IS_DIR, true));
989 EXPECT_TRUE(folder.Put(IS_UNSYNCED, true)); 995 EXPECT_TRUE(folder.Put(IS_UNSYNCED, true));
990 folder_id = folder.Get(ID); 996 folder_id = folder.Get(ID);
991 997
992 MutableEntry entry(&trans, CREATE, folder.Get(ID), entry_name); 998 MutableEntry entry(&trans, CREATE, folder.Get(ID), entry_name);
993 ASSERT_TRUE(entry.good()); 999 ASSERT_TRUE(entry.good());
994 entry_handle = entry.Get(META_HANDLE); 1000 entry_handle = entry.Get(META_HANDLE);
995 entry.Put(IS_UNSYNCED, true); 1001 entry.Put(IS_UNSYNCED, true);
996 entry_id = entry.Get(ID); 1002 entry_id = entry.Get(ID);
997 } 1003 }
998 1004
999 // Make sure we can find the entry in the folder. 1005 // Make sure we can find the entry in the folder.
1000 { 1006 {
1001 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1007 ReadTransaction trans(dir_.get(), FROM_HERE);
1002 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), entry_name)); 1008 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), entry_name));
1003 EXPECT_EQ(1, CountEntriesWithName(&trans, folder_id, entry_name)); 1009 EXPECT_EQ(1, CountEntriesWithName(&trans, folder_id, entry_name));
1004 1010
1005 Entry entry(&trans, GET_BY_ID, entry_id); 1011 Entry entry(&trans, GET_BY_ID, entry_id);
1006 ASSERT_TRUE(entry.good()); 1012 ASSERT_TRUE(entry.good());
1007 EXPECT_EQ(entry_handle, entry.Get(META_HANDLE)); 1013 EXPECT_EQ(entry_handle, entry.Get(META_HANDLE));
1008 EXPECT_TRUE(entry.Get(NON_UNIQUE_NAME) == entry_name); 1014 EXPECT_TRUE(entry.Get(NON_UNIQUE_NAME) == entry_name);
1009 EXPECT_TRUE(entry.Get(PARENT_ID) == folder_id); 1015 EXPECT_TRUE(entry.Get(PARENT_ID) == folder_id);
1010 } 1016 }
1011 } 1017 }
1012 1018
1013 TEST_F(SyncableDirectoryTest, TestParentIdIndexUpdate) { 1019 TEST_F(SyncableDirectoryTest, TestParentIdIndexUpdate) {
1014 std::string child_name = "child"; 1020 std::string child_name = "child";
1015 1021
1016 WriteTransaction wt(dir_.get(), UNITTEST, __FILE__, __LINE__); 1022 WriteTransaction wt(dir_.get(), UNITTEST, FROM_HERE);
1017 MutableEntry parent_folder(&wt, CREATE, wt.root_id(), "folder1"); 1023 MutableEntry parent_folder(&wt, CREATE, wt.root_id(), "folder1");
1018 parent_folder.Put(IS_UNSYNCED, true); 1024 parent_folder.Put(IS_UNSYNCED, true);
1019 EXPECT_TRUE(parent_folder.Put(IS_DIR, true)); 1025 EXPECT_TRUE(parent_folder.Put(IS_DIR, true));
1020 1026
1021 MutableEntry parent_folder2(&wt, CREATE, wt.root_id(), "folder2"); 1027 MutableEntry parent_folder2(&wt, CREATE, wt.root_id(), "folder2");
1022 parent_folder2.Put(IS_UNSYNCED, true); 1028 parent_folder2.Put(IS_UNSYNCED, true);
1023 EXPECT_TRUE(parent_folder2.Put(IS_DIR, true)); 1029 EXPECT_TRUE(parent_folder2.Put(IS_DIR, true));
1024 1030
1025 MutableEntry child(&wt, CREATE, parent_folder.Get(ID), child_name); 1031 MutableEntry child(&wt, CREATE, parent_folder.Get(ID), child_name);
1026 EXPECT_TRUE(child.Put(IS_DIR, true)); 1032 EXPECT_TRUE(child.Put(IS_DIR, true));
1027 child.Put(IS_UNSYNCED, true); 1033 child.Put(IS_UNSYNCED, true);
1028 1034
1029 ASSERT_TRUE(child.good()); 1035 ASSERT_TRUE(child.good());
1030 1036
1031 EXPECT_EQ(0, CountEntriesWithName(&wt, wt.root_id(), child_name)); 1037 EXPECT_EQ(0, CountEntriesWithName(&wt, wt.root_id(), child_name));
1032 EXPECT_EQ(parent_folder.Get(ID), child.Get(PARENT_ID)); 1038 EXPECT_EQ(parent_folder.Get(ID), child.Get(PARENT_ID));
1033 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); 1039 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name));
1034 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); 1040 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name));
1035 child.Put(PARENT_ID, parent_folder2.Get(ID)); 1041 child.Put(PARENT_ID, parent_folder2.Get(ID));
1036 EXPECT_EQ(parent_folder2.Get(ID), child.Get(PARENT_ID)); 1042 EXPECT_EQ(parent_folder2.Get(ID), child.Get(PARENT_ID));
1037 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); 1043 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name));
1038 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); 1044 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name));
1039 } 1045 }
1040 1046
1041 TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) { 1047 TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) {
1042 std::string folder_name = "folder"; 1048 std::string folder_name = "folder";
1043 std::string new_name = "new_name"; 1049 std::string new_name = "new_name";
1044 1050
1045 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1051 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1046 MutableEntry folder(&trans, CREATE, trans.root_id(), folder_name); 1052 MutableEntry folder(&trans, CREATE, trans.root_id(), folder_name);
1047 ASSERT_TRUE(folder.good()); 1053 ASSERT_TRUE(folder.good());
1048 ASSERT_TRUE(folder.Put(IS_DIR, true)); 1054 ASSERT_TRUE(folder.Put(IS_DIR, true));
1049 ASSERT_TRUE(folder.Put(IS_DEL, true)); 1055 ASSERT_TRUE(folder.Put(IS_DEL, true));
1050 1056
1051 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); 1057 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name));
1052 1058
1053 MutableEntry deleted(&trans, GET_BY_ID, folder.Get(ID)); 1059 MutableEntry deleted(&trans, GET_BY_ID, folder.Get(ID));
1054 ASSERT_TRUE(deleted.good()); 1060 ASSERT_TRUE(deleted.good());
1055 ASSERT_TRUE(deleted.Put(PARENT_ID, trans.root_id())); 1061 ASSERT_TRUE(deleted.Put(PARENT_ID, trans.root_id()));
1056 ASSERT_TRUE(deleted.Put(NON_UNIQUE_NAME, new_name)); 1062 ASSERT_TRUE(deleted.Put(NON_UNIQUE_NAME, new_name));
1057 1063
1058 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); 1064 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name));
1059 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), new_name)); 1065 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), new_name));
1060 } 1066 }
1061 1067
1062 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) { 1068 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) {
1063 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1069 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1064 MutableEntry folder(&trans, CREATE, trans.root_id(), "CaseChange"); 1070 MutableEntry folder(&trans, CREATE, trans.root_id(), "CaseChange");
1065 ASSERT_TRUE(folder.good()); 1071 ASSERT_TRUE(folder.good());
1066 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id())); 1072 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id()));
1067 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE")); 1073 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE"));
1068 EXPECT_TRUE(folder.Put(IS_DEL, true)); 1074 EXPECT_TRUE(folder.Put(IS_DEL, true));
1069 } 1075 }
1070 1076
1071 TEST_F(SyncableDirectoryTest, TestShareInfo) { 1077 TEST_F(SyncableDirectoryTest, TestShareInfo) {
1072 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); 1078 dir_->set_initial_sync_ended_for_type(AUTOFILL, true);
1073 dir_->set_store_birthday("Jan 31st"); 1079 dir_->set_store_birthday("Jan 31st");
1074 dir_->SetNotificationState("notification_state"); 1080 dir_->SetNotificationState("notification_state");
1075 { 1081 {
1076 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1082 ReadTransaction trans(dir_.get(), FROM_HERE);
1077 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); 1083 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL));
1078 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); 1084 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS));
1079 EXPECT_EQ("Jan 31st", dir_->store_birthday()); 1085 EXPECT_EQ("Jan 31st", dir_->store_birthday());
1080 EXPECT_EQ("notification_state", dir_->GetAndClearNotificationState()); 1086 EXPECT_EQ("notification_state", dir_->GetAndClearNotificationState());
1081 EXPECT_EQ("", dir_->GetAndClearNotificationState()); 1087 EXPECT_EQ("", dir_->GetAndClearNotificationState());
1082 } 1088 }
1083 dir_->set_store_birthday("April 10th"); 1089 dir_->set_store_birthday("April 10th");
1084 dir_->SetNotificationState("notification_state2"); 1090 dir_->SetNotificationState("notification_state2");
1085 dir_->SaveChanges(); 1091 dir_->SaveChanges();
1086 { 1092 {
1087 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1093 ReadTransaction trans(dir_.get(), FROM_HERE);
1088 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); 1094 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL));
1089 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); 1095 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS));
1090 EXPECT_EQ("April 10th", dir_->store_birthday()); 1096 EXPECT_EQ("April 10th", dir_->store_birthday());
1091 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState()); 1097 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState());
1092 EXPECT_EQ("", dir_->GetAndClearNotificationState()); 1098 EXPECT_EQ("", dir_->GetAndClearNotificationState());
1093 } 1099 }
1094 dir_->SetNotificationState("notification_state2"); 1100 dir_->SetNotificationState("notification_state2");
1095 // Restore the directory from disk. Make sure that nothing's changed. 1101 // Restore the directory from disk. Make sure that nothing's changed.
1096 SaveAndReloadDir(); 1102 SaveAndReloadDir();
1097 { 1103 {
1098 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1104 ReadTransaction trans(dir_.get(), FROM_HERE);
1099 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); 1105 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL));
1100 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); 1106 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS));
1101 EXPECT_EQ("April 10th", dir_->store_birthday()); 1107 EXPECT_EQ("April 10th", dir_->store_birthday());
1102 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState()); 1108 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState());
1103 EXPECT_EQ("", dir_->GetAndClearNotificationState()); 1109 EXPECT_EQ("", dir_->GetAndClearNotificationState());
1104 } 1110 }
1105 } 1111 }
1106 1112
1107 TEST_F(SyncableDirectoryTest, TestSimpleFieldsPreservedDuringSaveChanges) { 1113 TEST_F(SyncableDirectoryTest, TestSimpleFieldsPreservedDuringSaveChanges) {
1108 Id update_id = TestIdFactory::FromNumber(1); 1114 Id update_id = TestIdFactory::FromNumber(1);
1109 Id create_id; 1115 Id create_id;
1110 EntryKernel create_pre_save, update_pre_save; 1116 EntryKernel create_pre_save, update_pre_save;
1111 EntryKernel create_post_save, update_post_save; 1117 EntryKernel create_post_save, update_post_save;
1112 std::string create_name = "Create"; 1118 std::string create_name = "Create";
1113 1119
1114 { 1120 {
1115 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1121 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1116 MutableEntry create(&trans, CREATE, trans.root_id(), create_name); 1122 MutableEntry create(&trans, CREATE, trans.root_id(), create_name);
1117 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); 1123 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id);
1118 create.Put(IS_UNSYNCED, true); 1124 create.Put(IS_UNSYNCED, true);
1119 update.Put(IS_UNAPPLIED_UPDATE, true); 1125 update.Put(IS_UNAPPLIED_UPDATE, true);
1120 sync_pb::EntitySpecifics specifics; 1126 sync_pb::EntitySpecifics specifics;
1121 specifics.MutableExtension(sync_pb::bookmark)->set_favicon("PNG"); 1127 specifics.MutableExtension(sync_pb::bookmark)->set_favicon("PNG");
1122 specifics.MutableExtension(sync_pb::bookmark)->set_url("http://nowhere"); 1128 specifics.MutableExtension(sync_pb::bookmark)->set_url("http://nowhere");
1123 create.Put(SPECIFICS, specifics); 1129 create.Put(SPECIFICS, specifics);
1124 create_pre_save = create.GetKernelCopy(); 1130 create_pre_save = create.GetKernelCopy();
1125 update_pre_save = update.GetKernelCopy(); 1131 update_pre_save = update.GetKernelCopy();
1126 create_id = create.Get(ID); 1132 create_id = create.Get(ID);
1127 } 1133 }
1128 1134
1129 dir_->SaveChanges(); 1135 dir_->SaveChanges();
1130 dir_.reset(new Directory()); 1136 dir_.reset(new Directory());
1131 ASSERT_TRUE(dir_.get()); 1137 ASSERT_TRUE(dir_.get());
1132 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName)); 1138 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName, &delegate_));
1133 ASSERT_TRUE(dir_->good()); 1139 ASSERT_TRUE(dir_->good());
1134 1140
1135 { 1141 {
1136 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1142 ReadTransaction trans(dir_.get(), FROM_HERE);
1137 Entry create(&trans, GET_BY_ID, create_id); 1143 Entry create(&trans, GET_BY_ID, create_id);
1138 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name)); 1144 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name));
1139 Entry update(&trans, GET_BY_ID, update_id); 1145 Entry update(&trans, GET_BY_ID, update_id);
1140 create_post_save = create.GetKernelCopy(); 1146 create_post_save = create.GetKernelCopy();
1141 update_post_save = update.GetKernelCopy(); 1147 update_post_save = update.GetKernelCopy();
1142 } 1148 }
1143 int i = BEGIN_FIELDS; 1149 int i = BEGIN_FIELDS;
1144 for ( ; i < INT64_FIELDS_END ; ++i) { 1150 for ( ; i < INT64_FIELDS_END ; ++i) {
1145 EXPECT_EQ(create_pre_save.ref((Int64Field)i), 1151 EXPECT_EQ(create_pre_save.ref((Int64Field)i),
1146 create_post_save.ref((Int64Field)i)) 1152 create_post_save.ref((Int64Field)i))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(), 1186 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(),
1181 update_post_save.ref((ProtoField)i).SerializeAsString()) 1187 update_post_save.ref((ProtoField)i).SerializeAsString())
1182 << "Blob field #" << i << " changed during save/load"; 1188 << "Blob field #" << i << " changed during save/load";
1183 } 1189 }
1184 } 1190 }
1185 1191
1186 TEST_F(SyncableDirectoryTest, TestSaveChangesFailure) { 1192 TEST_F(SyncableDirectoryTest, TestSaveChangesFailure) {
1187 int64 handle1 = 0; 1193 int64 handle1 = 0;
1188 // Set up an item using a regular, saveable directory. 1194 // Set up an item using a regular, saveable directory.
1189 { 1195 {
1190 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1196 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1191 1197
1192 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); 1198 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera");
1193 ASSERT_TRUE(e1.good()); 1199 ASSERT_TRUE(e1.good());
1194 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); 1200 EXPECT_TRUE(e1.GetKernelCopy().is_dirty());
1195 handle1 = e1.Get(META_HANDLE); 1201 handle1 = e1.Get(META_HANDLE);
1196 e1.Put(BASE_VERSION, 1); 1202 e1.Put(BASE_VERSION, 1);
1197 e1.Put(IS_DIR, true); 1203 e1.Put(IS_DIR, true);
1198 e1.Put(ID, TestIdFactory::FromNumber(101)); 1204 e1.Put(ID, TestIdFactory::FromNumber(101));
1199 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); 1205 EXPECT_TRUE(e1.GetKernelCopy().is_dirty());
1200 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1206 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1201 } 1207 }
1202 ASSERT_TRUE(dir_->SaveChanges()); 1208 ASSERT_TRUE(dir_->SaveChanges());
1203 1209
1204 // Make sure the item is no longer dirty after saving, 1210 // Make sure the item is no longer dirty after saving,
1205 // and make a modification. 1211 // and make a modification.
1206 { 1212 {
1207 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1213 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1208 1214
1209 MutableEntry aguilera(&trans, GET_BY_HANDLE, handle1); 1215 MutableEntry aguilera(&trans, GET_BY_HANDLE, handle1);
1210 ASSERT_TRUE(aguilera.good()); 1216 ASSERT_TRUE(aguilera.good());
1211 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); 1217 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty());
1212 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "aguilera"); 1218 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "aguilera");
1213 aguilera.Put(NON_UNIQUE_NAME, "overwritten"); 1219 aguilera.Put(NON_UNIQUE_NAME, "overwritten");
1214 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty()); 1220 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty());
1215 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1221 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1216 } 1222 }
1217 ASSERT_TRUE(dir_->SaveChanges()); 1223 ASSERT_TRUE(dir_->SaveChanges());
1218 1224
1219 // Now do some operations using a directory for which SaveChanges will 1225 // Now do some operations using a directory for which SaveChanges will
1220 // always fail. 1226 // always fail.
1221 dir_.reset(new TestUnsaveableDirectory()); 1227 dir_.reset(new TestUnsaveableDirectory());
1222 ASSERT_TRUE(dir_.get()); 1228 ASSERT_TRUE(dir_.get());
1223 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName)); 1229 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName, &delegate_));
1224 ASSERT_TRUE(dir_->good()); 1230 ASSERT_TRUE(dir_->good());
1225 int64 handle2 = 0; 1231 int64 handle2 = 0;
1226 { 1232 {
1227 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1233 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1228 1234
1229 MutableEntry aguilera(&trans, GET_BY_HANDLE, handle1); 1235 MutableEntry aguilera(&trans, GET_BY_HANDLE, handle1);
1230 ASSERT_TRUE(aguilera.good()); 1236 ASSERT_TRUE(aguilera.good());
1231 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); 1237 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty());
1232 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "overwritten"); 1238 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "overwritten");
1233 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); 1239 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty());
1234 EXPECT_FALSE(IsInDirtyMetahandles(handle1)); 1240 EXPECT_FALSE(IsInDirtyMetahandles(handle1));
1235 aguilera.Put(NON_UNIQUE_NAME, "christina"); 1241 aguilera.Put(NON_UNIQUE_NAME, "christina");
1236 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty()); 1242 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty());
1237 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1243 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1238 1244
1239 // New item. 1245 // New item.
1240 MutableEntry kids_on_block(&trans, CREATE, trans.root_id(), "kids"); 1246 MutableEntry kids_on_block(&trans, CREATE, trans.root_id(), "kids");
1241 ASSERT_TRUE(kids_on_block.good()); 1247 ASSERT_TRUE(kids_on_block.good());
1242 handle2 = kids_on_block.Get(META_HANDLE); 1248 handle2 = kids_on_block.Get(META_HANDLE);
1243 kids_on_block.Put(BASE_VERSION, 1); 1249 kids_on_block.Put(BASE_VERSION, 1);
1244 kids_on_block.Put(IS_DIR, true); 1250 kids_on_block.Put(IS_DIR, true);
1245 kids_on_block.Put(ID, TestIdFactory::FromNumber(102)); 1251 kids_on_block.Put(ID, TestIdFactory::FromNumber(102));
1246 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty()); 1252 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty());
1247 EXPECT_TRUE(IsInDirtyMetahandles(handle2)); 1253 EXPECT_TRUE(IsInDirtyMetahandles(handle2));
1248 } 1254 }
1249 1255
1250 // We are using an unsaveable directory, so this can't succeed. However, 1256 // We are using an unsaveable directory, so this can't succeed. However,
1251 // the HandleSaveChangesFailure code path should have been triggered. 1257 // the HandleSaveChangesFailure code path should have been triggered.
1252 ASSERT_FALSE(dir_->SaveChanges()); 1258 ASSERT_FALSE(dir_->SaveChanges());
1253 1259
1254 // Make sure things were rolled back and the world is as it was before call. 1260 // Make sure things were rolled back and the world is as it was before call.
1255 { 1261 {
1256 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1262 ReadTransaction trans(dir_.get(), FROM_HERE);
1257 Entry e1(&trans, GET_BY_HANDLE, handle1); 1263 Entry e1(&trans, GET_BY_HANDLE, handle1);
1258 ASSERT_TRUE(e1.good()); 1264 ASSERT_TRUE(e1.good());
1259 EntryKernel aguilera = e1.GetKernelCopy(); 1265 EntryKernel aguilera = e1.GetKernelCopy();
1260 Entry kids(&trans, GET_BY_HANDLE, handle2); 1266 Entry kids(&trans, GET_BY_HANDLE, handle2);
1261 ASSERT_TRUE(kids.good()); 1267 ASSERT_TRUE(kids.good());
1262 EXPECT_TRUE(kids.GetKernelCopy().is_dirty()); 1268 EXPECT_TRUE(kids.GetKernelCopy().is_dirty());
1263 EXPECT_TRUE(IsInDirtyMetahandles(handle2)); 1269 EXPECT_TRUE(IsInDirtyMetahandles(handle2));
1264 EXPECT_TRUE(aguilera.is_dirty()); 1270 EXPECT_TRUE(aguilera.is_dirty());
1265 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1271 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1266 } 1272 }
1267 } 1273 }
1268 1274
1269 TEST_F(SyncableDirectoryTest, TestSaveChangesFailureWithPurge) { 1275 TEST_F(SyncableDirectoryTest, TestSaveChangesFailureWithPurge) {
1270 int64 handle1 = 0; 1276 int64 handle1 = 0;
1271 // Set up an item using a regular, saveable directory. 1277 // Set up an item using a regular, saveable directory.
1272 { 1278 {
1273 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1279 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1274 1280
1275 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); 1281 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera");
1276 ASSERT_TRUE(e1.good()); 1282 ASSERT_TRUE(e1.good());
1277 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); 1283 EXPECT_TRUE(e1.GetKernelCopy().is_dirty());
1278 handle1 = e1.Get(META_HANDLE); 1284 handle1 = e1.Get(META_HANDLE);
1279 e1.Put(BASE_VERSION, 1); 1285 e1.Put(BASE_VERSION, 1);
1280 e1.Put(IS_DIR, true); 1286 e1.Put(IS_DIR, true);
1281 e1.Put(ID, TestIdFactory::FromNumber(101)); 1287 e1.Put(ID, TestIdFactory::FromNumber(101));
1282 sync_pb::EntitySpecifics bookmark_specs; 1288 sync_pb::EntitySpecifics bookmark_specs;
1283 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs); 1289 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs);
1284 e1.Put(SPECIFICS, bookmark_specs); 1290 e1.Put(SPECIFICS, bookmark_specs);
1285 e1.Put(SERVER_SPECIFICS, bookmark_specs); 1291 e1.Put(SERVER_SPECIFICS, bookmark_specs);
1286 e1.Put(ID, TestIdFactory::FromNumber(101)); 1292 e1.Put(ID, TestIdFactory::FromNumber(101));
1287 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); 1293 EXPECT_TRUE(e1.GetKernelCopy().is_dirty());
1288 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1294 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1289 } 1295 }
1290 ASSERT_TRUE(dir_->SaveChanges()); 1296 ASSERT_TRUE(dir_->SaveChanges());
1291 1297
1292 // Now do some operations using a directory for which SaveChanges will 1298 // Now do some operations using a directory for which SaveChanges will
1293 // always fail. 1299 // always fail.
1294 dir_.reset(new TestUnsaveableDirectory()); 1300 dir_.reset(new TestUnsaveableDirectory());
1295 ASSERT_TRUE(dir_.get()); 1301 ASSERT_TRUE(dir_.get());
1296 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName)); 1302 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName, &delegate_));
1297 ASSERT_TRUE(dir_->good()); 1303 ASSERT_TRUE(dir_->good());
1298 1304
1299 ModelTypeSet set; 1305 ModelTypeSet set;
1300 set.insert(BOOKMARKS); 1306 set.insert(BOOKMARKS);
1301 dir_->PurgeEntriesWithTypeIn(set); 1307 dir_->PurgeEntriesWithTypeIn(set);
1302 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); 1308 EXPECT_TRUE(IsInMetahandlesToPurge(handle1));
1303 ASSERT_FALSE(dir_->SaveChanges()); 1309 ASSERT_FALSE(dir_->SaveChanges());
1304 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); 1310 EXPECT_TRUE(IsInMetahandlesToPurge(handle1));
1305 } 1311 }
1306 1312
1307 // Create items of each model type, and check that GetModelType and 1313 // Create items of each model type, and check that GetModelType and
1308 // GetServerModelType return the right value. 1314 // GetServerModelType return the right value.
1309 TEST_F(SyncableDirectoryTest, GetModelType) { 1315 TEST_F(SyncableDirectoryTest, GetModelType) {
1310 TestIdFactory id_factory; 1316 TestIdFactory id_factory;
1311 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { 1317 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) {
1312 ModelType datatype = ModelTypeFromInt(i); 1318 ModelType datatype = ModelTypeFromInt(i);
1313 SCOPED_TRACE(testing::Message("Testing model type ") << datatype); 1319 SCOPED_TRACE(testing::Message("Testing model type ") << datatype);
1314 switch (datatype) { 1320 switch (datatype) {
1315 case UNSPECIFIED: 1321 case UNSPECIFIED:
1316 case TOP_LEVEL_FOLDER: 1322 case TOP_LEVEL_FOLDER:
1317 continue; // Datatype isn't a function of Specifics. 1323 continue; // Datatype isn't a function of Specifics.
1318 default: 1324 default:
1319 break; 1325 break;
1320 } 1326 }
1321 sync_pb::EntitySpecifics specifics; 1327 sync_pb::EntitySpecifics specifics;
1322 AddDefaultExtensionValue(datatype, &specifics); 1328 AddDefaultExtensionValue(datatype, &specifics);
1323 1329
1324 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1330 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1325 1331
1326 MutableEntry folder(&trans, CREATE, trans.root_id(), "Folder"); 1332 MutableEntry folder(&trans, CREATE, trans.root_id(), "Folder");
1327 ASSERT_TRUE(folder.good()); 1333 ASSERT_TRUE(folder.good());
1328 folder.Put(ID, id_factory.NewServerId()); 1334 folder.Put(ID, id_factory.NewServerId());
1329 folder.Put(SPECIFICS, specifics); 1335 folder.Put(SPECIFICS, specifics);
1330 folder.Put(BASE_VERSION, 1); 1336 folder.Put(BASE_VERSION, 1);
1331 folder.Put(IS_DIR, true); 1337 folder.Put(IS_DIR, true);
1332 folder.Put(IS_DEL, false); 1338 folder.Put(IS_DEL, false);
1333 ASSERT_EQ(datatype, folder.GetModelType()); 1339 ASSERT_EQ(datatype, folder.GetModelType());
1334 1340
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 class SyncableDirectoryManager : public testing::Test { 1415 class SyncableDirectoryManager : public testing::Test {
1410 public: 1416 public:
1411 virtual void SetUp() { 1417 virtual void SetUp() {
1412 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 1418 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1413 } 1419 }
1414 1420
1415 virtual void TearDown() { 1421 virtual void TearDown() {
1416 } 1422 }
1417 protected: 1423 protected:
1418 ScopedTempDir temp_dir_; 1424 ScopedTempDir temp_dir_;
1425 NullDirectoryChangeDelegate delegate_;
1419 }; 1426 };
1420 1427
1421 TEST_F(SyncableDirectoryManager, TestFileRelease) { 1428 TEST_F(SyncableDirectoryManager, TestFileRelease) {
1422 DirectoryManager dm(FilePath(temp_dir_.path())); 1429 DirectoryManager dm(FilePath(temp_dir_.path()));
1423 ASSERT_TRUE(dm.Open("ScopeTest")); 1430 ASSERT_TRUE(dm.Open("ScopeTest", &delegate_));
1424 { 1431 {
1425 ScopedDirLookup(&dm, "ScopeTest"); 1432 ScopedDirLookup(&dm, "ScopeTest");
1426 } 1433 }
1427 dm.Close("ScopeTest"); 1434 dm.Close("ScopeTest");
1428 ASSERT_TRUE(file_util::Delete(dm.GetSyncDataDatabasePath(), true)); 1435 ASSERT_TRUE(file_util::Delete(dm.GetSyncDataDatabasePath(), true));
1429 } 1436 }
1430 1437
1431 class ThreadOpenTestDelegate : public base::PlatformThread::Delegate { 1438 class ThreadOpenTestDelegate : public base::PlatformThread::Delegate {
1432 public: 1439 public:
1433 explicit ThreadOpenTestDelegate(DirectoryManager* dm) 1440 explicit ThreadOpenTestDelegate(DirectoryManager* dm)
1434 : directory_manager_(dm) {} 1441 : directory_manager_(dm) {}
1435 DirectoryManager* const directory_manager_; 1442 DirectoryManager* const directory_manager_;
1443 NullDirectoryChangeDelegate delegate_;
1436 1444
1437 private: 1445 private:
1438 // PlatformThread::Delegate methods: 1446 // PlatformThread::Delegate methods:
1439 virtual void ThreadMain() { 1447 virtual void ThreadMain() {
1440 CHECK(directory_manager_->Open("Open")); 1448 CHECK(directory_manager_->Open("Open", &delegate_));
1441 } 1449 }
1442 1450
1443 DISALLOW_COPY_AND_ASSIGN(ThreadOpenTestDelegate); 1451 DISALLOW_COPY_AND_ASSIGN(ThreadOpenTestDelegate);
1444 }; 1452 };
1445 1453
1446 TEST_F(SyncableDirectoryManager, ThreadOpenTest) { 1454 TEST_F(SyncableDirectoryManager, ThreadOpenTest) {
1447 DirectoryManager dm(FilePath(temp_dir_.path())); 1455 DirectoryManager dm(FilePath(temp_dir_.path()));
1448 base::PlatformThreadHandle thread_handle; 1456 base::PlatformThreadHandle thread_handle;
1449 ThreadOpenTestDelegate test_delegate(&dm); 1457 ThreadOpenTestDelegate test_delegate(&dm);
1450 ASSERT_TRUE(base::PlatformThread::Create(0, &test_delegate, &thread_handle)); 1458 ASSERT_TRUE(base::PlatformThread::Create(0, &test_delegate, &thread_handle));
(...skipping 18 matching lines...) Expand all
1469 1477
1470 class ThreadBugDelegate : public base::PlatformThread::Delegate { 1478 class ThreadBugDelegate : public base::PlatformThread::Delegate {
1471 public: 1479 public:
1472 // a role is 0 or 1, meaning this thread does the odd or event steps. 1480 // a role is 0 or 1, meaning this thread does the odd or event steps.
1473 ThreadBugDelegate(int role, Step* step, DirectoryManager* dirman) 1481 ThreadBugDelegate(int role, Step* step, DirectoryManager* dirman)
1474 : role_(role), step_(step), directory_manager_(dirman) {} 1482 : role_(role), step_(step), directory_manager_(dirman) {}
1475 1483
1476 protected: 1484 protected:
1477 const int role_; 1485 const int role_;
1478 Step* const step_; 1486 Step* const step_;
1487 NullDirectoryChangeDelegate delegate_;
1479 DirectoryManager* const directory_manager_; 1488 DirectoryManager* const directory_manager_;
1480 1489
1481 // PlatformThread::Delegate methods: 1490 // PlatformThread::Delegate methods:
1482 virtual void ThreadMain() { 1491 virtual void ThreadMain() {
1483 const std::string dirname = "ThreadBug1"; 1492 const std::string dirname = "ThreadBug1";
1484 base::AutoLock scoped_lock(step_->mutex); 1493 base::AutoLock scoped_lock(step_->mutex);
1485 1494
1486 while (step_->number < 3) { 1495 while (step_->number < 3) {
1487 while (step_->number % 2 != role_) { 1496 while (step_->number % 2 != role_) {
1488 step_->condvar.Wait(); 1497 step_->condvar.Wait();
1489 } 1498 }
1490 switch (step_->number) { 1499 switch (step_->number) {
1491 case 0: 1500 case 0:
1492 directory_manager_->Open(dirname); 1501 directory_manager_->Open(dirname, &delegate_);
1493 break; 1502 break;
1494 case 1: 1503 case 1:
1495 { 1504 {
1496 directory_manager_->Close(dirname); 1505 directory_manager_->Close(dirname);
1497 directory_manager_->Open(dirname); 1506 directory_manager_->Open(dirname, &delegate_);
1498 ScopedDirLookup dir(directory_manager_, dirname); 1507 ScopedDirLookup dir(directory_manager_, dirname);
1499 CHECK(dir.good()); 1508 CHECK(dir.good());
1500 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1509 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1501 MutableEntry me(&trans, CREATE, trans.root_id(), "Jeff"); 1510 MutableEntry me(&trans, CREATE, trans.root_id(), "Jeff");
1502 step_->metahandle = me.Get(META_HANDLE); 1511 step_->metahandle = me.Get(META_HANDLE);
1503 me.Put(IS_UNSYNCED, true); 1512 me.Put(IS_UNSYNCED, true);
1504 } 1513 }
1505 break; 1514 break;
1506 case 2: 1515 case 2:
1507 { 1516 {
1508 ScopedDirLookup dir(directory_manager_, dirname); 1517 ScopedDirLookup dir(directory_manager_, dirname);
1509 CHECK(dir.good()); 1518 CHECK(dir.good());
1510 ReadTransaction trans(dir, __FILE__, __LINE__); 1519 ReadTransaction trans(dir, FROM_HERE);
1511 Entry e(&trans, GET_BY_HANDLE, step_->metahandle); 1520 Entry e(&trans, GET_BY_HANDLE, step_->metahandle);
1512 CHECK(e.good()); // Failed due to ThreadBug1 1521 CHECK(e.good()); // Failed due to ThreadBug1
1513 } 1522 }
1514 directory_manager_->Close(dirname); 1523 directory_manager_->Close(dirname);
1515 break; 1524 break;
1516 } 1525 }
1517 step_->number += 1; 1526 step_->number += 1;
1518 step_->condvar.Signal(); 1527 step_->condvar.Signal();
1519 } 1528 }
1520 } 1529 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 while (step_->number % 2 != role_) { 1570 while (step_->number % 2 != role_) {
1562 step_->condvar.Wait(); 1571 step_->condvar.Wait();
1563 } 1572 }
1564 switch (step_->number) { 1573 switch (step_->number) {
1565 case 0: 1574 case 0:
1566 { 1575 {
1567 // Clean up remnants of earlier test runs. 1576 // Clean up remnants of earlier test runs.
1568 file_util::Delete(directory_manager_->GetSyncDataDatabasePath(), 1577 file_util::Delete(directory_manager_->GetSyncDataDatabasePath(),
1569 true); 1578 true);
1570 // Test. 1579 // Test.
1571 directory_manager_->Open(dirname); 1580 directory_manager_->Open(dirname, &delegate_);
1572 ScopedDirLookup dir(directory_manager_, dirname); 1581 ScopedDirLookup dir(directory_manager_, dirname);
1573 CHECK(dir.good()); 1582 CHECK(dir.good());
1574 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1583 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1575 MutableEntry me(&trans, CREATE, trans.root_id(), "Jeff"); 1584 MutableEntry me(&trans, CREATE, trans.root_id(), "Jeff");
1576 me.Put(BASE_VERSION, 1); 1585 me.Put(BASE_VERSION, 1);
1577 me.Put(ID, jeff_id); 1586 me.Put(ID, jeff_id);
1578 PutDataAsBookmarkFavicon(&trans, &me, test_bytes, 1587 PutDataAsBookmarkFavicon(&trans, &me, test_bytes,
1579 sizeof(test_bytes)); 1588 sizeof(test_bytes));
1580 } 1589 }
1581 { 1590 {
1582 ScopedDirLookup dir(directory_manager_, dirname); 1591 ScopedDirLookup dir(directory_manager_, dirname);
1583 CHECK(dir.good()); 1592 CHECK(dir.good());
1584 dir->SaveChanges(); 1593 dir->SaveChanges();
1585 } 1594 }
1586 directory_manager_->Close(dirname); 1595 directory_manager_->Close(dirname);
1587 break; 1596 break;
1588 case 1: 1597 case 1:
1589 { 1598 {
1590 directory_manager_->Open(dirname); 1599 directory_manager_->Open(dirname, &delegate_);
1591 ScopedDirLookup dir(directory_manager_, dirname); 1600 ScopedDirLookup dir(directory_manager_, dirname);
1592 CHECK(dir.good()); 1601 CHECK(dir.good());
1593 } 1602 }
1594 break; 1603 break;
1595 case 2: 1604 case 2:
1596 { 1605 {
1597 ScopedDirLookup dir(directory_manager_, dirname); 1606 ScopedDirLookup dir(directory_manager_, dirname);
1598 CHECK(dir.good()); 1607 CHECK(dir.good());
1599 } 1608 }
1600 break; 1609 break;
1601 case 3: 1610 case 3:
1602 { 1611 {
1603 ScopedDirLookup dir(directory_manager_, dirname); 1612 ScopedDirLookup dir(directory_manager_, dirname);
1604 CHECK(dir.good()); 1613 CHECK(dir.good());
1605 ReadTransaction trans(dir, __FILE__, __LINE__); 1614 ReadTransaction trans(dir, FROM_HERE);
1606 Entry e(&trans, GET_BY_ID, jeff_id); 1615 Entry e(&trans, GET_BY_ID, jeff_id);
1607 ExpectDataFromBookmarkFaviconEquals(&trans, &e, test_bytes, 1616 ExpectDataFromBookmarkFaviconEquals(&trans, &e, test_bytes,
1608 sizeof(test_bytes)); 1617 sizeof(test_bytes));
1609 } 1618 }
1610 // Same result as CloseAllDirectories, but more code coverage. 1619 // Same result as CloseAllDirectories, but more code coverage.
1611 directory_manager_->Close(dirname); 1620 directory_manager_->Close(dirname);
1612 break; 1621 break;
1613 } 1622 }
1614 step_->number += 1; 1623 step_->number += 1;
1615 step_->condvar.Signal(); 1624 step_->condvar.Signal();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 // PlatformThread::Delegate methods: 1664 // PlatformThread::Delegate methods:
1656 virtual void ThreadMain() { 1665 virtual void ThreadMain() {
1657 ScopedDirLookup dir(directory_manager_, dirname_); 1666 ScopedDirLookup dir(directory_manager_, dirname_);
1658 CHECK(dir.good()); 1667 CHECK(dir.good());
1659 int entry_count = 0; 1668 int entry_count = 0;
1660 std::string path_name; 1669 std::string path_name;
1661 1670
1662 for (int i = 0; i < 20; ++i) { 1671 for (int i = 0; i < 20; ++i) {
1663 const int rand_action = rand() % 10; 1672 const int rand_action = rand() % 10;
1664 if (rand_action < 4 && !path_name.empty()) { 1673 if (rand_action < 4 && !path_name.empty()) {
1665 ReadTransaction trans(dir, __FILE__, __LINE__); 1674 ReadTransaction trans(dir, FROM_HERE);
1666 CHECK(1 == CountEntriesWithName(&trans, trans.root_id(), path_name)); 1675 CHECK(1 == CountEntriesWithName(&trans, trans.root_id(), path_name));
1667 base::PlatformThread::Sleep(rand() % 10); 1676 base::PlatformThread::Sleep(rand() % 10);
1668 } else { 1677 } else {
1669 std::string unique_name = 1678 std::string unique_name =
1670 base::StringPrintf("%d.%d", thread_number_, entry_count++); 1679 base::StringPrintf("%d.%d", thread_number_, entry_count++);
1671 path_name.assign(unique_name.begin(), unique_name.end()); 1680 path_name.assign(unique_name.begin(), unique_name.end());
1672 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1681 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1673 MutableEntry e(&trans, CREATE, trans.root_id(), path_name); 1682 MutableEntry e(&trans, CREATE, trans.root_id(), path_name);
1674 CHECK(e.good()); 1683 CHECK(e.good());
1675 base::PlatformThread::Sleep(rand() % 20); 1684 base::PlatformThread::Sleep(rand() % 20);
1676 e.Put(IS_UNSYNCED, true); 1685 e.Put(IS_UNSYNCED, true);
1677 if (e.Put(ID, TestIdFactory::FromNumber(rand())) && 1686 if (e.Put(ID, TestIdFactory::FromNumber(rand())) &&
1678 e.Get(ID).ServerKnows() && !e.Get(ID).IsRoot()) { 1687 e.Get(ID).ServerKnows() && !e.Get(ID).IsRoot()) {
1679 e.Put(BASE_VERSION, 1); 1688 e.Put(BASE_VERSION, 1);
1680 } 1689 }
1681 } 1690 }
1682 } 1691 }
1683 } 1692 }
1684 1693
1685 DISALLOW_COPY_AND_ASSIGN(StressTransactionsDelegate); 1694 DISALLOW_COPY_AND_ASSIGN(StressTransactionsDelegate);
1686 }; 1695 };
1687 1696
1688 TEST(SyncableDirectory, StressTransactions) { 1697 TEST(SyncableDirectory, StressTransactions) {
1689 ScopedTempDir temp_dir; 1698 ScopedTempDir temp_dir;
1690 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1699 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1691 DirectoryManager dirman(FilePath(temp_dir.path())); 1700 DirectoryManager dirman(FilePath(temp_dir.path()));
1692 std::string dirname = "stress"; 1701 std::string dirname = "stress";
1693 file_util::Delete(dirman.GetSyncDataDatabasePath(), true); 1702 file_util::Delete(dirman.GetSyncDataDatabasePath(), true);
1694 dirman.Open(dirname); 1703 NullDirectoryChangeDelegate delegate;
1704 dirman.Open(dirname, &delegate);
1695 1705
1696 const int kThreadCount = 7; 1706 const int kThreadCount = 7;
1697 base::PlatformThreadHandle threads[kThreadCount]; 1707 base::PlatformThreadHandle threads[kThreadCount];
1698 scoped_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount]; 1708 scoped_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount];
1699 1709
1700 for (int i = 0; i < kThreadCount; ++i) { 1710 for (int i = 0; i < kThreadCount; ++i) {
1701 thread_delegates[i].reset( 1711 thread_delegates[i].reset(
1702 new StressTransactionsDelegate(&dirman, dirname, i)); 1712 new StressTransactionsDelegate(&dirman, dirname, i));
1703 ASSERT_TRUE(base::PlatformThread::Create( 1713 ASSERT_TRUE(base::PlatformThread::Create(
1704 0, thread_delegates[i].get(), &threads[i])); 1714 0, thread_delegates[i].get(), &threads[i]));
(...skipping 14 matching lines...) Expand all
1719 const char* test_tag_; 1729 const char* test_tag_;
1720 1730
1721 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {} 1731 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {}
1722 1732
1723 bool CreateWithDefaultTag(Id id, bool deleted) { 1733 bool CreateWithDefaultTag(Id id, bool deleted) {
1724 return CreateWithTag(test_tag_, id, deleted); 1734 return CreateWithTag(test_tag_, id, deleted);
1725 } 1735 }
1726 1736
1727 // Attempt to create an entry with a default tag. 1737 // Attempt to create an entry with a default tag.
1728 bool CreateWithTag(const char* tag, Id id, bool deleted) { 1738 bool CreateWithTag(const char* tag, Id id, bool deleted) {
1729 WriteTransaction wtrans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1739 WriteTransaction wtrans(dir_.get(), UNITTEST, FROM_HERE);
1730 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), test_name_); 1740 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), test_name_);
1731 CHECK(me.good()); 1741 CHECK(me.good());
1732 me.Put(ID, id); 1742 me.Put(ID, id);
1733 if (id.ServerKnows()) { 1743 if (id.ServerKnows()) {
1734 me.Put(BASE_VERSION, kBaseVersion); 1744 me.Put(BASE_VERSION, kBaseVersion);
1735 } 1745 }
1736 me.Put(IS_DEL, deleted); 1746 me.Put(IS_DEL, deleted);
1737 me.Put(IS_UNSYNCED, true); 1747 me.Put(IS_UNSYNCED, true);
1738 me.Put(IS_DIR, false); 1748 me.Put(IS_DIR, false);
1739 return me.Put(UNIQUE_CLIENT_TAG, tag); 1749 return me.Put(UNIQUE_CLIENT_TAG, tag);
1740 } 1750 }
1741 1751
1742 // Verify an entry exists with the default tag. 1752 // Verify an entry exists with the default tag.
1743 void VerifyTag(Id id, bool deleted) { 1753 void VerifyTag(Id id, bool deleted) {
1744 // Should still be present and valid in the client tag index. 1754 // Should still be present and valid in the client tag index.
1745 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1755 ReadTransaction trans(dir_.get(), FROM_HERE);
1746 Entry me(&trans, GET_BY_CLIENT_TAG, test_tag_); 1756 Entry me(&trans, GET_BY_CLIENT_TAG, test_tag_);
1747 CHECK(me.good()); 1757 CHECK(me.good());
1748 EXPECT_EQ(me.Get(ID), id); 1758 EXPECT_EQ(me.Get(ID), id);
1749 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), test_tag_); 1759 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), test_tag_);
1750 EXPECT_EQ(me.Get(IS_DEL), deleted); 1760 EXPECT_EQ(me.Get(IS_DEL), deleted);
1751 EXPECT_EQ(me.Get(IS_UNSYNCED), true); 1761 EXPECT_EQ(me.Get(IS_UNSYNCED), true);
1752 } 1762 }
1753 1763
1754 protected: 1764 protected:
1755 TestIdFactory factory_; 1765 TestIdFactory factory_;
1756 }; 1766 };
1757 1767
1758 TEST_F(SyncableClientTagTest, TestClientTagClear) { 1768 TEST_F(SyncableClientTagTest, TestClientTagClear) {
1759 Id server_id = factory_.NewServerId(); 1769 Id server_id = factory_.NewServerId();
1760 EXPECT_TRUE(CreateWithDefaultTag(server_id, false)); 1770 EXPECT_TRUE(CreateWithDefaultTag(server_id, false));
1761 { 1771 {
1762 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 1772 WriteTransaction trans(dir_.get(), UNITTEST, FROM_HERE);
1763 MutableEntry me(&trans, GET_BY_CLIENT_TAG, test_tag_); 1773 MutableEntry me(&trans, GET_BY_CLIENT_TAG, test_tag_);
1764 EXPECT_TRUE(me.good()); 1774 EXPECT_TRUE(me.good());
1765 me.Put(UNIQUE_CLIENT_TAG, ""); 1775 me.Put(UNIQUE_CLIENT_TAG, "");
1766 } 1776 }
1767 { 1777 {
1768 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); 1778 ReadTransaction trans(dir_.get(), FROM_HERE);
1769 Entry by_tag(&trans, GET_BY_CLIENT_TAG, test_tag_); 1779 Entry by_tag(&trans, GET_BY_CLIENT_TAG, test_tag_);
1770 EXPECT_FALSE(by_tag.good()); 1780 EXPECT_FALSE(by_tag.good());
1771 1781
1772 Entry by_id(&trans, GET_BY_ID, server_id); 1782 Entry by_id(&trans, GET_BY_ID, server_id);
1773 EXPECT_TRUE(by_id.good()); 1783 EXPECT_TRUE(by_id.good());
1774 EXPECT_TRUE(by_id.Get(UNIQUE_CLIENT_TAG).empty()); 1784 EXPECT_TRUE(by_id.Get(UNIQUE_CLIENT_TAG).empty());
1775 } 1785 }
1776 } 1786 }
1777 1787
1778 TEST_F(SyncableClientTagTest, TestClientTagIndexServerId) { 1788 TEST_F(SyncableClientTagTest, TestClientTagIndexServerId) {
(...skipping 23 matching lines...) Expand all
1802 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1812 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1803 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1813 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1804 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1814 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1805 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1815 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1806 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1816 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1807 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1817 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1808 } 1818 }
1809 1819
1810 } // namespace 1820 } // namespace
1811 } // namespace syncable 1821 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable_mock.cc ('k') | chrome/browser/sync/syncable/transaction_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698