OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/synchronization/condition_variable.h" | 17 #include "base/synchronization/condition_variable.h" |
18 #include "base/test/values_test_util.h" | 18 #include "base/test/values_test_util.h" |
19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "sync/internal_api/public/base/node_ordinal.h" | |
22 #include "sync/protocol/bookmark_specifics.pb.h" | 21 #include "sync/protocol/bookmark_specifics.pb.h" |
23 #include "sync/syncable/directory_backing_store.h" | 22 #include "sync/syncable/directory_backing_store.h" |
24 #include "sync/syncable/directory_change_delegate.h" | 23 #include "sync/syncable/directory_change_delegate.h" |
25 #include "sync/syncable/in_memory_directory_backing_store.h" | 24 #include "sync/syncable/in_memory_directory_backing_store.h" |
26 #include "sync/syncable/metahandle_set.h" | 25 #include "sync/syncable/metahandle_set.h" |
27 #include "sync/syncable/mutable_entry.h" | 26 #include "sync/syncable/mutable_entry.h" |
28 #include "sync/syncable/on_disk_directory_backing_store.h" | 27 #include "sync/syncable/on_disk_directory_backing_store.h" |
29 #include "sync/syncable/read_transaction.h" | 28 #include "sync/syncable/read_transaction.h" |
30 #include "sync/syncable/syncable_proto_util.h" | 29 #include "sync/syncable/syncable_proto_util.h" |
31 #include "sync/syncable/syncable_util.h" | 30 #include "sync/syncable/syncable_util.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); | 137 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); |
139 EXPECT_TRUE(child_handles.empty()); | 138 EXPECT_TRUE(child_handles.empty()); |
140 | 139 |
141 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); | 140 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); |
142 EXPECT_TRUE(child_handles.empty()); | 141 EXPECT_TRUE(child_handles.empty()); |
143 } | 142 } |
144 | 143 |
145 // Test creating a new meta entry. | 144 // Test creating a new meta entry. |
146 { | 145 { |
147 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 146 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
148 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); | 147 MutableEntry me(&wtrans, CREATE_BOOKMARK, wtrans.root_id(), name); |
149 ASSERT_TRUE(me.good()); | 148 ASSERT_TRUE(me.good()); |
150 me.Put(ID, id); | 149 me.Put(ID, id); |
151 me.Put(BASE_VERSION, 1); | 150 me.Put(BASE_VERSION, 1); |
152 written_metahandle = me.Get(META_HANDLE); | 151 written_metahandle = me.Get(META_HANDLE); |
153 } | 152 } |
154 | 153 |
155 // Test GetChildHandles* after something is now in the DB. | 154 // Test GetChildHandles* after something is now in the DB. |
156 // Also check that GET_BY_ID works. | 155 // Also check that GET_BY_ID works. |
157 { | 156 { |
158 ReadTransaction rtrans(FROM_HERE, &dir); | 157 ReadTransaction rtrans(FROM_HERE, &dir); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 "SimpleTest", &delegate_, NullTransactionObserver())); | 221 "SimpleTest", &delegate_, NullTransactionObserver())); |
223 | 222 |
224 int64 written_metahandle; | 223 int64 written_metahandle; |
225 const Id id = TestIdFactory::FromNumber(99); | 224 const Id id = TestIdFactory::FromNumber(99); |
226 std::string name = "Jeff"; | 225 std::string name = "Jeff"; |
227 { | 226 { |
228 ReadTransaction rtrans(FROM_HERE, &dir); | 227 ReadTransaction rtrans(FROM_HERE, &dir); |
229 Entry e(&rtrans, GET_BY_ID, id); | 228 Entry e(&rtrans, GET_BY_ID, id); |
230 ASSERT_FALSE(e.good()); // Hasn't been written yet. | 229 ASSERT_FALSE(e.good()); // Hasn't been written yet. |
231 | 230 |
| 231 Entry root(&rtrans, GET_BY_ID, rtrans.root_id()); |
| 232 ASSERT_TRUE(root.good()); |
232 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id())); | 233 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id())); |
233 Id child_id; | 234 EXPECT_TRUE(root.GetFirstChildId().IsRoot()); |
234 EXPECT_TRUE(dir.GetFirstChildId(&rtrans, rtrans.root_id(), &child_id)); | |
235 EXPECT_TRUE(child_id.IsRoot()); | |
236 } | 235 } |
237 | 236 |
238 { | 237 { |
239 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 238 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
240 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); | 239 MutableEntry me(&wtrans, CREATE_BOOKMARK, wtrans.root_id(), name); |
241 ASSERT_TRUE(me.good()); | 240 ASSERT_TRUE(me.good()); |
242 me.Put(ID, id); | 241 me.Put(ID, id); |
243 me.Put(BASE_VERSION, 1); | 242 me.Put(BASE_VERSION, 1); |
244 written_metahandle = me.Get(META_HANDLE); | 243 written_metahandle = me.Get(META_HANDLE); |
245 } | 244 } |
246 | 245 |
247 // Test children ops after something is now in the DB. | 246 // Test children ops after something is now in the DB. |
248 { | 247 { |
249 ReadTransaction rtrans(FROM_HERE, &dir); | 248 ReadTransaction rtrans(FROM_HERE, &dir); |
250 Entry e(&rtrans, GET_BY_ID, id); | 249 Entry e(&rtrans, GET_BY_ID, id); |
251 ASSERT_TRUE(e.good()); | 250 ASSERT_TRUE(e.good()); |
252 | 251 |
253 Entry child(&rtrans, GET_BY_HANDLE, written_metahandle); | 252 Entry child(&rtrans, GET_BY_HANDLE, written_metahandle); |
254 ASSERT_TRUE(child.good()); | 253 ASSERT_TRUE(child.good()); |
255 | 254 |
| 255 Entry root(&rtrans, GET_BY_ID, rtrans.root_id()); |
| 256 ASSERT_TRUE(root.good()); |
256 EXPECT_TRUE(dir.HasChildren(&rtrans, rtrans.root_id())); | 257 EXPECT_TRUE(dir.HasChildren(&rtrans, rtrans.root_id())); |
257 Id child_id; | 258 EXPECT_EQ(e.Get(ID), root.GetFirstChildId()); |
258 EXPECT_TRUE(dir.GetFirstChildId(&rtrans, rtrans.root_id(), &child_id)); | |
259 EXPECT_EQ(e.Get(ID), child_id); | |
260 } | 259 } |
261 | 260 |
262 { | 261 { |
263 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 262 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
264 MutableEntry me(&wtrans, GET_BY_HANDLE, written_metahandle); | 263 MutableEntry me(&wtrans, GET_BY_HANDLE, written_metahandle); |
265 ASSERT_TRUE(me.good()); | 264 ASSERT_TRUE(me.good()); |
266 me.Put(IS_DEL, true); | 265 me.Put(IS_DEL, true); |
267 } | 266 } |
268 | 267 |
269 // Test children ops after the children have been deleted. | 268 // Test children ops after the children have been deleted. |
270 { | 269 { |
271 ReadTransaction rtrans(FROM_HERE, &dir); | 270 ReadTransaction rtrans(FROM_HERE, &dir); |
272 Entry e(&rtrans, GET_BY_ID, id); | 271 Entry e(&rtrans, GET_BY_ID, id); |
273 ASSERT_TRUE(e.good()); | 272 ASSERT_TRUE(e.good()); |
274 | 273 |
| 274 Entry root(&rtrans, GET_BY_ID, rtrans.root_id()); |
| 275 ASSERT_TRUE(root.good()); |
275 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id())); | 276 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id())); |
276 Id child_id; | 277 EXPECT_TRUE(root.GetFirstChildId().IsRoot()); |
277 EXPECT_TRUE(dir.GetFirstChildId(&rtrans, rtrans.root_id(), &child_id)); | |
278 EXPECT_TRUE(child_id.IsRoot()); | |
279 } | 278 } |
280 | 279 |
281 dir.SaveChanges(); | 280 dir.SaveChanges(); |
282 } | 281 } |
283 | 282 |
284 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) { | 283 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) { |
285 int64 written_metahandle; | 284 int64 written_metahandle; |
286 TestIdFactory factory; | 285 TestIdFactory factory; |
287 const Id id = factory.NewServerId(); | 286 const Id id = factory.NewServerId(); |
288 std::string name = "cheesepuffs"; | 287 std::string name = "cheesepuffs"; |
289 std::string tag = "dietcoke"; | 288 std::string tag = "dietcoke"; |
290 | 289 |
291 // Test creating a new meta entry. | 290 // Test creating a new meta entry. |
292 { | 291 { |
293 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), | 292 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), |
294 &handler_, | 293 &handler_, |
295 NULL, | 294 NULL, |
296 NULL, | 295 NULL, |
297 NULL); | 296 NULL); |
298 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, | 297 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, |
299 NullTransactionObserver())); | 298 NullTransactionObserver())); |
300 { | 299 { |
301 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 300 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
302 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); | 301 MutableEntry me(&wtrans, CREATE_BOOKMARK, wtrans.root_id(), name); |
303 ASSERT_TRUE(me.good()); | 302 ASSERT_TRUE(me.good()); |
304 me.Put(ID, id); | 303 me.Put(ID, id); |
305 me.Put(BASE_VERSION, 1); | 304 me.Put(BASE_VERSION, 1); |
306 me.Put(UNIQUE_CLIENT_TAG, tag); | 305 me.Put(UNIQUE_CLIENT_TAG, tag); |
307 written_metahandle = me.Get(META_HANDLE); | 306 written_metahandle = me.Get(META_HANDLE); |
308 } | 307 } |
309 dir.SaveChanges(); | 308 dir.SaveChanges(); |
310 } | 309 } |
311 | 310 |
312 // The DB was closed. Now reopen it. This will cause index regeneration. | 311 // The DB was closed. Now reopen it. This will cause index regeneration. |
(...skipping 25 matching lines...) Expand all Loading... |
338 { | 337 { |
339 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), | 338 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), |
340 &handler_, | 339 &handler_, |
341 NULL, | 340 NULL, |
342 NULL, | 341 NULL, |
343 NULL); | 342 NULL); |
344 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, | 343 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, |
345 NullTransactionObserver())); | 344 NullTransactionObserver())); |
346 { | 345 { |
347 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 346 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
348 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "deleted"); | 347 MutableEntry me(&wtrans, CREATE_BOOKMARK, wtrans.root_id(), "deleted"); |
349 ASSERT_TRUE(me.good()); | 348 ASSERT_TRUE(me.good()); |
350 me.Put(ID, id); | 349 me.Put(ID, id); |
351 me.Put(BASE_VERSION, 1); | 350 me.Put(BASE_VERSION, 1); |
352 me.Put(UNIQUE_CLIENT_TAG, tag); | 351 me.Put(UNIQUE_CLIENT_TAG, tag); |
353 me.Put(IS_DEL, true); | 352 me.Put(IS_DEL, true); |
354 me.Put(IS_UNSYNCED, true); // Or it might be purged. | 353 me.Put(IS_UNSYNCED, true); // Or it might be purged. |
355 } | 354 } |
356 dir.SaveChanges(); | 355 dir.SaveChanges(); |
357 } | 356 } |
358 | 357 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 EXPECT_FALSE(e.good()); // Hasn't been written yet. | 392 EXPECT_FALSE(e.good()); // Hasn't been written yet. |
394 | 393 |
395 scoped_ptr<DictionaryValue> value(e.ToValue(NULL)); | 394 scoped_ptr<DictionaryValue> value(e.ToValue(NULL)); |
396 ExpectDictBooleanValue(false, *value, "good"); | 395 ExpectDictBooleanValue(false, *value, "good"); |
397 EXPECT_EQ(1u, value->size()); | 396 EXPECT_EQ(1u, value->size()); |
398 } | 397 } |
399 | 398 |
400 // Test creating a new meta entry. | 399 // Test creating a new meta entry. |
401 { | 400 { |
402 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 401 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
403 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "new"); | 402 MutableEntry me(&wtrans, CREATE_BOOKMARK, wtrans.root_id(), "new"); |
404 ASSERT_TRUE(me.good()); | 403 ASSERT_TRUE(me.good()); |
405 me.Put(ID, id); | 404 me.Put(ID, id); |
406 me.Put(BASE_VERSION, 1); | 405 me.Put(BASE_VERSION, 1); |
407 | 406 |
408 scoped_ptr<DictionaryValue> value(me.ToValue(NULL)); | 407 scoped_ptr<DictionaryValue> value(me.ToValue(NULL)); |
409 ExpectDictBooleanValue(true, *value, "good"); | 408 ExpectDictBooleanValue(true, *value, "good"); |
410 EXPECT_TRUE(value->HasKey("kernel")); | 409 EXPECT_TRUE(value->HasKey("kernel")); |
411 ExpectDictStringValue("Unspecified", *value, "modelType"); | 410 ExpectDictStringValue("Bookmarks", *value, "modelType"); |
412 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty"); | 411 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty"); |
413 ExpectDictBooleanValue(false, *value, "isRoot"); | 412 ExpectDictBooleanValue(false, *value, "isRoot"); |
414 } | 413 } |
415 | 414 |
416 dir.SaveChanges(); | 415 dir.SaveChanges(); |
417 } | 416 } |
418 | 417 |
419 // A test fixture for syncable::Directory. Uses an in-memory database to keep | 418 // A test fixture for syncable::Directory. Uses an in-memory database to keep |
420 // the unit tests fast. | 419 // the unit tests fast. |
421 class SyncableDirectoryTest : public testing::Test { | 420 class SyncableDirectoryTest : public testing::Test { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 void CreateEntry(const std::string& entryname) { | 495 void CreateEntry(const std::string& entryname) { |
497 CreateEntry(entryname, TestIdFactory::FromNumber(-99)); | 496 CreateEntry(entryname, TestIdFactory::FromNumber(-99)); |
498 } | 497 } |
499 | 498 |
500 // Creates an empty entry and sets the ID field to id. | 499 // Creates an empty entry and sets the ID field to id. |
501 void CreateEntry(const std::string& entryname, const int id) { | 500 void CreateEntry(const std::string& entryname, const int id) { |
502 CreateEntry(entryname, TestIdFactory::FromNumber(id)); | 501 CreateEntry(entryname, TestIdFactory::FromNumber(id)); |
503 } | 502 } |
504 void CreateEntry(const std::string& entryname, Id id) { | 503 void CreateEntry(const std::string& entryname, Id id) { |
505 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); | 504 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); |
506 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), entryname); | 505 MutableEntry me(&wtrans, CREATE_BOOKMARK, wtrans.root_id(), entryname); |
507 ASSERT_TRUE(me.good()); | 506 ASSERT_TRUE(me.good()); |
508 me.Put(ID, id); | 507 me.Put(ID, id); |
509 me.Put(IS_UNSYNCED, true); | 508 me.Put(IS_UNSYNCED, true); |
510 } | 509 } |
511 | 510 |
512 void ValidateEntry(BaseTransaction* trans, | 511 void ValidateEntry(BaseTransaction* trans, |
513 int64 id, | 512 int64 id, |
514 bool check_name, | 513 bool check_name, |
515 const std::string& name, | 514 const std::string& name, |
516 int64 base_version, | 515 int64 base_version, |
(...skipping 19 matching lines...) Expand all Loading... |
536 DirOpenResult ReloadDirImpl(); | 535 DirOpenResult ReloadDirImpl(); |
537 }; | 536 }; |
538 | 537 |
539 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) { | 538 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) { |
540 const int metas_to_create = 50; | 539 const int metas_to_create = 50; |
541 MetahandleSet expected_purges; | 540 MetahandleSet expected_purges; |
542 MetahandleSet all_handles; | 541 MetahandleSet all_handles; |
543 { | 542 { |
544 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 543 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
545 for (int i = 0; i < metas_to_create; i++) { | 544 for (int i = 0; i < metas_to_create; i++) { |
546 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); | 545 MutableEntry e(&trans, CREATE_BOOKMARK, trans.root_id(), "foo"); |
547 e.Put(IS_UNSYNCED, true); | 546 e.Put(IS_UNSYNCED, true); |
548 sync_pb::EntitySpecifics specs; | 547 sync_pb::EntitySpecifics specs; |
549 if (i % 2 == 0) { | 548 if (i % 2 == 0) { |
550 AddDefaultFieldValue(BOOKMARKS, &specs); | 549 AddDefaultFieldValue(BOOKMARKS, &specs); |
551 expected_purges.insert(e.Get(META_HANDLE)); | 550 expected_purges.insert(e.Get(META_HANDLE)); |
552 all_handles.insert(e.Get(META_HANDLE)); | 551 all_handles.insert(e.Get(META_HANDLE)); |
553 } else { | 552 } else { |
554 AddDefaultFieldValue(PREFERENCES, &specs); | 553 AddDefaultFieldValue(PREFERENCES, &specs); |
555 all_handles.insert(e.Get(META_HANDLE)); | 554 all_handles.insert(e.Get(META_HANDLE)); |
556 } | 555 } |
(...skipping 20 matching lines...) Expand all Loading... |
577 dir_->TakeSnapshotForSaveChanges(&snapshot2); | 576 dir_->TakeSnapshotForSaveChanges(&snapshot2); |
578 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge); | 577 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge); |
579 } | 578 } |
580 | 579 |
581 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { | 580 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { |
582 const int metahandles_to_create = 100; | 581 const int metahandles_to_create = 100; |
583 std::vector<int64> expected_dirty_metahandles; | 582 std::vector<int64> expected_dirty_metahandles; |
584 { | 583 { |
585 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 584 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
586 for (int i = 0; i < metahandles_to_create; i++) { | 585 for (int i = 0; i < metahandles_to_create; i++) { |
587 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); | 586 MutableEntry e(&trans, CREATE_BOOKMARK, trans.root_id(), "foo"); |
588 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); | 587 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); |
589 e.Put(IS_UNSYNCED, true); | 588 e.Put(IS_UNSYNCED, true); |
590 } | 589 } |
591 } | 590 } |
592 // Fake SaveChanges() and make sure we got what we expected. | 591 // Fake SaveChanges() and make sure we got what we expected. |
593 { | 592 { |
594 Directory::SaveChangesSnapshot snapshot; | 593 Directory::SaveChangesSnapshot snapshot; |
595 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); | 594 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); |
596 dir_->TakeSnapshotForSaveChanges(&snapshot); | 595 dir_->TakeSnapshotForSaveChanges(&snapshot); |
597 // Make sure there's an entry for each new metahandle. Make sure all | 596 // Make sure there's an entry for each new metahandle. Make sure all |
(...skipping 10 matching lines...) Expand all Loading... |
608 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 607 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
609 std::vector<int64> new_dirty_metahandles; | 608 std::vector<int64> new_dirty_metahandles; |
610 for (std::vector<int64>::const_iterator i = | 609 for (std::vector<int64>::const_iterator i = |
611 expected_dirty_metahandles.begin(); | 610 expected_dirty_metahandles.begin(); |
612 i != expected_dirty_metahandles.end(); ++i) { | 611 i != expected_dirty_metahandles.end(); ++i) { |
613 // Change existing entries to directories to dirty them. | 612 // Change existing entries to directories to dirty them. |
614 MutableEntry e1(&trans, GET_BY_HANDLE, *i); | 613 MutableEntry e1(&trans, GET_BY_HANDLE, *i); |
615 e1.Put(IS_DIR, true); | 614 e1.Put(IS_DIR, true); |
616 e1.Put(IS_UNSYNCED, true); | 615 e1.Put(IS_UNSYNCED, true); |
617 // Add new entries | 616 // Add new entries |
618 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar"); | 617 MutableEntry e2(&trans, CREATE_BOOKMARK, trans.root_id(), "bar"); |
619 e2.Put(IS_UNSYNCED, true); | 618 e2.Put(IS_UNSYNCED, true); |
620 new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); | 619 new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); |
621 } | 620 } |
622 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), | 621 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), |
623 new_dirty_metahandles.begin(), new_dirty_metahandles.end()); | 622 new_dirty_metahandles.begin(), new_dirty_metahandles.end()); |
624 } | 623 } |
625 // Fake SaveChanges() and make sure we got what we expected. | 624 // Fake SaveChanges() and make sure we got what we expected. |
626 { | 625 { |
627 Directory::SaveChangesSnapshot snapshot; | 626 Directory::SaveChangesSnapshot snapshot; |
628 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); | 627 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); |
(...skipping 11 matching lines...) Expand all Loading... |
640 | 639 |
641 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { | 640 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { |
642 const int metahandles_to_create = 100; | 641 const int metahandles_to_create = 100; |
643 | 642 |
644 // half of 2 * metahandles_to_create | 643 // half of 2 * metahandles_to_create |
645 const unsigned int number_changed = 100u; | 644 const unsigned int number_changed = 100u; |
646 std::vector<int64> expected_dirty_metahandles; | 645 std::vector<int64> expected_dirty_metahandles; |
647 { | 646 { |
648 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 647 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
649 for (int i = 0; i < metahandles_to_create; i++) { | 648 for (int i = 0; i < metahandles_to_create; i++) { |
650 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); | 649 MutableEntry e(&trans, CREATE_BOOKMARK, trans.root_id(), "foo"); |
651 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); | 650 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); |
652 e.Put(IS_UNSYNCED, true); | 651 e.Put(IS_UNSYNCED, true); |
653 } | 652 } |
654 } | 653 } |
655 dir_->SaveChanges(); | 654 dir_->SaveChanges(); |
656 // Put a new value with existing transactions as well as adding new ones. | 655 // Put a new value with existing transactions as well as adding new ones. |
657 { | 656 { |
658 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 657 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
659 std::vector<int64> new_dirty_metahandles; | 658 std::vector<int64> new_dirty_metahandles; |
660 for (std::vector<int64>::const_iterator i = | 659 for (std::vector<int64>::const_iterator i = |
661 expected_dirty_metahandles.begin(); | 660 expected_dirty_metahandles.begin(); |
662 i != expected_dirty_metahandles.end(); ++i) { | 661 i != expected_dirty_metahandles.end(); ++i) { |
663 // Change existing entries to directories to dirty them. | 662 // Change existing entries to directories to dirty them. |
664 MutableEntry e1(&trans, GET_BY_HANDLE, *i); | 663 MutableEntry e1(&trans, GET_BY_HANDLE, *i); |
665 ASSERT_TRUE(e1.good()); | 664 ASSERT_TRUE(e1.good()); |
666 e1.Put(IS_DIR, true); | 665 e1.Put(IS_DIR, true); |
667 e1.Put(IS_UNSYNCED, true); | 666 e1.Put(IS_UNSYNCED, true); |
668 // Add new entries | 667 // Add new entries |
669 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar"); | 668 MutableEntry e2(&trans, CREATE_BOOKMARK, trans.root_id(), "bar"); |
670 e2.Put(IS_UNSYNCED, true); | 669 e2.Put(IS_UNSYNCED, true); |
671 new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); | 670 new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); |
672 } | 671 } |
673 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), | 672 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), |
674 new_dirty_metahandles.begin(), new_dirty_metahandles.end()); | 673 new_dirty_metahandles.begin(), new_dirty_metahandles.end()); |
675 } | 674 } |
676 dir_->SaveChanges(); | 675 dir_->SaveChanges(); |
677 // Don't make any changes whatsoever and ensure nothing comes back. | 676 // Don't make any changes whatsoever and ensure nothing comes back. |
678 { | 677 { |
679 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 678 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { | 739 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { |
741 CreateEntry("rtc"); | 740 CreateEntry("rtc"); |
742 ReadTransaction rtrans(FROM_HERE, dir_.get()); | 741 ReadTransaction rtrans(FROM_HERE, dir_.get()); |
743 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99)); | 742 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99)); |
744 ASSERT_TRUE(e.good()); | 743 ASSERT_TRUE(e.good()); |
745 } | 744 } |
746 | 745 |
747 TEST_F(SyncableDirectoryTest, TestDelete) { | 746 TEST_F(SyncableDirectoryTest, TestDelete) { |
748 std::string name = "peanut butter jelly time"; | 747 std::string name = "peanut butter jelly time"; |
749 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 748 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
750 MutableEntry e1(&trans, CREATE, trans.root_id(), name); | 749 MutableEntry e1(&trans, CREATE_BOOKMARK, trans.root_id(), name); |
751 ASSERT_TRUE(e1.good()); | 750 ASSERT_TRUE(e1.good()); |
752 ASSERT_TRUE(e1.Put(IS_DEL, true)); | 751 ASSERT_TRUE(e1.Put(IS_DEL, true)); |
753 MutableEntry e2(&trans, CREATE, trans.root_id(), name); | 752 MutableEntry e2(&trans, CREATE_BOOKMARK, trans.root_id(), name); |
754 ASSERT_TRUE(e2.good()); | 753 ASSERT_TRUE(e2.good()); |
755 ASSERT_TRUE(e2.Put(IS_DEL, true)); | 754 ASSERT_TRUE(e2.Put(IS_DEL, true)); |
756 MutableEntry e3(&trans, CREATE, trans.root_id(), name); | 755 MutableEntry e3(&trans, CREATE_BOOKMARK, trans.root_id(), name); |
757 ASSERT_TRUE(e3.good()); | 756 ASSERT_TRUE(e3.good()); |
758 ASSERT_TRUE(e3.Put(IS_DEL, true)); | 757 ASSERT_TRUE(e3.Put(IS_DEL, true)); |
759 | 758 |
760 ASSERT_TRUE(e1.Put(IS_DEL, false)); | 759 ASSERT_TRUE(e1.Put(IS_DEL, false)); |
761 ASSERT_TRUE(e2.Put(IS_DEL, false)); | 760 ASSERT_TRUE(e2.Put(IS_DEL, false)); |
762 ASSERT_TRUE(e3.Put(IS_DEL, false)); | 761 ASSERT_TRUE(e3.Put(IS_DEL, false)); |
763 | 762 |
764 ASSERT_TRUE(e1.Put(IS_DEL, true)); | 763 ASSERT_TRUE(e1.Put(IS_DEL, true)); |
765 ASSERT_TRUE(e2.Put(IS_DEL, true)); | 764 ASSERT_TRUE(e2.Put(IS_DEL, true)); |
766 ASSERT_TRUE(e3.Put(IS_DEL, true)); | 765 ASSERT_TRUE(e3.Put(IS_DEL, true)); |
767 } | 766 } |
768 | 767 |
769 TEST_F(SyncableDirectoryTest, TestGetUnsynced) { | 768 TEST_F(SyncableDirectoryTest, TestGetUnsynced) { |
770 Directory::UnsyncedMetaHandles handles; | 769 Directory::UnsyncedMetaHandles handles; |
771 int64 handle1, handle2; | 770 int64 handle1, handle2; |
772 { | 771 { |
773 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 772 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
774 | 773 |
775 dir_->GetUnsyncedMetaHandles(&trans, &handles); | 774 dir_->GetUnsyncedMetaHandles(&trans, &handles); |
776 ASSERT_TRUE(0 == handles.size()); | 775 ASSERT_TRUE(0 == handles.size()); |
777 | 776 |
778 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); | 777 MutableEntry e1(&trans, CREATE_BOOKMARK, trans.root_id(), "abba"); |
779 ASSERT_TRUE(e1.good()); | 778 ASSERT_TRUE(e1.good()); |
780 handle1 = e1.Get(META_HANDLE); | 779 handle1 = e1.Get(META_HANDLE); |
781 e1.Put(BASE_VERSION, 1); | 780 e1.Put(BASE_VERSION, 1); |
782 e1.Put(IS_DIR, true); | 781 e1.Put(IS_DIR, true); |
783 e1.Put(ID, TestIdFactory::FromNumber(101)); | 782 e1.Put(ID, TestIdFactory::FromNumber(101)); |
784 | 783 |
785 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); | 784 MutableEntry e2(&trans, CREATE_BOOKMARK, e1.Get(ID), "bread"); |
786 ASSERT_TRUE(e2.good()); | 785 ASSERT_TRUE(e2.good()); |
787 handle2 = e2.Get(META_HANDLE); | 786 handle2 = e2.Get(META_HANDLE); |
788 e2.Put(BASE_VERSION, 1); | 787 e2.Put(BASE_VERSION, 1); |
789 e2.Put(ID, TestIdFactory::FromNumber(102)); | 788 e2.Put(ID, TestIdFactory::FromNumber(102)); |
790 } | 789 } |
791 dir_->SaveChanges(); | 790 dir_->SaveChanges(); |
792 { | 791 { |
793 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 792 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
794 | 793 |
795 dir_->GetUnsyncedMetaHandles(&trans, &handles); | 794 dir_->GetUnsyncedMetaHandles(&trans, &handles); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { | 839 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { |
841 std::vector<int64> handles; | 840 std::vector<int64> handles; |
842 int64 handle1, handle2; | 841 int64 handle1, handle2; |
843 const FullModelTypeSet all_types = FullModelTypeSet::All(); | 842 const FullModelTypeSet all_types = FullModelTypeSet::All(); |
844 { | 843 { |
845 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 844 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
846 | 845 |
847 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 846 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); |
848 ASSERT_TRUE(0 == handles.size()); | 847 ASSERT_TRUE(0 == handles.size()); |
849 | 848 |
850 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); | 849 MutableEntry e1(&trans, CREATE_BOOKMARK, trans.root_id(), "abba"); |
851 ASSERT_TRUE(e1.good()); | 850 ASSERT_TRUE(e1.good()); |
852 handle1 = e1.Get(META_HANDLE); | 851 handle1 = e1.Get(META_HANDLE); |
853 e1.Put(IS_UNAPPLIED_UPDATE, false); | 852 e1.Put(IS_UNAPPLIED_UPDATE, false); |
854 e1.Put(BASE_VERSION, 1); | 853 e1.Put(BASE_VERSION, 1); |
855 e1.Put(ID, TestIdFactory::FromNumber(101)); | 854 e1.Put(ID, TestIdFactory::FromNumber(101)); |
856 e1.Put(IS_DIR, true); | 855 e1.Put(IS_DIR, true); |
857 | 856 |
858 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); | 857 MutableEntry e2(&trans, CREATE_BOOKMARK, e1.Get(ID), "bread"); |
859 ASSERT_TRUE(e2.good()); | 858 ASSERT_TRUE(e2.good()); |
860 handle2 = e2.Get(META_HANDLE); | 859 handle2 = e2.Get(META_HANDLE); |
861 e2.Put(IS_UNAPPLIED_UPDATE, false); | 860 e2.Put(IS_UNAPPLIED_UPDATE, false); |
862 e2.Put(BASE_VERSION, 1); | 861 e2.Put(BASE_VERSION, 1); |
863 e2.Put(ID, TestIdFactory::FromNumber(102)); | 862 e2.Put(ID, TestIdFactory::FromNumber(102)); |
864 } | 863 } |
865 dir_->SaveChanges(); | 864 dir_->SaveChanges(); |
866 { | 865 { |
867 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 866 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
868 | 867 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 } | 908 } |
910 } | 909 } |
911 | 910 |
912 | 911 |
913 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { | 912 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { |
914 // Try to evoke a check failure... | 913 // Try to evoke a check failure... |
915 TestIdFactory id_factory; | 914 TestIdFactory id_factory; |
916 int64 grandchild_handle; | 915 int64 grandchild_handle; |
917 { | 916 { |
918 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); | 917 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); |
919 MutableEntry parent(&wtrans, CREATE, id_factory.root(), "Bob"); | 918 MutableEntry parent(&wtrans, CREATE_BOOKMARK, id_factory.root(), "Bob"); |
920 ASSERT_TRUE(parent.good()); | 919 ASSERT_TRUE(parent.good()); |
921 parent.Put(IS_DIR, true); | 920 parent.Put(IS_DIR, true); |
922 parent.Put(ID, id_factory.NewServerId()); | 921 parent.Put(ID, id_factory.NewServerId()); |
923 parent.Put(BASE_VERSION, 1); | 922 parent.Put(BASE_VERSION, 1); |
924 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob"); | 923 MutableEntry child(&wtrans, CREATE_BOOKMARK, parent.Get(ID), "Bob"); |
925 ASSERT_TRUE(child.good()); | 924 ASSERT_TRUE(child.good()); |
926 child.Put(IS_DIR, true); | 925 child.Put(IS_DIR, true); |
927 child.Put(ID, id_factory.NewServerId()); | 926 child.Put(ID, id_factory.NewServerId()); |
928 child.Put(BASE_VERSION, 1); | 927 child.Put(BASE_VERSION, 1); |
929 MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob"); | 928 MutableEntry grandchild(&wtrans, CREATE_BOOKMARK, child.Get(ID), "Bob"); |
930 ASSERT_TRUE(grandchild.good()); | 929 ASSERT_TRUE(grandchild.good()); |
931 grandchild.Put(ID, id_factory.NewServerId()); | 930 grandchild.Put(ID, id_factory.NewServerId()); |
932 grandchild.Put(BASE_VERSION, 1); | 931 grandchild.Put(BASE_VERSION, 1); |
933 ASSERT_TRUE(grandchild.Put(IS_DEL, true)); | 932 ASSERT_TRUE(grandchild.Put(IS_DEL, true)); |
934 MutableEntry twin(&wtrans, CREATE, child.Get(ID), "Bob"); | 933 MutableEntry twin(&wtrans, CREATE_BOOKMARK, child.Get(ID), "Bob"); |
935 ASSERT_TRUE(twin.good()); | 934 ASSERT_TRUE(twin.good()); |
936 ASSERT_TRUE(twin.Put(IS_DEL, true)); | 935 ASSERT_TRUE(twin.Put(IS_DEL, true)); |
937 ASSERT_TRUE(grandchild.Put(IS_DEL, false)); | 936 ASSERT_TRUE(grandchild.Put(IS_DEL, false)); |
938 | 937 |
939 grandchild_handle = grandchild.Get(META_HANDLE); | 938 grandchild_handle = grandchild.Get(META_HANDLE); |
940 } | 939 } |
941 dir_->SaveChanges(); | 940 dir_->SaveChanges(); |
942 { | 941 { |
943 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); | 942 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); |
944 MutableEntry grandchild(&wtrans, GET_BY_HANDLE, grandchild_handle); | 943 MutableEntry grandchild(&wtrans, GET_BY_HANDLE, grandchild_handle); |
945 grandchild.Put(IS_DEL, true); // Used to CHECK fail here. | 944 grandchild.Put(IS_DEL, true); // Used to CHECK fail here. |
946 } | 945 } |
947 } | 946 } |
948 | 947 |
949 static inline bool IsLegalNewParent(const Entry& a, const Entry& b) { | 948 static inline bool IsLegalNewParent(const Entry& a, const Entry& b) { |
950 return IsLegalNewParent(a.trans(), a.Get(ID), b.Get(ID)); | 949 return IsLegalNewParent(a.trans(), a.Get(ID), b.Get(ID)); |
951 } | 950 } |
952 | 951 |
953 TEST_F(SyncableDirectoryTest, TestIsLegalNewParent) { | 952 TEST_F(SyncableDirectoryTest, TestIsLegalNewParent) { |
954 TestIdFactory id_factory; | 953 TestIdFactory id_factory; |
955 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); | 954 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); |
956 Entry root(&wtrans, GET_BY_ID, id_factory.root()); | 955 Entry root(&wtrans, GET_BY_ID, id_factory.root()); |
957 ASSERT_TRUE(root.good()); | 956 ASSERT_TRUE(root.good()); |
958 MutableEntry parent(&wtrans, CREATE, root.Get(ID), "Bob"); | 957 MutableEntry parent(&wtrans, CREATE_BOOKMARK, root.Get(ID), "Bob"); |
959 ASSERT_TRUE(parent.good()); | 958 ASSERT_TRUE(parent.good()); |
960 parent.Put(IS_DIR, true); | 959 parent.Put(IS_DIR, true); |
961 parent.Put(ID, id_factory.NewServerId()); | 960 parent.Put(ID, id_factory.NewServerId()); |
962 parent.Put(BASE_VERSION, 1); | 961 parent.Put(BASE_VERSION, 1); |
963 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob"); | 962 MutableEntry child(&wtrans, CREATE_BOOKMARK, parent.Get(ID), "Bob"); |
964 ASSERT_TRUE(child.good()); | 963 ASSERT_TRUE(child.good()); |
965 child.Put(IS_DIR, true); | 964 child.Put(IS_DIR, true); |
966 child.Put(ID, id_factory.NewServerId()); | 965 child.Put(ID, id_factory.NewServerId()); |
967 child.Put(BASE_VERSION, 1); | 966 child.Put(BASE_VERSION, 1); |
968 MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob"); | 967 MutableEntry grandchild(&wtrans, CREATE_BOOKMARK, child.Get(ID), "Bob"); |
969 ASSERT_TRUE(grandchild.good()); | 968 ASSERT_TRUE(grandchild.good()); |
970 grandchild.Put(ID, id_factory.NewServerId()); | 969 grandchild.Put(ID, id_factory.NewServerId()); |
971 grandchild.Put(BASE_VERSION, 1); | 970 grandchild.Put(BASE_VERSION, 1); |
972 | 971 |
973 MutableEntry parent2(&wtrans, CREATE, root.Get(ID), "Pete"); | 972 MutableEntry parent2(&wtrans, CREATE_BOOKMARK, root.Get(ID), "Pete"); |
974 ASSERT_TRUE(parent2.good()); | 973 ASSERT_TRUE(parent2.good()); |
975 parent2.Put(IS_DIR, true); | 974 parent2.Put(IS_DIR, true); |
976 parent2.Put(ID, id_factory.NewServerId()); | 975 parent2.Put(ID, id_factory.NewServerId()); |
977 parent2.Put(BASE_VERSION, 1); | 976 parent2.Put(BASE_VERSION, 1); |
978 MutableEntry child2(&wtrans, CREATE, parent2.Get(ID), "Pete"); | 977 MutableEntry child2(&wtrans, CREATE_BOOKMARK, parent2.Get(ID), "Pete"); |
979 ASSERT_TRUE(child2.good()); | 978 ASSERT_TRUE(child2.good()); |
980 child2.Put(IS_DIR, true); | 979 child2.Put(IS_DIR, true); |
981 child2.Put(ID, id_factory.NewServerId()); | 980 child2.Put(ID, id_factory.NewServerId()); |
982 child2.Put(BASE_VERSION, 1); | 981 child2.Put(BASE_VERSION, 1); |
983 MutableEntry grandchild2(&wtrans, CREATE, child2.Get(ID), "Pete"); | 982 MutableEntry grandchild2(&wtrans, CREATE_BOOKMARK, child2.Get(ID), "Pete"); |
984 ASSERT_TRUE(grandchild2.good()); | 983 ASSERT_TRUE(grandchild2.good()); |
985 grandchild2.Put(ID, id_factory.NewServerId()); | 984 grandchild2.Put(ID, id_factory.NewServerId()); |
986 grandchild2.Put(BASE_VERSION, 1); | 985 grandchild2.Put(BASE_VERSION, 1); |
987 // resulting tree | 986 // resulting tree |
988 // root | 987 // root |
989 // / | | 988 // / | |
990 // parent parent2 | 989 // parent parent2 |
991 // | | | 990 // | | |
992 // child child2 | 991 // child child2 |
993 // | | | 992 // | | |
(...skipping 11 matching lines...) Expand all Loading... |
1005 | 1004 |
1006 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { | 1005 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { |
1007 // Create a subdir and an entry. | 1006 // Create a subdir and an entry. |
1008 int64 entry_handle; | 1007 int64 entry_handle; |
1009 syncable::Id folder_id; | 1008 syncable::Id folder_id; |
1010 syncable::Id entry_id; | 1009 syncable::Id entry_id; |
1011 std::string entry_name = "entry"; | 1010 std::string entry_name = "entry"; |
1012 | 1011 |
1013 { | 1012 { |
1014 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1013 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1015 MutableEntry folder(&trans, CREATE, trans.root_id(), "folder"); | 1014 MutableEntry folder(&trans, CREATE_BOOKMARK, trans.root_id(), "folder"); |
1016 ASSERT_TRUE(folder.good()); | 1015 ASSERT_TRUE(folder.good()); |
1017 EXPECT_TRUE(folder.Put(IS_DIR, true)); | 1016 EXPECT_TRUE(folder.Put(IS_DIR, true)); |
1018 EXPECT_TRUE(folder.Put(IS_UNSYNCED, true)); | 1017 EXPECT_TRUE(folder.Put(IS_UNSYNCED, true)); |
1019 folder_id = folder.Get(ID); | 1018 folder_id = folder.Get(ID); |
1020 | 1019 |
1021 MutableEntry entry(&trans, CREATE, folder.Get(ID), entry_name); | 1020 MutableEntry entry(&trans, CREATE_BOOKMARK, folder.Get(ID), entry_name); |
1022 ASSERT_TRUE(entry.good()); | 1021 ASSERT_TRUE(entry.good()); |
1023 entry_handle = entry.Get(META_HANDLE); | 1022 entry_handle = entry.Get(META_HANDLE); |
1024 entry.Put(IS_UNSYNCED, true); | 1023 entry.Put(IS_UNSYNCED, true); |
1025 entry_id = entry.Get(ID); | 1024 entry_id = entry.Get(ID); |
1026 } | 1025 } |
1027 | 1026 |
1028 // Make sure we can find the entry in the folder. | 1027 // Make sure we can find the entry in the folder. |
1029 { | 1028 { |
1030 ReadTransaction trans(FROM_HERE, dir_.get()); | 1029 ReadTransaction trans(FROM_HERE, dir_.get()); |
1031 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), entry_name)); | 1030 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), entry_name)); |
1032 EXPECT_EQ(1, CountEntriesWithName(&trans, folder_id, entry_name)); | 1031 EXPECT_EQ(1, CountEntriesWithName(&trans, folder_id, entry_name)); |
1033 | 1032 |
1034 Entry entry(&trans, GET_BY_ID, entry_id); | 1033 Entry entry(&trans, GET_BY_ID, entry_id); |
1035 ASSERT_TRUE(entry.good()); | 1034 ASSERT_TRUE(entry.good()); |
1036 EXPECT_EQ(entry_handle, entry.Get(META_HANDLE)); | 1035 EXPECT_EQ(entry_handle, entry.Get(META_HANDLE)); |
1037 EXPECT_TRUE(entry.Get(NON_UNIQUE_NAME) == entry_name); | 1036 EXPECT_TRUE(entry.Get(NON_UNIQUE_NAME) == entry_name); |
1038 EXPECT_TRUE(entry.Get(PARENT_ID) == folder_id); | 1037 EXPECT_TRUE(entry.Get(PARENT_ID) == folder_id); |
1039 } | 1038 } |
1040 } | 1039 } |
1041 | 1040 |
1042 TEST_F(SyncableDirectoryTest, TestParentIdIndexUpdate) { | 1041 TEST_F(SyncableDirectoryTest, TestParentIdIndexUpdate) { |
1043 std::string child_name = "child"; | 1042 std::string child_name = "child"; |
1044 | 1043 |
1045 WriteTransaction wt(FROM_HERE, UNITTEST, dir_.get()); | 1044 WriteTransaction wt(FROM_HERE, UNITTEST, dir_.get()); |
1046 MutableEntry parent_folder(&wt, CREATE, wt.root_id(), "folder1"); | 1045 MutableEntry parent_folder(&wt, CREATE_BOOKMARK, wt.root_id(), "folder1"); |
1047 parent_folder.Put(IS_UNSYNCED, true); | 1046 parent_folder.Put(IS_UNSYNCED, true); |
1048 EXPECT_TRUE(parent_folder.Put(IS_DIR, true)); | 1047 EXPECT_TRUE(parent_folder.Put(IS_DIR, true)); |
1049 | 1048 |
1050 MutableEntry parent_folder2(&wt, CREATE, wt.root_id(), "folder2"); | 1049 MutableEntry parent_folder2(&wt, CREATE_BOOKMARK, wt.root_id(), "folder2"); |
1051 parent_folder2.Put(IS_UNSYNCED, true); | 1050 parent_folder2.Put(IS_UNSYNCED, true); |
1052 EXPECT_TRUE(parent_folder2.Put(IS_DIR, true)); | 1051 EXPECT_TRUE(parent_folder2.Put(IS_DIR, true)); |
1053 | 1052 |
1054 MutableEntry child(&wt, CREATE, parent_folder.Get(ID), child_name); | 1053 MutableEntry child(&wt, CREATE_BOOKMARK, parent_folder.Get(ID), child_name); |
1055 EXPECT_TRUE(child.Put(IS_DIR, true)); | 1054 EXPECT_TRUE(child.Put(IS_DIR, true)); |
1056 child.Put(IS_UNSYNCED, true); | 1055 child.Put(IS_UNSYNCED, true); |
1057 | 1056 |
1058 ASSERT_TRUE(child.good()); | 1057 ASSERT_TRUE(child.good()); |
1059 | 1058 |
1060 EXPECT_EQ(0, CountEntriesWithName(&wt, wt.root_id(), child_name)); | 1059 EXPECT_EQ(0, CountEntriesWithName(&wt, wt.root_id(), child_name)); |
1061 EXPECT_EQ(parent_folder.Get(ID), child.Get(PARENT_ID)); | 1060 EXPECT_EQ(parent_folder.Get(ID), child.Get(PARENT_ID)); |
1062 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); | 1061 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); |
1063 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); | 1062 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); |
1064 child.Put(PARENT_ID, parent_folder2.Get(ID)); | 1063 child.Put(PARENT_ID, parent_folder2.Get(ID)); |
1065 EXPECT_EQ(parent_folder2.Get(ID), child.Get(PARENT_ID)); | 1064 EXPECT_EQ(parent_folder2.Get(ID), child.Get(PARENT_ID)); |
1066 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); | 1065 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); |
1067 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); | 1066 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); |
1068 } | 1067 } |
1069 | 1068 |
1070 TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) { | 1069 TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) { |
1071 std::string folder_name = "folder"; | 1070 std::string folder_name = "folder"; |
1072 std::string new_name = "new_name"; | 1071 std::string new_name = "new_name"; |
1073 | 1072 |
1074 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1073 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1075 MutableEntry folder(&trans, CREATE, trans.root_id(), folder_name); | 1074 MutableEntry folder(&trans, CREATE_BOOKMARK, trans.root_id(), folder_name); |
1076 ASSERT_TRUE(folder.good()); | 1075 ASSERT_TRUE(folder.good()); |
1077 ASSERT_TRUE(folder.Put(IS_DIR, true)); | 1076 ASSERT_TRUE(folder.Put(IS_DIR, true)); |
1078 ASSERT_TRUE(folder.Put(IS_DEL, true)); | 1077 ASSERT_TRUE(folder.Put(IS_DEL, true)); |
1079 | 1078 |
1080 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); | 1079 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); |
1081 | 1080 |
1082 MutableEntry deleted(&trans, GET_BY_ID, folder.Get(ID)); | 1081 MutableEntry deleted(&trans, GET_BY_ID, folder.Get(ID)); |
1083 ASSERT_TRUE(deleted.good()); | 1082 ASSERT_TRUE(deleted.good()); |
1084 ASSERT_TRUE(deleted.Put(PARENT_ID, trans.root_id())); | 1083 ASSERT_TRUE(deleted.Put(PARENT_ID, trans.root_id())); |
1085 ASSERT_TRUE(deleted.Put(NON_UNIQUE_NAME, new_name)); | 1084 ASSERT_TRUE(deleted.Put(NON_UNIQUE_NAME, new_name)); |
1086 | 1085 |
1087 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); | 1086 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); |
1088 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), new_name)); | 1087 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), new_name)); |
1089 } | 1088 } |
1090 | 1089 |
1091 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) { | 1090 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) { |
1092 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1091 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1093 MutableEntry folder(&trans, CREATE, trans.root_id(), "CaseChange"); | 1092 MutableEntry folder(&trans, CREATE_BOOKMARK, trans.root_id(), "CaseChange"); |
1094 ASSERT_TRUE(folder.good()); | 1093 ASSERT_TRUE(folder.good()); |
1095 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id())); | 1094 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id())); |
1096 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE")); | 1095 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE")); |
1097 EXPECT_TRUE(folder.Put(IS_DEL, true)); | 1096 EXPECT_TRUE(folder.Put(IS_DEL, true)); |
1098 } | 1097 } |
1099 | 1098 |
1100 // Create items of each model type, and check that GetModelType and | 1099 // Create items of each model type, and check that GetModelType and |
1101 // GetServerModelType return the right value. | 1100 // GetServerModelType return the right value. |
1102 TEST_F(SyncableDirectoryTest, GetModelType) { | 1101 TEST_F(SyncableDirectoryTest, GetModelType) { |
1103 TestIdFactory id_factory; | 1102 TestIdFactory id_factory; |
1104 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { | 1103 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { |
1105 ModelType datatype = ModelTypeFromInt(i); | 1104 ModelType datatype = ModelTypeFromInt(i); |
1106 SCOPED_TRACE(testing::Message("Testing model type ") << datatype); | 1105 SCOPED_TRACE(testing::Message("Testing model type ") << datatype); |
1107 switch (datatype) { | 1106 switch (datatype) { |
1108 case UNSPECIFIED: | 1107 case UNSPECIFIED: |
1109 case TOP_LEVEL_FOLDER: | 1108 case TOP_LEVEL_FOLDER: |
1110 continue; // Datatype isn't a function of Specifics. | 1109 continue; // Datatype isn't a function of Specifics. |
1111 default: | 1110 default: |
1112 break; | 1111 break; |
1113 } | 1112 } |
1114 sync_pb::EntitySpecifics specifics; | 1113 sync_pb::EntitySpecifics specifics; |
1115 AddDefaultFieldValue(datatype, &specifics); | 1114 AddDefaultFieldValue(datatype, &specifics); |
1116 | 1115 |
1117 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1116 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1118 | 1117 |
1119 MutableEntry folder(&trans, CREATE, trans.root_id(), "Folder"); | 1118 MutableEntry folder(&trans, CREATE_BOOKMARK, trans.root_id(), "Folder"); |
1120 ASSERT_TRUE(folder.good()); | 1119 ASSERT_TRUE(folder.good()); |
1121 folder.Put(ID, id_factory.NewServerId()); | 1120 folder.Put(ID, id_factory.NewServerId()); |
1122 folder.Put(SPECIFICS, specifics); | 1121 folder.Put(SPECIFICS, specifics); |
1123 folder.Put(BASE_VERSION, 1); | 1122 folder.Put(BASE_VERSION, 1); |
1124 folder.Put(IS_DIR, true); | 1123 folder.Put(IS_DIR, true); |
1125 folder.Put(IS_DEL, false); | 1124 folder.Put(IS_DEL, false); |
1126 ASSERT_EQ(datatype, folder.GetModelType()); | 1125 ASSERT_EQ(datatype, folder.GetModelType()); |
1127 | 1126 |
1128 MutableEntry item(&trans, CREATE, trans.root_id(), "Item"); | 1127 MutableEntry item(&trans, CREATE_BOOKMARK, trans.root_id(), "Item"); |
1129 ASSERT_TRUE(item.good()); | 1128 ASSERT_TRUE(item.good()); |
1130 item.Put(ID, id_factory.NewServerId()); | 1129 item.Put(ID, id_factory.NewServerId()); |
1131 item.Put(SPECIFICS, specifics); | 1130 item.Put(SPECIFICS, specifics); |
1132 item.Put(BASE_VERSION, 1); | 1131 item.Put(BASE_VERSION, 1); |
1133 item.Put(IS_DIR, false); | 1132 item.Put(IS_DIR, false); |
1134 item.Put(IS_DEL, false); | 1133 item.Put(IS_DEL, false); |
1135 ASSERT_EQ(datatype, item.GetModelType()); | 1134 ASSERT_EQ(datatype, item.GetModelType()); |
1136 | 1135 |
1137 // It's critical that deletion records retain their datatype, so that | 1136 // It's critical that deletion records retain their datatype, so that |
1138 // they can be dispatched to the appropriate change processor. | 1137 // they can be dispatched to the appropriate change processor. |
1139 MutableEntry deleted_item(&trans, CREATE, trans.root_id(), "Deleted Item"); | 1138 MutableEntry deleted_item( |
| 1139 &trans, CREATE_BOOKMARK, trans.root_id(), "Deleted Item"); |
1140 ASSERT_TRUE(item.good()); | 1140 ASSERT_TRUE(item.good()); |
1141 deleted_item.Put(ID, id_factory.NewServerId()); | 1141 deleted_item.Put(ID, id_factory.NewServerId()); |
1142 deleted_item.Put(SPECIFICS, specifics); | 1142 deleted_item.Put(SPECIFICS, specifics); |
1143 deleted_item.Put(BASE_VERSION, 1); | 1143 deleted_item.Put(BASE_VERSION, 1); |
1144 deleted_item.Put(IS_DIR, false); | 1144 deleted_item.Put(IS_DIR, false); |
1145 deleted_item.Put(IS_DEL, true); | 1145 deleted_item.Put(IS_DEL, true); |
1146 ASSERT_EQ(datatype, deleted_item.GetModelType()); | 1146 ASSERT_EQ(datatype, deleted_item.GetModelType()); |
1147 | 1147 |
1148 MutableEntry server_folder(&trans, CREATE_NEW_UPDATE_ITEM, | 1148 MutableEntry server_folder(&trans, CREATE_NEW_UPDATE_ITEM, |
1149 id_factory.NewServerId()); | 1149 id_factory.NewServerId()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 // a more common variant of the 'DeletedAndUnsyncedChild' scenario tested below. | 1184 // a more common variant of the 'DeletedAndUnsyncedChild' scenario tested below. |
1185 TEST_F(SyncableDirectoryTest, ChangeEntryIDAndUpdateChildren_ParentAndChild) { | 1185 TEST_F(SyncableDirectoryTest, ChangeEntryIDAndUpdateChildren_ParentAndChild) { |
1186 TestIdFactory id_factory; | 1186 TestIdFactory id_factory; |
1187 Id orig_parent_id; | 1187 Id orig_parent_id; |
1188 Id orig_child_id; | 1188 Id orig_child_id; |
1189 | 1189 |
1190 { | 1190 { |
1191 // Create two client-side items, a parent and child. | 1191 // Create two client-side items, a parent and child. |
1192 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1192 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1193 | 1193 |
1194 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent"); | 1194 MutableEntry parent(&trans, CREATE_BOOKMARK, id_factory.root(), "parent"); |
1195 parent.Put(IS_DIR, true); | 1195 parent.Put(IS_DIR, true); |
1196 parent.Put(IS_UNSYNCED, true); | 1196 parent.Put(IS_UNSYNCED, true); |
1197 | 1197 |
1198 MutableEntry child(&trans, CREATE, parent.Get(ID), "child"); | 1198 MutableEntry child(&trans, CREATE_BOOKMARK, parent.Get(ID), "child"); |
1199 child.Put(IS_UNSYNCED, true); | 1199 child.Put(IS_UNSYNCED, true); |
1200 | 1200 |
1201 orig_parent_id = parent.Get(ID); | 1201 orig_parent_id = parent.Get(ID); |
1202 orig_child_id = child.Get(ID); | 1202 orig_child_id = child.Get(ID); |
1203 } | 1203 } |
1204 | 1204 |
1205 { | 1205 { |
1206 // Simulate what happens after committing two items. Their IDs will be | 1206 // Simulate what happens after committing two items. Their IDs will be |
1207 // replaced with server IDs. The child is renamed first, then the parent. | 1207 // replaced with server IDs. The child is renamed first, then the parent. |
1208 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1208 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
(...skipping 23 matching lines...) Expand all Loading... |
1232 TEST_F(SyncableDirectoryTest, | 1232 TEST_F(SyncableDirectoryTest, |
1233 ChangeEntryIDAndUpdateChildren_DeletedAndUnsyncedChild) { | 1233 ChangeEntryIDAndUpdateChildren_DeletedAndUnsyncedChild) { |
1234 TestIdFactory id_factory; | 1234 TestIdFactory id_factory; |
1235 Id orig_parent_id; | 1235 Id orig_parent_id; |
1236 Id orig_child_id; | 1236 Id orig_child_id; |
1237 | 1237 |
1238 { | 1238 { |
1239 // Create two client-side items, a parent and child. | 1239 // Create two client-side items, a parent and child. |
1240 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1240 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1241 | 1241 |
1242 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent"); | 1242 MutableEntry parent(&trans, CREATE_BOOKMARK, id_factory.root(), "parent"); |
1243 parent.Put(IS_DIR, true); | 1243 parent.Put(IS_DIR, true); |
1244 parent.Put(IS_UNSYNCED, true); | 1244 parent.Put(IS_UNSYNCED, true); |
1245 | 1245 |
1246 MutableEntry child(&trans, CREATE, parent.Get(ID), "child"); | 1246 MutableEntry child(&trans, CREATE_BOOKMARK, parent.Get(ID), "child"); |
1247 child.Put(IS_UNSYNCED, true); | 1247 child.Put(IS_UNSYNCED, true); |
1248 | 1248 |
1249 orig_parent_id = parent.Get(ID); | 1249 orig_parent_id = parent.Get(ID); |
1250 orig_child_id = child.Get(ID); | 1250 orig_child_id = child.Get(ID); |
1251 } | 1251 } |
1252 | 1252 |
1253 { | 1253 { |
1254 // Delete the child. | 1254 // Delete the child. |
1255 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1255 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1256 | 1256 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 Id zombie_id = id_factory.NewLocalId(); | 1315 Id zombie_id = id_factory.NewLocalId(); |
1316 | 1316 |
1317 // We're about to do some bad things. Tell the directory verification | 1317 // We're about to do some bad things. Tell the directory verification |
1318 // routines to look the other way. | 1318 // routines to look the other way. |
1319 dir_->SetInvariantCheckLevel(OFF); | 1319 dir_->SetInvariantCheckLevel(OFF); |
1320 | 1320 |
1321 { | 1321 { |
1322 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1322 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1323 | 1323 |
1324 // Create an uncommitted tombstone entry. | 1324 // Create an uncommitted tombstone entry. |
1325 MutableEntry server_knows(&trans, CREATE, id_factory.root(), | 1325 MutableEntry server_knows(&trans, CREATE_BOOKMARK, id_factory.root(), |
1326 "server_knows"); | 1326 "server_knows"); |
1327 server_knows.Put(ID, server_knows_id); | 1327 server_knows.Put(ID, server_knows_id); |
1328 server_knows.Put(IS_UNSYNCED, true); | 1328 server_knows.Put(IS_UNSYNCED, true); |
1329 server_knows.Put(IS_DEL, true); | 1329 server_knows.Put(IS_DEL, true); |
1330 server_knows.Put(BASE_VERSION, 5); | 1330 server_knows.Put(BASE_VERSION, 5); |
1331 server_knows.Put(SERVER_VERSION, 4); | 1331 server_knows.Put(SERVER_VERSION, 4); |
1332 | 1332 |
1333 // Create a valid update entry. | 1333 // Create a valid update entry. |
1334 MutableEntry not_is_del(&trans, CREATE, id_factory.root(), "not_is_del"); | 1334 MutableEntry not_is_del( |
| 1335 &trans, CREATE_BOOKMARK, id_factory.root(), "not_is_del"); |
1335 not_is_del.Put(ID, not_is_del_id); | 1336 not_is_del.Put(ID, not_is_del_id); |
1336 not_is_del.Put(IS_DEL, false); | 1337 not_is_del.Put(IS_DEL, false); |
1337 not_is_del.Put(IS_UNSYNCED, true); | 1338 not_is_del.Put(IS_UNSYNCED, true); |
1338 | 1339 |
1339 // Create a tombstone which should never be sent to the server because the | 1340 // Create a tombstone which should never be sent to the server because the |
1340 // server never knew about the item's existence. | 1341 // server never knew about the item's existence. |
1341 // | 1342 // |
1342 // New clients should never put entries into this state. We work around | 1343 // New clients should never put entries into this state. We work around |
1343 // this by setting IS_DEL before setting IS_UNSYNCED, something which the | 1344 // this by setting IS_DEL before setting IS_UNSYNCED, something which the |
1344 // client should never do in practice. | 1345 // client should never do in practice. |
1345 MutableEntry zombie(&trans, CREATE, id_factory.root(), "zombie"); | 1346 MutableEntry zombie(&trans, CREATE_BOOKMARK, id_factory.root(), "zombie"); |
1346 zombie.Put(ID, zombie_id); | 1347 zombie.Put(ID, zombie_id); |
1347 zombie.Put(IS_DEL, true); | 1348 zombie.Put(IS_DEL, true); |
1348 zombie.Put(IS_UNSYNCED, true); | 1349 zombie.Put(IS_UNSYNCED, true); |
1349 } | 1350 } |
1350 | 1351 |
1351 ASSERT_EQ(OPENED, SimulateSaveAndReloadDir()); | 1352 ASSERT_EQ(OPENED, SimulateSaveAndReloadDir()); |
1352 | 1353 |
1353 { | 1354 { |
1354 ReadTransaction trans(FROM_HERE, dir_.get()); | 1355 ReadTransaction trans(FROM_HERE, dir_.get()); |
1355 | 1356 |
1356 // The directory loading routines should have cleaned things up, making it | 1357 // The directory loading routines should have cleaned things up, making it |
1357 // safe to check invariants once again. | 1358 // safe to check invariants once again. |
1358 dir_->FullyCheckTreeInvariants(&trans); | 1359 dir_->FullyCheckTreeInvariants(&trans); |
1359 | 1360 |
1360 Entry server_knows(&trans, GET_BY_ID, server_knows_id); | 1361 Entry server_knows(&trans, GET_BY_ID, server_knows_id); |
1361 EXPECT_TRUE(server_knows.good()); | 1362 EXPECT_TRUE(server_knows.good()); |
1362 | 1363 |
1363 Entry not_is_del(&trans, GET_BY_ID, not_is_del_id); | 1364 Entry not_is_del(&trans, GET_BY_ID, not_is_del_id); |
1364 EXPECT_TRUE(not_is_del.good()); | 1365 EXPECT_TRUE(not_is_del.good()); |
1365 | 1366 |
1366 Entry zombie(&trans, GET_BY_ID, zombie_id); | 1367 Entry zombie(&trans, GET_BY_ID, zombie_id); |
1367 EXPECT_FALSE(zombie.good()); | 1368 EXPECT_FALSE(zombie.good()); |
1368 } | 1369 } |
1369 } | 1370 } |
1370 | 1371 |
1371 TEST_F(SyncableDirectoryTest, OrdinalWithNullSurvivesSaveAndReload) { | 1372 TEST_F(SyncableDirectoryTest, PositionWithNullSurvivesSaveAndReload) { |
1372 TestIdFactory id_factory; | 1373 TestIdFactory id_factory; |
1373 Id null_child_id; | 1374 Id null_child_id; |
1374 const char null_cstr[] = "\0null\0test"; | 1375 const char null_cstr[] = "\0null\0test"; |
1375 std::string null_str(null_cstr, arraysize(null_cstr) - 1); | 1376 std::string null_str(null_cstr, arraysize(null_cstr) - 1); |
1376 NodeOrdinal null_ord = NodeOrdinal(null_str); | 1377 std::string suffix = |
| 1378 std::string(UniquePosition::kSuffixLength - null_str.length(), '\x7f') |
| 1379 + null_str; |
| 1380 UniquePosition null_pos = UniquePosition::FromInt64(10, suffix); |
1377 | 1381 |
1378 { | 1382 { |
1379 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1383 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1380 | 1384 |
1381 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent"); | 1385 MutableEntry parent(&trans, CREATE_BOOKMARK, id_factory.root(), "parent"); |
1382 parent.Put(IS_DIR, true); | 1386 parent.Put(IS_DIR, true); |
1383 parent.Put(IS_UNSYNCED, true); | 1387 parent.Put(IS_UNSYNCED, true); |
1384 | 1388 |
1385 MutableEntry child(&trans, CREATE, parent.Get(ID), "child"); | 1389 MutableEntry child(&trans, CREATE_BOOKMARK, parent.Get(ID), "child"); |
1386 child.Put(IS_UNSYNCED, true); | 1390 child.Put(IS_UNSYNCED, true); |
1387 child.Put(SERVER_ORDINAL_IN_PARENT, null_ord); | 1391 child.Put(UNIQUE_POSITION, null_pos); |
| 1392 child.Put(SERVER_UNIQUE_POSITION, null_pos); |
1388 | 1393 |
1389 null_child_id = child.Get(ID); | 1394 null_child_id = child.Get(ID); |
1390 } | 1395 } |
1391 | 1396 |
1392 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); | 1397 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); |
1393 | 1398 |
1394 { | 1399 { |
1395 ReadTransaction trans(FROM_HERE, dir_.get()); | 1400 ReadTransaction trans(FROM_HERE, dir_.get()); |
1396 | 1401 |
1397 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id); | 1402 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id); |
1398 EXPECT_TRUE( | 1403 EXPECT_TRUE( |
1399 null_ord.Equals(null_ordinal_child.Get(SERVER_ORDINAL_IN_PARENT))); | 1404 null_pos.Equals(null_ordinal_child.Get(UNIQUE_POSITION))); |
| 1405 EXPECT_TRUE( |
| 1406 null_pos.Equals(null_ordinal_child.Get(SERVER_UNIQUE_POSITION))); |
1400 } | 1407 } |
1401 | |
1402 } | 1408 } |
1403 | 1409 |
1404 // An OnDirectoryBackingStore that can be set to always fail SaveChanges. | 1410 // An OnDirectoryBackingStore that can be set to always fail SaveChanges. |
1405 class TestBackingStore : public OnDiskDirectoryBackingStore { | 1411 class TestBackingStore : public OnDiskDirectoryBackingStore { |
1406 public: | 1412 public: |
1407 TestBackingStore(const std::string& dir_name, | 1413 TestBackingStore(const std::string& dir_name, |
1408 const FilePath& backing_filepath); | 1414 const FilePath& backing_filepath); |
1409 | 1415 |
1410 virtual ~TestBackingStore(); | 1416 virtual ~TestBackingStore(); |
1411 | 1417 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1565 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1560 | 1566 |
1561 // Make it look like these types have completed initial sync. | 1567 // Make it look like these types have completed initial sync. |
1562 CreateTypeRoot(&trans, dir_.get(), BOOKMARKS); | 1568 CreateTypeRoot(&trans, dir_.get(), BOOKMARKS); |
1563 CreateTypeRoot(&trans, dir_.get(), PREFERENCES); | 1569 CreateTypeRoot(&trans, dir_.get(), PREFERENCES); |
1564 CreateTypeRoot(&trans, dir_.get(), AUTOFILL); | 1570 CreateTypeRoot(&trans, dir_.get(), AUTOFILL); |
1565 | 1571 |
1566 // Add more nodes for this type. Technically, they should be placed under | 1572 // Add more nodes for this type. Technically, they should be placed under |
1567 // the proper type root nodes but the assertions in this test won't notice | 1573 // the proper type root nodes but the assertions in this test won't notice |
1568 // if their parent isn't quite right. | 1574 // if their parent isn't quite right. |
1569 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); | 1575 MutableEntry item1(&trans, CREATE_BOOKMARK, trans.root_id(), "Item"); |
1570 ASSERT_TRUE(item1.good()); | 1576 ASSERT_TRUE(item1.good()); |
1571 item1.Put(SPECIFICS, bookmark_specs); | |
1572 item1.Put(SERVER_SPECIFICS, bookmark_specs); | 1577 item1.Put(SERVER_SPECIFICS, bookmark_specs); |
1573 item1.Put(IS_UNSYNCED, true); | 1578 item1.Put(IS_UNSYNCED, true); |
1574 | 1579 |
1575 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM, | 1580 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM, |
1576 id_factory.NewServerId()); | 1581 id_factory.NewServerId()); |
1577 ASSERT_TRUE(item2.good()); | 1582 ASSERT_TRUE(item2.good()); |
1578 item2.Put(SERVER_SPECIFICS, bookmark_specs); | 1583 item2.Put(SERVER_SPECIFICS, bookmark_specs); |
1579 item2.Put(IS_UNAPPLIED_UPDATE, true); | 1584 item2.Put(IS_UNAPPLIED_UPDATE, true); |
1580 | 1585 |
1581 MutableEntry item3(&trans, CREATE, trans.root_id(), "Item"); | 1586 MutableEntry item3(&trans, CREATE_UNIQUE, PREFERENCES, |
| 1587 trans.root_id(), "Item"); |
1582 ASSERT_TRUE(item3.good()); | 1588 ASSERT_TRUE(item3.good()); |
1583 item3.Put(SPECIFICS, preference_specs); | 1589 item3.Put(SPECIFICS, preference_specs); |
1584 item3.Put(SERVER_SPECIFICS, preference_specs); | 1590 item3.Put(SERVER_SPECIFICS, preference_specs); |
1585 item3.Put(IS_UNSYNCED, true); | 1591 item3.Put(IS_UNSYNCED, true); |
1586 | 1592 |
1587 MutableEntry item4(&trans, CREATE_NEW_UPDATE_ITEM, | 1593 MutableEntry item4(&trans, CREATE_NEW_UPDATE_ITEM, |
1588 id_factory.NewServerId()); | 1594 id_factory.NewServerId()); |
1589 ASSERT_TRUE(item4.good()); | 1595 ASSERT_TRUE(item4.good()); |
1590 item4.Put(SERVER_SPECIFICS, preference_specs); | 1596 item4.Put(SERVER_SPECIFICS, preference_specs); |
1591 item4.Put(IS_UNAPPLIED_UPDATE, true); | 1597 item4.Put(IS_UNAPPLIED_UPDATE, true); |
1592 | 1598 |
1593 MutableEntry item5(&trans, CREATE, trans.root_id(), "Item"); | 1599 MutableEntry item5(&trans, CREATE_UNIQUE, AUTOFILL, |
| 1600 trans.root_id(), "Item"); |
1594 ASSERT_TRUE(item5.good()); | 1601 ASSERT_TRUE(item5.good()); |
1595 item5.Put(SPECIFICS, autofill_specs); | 1602 item5.Put(SPECIFICS, autofill_specs); |
1596 item5.Put(SERVER_SPECIFICS, autofill_specs); | 1603 item5.Put(SERVER_SPECIFICS, autofill_specs); |
1597 item5.Put(IS_UNSYNCED, true); | 1604 item5.Put(IS_UNSYNCED, true); |
1598 | 1605 |
1599 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM, | 1606 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM, |
1600 id_factory.NewServerId()); | 1607 id_factory.NewServerId()); |
1601 ASSERT_TRUE(item6.good()); | 1608 ASSERT_TRUE(item6.good()); |
1602 item6.Put(SERVER_SPECIFICS, autofill_specs); | 1609 item6.Put(SERVER_SPECIFICS, autofill_specs); |
1603 item6.Put(IS_UNAPPLIED_UPDATE, true); | 1610 item6.Put(IS_UNAPPLIED_UPDATE, true); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 TEST_F(OnDiskSyncableDirectoryTest, | 1667 TEST_F(OnDiskSyncableDirectoryTest, |
1661 TestSimpleFieldsPreservedDuringSaveChanges) { | 1668 TestSimpleFieldsPreservedDuringSaveChanges) { |
1662 Id update_id = TestIdFactory::FromNumber(1); | 1669 Id update_id = TestIdFactory::FromNumber(1); |
1663 Id create_id; | 1670 Id create_id; |
1664 EntryKernel create_pre_save, update_pre_save; | 1671 EntryKernel create_pre_save, update_pre_save; |
1665 EntryKernel create_post_save, update_post_save; | 1672 EntryKernel create_post_save, update_post_save; |
1666 std::string create_name = "Create"; | 1673 std::string create_name = "Create"; |
1667 | 1674 |
1668 { | 1675 { |
1669 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1676 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1670 MutableEntry create(&trans, CREATE, trans.root_id(), create_name); | 1677 MutableEntry create(&trans, CREATE_BOOKMARK, trans.root_id(), create_name); |
1671 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); | 1678 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); |
1672 create.Put(IS_UNSYNCED, true); | 1679 create.Put(IS_UNSYNCED, true); |
1673 update.Put(IS_UNAPPLIED_UPDATE, true); | 1680 update.Put(IS_UNAPPLIED_UPDATE, true); |
1674 sync_pb::EntitySpecifics specifics; | 1681 sync_pb::EntitySpecifics specifics; |
1675 specifics.mutable_bookmark()->set_favicon("PNG"); | 1682 specifics.mutable_bookmark()->set_favicon("PNG"); |
1676 specifics.mutable_bookmark()->set_url("http://nowhere"); | 1683 specifics.mutable_bookmark()->set_url("http://nowhere"); |
1677 create.Put(SPECIFICS, specifics); | 1684 create.Put(SPECIFICS, specifics); |
1678 update.Put(SPECIFICS, specifics); | 1685 update.Put(SPECIFICS, specifics); |
1679 create_pre_save = create.GetKernelCopy(); | 1686 create_pre_save = create.GetKernelCopy(); |
1680 update_pre_save = update.GetKernelCopy(); | 1687 update_pre_save = update.GetKernelCopy(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 << "String field #" << i << " changed during save/load"; | 1751 << "String field #" << i << " changed during save/load"; |
1745 } | 1752 } |
1746 for ( ; i < PROTO_FIELDS_END; ++i) { | 1753 for ( ; i < PROTO_FIELDS_END; ++i) { |
1747 EXPECT_EQ(create_pre_save.ref((ProtoField)i).SerializeAsString(), | 1754 EXPECT_EQ(create_pre_save.ref((ProtoField)i).SerializeAsString(), |
1748 create_post_save.ref((ProtoField)i).SerializeAsString()) | 1755 create_post_save.ref((ProtoField)i).SerializeAsString()) |
1749 << "Blob field #" << i << " changed during save/load"; | 1756 << "Blob field #" << i << " changed during save/load"; |
1750 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(), | 1757 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(), |
1751 update_post_save.ref((ProtoField)i).SerializeAsString()) | 1758 update_post_save.ref((ProtoField)i).SerializeAsString()) |
1752 << "Blob field #" << i << " changed during save/load"; | 1759 << "Blob field #" << i << " changed during save/load"; |
1753 } | 1760 } |
1754 for ( ; i < ORDINAL_FIELDS_END; ++i) { | 1761 for ( ; i < UNIQUE_POSITION_FIELDS_END; ++i) { |
1755 EXPECT_EQ(create_pre_save.ref((OrdinalField)i).ToInternalValue(), | 1762 EXPECT_EQ(create_pre_save.ref((UniquePositionField)i).ToInternalValue(), |
1756 create_post_save.ref((OrdinalField)i).ToInternalValue()) | 1763 create_post_save.ref((UniquePositionField)i).ToInternalValue()) |
1757 << "Blob field #" << i << " changed during save/load"; | 1764 << "Position field #" << i << " changed during save/load"; |
1758 EXPECT_EQ(update_pre_save.ref((OrdinalField)i).ToInternalValue(), | 1765 EXPECT_EQ(update_pre_save.ref((UniquePositionField)i).ToInternalValue(), |
1759 update_post_save.ref((OrdinalField)i).ToInternalValue()) | 1766 update_post_save.ref((UniquePositionField)i).ToInternalValue()) |
1760 << "Blob field #" << i << " changed during save/load"; | 1767 << "Position field #" << i << " changed during save/load"; |
| 1768 } |
| 1769 for ( ; i < BYTES_FIELDS_END; ++i) { |
| 1770 EXPECT_EQ(create_pre_save.ref((BytesField)i), |
| 1771 create_post_save.ref((BytesField)i)) |
| 1772 << "Bytes field #" << i << " changed during save/load"; |
| 1773 EXPECT_EQ(update_pre_save.ref((BytesField)i), |
| 1774 update_post_save.ref((BytesField)i)) |
| 1775 << "Bytes field #" << i << " changed during save/load"; |
1761 } | 1776 } |
1762 } | 1777 } |
1763 | 1778 |
1764 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { | 1779 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { |
1765 int64 handle1 = 0; | 1780 int64 handle1 = 0; |
1766 // Set up an item using a regular, saveable directory. | 1781 // Set up an item using a regular, saveable directory. |
1767 { | 1782 { |
1768 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1783 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1769 | 1784 |
1770 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); | 1785 MutableEntry e1(&trans, CREATE_BOOKMARK, trans.root_id(), "aguilera"); |
1771 ASSERT_TRUE(e1.good()); | 1786 ASSERT_TRUE(e1.good()); |
1772 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); | 1787 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); |
1773 handle1 = e1.Get(META_HANDLE); | 1788 handle1 = e1.Get(META_HANDLE); |
1774 e1.Put(BASE_VERSION, 1); | 1789 e1.Put(BASE_VERSION, 1); |
1775 e1.Put(IS_DIR, true); | 1790 e1.Put(IS_DIR, true); |
1776 e1.Put(ID, TestIdFactory::FromNumber(101)); | 1791 e1.Put(ID, TestIdFactory::FromNumber(101)); |
1777 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); | 1792 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); |
1778 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); | 1793 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); |
1779 } | 1794 } |
1780 ASSERT_TRUE(dir_->SaveChanges()); | 1795 ASSERT_TRUE(dir_->SaveChanges()); |
(...skipping 25 matching lines...) Expand all Loading... |
1806 ASSERT_TRUE(aguilera.good()); | 1821 ASSERT_TRUE(aguilera.good()); |
1807 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); | 1822 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); |
1808 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "overwritten"); | 1823 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "overwritten"); |
1809 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); | 1824 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); |
1810 EXPECT_FALSE(IsInDirtyMetahandles(handle1)); | 1825 EXPECT_FALSE(IsInDirtyMetahandles(handle1)); |
1811 aguilera.Put(NON_UNIQUE_NAME, "christina"); | 1826 aguilera.Put(NON_UNIQUE_NAME, "christina"); |
1812 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty()); | 1827 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty()); |
1813 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); | 1828 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); |
1814 | 1829 |
1815 // New item. | 1830 // New item. |
1816 MutableEntry kids_on_block(&trans, CREATE, trans.root_id(), "kids"); | 1831 MutableEntry kids_on_block( |
| 1832 &trans, CREATE_BOOKMARK, trans.root_id(), "kids"); |
1817 ASSERT_TRUE(kids_on_block.good()); | 1833 ASSERT_TRUE(kids_on_block.good()); |
1818 handle2 = kids_on_block.Get(META_HANDLE); | 1834 handle2 = kids_on_block.Get(META_HANDLE); |
1819 kids_on_block.Put(BASE_VERSION, 1); | 1835 kids_on_block.Put(BASE_VERSION, 1); |
1820 kids_on_block.Put(IS_DIR, true); | 1836 kids_on_block.Put(IS_DIR, true); |
1821 kids_on_block.Put(ID, TestIdFactory::FromNumber(102)); | 1837 kids_on_block.Put(ID, TestIdFactory::FromNumber(102)); |
1822 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty()); | 1838 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty()); |
1823 EXPECT_TRUE(IsInDirtyMetahandles(handle2)); | 1839 EXPECT_TRUE(IsInDirtyMetahandles(handle2)); |
1824 } | 1840 } |
1825 | 1841 |
1826 // We are using an unsaveable directory, so this can't succeed. However, | 1842 // We are using an unsaveable directory, so this can't succeed. However, |
(...skipping 14 matching lines...) Expand all Loading... |
1841 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); | 1857 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); |
1842 } | 1858 } |
1843 } | 1859 } |
1844 | 1860 |
1845 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailureWithPurge) { | 1861 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailureWithPurge) { |
1846 int64 handle1 = 0; | 1862 int64 handle1 = 0; |
1847 // Set up an item using a regular, saveable directory. | 1863 // Set up an item using a regular, saveable directory. |
1848 { | 1864 { |
1849 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1865 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1850 | 1866 |
1851 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); | 1867 MutableEntry e1(&trans, CREATE_BOOKMARK, trans.root_id(), "aguilera"); |
1852 ASSERT_TRUE(e1.good()); | 1868 ASSERT_TRUE(e1.good()); |
1853 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); | 1869 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); |
1854 handle1 = e1.Get(META_HANDLE); | 1870 handle1 = e1.Get(META_HANDLE); |
1855 e1.Put(BASE_VERSION, 1); | 1871 e1.Put(BASE_VERSION, 1); |
1856 e1.Put(IS_DIR, true); | 1872 e1.Put(IS_DIR, true); |
1857 e1.Put(ID, TestIdFactory::FromNumber(101)); | 1873 e1.Put(ID, TestIdFactory::FromNumber(101)); |
1858 sync_pb::EntitySpecifics bookmark_specs; | 1874 sync_pb::EntitySpecifics bookmark_specs; |
1859 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); | 1875 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); |
1860 e1.Put(SPECIFICS, bookmark_specs); | 1876 e1.Put(SPECIFICS, bookmark_specs); |
1861 e1.Put(SERVER_SPECIFICS, bookmark_specs); | 1877 e1.Put(SERVER_SPECIFICS, bookmark_specs); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 if (rand_action < 4 && !path_name.empty()) { | 2001 if (rand_action < 4 && !path_name.empty()) { |
1986 ReadTransaction trans(FROM_HERE, dir_); | 2002 ReadTransaction trans(FROM_HERE, dir_); |
1987 CHECK(1 == CountEntriesWithName(&trans, trans.root_id(), path_name)); | 2003 CHECK(1 == CountEntriesWithName(&trans, trans.root_id(), path_name)); |
1988 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 2004 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
1989 rand() % 10)); | 2005 rand() % 10)); |
1990 } else { | 2006 } else { |
1991 std::string unique_name = | 2007 std::string unique_name = |
1992 base::StringPrintf("%d.%d", thread_number_, entry_count++); | 2008 base::StringPrintf("%d.%d", thread_number_, entry_count++); |
1993 path_name.assign(unique_name.begin(), unique_name.end()); | 2009 path_name.assign(unique_name.begin(), unique_name.end()); |
1994 WriteTransaction trans(FROM_HERE, UNITTEST, dir_); | 2010 WriteTransaction trans(FROM_HERE, UNITTEST, dir_); |
1995 MutableEntry e(&trans, CREATE, trans.root_id(), path_name); | 2011 MutableEntry e(&trans, CREATE_BOOKMARK, trans.root_id(), path_name); |
1996 CHECK(e.good()); | 2012 CHECK(e.good()); |
1997 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 2013 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
1998 rand() % 20)); | 2014 rand() % 20)); |
1999 e.Put(IS_UNSYNCED, true); | 2015 e.Put(IS_UNSYNCED, true); |
2000 if (e.Put(ID, TestIdFactory::FromNumber(rand())) && | 2016 if (e.Put(ID, TestIdFactory::FromNumber(rand())) && |
2001 e.Get(ID).ServerKnows() && !e.Get(ID).IsRoot()) { | 2017 e.Get(ID).ServerKnows() && !e.Get(ID).IsRoot()) { |
2002 e.Put(BASE_VERSION, 1); | 2018 e.Put(BASE_VERSION, 1); |
2003 } | 2019 } |
2004 } | 2020 } |
2005 } | 2021 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2042 | 2058 |
2043 class SyncableClientTagTest : public SyncableDirectoryTest { | 2059 class SyncableClientTagTest : public SyncableDirectoryTest { |
2044 public: | 2060 public: |
2045 static const int kBaseVersion = 1; | 2061 static const int kBaseVersion = 1; |
2046 const char* test_name_; | 2062 const char* test_name_; |
2047 const char* test_tag_; | 2063 const char* test_tag_; |
2048 | 2064 |
2049 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {} | 2065 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {} |
2050 | 2066 |
2051 bool CreateWithDefaultTag(Id id, bool deleted) { | 2067 bool CreateWithDefaultTag(Id id, bool deleted) { |
2052 return CreateWithTag(test_tag_, id, deleted); | |
2053 } | |
2054 | |
2055 // Attempt to create an entry with a default tag. | |
2056 bool CreateWithTag(const char* tag, Id id, bool deleted) { | |
2057 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); | 2068 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); |
2058 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), test_name_); | 2069 MutableEntry me(&wtrans, CREATE_UNIQUE, PREFERENCES, |
| 2070 wtrans.root_id(), test_name_); |
2059 CHECK(me.good()); | 2071 CHECK(me.good()); |
2060 me.Put(ID, id); | 2072 me.Put(ID, id); |
2061 if (id.ServerKnows()) { | 2073 if (id.ServerKnows()) { |
2062 me.Put(BASE_VERSION, kBaseVersion); | 2074 me.Put(BASE_VERSION, kBaseVersion); |
2063 } | 2075 } |
2064 me.Put(IS_UNSYNCED, true); | 2076 me.Put(IS_UNSYNCED, true); |
2065 me.Put(IS_DEL, deleted); | 2077 me.Put(IS_DEL, deleted); |
2066 me.Put(IS_DIR, false); | 2078 me.Put(IS_DIR, false); |
2067 return me.Put(UNIQUE_CLIENT_TAG, tag); | 2079 return me.Put(UNIQUE_CLIENT_TAG, test_tag_); |
2068 } | 2080 } |
2069 | 2081 |
2070 // Verify an entry exists with the default tag. | 2082 // Verify an entry exists with the default tag. |
2071 void VerifyTag(Id id, bool deleted) { | 2083 void VerifyTag(Id id, bool deleted) { |
2072 // Should still be present and valid in the client tag index. | 2084 // Should still be present and valid in the client tag index. |
2073 ReadTransaction trans(FROM_HERE, dir_.get()); | 2085 ReadTransaction trans(FROM_HERE, dir_.get()); |
2074 Entry me(&trans, GET_BY_CLIENT_TAG, test_tag_); | 2086 Entry me(&trans, GET_BY_CLIENT_TAG, test_tag_); |
2075 CHECK(me.good()); | 2087 CHECK(me.good()); |
2076 EXPECT_EQ(me.Get(ID), id); | 2088 EXPECT_EQ(me.Get(ID), id); |
2077 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), test_tag_); | 2089 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), test_tag_); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2147 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2136 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2148 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2137 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 2149 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
2138 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 2150 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
2139 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 2151 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
2140 } | 2152 } |
2141 | 2153 |
2142 } // namespace | 2154 } // namespace |
2143 } // namespace syncable | 2155 } // namespace syncable |
2144 } // namespace syncer | 2156 } // namespace syncer |
OLD | NEW |